Page MenuHomeFreeBSD

vm_page: update legend documenting allocation
ClosedPublic

Authored by alc on Mar 16 2025, 6:15 AM.
Tags
None
Referenced Files
F134521943: D49391.id152332.diff
Sun, Nov 2, 9:13 PM
Unknown Object (File)
Fri, Oct 31, 2:02 AM
Unknown Object (File)
Tue, Oct 21, 9:35 AM
Unknown Object (File)
Sat, Oct 18, 12:09 AM
Unknown Object (File)
Sun, Oct 12, 4:58 AM
Unknown Object (File)
Mon, Oct 6, 11:56 AM
Unknown Object (File)
Sep 30 2025, 11:05 PM
Unknown Object (File)
Sep 30 2025, 6:24 PM
Subscribers

Details

Summary

Update the legend describing the arguments to the most commonly used page allocation functions. Notably, eliminate a reference to a function that no longer exists; and update to reflect the elimination of VM_ALLOC_NOOBJ, specifically, VM_ALLOC_WAITOK is no longer a legal option to vm_page_alloc{,_contig}().

Eliminate a nonsensical KASSERT(). VM_ALLOC_SBUSY is forbidden as an argument to vm_page_alloc_noobj{,_contig,}_domain() by a KASSERT(), so having a different KASSERT() that tests for it is nonsensical.

Strengthen other KASSERT()s involving VM_ALLOC_NOBUSY and VM_ALLOC_NOFREE.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

dougm requested review of this revision.Mar 16 2025, 6:15 AM
dougm created this revision.
sys/vm/vm_page.c
4660

I think that noting that the object is locked on entry and exit, with possible drop in between, is at least in line with other functions descriptions.

4706

Or you could write MPASS((allocflags & VM_ALLOC_WAITFAIL) == 0);

dougm marked 2 inline comments as done.

Address @kib comments.

This revision is now accepted and ready to land.Mar 17 2025, 12:52 AM
sys/vm/vm_page.c
4706

You could pass __func__ to this function and use %s here. Constant propagation with inlining will make it the generated code equivalent to the callers performing the KASSERTs directly.

dougm marked an inline comment as done.

Apply @alc suggestion for func in KASSERTS in vm_page_grab_check().

This revision now requires review to proceed.Mar 17 2025, 6:18 AM

The vm_page.h comment incorrectly says vm_page_alloc accepts VM_ALLOC_WAITOK.

In D49391#1126158, @alc wrote:

The vm_page.h comment incorrectly says vm_page_alloc accepts VM_ALLOC_WAITOK.

VM_ALLOC_NODUMP is also incorrectly annotated.

Correct a couple of vm allocflags annotations in readcli.h.

sys/vm/vm_page.h
489–490
sys/vm/vm_page.h
464–465

vm_page_alloc_freelist() no longer exists.

481
dougm marked 3 inline comments as done.

Further correct the page allocation parameter comments of vm_page.h, guided by @alc. Add a func parameter to vm_page_grab_check.

This revision is now accepted and ready to land.Mar 18 2025, 1:42 AM

The functional portion of the change seems fine, but I'm not sure why it's a problem for vm_page_grab* to support VM_ALLOC_WAITFAIL?

sys/vm/vm_page.c
4664
4694

You might need to annotate func with __diagused to dampen build warnings when KASSERT() is compiled out, i.e., the GENERIC-NODEBUG kernel config.

Rather than forcing callers to explicitly pass __func__, it'd be a bit nicer to rename this function to _vm_page_grab_check() and have #define vm_page_grab_check(...) _vm_page_grab_check(__VA_ARGS__, __func__).

The functional portion of the change seems fine, but I'm not sure why it's a problem for vm_page_grab* to support VM_ALLOC_WAITFAIL?

Because in comments on D49371, @kib suggested that VM_ALLOC_WAITFAIL was invalid here. So, to remove that obstacle to getting D49371 approved, I investigated and found that he might be right. Now, @alc has verbally placed a hold on this change because, when he is freed from another task, he plans to look for other illegal allocflag settings.

This revision now requires review to proceed.Mar 23 2025, 5:16 PM

The functional portion of the change seems fine, but I'm not sure why it's a problem for vm_page_grab* to support VM_ALLOC_WAITFAIL?

Because in comments on D49371, @kib suggested that VM_ALLOC_WAITFAIL was invalid here. So, to remove that obstacle to getting D49371 approved, I investigated and found that he might be right. Now, @alc has verbally placed a hold on this change because, when he is freed from another task, he plans to look for other illegal allocflag settings.

