Page MenuHomeFreeBSD

vm_reserv: Introduce vm_reserv_alloc_npages
Needs ReviewPublic

Authored by bnovkov on Oct 10 2024, 9:39 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Nov 14, 11:35 AM
Unknown Object (File)
Sat, Nov 9, 5:55 PM
Unknown Object (File)
Sat, Nov 9, 9:20 AM
Unknown Object (File)
Thu, Nov 7, 2:55 PM
Unknown Object (File)
Wed, Nov 6, 6:41 AM
Unknown Object (File)
Wed, Nov 6, 6:39 AM
Unknown Object (File)
Wed, Nov 6, 6:39 AM
Unknown Object (File)
Wed, Nov 6, 4:33 AM
Subscribers

Details

Reviewers
markj
alc
kib
Summary

This change adds an interface for allocating multiple pages
from a reservation. It is meant to be used instead of invoking
vm_reserv_alloc_page in a loop.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

sys/vm/vm_reserv.c
854

How is it possible for the pages to not be physically contiguous? Don't they always come from a single reservation?

Correct comment pointed out by @markj .

sys/vm/vm_reserv.c
854

You are right, after taking a closer look at the reservation lifecycle I see that this cannot happen. I've corrected the comment.
We should also probably break from the allocation loop (and possibly even panic after further checks) instead of continuing when encountering an allocated page.

sys/vm/vm_reserv.c
964

Can this condition actually arise? That would mean that the page is already allocated, which is presumably due to a bug in the caller.

966

If you assume that the returned run of pages is always contiguous, then you don't need to return a pointer to each page. You can simply return a point to the first page in the run, and a count.

Then, it's probably profitable to have a variant of vm_reserv_populate() which adjusts the reservation for count pages starting at index, e.g., using bit_nset() rather than a loop.

sys/vm/vm_reserv.c
964

Other than a caller bug or a vm_reserv bug I don't think so.
I still think it is useful to check for this, but we can have this check along with the approach you described in the other comment.

966

Right, I'll work that assumption into the code. Callers can "unpack" the returned run into individual 0-order pages if need be.

sys/vm/vm_reserv.c
964

It happens due to vm_page_rename()s by, for example, vm_fault(). (I'm incredibly busy this week, when my workload lightens next week, I will elaborate.)

sys/vm/vm_reserv.c
964

Ahh, right, I forgot that it's possible for a page to be allocated from a reservation without belonging to the object that "owns" the reservation.

But, in this case I believe we have to terminate the loop, not continue.

Update diff according to @markj 's suggestion - pages are now allocated using a combination of bit_nset and bit_ffs_at.