SF_BUF(9)
β¨ NAME β¨
okay so bestie, welcome to sf_buf(9) from the Kernel Developer's Manual π. The whole vibe is: sf_buf β manage temporary kernel address space mapping for memory pages. Iconic little kernel helper.
πΈ 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 π
The sf_buf interface β historically the sendfile(2) buffer interface β lets kernel subsystems manage temporary kernel address space mappings for physical memory pages. No cap. On systems with a direct memory map region (allowing all physical pages to be visible in the kernel address space at all times), the struct sf_buf will point to an address in the direct map region; on systems without a direct memory map region, the struct sf_buf will manage a temporary kernel address space mapping valid for the lifetime of the struct sf_buf.
Call sf_buf_alloc() to allocate a struct sf_buf for a physical memory page. Important: 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 calling vm_page_wire(9). That part is on you, bestie. 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().
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 into sf_buf_alloc().
Call sf_buf_free() to release the struct sf_buf reference. 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. Read that again: the mapping goes, but the page itself is not released by this call.
π bestie warning: you still own the wiring on that physical page after this call.
Uses of this interface include managing mappings of borrowed pages from user memory, such as in zero-copy socket I/O, or pages of memory from the buffer cache referenced by mbuf external storage for sendfile(2). Very sendfile-core, iykyk.
π₯ 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. Respect the kernel legends.
cute sign-off: Debian Β· January 28, 2007 Β· SF_BUF(9) β bye bestie, go wire those pages responsibly π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2007 Seccuris Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms