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

From: Kostik Belousov <kostikbel_at_gmail.com>
Date: Tue, 22 Nov 2011 14:44:10 +0200
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


Received on Tue Nov 22 2011 - 11:44:16 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:20 UTC