Subject: pool(9) revisited
To: None <tech-kern@NetBSD.ORG>
From: Paul Kranenburg <>
List: tech-kern
Date: 06/28/1998 23:51:51
So, here's a new set of pool interface routines:

struct pool *
pool_create(size, nitems, wchan, pagesz, alloc, release, mtype)

        size_t  size;   
		size of a pool elements

        int     nitems; 
		initial number of elements

        char    *wchan; 
		pool identifier

        size_t  pagesz; 
		page size, must be power of 2; if 0, the default is NBPG

        void    *(*alloc) __P((unsigned long size, int flags, int type));
		page allocator to use;
		must return `pagesz' aligned memory;
		`size' shall be a multiple of `pagesz'.
		flags defined:
		If NULL, defaults to internal allocator based on kmem_alloc()

        void    (*release) __P((void *p, unsigned long size, int type));
		page deallocator; used to free pages
		If NULL, defaults to internal deallocator based on kmem_free()

        int     mtype;
		a memory tag; passed to `alloc' and `release'.

	Note: the pool structure is allocated using malloc(9)

pool_init(pp, size, flags, wchan, pagesz, alloc, release, mtype)

	struct pool     *pp;

	Initialize the pool structure passed in `pp'. Use with statically
	declared pools.

	int flags;
		PR_STATIC - pool memory will come from external sources
			    through pool_prime()

pool_prime(pp, n, storage)
        struct pool *pp;
        int n;
        caddr_t storage;

	Add `n' more elements to the given pool.
	`storage' must be non-NULL if the pool is flagged PR_STATIC

void *                  
pool_get(pp, flags)
        struct pool *pp;
        int flags;      

	Get a pool item.
	New flag: PR_URGENT:
		page allocator should make "every effort" to get new memory

	PR_MALLOCOK should be deprecated

pool_put(pp, v)  
        struct pool *pp;
        void *v;

	No change.

pool_sethiwat(pp, n)
        pool_handle_t   pp;
        int n;

	Set high water mark, but do not allocate memory up front
	like pool_prime().