[inferno-npe] 2 new revisions pushed by extrudedaluminiu on 2010-08-04 01:01 GMT

1 view
Skip to first unread message

infer...@googlecode.com

unread,
Aug 3, 2010, 9:02:11 PM8/3/10
to inferno-n...@googlegroups.com
2 new revisions:

Revision: 23c199ff0b
Author: Venkatesh Srinivas <m...@endeavour.zapto.org>
Date: Tue Aug 3 13:19:46 2010
Log: Add a small cache of logarithmic sized buffers in front of the
mainmem...
http://code.google.com/p/inferno-npe/source/detail?r=23c199ff0b

Revision: 3adc963013
Author: Venkatesh Srinivas <m...@acm.jhu.edu>
Date: Tue Aug 3 17:50:13 2010
Log: Add assertions regarding block sizes.
http://code.google.com/p/inferno-npe/source/detail?r=3adc963013

==============================================================================
Revision: 23c199ff0b
Author: Venkatesh Srinivas <m...@endeavour.zapto.org>
Date: Tue Aug 3 13:19:46 2010
Log: Add a small cache of logarithmic sized buffers in front of the mainmem
pool.
http://code.google.com/p/inferno-npe/source/detail?r=23c199ff0b

Modified:
/Linux/386/bin/data2c
/Linux/386/bin/iyacc
/Linux/386/bin/mk
/Linux/386/bin/mkext
/emu/port/alloc.c

=======================================
--- /Linux/386/bin/data2c Tue Nov 18 12:49:59 2008
+++ /Linux/386/bin/data2c Tue Aug 3 13:19:46 2010
Binary file, no diff available.
=======================================
--- /Linux/386/bin/iyacc Tue Nov 18 12:49:59 2008
+++ /Linux/386/bin/iyacc Tue Aug 3 13:19:46 2010
Binary file, no diff available.
=======================================
--- /Linux/386/bin/mk Tue Nov 18 12:58:27 2008
+++ /Linux/386/bin/mk Tue Aug 3 13:19:46 2010
Binary file, no diff available.
=======================================
--- /Linux/386/bin/mkext Tue Nov 18 12:58:27 2008
+++ /Linux/386/bin/mkext Tue Aug 3 13:19:46 2010
Binary file, no diff available.
=======================================
--- /emu/port/alloc.c Fri Jan 29 04:39:08 2010
+++ /emu/port/alloc.c Tue Aug 3 13:19:46 2010
@@ -90,6 +90,78 @@
#define CKLEAK 0
int ckleak;
#define ML(v, sz, pc) if(CKLEAK && ckleak && v){ if(sz)
fprint(2, "%lux %lux %lux\n", (ulong)v, (ulong)sz, (ulong)pc); else
fprint(2, "%lux\n", (ulong)v); }
+
+/* main pool magazines */
+#define MAG_ROUNDS 32
+#define NCACHES 7
+#define MAXMAG 256
+
+struct blkcache {
+ Bhdr *blk[MAG_ROUNDS];
+};
+
+struct magazine {
+ int idx[NCACHES];
+ struct blkcache c[NCACHES];
+ Lock lk[NCACHES];
+ int fast_allocs[NCACHES];
+ int fast_frees[NCACHES];
+};
+
+static struct magazine Mag;
+
+static int
+size2idx(size_t size)
+{
+ if (size < 32)
+ return 0;
+ if (size < 64)
+ return 1;
+ if (size < 96)
+ return 2;
+ if (size < 128)
+ return 3;
+ if (size < 160)
+ return 4;
+ if (size < 192)
+ return 5;
+ if (size < 256)
+ return 6;
+ return -1;
+}
+
+/* main malloc vmstats */
+Lock stats_initlock;
+static int stats_init = 0;
+
+static int n_mallocs = 0;
+static int n_fast_mallocs = 0;
+static int n_frees = 0;
+static int n_fast_frees = 0;
+
+static void
+alloc_statsinit(void)
+{
+ if (stats_init == 1)
+ return;
+
+ lock(&stats_initlock);
+ do {
+ if (stats_init == 1)
+ break;
+
+ vmstat_entry("vm.alloc.main.n_mallocs", &n_mallocs, nil);
+ vmstat_entry("vm.alloc.main.n_fast_mallocs", &n_fast_mallocs,
+ nil);
+ vmstat_entry("vm.alloc.main.n_frees", &n_frees, nil);
+ vmstat_entry("vm.alloc.main.n_fast_frees", &n_fast_frees, nil);
+
+ stats_init = 1;
+ } while (0);
+ unlock(&stats_initlock);
+}
+
+/* */

