aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2025-08-14 03:39:05 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2025-09-14 19:12:46 +0000
commit5bd4c04a4e7f7bda657e6027e64675d0caf50715 (patch)
tree91bdadff3cecfa21154de54e944f067670430a9f
parentc6b79f587f27649f90e00bc131d37bafa50ffc62 (diff)
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
-rw-r--r--sys/vm/vm_fault.c16
1 files 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.
*/