Page MenuHomeFreeBSD

kern: physmem: improve region coalescing logic
ClosedPublic

Authored by kevans on Oct 28 2021, 4:47 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, May 22, 4:28 AM
Unknown Object (File)
Mon, May 20, 3:18 PM
Unknown Object (File)
Sun, May 19, 9:44 PM
Unknown Object (File)
Sun, May 19, 9:44 PM
Unknown Object (File)
Thu, May 16, 10:58 PM
Unknown Object (File)
Sun, May 12, 7:09 PM
Unknown Object (File)
Sun, May 12, 7:08 PM
Unknown Object (File)
Sun, May 12, 6:25 PM
Subscribers

Details

Summary

The existing logic didn't take into account newly inserted mappings
wholly contained by an existing region (or vice versa), nor did it
account for weird overlap scenarios. The latter is probably unlikely
to happen, but the former may happen in UEFI: BootServicesData allocated
within a large chunk of ConventionalMemory. This situation blows up vm
initialization.

While we're here, remove the "exact match" logic as it's likely wrong;
if an exact match exists with conflicting flags, for instance, then we
should probably be doing something else. The new logic takes into
account exact matches as part of the overlapping efforts.

Diff Detail

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

Event Timeline

It would be great if at least x86 was changed to use this KPI.

sys/kern/subr_physmem.c
363–364

I think, at this point you need to check both siblings and see if any of them coalesce as well.
Then you would need to compact the regions array.

370

Same

sys/kern/subr_physmem.c
363–364

I had to stare at it for a bit, but I think I mostly agree on both cases -- if the lower sibling had overlap then we would've already merged with it, so I think both cases just need to check the next entry if we extended past this one.

As pointed out: merge upwards as needed. We may have consumed multiple regions
with the new addition, so grab as many as we can then fill the hole if needed.

This has been lightly tested in userland, and things looked generally OK... I
tested a couple of scenarios to try and hit every branch.

Take flags into account when merging up

This revision is now accepted and ready to land.Oct 31 2021, 1:47 AM

LGTM

sys/kern/subr_physmem.c
291
358–362

Just to confirm, even when nend == rend, merge_upper_regions() might have work to do?

sys/kern/subr_physmem.c
358–362

Ah, no, good catch; I'll simplify this to nend > rend since this won't do anything useful for either statements. If we had upper region to merge with the end not moving, we failed with an earlier addition.

This revision was automatically updated to reflect the committed changes.
kevans marked an inline comment as done.