pool: use uintptr for pool size

note, arenas and blocks still use ulong for sizes. so
we have to check for overflow when attempting to merge
arenas.
This commit is contained in:
cinap_lenrek 2014-02-06 22:47:05 +01:00
parent c065eadb53
commit e836796365
2 changed files with 10 additions and 8 deletions

View file

@ -1,11 +1,11 @@
typedef struct Pool Pool; typedef struct Pool Pool;
struct Pool { struct Pool {
char* name; char* name;
ulong maxsize; uintptr maxsize;
ulong cursize; uintptr cursize;
ulong curfree; uintptr curfree;
ulong curalloc; uintptr curalloc;
ulong minarena; /* smallest size of new arena */ ulong minarena; /* smallest size of new arena */
ulong quantum; /* allocated blocks should be multiple of */ ulong quantum; /* allocated blocks should be multiple of */

View file

@ -555,8 +555,8 @@ poolnewarena(Pool *p, ulong asize)
LOG(p, "newarena %lud\n", asize); LOG(p, "newarena %lud\n", asize);
if(p->cursize+asize > p->maxsize) { if(p->cursize+asize > p->maxsize) {
if(poolcompactl(p) == 0){ if(poolcompactl(p) == 0){
LOG(p, "pool too big: %lud+%lud > %lud\n", LOG(p, "pool too big: %llud+%lud > %llud\n",
p->cursize, asize, p->maxsize); (uvlong)p->cursize, asize, (uvlong)p->maxsize);
werrstr("memory pool too large"); werrstr("memory pool too large");
} }
return; return;
@ -637,12 +637,14 @@ arenamerge(Pool *p, Arena *bot, Arena *top)
{ {
Bhdr *bbot, *btop; Bhdr *bbot, *btop;
Btail *t; Btail *t;
ulong newsize;
blockcheck(p, bot); blockcheck(p, bot);
blockcheck(p, top); blockcheck(p, top);
assert(bot->aup == top && top > bot); assert(bot->aup == top && top > bot);
if(p->merge == nil || p->merge(bot, top) == 0) newsize = top->asize + ((uchar*)top - (uchar*)bot);
if(newsize < top->asize || p->merge == nil || p->merge(bot, top) == 0)
return nil; return nil;
/* remove top from list */ /* remove top from list */
@ -659,7 +661,7 @@ arenamerge(Pool *p, Arena *bot, Arena *top)
blockcheck(p, btop); blockcheck(p, btop);
/* grow bottom arena to encompass top */ /* grow bottom arena to encompass top */
arenasetsize(bot, top->asize + ((uchar*)top - (uchar*)bot)); arenasetsize(bot, newsize);
/* grow bottom block to encompass space between arenas */ /* grow bottom block to encompass space between arenas */
blockgrow(p, bbot, (uchar*)btop-(uchar*)bbot); blockgrow(p, bbot, (uchar*)btop-(uchar*)bbot);