2 * Copyright (c) 2003 Matthew Dillon <dillon@backplane.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $DragonFly: src/sys/sys/mpipe.h,v 1.3 2004/06/04 06:56:11 dillon Exp $
32 #ifndef _SYS_MALLOC_H_
33 #include <sys/malloc.h>
37 * Pipeline memory allocations with persistent store capabilities. This
38 * implements a pipeline for allocations of a particular size. It is used
39 * in order to allow memory allocations to block while at the same time
40 * guarenteeing that no deadlocks will occur.
42 * By default new allocations are zero'd out.
44 * MPF_NOZERO If specified the underlying buffers are not zero'd.
45 * Note this also means you have no way of knowing which
46 * buffers are coming from the cache and which are new
49 * MPF_CACHEDATA If specified the deconstructor will be called when
50 * the underlying buffer is free()'d, but the buffer may
51 * be reused many times before/if that happens. The
52 * buffer is NOT zero'd on reuse regardless of the
55 * If not specified and MPF_NOZERO is also not specified,
56 * then buffers reused from the cache will be zero'd as
57 * well as new allocations.
59 * Note that the deconstructor function may still be NULL
60 * if this flag is specified, meaning that you don't need
61 * notification when the cached contents is physically
64 * MPF_INT Use the interrupt reserve if necessary.
69 malloc_type_t type; /* malloc bucket */
70 int bytes; /* allocation size */
71 int mpflags; /* MPF_ flags */
72 int mflags; /* M_ flags (used internally) */
73 int pending; /* there is a request pending */
74 int free_count; /* entries in array[] */
75 int total_count; /* total outstanding allocations incl free */
76 int ary_count; /* guarenteed allocation count */
77 int max_count; /* maximum count (M_NOWAIT used beyond nom) */
78 void **array; /* array[ary_count] */
79 void (*deconstruct)(struct malloc_pipe *, void *buf);
82 #define MPF_CACHEDATA 0x0001 /* cache old buffers (do not zero) */
83 #define MPF_NOZERO 0x0002 /* do not zero-out new allocations */
84 #define MPF_INT 0x0004 /* use the interrupt memory reserve */
86 typedef struct malloc_pipe *malloc_pipe_t;
90 void mpipe_init(malloc_pipe_t mpipe, malloc_type_t type,
91 int bytes, int nnom, int nmax,
92 int mpflags, void (*deconstruct)(struct malloc_pipe *, void *));
93 void mpipe_done(malloc_pipe_t mpipe);
94 void *mpipe_alloc_waitok(malloc_pipe_t mpipe);
95 void *mpipe_alloc_nowait(malloc_pipe_t mpipe);
96 void mpipe_free(malloc_pipe_t mpipe, void *vbuf);