mallopt disabling mmap

Here are some notes for using mallopt to disable mmap for potentially better performance.

If we use the default malloc, it will use mmap for pages larger than a certain size.

Using mmap means that if a page is freed, it will be given back to the OS. The OS would need to clean (zero out) all the values of the pages before it can be reallocated. This can take more time, but can be more memory efficient with the OS.

On the other hand, malloc be default will keep the freed spaces in its own free list for small allocations.

Sometimes using MMap can lead to significant overhead when the OS is spending a lot of time cleaning the freed pages. As a result, disabling the mmap, always use the malloc freelist can sometimes be good. It would sometimes come at a cost of larger memory footprint.

To do this, we can use the following commands (borrowed from Ligra github, https://github.com/jshun/ligra/blob/master/ligra/utils.h  )

static int __ii = mallopt(M_MMAP_MAX,0);

static int __jj = mallopt(M_TRIM_THRESHOLD,-1);

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s