---
name: "sf_buf"
section: "9"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/sf_buf"
---

# sf\_buf(9)

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

The **sf\_buf** interface, historically the [sendfile(2)](/sendfile/2.md) buffer interface, allows kernel subsystems to manage temporary kernel address space mappings for physical memory pages. 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. **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)](/vm_page_wire/9.md). Several flags may be passed to **sf\_buf\_alloc**():

- SFB\_CATCH

  Cause **sf\_buf\_alloc**() to abort and return NULL if a signal is received waiting for a *struct sf\_buf* to become available.

- SFB\_NOWAIT

  Cause **sf\_buf\_alloc**() to return NULL rather than sleeping if a *struct sf\_buf* is not immediately available.

- SFB\_CPUPRIVATE

  Cause **sf\_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 which **sf\_buf\_alloc**() was invoked, perhaps by using **sched\_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.

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)](/sendfile/2.md).

## SEE ALSO

[sendfile(2)](/sendfile/2.md), [vm\_page\_wire(9)](/vm_page_wire/9.md)

## AUTHORS

The *struct sf\_buf* API was designed and implemented by Alan L. Cox. This manual page was written by Robert N. M. Watson.
