mmap: Use MAP_NORESERVE to request overcommit, not PROT_NONE.
This reverts hrev54120 and instead adds the commonly supported MAP_NORESERVE flag to request overcommit. Using PROT_NONE for overcommit is problematic as the protection of individual pages can still be changed via mprotect to make them accessible, but that won't change the commitment. An application using such a pattern may then unexpectedly run into out of memory conditions on random writes into the address space. With MAP_NORESERVE the overcommit can explicitly be requested by applications that want to reserve address space without producing memory pressure. Change-Id: Id213d2245c5e23103e8e0857f7902e0cd8a2c65d Reviewed-on: https://review.haiku-os.org/c/haiku/+/2611 Reviewed-by: waddlesplash <waddlesplash@gmail.com> Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
This commit is contained in:
parent
7362b02b0e
commit
b94221f3b2
@ -23,6 +23,7 @@
|
||||
#define MAP_FIXED 0x04 /* require mapping to specified addr */
|
||||
#define MAP_ANONYMOUS 0x08 /* no underlying object */
|
||||
#define MAP_ANON MAP_ANONYMOUS
|
||||
#define MAP_NORESERVE 0x10 /* don't commit memory */
|
||||
|
||||
/* mmap() error return code */
|
||||
#define MAP_FAILED ((void*)-1)
|
||||
|
@ -131,8 +131,9 @@ mmap(void* address, size_t length, int protection, int flags, int fd,
|
||||
areaProtection |= B_WRITE_AREA;
|
||||
if ((protection & PROT_EXEC) != 0)
|
||||
areaProtection |= B_EXECUTE_AREA;
|
||||
if (protection == PROT_NONE)
|
||||
areaProtection = B_OVERCOMMITTING_AREA;
|
||||
|
||||
if ((flags & MAP_NORESERVE) != 0)
|
||||
areaProtection |= B_OVERCOMMITTING_AREA;
|
||||
|
||||
// create a name for this area based on calling image
|
||||
void* addr = __builtin_return_address(0);
|
||||
|
Loading…
Reference in New Issue
Block a user