summaryrefslogtreecommitdiff
path: root/sys/src/cmd/cwfs/malloc.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2014-05-03 00:51:45 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2014-05-03 00:51:45 +0200
commit4c639475ce8cf0aec59632b6f7537169f1537f13 (patch)
treebc8aedcf42c1527d7ee62a43c5d73c923c24bcad /sys/src/cmd/cwfs/malloc.c
parent72e4d850a4c2b334b3442dd39aa973650e5d5ba4 (diff)
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.
Diffstat (limited to 'sys/src/cmd/cwfs/malloc.c')
-rw-r--r--sys/src/cmd/cwfs/malloc.c40
1 files changed, 25 insertions, 15 deletions
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 <pool.h>
+
+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<nhiob; i++) {