guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 02/04: Speed up load-thunk-from-memory for page alignmen


From: Andy Wingo
Subject: [Guile-commits] 02/04: Speed up load-thunk-from-memory for page alignment
Date: Sun, 8 Jan 2017 22:50:31 +0000 (UTC)

wingo pushed a commit to branch master
in repository guile.

commit c391ab8c9085226d0dd51424d427fa48c3e26881
Author: Andy Wingo <address@hidden>
Date:   Sun Jan 8 23:39:42 2017 +0100

    Speed up load-thunk-from-memory for page alignment
    
    * libguile/loader.c (page_size): New static var.
      (alloc_aligned): Enable mmap path that was never used in the
      past (!).  Thanks to Matt Wette for the bug report!
      (load_thunk_from_memory): Use page_size instead of 4096.
      (scm_bootstrap_loader): Init page_size.
---
 libguile/loader.c |   21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/libguile/loader.c b/libguile/loader.c
index 97effb3..191e4c1 100644
--- a/libguile/loader.c
+++ b/libguile/loader.c
@@ -79,6 +79,9 @@
 #define ELFDATA ELFDATA2LSB
 #endif
 
+/* The page size.  */
+static size_t page_size;
+
 static void register_elf (char *data, size_t len, char *frame_maps);
 
 enum bytecode_kind
@@ -192,12 +195,13 @@ alloc_aligned (size_t len, unsigned alignment)
       /* FIXME: Assert that we actually have an 8-byte-aligned malloc.  */
       ret = malloc (len);
     }
-#if defined(HAVE_SYS_MMAN_H) && defined(MMAP_ANONYMOUS)
-  else if (alignment == SCM_PAGE_SIZE)
+#if defined(HAVE_SYS_MMAN_H) && defined(HAVE_MAP_ANONYMOUS)
+  else if (alignment == page_size)
     {
-      ret = mmap (NULL, len, PROT_READ | PROT_WRITE, -1, 0);
+      ret = mmap (NULL, len, PROT_READ | PROT_WRITE,
+                  MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
       if (ret == MAP_FAILED)
-        SCM_SYSERROR;
+        scm_syserror ("load-thunk-from-memory");
     }
 #endif
   else
@@ -429,7 +433,7 @@ load_thunk_from_memory (char *data, size_t len, int 
is_read_only)
             continue;
           if (ph[i].p_flags == PF_R)
             continue;
-          if (ph[i].p_align != 4096)
+          if (ph[i].p_align != page_size)
             continue;
 
           if (mprotect (data + ph[i].p_vaddr,
@@ -464,8 +468,6 @@ load_thunk_from_memory (char *data, size_t len, int 
is_read_only)
 }
 #undef FUNC_NAME
 
-#define SCM_PAGE_SIZE 4096
-
 static char*
 map_file_contents (int fd, size_t len, int *is_read_only)
 #define FUNC_NAME "load-thunk-from-file"
@@ -794,6 +796,11 @@ scm_find_slot_map_unlocked (const scm_t_uint32 *ip)
 void
 scm_bootstrap_loader (void)
 {
+  page_size = getpagesize ();
+  /* page_size should be a power of two.  */
+  if (page_size & (page_size - 1))
+    abort ();
+
   scm_c_register_extension ("libguile-" SCM_EFFECTIVE_VERSION,
                             "scm_init_loader",
                             (scm_t_extension_init_func)scm_init_loader, NULL);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]