Page MenuHomeFreeBSD

Don't drop xbusy on kmem pages.
ClosedPublic

Authored by jeff on Feb 4 2020, 8:33 PM.
Tags
None
Referenced Files
Unknown Object (File)
Feb 14 2024, 1:32 AM
Unknown Object (File)
Feb 14 2024, 1:28 AM
Unknown Object (File)
Feb 14 2024, 1:28 AM
Unknown Object (File)
Feb 7 2024, 9:16 PM
Unknown Object (File)
Jan 11 2024, 10:46 PM
Unknown Object (File)
Dec 21 2023, 2:37 PM
Unknown Object (File)
Dec 20 2023, 7:46 AM
Unknown Object (File)
Oct 30 2023, 9:23 AM
Subscribers

Details

Summary

We can not block waiting for busy in the free path and nothing should be acquiring busy other than incorrect transients from unlocked lookup. I simply leave the pages xbusied from alloc until they are freed. uma_small_alloc/free does not have this problem because it uses NOOBJ allocation and so busy is not required on free. We technically could allow the asserts to skip xbusy on free for kmem_object but I think that is more confusing than simply leaving the pages locked.

vm_page_xbusy_claim() additionally allows us to improve our debugging in areas where the lock ownership is known to specifically change. It costs nothing on release kernels and it is safer than the KERNPROC approach that anyone can acquire. It should allow us to remove other unchecked busy asserts.

Diff Detail

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

Event Timeline

jeff added reviewers: alc, kib, markj, dougm.
This revision is now accepted and ready to land.Feb 4 2020, 9:13 PM
sys/vm/vm_glue.c
347 ↗(On Diff #67792)

Doesn't vm_thread_swapout() now need to unbusy the pages? Thread stacks can be swapped.

Correct swapout. I am still testing this but I believe it is correct.

This revision now requires review to proceed.Feb 6 2020, 8:54 PM
sys/vm/vm_swapout.c
543 ↗(On Diff #67892)

Don't you need to claim xbusy first?

sys/vm/vm_swapout.c
543 ↗(On Diff #67892)

xbusy should be left from the allocation.

It should be:
alloc -> xbusy
swapout ->unbusy
swapin -> xbusy
free -> unbusy

sys/vm/vm_swapout.c
543 ↗(On Diff #67892)

Right but alloc and swapout are done by different threads. I think the code is correct as-is but will fail under INVARIANTS.

Resolve two swapin/swapout issues. This now passes stress2.

This revision is now accepted and ready to land.Feb 9 2020, 8:28 PM

One final bug to pass stress; when we fault out and back in we may have
valid swap backing for busy pages. This can deadlock with swapoff. This
also means we're not freeing swap space that had been used by kernel
stacks.

The solution is somewhat specific to kernel stacks but will save on I/O for
other objects in the same situation. Namely, I simply delete the swap space
if the pages are all resident.

There are other existing bugs in this code that will need to be addressed
and I write this fix slightly differently at that time.

This revision now requires review to proceed.Feb 10 2020, 8:05 PM
sys/vm/vm_swapout.c
589 ↗(On Diff #68088)

Doesn't this effectively leak swap space still? The object lock is not owned here, so we will set PGA_SWAP_FREE, but the pages are wired and so won't be visited by the page daemon.

sys/vm/swap_pager.c
1763 ↗(On Diff #68088)

This should be done a layer up, in swap_pager_swapoff_object().

sys/vm/swap_pager.c
1763 ↗(On Diff #68088)

I have another problem. Since I allow non-valid pages on default/swap objects that are undergoing fault the size check is not consistent.

I know you rewrote this function in another patch. I may have to solve this differently. If you are going to commit that soonish I will wait and see if your restructuring helps. I think it should.

sys/vm/vm_swapout.c
589 ↗(On Diff #68088)

Yes you're right. I can delete the space here directly.

sys/vm/swap_pager.c
1763 ↗(On Diff #68088)

For me this raises the question of why it is useful to keep stack pages busied to begin with.

I don't think my patches help you here. As I noted in D23664, swapoff needs to acquire xbusy on valid pages to ensure that they are not concurrently being paged out. One somewhat lame thing you could do in vm_thread_swapin() would be to unbusy the pages after page-in, delete the swap space (under the object lock), and re-busy them.

This revision was not accepted when it landed; it landed in state Needs Review.Feb 19 2020, 9:10 AM
This revision was automatically updated to reflect the committed changes.