xref: /dflybsd-src/share/man/man9/mpipe.9 (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino.\"
286d7f5d3SJohn Marino.\" Copyright (c) 2010, The DragonFly Project.
386d7f5d3SJohn Marino.\"
486d7f5d3SJohn Marino.\" This software is derived from software contributed to the DragonFly Project
586d7f5d3SJohn Marino.\" by Venkatesh Srinivas <me@endeavour.zapto.org>.
686d7f5d3SJohn Marino.\"
786d7f5d3SJohn Marino.\" Permission to use, copy, modify, or distribute this software for any
886d7f5d3SJohn Marino.\" purpose with or without fee is hereby granted, provided that the above
986d7f5d3SJohn Marino.\" copyright notice and this permission notice appear in all copies.
1086d7f5d3SJohn Marino.\"
1186d7f5d3SJohn Marino.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1286d7f5d3SJohn Marino.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1386d7f5d3SJohn Marino.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1486d7f5d3SJohn Marino.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR OTHER DAMAGES
1586d7f5d3SJohn Marino.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN
1686d7f5d3SJohn Marino.\" ACTION OF CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF
1786d7f5d3SJohn Marino.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1886d7f5d3SJohn Marino.\"
1986d7f5d3SJohn Marino.Dd December 21, 2010
2086d7f5d3SJohn Marino.Dt MPIPE 9
2186d7f5d3SJohn Marino.Os
2286d7f5d3SJohn Marino.Sh NAME
2386d7f5d3SJohn Marino.Nm mpipe_init ,
2486d7f5d3SJohn Marino.Nm mpipe_done ,
2586d7f5d3SJohn Marino.Nm mpipe_alloc_nowait ,
2686d7f5d3SJohn Marino.Nm mpipe_alloc_waitok ,
2786d7f5d3SJohn Marino.Nm mpipe_free
2886d7f5d3SJohn Marino.Nd malloc pipelines
2986d7f5d3SJohn Marino.Sh SYNOPSIS
3086d7f5d3SJohn Marino.In sys/mpipe.h
3186d7f5d3SJohn Marino.Ft void
3286d7f5d3SJohn Marino.Fn mpipe_init "malloc_pipe_t mpipe" "malloc_type_t type" "int bytes" \
3386d7f5d3SJohn Marino"int nnom" "int nmax" "int mpflags" \
3486d7f5d3SJohn Marino"void (*construct)(void *, void *)" \
3586d7f5d3SJohn Marino"void (*deconstruct)(void *, void *)" \
3686d7f5d3SJohn Marino"void *priv"
3786d7f5d3SJohn Marino.Ft void
3886d7f5d3SJohn Marino.Fn mpipe_done "malloc_pipe_t mpipe"
3986d7f5d3SJohn Marino.Ft void *
4086d7f5d3SJohn Marino.Fn mpipe_alloc_nowait "malloc_pipe_t mpipe"
4186d7f5d3SJohn Marino.Ft void *
4286d7f5d3SJohn Marino.Fn mpipe_alloc_waitok "malloc_pipe_t mpipe"
4386d7f5d3SJohn Marino.Ft void
4486d7f5d3SJohn Marino.Fn mpipe_free "malloc_pipe_t mpipe" "void *buf"
4586d7f5d3SJohn Marino.Sh DESCRIPTION
4686d7f5d3SJohn MarinoA malloc pipeline is a linear pool of buffers of a single type.
4786d7f5d3SJohn MarinoA malloc
4886d7f5d3SJohn Marinopipeline guarantees a number of outstanding allocations and provides both
4986d7f5d3SJohn Marinoblocking and non-blocking behavior above the guaranteed allocation amounts.
5086d7f5d3SJohn MarinoA malloc pipeline can have an upper limit, beyond which allocations sleep
5186d7f5d3SJohn Marinoor fail respectively.
5286d7f5d3SJohn MarinoMalloc pipelines are intended for situations where
5386d7f5d3SJohn Marinoa minimum number of buffers are required to make progress.
5486d7f5d3SJohn Marino.Pp
5586d7f5d3SJohn MarinoThe
5686d7f5d3SJohn Marino.Fn mpipe_init
5786d7f5d3SJohn Marinofunction initializes a malloc pipeline
5886d7f5d3SJohn Marino.Fa mpipe .
5986d7f5d3SJohn MarinoThe pipeline allocates buffers of size
6086d7f5d3SJohn Marino.Fa bytes
6186d7f5d3SJohn Marinofrom the malloc zone
6286d7f5d3SJohn Marino.Fa type .
6386d7f5d3SJohn MarinoThe pipeline is prefilled with
6486d7f5d3SJohn Marino.Fa nnom
6586d7f5d3SJohn Marinobuffers and has a limit of
6686d7f5d3SJohn Marino.Fa nmax
6786d7f5d3SJohn Marinobuffers.
6886d7f5d3SJohn MarinoThe
6986d7f5d3SJohn Marino.Fa construct
7086d7f5d3SJohn Marinoargument is a callback, invoked when a buffer is allocated from the system.
7186d7f5d3SJohn MarinoThe
7286d7f5d3SJohn Marino.Fa deconstruct
7386d7f5d3SJohn Marinoargument is a callback, invoked when the malloc pipeline is destroyed or a
7486d7f5d3SJohn Marinobuffer is freed to the system.
7586d7f5d3SJohn MarinoBoth
7686d7f5d3SJohn Marino.Fa construct
7786d7f5d3SJohn Marinoand
7886d7f5d3SJohn Marino.Fa deconstruct
7986d7f5d3SJohn Marinoare invoked with the buffer address as their first parameter and with
8086d7f5d3SJohn Marino.Fa priv
8186d7f5d3SJohn Marinoas their second parameter.
8286d7f5d3SJohn MarinoThe
8386d7f5d3SJohn Marino.Fa flags
8486d7f5d3SJohn Marinoargument controls allocation parameters:
8586d7f5d3SJohn Marino.Bl -tag -width ".Dv MPF_NOZERO" -offset indent
8686d7f5d3SJohn Marino.It Dv MPF_NOZERO
8786d7f5d3SJohn MarinoDo not zero allocated buffers.
8886d7f5d3SJohn Marino.It Dv MPF_CACHEDATA
8986d7f5d3SJohn MarinoBy default, MPIPE buffers are zeroed on free; this flag disables that behavior.
9086d7f5d3SJohn Marino.It Dv MPF_INT
9186d7f5d3SJohn MarinoAllocations may use the interrupt memory reserve.
9286d7f5d3SJohn Marino.El
9386d7f5d3SJohn Marino.Pp
9486d7f5d3SJohn MarinoThis function may block.
9586d7f5d3SJohn Marino.Pp
9686d7f5d3SJohn MarinoThe
9786d7f5d3SJohn Marino.Fn mpipe_done
9886d7f5d3SJohn Marinofunction destroys a malloc pipeline.
9986d7f5d3SJohn MarinoThe pipeline's destructor is invoked on
10086d7f5d3SJohn Marinoeach buffer and then they are returned to the system.
10186d7f5d3SJohn MarinoIt is an error to invoke
10286d7f5d3SJohn Marinothis function on a pipeline with outstanding allocations.
10386d7f5d3SJohn MarinoThis function may block.
10486d7f5d3SJohn Marino.Pp
10586d7f5d3SJohn MarinoThe
10686d7f5d3SJohn Marino.Fn mpipe_alloc_nowait
10786d7f5d3SJohn Marinofunction allocates a buffer from the malloc pipeline.
10886d7f5d3SJohn MarinoIt will first allocate from the pipeline itself; if that is exhausted,
10986d7f5d3SJohn Marinoit will fall back on
11086d7f5d3SJohn Marino.Xr kmalloc 9 ,
11186d7f5d3SJohn Marinoup to the pipeline maximum.
11286d7f5d3SJohn MarinoThis function may not block.
11386d7f5d3SJohn Marino.Pp
11486d7f5d3SJohn MarinoThe
11586d7f5d3SJohn Marino.Fn mpipe_alloc_waitok
11686d7f5d3SJohn Marinofunction allocates a buffer from the malloc pipeline.
11786d7f5d3SJohn MarinoIt will first allocate from the pipeline; if that is exhausted,
11886d7f5d3SJohn Marinoit will fall back on
11986d7f5d3SJohn Marino.Xr kmalloc 9 ,
12086d7f5d3SJohn Marinoup to the pipeline maximum.
12186d7f5d3SJohn MarinoIt will sleep if it reaches the maximum, potentially releasing any tokens.
12286d7f5d3SJohn Marino.Pp
12386d7f5d3SJohn MarinoThe
12486d7f5d3SJohn Marino.Fn mpipe_free
12586d7f5d3SJohn Marinofunction frees a buffer to the malloc pipeline.
12686d7f5d3SJohn MarinoIf the pipeline is full, it will free directly to the kernel allocator,
12786d7f5d3SJohn Marinocalling the destructor as it does.
12886d7f5d3SJohn MarinoThis function may block.
12986d7f5d3SJohn Marino.Sh FILES
13086d7f5d3SJohn MarinoThe MPIPE implementation is in
13186d7f5d3SJohn Marino.Pa /sys/kern/kern_mpipe.c .
13286d7f5d3SJohn Marino.Sh SEE ALSO
13386d7f5d3SJohn Marino.Xr memory 9
13486d7f5d3SJohn Marino.Sh HISTORY
13586d7f5d3SJohn MarinoMPIPE first appeared in
13686d7f5d3SJohn Marino.Dx 1.0 .
137