2 .\" Copyright (c) 2010, The DragonFly Project.
4 .\" This software is derived from software contributed to the DragonFly Project
5 .\" by Venkatesh Srinivas <me@endeavour.zapto.org>.
7 .\" Permission to use, copy, modify, or distribute this software for any
8 .\" purpose with or without fee is hereby granted, provided that the above
9 .\" copyright notice and this permission notice appear in all copies.
11 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR OTHER DAMAGES
15 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN
16 .\" ACTION OF CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 .Nm mpipe_alloc_nowait ,
26 .Nm mpipe_alloc_waitok ,
32 .Fn mpipe_init "malloc_pipe_t mpipe" "malloc_type_t type" "int bytes" \
33 "int nnom" "int nmax" "int mpflags" \
34 "void (*destructor)(struct malloc_pipe *, void *)"
36 .Fn mpipe_done "malloc_pipe_t mpipe"
38 .Fn mpipe_alloc_nowait "malloc_pipe_t mpipe"
40 .Fn mpipe_alloc_waitok "malloc_pipe_t mpipe"
42 .Fn mpipe_free "malloc_pipe_t mpipe" "void *buf"
45 A malloc pipeline is a linear pool of buffers of a single type.
47 pipeline guarantees a number of outstanding allocations and provides both
48 blocking and non-blocking behavior above the guaranteed allocation amounts.
49 A malloc pipeline can have an upper limit, beyond which allocations sleep
51 Malloc pipelines are intended for situations where
52 a minimum number of buffers are required to make progress.
56 function initializes a malloc pipeline
58 The pipeline allocates buffers of size
62 The pipeline is prefilled with
64 buffers and has a limit of
69 argument is a callback, invoked when the malloc pipeline is destroyed.
72 argument controls allocation parameters:
73 .Bl -tag -width ".Dv MPF_NOZERO" -offset indent
75 Do not zero allocated buffers.
77 Allocations may use the interrupt memory reserve.
80 This function may block.
84 function destroys a malloc pipeline.
85 The pipeline's destructor is invoked on
86 each buffer and then they are returned to the system.
87 It is an error to invoke
88 this function on a pipeline with outstanding allocations.
89 This function may block.
92 .Fn mpipe_alloc_nowait
93 function allocates a buffer from the malloc pipeline.
94 It will first allocate from the pipeline itself; if that is exhausted,
97 up to the pipeline maximum.
98 This function may not block.
101 .Fn mpipe_alloc_waitok
102 function allocates a buffer from the malloc pipeline.
103 It will first allocate from the pipeline; if that is exhausted,
106 up to the pipeline maximum.
107 It will sleep if it reaches the maximum, potentially releasing any tokens.
111 function frees a buffer to the malloc pipeline.
112 If the pipeline is full, it will free directly to the kernel allocator,
113 calling the destructor as it does.
114 This function may block.
116 The mpipe functions do not synchronize access to a pipeline.
117 It is up to higher-level code to use appropriate locks to ensure that
118 multiple CPUs are not simultaneously accessing a pipeline.
119 The pipeline functions do
120 guard against preemption by entering critical sections.
122 The MPIPE implementation is in
123 .Pa /sys/kern/kern_mpipe.c .
127 MPIPE first appeared in