SF_BUF(9)
π SF_BUF(9) π
okay bestie, gather round, because this is a Kernel Developer's Manual page (section 9, the cool section) and it's all about sf_buf β the girlies who manage temporary kernel address space mapping for memory pages β¨
πΈ NAME πΈ
sf_buf β manage temporary kernel address space mapping for memory pages
π SYNOPSIS π
#include <sys/sf_buf.h>
struct sf_buf *
sf_buf_alloc(struct vm_page *m, int flags);
void
sf_buf_free(struct sf_buf *sf);
vm_offset_t
sf_buf_kva(struct sf_buf *sf);
struct vm_page *
sf_buf_page(struct sf_buf *sf);
π¦ DESCRIPTION π¦
so the sf_buf interface β historically known as the sendfile(2) buffer interface, ikyk β lets kernel subsystems manage temporary kernel address space mappings for physical memory pages. literally its whole job π
here's the tea on how it works, depending on your system:
- on systems with a direct memory map region (meaning all physical pages are visible in the kernel address space at all times), the
struct sf_bufwill point to an address in the direct map region - on systems without a direct memory map region, the
struct sf_bufwill manage a temporary kernel address space mapping that's valid for the lifetime of thestruct sf_buf
periodt. moving on π«Ά
β¨ allocating: sf_buf_alloc() β¨
call sf_buf_alloc() to allocate a struct sf_buf for a physical memory page.
β οΈ heads up bestie:sf_buf_alloc()is not responsible for arranging for the page to be present in physical memory. the caller should already have arranged for the page to be wired, i.e., by callingvm_page_wire(9). no cap, that's on you.
several flags may be passed to sf_buf_alloc():
SFB_CATCHβ causesf_buf_alloc()to abort and returnNULLif a signal is received waiting for astruct sf_bufto become available.SFB_NOWAITβ causesf_buf_alloc()to returnNULLrather than sleeping if astruct sf_bufis not immediately available.SFB_CPUPRIVATEβ causesf_buf_alloc()to only arrange that the temporary mapping be valid on the current CPU, avoiding unnecessary TLB shootdowns for mappings that will only be accessed on a single CPU at a time. the caller must ensure that accesses to the virtual address occur only on the CPU from whichsf_buf_alloc()was invoked, perhaps by usingsched_pin(). π (main character CPU energy, we love to see it)
π the getters π
- call
sf_buf_kva()to return a kernel mapped address for the page. π - call
sf_buf_page()to return a pointer to the page originally passed intosf_buf_alloc(). π―
π freeing: sf_buf_free() π
call sf_buf_free() to release the struct sf_buf reference.
π bestie listen: the caller is responsible for releasing any wiring they have previously acquired on the physical page. sf_buf_free() releases only the temporary kernel address space mapping, not the page itself. don't get it twisted.
π§ where you'll see this queen in the wild
uses of this interface include:
- managing mappings of borrowed pages from user memory, such as in zero-copy socket I/O π₯
- pages of memory from the buffer cache referenced by mbuf external storage for
sendfile(2)β
it's giving foundational, honestly.
π SEE ALSO π
π AUTHORS π
the struct sf_buf API was designed and implemented by Alan L. Cox. this manual page was written by Robert N. M. Watson.
πΈ and that's the whole page, bestie! this one came from the Debian edition of the Kernel Developer's Manual, dated January 28, 2007, filed under SF_BUF(9). slay, read responsibly, and don't forget to free your buffers π β¨π
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2007 Seccuris Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms