mirror of
git://git.9front.org/plan9front/plan9front
synced 2025-01-12 11:10:06 +00:00
libc: Add poolreset() function
This is intended for the secrmem pool in the kernel, but could also be used for temporary pools to recover the memory used by the arenas.
This commit is contained in:
parent
26e42d1159
commit
bd43bd6f1a
5 changed files with 64 additions and 2 deletions
|
@ -17,6 +17,7 @@ struct Pool {
|
||||||
void* (*alloc)(ulong);
|
void* (*alloc)(ulong);
|
||||||
int (*merge)(void*, void*);
|
int (*merge)(void*, void*);
|
||||||
void (*move)(void* from, void* to);
|
void (*move)(void* from, void* to);
|
||||||
|
void (*free)(void*, ulong);
|
||||||
|
|
||||||
int flags;
|
int flags;
|
||||||
int nfree;
|
int nfree;
|
||||||
|
@ -36,6 +37,7 @@ extern void* poolallocalign(Pool*, ulong, ulong, long, ulong);
|
||||||
extern void poolfree(Pool*, void*);
|
extern void poolfree(Pool*, void*);
|
||||||
extern ulong poolmsize(Pool*, void*);
|
extern ulong poolmsize(Pool*, void*);
|
||||||
extern int poolisoverlap(Pool*, void*, ulong);
|
extern int poolisoverlap(Pool*, void*, ulong);
|
||||||
|
extern void poolreset(Pool*);
|
||||||
extern void* poolrealloc(Pool*, void*, ulong);
|
extern void* poolrealloc(Pool*, void*, ulong);
|
||||||
extern void poolcheck(Pool*);
|
extern void poolcheck(Pool*);
|
||||||
extern int poolcompact(Pool*);
|
extern int poolcompact(Pool*);
|
||||||
|
|
|
@ -28,6 +28,9 @@ ulong poolmsize(Pool* pool, void* ptr)
|
||||||
int poolisoverlap(Pool* pool, void* ptr, ulong len)
|
int poolisoverlap(Pool* pool, void* ptr, ulong len)
|
||||||
.PP
|
.PP
|
||||||
.B
|
.B
|
||||||
|
void poolreset(Pool* pool)
|
||||||
|
.PP
|
||||||
|
.B
|
||||||
void* poolrealloc(Pool* pool, void* ptr, ulong size)
|
void* poolrealloc(Pool* pool, void* ptr, ulong size)
|
||||||
.PP
|
.PP
|
||||||
.B
|
.B
|
||||||
|
@ -119,6 +122,18 @@ overlaps the arenas of the specified
|
||||||
.BR pool ,
|
.BR pool ,
|
||||||
returning non-zero when there is overlap or zero if none.
|
returning non-zero when there is overlap or zero if none.
|
||||||
.PP
|
.PP
|
||||||
|
.I Poolreset
|
||||||
|
clears the pool counters and frees all arenas.
|
||||||
|
The arenas are filled with a pattern before
|
||||||
|
freeing them when the
|
||||||
|
.B POOL_ANTAGONISM
|
||||||
|
flag is set.
|
||||||
|
When the
|
||||||
|
.B free
|
||||||
|
function of the pool is non-nil,
|
||||||
|
it is called for each arena,
|
||||||
|
passing its pointer and size.
|
||||||
|
.PP
|
||||||
The
|
The
|
||||||
.I poolblockcheck
|
.I poolblockcheck
|
||||||
and
|
and
|
||||||
|
@ -156,6 +171,7 @@ struct Pool {
|
||||||
void* (*alloc)(ulong);
|
void* (*alloc)(ulong);
|
||||||
int (*merge)(void*, void*);
|
int (*merge)(void*, void*);
|
||||||
void (*move)(void* from, void* to);
|
void (*move)(void* from, void* to);
|
||||||
|
void (*free)(void*, ulong);
|
||||||
void (*lock)(Pool*);
|
void (*lock)(Pool*);
|
||||||
void (*unlock)(Pool*);
|
void (*unlock)(Pool*);
|
||||||
void (*print)(Pool*, char*, ...);
|
void (*print)(Pool*, char*, ...);
|
||||||
|
@ -284,7 +300,10 @@ Freed blocks use the constant
|
||||||
newly allocated blocks
|
newly allocated blocks
|
||||||
.BR 0xF9000000 ,
|
.BR 0xF9000000 ,
|
||||||
and newly created unallocated blocks
|
and newly created unallocated blocks
|
||||||
.BR 0xF1000000 .
|
.BR 0xF1000000 ,
|
||||||
|
freed arenas after
|
||||||
|
.I poolreset
|
||||||
|
.BR 0xFF000000 .
|
||||||
For example, if
|
For example, if
|
||||||
.B POOL_ANTAGONISM
|
.B POOL_ANTAGONISM
|
||||||
is set and
|
is set and
|
||||||
|
|
|
@ -131,6 +131,8 @@ UPDATE=mkfile\
|
||||||
|
|
||||||
profile.$O: /sys/include/tos.h
|
profile.$O: /sys/include/tos.h
|
||||||
|
|
||||||
|
malloc.$O pool.$O: /sys/include/pool.h
|
||||||
|
|
||||||
runenorm.$O: runenormdata runenorm.c
|
runenorm.$O: runenormdata runenorm.c
|
||||||
runetotype.$O: runetotypedata runetotype.c
|
runetotype.$O: runetotypedata runetotype.c
|
||||||
runeistype.$O: runeistypedata runeistype.c
|
runeistype.$O: runeistypedata runeistype.c
|
||||||
|
|
|
@ -1345,6 +1345,43 @@ poolisoverlap(Pool *p, void *v, ulong n)
|
||||||
return a != nil;
|
return a != nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
poolreset(Pool *p)
|
||||||
|
{
|
||||||
|
Arena *a;
|
||||||
|
|
||||||
|
if(p == nil)
|
||||||
|
return;
|
||||||
|
|
||||||
|
p->lock(p);
|
||||||
|
paranoia {
|
||||||
|
poolcheckl(p);
|
||||||
|
}
|
||||||
|
verbosity {
|
||||||
|
pooldumpl(p);
|
||||||
|
}
|
||||||
|
p->cursize = 0;
|
||||||
|
p->curfree = 0;
|
||||||
|
p->curalloc = 0;
|
||||||
|
p->lastcompact = p->nfree = 0;
|
||||||
|
p->freeroot = nil;
|
||||||
|
a = p->arenalist;
|
||||||
|
p->arenalist = nil;
|
||||||
|
LOG(p, "poolreset %p\n", p);
|
||||||
|
p->unlock(p);
|
||||||
|
|
||||||
|
while(a != nil){
|
||||||
|
Arena *next = a->down;
|
||||||
|
ulong asize = a->asize;
|
||||||
|
antagonism {
|
||||||
|
memmark(a, 0xFF, asize);
|
||||||
|
}
|
||||||
|
if(p->free)
|
||||||
|
p->free(a, asize);
|
||||||
|
a = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Debugging
|
* Debugging
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -29,6 +29,8 @@ UPDATE=\
|
||||||
|
|
||||||
</sys/src/cmd/mksyslib
|
</sys/src/cmd/mksyslib
|
||||||
|
|
||||||
|
alloc.$O draw.$O: /sys/include/pool.h
|
||||||
|
|
||||||
$O.drawtest: drawtest.$O $LIB
|
$O.drawtest: drawtest.$O $LIB
|
||||||
$LD -o $target $prereq
|
$LD -o $target $prereq
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue