+++ /dev/null
-/* $NetBSD: pool.h,v 1.54 2006/08/20 09:35:25 yamt Exp $ */\r
-\r
-/*-\r
- * Copyright (c) 1997, 1998, 1999, 2000 The NetBSD Foundation, Inc.\r
- * All rights reserved.\r
- *\r
- * This code is derived from software contributed to The NetBSD Foundation\r
- * by Paul Kranenburg; by Jason R. Thorpe of the Numerical Aerospace\r
- * Simulation Facility, NASA Ames Research Center.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * 1. Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- * 3. All advertising materials mentioning features or use of this software\r
- * must display the following acknowledgement:\r
- * This product includes software developed by the NetBSD\r
- * Foundation, Inc. and its contributors.\r
- * 4. Neither the name of The NetBSD Foundation nor the names of its\r
- * contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
- * POSSIBILITY OF SUCH DAMAGE.\r
- */\r
-\r
-#ifndef _SYS_POOL_H_\r
-#define _SYS_POOL_H_\r
-\r
-#ifdef _KERNEL\r
-#define __POOL_EXPOSE\r
-#endif\r
-\r
-#if defined(_KERNEL_OPT)\r
-#include "opt_pool.h"\r
-#endif\r
-\r
-#ifdef __POOL_EXPOSE\r
-#include <sys/lock.h>\r
-#include <sys/queue.h>\r
-#include <sys/time.h>\r
-#include <sys/tree.h>\r
-#if defined(_KERNEL)\r
-#include <sys/callback.h>\r
-#endif /* defined(_KERNEL) */\r
-#endif\r
-\r
-#define PCG_NOBJECTS 16\r
-\r
-#define POOL_PADDR_INVALID ((paddr_t) -1)\r
-\r
-#ifdef __POOL_EXPOSE\r
-/* The pool cache group. */\r
-struct pool_cache_group {\r
- LIST_ENTRY(pool_cache_group)\r
- pcg_list; /* link in the pool cache's group list */\r
- u_int pcg_avail; /* # available objects */\r
- /* pointers to the objects */\r
- struct {\r
- void *pcgo_va; /* cache object virtual address */\r
- paddr_t pcgo_pa;/* cache object physical address */\r
- } pcg_objects[PCG_NOBJECTS];\r
-};\r
-\r
-LIST_HEAD(pool_cache_grouplist,pool_cache_group);\r
-struct pool_cache {\r
- LIST_ENTRY(pool_cache)\r
- pc_poollist; /* entry on pool's group list */\r
- struct pool_cache_grouplist\r
- pc_emptygroups; /* list of empty cache groups */\r
- struct pool_cache_grouplist\r
- pc_fullgroups; /* list of full cache groups */\r
- struct pool_cache_grouplist\r
- pc_partgroups; /* list of partial cache groups */\r
- struct pool *pc_pool; /* parent pool */\r
- struct simplelock pc_slock; /* mutex */\r
-\r
- int (*pc_ctor)(void *, void *, int);\r
- void (*pc_dtor)(void *, void *);\r
- void *pc_arg;\r
-\r
- /* Statistics. */\r
- unsigned long pc_hits; /* cache hits */\r
- unsigned long pc_misses; /* cache misses */\r
-\r
- unsigned long pc_ngroups; /* # cache groups */\r
-\r
- unsigned long pc_nitems; /* # objects currently in cache */\r
-};\r
-\r
-struct pool_allocator {\r
- void *(*pa_alloc)(struct pool *, int);\r
- void (*pa_free)(struct pool *, void *);\r
- unsigned int pa_pagesz;\r
-\r
- /* The following fields are for internal use only. */\r
- struct simplelock pa_slock;\r
- TAILQ_HEAD(, pool) pa_list; /* list of pools using this allocator */\r
- int pa_flags;\r
-#define PA_INITIALIZED 0x01\r
- int pa_pagemask;\r
- int pa_pageshift;\r
- struct vm_map *pa_backingmap;\r
-#if defined(_KERNEL)\r
- struct vm_map **pa_backingmapptr;\r
- SLIST_ENTRY(pool_allocator) pa_q;\r
-#endif /* defined(_KERNEL) */\r
-};\r
-\r
-LIST_HEAD(pool_pagelist,pool_item_header);\r
-\r
-struct pool {\r
- LIST_ENTRY(pool)\r
- pr_poollist;\r
- struct pool_pagelist\r
- pr_emptypages; /* Empty pages */\r
- struct pool_pagelist\r
- pr_fullpages; /* Full pages */\r
- struct pool_pagelist\r
- pr_partpages; /* Partially-allocated pages */\r
- struct pool_item_header *pr_curpage;\r
- struct pool *pr_phpool; /* Pool item header pool */\r
- LIST_HEAD(,pool_cache)\r
- pr_cachelist; /* Caches for this pool */\r
- unsigned int pr_size; /* Size of item */\r
- unsigned int pr_align; /* Requested alignment, must be 2^n */\r
- unsigned int pr_itemoffset; /* Align this offset in item */\r
- unsigned int pr_minitems; /* minimum # of items to keep */\r
- unsigned int pr_minpages; /* same in page units */\r
- unsigned int pr_maxpages; /* maximum # of pages to keep */\r
- unsigned int pr_npages; /* # of pages allocated */\r
- unsigned int pr_itemsperpage;/* # items that fit in a page */\r
- unsigned int pr_slack; /* unused space in a page */\r
- unsigned int pr_nitems; /* number of available items in pool */\r
- unsigned int pr_nout; /* # items currently allocated */\r
- unsigned int pr_hardlimit; /* hard limit to number of allocated\r
- items */\r
- struct pool_allocator *pr_alloc;/* back-end allocator */\r
- TAILQ_ENTRY(pool) pr_alloc_list;/* link on allocator's pool list */\r
-\r
- /* Drain hook. */\r
- void (*pr_drain_hook)(void *, int);\r
- void *pr_drain_hook_arg;\r
-\r
- const char *pr_wchan; /* tsleep(9) identifier */\r
- unsigned int pr_flags; /* r/w flags */\r
- unsigned int pr_roflags; /* r/o flags */\r
-#define PR_NOWAIT 0x00 /* for symmetry */\r
-#define PR_WAITOK 0x02\r
-#define PR_WANTED 0x04\r
-#define PR_PHINPAGE 0x40\r
-#define PR_LOGGING 0x80\r
-#define PR_LIMITFAIL 0x100 /* even if waiting, fail if we hit limit */\r
-#define PR_RECURSIVE 0x200 /* pool contains pools, for vmstat(8) */\r
-#define PR_NOTOUCH 0x400 /* don't use free items to keep internal state*/\r
-#define PR_NOALIGN 0x800 /* don't assume backend alignment */\r
-\r
- /*\r
- * `pr_slock' protects the pool's data structures when removing\r
- * items from or returning items to the pool, or when reading\r
- * or updating read/write fields in the pool descriptor.\r
- *\r
- * We assume back-end page allocators provide their own locking\r
- * scheme. They will be called with the pool descriptor _unlocked_,\r
- * since the page allocators may block.\r
- */\r
- struct simplelock pr_slock;\r
-\r
- SPLAY_HEAD(phtree, pool_item_header) pr_phtree;\r
-\r
- int pr_maxcolor; /* Cache colouring */\r
- int pr_curcolor;\r
- int pr_phoffset; /* Offset in page of page header */\r
-\r
- /*\r
- * Warning message to be issued, and a per-time-delta rate cap,\r
- * if the hard limit is reached.\r
- */\r
- const char *pr_hardlimit_warning;\r
- struct timeval pr_hardlimit_ratecap;\r
- struct timeval pr_hardlimit_warning_last;\r
-\r
- /*\r
- * Instrumentation\r
- */\r
- unsigned long pr_nget; /* # of successful requests */\r
- unsigned long pr_nfail; /* # of unsuccessful requests */\r
- unsigned long pr_nput; /* # of releases */\r
- unsigned long pr_npagealloc; /* # of pages allocated */\r
- unsigned long pr_npagefree; /* # of pages released */\r
- unsigned int pr_hiwat; /* max # of pages in pool */\r
- unsigned long pr_nidle; /* # of idle pages */\r
-\r
- /*\r
- * Diagnostic aides.\r
- */\r
- struct pool_log *pr_log;\r
- int pr_curlogentry;\r
- int pr_logsize;\r
-\r
- const char *pr_entered_file; /* reentrancy check */\r
- long pr_entered_line;\r
-\r
-#if defined(_KERNEL)\r
- struct callback_entry pr_reclaimerentry;\r
-#endif\r
-};\r
-#endif /* __POOL_EXPOSE */\r
-\r
-#ifdef _KERNEL\r
-/*\r
- * pool_allocator_kmem is the default that all pools get unless\r
- * otherwise specified. pool_allocator_nointr is provided for\r
- * pools that know they will never be accessed in interrupt\r
- * context.\r
- */\r
-extern struct pool_allocator pool_allocator_kmem;\r
-extern struct pool_allocator pool_allocator_nointr;\r
-#ifdef POOL_SUBPAGE\r
-/* The above are subpage allocators in this case. */\r
-extern struct pool_allocator pool_allocator_kmem_fullpage;\r
-extern struct pool_allocator pool_allocator_nointr_fullpage;\r
-#endif\r
-\r
-struct link_pool_init { /* same as args to pool_init() */\r
- struct pool *pp;\r
- size_t size;\r
- u_int align;\r
- u_int align_offset;\r
- int flags;\r
- const char *wchan;\r
- struct pool_allocator *palloc;\r
-};\r
-#define POOL_INIT(pp, size, align, align_offset, flags, wchan, palloc) \\r
-struct pool pp; \\r
-static const struct link_pool_init _link_ ## pp[1] = { \\r
- { &pp, size, align, align_offset, flags, wchan, palloc } \\r
-}; \\r
-__link_set_add_rodata(pools, _link_ ## pp)\r
-\r
-void pool_subsystem_init(void);\r
-\r
-void pool_init(struct pool *, size_t, u_int, u_int,\r
- int, const char *, struct pool_allocator *);\r
-void pool_destroy(struct pool *);\r
-\r
-void pool_set_drain_hook(struct pool *,\r
- void (*)(void *, int), void *);\r
-\r
-void *pool_get(struct pool *, int);\r
-void pool_put(struct pool *, void *);\r
-int pool_reclaim(struct pool *);\r
-\r
-#ifdef POOL_DIAGNOSTIC\r
-/*\r
- * These versions do reentrancy checking.\r
- */\r
-void *_pool_get(struct pool *, int, const char *, long);\r
-void _pool_put(struct pool *, void *, const char *, long);\r
-int _pool_reclaim(struct pool *, const char *, long);\r
-#define pool_get(h, f) _pool_get((h), (f), __FILE__, __LINE__)\r
-#define pool_put(h, v) _pool_put((h), (v), __FILE__, __LINE__)\r
-#define pool_reclaim(h) _pool_reclaim((h), __FILE__, __LINE__)\r
-#endif /* POOL_DIAGNOSTIC */\r
-\r
-int pool_prime(struct pool *, int);\r
-void pool_setlowat(struct pool *, int);\r
-void pool_sethiwat(struct pool *, int);\r
-void pool_sethardlimit(struct pool *, int, const char *, int);\r
-void pool_drain(void *);\r
-\r
-/*\r
- * Debugging and diagnostic aides.\r
- */\r
-void pool_print(struct pool *, const char *);\r
-void pool_printit(struct pool *, const char *,\r
- void (*)(const char *, ...));\r
-void pool_printall(const char *, void (*)(const char *, ...));\r
-int pool_chk(struct pool *, const char *);\r
-\r
-/*\r
- * Pool cache routines.\r
- */\r
-void pool_cache_init(struct pool_cache *, struct pool *,\r
- int (*)(void *, void *, int),\r
- void (*)(void *, void *),\r
- void *);\r
-void pool_cache_destroy(struct pool_cache *);\r
-void *pool_cache_get_paddr(struct pool_cache *, int, paddr_t *);\r
-#define pool_cache_get(pc, f) pool_cache_get_paddr((pc), (f), NULL)\r
-void pool_cache_put_paddr(struct pool_cache *, void *, paddr_t);\r
-#define pool_cache_put(pc, o) pool_cache_put_paddr((pc), (o), \\r
- POOL_PADDR_INVALID)\r
-void pool_cache_destruct_object(struct pool_cache *, void *);\r
-void pool_cache_invalidate(struct pool_cache *);\r
-#endif /* _KERNEL */\r
-\r
-#endif /* _SYS_POOL_H_ */\r