if we have many embedded calls to nb_queue, make sure we don't allocate a lot of memory for each one.
This commit is contained in:
parent
51875c627a
commit
48eaa975f2
@ -24,6 +24,7 @@ static char SccsId[] = "%W% %G%";
|
||||
#include "yapio.h"
|
||||
#include "iopreds.h"
|
||||
#include "attvar.h"
|
||||
#include <math.h>
|
||||
|
||||
/* Non-backtrackable terms will from now on be stored on arenas, a
|
||||
special term on the heap. Arenas automatically contract as we add terms to
|
||||
@ -44,6 +45,7 @@ static char SccsId[] = "%W% %G%";
|
||||
#define HEAP_START 4
|
||||
|
||||
#define MIN_ARENA_SIZE 2048
|
||||
#define MAX_ARENA_SIZE (2048*16)
|
||||
|
||||
#define Global_MkIntegerTerm(I) MkIntegerTerm(I)
|
||||
|
||||
@ -265,6 +267,7 @@ adjust_cps(UInt size)
|
||||
static int
|
||||
GrowArena(Term arena, CELL *pt, UInt old_size, UInt size, UInt arity)
|
||||
{
|
||||
ArenaOverflows++;
|
||||
if (size == 0) {
|
||||
if (old_size < 1024*1024) {
|
||||
size = old_size;
|
||||
@ -1423,8 +1426,13 @@ p_nb_queue(void)
|
||||
#endif
|
||||
Term t = Deref(ARG1);
|
||||
UInt arena_sz = (ASP-H)/16;
|
||||
DepthArenas++;
|
||||
if (DepthArenas > 1)
|
||||
arena_sz /= log(MIN_ARENA_SIZE);
|
||||
if (arena_sz < MIN_ARENA_SIZE)
|
||||
arena_sz = MIN_ARENA_SIZE;
|
||||
if (arena_sz > MAX_ARENA_SIZE)
|
||||
arena_sz = MAX_ARENA_SIZE;
|
||||
|
||||
if (!IsVarTerm(t)) {
|
||||
if (!IsApplTerm(t)) {
|
||||
@ -1539,6 +1547,7 @@ p_nb_queue_close(void)
|
||||
Term t = Deref(ARG1);
|
||||
Int out;
|
||||
|
||||
DepthArenas--;
|
||||
if (!IsVarTerm(t)) {
|
||||
CELL *qp;
|
||||
|
||||
|
@ -3907,8 +3907,6 @@ call_gc(UInt gc_lim, Int predarity, CELL *current_env, yamop *nextop)
|
||||
}
|
||||
if (gc_margin < gc_lim)
|
||||
gc_margin = gc_lim;
|
||||
if (gc_margin < CalculateStackGap())
|
||||
gc_margin = CalculateStackGap();
|
||||
GcCalls++;
|
||||
HGEN = VarOfTerm(Yap_ReadTimedVar(GcGeneration));
|
||||
if (gc_on && !(Yap_PrologMode & InErrorMode) &&
|
||||
@ -3929,7 +3927,9 @@ call_gc(UInt gc_lim, Int predarity, CELL *current_env, yamop *nextop)
|
||||
if (ASP - H < gc_margin/sizeof(CELL) ||
|
||||
effectiveness < 20) {
|
||||
LeaveGCMode();
|
||||
return Yap_growstack(gc_margin);
|
||||
if (gc_margin < 2*CalculateStackGap())
|
||||
gc_margin = 2*CalculateStackGap();
|
||||
return Yap_growstack(gc_margin*sizeof(CELL));
|
||||
}
|
||||
/*
|
||||
* debug for(save_total=1; save_total<=N; ++save_total)
|
||||
|
2
C/init.c
2
C/init.c
@ -1416,6 +1416,8 @@ Yap_InitWorkspace(int Heap, int Stack, int Trail, int max_table_size,
|
||||
ActiveSignals = 0;
|
||||
DoingUndefp = FALSE;
|
||||
DelayArenaOverflows = 0;
|
||||
ArenaOverflows = 0;
|
||||
DepthArenas = 0;
|
||||
DBErasedList = NULL;
|
||||
DBErasedIList = NULL;
|
||||
Yap_heap_regs->IntLUKeys = NULL;
|
||||
|
@ -172,9 +172,6 @@ low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args)
|
||||
LOCK(Yap_heap_regs->low_level_trace_lock);
|
||||
sc = Yap_heap_regs;
|
||||
vsc_count++;
|
||||
if (vsc_count == 231868LL)
|
||||
jmp_deb(1);
|
||||
return;
|
||||
#ifdef THREADS
|
||||
Yap_heap_regs->thread_handle[worker_id].thread_inst_count++;
|
||||
#endif
|
||||
|
4
H/Heap.h
4
H/Heap.h
@ -106,6 +106,8 @@ extern struct restore_info rinfo;
|
||||
typedef struct worker_local_struct {
|
||||
struct format_status *f_info;
|
||||
Int delay_arena_overflows;
|
||||
Int arena_overflows;
|
||||
Int depth_arenas;
|
||||
char *scanner_stack;
|
||||
struct scanner_extra_alloc *scanner_extra_blocks;
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
@ -690,6 +692,8 @@ extern struct various_codes *Yap_heap_regs;
|
||||
#define DebugOn Yap_heap_regs->WL.debug_on
|
||||
#define FormatInfo Yap_heap_regs->WL.f_info
|
||||
#define DelayArenaOverflows Yap_heap_regs->WL.delay_arena_overflows
|
||||
#define ArenaOverflows Yap_heap_regs->WL.arena_overflows
|
||||
#define DepthArenas Yap_heap_regs->WL.depth_arenas
|
||||
#define ScannerStack Yap_heap_regs->WL.scanner_stack
|
||||
#define ScannerExtraBlocks Yap_heap_regs->WL.scanner_extra_blocks
|
||||
#define Yap_BigTmp Yap_heap_regs->WL.big_tmp
|
||||
|
Reference in New Issue
Block a user