From 4c639475ce8cf0aec59632b6f7537169f1537f13 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 3 May 2014 00:51:45 +0200 Subject: cwfs: fix 1GB memsize limitation the malloc pool allocator is limited in its allocation size. as almost all data structures in cwfs are never freed, use brk() in ialloc() instead of mallocalign(). this means memory returned by ialloc() cannot be freed! to make sure we do not call free by accident, remove the #define malloc(n) ialloc(n, 0) macro and use ialloc() directly as in the original code to show the intend of permanent allocations. --- sys/src/cmd/cwfs/malloc.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'sys/src/cmd/cwfs/malloc.c') diff --git a/sys/src/cmd/cwfs/malloc.c b/sys/src/cmd/cwfs/malloc.c index aed02b117..165599623 100644 --- a/sys/src/cmd/cwfs/malloc.c +++ b/sys/src/cmd/cwfs/malloc.c @@ -1,10 +1,12 @@ #include "all.h" #include "io.h" -static ulong +#include + +static uvlong memsize(void) { - ulong pgsize, pgmax, userpgs, userused; + ulong pgsize, userpgs, userused; char *s, *f[2]; int n, mpcnt; Biobuf *bp; @@ -37,17 +39,13 @@ memsize(void) if(mpcnt < 1) mpcnt = 1; userpgs = (userpgs*mpcnt)/100; - pgmax = (1024*1024*1024)/pgsize; /* 1GB max */ - if(userpgs > pgmax) - userpgs = pgmax; - return userpgs*pgsize; + return (uvlong)userpgs*pgsize; } return 16*MB; } - -long niob; -long nhiob; +uint niob; +uint nhiob; Hiob *hiob; /* @@ -56,14 +54,26 @@ Hiob *hiob; * end of the allocated memory. */ void* -ialloc(ulong n, int align) +ialloc(uintptr n, int align) { - void *p = mallocalign(n, align, 0, 0); + char *p; + int m; + + if(align <= 0) + align = sizeof(uintptr); - if (p == nil) + mainmem->lock(mainmem); + + p = sbrk(0); + if(m = n % align) + n += align - m; + if(m = (uintptr)p % align) + p += align - m; + if(brk(p+n) < 0) panic("ialloc: out of memory"); - setmalloctag(p, getcallerpc(&n)); - memset(p, 0, n); + + mainmem->unlock(mainmem); + return p; } @@ -89,7 +99,7 @@ iobufinit(void) while(!prime(nhiob)) nhiob++; if(chatty) - print("\t%ld buffers; %ld hashes\n", niob, nhiob); + print("\t%ud buffers; %ud hashes\n", niob, nhiob); hiob = ialloc(nhiob * sizeof(Hiob), 0); hp = hiob; for(i=0; i