guile-devel
[Top][All Lists]
Advanced

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

Page size is not a compile-time constant


From: Mark H Weaver
Subject: Page size is not a compile-time constant
Date: Thu, 14 Nov 2013 02:29:09 -0500

Hello all,

Currently, the master branch incorporates the assumption that memory
pages are 4KB.  Both module/system/vm/linker.scm and libguile/opcodes.c
hardcode this value into the source code (search for "4096" in those
files).

This didn't work on my system, where the page size is 16KB.  For now, I
got it working with the patch below, but obviously it's not a proper
fix.

Of course, it wouldn't be hard to change the page size to an arbitrary
compile-time constant, but unfortunately that won't be sufficient.  In
the general case, we cannot know the page size until runtime.

Several architectures support multiple page sizes, and Linux allows the
page size to be configured as part of the kernel configuration.  For
example, on MIPS, Linux allows the page size to be configured as 4KB,
16KB, or 64KB, and there are significant performance advantages to using
a page size greater than 4KB.  If you want to see a more complete list
of supported page sizes of various architectures, run the following
command in a Linux source tree:

  grep CONFIG_PAGE_SIZE arch/*/include/asm/page.h

On POSIX systems, the recommended way to find the page size is this:

  #include <unistd.h>
  long page_size = sysconf(_SC_PAGESIZE);

A cursory glance at the new RTL code makes me concerned that the design
of the RTL linker and loader might assume that the page size is a
compile-time constant, and that the page size is "baked in" to the
generated .go files.  Is this true?  If so, I hope it's not too hard to
change, because unfortunately we cannot make this assumption in Guile.

    Regards,
      Mark


diff --git a/libguile/objcodes.c b/libguile/objcodes.c
index 0515a7c..e1fede3 100644
--- a/libguile/objcodes.c
+++ b/libguile/objcodes.c
@@ -77,6 +77,8 @@
 #define ELFDATA ELFDATA2LSB
 #endif
 
+#define SCM_PAGE_SIZE 16384
+
 static void register_elf (char *data, size_t len);
 
 enum bytecode_kind
@@ -413,7 +415,7 @@ load_thunk_from_memory (char *data, size_t len, int 
is_read_only)
         {
           if (ph[i].p_flags == PF_R)
             continue;
-          if (ph[i].p_align != 4096)
+          if (ph[i].p_align != SCM_PAGE_SIZE)
             continue;
 
           if (mprotect (data + ph[i].p_vaddr,
@@ -448,8 +450,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"
diff --git a/module/system/vm/linker.scm b/module/system/vm/linker.scm
index 9a51778..86c3b2a 100644
--- a/module/system/vm/linker.scm
+++ b/module/system/vm/linker.scm
@@ -316,7 +316,7 @@ segment, the order of the linker objects is preserved."
                     #:addralign (elf-section-addralign sec)
                     #:entsize (elf-section-entsize sec)))
 
-(define *page-size* 4096)
+(define *page-size* 16384)
 
 (define (add-symbols symbols offset symtab)
   "Add @var{symbols} to the symbol table @var{symtab}, relocating them

reply via email to

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