From nobody Sat Nov 08 10:55:16 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4d3Xrh731Tz657Vq; Sat, 08 Nov 2025 10:55:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4d3Xrh6XBzz3mtQ; Sat, 08 Nov 2025 10:55:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1762599316; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gcPzl1sFvZiEIpmvxZoLeqM57SU0qET7+LED2nqBpbs=; b=CWB8W8Eu2kGrLTlFXmOHqtNpOXIYb9R9JuCgGP134LTpgI48rJtNx5TJ0+bBddPwPkxU2M tMV+adNdtYg8PbEsl9xJVubi1JCRyG7LYuInwpaA7AB1Sb5jvQKsqs3ZKzz8ywfqlxnijA 9qEJTna+Sg1c8YOk/hNbhb31Up9LL2Gi87NR+OG3m0BT3Y06M75Wkyw228NNmz+LwMIDDH Ps7r/D3cbr38nkmzU2Lq2LjEYxfQqvhYeSYdkSRALO/uOvXTOUU0SXziJFV8rHyVHeyCXE amudI2tsKQ35MiaODqZw0/md7dnX/bF4U5QaTy0QjBw0MxQxl22zJIDhyaCAVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1762599316; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gcPzl1sFvZiEIpmvxZoLeqM57SU0qET7+LED2nqBpbs=; b=QADA8d57I+jLjdrKZ9gdW3AXAz8m0sVj9pG04OtDxcIsD+iNLWDFJEv5ecM7qH5E4k8Dgr 8OuKZWKafOI07eOZqgBo2CjNvsU8XW+XgMt30axE7NUcdIbOIzKNVa9UPkUQqTaTgLl/82 HSaTtz714o2s0C3cryrz+mx+V008XKPpdLPRw+rgfJYI4tQzGc+98WaUuoBralwBBmkbEm KfOeWLYUHtbBVd1VWNNbmZQaKcUDDc3lZvhFn/dHezEk6ABvB2wIzfPq+BtTTIph++EIHI oBh1jEa1zg01jjaeEtqPtuVW9EDPj44bNabB8Pc6qT0NQdrmcKq12SAO799Oqg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1762599316; a=rsa-sha256; cv=none; b=gvuKhZ70v9+6dZhCwJzypYUfw3KBoeIdaBNu1mfe/UfihiiEFGKfDjAC5e096dE2vf2xTB M9lhFngPxy7w0VFtYyuPc9d8/b+CugEYjsxyj47HhFZZRzFQBHKhEt38h2qVQ6oxjcPK5Z TFTSIxQtGUkuAVBGBS6ClUabgwBtwnfxeJrbj7NS97HKSJOThNs8dJ63jOrfkG1CoAG1KP uDdoexbx7pdF+bFwLbH8GPfHtW/TtvPr0G0BrIZSDlVRBjLVIxTI0+tkNI/uurAIIH4nkV MNgJHRV/MWrGFIxPbPr2CZJKXLf55Pb8UU+eFdQf9VOw3HOMyKL7FUdR7ki1+Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4d3Xrh5xvZzjkH; Sat, 08 Nov 2025 10:55:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 5A8AtG2R049693; Sat, 8 Nov 2025 10:55:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5A8AtGvm049690; Sat, 8 Nov 2025 10:55:16 GMT (envelope-from git) Date: Sat, 8 Nov 2025 10:55:16 GMT Message-Id: <202511081055.5A8AtGvm049690@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Piotrowski <0mp@FreeBSD.org> Subject: git: f1424dfe45b8 - stable/15 - buf.9: Sprinkle with mdoc macros List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: 0mp X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: f1424dfe45b8b0f05d5fda20c155bc8937d308fb Auto-Submitted: auto-generated The branch stable/15 has been updated by 0mp: URL: https://cgit.FreeBSD.org/src/commit/?id=f1424dfe45b8b0f05d5fda20c155bc8937d308fb commit f1424dfe45b8b0f05d5fda20c155bc8937d308fb Author: Mateusz Piotrowski <0mp@FreeBSD.org> AuthorDate: 2025-11-04 11:04:43 +0000 Commit: Mateusz Piotrowski <0mp@FreeBSD.org> CommitDate: 2025-11-08 10:55:13 +0000 buf.9: Sprinkle with mdoc macros I did not bump the date here as the manual page looks more like a draft and I'm not sure if it is actually up-to-date considering that it's current Dd dates back to 1998. MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D52770 (cherry picked from commit fc7f5452c6ff1a9d01a9d8d0638da593ae4f080c) --- share/man/man9/buf.9 | 97 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 72 insertions(+), 25 deletions(-) diff --git a/share/man/man9/buf.9 b/share/man/man9/buf.9 index ecd4a1487735..ff9a1d0d46e0 100644 --- a/share/man/man9/buf.9 +++ b/share/man/man9/buf.9 @@ -36,44 +36,70 @@ The kernel implements a KVM abstraction of the buffer cache which allows it to map potentially disparate vm_page's into contiguous KVM for use by (mainly file system) devices and device I/O. This abstraction supports -block sizes from DEV_BSIZE (usually 512) to upwards of several pages or more. +block sizes from +.Dv DEV_BSIZE +(usually 512) to upwards of several pages or more. It also supports a relatively primitive byte-granular valid range and dirty range currently hardcoded for use by NFS. The code implementing the VM Buffer abstraction is mostly concentrated in -.Pa /usr/src/sys/kern/vfs_bio.c . +.Pa sys/kern/vfs_bio.c +in the +.Fx +source tree. .Pp One of the most important things to remember when dealing with buffer pointers -(struct buf) is that the underlying pages are mapped directly from the buffer +.Pq Vt struct buf +is that the underlying pages are mapped directly from the buffer cache. No data copying occurs in the scheme proper, though some file systems such as UFS do have to copy a little when dealing with file fragments. The second most important thing to remember is that due to the underlying page -mapping, the b_data base pointer in a buf is always *page* aligned, not -*block* aligned. -When you have a VM buffer representing some b_offset and -b_size, the actual start of the buffer is (b_data + (b_offset & PAGE_MASK)) -and not just b_data. +mapping, the +.Va b_data +base pointer in a buf is always +.Em page Ns -aligned , +not +.Em block Ns -aligned . +When you have a VM buffer representing some +.Va b_offset +and +.Va b_size , +the actual start of the buffer is +.Ql b_data + (b_offset & PAGE_MASK) +and not just +.Ql b_data . Finally, the VM system's core buffer cache supports -valid and dirty bits (m->valid, m->dirty) for pages in DEV_BSIZE chunks. +valid and dirty bits +.Pq Va m->valid , m->dirty +for pages in +.Dv DEV_BSIZE +chunks. Thus a platform with a hardware page size of 4096 bytes has 8 valid and 8 dirty bits. These bits are generally set and cleared in groups based on the device block size of the device backing the page. Complete page's worth are often -referred to using the VM_PAGE_BITS_ALL bitmask (i.e., 0xFF if the hardware page +referred to using the +.Dv VM_PAGE_BITS_ALL +bitmask (i.e., 0xFF if the hardware page size is 4096). .Pp VM buffers also keep track of a byte-granular dirty range and valid range. This feature is normally only used by the NFS subsystem. I am not sure why it -is used at all, actually, since we have DEV_BSIZE valid/dirty granularity +is used at all, actually, since we have +.Dv DEV_BSIZE +valid/dirty granularity within the VM buffer. -If a buffer dirty operation creates a 'hole', +If a buffer dirty operation creates a +.Dq hole , the dirty range will extend to cover the hole. If a buffer validation -operation creates a 'hole' the byte-granular valid range is left alone and +operation creates a +.Dq hole +the byte-granular valid range is left alone and will not take into account the new extension. Thus the whole byte-granular abstraction is considered a bad hack and it would be nice if we could get rid @@ -81,16 +107,24 @@ of it completely. .Pp A VM buffer is capable of mapping the underlying VM cache pages into KVM in order to allow the kernel to directly manipulate the data associated with -the (vnode,b_offset,b_size). +the +.Pq Va vnode , b_offset , b_size . The kernel typically unmaps VM buffers the moment -they are no longer needed but often keeps the 'struct buf' structure -instantiated and even bp->b_pages array instantiated despite having unmapped +they are no longer needed but often keeps the +.Vt struct buf +structure +instantiated and even +.Va bp->b_pages +array instantiated despite having unmapped them from KVM. If a page making up a VM buffer is about to undergo I/O, the -system typically unmaps it from KVM and replaces the page in the b_pages[] +system typically unmaps it from KVM and replaces the page in the +.Va b_pages[] array with a place-marker called bogus_page. The place-marker forces any kernel -subsystems referencing the associated struct buf to re-lookup the associated +subsystems referencing the associated +.Vt struct buf +to re-lookup the associated page. I believe the place-marker hack is used to allow sophisticated devices such as file system devices to remap underlying pages in order to deal with, @@ -107,18 +141,29 @@ you wind up with pages marked clean that are actually still dirty. If not treated carefully, these pages could be thrown away! Indeed, a number of -serious bugs related to this hack were not fixed until the 2.2.8/3.0 release. -The kernel uses an instantiated VM buffer (i.e., struct buf) to place-mark pages +serious bugs related to this hack were not fixed until the +.Fx 2.2.8 / +.Fx 3.0 +release. +The kernel uses an instantiated VM buffer (i.e., +.Vt struct buf ) +to place-mark pages in this special state. -The buffer is typically flagged B_DELWRI. +The buffer is typically flagged +.Dv B_DELWRI . When a -device no longer needs a buffer it typically flags it as B_RELBUF. +device no longer needs a buffer it typically flags it as +.Dv B_RELBUF . Due to -the underlying pages being marked clean, the B_DELWRI|B_RELBUF combination must +the underlying pages being marked clean, the +.Ql B_DELWRI|B_RELBUF +combination must be interpreted to mean that the buffer is still actually dirty and must be written to its backing store before it can actually be released. In the case -where B_DELWRI is not set, the underlying dirty pages are still properly +where +.Dv B_DELWRI +is not set, the underlying dirty pages are still properly marked as dirty and the buffer can be completely freed without losing that clean/dirty state information. (XXX do we have to check other flags in @@ -128,7 +173,9 @@ The kernel reserves a portion of its KVM space to hold VM Buffer's data maps. Even though this is virtual space (since the buffers are mapped from the buffer cache), we cannot make it arbitrarily large because -instantiated VM Buffers (struct buf's) prevent their underlying pages in the +instantiated VM Buffers +.Pq Vt struct buf Ap s +prevent their underlying pages in the buffer cache from being freed. This can complicate the life of the paging system.