浏览代码

- support for pre-faulting the shm mem. pages (memset(0))

Andrei Pelinescu-Onciul 18 年之前
父节点
当前提交
7c855aa056
共有 4 个文件被更改,包括 7 次插入5 次删除
  1. 2 2
      mem/mem.c
  2. 1 1
      mem/mem.h
  3. 3 1
      mem/shm_mem.c
  4. 1 1
      mem/shm_mem.h

+ 2 - 2
mem/mem.c

@@ -94,10 +94,10 @@ int init_pkg_mallocs()
 
 
 
-int init_shm_mallocs()
+int init_shm_mallocs(int force_alloc)
 {
 #ifdef SHM_MEM
-	if (shm_mem_init()<0) {
+	if (shm_mem_init(force_alloc)<0) {
 		LOG(L_CRIT, "could not initialize shared memory pool, exiting...\n");
 		 fprintf(stderr, "Too much shared memory demanded: %ld\n",
 			shm_mem_size );

+ 1 - 1
mem/mem.h

@@ -150,6 +150,6 @@
 #endif
 
 int init_pkg_mallocs();
-int init_shm_mallocs();
+int init_shm_mallocs(int force_alloc);
 
 #endif

+ 3 - 1
mem/shm_mem.c

@@ -213,12 +213,14 @@ int shm_mem_init_mallocs(void* mempool, unsigned long pool_size)
 }
 
 
-int shm_mem_init()
+int shm_mem_init(int force_alloc)
 {
 	int ret;
 	
 	ret=shm_getmem();
 	if (ret<0) return ret;
+	if (force_alloc)
+		memset(shm_mempool, 0, shm_mem_size);
 	return shm_mem_init_mallocs(shm_mempool, shm_mem_size);
 }
 

+ 1 - 1
mem/shm_mem.h

@@ -117,7 +117,7 @@
 	extern gen_lock_t* mem_lock;
 
 
-int shm_mem_init(); /* calls shm_getmem & shm_mem_init_mallocs */
+int shm_mem_init(int); /* calls shm_getmem & shm_mem_init_mallocs */
 int shm_getmem();   /* allocates the memory (mmap or sysv shmap) */
 int shm_mem_init_mallocs(void* mempool, unsigned long size); /* initialize
 																the mallocs