Page MenuHomeFreeBSD

uma: Improve M_USE_RESERVE handling in keg_fetch_slab()
ClosedPublic

Authored by markj on Oct 15 2021, 10:00 PM.
Tags
None
Referenced Files
Unknown Object (File)
Apr 5 2024, 10:46 AM
Unknown Object (File)
Jan 18 2024, 12:40 AM
Unknown Object (File)
Dec 24 2023, 3:35 PM
Unknown Object (File)
Dec 23 2023, 2:57 PM
Unknown Object (File)
Sep 18 2023, 3:49 PM
Unknown Object (File)
Aug 28 2023, 12:17 PM
Unknown Object (File)
Aug 26 2023, 1:42 PM
Unknown Object (File)
Jul 9 2023, 5:25 PM
Subscribers

Details

Summary

M_USE_RESERVE is used in a couple of places in the VM to avoid unbounded
recursion when the direct map is not available, as is the case on 32-bit
platforms or when certain kernel sanitizers (KASAN and KMSAN) are
enabled. For example, to allocate KVA, the kernel might allocate a
kernel map entry, which might require a new slab, which requires KVA.

For these zones, we use uma_prealloc() to populate a reserve of items,
and then in certain serialized contexts M_USE_RESERVE can be used to
guarantee a successful allocation. uma_prealloc() allocates the
requested number of items, distributing them evenly among NUMA domains.
Thus, in a first-touch zone, to satisfy an M_USE_RESERVE allocation we
might have to check the slab lists of other domains than the current one
to provide the semantics expected by consumers.

So, try harder to find an item if M_USE_RESERVE is specified and the keg
doesn't have anything for current (first-touch) domain. Specifically,
fall back to a round-robin slab allocation. This change fixes boot-time
panics on NUMA systems with KASAN or KMSAN enabled.

Alternately we could have uma_prealloc() allocate the requested number
of items for each domain, but for some existing consumers this would be
quite wasteful. In general I think keg_fetch_slab() should try harder
to find free slabs in other domains before trying to allocate fresh
ones, but let's limit this to M_USE_RESERVE for now.

Also fix a separate problem that I noticed: in a non-round-robin slab
allocation with M_WAITOK, rather than sleeping after a failed slab
allocation we simply try again. Call vm_wait_domain() before retrying.

Reported by: mjg, tuexen

Diff Detail

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

Event Timeline

I'd like to commit this soon, but if there's any interest in reviewing I'm happy to wait.

If you can wait until the weekend, I will look at this then. Weren't there other changes related to replacing preallocation with explicit reservation?

In D32515#737429, @alc wrote:

If you can wait until the weekend, I will look at this then. Weren't there other changes related to replacing preallocation with explicit reservation?

Thank you. There's no real urgency, the problem is limited to kernel sanitizers (which disable UMA_MD_SMALL_ALLOC) and NUMA systems.

I think I made some attempts to merge uma_prealloc() and uma_zone_reserve() but it stalled. That is somewhat orthogonal to this, though, unless I misunderstood.

In D32515#737429, @alc wrote:

If you can wait until the weekend, I will look at this then. Weren't there other changes related to replacing preallocation with explicit reservation?

Thank you. There's no real urgency, the problem is limited to kernel sanitizers (which disable UMA_MD_SMALL_ALLOC) and NUMA systems.

I think I made some attempts to merge uma_prealloc() and uma_zone_reserve() but it stalled. That is somewhat orthogonal to this, though, unless I misunderstood.

I only asked out of curiosity.

This revision is now accepted and ready to land.Nov 1 2021, 1:35 AM