Skip to content

Instantly share code, notes, and snippets.

@lbolla
Created February 26, 2016 16:42
Show Gist options
  • Save lbolla/8e2640133032b0a6bb9c to your computer and use it in GitHub Desktop.
Save lbolla/8e2640133032b0a6bb9c to your computer and use it in GitHub Desktop.
import gc
import os
import resource
def print_mem():
u = resource.getrusage(resource.RUSAGE_SELF)
print 'N={} RSS={}'.format(N, u.ru_maxrss)
def alloc(N):
_x = {i: i for i in xrange(N)}
# print_mem()
print 'MALLOC_MMAP_THRESHOLD_={} MALLOC_MMAP_MAX_={}'.format(
os.environ.get('MALLOC_MMAP_THRESHOLD_'),
os.environ.get('MALLOC_MMAP_MAX_'),
)
for N in xrange(10):
alloc(N * 100000)
print_mem()
#!/bin/bash
python alloc.py
MALLOC_MMAP_THRESHOLD_=512 python alloc.py
MALLOC_MMAP_THRESHOLD_=1024 python alloc.py
MALLOC_MMAP_THRESHOLD_=2048 python alloc.py
MALLOC_MMAP_THRESHOLD_=4096 python alloc.py
MALLOC_MMAP_THRESHOLD_=100000 python alloc.py
MALLOC_MMAP_THRESHOLD_=512 MALLOC_MMAP_MAX_=0 python alloc.py
MALLOC_MMAP_THRESHOLD_=1024 MALLOC_MMAP_MAX_=0 python alloc.py
MALLOC_MMAP_THRESHOLD_=2048 MALLOC_MMAP_MAX_=0 python alloc.py
MALLOC_MMAP_THRESHOLD_=4096 MALLOC_MMAP_MAX_=0 python alloc.py
MALLOC_MMAP_THRESHOLD_=100000 MALLOC_MMAP_MAX_=0 python alloc.py
MALLOC_MMAP_THRESHOLD_=512 MALLOC_MMAP_MAX_=16777216 python alloc.py
MALLOC_MMAP_THRESHOLD_=1024 MALLOC_MMAP_MAX_=16777216 python alloc.py
MALLOC_MMAP_THRESHOLD_=2048 MALLOC_MMAP_MAX_=16777216 python alloc.py
MALLOC_MMAP_THRESHOLD_=4096 MALLOC_MMAP_MAX_=16777216 python alloc.py
MALLOC_MMAP_THRESHOLD_=100000 MALLOC_MMAP_MAX_=16777216 python alloc.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment