Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Cache the size of a memory page for the current system.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 13 Mar 2014 22:38:37 +0000 (23:38 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Mon, 17 Mar 2014 09:41:04 +0000 (10:41 +0100)
include/xbt/misc.h
src/mc/mc_memory.c
src/xbt/mmalloc/mm_diff.c
src/xbt/mmalloc/mm_module.c
src/xbt/mmalloc/mmorecore.c
src/xbt/xbt_main.c
teshsuite/xbt/mmalloc_test.c

index 43fb347..14e48b0 100644 (file)
 
 SG_BEGIN_DECL()
 
+/** Cache the size of a memory page for the current system. */
+XBT_PUBLIC_DATA(int) xbt_pagesize;
+
 XBT_PUBLIC(const char *) xbt_procname(void);
 
 #define XBT_BACKTRACE_SIZE 10   /* FIXME: better place? Do document */
index aa38112..2253daf 100644 (file)
@@ -30,7 +30,7 @@ void MC_memory_init()
   raw_heap = NULL;
 #else
   /* Create the second region a page after the first one ends + safety gap */
-  raw_heap = xbt_mheap_new(-1, (char*)(std_heap) + STD_HEAP_SIZE + getpagesize());
+  raw_heap = xbt_mheap_new(-1, (char*)(std_heap) + STD_HEAP_SIZE + xbt_pagesize);
   xbt_assert(raw_heap != NULL);
 #endif
 }
index 2762185..39cd21c 100644 (file)
@@ -316,7 +316,7 @@ int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1,
 
   heaplimit = ((struct mdesc *)heap1)->heaplimit;
 
-  s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - getpagesize();
+  s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - xbt_pagesize;
 
   heapbase1 = (char *)heap1 + BLOCKSIZE;
   heapbase2 = (char *)heap2 + BLOCKSIZE;
@@ -1372,7 +1372,7 @@ int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2){
   /* Heap information */
   heaplimit = ((struct mdesc *)heap1)->heaplimit;
 
-  s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - getpagesize();
+  s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - xbt_pagesize;
 
   heapbase1 = (char *)heap1 + BLOCKSIZE;
   heapbase2 = (char *)heap2 + BLOCKSIZE;
index 7cfde64..08f9de2 100644 (file)
@@ -323,7 +323,7 @@ void *mmalloc_preinit(void)
 {
   int res;
   if (__mmalloc_default_mdp == NULL) {
-    unsigned long mask = ~((unsigned long)getpagesize() - 1);
+    unsigned long mask = ~((unsigned long)xbt_pagesize - 1);
     void *addr = (void*)(((unsigned long)sbrk(0) + HEAP_OFFSET) & mask);
     __mmalloc_default_mdp = xbt_mheap_new(-1, addr);
     /* Fixme? only the default mdp in protected against forks */
index 5ad7cd3..2182cc4 100644 (file)
 
 #include "mmprivate.h"
 
-/* Cache the pagesize for the current host machine.  Note that if the host
-   does not readily provide a getpagesize() function, we need to emulate it
-   elsewhere, not clutter up this file with lots of kluges to try to figure
-   it out. */
-
-static size_t pagesize;
-
-#define PAGE_ALIGN(addr) (void*) (((long)(addr) + pagesize - 1) & \
-                                  ~(pagesize - 1))
+#define PAGE_ALIGN(addr) (void*) (((long)(addr) + xbt_pagesize - 1) &   \
+                                  ~((long)xbt_pagesize - 1))
 
 /* Return MAP_PRIVATE if MDP represents /dev/zero.  Otherwise, return
    MAP_SHARED.  */
@@ -65,8 +58,6 @@ void *mmorecore(struct mdesc *mdp, ssize_t size)
   char buf = 0;                 /* Single byte to write to extend mapped file */
 
 //  fprintf(stderr,"increase %p by %u\n",mdp,size);
-  if (pagesize == 0)
-    pagesize = getpagesize();
 
   if (size == 0) {
     /* Just return the current "break" value. */
index 26e8dd1..30c1a84 100644 (file)
@@ -9,7 +9,7 @@
 #include "xbt/misc.h"
 #include "simgrid_config.h"     /* _XBT_WIN32 */
 #include "internal_config.h"    /* MMALLOC_WANT_OVERRIDE_LEGACY */
-
+#include "portable.h"
 #include "xbt/sysdep.h"
 #include "xbt/log.h"
 #include "xbt/dynar.h"
@@ -35,6 +35,8 @@ xbt_dynar_t xbt_cmdline = NULL; /* all we got in argv */
 int xbt_initialized = 0;
 int _sg_do_clean_atexit = 1;
 
+int xbt_pagesize;
+
 /* Declare xbt_preinit and xbt_postexit as constructor/destructor of the library.
  * This is crude and rather compiler-specific, unfortunately.
  */
@@ -84,6 +86,8 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
 static void xbt_preinit(void) {
   unsigned int seed = 2147483647;
 
+  xbt_pagesize = sysconf(_SC_PAGESIZE);
+
 #ifdef MMALLOC_WANT_OVERRIDE_LEGACY
   mmalloc_preinit();
 #endif
index a09704d..b9a074c 100644 (file)
@@ -27,7 +27,7 @@ int main(int argc, char**argv)
   xbt_init(&argc,argv);
 
   XBT_INFO("Allocating a new heap");
-  unsigned long mask = ~((unsigned long)getpagesize() - 1);
+  unsigned long mask = ~((unsigned long)xbt_pagesize - 1);
   void *addr = (void*)(((unsigned long)sbrk(0) + BUFFSIZE) & mask);
   heapA = xbt_mheap_new(-1, addr);
   if (heapA == NULL) {