Page MenuHomeFreeBSD

vm_page_advise(): reformat conditional statements
Needs ReviewPublic

Authored by mhorne on Nov 8 2023, 7:01 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Nov 14, 3:37 PM
Unknown Object (File)
Oct 26 2025, 8:38 PM
Unknown Object (File)
Oct 22 2025, 2:59 PM
Unknown Object (File)
Oct 22 2025, 2:17 AM
Unknown Object (File)
Oct 21 2025, 2:39 PM
Unknown Object (File)
Oct 16 2025, 7:30 PM
Unknown Object (File)
Oct 3 2025, 5:09 PM
Unknown Object (File)
Sep 29 2025, 6:17 AM
Subscribers

Details

Reviewers
markj
kib
alc
dougm
Summary

Use a switch, for better enumeration of the possible values. This is
non-functional change, but IMO it makes the logic a little easier to
follow.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 54337
Build 51227: arc lint + arc unit

Event Timeline

mhorne requested review of this revision.Nov 8 2023, 7:01 PM
sys/vm/vm_page.c
4453

Suppose that advise is MADV_WILLNEED. Before the patch, the page is dirtied if pmap thinks it is modified.

sys/vm/vm_page.c
4453

If advise is MADV_WILLNEED, we don't get to this point. We return on line 4450.

sys/vm/vm_page.c
4459

This change simplifies the control flow, but I don't know that the code is really clearer. The handling the dirty bits for MADV_FREE/DONTNEED above is connected to the rest of the function below, but that's not obvious. I think this would be the easiest to follow:

if (advice != MADV_DONTNEED && advice != MADV_FREE) {
    if (advice == MADV_WILLNEED)
        vm_page_activate(m);
    return;
}

if (advice == MADV_FREE)
    vm_page_undirty(m);
else if (m->dirty == 0 && pmap_is_modified(m))
    vm_page_dirty(m);
...