git: 5bd4c04a4e7f - main - vm_fault: add vm_fault_might_be_cow() helper
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 14 Sep 2025 20:13:21 UTC
The branch main has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=5bd4c04a4e7f7bda657e6027e64675d0caf50715
commit 5bd4c04a4e7f7bda657e6027e64675d0caf50715
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-08-14 03:39:05 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-09-14 19:12:46 +0000
vm_fault: add vm_fault_might_be_cow() helper
The helper checks that the object containing the fs->m page is not the
top object in the shadow chain.
Reviewed by: alc, markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D51474
---
sys/vm/vm_fault.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/sys/vm/vm_fault.c b/sys/vm/vm_fault.c
index a00134715171..226cf34b3ca4 100644
--- a/sys/vm/vm_fault.c
+++ b/sys/vm/vm_fault.c
@@ -258,6 +258,12 @@ vm_fault_unlock_vp(struct faultstate *fs)
}
}
+static bool
+vm_fault_might_be_cow(struct faultstate *fs)
+{
+ return (fs->object != fs->first_object);
+}
+
static void
vm_fault_deallocate(struct faultstate *fs)
{
@@ -265,7 +271,7 @@ vm_fault_deallocate(struct faultstate *fs)
vm_fault_page_release(&fs->m_cow);
vm_fault_page_release(&fs->m);
vm_object_pip_wakeup(fs->object);
- if (fs->object != fs->first_object) {
+ if (vm_fault_might_be_cow(fs)) {
VM_OBJECT_WLOCK(fs->first_object);
vm_fault_page_free(&fs->first_m);
VM_OBJECT_WUNLOCK(fs->first_object);
@@ -1005,7 +1011,7 @@ vm_fault_cow(struct faultstate *fs)
{
bool is_first_object_locked;
- KASSERT(fs->object != fs->first_object,
+ KASSERT(vm_fault_might_be_cow(fs),
("source and target COW objects are identical"));
/*
@@ -1169,7 +1175,7 @@ vm_fault_zerofill(struct faultstate *fs)
* If there's no object left, fill the page in the top
* object with zeros.
*/
- if (fs->object != fs->first_object) {
+ if (vm_fault_might_be_cow(fs)) {
vm_object_pip_wakeup(fs->object);
fs->object = fs->first_object;
fs->pindex = fs->first_pindex;
@@ -1433,7 +1439,7 @@ vm_fault_busy_sleep(struct faultstate *fs, int allocflags)
* likely to reclaim it.
*/
vm_page_aflag_set(fs->m, PGA_REFERENCED);
- if (fs->object != fs->first_object) {
+ if (vm_fault_might_be_cow(fs)) {
vm_fault_page_release(&fs->first_m);
vm_object_pip_wakeup(fs->first_object);
}
@@ -1710,7 +1716,7 @@ found:
* top-level object, we have to copy it into a new page owned by the
* top-level object.
*/
- if (fs.object != fs.first_object) {
+ if (vm_fault_might_be_cow(&fs)) {
/*
* We only really need to copy if we want to write it.
*/