add malloc flag to blist so that it can be used in ithread context

Reviewed by: alc, bsdimp
This commit is contained in:
Kip Macy 2008-05-05 19:48:54 +00:00
parent 805dc5adca
commit c8c7ad9260
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=178792
3 changed files with 14 additions and 12 deletions

View File

@ -152,14 +152,15 @@ static MALLOC_DEFINE(M_SWAP, "SWAP", "Swap space");
* blist_create() - create a blist capable of handling up to the specified
* number of blocks
*
* blocks must be greater then 0
* blocks - must be greater then 0
* flags - malloc flags
*
* The smallest blist consists of a single leaf node capable of
* managing BLIST_BMAP_RADIX blocks.
*/
blist_t
blist_create(daddr_t blocks)
blist_create(daddr_t blocks, int flags)
{
blist_t bl;
int radix;
@ -175,14 +176,14 @@ blist_create(daddr_t blocks)
skip = (skip + 1) * BLIST_META_RADIX;
}
bl = malloc(sizeof(struct blist), M_SWAP, M_WAITOK | M_ZERO);
bl = malloc(sizeof(struct blist), M_SWAP, flags | M_ZERO);
bl->bl_blocks = blocks;
bl->bl_radix = radix;
bl->bl_skip = skip;
bl->bl_rootblks = 1 +
blst_radix_init(NULL, bl->bl_radix, bl->bl_skip, blocks);
bl->bl_root = malloc(sizeof(blmeta_t) * bl->bl_rootblks, M_SWAP, M_WAITOK);
bl->bl_root = malloc(sizeof(blmeta_t) * bl->bl_rootblks, M_SWAP, flags);
#if defined(BLIST_DEBUG)
printf(
@ -280,9 +281,9 @@ blist_fill(blist_t bl, daddr_t blkno, daddr_t count)
*/
void
blist_resize(blist_t *pbl, daddr_t count, int freenew)
blist_resize(blist_t *pbl, daddr_t count, int freenew, int flags)
{
blist_t newbl = blist_create(count);
blist_t newbl = blist_create(count, flags);
blist_t save = *pbl;
*pbl = newbl;
@ -1014,7 +1015,7 @@ main(int ac, char **av)
fprintf(stderr, "Bad option: %s\n", ptr - 2);
exit(1);
}
bl = blist_create(size);
bl = blist_create(size, M_WAITOK);
blist_free(bl, 0, size);
for (;;) {

View File

@ -29,12 +29,12 @@
* Implements bitmap resource lists.
*
* Usage:
* blist = blist_create(blocks)
* blist = blist_create(blocks, flags)
* (void) blist_destroy(blist)
* blkno = blist_alloc(blist, count)
* (void) blist_free(blist, blkno, count)
* nblks = blist_fill(blist, blkno, count)
* (void) blist_resize(&blist, count, freeextra)
* (void) blist_resize(&blist, count, freeextra, flags)
*
*
* Notes:
@ -50,6 +50,7 @@
* eats around 32 KBytes of memory.
*
* $FreeBSD$
*/
#ifndef _SYS_BLIST_H_
@ -91,13 +92,13 @@ typedef struct blist {
#define BLIST_MAX_ALLOC BLIST_BMAP_RADIX
extern blist_t blist_create(daddr_t blocks);
extern blist_t blist_create(daddr_t blocks, int flags);
extern void blist_destroy(blist_t blist);
extern daddr_t blist_alloc(blist_t blist, daddr_t count);
extern void blist_free(blist_t blist, daddr_t blkno, daddr_t count);
extern int blist_fill(blist_t bl, daddr_t blkno, daddr_t count);
extern void blist_print(blist_t blist);
extern void blist_resize(blist_t *pblist, daddr_t count, int freenew);
extern void blist_resize(blist_t *pblist, daddr_t count, int freenew, int flags);
#endif /* _SYS_BLIST_H_ */

View File

@ -2018,7 +2018,7 @@ swaponsomething(struct vnode *vp, void *id, u_long nblks, sw_strategy_t *strateg
sp->sw_strategy = strategy;
sp->sw_close = close;
sp->sw_blist = blist_create(nblks);
sp->sw_blist = blist_create(nblks, M_WAITOK);
/*
* Do not free the first two block in order to avoid overwriting
* any bsd label at the front of the partition