fix yapor memory allocation

This commit is contained in:
Ricardo Rocha 2011-06-02 17:01:00 +01:00
parent 333474f3c5
commit d601ba9caf
11 changed files with 140 additions and 310 deletions

View File

@ -34,8 +34,11 @@ static char SccsId[] = "%W% %G%";
#include "tracer.h" #include "tracer.h"
#endif #endif
#ifdef YAPOR #ifdef YAPOR
#ifdef YAPOR_COW
#include <signal.h>
#endif /* YAPOR_COW */
#include "or.macros.h" #include "or.macros.h"
#endif /* YAPOR */ #endif /* YAPOR */
#if defined(YAPOR) || defined(TABLING) #if defined(YAPOR) || defined(TABLING)
#if HAVE_SYS_TYPES_H #if HAVE_SYS_TYPES_H
#include <sys/types.h> #include <sys/types.h>
@ -1067,6 +1070,7 @@ void Yap_init_yapor_workers(void) {
return; return;
#endif /* YAPOR_THREADS */ #endif /* YAPOR_THREADS */
#ifdef YAPOR_COW #ifdef YAPOR_COW
GLOBAL_master_worker = getpid();
if (GLOBAL_number_workers > 1) { if (GLOBAL_number_workers > 1) {
int son; int son;
son = fork(); son = fork();
@ -1075,8 +1079,6 @@ void Yap_init_yapor_workers(void) {
if (son > 0) { if (son > 0) {
/* I am the father, I must stay here and wait for my children to all die */ /* I am the father, I must stay here and wait for my children to all die */
struct sigaction sigact; struct sigaction sigact;
GLOBAL_master_worker = getpid();
sigact.sa_handler = SIG_DFL; sigact.sa_handler = SIG_DFL;
sigemptyset(&sigact.sa_mask); sigemptyset(&sigact.sa_mask);
sigact.sa_flags = SA_RESTART; sigact.sa_flags = SA_RESTART;
@ -1095,9 +1097,9 @@ void Yap_init_yapor_workers(void) {
if (son == 0) { if (son == 0) {
/* new worker */ /* new worker */
worker_id = proc; worker_id = proc;
Yap_remap_optyap_memory(); Yap_remap_yapor_memory();
LOCAL = REMOTE(worker_id); LOCAL = REMOTE(worker_id);
memcpy(REMOTE(worker_id),REMOTE(0),sizeof(struct worker_local)); memcpy(REMOTE(worker_id), REMOTE(0), sizeof(struct worker_local));
InitWorker(worker_id); InitWorker(worker_id);
break; break;
} else } else
@ -1357,8 +1359,8 @@ Yap_exit (int value)
{ {
CACHE_REGS CACHE_REGS
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) #if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
Yap_unmap_optyap_memory(); Yap_unmap_yapor_memory();
#endif #endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */
if (! (LOCAL_PrologMode & BootMode) ) { if (! (LOCAL_PrologMode & BootMode) ) {
#ifdef LOW_PROF #ifdef LOW_PROF

View File

@ -1275,9 +1275,6 @@ typedef struct scratch_block_struct {
#include "opt.macros.h" #include "opt.macros.h"
#endif /* YAPOR || TABLING */ #endif /* YAPOR || TABLING */
#ifdef YAPOR_SBA
#include "or.sba_unify.h"
#endif /* YAPOR_SBA */
/************************************************************************************************* /*************************************************************************************************
@ -1316,6 +1313,7 @@ extern struct worker_local Yap_local;
#ifdef YAPOR_SBA #ifdef YAPOR_SBA
#include "or.sba_amiops.h" #include "or.sba_amiops.h"
#include "or.sba_unify.h"
#else #else
#include "amiops.h" #include "amiops.h"
#endif /* YAPOR_SBA */ #endif /* YAPOR_SBA */

View File

@ -17,9 +17,9 @@
** General Configuration Parameters ** ** General Configuration Parameters **
************************************************************************/ ************************************************************************/
/**************************************************************** /******************************************************************************************
** use shared pages memory alloc scheme ? (optional) ** ** use shared pages memory alloc scheme for OPTYap data structures? (optional) **
****************************************************************/ ******************************************************************************************/
/* #define USE_PAGES_MALLOC 1 */ /* #define USE_PAGES_MALLOC 1 */
@ -92,7 +92,7 @@
** memory mapping scheme (mandatory, define one) ** ** memory mapping scheme (mandatory, define one) **
************************************************************/ ************************************************************/
#define MMAP_MEMORY_MAPPING_SCHEME 1 #define MMAP_MEMORY_MAPPING_SCHEME 1
/* #define SHM_MEMORY_MAPPING_SCHEME 1 */ /* #define SHM_MEMORY_MAPPING_SCHEME 1 */
/************************************************* /*************************************************
** enable error checking ? (optional) ** ** enable error checking ? (optional) **

View File

@ -71,8 +71,8 @@ void Yap_init_global_optyap_data(int max_table_size, int n_workers, int sch_loop
#endif /* LIMIT_TABLING */ #endif /* LIMIT_TABLING */
INIT_PAGES(GLOBAL_pages_void, void *); INIT_PAGES(GLOBAL_pages_void, void *);
#ifdef YAPOR #ifdef YAPOR
INIT_PAGES(GLOBAL_pages_or_fr , struct or_frame); INIT_PAGES(GLOBAL_pages_or_fr, struct or_frame);
INIT_PAGES(GLOBAL_pages_qg_sol_fr , struct query_goal_solution_frame); INIT_PAGES(GLOBAL_pages_qg_sol_fr, struct query_goal_solution_frame);
INIT_PAGES(GLOBAL_pages_qg_ans_fr, struct query_goal_answer_frame); INIT_PAGES(GLOBAL_pages_qg_ans_fr, struct query_goal_answer_frame);
#endif /* YAPOR */ #endif /* YAPOR */
#ifdef TABLING_INNER_CUTS #ifdef TABLING_INNER_CUTS

View File

@ -263,7 +263,7 @@ extern int Yap_page_size;
** USE_PAGES_MALLOC && ! LIMIT_TABLING ** ** USE_PAGES_MALLOC && ! LIMIT_TABLING **
*************************************************************************************************/ *************************************************************************************************/
#define ALLOC_PAGE(PG_HD) \ #define ALLOC_PAGE(PG_HD) \
LOCK(Pg_lock(GLOBAL_pages_void)); \ LOCK(Pg_lock(GLOBAL_pages_void)); \
if (Pg_free_pg(GLOBAL_pages_void) == NULL) { \ if (Pg_free_pg(GLOBAL_pages_void) == NULL) { \
int i, shmid; \ int i, shmid; \
pg_hd_ptr pg_hd, aux_pg_hd; \ pg_hd_ptr pg_hd, aux_pg_hd; \

View File

@ -18,18 +18,12 @@
#include "Yap.h" #include "Yap.h"
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) #if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
#include <signal.h> #include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h>
#include <string.h> #include <string.h>
#include <stdlib.h>
#include <sys/shm.h> #include <sys/shm.h>
#include <sys/mman.h> #include <sys/mman.h>
#include "Yatom.h" #include "Yatom.h"
#include "YapHeap.h"
#include "alloc.h" #include "alloc.h"
#include "heapgc.h"
#include "or.macros.h" #include "or.macros.h"
@ -38,12 +32,12 @@
** Macros & Declarations ** ** Macros & Declarations **
************************************/ ************************************/
#define KBYTES 1024 #define GLOBAL_LOCAL_STRUCTS_AREA ADJUST_SIZE_TO_PAGE(sizeof(struct global_data) + MAX_WORKERS * sizeof(struct worker_local))
#ifdef MMAP_MEMORY_MAPPING_SCHEME #ifdef MMAP_MEMORY_MAPPING_SCHEME
int fd_mapfile; int fd_mapfile;
#else /* SHM_MEMORY_MAPPING_SCHEME */ #elif SHM_MEMORY_MAPPING_SCHEME
int shm_mapid[MAX_WORKERS + 1]; int shm_mapid[MAX_WORKERS + 2];
#endif /* MEMORY_MAPPING_SCHEME */ #endif /* MEMORY_MAPPING_SCHEME */
@ -52,11 +46,10 @@ int shm_mapid[MAX_WORKERS + 1];
** Local functions declaration ** ** Local functions declaration **
******************************************/ ******************************************/
#ifdef MMAP_MEMORY_MAPPING_SCHEME #ifdef SHM_MEMORY_MAPPING_SCHEME
void open_mapfile(long TotalArea);
#else /* SHM_MEMORY_MAPPING_SCHEME */
void shm_map_memory(int id, int size, void *shmaddr); void shm_map_memory(int id, int size, void *shmaddr);
#endif /* MEMORY_MAPPING_SCHEME */ void shm_unmap_memory(int id);
#endif /* SHM_MEMORY_MAPPING_SCHEME */
@ -65,295 +58,140 @@ void shm_map_memory(int id, int size, void *shmaddr);
********************************/ ********************************/
void Yap_init_yapor_global_local_memory(void) { void Yap_init_yapor_global_local_memory(void) {
#ifdef YAPOR_COW Yap_local = (struct worker_local *)(MMAP_ADDR - GLOBAL_LOCAL_STRUCTS_AREA);
int private_fd_mapfile;
#endif /* YAPOR_COW */
long ExtraArea = ADJUST_SIZE_TO_PAGE(sizeof(struct global_data) + MAX_WORKERS * sizeof(struct worker_local));
Yap_local = (struct worker_local *)(MMAP_ADDR - ExtraArea);
Yap_global = (struct global_data *)(MMAP_ADDR - sizeof(struct global_data)); Yap_global = (struct global_data *)(MMAP_ADDR - sizeof(struct global_data));
#ifdef MMAP_MEMORY_MAPPING_SCHEME #ifdef MMAP_MEMORY_MAPPING_SCHEME
//open_mapfile(ExtraArea); { char mapfile[20];
char mapfile[20]; strcpy(mapfile,"./mapfile");
strcpy(mapfile,"./mapfile"); itos(getpid(), &mapfile[9]);
itos(getpid(), &mapfile[9]); if ((fd_mapfile = open(mapfile, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0)
if ((fd_mapfile = open(mapfile, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0) Yap_Error(FATAL_ERROR, TermNil, "open error (Yap_init_yapor_global_local_memory)");
Yap_Error(FATAL_ERROR, TermNil, "open error (open_mapfile)"); if (lseek(fd_mapfile, GLOBAL_LOCAL_STRUCTS_AREA, SEEK_SET) < 0)
if (lseek(fd_mapfile, ExtraArea, SEEK_SET) < 0) Yap_Error(FATAL_ERROR, TermNil, "lseek error (Yap_init_yapor_global_local_memory)");
Yap_Error(FATAL_ERROR, TermNil, "lseek error (open_mapfile)"); if (write(fd_mapfile, "", 1) < 0)
if (write(fd_mapfile, "", 1) < 0) Yap_Error(FATAL_ERROR, TermNil, "write error (Yap_init_yapor_global_local_memory)");
Yap_Error(FATAL_ERROR, TermNil, "write error (open_mapfile)"); if (mmap((void *) Yap_local, (size_t) GLOBAL_LOCAL_STRUCTS_AREA, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd_mapfile, 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (Yap_init_global_local_memory)");
if (mmap((void *) Yap_local, (size_t) ExtraArea, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd_mapfile, 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (Yap_init_global_local_memory)");
#else /* SHM_MEMORY_MAPPING_SCHEME */
/* most systems are limited regarding what we can allocate */
#ifdef YAPOR_COW
/* single shared segment in ACOW */
shm_map_memory(0, ExtraArea + HeapArea, (void *) MMAP_ADDR);
#else /* YAPOR_COPY || YAPOR_SBA */
/* place as segment n otherwise (0..n-1 reserved for worker areas */
shm_map_memory(n_workers, ExtraArea + HeapArea, (void *) Yap_local);
{ int i;
for (i = 0; i < n_workers; i++)
shm_map_memory(i, Yap_worker_area_size, GlobalBase + Yap_worker_area_size * i);
}
#endif
#endif /* MEMORY_MAPPING_SCHEME */
#ifdef YAPOR_COW
/* just allocate local space for stacks */
if ((private_fd_mapfile = open("/dev/zero", O_RDWR)) < 0)
Yap_Error(FATAL_ERROR, TermNil, "open error (Yap_init_optyap_memory)");
if (mmap(GlobalBase, GlobalLocalArea + TrailAuxArea, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED, private_fd_mapfile, 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (Yap_init_optyap_memory)");
close(private_fd_mapfile);
#endif /* YAPOR_COW */
#ifdef YAPOR_SBA
/* alloc space for the sparse binding array */
sba_size = Yap_worker_area_size * n_workers;
if ((binding_array = (char *)malloc(sba_size)) == NULL)
Yap_Error(FATAL_ERROR, TermNil, "malloc error (Yap_init_optyap_memory)");
if ((CELL)binding_array & MBIT) {
Yap_Error(INTERNAL_ERROR, TermNil, "binding_array start address conflicts with tag used in IDB (Yap_init_optyap_memory)");
} }
sba_offset = binding_array - GlobalBase; #elif SHM_MEMORY_MAPPING_SCHEME
sba_end = (int)binding_array + sba_size; /* place as segment MAX_WORKERS (0..MAX_WORKERS-1 reserved for worker areas) */
#endif /* YAPOR_SBA */ shm_map_memory(MAX_WORKERS, GLOBAL_LOCAL_STRUCTS_AREA, (void *) Yap_local);
#endif /* MEMORY_MAPPING_SCHEME */
return; return;
} }
void Yap_init_yapor_stacks_memory(long TrailAuxArea, long HeapArea, long GlobalLocalArea, int n_workers) { void Yap_init_yapor_stacks_memory(long TrailStackArea, long HeapStackArea, long GlobalLocalStackArea, int n_workers) {
#ifdef YAPOR_COW long StacksArea;
int private_fd_mapfile;
#if MMAP_MEMORY_MAPPING_SCHEME TrailStackArea = ADJUST_SIZE_TO_PAGE(TrailStackArea);
long TotalArea; HeapStackArea = ADJUST_SIZE_TO_PAGE(HeapStackArea);
#endif /* MMAP_MEMORY_MAPPING_SCHEME */ GlobalLocalStackArea = ADJUST_SIZE_TO_PAGE(GlobalLocalStackArea);
#else /* YAPOR_COPY || YAPOR_SBA */ Yap_worker_area_size = GlobalLocalStackArea + TrailStackArea;
long TotalArea; #if defined(YAPOR_COPY) || defined(YAPOR_SBA)
#endif StacksArea = HeapStackArea + Yap_worker_area_size * n_workers;
long ExtraArea = ADJUST_SIZE_TO_PAGE(sizeof(struct global_data) + MAX_WORKERS * sizeof(struct worker_local)); #elif defined(YAPOR_COW)
StacksArea = HeapStackArea;
#endif /* YAPOR_COPY || YAPOR_SBA || YAPOR_COW */
TrailAuxArea = ADJUST_SIZE(TrailAuxArea);
HeapArea = ADJUST_SIZE_TO_PAGE(HeapArea);
GlobalLocalArea = ADJUST_SIZE(GlobalLocalArea);
Yap_HeapBase = (ADDR) MMAP_ADDR; Yap_HeapBase = (ADDR) MMAP_ADDR;
LOCAL_GlobalBase = (ADDR) (MMAP_ADDR + HeapArea); LOCAL_GlobalBase = (ADDR) (MMAP_ADDR + HeapStackArea);
/* shared memory allocation - model dependent */
#ifdef YAPOR_COW
/* acow just needs one stack */
#ifdef MMAP_MEMORY_MAPPING_SCHEME
/* I need this for MMAP to know what it must allocate */
TotalArea = HeapArea;
#endif /* MMAP_MEMORY_MAPPING_SCHEME */
#else /* YAPOR_COPY || YAPOR_SBA */
/* the others need n stacks */
Yap_worker_area_size = ADJUST_SIZE_TO_PAGE(GlobalLocalArea + TrailAuxArea);
TotalArea = ExtraArea + HeapArea + Yap_worker_area_size * n_workers;
#endif
#ifdef MMAP_MEMORY_MAPPING_SCHEME #ifdef MMAP_MEMORY_MAPPING_SCHEME
/* map total area in a single go */ /* map stacks in a single go */
//open_mapfile(TotalArea); if (lseek(fd_mapfile, GLOBAL_LOCAL_STRUCTS_AREA + StacksArea, SEEK_SET) < 0)
if (lseek(fd_mapfile, TotalArea, SEEK_SET) < 0) Yap_Error(FATAL_ERROR, TermNil, "lseek error (Yap_init_yapor_stacks_memory)");
Yap_Error(FATAL_ERROR, TermNil, "lseek error (open_mapfile)");
if (write(fd_mapfile, "", 1) < 0) if (write(fd_mapfile, "", 1) < 0)
Yap_Error(FATAL_ERROR, TermNil, "write error (open_mapfile)"); Yap_Error(FATAL_ERROR, TermNil, "write error (Yap_init_yapor_stacks_memory)");
if (mmap((void *) Yap_HeapBase, (size_t) TotalArea, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd_mapfile, ExtraArea) == (void *) -1) if (mmap((void *) Yap_HeapBase, (size_t) StacksArea, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd_mapfile, GLOBAL_LOCAL_STRUCTS_AREA) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (Yap_init_yapor_memory)"); Yap_Error(FATAL_ERROR, TermNil, "mmap error (Yap_init_yapor_stacks_memory)");
#else /* SHM_MEMORY_MAPPING_SCHEME */ #elif SHM_MEMORY_MAPPING_SCHEME
/* most systems are limited regarding what we can allocate */ /* place heap stack segment as MAX_WORKERS+1 */
#ifdef YAPOR_COW shm_map_memory(MAX_WORKERS + 1, HeapStackArea, (void *) Yap_HeapBase);
/* single shared segment in ACOW */ #if defined(YAPOR_COPY) || defined(YAPOR_SBA)
shm_map_memory(0, ExtraArea + HeapArea, (void *) MMAP_ADDR); /* map segments for worker areas as 0..MAX_WORKERS-1 */
#else /* YAPOR_COPY || YAPOR_SBA */
/* place as segment n otherwise (0..n-1 reserved for worker areas */
shm_map_memory(n_workers, ExtraArea + HeapArea, (void *) Yap_local);
{ int i; { int i;
for (i = 0; i < n_workers; i++) for (i = 0; i < n_workers; i++)
shm_map_memory(i, Yap_worker_area_size, LOCAL_GlobalBase + Yap_worker_area_size * i); shm_map_memory(i, Yap_worker_area_size, LOCAL_GlobalBase + Yap_worker_area_size * i);
} }
#endif #endif /* YAPOR_COPY || YAPOR_SBA */
#endif /* MEMORY_MAPPING_SCHEME */ #endif /* MEMORY_MAPPING_SCHEME */
#ifdef YAPOR_COW #ifdef YAPOR_COW
/* just allocate local space for stacks */ /* just allocate local space for stacks */
if ((private_fd_mapfile = open("/dev/zero", O_RDWR)) < 0) { int private_fd_mapfile;
Yap_Error(FATAL_ERROR, TermNil, "open error (Yap_init_optyap_memory)"); if ((private_fd_mapfile = open("/dev/zero", O_RDWR)) < 0)
if (mmap(LOCAL_GlobalBase, GlobalLocalArea + TrailAuxArea, PROT_READ|PROT_WRITE, Yap_Error(FATAL_ERROR, TermNil, "open error (Yap_init_yapor_stacks_memory)");
MAP_PRIVATE|MAP_FIXED, private_fd_mapfile, 0) == (void *) -1) if (mmap(LOCAL_GlobalBase, Yap_worker_area_size, PROT_READ|PROT_WRITE,
Yap_Error(FATAL_ERROR, TermNil, "mmap error (Yap_init_optyap_memory)"); MAP_PRIVATE|MAP_FIXED, private_fd_mapfile, 0) == (void *) -1)
close(private_fd_mapfile); Yap_Error(FATAL_ERROR, TermNil, "mmap error (Yap_init_yapor_stacks_memory)");
close(private_fd_mapfile);
}
#endif /* YAPOR_COW */ #endif /* YAPOR_COW */
#ifdef YAPOR_SBA #ifdef YAPOR_SBA
/* alloc space for the sparse binding array */ /* alloc space for the sparse binding array */
sba_size = Yap_worker_area_size * n_workers; sba_size = Yap_worker_area_size * n_workers;
if ((binding_array = (char *)malloc(sba_size)) == NULL) if ((binding_array = (char *)malloc(sba_size)) == NULL)
Yap_Error(FATAL_ERROR, TermNil, "malloc error (Yap_init_optyap_memory)"); Yap_Error(FATAL_ERROR, TermNil, "malloc error (Yap_init_yapor_stacks_memory)");
if ((CELL)binding_array & MBIT) { if ((CELL)binding_array & MBIT)
Yap_Error(INTERNAL_ERROR, TermNil, "binding_array start address conflicts with tag used in IDB (Yap_init_optyap_memory)"); Yap_Error(INTERNAL_ERROR, TermNil, "binding_array start address conflicts with tag used in IDB (Yap_init_yapor_stacks_memory)");
}
sba_offset = binding_array - LOCAL_GlobalBase; sba_offset = binding_array - LOCAL_GlobalBase;
sba_end = (int)binding_array + sba_size; sba_end = (int)binding_array + sba_size;
#endif /* YAPOR_SBA */ #endif /* YAPOR_SBA */
LOCAL_TrailBase = LOCAL_GlobalBase + GlobalLocalArea; LOCAL_TrailBase = LOCAL_GlobalBase + GlobalLocalStackArea;
LOCAL_LocalBase = LOCAL_TrailBase - CellSize; LOCAL_LocalBase = LOCAL_TrailBase - CellSize;
LOCAL_TrailTop = LOCAL_TrailBase + (TrailAuxArea /2); LOCAL_TrailTop = LOCAL_TrailBase + TrailStackArea;
HeapLim = LOCAL_GlobalBase;
Yap_InitHeap(Yap_HeapBase); Yap_InitHeap(Yap_HeapBase);
//HeapMax = (CELL)(LOCAL_TrailBase + (TrailAuxArea - CellSize));
// HeapLim = LOCAL_GlobalBase;
return; return;
} }
void Yap_remap_yapor_memory(void) {
#if defined(YAPOR_COPY)
void OLD_Yap_init_optyap_memory(long TrailAuxArea, long HeapArea, long GlobalLocalArea, int n_workers) {
#ifdef YAPOR_COW
int private_fd_mapfile;
#if MMAP_MEMORY_MAPPING_SCHEME
long TotalArea;
#endif /* MMAP_MEMORY_MAPPING_SCHEME */
#else /* YAPOR_COPY || YAPOR_SBA */
long TotalArea;
#endif
long ExtraArea;
ADDR GlobalBase;
HeapArea = ADJUST_SIZE_TO_PAGE(HeapArea);
GlobalLocalArea = ADJUST_SIZE(GlobalLocalArea);
TrailAuxArea = ADJUST_SIZE(TrailAuxArea);
/* initial allocation - model independent */
ExtraArea = ADJUST_SIZE_TO_PAGE(sizeof(struct global_data) + MAX_WORKERS * sizeof(struct worker_local));
Yap_local = (struct worker_local *)(MMAP_ADDR - ExtraArea);
Yap_global = (struct global_data *)(MMAP_ADDR - sizeof(struct global_data));
Yap_HeapBase = (ADDR) MMAP_ADDR;
GlobalBase = (ADDR) (MMAP_ADDR + HeapArea);
/* shared memory allocation - model dependent */
#ifdef YAPOR_COW
/* acow just needs one stack */
#ifdef MMAP_MEMORY_MAPPING_SCHEME
/* I need this for MMAP to know what it must allocate */
TotalArea = HeapArea;
#endif /* MMAP_MEMORY_MAPPING_SCHEME */
#else /* YAPOR_COPY || YAPOR_SBA */
/* the others need n stacks */
Yap_worker_area_size = ADJUST_SIZE_TO_PAGE(GlobalLocalArea + TrailAuxArea);
TotalArea = ExtraArea + HeapArea + Yap_worker_area_size * n_workers;
#endif
#ifdef MMAP_MEMORY_MAPPING_SCHEME
/* map total area in a single go */
open_mapfile(TotalArea);
if (mmap((void *) Yap_local, (size_t) TotalArea, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd_mapfile, 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (Yap_init_optyap_memory)");
#else /* SHM_MEMORY_MAPPING_SCHEME */
/* most systems are limited regarding what we can allocate */
#ifdef YAPOR_COW
/* single shared segment in ACOW */
shm_map_memory(0, ExtraArea + HeapArea, (void *) MMAP_ADDR);
#else /* YAPOR_COPY || YAPOR_SBA */
/* place as segment n otherwise (0..n-1 reserved for worker areas */
shm_map_memory(n_workers, ExtraArea + HeapArea, (void *) Yap_local);
{ int i;
for (i = 0; i < n_workers; i++)
shm_map_memory(i, Yap_worker_area_size, GlobalBase + Yap_worker_area_size * i);
}
#endif
#endif /* MEMORY_MAPPING_SCHEME */
#ifdef YAPOR_COW
/* just allocate local space for stacks */
if ((private_fd_mapfile = open("/dev/zero", O_RDWR)) < 0)
Yap_Error(FATAL_ERROR, TermNil, "open error (Yap_init_optyap_memory)");
if (mmap(GlobalBase, GlobalLocalArea + TrailAuxArea, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED, private_fd_mapfile, 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (Yap_init_optyap_memory)");
close(private_fd_mapfile);
#endif /* YAPOR_COW */
#ifdef YAPOR_SBA
/* alloc space for the sparse binding array */
sba_size = Yap_worker_area_size * n_workers;
if ((binding_array = (char *)malloc(sba_size)) == NULL)
Yap_Error(FATAL_ERROR, TermNil, "malloc error (Yap_init_optyap_memory)");
if ((CELL)binding_array & MBIT) {
Yap_Error(INTERNAL_ERROR, TermNil, "binding_array start address conflicts with tag used in IDB (Yap_init_optyap_memory)");
}
sba_offset = binding_array - GlobalBase;
sba_end = (int)binding_array + sba_size;
#endif /* YAPOR_SBA */
Yap_InitHeap(Yap_HeapBase);
LOCAL = REMOTE(0); /* point to the first area */
LOCAL_GlobalBase = GlobalBase;
LOCAL_TrailBase = LOCAL_GlobalBase + GlobalLocalArea;
LOCAL_LocalBase = LOCAL_TrailBase - CellSize;
LOCAL_TrailTop = LOCAL_TrailBase + (TrailAuxArea /2);
//HeapMax = (CELL)(LOCAL_TrailBase + (TrailAuxArea - CellSize));
// HeapLim = LOCAL_GlobalBase;
}
void Yap_remap_optyap_memory(void) {
#ifdef YAPOR_SBA
/* setup workers so that they have different areas */
LOCAL_GlobalBase += worker_id * Yap_worker_area_size;
LOCAL_TrailBase += worker_id * Yap_worker_area_size;
LOCAL_LocalBase += worker_id * Yap_worker_area_size;
LOCAL_TrailTop += worker_id * Yap_worker_area_size;
#endif /* YAPOR_SBA */
#ifdef YAPOR_COPY
int i; int i;
void *remap_addr = LOCAL_GlobalBase; void *remap_addr = LOCAL_GlobalBase;
#ifdef MMAP_MEMORY_MAPPING_SCHEME #ifdef MMAP_MEMORY_MAPPING_SCHEME
long remap_offset = (ADDR) remap_addr - (ADDR) Yap_local; long remap_offset = (ADDR) remap_addr - (ADDR) Yap_local;
if (munmap(remap_addr, (size_t)(Yap_worker_area_size * GLOBAL_number_workers)) == -1) if (munmap(remap_addr, (size_t)(Yap_worker_area_size * GLOBAL_number_workers)) == -1)
Yap_Error(FATAL_ERROR, TermNil, "munmap error (Yap_remap_optyap_memory)"); Yap_Error(FATAL_ERROR, TermNil, "munmap error (Yap_remap_yapor_memory)");
for (i = 0; i < GLOBAL_number_workers; i++) for (i = 0; i < GLOBAL_number_workers; i++)
if (mmap(remap_addr + worker_offset(i), (size_t)Yap_worker_area_size, PROT_READ|PROT_WRITE, if (mmap(remap_addr + worker_offset(i), (size_t)Yap_worker_area_size, PROT_READ|PROT_WRITE,
MAP_SHARED|MAP_FIXED, fd_mapfile, remap_offset + i * Yap_worker_area_size) == (void *) -1) MAP_SHARED|MAP_FIXED, fd_mapfile, remap_offset + i * Yap_worker_area_size) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (Yap_remap_optyap_memory)"); Yap_Error(FATAL_ERROR, TermNil, "mmap error (Yap_remap_yapor_memory)");
#else /* SHM_MEMORY_MAPPING_SCHEME */ #else /* SHM_MEMORY_MAPPING_SCHEME */
for (i = 0; i < GLOBAL_number_workers; i++) for (i = 0; i < GLOBAL_number_workers; i++)
if (shmdt(remap_addr + Yap_worker_area_size * i) == -1) if (shmdt(remap_addr + Yap_worker_area_size * i) == -1)
Yap_Error(FATAL_ERROR, TermNil, "shmdt error (Yap_remap_optyap_memory)"); Yap_Error(FATAL_ERROR, TermNil, "shmdt error (Yap_remap_yapor_memory)");
for (i = 0; i < GLOBAL_number_workers; i++) for (i = 0; i < GLOBAL_number_workers; i++)
if(shmat(shm_mapid[i], remap_addr + worker_offset(i), 0) == (void *) -1) if(shmat(shm_mapid[i], remap_addr + worker_offset(i), 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "shmat error (Yap_remap_optyap_memory)"); Yap_Error(FATAL_ERROR, TermNil, "shmat error (Yap_remap_yapor_memory)");
#endif /* MEMORY_MAPPING_SCHEME */ #endif /* MEMORY_MAPPING_SCHEME */
#endif /* YAPOR_COPY */ #elif defined(YAPOR_SBA)
/* setup workers so that they have different areas */
LOCAL_GlobalBase += worker_id * Yap_worker_area_size;
LOCAL_TrailBase += worker_id * Yap_worker_area_size;
LOCAL_LocalBase += worker_id * Yap_worker_area_size;
LOCAL_TrailTop += worker_id * Yap_worker_area_size;
#endif /* YAPOR_COPY || YAPOR_SBA */
} }
void Yap_unmap_optyap_memory (void) { void Yap_unmap_yapor_memory (void) {
#ifdef MMAP_MEMORY_MAPPING_SCHEME
char MapFile[20];
#else /* SHM_MEMORY_MAPPING_SCHEME */
int i; int i;
#endif /* MEMORY_MAPPING_SCHEME */
int proc;
INFORMATION_MESSAGE("Worker %d exiting...", worker_id); INFORMATION_MESSAGE("Worker %d exiting...", worker_id);
for (proc = 0; proc < GLOBAL_number_workers; proc++) { for (i = 0; i < GLOBAL_number_workers; i++)
if (proc != worker_id && GLOBAL_worker_pid(proc) != 0) { if (i != worker_id && GLOBAL_worker_pid(i) != 0) {
if (kill(GLOBAL_worker_pid(proc), SIGKILL) != 0) if (kill(GLOBAL_worker_pid(i), SIGKILL) != 0)
INFORMATION_MESSAGE("Can't kill process %d", GLOBAL_worker_pid(proc)); INFORMATION_MESSAGE("Can't kill process %d", GLOBAL_worker_pid(i));
else else
INFORMATION_MESSAGE("Killing process %d", GLOBAL_worker_pid(proc)); INFORMATION_MESSAGE("Killing process %d", GLOBAL_worker_pid(i));
} }
}
#ifdef YAPOR_COW #ifdef YAPOR_COW
if (GLOBAL_number_workers > 1) { if (GLOBAL_number_workers > 1) {
if (kill(GLOBAL_master_worker, SIGINT) != 0) if (kill(GLOBAL_master_worker, SIGINT) != 0)
@ -363,30 +201,28 @@ void Yap_unmap_optyap_memory (void) {
} }
#endif /* YAPOR_COW */ #endif /* YAPOR_COW */
#ifdef MMAP_MEMORY_MAPPING_SCHEME #ifdef MMAP_MEMORY_MAPPING_SCHEME
strcpy(MapFile,"./mapfile"); { char mapfile[20];
#ifdef YAPOR_COW strcpy(mapfile,"./mapfile");
itos(GLOBAL_master_worker, &MapFile[9]); #if defined(YAPOR_COPY) || defined(YAPOR_SBA)
#else /* YAPOR_COPY || YAPOR_SBA */ itos(GLOBAL_worker_pid(0), &mapfile[9]);
itos(GLOBAL_worker_pid(0), &MapFile[9]); #elif defined(YAPOR_COW)
#endif itos(GLOBAL_master_worker, &mapfile[9]);
if (remove(MapFile) == 0) #endif /* YAPOR_COPY || YAPOR_SBA || YAPOR_COW */
INFORMATION_MESSAGE("Removing mapfile \"%s\"", MapFile); if (remove(mapfile) == 0)
else INFORMATION_MESSAGE("Removing mapfile \"%s\"", mapfile);
INFORMATION_MESSAGE("Can't remove mapfile \"%s\"", MapFile);
#else /* SHM_MEMORY_MAPPING_SCHEME */
#ifdef YAPOR_COW
i = 0;
#else /* YAPOR_COPY || YAPOR_SBA */
for (i = 0; i < GLOBAL_number_workers + 1; i++)
#endif
{
if (shmctl(shm_mapid[i], IPC_RMID, 0) == 0)
INFORMATION_MESSAGE("Removing shared memory segment %d", shm_mapid[i]);
else else
INFORMATION_MESSAGE("Can't remove shared memory segment %d", shm_mapid[i]); INFORMATION_MESSAGE("Can't remove mapfile \"%s\"", mapfile);
} }
#elif SHM_MEMORY_MAPPING_SCHEME
#if defined(YAPOR_COPY) || defined(YAPOR_SBA)
shm_unmap_memory(MAX_WORKERS);
shm_unmap_memory(MAX_WORKERS + 1);
for (i = 0; i < GLOBAL_number_workers; i++)
shm_unmap_memory(i);
#elif defined(YAPOR_COW)
shm_unmap_memory(0);
#endif /* YAPOR_COPY || YAPOR_SBA || YAPOR_COW */
#endif /* MEMORY_MAPPING_SCHEME */ #endif /* MEMORY_MAPPING_SCHEME */
return; return;
} }
@ -397,29 +233,22 @@ void Yap_unmap_optyap_memory (void) {
** Local functions ** ** Local functions **
** ------------------------- */ ** ------------------------- */
#ifdef MMAP_MEMORY_MAPPING_SCHEME #ifdef SHM_MEMORY_MAPPING_SCHEME
void open_mapfile(long TotalArea) {
char mapfile[20];
strcpy(mapfile,"./mapfile");
itos(getpid(), &mapfile[9]);
printf(" file %s \n", mapfile);
if ((fd_mapfile = open(mapfile, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0)
Yap_Error(FATAL_ERROR, TermNil, "open error (open_mapfile)");
if (lseek(fd_mapfile, TotalArea, SEEK_SET) < 0)
Yap_Error(FATAL_ERROR, TermNil, "lseek error (open_mapfile)");
if (write(fd_mapfile, "", 1) < 0)
Yap_Error(FATAL_ERROR, TermNil, "write error (open_mapfile)");
return;
}
#else /* SHM_MEMORY_MAPPING_SCHEME */
void shm_map_memory(int id, int size, void *shmaddr) { void shm_map_memory(int id, int size, void *shmaddr) {
if (size > SHMMAX)
Yap_Error(FATAL_ERROR, TermNil, "maximum size for a shm segment exceeded (shm_map_memory)");
if ((shm_mapid[id] = shmget(IPC_PRIVATE, size, SHM_R|SHM_W)) == -1) if ((shm_mapid[id] = shmget(IPC_PRIVATE, size, SHM_R|SHM_W)) == -1)
Yap_Error(FATAL_ERROR, TermNil, "shmget error (shm_map_memory)"); Yap_Error(FATAL_ERROR, TermNil, "shmget error (shm_map_memory)");
if (shmat(shm_mapid[id], shmaddr, 0) == (void *) -1) if (shmat(shm_mapid[id], shmaddr, 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "shmat error (shm_map_memory)"); Yap_Error(FATAL_ERROR, TermNil, "shmat error (shm_map_memory)");
return; return;
} }
#endif /* MMAP_MEMORY_MAPPING_SCHEME */
void shm_unmap_memory(int id) {
if (shmctl(shm_mapid[id], IPC_RMID, 0) == 0)
INFORMATION_MESSAGE("Removing shared memory segment %d", shm_mapid[id]);
else
INFORMATION_MESSAGE("Can't remove shared memory segment %d", shm_mapid[id]);
return;
}
#endif /* SHM_MEMORY_MAPPING_SCHEME */
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */ #endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */

View File

@ -27,7 +27,6 @@
#if HAVE_SYS_TIME_H #if HAVE_SYS_TIME_H
#include <sys/time.h> #include <sys/time.h>
#endif /* HAVE_SYS_TIME_H */ #endif /* HAVE_SYS_TIME_H */
#include "yapio.h"
#include "or.macros.h" #include "or.macros.h"
#endif /* YAPOR */ #endif /* YAPOR */
#ifdef TABLING #ifdef TABLING
@ -763,12 +762,12 @@ static Int p_show_statistics_or( USES_REGS1 ) {
Sfprintf(out, " Memory in use (II): %10ld bytes\n\n", aux_bytes); Sfprintf(out, " Memory in use (II): %10ld bytes\n\n", aux_bytes);
total_bytes += aux_bytes; total_bytes += aux_bytes;
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
Sfprintf(out, "Total memory in use (I+II+III): %10ld bytes (%ld pages in use)\n", Sfprintf(out, "Total memory in use (I+II): %10ld bytes (%ld pages in use)\n",
total_bytes, Pg_str_in_use(GLOBAL_pages_void)); total_bytes, Pg_str_in_use(GLOBAL_pages_void));
Sfprintf(out, "Total memory allocated: %10ld bytes (%ld pages in total)\n", Sfprintf(out, "Total memory allocated: %10ld bytes (%ld pages in total)\n",
Pg_pg_alloc(GLOBAL_pages_void) * Yap_page_size, Pg_pg_alloc(GLOBAL_pages_void)); Pg_pg_alloc(GLOBAL_pages_void) * Yap_page_size, Pg_pg_alloc(GLOBAL_pages_void));
#else #else
Sfprintf(out, "Total memory in use (I+II+III): %10ld bytes\n", total_bytes); Sfprintf(out, "Total memory in use (I+II): %10ld bytes\n", total_bytes);
#endif /* USE_PAGES_MALLOC */ #endif /* USE_PAGES_MALLOC */
return (TRUE); return (TRUE);
} }
@ -1303,6 +1302,7 @@ static inline long show_statistics_global_trie_nodes(IOSTREAM *out) {
static inline long show_statistics_global_trie_hashes(IOSTREAM *out) { static inline long show_statistics_global_trie_hashes(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
#ifdef DEBUG_TABLING #ifdef DEBUG_TABLING
/* suport not yet implemented :(
pg_hd_ptr pg_hd; pg_hd_ptr pg_hd;
gt_hash_ptr aux_ptr; gt_hash_ptr aux_ptr;
long cont = 0; long cont = 0;
@ -1317,6 +1317,7 @@ static inline long show_statistics_global_trie_hashes(IOSTREAM *out) {
pg_hd = PgHd_next(pg_hd); pg_hd = PgHd_next(pg_hd);
} }
TABLING_ERROR_CHECKING(statistics_global_trie_hashes, Pg_str_free(GLOBAL_pages_gt_hash) != cont); TABLING_ERROR_CHECKING(statistics_global_trie_hashes, Pg_str_free(GLOBAL_pages_gt_hash) != cont);
*/
#endif /* DEBUG_TABLING */ #endif /* DEBUG_TABLING */
Sfprintf(out, " Global trie hashes: %10ld bytes (%ld pages and %ld structs in use)\n", Sfprintf(out, " Global trie hashes: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_gt_hash) * sizeof(struct global_trie_hash), Pg_pg_alloc(GLOBAL_pages_gt_hash), Pg_str_in_use(GLOBAL_pages_gt_hash)); Pg_str_in_use(GLOBAL_pages_gt_hash) * sizeof(struct global_trie_hash), Pg_pg_alloc(GLOBAL_pages_gt_hash), Pg_str_in_use(GLOBAL_pages_gt_hash));

View File

@ -24,8 +24,8 @@
#ifdef YAPOR #ifdef YAPOR
void Yap_init_yapor_global_local_memory(void); void Yap_init_yapor_global_local_memory(void);
void Yap_init_yapor_stacks_memory(long, long, long, int); void Yap_init_yapor_stacks_memory(long, long, long, int);
void Yap_unmap_optyap_memory(void); void Yap_unmap_yapor_memory(void);
void Yap_remap_optyap_memory(void); void Yap_remap_yapor_memory(void);
#endif /* YAPOR */ #endif /* YAPOR */

View File

@ -57,6 +57,7 @@ cptr_to_offset_with_null(choiceptr node)
** Struct page_header ** ** Struct page_header **
*********************************/ *********************************/
#ifdef USE_PAGES_MALLOC
typedef struct page_header { typedef struct page_header {
volatile int structs_in_use; volatile int structs_in_use;
void *first_free_struct; void *first_free_struct;
@ -68,6 +69,7 @@ typedef struct page_header {
#define PgHd_free_str(X) ((X)->first_free_struct) #define PgHd_free_str(X) ((X)->first_free_struct)
#define PgHd_previous(X) ((X)->previous) #define PgHd_previous(X) ((X)->previous)
#define PgHd_next(X) ((X)->next) #define PgHd_next(X) ((X)->next)
#endif /* USE_PAGES_MALLOC */

View File

@ -66,7 +66,6 @@ Dereferencing macros
if (0 == (D)) break; \ if (0 == (D)) break; \
if (IsPairTerm(D)) goto LabelList; \ if (IsPairTerm(D)) goto LabelList; \
} while (TRUE); } while (TRUE);
#endif /* UNIQUE_TAG_FOR_PAIRS */ #endif /* UNIQUE_TAG_FOR_PAIRS */
EXTERN inline Term Deref(Term a) EXTERN inline Term Deref(Term a)
@ -108,6 +107,7 @@ A contains the address of the variable that is to be trailed
#define RESET_VARIABLE(V) (*(CELL *)(V) = 0) #define RESET_VARIABLE(V) (*(CELL *)(V) = 0)
#if SIZEOF_DOUBLE == 2*SIZEOF_LONG_INT
inline EXTERN void inline EXTERN void
AlignGlobalForDouble(void) AlignGlobalForDouble(void)
{ {
@ -118,6 +118,7 @@ AlignGlobalForDouble(void)
H++; H++;
} }
} }
#endif /* SIZEOF_DOUBLE == 2*SIZEOF_LONG_INT */
#ifdef YAPOR #ifdef YAPOR

View File

@ -37,9 +37,6 @@ Int bind_variable(Term t0, Term t1)
} }
EXTERN inline EXTERN inline
/*
Int unify(Term t0, Term t1)
*/
Int unify(Term t0, Term t1) Int unify(Term t0, Term t1)
{ {
tr_fr_ptr TR0 = TR; tr_fr_ptr TR0 = TR;