/* $NetBSD: pool.h,v 1.54 2006/08/20 09:35:25 yamt Exp $ */
/*-
* Copyright (c) 1997, 1998, 1999, 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Paul Kranenburg; by Jason R. Thorpe of the Numerical Aerospace
* Simulation Facility, NASA Ames Research Center.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _SYS_POOL_H_
#define _SYS_POOL_H_
#ifdef _KERNEL
#define __POOL_EXPOSE
#endif
#if defined(_KERNEL_OPT)
#include "opt_pool.h"
#endif
#ifdef __POOL_EXPOSE
#if defined(_KERNEL)
#include <sys/callback.h>
#endif /* defined(_KERNEL) */
#endif
#ifdef __POOL_EXPOSE
/* The pool cache group. */
struct pool_cache_group {
/* pointers to the objects */
struct {
};
struct pool_cache {
struct pool_cache_grouplist
struct pool_cache_grouplist
struct pool_cache_grouplist
int (*pc_ctor)(void *, void *, int);
void (*pc_dtor)(void *, void *);
void *pc_arg;
/* Statistics. */
};
struct pool_allocator {
unsigned int pa_pagesz;
/* The following fields are for internal use only. */
int pa_flags;
int pa_pagemask;
int pa_pageshift;
#if defined(_KERNEL)
#endif /* defined(_KERNEL) */
};
struct pool {
struct pool_pagelist
struct pool_pagelist
struct pool_pagelist
items */
/* Drain hook. */
void (*pr_drain_hook)(void *, int);
void *pr_drain_hook_arg;
/*
* `pr_slock' protects the pool's data structures when removing
* items from or returning items to the pool, or when reading
*
* We assume back-end page allocators provide their own locking
* scheme. They will be called with the pool descriptor _unlocked_,
* since the page allocators may block.
*/
int pr_curcolor;
/*
* Warning message to be issued, and a per-time-delta rate cap,
* if the hard limit is reached.
*/
const char *pr_hardlimit_warning;
/*
* Instrumentation
*/
/*
* Diagnostic aides.
*/
int pr_curlogentry;
int pr_logsize;
long pr_entered_line;
#if defined(_KERNEL)
#endif
};
#endif /* __POOL_EXPOSE */
#ifdef _KERNEL
/*
* pool_allocator_kmem is the default that all pools get unless
* otherwise specified. pool_allocator_nointr is provided for
* pools that know they will never be accessed in interrupt
* context.
*/
extern struct pool_allocator pool_allocator_kmem;
extern struct pool_allocator pool_allocator_nointr;
#ifdef POOL_SUBPAGE
/* The above are subpage allocators in this case. */
extern struct pool_allocator pool_allocator_kmem_fullpage;
extern struct pool_allocator pool_allocator_nointr_fullpage;
#endif
int flags;
const char *wchan;
};
}; \
void pool_subsystem_init(void);
int, const char *, struct pool_allocator *);
void pool_destroy(struct pool *);
void pool_set_drain_hook(struct pool *,
void (*)(void *, int), void *);
int pool_reclaim(struct pool *);
#ifdef POOL_DIAGNOSTIC
/*
* These versions do reentrancy checking.
*/
int _pool_reclaim(struct pool *, const char *, long);
#endif /* POOL_DIAGNOSTIC */
int pool_prime(struct pool *, int);
void pool_setlowat(struct pool *, int);
void pool_sethiwat(struct pool *, int);
void pool_sethardlimit(struct pool *, int, const char *, int);
void pool_drain(void *);
/*
* Debugging and diagnostic aides.
*/
void pool_print(struct pool *, const char *);
void pool_printit(struct pool *, const char *,
void (*)(const char *, ...));
void pool_printall(const char *, void (*)(const char *, ...));
/*
* Pool cache routines.
*/
int (*)(void *, void *, int),
void (*)(void *, void *),
void *);
void pool_cache_destroy(struct pool_cache *);
void pool_cache_destruct_object(struct pool_cache *, void *);
void pool_cache_invalidate(struct pool_cache *);
#endif /* _KERNEL */
#endif /* _SYS_POOL_H_ */