Page MenuHomeFreeBSD

simplify entries after vm_map_protect -> KERN_RESOURCE_SHORTAGE
ClosedPublic

Authored by dougm on Jun 25 2019, 8:38 AM.
Tags
None
Referenced Files
Unknown Object (File)
Dec 28 2023, 8:12 AM
Unknown Object (File)
Dec 20 2023, 1:31 AM
Unknown Object (File)
Nov 26 2023, 3:55 PM
Unknown Object (File)
Nov 8 2023, 2:54 PM
Unknown Object (File)
Nov 7 2023, 12:09 PM
Unknown Object (File)
Nov 5 2023, 2:58 PM
Unknown Object (File)
Nov 4 2023, 6:27 AM
Unknown Object (File)
Oct 7 2023, 1:44 PM
Subscribers

Details

Summary

If swap_reserve fails in vm_map_protect, don't return KERN_RESOURCE_SHORTAGE immediately. Instead, let the next loop simplify entries, but nothing else.

Diff Detail

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

Event Timeline

vm_map.c
2573 ↗(On Diff #58989)

I'd suggest adding a comment, perhaps at the beginning of the prior loop, explaining the error handling.

2575 ↗(On Diff #58989)

Logically I think it makes more sense to test rv before MAP_ENTRY_GUARD.

vm_map.c
2576 ↗(On Diff #59008)

Can't we avoid the calls to vm_map_simplify_entry() when rv == KERN_SUCCESS?

vm_map.c
2576 ↗(On Diff #59008)

I think you mean that you don't want to start simplifying current when
(current->eflags & MAP_ENTRY_GUARD) != 0) and rv==KERN_SUCCESS.

If that's what you mean, then, yes, I can change that.

markj added inline comments.
vm_map.c
2576 ↗(On Diff #59008)

I'm sorry, I missed that we were previously calling vm_map_simplify_entry() at the end of the final loop, so I was confused.

Now I think it makes more sense to leave the code as-is: the loop above clips map entries before checking for MAP_ENTRY_GUARD, so we should simplify before checking for MAP_ENTRY_GUARD.

This revision is now accepted and ready to land.Jun 25 2019, 4:54 PM
This revision now requires review to proceed.Jun 25 2019, 5:02 PM
kib added inline comments.
vm_map.c
2516 ↗(On Diff #59015)

some may BE mergeable.

This revision is now accepted and ready to land.Jun 25 2019, 5:03 PM
This revision now requires review to proceed.Jun 25 2019, 5:09 PM
This revision is now accepted and ready to land.Jun 25 2019, 7:41 PM
vm_map.c
2515 ↗(On Diff #59020)

This line reads as though pages are being copied here, which they are not.

Discard the parts of a comment that may mislead.

This revision now requires review to proceed.Jun 25 2019, 8:34 PM

IMO removing the sentence at all is overreaction, you can say 'will be copied' or use any other syntax construct that indicates that copying could occur in future.

In D20753#449053, @kib wrote:

IMO removing the sentence at all is overreaction, you can say 'will be copied' or use any other syntax construct that indicates that copying could occur in future.

Agreed. You can say, "If too little swap space is available to back the copy-on-write pages that may now be written to, ...

In D20753#449073, @alc wrote:
In D20753#449053, @kib wrote:

IMO removing the sentence at all is overreaction, you can say 'will be copied' or use any other syntax construct that indicates that copying could occur in future.

Agreed. You can say, "If too little swap space is available to back the copy-on-write pages that may now be written to, ...

Or, "If swap space can't be reserved to back the copy-on-write pages that may now be written, ..."

Fine-tune a comment that still includes "now will do cow".

This revision is now accepted and ready to land.Jun 26 2019, 6:42 AM
This revision now requires review to proceed.Jun 27 2019, 7:26 PM
vm_map.c
2520–2524 ↗(On Diff #59035)

I've tried to eliminate the repeated content between the two sentences:

"Before changing the protections, try to reserve swap space for any private (i.e., copy-on-write) mappings that are transitioning from read-only to read/write access. If a reservation fails, break out of this loop early and let the next loop simplify the entries, since some may now be mergeable.

2543 ↗(On Diff #59035)

Add

end = current->end;

so that the next loop doesn't bother iterating over entries that this loop never touched.

2567 ↗(On Diff #59035)

Ditto.

2580 ↗(On Diff #59035)

I would move the parenthetical comment to the end.

2584 ↗(On Diff #59035)

This line is indented by one space too many.

Accept reviewer suggestions.

In case of swap reservation failure, I suspect that only the first and last entries in the range will actually be mergeable.

This revision is now accepted and ready to land.Jun 27 2019, 11:09 PM