Page MenuHomeFreeBSD

Refactor domainset iterators in preparation for use by malloc() and UMA.
ClosedPublic

Authored by markj on Oct 4 2018, 7:55 PM.
Tags
None
Referenced Files
Unknown Object (File)
Jan 17 2025, 4:17 PM
Unknown Object (File)
Dec 10 2024, 11:35 PM
Unknown Object (File)
Dec 4 2024, 1:33 AM
Unknown Object (File)
Nov 29 2024, 12:10 PM
Unknown Object (File)
Nov 10 2024, 4:03 PM
Unknown Object (File)
Sep 28 2024, 1:18 PM
Unknown Object (File)
Sep 28 2024, 11:12 AM
Unknown Object (File)
Sep 22 2024, 1:55 PM
Subscribers

Details

Summary

Right now we have two flavours of vm_domainset iterators: "page" and
"malloc". The former is used by the page allocator, and the latter is
used by kmem_malloc() and friends. I would like to make the latter more
general.

The malloc iterator currently always derives its policy from
kernel_object, which has a DOMAINSET_POLICY_INTERLEAVE policy. However,
the iterator implementation just converts this to round-robin. Note
that the malloc iterator is used to select a vmem arena, which then
ensures that pages from the same 2MB virtual page are backed by physical
pages from the same domain. In particular, we're not relying on the
interleave policy to preserve superpages.

The malloc iterator currently also has the problem that it is run
without the kernel_object lock held, so updates to the iterator can race
with each other.

For the general case I would like to instead be able to specify a policy
in the vm_domainset_iter caller. In most cases this will just be a
round-robin policy, but this also permits the implementation of a
malloc_domainset(9) or uma_zalloc_domainset(9). This change refactors
the malloc iterator to support that case. I renamed it to be a "policy"
iterator, but better name suggestions are welcome. Policy iterators
always use curthread->td_domain.dr_iter as the iterator index, avoiding
races.

Aside from this, the lowmem handling for VM_ALLOC_WAITOK and M_WAITOK
allocations is not very robust. The current algorithm attempts NOWAIT
allocations from all domains in the set and then falls back to a WAITOK
allocation from the first domain in the set. If that domain's memory is
mostly wired, we may block indefinitely. Instead, we can use
vm_wait_doms() to sleep until _any_ domain in the set accumulates some
free pages. This change makes that adjustment.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

sys/vm/vm_kern.c
323 ↗(On Diff #48741)

Where is DOMAINSET_ROUNDROBIN declared? Am I messing a parent review? If I could find where it was declared, I'd suggest a shorter spelling. Eg, DSET_RR() or something..

markj marked an inline comment as done.Oct 8 2018, 5:17 PM
markj added inline comments.
sys/vm/vm_kern.c
323 ↗(On Diff #48741)

It's declared in D17416.

Thank you for handling this.

This revision is now accepted and ready to land.Oct 10 2018, 11:33 PM

Add vm_domainset_iter_policy_ref_init(), needed for D17420.

Now we have two variants: one which takes a domainset and uses the
current thread's iterator, and one which takes a domainset_ref (which
contains both the policy and an iterator). In the latter case, the
caller must handle synchronization of iterator updates.

This revision now requires review to proceed.Oct 16 2018, 4:01 PM
This revision was not accepted when it landed; it landed in state Needs Review.Oct 23 2018, 4:36 PM
This revision was automatically updated to reflect the committed changes.