.\" Copyright (c) 2010 by The DragonFly Project and Samuel J. Greear. .\" All rights reserved. .\" .\" This code is derived from software contributed to The DragonFly Project .\" by Samuel J. Greear .\" .\" 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 documentation and/or other materials provided with the .\" distribution. .\" 3. Neither the name of The DragonFly Project 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 COPYRIGHT HOLDERS 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 .\" COPYRIGHT HOLDERS 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. .\" " .Dd March 17, 2010 .Os .Dt lwbuf 9 .Sh NAME .Nm lwbuf_alloc , .Nm lwbuf_free , .Nm lwbuf_page , .Nm lwbuf_kva , .Nm lwbuf_set_global .Nd "Lightweight buffers" .Sh SYNOPSIS .In cpu/lwbuf.h .Ft "struct lwbuf *" .Fn lwbuf_alloc "vm_page_t m" .Ft void .Fn lwbuf_free "struct lwbuf *lwb" .Ft vm_page_t .Fn lwbuf_page "struct lwbuf *lwb" .Ft vm_offset_t .Fn lwbuf_kva "struct lwbuf *lwb" .Ft void .Fn lwbuf_set_global "struct lwbuf *lwb" .Sh DESCRIPTION The .Fa lwbuf kernel functions are used for maintaining a lightweight reference to and accessing an arbitrary .Fa vm_page_t . .Pp .Fn lwbuf_alloc returns a pointer to a lightweight buffer representing .Fa m . .Pp .Fn lwbuf_free frees all resources associated with the lightweight buffer .Fa lwb . .Pp .Fn lwbuf_page and .Fn lwbuf_kva return the associated .Fa vm_page_t or .Fa vm_offset_t of the lightweight buffer .Fa lwb . .Pp .Fn lwbuf_set_global ensures that a vm_offset_t previously obtained through .Fa lwbuf_kva will be valid on all processors without subsequent calls to .Fa lwbuf_kva . It should not be used. .Sh IMPLEMENTATION NOTES The implementation of .Fa lwbuf is cpu-dependent. On i386, pages taken from per-processor pools of kernel virtual address space (KVA) are used to map arbitrary .Fa vm_page_t objects. On x86_64 such tricks are unnecessary, the kernel maintains a direct map of KVA covering all physical memory. .Pp Lightweight buffers are thread and cross-processor safe with a number of limitations. Allocated buffers are not internally cached or reference counted. Any consumer of lightweight buffers may elect to share allocated buffers or allow them to be used in other threads or on other processors, but care must be taken. Buffers must be externally refcounted or in some other manner freed only after last use. .Sh HISTORY A .Nm lwbuf implementation first appeared in .Dx 2.5 . .Sh Authors The .Nm lwbuf implementation and this manpage were written by .An Samuel J. Greear .