]> git.eshelyaron.com Git - emacs.git/commitdiff
Keep the DS_DISCARDABLE address space reserved
authorDaniel Colascione <dancol@dancol.org>
Wed, 14 Feb 2018 19:25:46 +0000 (11:25 -0800)
committerDaniel Colascione <dancol@dancol.org>
Wed, 14 Feb 2018 19:25:46 +0000 (11:25 -0800)
configure.ac
src/pdumper.c

index 2b5f050cea24aa308460174a8d1407e4ce506c42..a3595a6426ed1f75f7fca84885cdfda80dbf505c 100644 (file)
@@ -4071,6 +4071,9 @@ dnl No need to check for posix_memalign if aligned_alloc works.
 AC_CHECK_FUNCS([aligned_alloc posix_memalign], [break])
 AC_CHECK_DECLS([aligned_alloc], [], [], [[#include <stdlib.h>]])
 
+# Dump loading
+AC_CHECK_FUNCS([posix_madvise])
+
 dnl Cannot use AC_CHECK_FUNCS
 AC_CACHE_CHECK([for __builtin_frame_address],
   [emacs_cv_func___builtin_frame_address],
index 6007f4a23d45c8b2307440357366e6426e3361dc..a36ec3abecb031a3b12d184652a6f1b12726b08f 100644 (file)
@@ -4251,6 +4251,40 @@ struct dump_memory_map {
   void *private;
 };
 
+/* Mark the pages as unneeded, potentially zeroing them, without
+   releasing the address space reservation.  */
+static void
+dump_discard_mem (void *mem, size_t size)
+{
+  if (VM_SUPPORTED == VM_MS_WINDOWS)
+    {
+#if VM_SUPPORTED == VM_MS_WINDOWS
+      /* Discard COWed pages.  */
+      (void) VirtualFree (mem, size, MEM_DECOMMIT);
+      /* Release the commit charge for the mapping.  */
+      (void) VirtualProtect (mem, size, PAGE_NOACCESS, NULL);
+#endif
+    }
+  else if (VM_SUPPORTED == VM_POSIX)
+    {
+#ifdef HAVE_POSIX_MADVISE
+      /* Discard COWed pages.  */
+      (void) posix_madvise (mem, size, POSIX_MADV_DONTNEED);
+#endif
+      /* Release the commit charge for the mapping.  */
+      (void) mprotect (mem, size, PROT_NONE);
+    }
+  else
+    /* Do nothing */;
+}
+
+static void
+dump_mmap_discard_contents (struct dump_memory_map *map)
+{
+  if (map->mapping)
+    dump_discard_mem (map->mapping, map->spec.size);
+}
+
 static void
 dump_mmap_reset (struct dump_memory_map *map)
 {
@@ -5027,7 +5061,7 @@ pdumper_load (const char *dump_filename)
   dump_do_all_dump_relocations (header, dump_base);
   dump_do_all_emacs_relocations (header, dump_base);
 
-  dump_mmap_release (&sections[DS_DISCARDABLE]);
+  dump_mmap_discard_contents (&sections[DS_DISCARDABLE]);
   for (int i = 0; i < ARRAYELTS (sections); ++i)
     dump_mmap_reset (&sections[i]);