RLIMIT_DATA and malloc(3) use of mmap(2)

Kostik Belousov kostikbel at gmail.com
Tue Nov 22 12:44:16 UTC 2011


I was reminded about the patch I wrote for Igor Sysoev some time ago.
The issue the patch tries to handle is that jemalloc uses mmap() instead
of sbrk() for pages allocation, and thus RLIMIT_DATA limit is no longer
effective to put the bounds on the process heap. Since reverting to sbrk
for such purpose is worse then the issue itself, I proposed a solution
of 'self-restricting malloc'.

The patch adds a flag MAP_DATALIMIT to the flags argument of mmap(2),
which instructs the system to account the mapping in the RLIMIT_DATA
resource count. The malloc(3) also gets new option 'L' to enable
passing MAP_DATALIMIT to mmap() when allocating pages. By default,
the 'L' option is not activated.

Now, if user wants to ensure that process heap is restricted by the
ulimit -d and still use mmap() for jemalloc, he supplies the option
using any mechanism. The behaviour is voluntaristic, to prevent the
trashing use RLIMIT_SWAP.

Do people consider the facility useful ? Any comments for the patch itself ?

http://people.freebsd.org/~kib/misc/map_datalimit.1.patch

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-current/attachments/20111122/abb91b8a/attachment.pgp


More information about the freebsd-current mailing list