Changeset: a79576945b18 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/a79576945b18
Modified Files:
gdk/gdk_posix.c
Branch: default
Log Message:
Use mmap's MAP_FIXED_NOREPLACE option if available.
diffs (71 lines):
diff --git a/gdk/gdk_posix.c b/gdk/gdk_posix.c
--- a/gdk/gdk_posix.c
+++ b/gdk/gdk_posix.c
@@ -370,6 +370,9 @@ MT_mremap(const char *path, int mode, vo
int flags = mode & MMAP_COPY ? MAP_PRIVATE : MAP_SHARED;
int prot = PROT_WRITE | PROT_READ;
+#ifdef MAP_FIXED_NOREPLACE
+ flags |= MAP_FIXED_NOREPLACE;
+#endif
/* round up to multiple of page size */
*new_size = (*new_size + GDK_mmap_pagesize - 1) & ~(GDK_mmap_pagesize -
1);
@@ -430,9 +433,11 @@ MT_mremap(const char *path, int mode, vo
/* try to map extension at end of current map */
p = mmap((char *) old_address + old_size, *new_size - old_size,
prot, flags, fd, old_size);
- /* if it failed, there is no point trying a full mmap:
- * that too won't fit */
- if (p != MAP_FAILED) {
+ /* if it failed and MAP_FIXED_NOREPLACE is not defined,
+ * there is no point trying a full mmap: that too won't
+ * fit either (if MAP_FIXED_NOREPLACE, only relevant
+ * failure is with EEXIST) */
+ if (p != MAP_FAILED || errno == EEXIST) {
if (p == (char *) old_address + old_size) {
/* we got the requested address, make
* sure we return the correct (old)
@@ -442,7 +447,8 @@ MT_mremap(const char *path, int mode, vo
} else {
/* we got some other address: discard
* it and make full mmap */
- if (munmap(p, *new_size - old_size) < 0)
+ if (p != MAP_FAILED &&
+ munmap(p, *new_size - old_size) < 0)
GDKsyserror("munmap");
#ifdef NO_MMAP_ALIASING
if (msync(old_address, old_size, MS_SYNC) < 0)
@@ -450,6 +456,9 @@ MT_mremap(const char *path, int mode, vo
#endif
/* first create full mmap, then, if
* successful, remove old mmap */
+#ifdef MAP_FIXED_NOREPLACE
+ flags &= ~MAP_FIXED_NOREPLACE;
+#endif
p = mmap(NULL, *new_size, prot, flags, fd, 0);
if (p != MAP_FAILED) {
VALGRIND_MALLOCLIKE_BLOCK(p, *new_size,
0, 1);
@@ -479,7 +488,7 @@ MT_mremap(const char *path, int mode, vo
prot, flags, fd, 0);
/* no point trying a full map if this didn't work:
* there isn't enough space */
- if (p != MAP_FAILED) {
+ if (p != MAP_FAILED || errno == EEXIST) {
if (p == (char *) old_address + old_size) {
/* we got the requested address, make
* sure we return the correct (old)
@@ -489,8 +498,12 @@ MT_mremap(const char *path, int mode, vo
} else {
/* we got some other address: discard
* it and make full mmap */
- if (munmap(p, *new_size - old_size) < 0)
+ if (p != MAP_FAILED &&
+ munmap(p, *new_size - old_size) < 0)
GDKsyserror("munmap");
+#ifdef MAP_FIXED_NOREPLACE
+ flags &= ~MAP_FIXED_NOREPLACE;
+#endif
#ifdef HAVE_MREMAP
/* first get an area large enough for
* *new_size */
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]