xref: /dflybsd-src/share/man/man9/mpipe.9 (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
1*86d7f5d3SJohn Marino.\"
2*86d7f5d3SJohn Marino.\" Copyright (c) 2010, The DragonFly Project.
3*86d7f5d3SJohn Marino.\"
4*86d7f5d3SJohn Marino.\" This software is derived from software contributed to the DragonFly Project
5*86d7f5d3SJohn Marino.\" by Venkatesh Srinivas <me@endeavour.zapto.org>.
6*86d7f5d3SJohn Marino.\"
7*86d7f5d3SJohn Marino.\" Permission to use, copy, modify, or distribute this software for any
8*86d7f5d3SJohn Marino.\" purpose with or without fee is hereby granted, provided that the above
9*86d7f5d3SJohn Marino.\" copyright notice and this permission notice appear in all copies.
10*86d7f5d3SJohn Marino.\"
11*86d7f5d3SJohn Marino.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12*86d7f5d3SJohn Marino.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13*86d7f5d3SJohn Marino.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14*86d7f5d3SJohn Marino.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR OTHER DAMAGES
15*86d7f5d3SJohn Marino.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN
16*86d7f5d3SJohn Marino.\" ACTION OF CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF
17*86d7f5d3SJohn Marino.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18*86d7f5d3SJohn Marino.\"
19*86d7f5d3SJohn Marino.Dd December 21, 2010
20*86d7f5d3SJohn Marino.Dt MPIPE 9
21*86d7f5d3SJohn Marino.Os
22*86d7f5d3SJohn Marino.Sh NAME
23*86d7f5d3SJohn Marino.Nm mpipe_init ,
24*86d7f5d3SJohn Marino.Nm mpipe_done ,
25*86d7f5d3SJohn Marino.Nm mpipe_alloc_nowait ,
26*86d7f5d3SJohn Marino.Nm mpipe_alloc_waitok ,
27*86d7f5d3SJohn Marino.Nm mpipe_free
28*86d7f5d3SJohn Marino.Nd malloc pipelines
29*86d7f5d3SJohn Marino.Sh SYNOPSIS
30*86d7f5d3SJohn Marino.In sys/mpipe.h
31*86d7f5d3SJohn Marino.Ft void
32*86d7f5d3SJohn Marino.Fn mpipe_init "malloc_pipe_t mpipe" "malloc_type_t type" "int bytes" \
33*86d7f5d3SJohn Marino"int nnom" "int nmax" "int mpflags" \
34*86d7f5d3SJohn Marino"void (*construct)(void *, void *)" \
35*86d7f5d3SJohn Marino"void (*deconstruct)(void *, void *)" \
36*86d7f5d3SJohn Marino"void *priv"
37*86d7f5d3SJohn Marino.Ft void
38*86d7f5d3SJohn Marino.Fn mpipe_done "malloc_pipe_t mpipe"
39*86d7f5d3SJohn Marino.Ft void *
40*86d7f5d3SJohn Marino.Fn mpipe_alloc_nowait "malloc_pipe_t mpipe"
41*86d7f5d3SJohn Marino.Ft void *
42*86d7f5d3SJohn Marino.Fn mpipe_alloc_waitok "malloc_pipe_t mpipe"
43*86d7f5d3SJohn Marino.Ft void
44*86d7f5d3SJohn Marino.Fn mpipe_free "malloc_pipe_t mpipe" "void *buf"
45*86d7f5d3SJohn Marino.Sh DESCRIPTION
46*86d7f5d3SJohn MarinoA malloc pipeline is a linear pool of buffers of a single type.
47*86d7f5d3SJohn MarinoA malloc
48*86d7f5d3SJohn Marinopipeline guarantees a number of outstanding allocations and provides both
49*86d7f5d3SJohn Marinoblocking and non-blocking behavior above the guaranteed allocation amounts.
50*86d7f5d3SJohn MarinoA malloc pipeline can have an upper limit, beyond which allocations sleep
51*86d7f5d3SJohn Marinoor fail respectively.
52*86d7f5d3SJohn MarinoMalloc pipelines are intended for situations where
53*86d7f5d3SJohn Marinoa minimum number of buffers are required to make progress.
54*86d7f5d3SJohn Marino.Pp
55*86d7f5d3SJohn MarinoThe
56*86d7f5d3SJohn Marino.Fn mpipe_init
57*86d7f5d3SJohn Marinofunction initializes a malloc pipeline
58*86d7f5d3SJohn Marino.Fa mpipe .
59*86d7f5d3SJohn MarinoThe pipeline allocates buffers of size
60*86d7f5d3SJohn Marino.Fa bytes
61*86d7f5d3SJohn Marinofrom the malloc zone
62*86d7f5d3SJohn Marino.Fa type .
63*86d7f5d3SJohn MarinoThe pipeline is prefilled with
64*86d7f5d3SJohn Marino.Fa nnom
65*86d7f5d3SJohn Marinobuffers and has a limit of
66*86d7f5d3SJohn Marino.Fa nmax
67*86d7f5d3SJohn Marinobuffers.
68*86d7f5d3SJohn MarinoThe
69*86d7f5d3SJohn Marino.Fa construct
70*86d7f5d3SJohn Marinoargument is a callback, invoked when a buffer is allocated from the system.
71*86d7f5d3SJohn MarinoThe
72*86d7f5d3SJohn Marino.Fa deconstruct
73*86d7f5d3SJohn Marinoargument is a callback, invoked when the malloc pipeline is destroyed or a
74*86d7f5d3SJohn Marinobuffer is freed to the system.
75*86d7f5d3SJohn MarinoBoth
76*86d7f5d3SJohn Marino.Fa construct
77*86d7f5d3SJohn Marinoand
78*86d7f5d3SJohn Marino.Fa deconstruct
79*86d7f5d3SJohn Marinoare invoked with the buffer address as their first parameter and with
80*86d7f5d3SJohn Marino.Fa priv
81*86d7f5d3SJohn Marinoas their second parameter.
82*86d7f5d3SJohn MarinoThe
83*86d7f5d3SJohn Marino.Fa flags
84*86d7f5d3SJohn Marinoargument controls allocation parameters:
85*86d7f5d3SJohn Marino.Bl -tag -width ".Dv MPF_NOZERO" -offset indent
86*86d7f5d3SJohn Marino.It Dv MPF_NOZERO
87*86d7f5d3SJohn MarinoDo not zero allocated buffers.
88*86d7f5d3SJohn Marino.It Dv MPF_CACHEDATA
89*86d7f5d3SJohn MarinoBy default, MPIPE buffers are zeroed on free; this flag disables that behavior.
90*86d7f5d3SJohn Marino.It Dv MPF_INT
91*86d7f5d3SJohn MarinoAllocations may use the interrupt memory reserve.
92*86d7f5d3SJohn Marino.El
93*86d7f5d3SJohn Marino.Pp
94*86d7f5d3SJohn MarinoThis function may block.
95*86d7f5d3SJohn Marino.Pp
96*86d7f5d3SJohn MarinoThe
97*86d7f5d3SJohn Marino.Fn mpipe_done
98*86d7f5d3SJohn Marinofunction destroys a malloc pipeline.
99*86d7f5d3SJohn MarinoThe pipeline's destructor is invoked on
100*86d7f5d3SJohn Marinoeach buffer and then they are returned to the system.
101*86d7f5d3SJohn MarinoIt is an error to invoke
102*86d7f5d3SJohn Marinothis function on a pipeline with outstanding allocations.
103*86d7f5d3SJohn MarinoThis function may block.
104*86d7f5d3SJohn Marino.Pp
105*86d7f5d3SJohn MarinoThe
106*86d7f5d3SJohn Marino.Fn mpipe_alloc_nowait
107*86d7f5d3SJohn Marinofunction allocates a buffer from the malloc pipeline.
108*86d7f5d3SJohn MarinoIt will first allocate from the pipeline itself; if that is exhausted,
109*86d7f5d3SJohn Marinoit will fall back on
110*86d7f5d3SJohn Marino.Xr kmalloc 9 ,
111*86d7f5d3SJohn Marinoup to the pipeline maximum.
112*86d7f5d3SJohn MarinoThis function may not block.
113*86d7f5d3SJohn Marino.Pp
114*86d7f5d3SJohn MarinoThe
115*86d7f5d3SJohn Marino.Fn mpipe_alloc_waitok
116*86d7f5d3SJohn Marinofunction allocates a buffer from the malloc pipeline.
117*86d7f5d3SJohn MarinoIt will first allocate from the pipeline; if that is exhausted,
118*86d7f5d3SJohn Marinoit will fall back on
119*86d7f5d3SJohn Marino.Xr kmalloc 9 ,
120*86d7f5d3SJohn Marinoup to the pipeline maximum.
121*86d7f5d3SJohn MarinoIt will sleep if it reaches the maximum, potentially releasing any tokens.
122*86d7f5d3SJohn Marino.Pp
123*86d7f5d3SJohn MarinoThe
124*86d7f5d3SJohn Marino.Fn mpipe_free
125*86d7f5d3SJohn Marinofunction frees a buffer to the malloc pipeline.
126*86d7f5d3SJohn MarinoIf the pipeline is full, it will free directly to the kernel allocator,
127*86d7f5d3SJohn Marinocalling the destructor as it does.
128*86d7f5d3SJohn MarinoThis function may block.
129*86d7f5d3SJohn Marino.Sh FILES
130*86d7f5d3SJohn MarinoThe MPIPE implementation is in
131*86d7f5d3SJohn Marino.Pa /sys/kern/kern_mpipe.c .
132*86d7f5d3SJohn Marino.Sh SEE ALSO
133*86d7f5d3SJohn Marino.Xr memory 9
134*86d7f5d3SJohn Marino.Sh HISTORY
135*86d7f5d3SJohn MarinoMPIPE first appeared in
136*86d7f5d3SJohn Marino.Dx 1.0 .
137