Browse Source

align raw block size to page size when mmap is used

Ioannis Koutras 12 years ago
parent
commit
2899d13ab7
3 changed files with 17 additions and 0 deletions
  1. 4 0
      CMakeLists.txt
  2. 2 0
      dmm_config.h.in
  3. 11 0
      src/raw_block.c

+ 4 - 0
CMakeLists.txt

@@ -17,6 +17,10 @@ if(CMAKE_COMPILER_IS_GNUCC AND LINUXTEST)
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -Wno-long-long -Wconversion -Wstrict-prototypes")  
 endif(CMAKE_COMPILER_IS_GNUCC AND LINUXTEST)
 
+if(WITH_SYSTEM_CALLS STREQUAL "mmap")
+  set(PAGESIZE_ALIGN ON)
+endif(WITH_SYSTEM_CALLS STREQUAL "mmap")
+
 configure_file (
 	"${PROJECT_SOURCE_DIR}/dmm_config.h.in"
 	"${PROJECT_BINARY_DIR}/dmm_config.h"

+ 2 - 0
dmm_config.h.in

@@ -65,5 +65,7 @@
 
 #cmakedefine WITH_REALLOC
 
+#cmakedefine PAGESIZE_ALIGN
+
 #endif /* DMM_CONFIG_H */
 

+ 11 - 0
src/raw_block.c

@@ -19,6 +19,10 @@
 
 #include <inttypes.h>
 
+#ifdef PAGESIZE_ALIGN
+#include <unistd.h> /* for pagesize */
+#endif /* PAGESIZE_ALIGN */
+
 #include "request_memory.h"
 #ifdef FL_RB_ONLY
 #include "dmmlib/freelist/freelist_rb.h"
@@ -39,6 +43,13 @@ raw_block_header_t *create_raw_block(size_t raw_block_size, rb_type type) {
     size_t remaining_cells;
 #endif /* BITMAP_RB_ONLY */
 
+    // In case mmap() function is used, align the requested size to multiple of
+    // pagesizes
+#ifdef PAGESIZE_ALIGN
+    size_t pagesize = (size_t) sysconf(_SC_PAGESIZE);
+    raw_block_size = pagesize * ((raw_block_size + pagesize - 1) / pagesize);
+#endif /* PAGESIZE_ALIGN */
+
     ptr = (raw_block_header_t *)request_memory(raw_block_size);
 
     if(ptr == NULL) {