Page MenuHomeFreeBSD

When traversing vm_map entries, don't look up the same neighbor twice
ClosedPublic

Authored by dougm on Nov 13 2019, 5:41 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Jun 29, 8:14 PM
Unknown Object (File)
Fri, Jun 28, 3:27 AM
Unknown Object (File)
Thu, Jun 27, 1:23 AM
Unknown Object (File)
Thu, Jun 27, 1:23 AM
Unknown Object (File)
Tue, Jun 25, 6:22 PM
Unknown Object (File)
Fri, Jun 14, 11:14 AM
Unknown Object (File)
Thu, Jun 13, 8:10 PM
Unknown Object (File)
Tue, Jun 11, 9:18 PM
Subscribers

Details

Summary

Instead of looking up a predecessor or successor to the current map entry, when that entry has been seen already, keep the already-looked-up value in a variable and use that instead of looking it up again.

Define a standard naming convention for map entry iterators in vm_map.c and apply it.

Diff Detail

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

Event Timeline

Add parens around returned value in vm_map_entry_first.

This change reduces the size of mac_process.o and vm_map.o by 56 and 656 bytes, respectively, on the amd64 machine I'm testing on.

It would be nice if the loop variable names were more consistent: in some places we use prev_entry/entry, in others it's temp_entry/current or entry/current, etc.. I think I prefer prev_entry/entry, FWIW. Anyway, that does not block this patch.

sys/vm/vm_map.c
2575 ↗(On Diff #64362)

Why do we need an opening paren here?

3003 ↗(On Diff #64362)

first_entry is a bit of a misnomer now, perhaps it should become prev_entry.

3290 ↗(On Diff #64362)

Same comment about changing to prev_entry.

This revision is now accepted and ready to land.Nov 15 2019, 8:37 PM

Rename variables in vm_map loops, so that the fixed starting point is called 'first_entry', the iterator is called 'entry', and the iterator trailing it, if any, is called 'prev_entry'.

This revision now requires review to proceed.Nov 16 2019, 4:23 AM

Fix a transcription error.

Rewrite a couple of lines to that prev_entry isn't, briefly, after entry.

This revision is now accepted and ready to land.Nov 16 2019, 10:25 AM
sys/vm/vm_map.c
1430 ↗(On Diff #64426)

Unsorted.

dougm marked 4 inline comments as done.
dougm edited the summary of this revision. (Show Details)

Update to account for r354785. Address reviewer comments.

This revision now requires review to proceed.Nov 17 2019, 7:06 AM

Use the FOREACH macros for iterating over the old map in vm_fork. Reformat a comment to fit in 80 columns.

markj added inline comments.
sys/vm/vm_map.c
2678 ↗(On Diff #64500)

I suspect that some versions of GCC will complain that prev_entry may be left initialized while handling the modify_map case below, even though it is initialized correctly in that case.

2853 ↗(On Diff #64500)

These assignments could be placed in a for-loop header.

sys/vm/vm_map.h
426 ↗(On Diff #64500)

You have an extra newline in the function below. The newline is now optional per style(9), but we should be consistent within the same file.

This revision is now accepted and ready to land.Nov 18 2019, 6:53 PM
sys/vm/vm_map.c
3399–3402 ↗(On Diff #64500)

I would find this clearer if it were written with entry and next_entry, not prev_entry.

sys/vm/vm_map.c
2969–2970 ↗(On Diff #64500)

Again, I think that this would be clearer if it were written with entry and next_entry.

3286–3287 ↗(On Diff #64500)

Initializing prev_entry and entry in the same order in both the then and else clause will make this easier to read.

dougm marked 6 inline comments as done.

Accept reviewer suggestions. Where the introduction of "next_entry" suggests that a for loop could replace a while loop, do so. Where that looks tricky because of a mid-loop continue (wire/unwire), make sure the continue case sets next_entry too. Observe that this all makes the 'first_iteration' state variable redundant, and eliminate it.

This revision now requires review to proceed.Nov 19 2019, 4:17 AM

Address small style violations from an in-person review.

sys/vm/vm_map.c
3121 ↗(On Diff #64607)

unsorted

3230 ↗(On Diff #64607)

indentation

dougm marked 2 inline comments as done.

Address reviewer feedback.

sys/vm/vm_map.c
2971 ↗(On Diff #64607)

unnecessary parens

sys/vm/vm_map.c
3743 ↗(On Diff #64608)

need spaces around the bitwise or.

dougm marked 2 inline comments as done.

Address online and offline comments.

Undo some overzealous style-fixing.

In all the loops over map entries where the iterator wasn't called 'entry' and the last several versions of this patch renamed it to 'entry', revert the name back to what is was before, mostly limiting this patch to its original purpose and leaving a renaming patch for another day.

sys/vm/vm_map.c
2690 ↗(On Diff #64613)

This assignment would fit at the end of the previous line.

While I like the suggestion that we use a consistent variable naming schema, I felt like those style changes were overwhelming the functional changes. So, I asked Doug to separate the functional and stylistic changes.

This revision is now accepted and ready to land.Nov 20 2019, 3:58 PM