[haiku-commits] Change in haiku[master]: mmap: Use MAP_NORESERVE to request overcommit, not PROT_NONE.

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 8 May 2020 21:19:26 +0000

From Michael Lotz <mmlr@xxxxxxxx>:

Michael Lotz has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/2611 ;)


Change subject: mmap: Use MAP_NORESERVE to request overcommit, not PROT_NONE.
......................................................................

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
accessibe, 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.
---
M headers/posix/sys/mman.h
M src/system/libroot/posix/sys/mman.cpp
2 files changed, 4 insertions(+), 2 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/11/2611/1

diff --git a/headers/posix/sys/mman.h b/headers/posix/sys/mman.h
index a69991a..40c49c7 100644
--- a/headers/posix/sys/mman.h
+++ b/headers/posix/sys/mman.h
@@ -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)
diff --git a/src/system/libroot/posix/sys/mman.cpp 
b/src/system/libroot/posix/sys/mman.cpp
index 8de57a3..3944538 100644
--- a/src/system/libroot/posix/sys/mman.cpp
+++ b/src/system/libroot/posix/sys/mman.cpp
@@ -131,8 +131,9 @@
                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);

--
To view, visit https://review.haiku-os.org/c/haiku/+/2611
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: Id213d2245c5e23103e8e0857f7902e0cd8a2c65d
Gerrit-Change-Number: 2611
Gerrit-PatchSet: 1
Gerrit-Owner: Michael Lotz <mmlr@xxxxxxxx>
Gerrit-MessageType: newchange

Other related posts:

  • » [haiku-commits] Change in haiku[master]: mmap: Use MAP_NORESERVE to request overcommit, not PROT_NONE. - Gerrit