core: jam-scaper/garbage-collector: Use only one arena.

* src/mes.c (ARENA_SIZE): Lower to 200000.
  (MES_MAX_ARENA): Bump to 300000000.
  (JAM_SIZE): New global.
  (make_cell__): Remove ARENA assert.
  (gc_init_cells): Alloc ARENA_SIZE + JAM_SIZE.
  (mes_symbols): Do not init news.
  (gc_init_news): Remove.
  (main): Initialize JAM_SIZE, consider MES_JAM environment variable.
* src/gc.c (gc_init_news): Move from mes.c.  Start at g_free.
  (gc_flip): Do not flip to g_news, instead copy g_news to cells.
  (gc_up_arena): Realloc to ARENA_SIZE + JAM_SIZE.
  (gc_): Init news.  Only up arena if g_news is safe.
This commit is contained in:
Jan Nieuwenhuizen 2018-04-25 08:35:05 +02:00
parent e628b311d6
commit e3b929aa87
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
2 changed files with 38 additions and 38 deletions

View File

@ -23,8 +23,15 @@
SCM
gc_up_arena () ///((internal))
{
ARENA_SIZE *= 2;
void *p = realloc (g_cells-1, 2*ARENA_SIZE*sizeof(struct scm));
if (ARENA_SIZE >> 1 < MAX_ARENA_SIZE >> 2)
{
ARENA_SIZE <<= 1;
JAM_SIZE <<= 1;
GC_SAFETY <<= 1;
}
else
ARENA_SIZE = MAX_ARENA_SIZE -JAM_SIZE;
void *p = realloc (g_cells-1, (ARENA_SIZE+JAM_SIZE)*sizeof (struct scm));
if (!p)
{
eputs ("realloc failed, g_free=");
@ -37,7 +44,6 @@ gc_up_arena () ///((internal))
}
g_cells = (struct scm*)p;
g_cells++;
gc_init_news ();
return 0;
}
@ -45,15 +51,15 @@ gc_up_arena () ///((internal))
SCM
gc_flip () ///((internal))
{
struct scm *cells = g_cells;
g_cells = g_news;
g_news = cells;
if (g_debug > 2)
{
eputs (";;; => jam[");
eputs (itoa (g_free));
eputs ("]\n");
}
if (g_free > JAM_SIZE)
JAM_SIZE = g_free + g_free / 2;
memcpy (g_cells-1, g_news-1, (g_free+2)*sizeof (struct scm));
return g_stack;
}
@ -135,9 +141,23 @@ gc_check ()
return cell_unspecified;
}
SCM
gc_init_news () ///((internal))
{
g_news = g_cells + g_free;
NTYPE (0) = TVECTOR;
NLENGTH (0) = 1000;
NVECTOR (0) = 0;
g_news++;
NTYPE (0) = TCHAR;
NVALUE (0) = 'n';
return 0;
}
SCM
gc_ () ///((internal))
{
gc_init_news ();
if (g_debug == 2)
eputs (".");
if (g_debug > 2)
@ -150,9 +170,7 @@ gc_ () ///((internal))
}
g_free = 1;
if (g_cells < g_news
//&& g_free > ARENA_SIZE >> 2
&& ARENA_SIZE < MAX_ARENA_SIZE)
if (ARENA_SIZE < MAX_ARENA_SIZE && (int)g_news > 0)
{
if (g_debug == 2)
eputs ("+");

View File

@ -25,22 +25,15 @@
#include <mlibc.h>
//#define MES_MINI 1
// minimal for boot-0.scm
// int ARENA_SIZE = 100000; // 32b: 1MiB, 64b: 2 MiB
// take a bit more to run all tests
// int ARENA_SIZE = 400000; // 32b: 1MiB, 64b: 2 MiB
// take a bit extra for loading repl
int ARENA_SIZE = 1000000; // 32b: 2MiB, 64b: 4 MiB
#if !_POSIX_SOURCE
//int MAX_ARENA_SIZE = 60000000; // 32b: ~ 300MiB
int MAX_ARENA_SIZE = 166600000; // 32b: ~ 2GiB
//int MAX_ARENA_SIZE = 500000000; // 32b: ~ 8GiB
#if _POSIX_SOURCE
int ARENA_SIZE = 300000000; // 32b: 4GiB, 64b: 8 GiB
#else
int MAX_ARENA_SIZE = 200000000; // 32b: 2.3GiB, 64b: 4.6GiB
int ARENA_SIZE = 200000; // 32b: 2MiB, 64b: 4 MiB
#endif
int MAX_ARENA_SIZE = 300000000;
int GC_SAFETY = 4000;
int JAM_SIZE = 20000;
int GC_SAFETY = 2000;
char *g_arena = 0;
typedef int SCM;
@ -324,7 +317,6 @@ int g_function = 0;
SCM
alloc (int n)
{
assert (g_free + n < ARENA_SIZE);
SCM x = g_free;
g_free += n;
return x;
@ -1537,7 +1529,7 @@ SCM g_symbol_max;
SCM
gc_init_cells () ///((internal))
{
g_cells = (struct scm *)malloc (2*ARENA_SIZE*sizeof (struct scm));
g_cells = (struct scm *)malloc ((ARENA_SIZE+JAM_SIZE)*sizeof (struct scm));
TYPE (0) = TVECTOR;
LENGTH (0) = 1000;
VECTOR (0) = 0;
@ -1547,24 +1539,10 @@ gc_init_cells () ///((internal))
return 0;
}
SCM
gc_init_news () ///((internal))
{
g_news = g_cells-1 + ARENA_SIZE;
NTYPE (0) = TVECTOR;
NLENGTH (0) = 1000;
NVECTOR (0) = 0;
g_news++;
NTYPE (0) = TCHAR;
NVALUE (0) = 'n';
return 0;
}
SCM
mes_symbols () ///((internal))
{
gc_init_cells ();
gc_init_news ();
#if MES_MINI
@ -2364,6 +2342,10 @@ main (int argc, char *argv[])
MAX_ARENA_SIZE = atoi (p);
if (p = getenv ("MES_ARENA"))
ARENA_SIZE = atoi (p);
JAM_SIZE = ARENA_SIZE / 10;
if (p = getenv ("MES_JAM"))
JAM_SIZE = atoi (p);
GC_SAFETY = ARENA_SIZE / 100;
if (p = getenv ("MES_SAFETY"))
GC_SAFETY = atoi (p);
g_stdin = STDIN;