LWBUF(9)

NAME
lwbuf_alloc, lwbuf_free, lwbuf_page, lwbuf_kva, lwbuf_set_global - lightweight buffers

SYNOPSIS
#include <cpu/lwbuf.h>
struct lwbuf *
lwbuf_alloc(vm_page_t m, struct lwbuf *);
void
lwbuf_free(struct lwbuf *lwb);
vm_page_t
lwbuf_page(struct lwbuf *lwb);
vm_offset_t
lwbuf_kva(struct lwbuf *lwb);
void
lwbuf_set_global(struct lwbuf *lwb);

DESCRIPTION
The lwbuf kernel functions are used for maintaining a lightweight reference to and accessing an arbitrary vm_page_t.

lwbuf_alloc() returns a pointer to a lightweight buffer representing m. The lwb argument is an lwbuf structure, used to avoid allocation of an lwbuf on the x86_64 architecture.

lwbuf_free() frees all resources associated with the lightweight buffer lwb.

lwbuf_page() and lwbuf_kva() return the associated vm_page_t or vm_offset_t of the lightweight buffer lwb.

lwbuf_set_global() ensures that a vm_offset_t previously obtained through lwbuf_kva will be valid on all processors without subsequent calls to lwbuf_kva. It should not be used.

IMPLEMENTATION NOTES
The implementation of lwbuf is CPU-dependent. On x86_64 the kernel maintains a direct map of KVA covering all physical memory.

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.

HISTORY
A lwbuf implementation first appeared in DragonFly 2.5.

AUTHORS
The lwbuf implementation and this manpage were written by Samuel J. Greear.