int
heapneedgc(ulong osize)
@@ -605,6 +677,8 @@
{
void *v;

+ alloc_statsinit();
+
for(;;){
v = malloc(size);
if(v != nil)
@@ -624,9 +698,40 @@
kmalloc(size_t size)
{
void *v;
-
+ int blksize, i, idx;
+ Bhdr *b;
+
+ alloc_statsinit();
+
+ blksize = size + (Npadlong * sizeof(ulong)) + BHDRSIZE +
+ mainmem->quanta;
+
+ if (blksize < MAXMAG) {
+ idx = size2idx(blksize);
+ if (idx == -1)
+ goto doalloc;
+
+ lock(&Mag.lk[idx]);
+ i = Mag.idx[idx];
+ if (i == 0) {
+ unlock(&Mag.lk[idx]);
+ goto doalloc;
+ }
+
+ Mag.idx[idx]--;
+ b = Mag.c[idx].blk[i - 1];
+ v = B2D(b);
+ Mag.fast_allocs[idx]++;
+ unlock(&Mag.lk[idx]);
+ n_fast_mallocs++;
+ goto donealloc;
+ }
+
+doalloc:
v = dopoolalloc(mainmem, size+Npadlong*sizeof(ulong), getcallerpc(&size));
+donealloc:
if(v != nil){
+ n_mallocs++;
ML(v, size, getcallerpc(&size));
if(Npadlong){
v = (ulong*)v+Npadlong;
@@ -645,9 +750,41 @@
malloc(size_t size)
{
void *v;
-
+ int blksize;
+ int i, idx;
+ Bhdr *b;
+
+ alloc_statsinit();
+
+ blksize = size + (Npadlong * sizeof(ulong)) + BHDRSIZE +
+ mainmem->quanta;
+
+ if (blksize < MAXMAG) {
+ idx = size2idx(blksize);
+ if (idx == -1)
+ goto doalloc;
+
+ lock(&Mag.lk[idx]);
+ i = Mag.idx[idx];
+ if (i == 0) {
+ unlock(&Mag.lk[idx]);
+ goto doalloc;
+ }
+
+ Mag.idx[idx]--;
+ b = Mag.c[idx].blk[i - 1];
+ v = B2D(b);
+ Mag.fast_allocs[idx]++;
+ unlock(&Mag.lk[idx]);
+ n_fast_mallocs++;
+ goto donealloc;
+ }
+
+doalloc:
v = poolalloc(mainmem, size+Npadlong*sizeof(ulong));
+donealloc:
if(v != nil){
+ n_mallocs++;
ML(v, size, getcallerpc(&size));
if(Npadlong){
v = (ulong*)v+Npadlong;
@@ -665,9 +802,41 @@
mallocz(ulong size, int clr)
{
void *v;
-
+ int blksize;
+ int i, idx;
+ Bhdr *b;
+
+ alloc_statsinit();
+
+ blksize = size + (Npadlong * sizeof(ulong)) + BHDRSIZE +
+ mainmem->quanta;
+
+ if (blksize < MAXMAG) {
+ idx = size2idx(blksize);
+ if (idx == -1)
+ goto doalloc;
+
+ lock(&Mag.lk[idx]);
+ i = Mag.idx[idx];
+ if (i == 0) {
+ unlock(&Mag.lk[idx]);
+ goto doalloc;
+ }
+
+ Mag.idx[idx]--;
+ b = Mag.c[idx].blk[i - 1];
+ v = B2D(b);
+ Mag.fast_allocs[idx]++;
+ unlock(&Mag.lk[idx]);
+ n_fast_mallocs++;
+ goto donealloc;
+ }
+
+doalloc:
v = poolalloc(mainmem, size+Npadlong*sizeof(ulong));
+donealloc:
if(v != nil){
+ n_mallocs++;
ML(v, size, getcallerpc(&size));
if(Npadlong){
v = (ulong*)v+Npadlong;
@@ -686,6 +855,10 @@
free(void *v)
{
Bhdr *b;
+ int bs, idx;
+ int i, j;
+
+ alloc_statsinit();

if(v != nil) {
if(Npadlong)
@@ -693,7 +866,33 @@
D2B(b, v);
ML(v, 0, 0);
MM(1<<8|0, getcallerpc(&v), (ulong)((ulong*)v+Npadlong), b->size);
+ bs = b->size - BHDRSIZE;
+ if(bs < MAXMAG) {
+ idx = size2idx(bs);
+ if (idx == -1)
+ goto dofree;
+
+ lock(&Mag.lk[idx]);
+ j = Mag.idx[idx];
+ if (j == MAG_ROUNDS) {
+ unlock(&Mag.lk[idx]);
+ goto dofree;
+ }
+
+ Mag.idx[idx]++;
+ Mag.c[idx].blk[j] = b;
+ Mag.fast_frees[idx]++;
+ unlock(&Mag.lk[idx]);
+
+ n_frees++;
+ n_fast_frees++;
+ return;
+ }
+
+dofree:
poolfree(mainmem, v);
+
+ n_frees++;
}
}

@@ -702,6 +901,8 @@
{
void *nv;

+ alloc_statsinit();
+
if(size == 0)
return malloc(size); /* temporary change until realloc calls can be
checked */
if(v != nil)
@@ -776,6 +977,8 @@
void*
calloc(size_t n, size_t szelem)
{
+ alloc_statsinit();
+
return malloc(n*szelem);
}


==============================================================================
Revision: 3adc963013
Author: Venkatesh Srinivas <m...@acm.jhu.edu>
Date: Tue Aug 3 17:50:13 2010
Log: Add assertions regarding block sizes.
http://code.google.com/p/inferno-npe/source/detail?r=3adc963013

Modified:
/emu/port/alloc.c

=======================================
--- /emu/port/alloc.c Tue Aug 3 13:19:46 2010
+++ /emu/port/alloc.c Tue Aug 3 17:50:13 2010
@@ -63,15 +63,14 @@
static void _poolfault(void *, char *, ulong);
void (*poolfault)(void *, char *, ulong) = _poolfault;

-/* non tracing
- *
+/* non tracing */
+/*
enum {
Npadlong = 0,
MallocOffset = 0,
ReallocOffset = 0
};
- *
- */
+*/

/* tracing */
enum {
@@ -79,7 +78,6 @@
MallocOffset = 0,
ReallocOffset = 1
};
-
enum {
Monitor = 1
};
@@ -92,7 +90,7 @@
#define ML(v, sz, pc) if(CKLEAK && ckleak && v){ if(sz)
fprint(2, "%lux %lux %lux\n", (ulong)v, (ulong)sz, (ulong)pc); else
fprint(2, "%lux\n", (ulong)v); }

/* main pool magazines */
-#define MAG_ROUNDS 32
+#define MAG_ROUNDS 16
#define NCACHES 7
#define MAXMAG 256

@@ -724,6 +722,8 @@
Mag.fast_allocs[idx]++;
unlock(&Mag.lk[idx]);
n_fast_mallocs++;
+ if(Monitor)
+ assert((b->size - BHDRSIZE) >= size);
goto donealloc;
}

@@ -777,6 +777,8 @@
Mag.fast_allocs[idx]++;
unlock(&Mag.lk[idx]);
n_fast_mallocs++;
+ if (Monitor)
+ assert((b->size - BHDRSIZE) >= size);
goto donealloc;
}

@@ -829,6 +831,8 @@
Mag.fast_allocs[idx]++;
unlock(&Mag.lk[idx]);
n_fast_mallocs++;
+ if (Monitor)
+ assert((b->size - BHDRSIZE) >= size);
goto donealloc;
}

Reply all
Reply to author
Forward
0 new messages