ref: ca9d65e40b3f78d2580fff9ff1844bad1be08673
parent: 49c159b50f113fe0c61cc841c14a6fc664f87b49
author: cinap_lenrek <[email protected]>
date: Sat Apr 11 10:19:35 EDT 2020
cc: remove mysbrk(), exponentially increase gethunk() allocation delta mysbrk() was only used in gethunk() and should not be called by anyone, so dont export the symbol. simplify gethunk() using brk(). double allocation size on each call until we reach 1000*NHUNK. use signed long for nhunk as alignment rountin might make it negative and handle that case.
--- a/sys/src/cmd/cc/compat
+++ b/sys/src/cmd/cc/compat
@@ -4,12 +4,6 @@
return access(f, AEXIST);
}
-void*
-mysbrk(ulong size)
-{
- return sbrk(size);
-}
-
int
mycreat(char *n, int p)
{
@@ -77,27 +71,35 @@
return fork();
}
+
/*
* real allocs
*/
+
+extern char end[];
+
+char* hunk = end;
+long nhunk;
+uintptr thunk;
+
void
gethunk(void)
{
- char *h;
- ulong nh;
+ long nh;
- nh = NHUNK;
- if(thunk >= 10L*NHUNK)
- nh = 10L*NHUNK;
- h = (char*)mysbrk(nh);
- if(h == (char*)-1)
- sysfatal("out of memory");
- if(nhunk == 0)
- hunk = h;
+ if(thunk < NHUNK)
+ nh = NHUNK;
+ else if(thunk < 1000*NHUNK)
+ nh = thunk;
else
- nh += (h - hunk) - nhunk;
+ nh = 1000*NHUNK;
+
+ if(nhunk < 0)
+ nhunk = 0;
nhunk += nh;
thunk += nh;
+ if(brk(hunk+nhunk) < 0)
+ sysfatal("out of memory");
}
void*
--- a/sys/src/cmd/cc/compat.h
+++ b/sys/src/cmd/cc/compat.h
@@ -23,12 +23,11 @@
EXTERN int mydup(int, int);
EXTERN int myfork(void);
EXTERN int mypipe(int*);
-EXTERN void* mysbrk(ulong);
EXTERN void gethunk(void);
EXTERN char* hunk;
-EXTERN uintptr nhunk;
+EXTERN long nhunk;
EXTERN uintptr thunk;
EXTERN void* alloc(long n);