My reading of the comments is that kib is pointing out a bug in the new code.

The functional portion of the change seems fine, but I'm not sure why it's a problem for vm_page_grab* to support VM_ALLOC_WAITFAIL?

Because in comments on D49371, @kib suggested that VM_ALLOC_WAITFAIL was invalid here. So, to remove that obstacle to getting D49371 approved, I investigated and found that he might be right. Now, @alc has verbally placed a hold on this change because, when he is freed from another task, he plans to look for other illegal allocflag settings.

My reading of the comments is that kib is pointing out a bug in the new code.

He wrote, at D49371:
I am not sure about the semantic of VM_ALLOC_WAITFAIL. If we sleep inside vm_page_grab_lookup(), should we also return NULL for VM_ALLOC_WAITFAIL? (This is the pre-existing bug, if indeed a bug).

So I disagree that he is calling out a bug in new code.

The functional portion of the change seems fine, but I'm not sure why it's a problem for vm_page_grab* to support VM_ALLOC_WAITFAIL?

Because in comments on D49371, @kib suggested that VM_ALLOC_WAITFAIL was invalid here. So, to remove that obstacle to getting D49371 approved, I investigated and found that he might be right. Now, @alc has verbally placed a hold on this change because, when he is freed from another task, he plans to look for other illegal allocflag settings.

My reading of the comments is that kib is pointing out a bug in the new code.

He wrote, at D49371:
I am not sure about the semantic of VM_ALLOC_WAITFAIL. If we sleep inside vm_page_grab_lookup(), should we also return NULL for VM_ALLOC_WAITFAIL? (This is the pre-existing bug, if indeed a bug).

So I disagree that he is calling out a bug in new code.

Then I don't follow: in the old code, if we sleep inside vm_page_grab_sleep(WAITFAIL), then vm_page_grab_sleep() returns false, in which case vm_page_grab() indeed returns NULL. That's consistent with vm_page_alloc*(). Where is the bug?

The functional portion of the change seems fine, but I'm not sure why it's a problem for vm_page_grab* to support VM_ALLOC_WAITFAIL?

Because in comments on D49371, @kib suggested that VM_ALLOC_WAITFAIL was invalid here. So, to remove that obstacle to getting D49371 approved, I investigated and found that he might be right. Now, @alc has verbally placed a hold on this change because, when he is freed from another task, he plans to look for other illegal allocflag settings.

My reading of the comments is that kib is pointing out a bug in the new code.

He wrote, at D49371:
I am not sure about the semantic of VM_ALLOC_WAITFAIL. If we sleep inside vm_page_grab_lookup(), should we also return NULL for VM_ALLOC_WAITFAIL? (This is the pre-existing bug, if indeed a bug).

So I disagree that he is calling out a bug in new code.

Then I don't follow: in the old code, if we sleep inside vm_page_grab_sleep(WAITFAIL), then vm_page_grab_sleep() returns false, in which case vm_page_grab() indeed returns NULL. That's consistent with vm_page_alloc*(). Where is the bug?

I did pointed out that the new code handled NOWAIT improperly. I have no reason to request that the flag was disallowed for the function, but Doug' analysis demonstrated that no callers needed it, so I did not objected against the route of disallowing it.

Aren't all of the changes to vm_page.h valid? Can we have a standalone patch with just those changes?

Drop all but the header file changes.

dougm foisted this revision upon alc.
dougm edited reviewers, added: dougm; removed: alc.
This revision is now accepted and ready to land.Apr 26 2025, 8:48 PM
alc added reviewers: kib, markj.
This revision now requires review to proceed.Jun 20 2025, 5:14 PM
alc retitled this revision from vm_grab: assert no VM_ALLOC_WAITFAIL to vm_page: update legend documenting allocation.Jun 20 2025, 5:16 PM
alc edited the summary of this revision. (Show Details)
sys/vm/vm_page.c
2330

Wouldn't it be better to have e.g. VPA_COMMON flags without VM_ALLOC_NOFREE, and then use this to define VPA/VPAN/VPAC/VPANC without the ~ hack?

sys/vm/vm_page.h
499

s/flag/state/ ?

alc marked 2 inline comments as done.Jun 20 2025, 11:24 PM

Introduce VM_ALLOC_COMMON.

Some wording changes.

This revision is now accepted and ready to land.Jun 21 2025, 11:54 AM