Page MenuHomeFreeBSD

ktls: re-work alloc thread
ClosedPublic

Authored by gallatin on Apr 4 2023, 9:08 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, May 3, 4:27 PM
Unknown Object (File)
Fri, May 3, 2:29 PM
Unknown Object (File)
Wed, May 1, 7:36 PM
Unknown Object (File)
Wed, May 1, 6:26 PM
Unknown Object (File)
Mar 8 2024, 5:47 AM
Unknown Object (File)
Mar 8 2024, 5:47 AM
Unknown Object (File)
Mar 8 2024, 5:47 AM
Unknown Object (File)
Mar 8 2024, 5:47 AM
Subscribers

Details

Summary
When the ktls_buffer zone needs to expand, it may fail due
to a lack of physically contiguous memory.  We tried to rectify
that by introducing an alloc thread to provide a context where
it is harmless to sleep, and letting that thread repopulate
the ktls_buffer zone.

However, it turns out that M_WAITOK is not enough, and we
must call vm_page_reclaim_contig_domain() to reclaim contig
memory. Worse, M_WAITOK results in the allocation essentially
busy-looping around vm_domain_alloc_fail() returning EAGIN,
causing vm_page_alloc_noobj_contig_domain() to loop and resulting
in the alloc thread consuming 100% CPU.

To fix this, we change the alloc thread to call vm_page_reclaim_contig_domain_ext()
 
In order to prevent the busy loop around vm_domain_alloc_fail(), we must change
the uma_zalloc flags to  M_NORECLAIM | M_NOWAIT.  However, once that is done,
these allocations become no different than the allocations done in the critical path
in ktls_buffer_alloc(), so its best to just eliminate them.

Since we're no longer doing allocations but just calling vm_page_reclaim_contig_domain_ext(),
the name has changed to the ktls reclaim thread.
Test Plan

Put a machine under memory pressure while serving a netflix heavy webserver workload, ensure that we see a small number of failed allocations in the ktls_buffers zone, and that the alloc thread is not consuming 100% of a core.

Diff Detail

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

Event Timeline

The first patch did not test well.. We wound up with just a single 16k allocation succeeding per wakeup of the alloc thread. I'm going to try a few things and revise the patch.

This revision is now accepted and ready to land.Apr 20 2023, 11:39 PM
sys/kern/uipc_ktls.c
3164–3168

It's not obvious to me that you want VM_ALLOC_SYSTEM here instead of VM_ALLOC_NORMAL. The former will basically let this thread run the domain out of free pages. Since this is an optimization, we probably don't want to do that?

3165

Indentation here should be by four spaces.

  • Address Mark's feedback: VM_ALLOC_NORMAL and indentation
This revision now requires review to proceed.Apr 25 2023, 5:14 PM
gallatin added inline comments.
sys/kern/uipc_ktls.c
3164–3168

Good point, Thank you!

3165

Thanks.. I need a better emacs mode.

This revision was not accepted when it landed; it landed in state Needs Review.May 9 2023, 5:12 PM
This revision was automatically updated to reflect the committed changes.
gallatin marked 2 inline comments as done.