This is an archive of the discontinued LLVM Phabricator instance.

[scudo][standalone] Precommit pages
ClosedPublic

Authored by yaneury on Dec 19 2022, 10:26 AM.

Details

Summary

On Fuchsia, this CL changes garbage collection
to precommit all pages if the |Buffer| doesn't
fit into the static buffer size.

A test program (scudotest) was used that deliberately
grows a size class high water mark to the point where
the pre-allocated static buffer is no longer used for
garbage collection.

Traces showed that precommiting the Vmar removes ~30 page faults
and ~.22ms of wall time.*

Before: https://ui.perfetto.dev/#!/?s=7da19fc3f59448eef51fd6fd03283bb87b702cf1a565bcbe6c9c28371671
After: https://ui.perfetto.dev/#!/?s=97707cd99b2c9efd1e6569b2deb97e3d16f8be532c59a0cc12463c37fbb1d8

*: Use the added zx_vmar_op_range as a reference point to observe
the differences.

For more context, see https://fxbug.dev/115594.

Diff Detail

Event Timeline

yaneury created this revision.Dec 19 2022, 10:26 AM
yaneury requested review of this revision.Dec 19 2022, 10:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 19 2022, 10:26 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
cryptoad added inline comments.Dec 19 2022, 10:42 AM
compiler-rt/lib/scudo/standalone/release.h
117

Probably can use a construct like MAP_ALLOWNOMEM | (SCUDO_FUCHSIA ? MAP_PRECOMMIT : 0) (or something in that general realm) to avoid the #ifdef duplication

The reduction of number of page faults is expected. I'm curious about how it impacts the real cases(Especially when we have D140311). Like the scenario mentioned in https://bugs.fuchsia.dev/p/fuchsia/issues/detail?id=115594#c3

yaneury updated this revision to Diff 484035.Dec 19 2022, 12:12 PM

Readability improvements

yaneury marked an inline comment as done.Dec 19 2022, 12:13 PM
yaneury updated this revision to Diff 484036.Dec 19 2022, 12:14 PM

Readability improvements

Chia-hungDuan added inline comments.Dec 19 2022, 12:27 PM
compiler-rt/lib/scudo/standalone/release.h
117

Sorry I should leave the comment earlier. Can we do something like

// Comment...
int MmapFlags = ...;
...
... = map (... MmapFlags ...);

So that the comment be attached to the flag closer and we can refine the comment to be more Fuchsia specific.
Just to raise the concern here again (it was in D139897). We may over commit pages before we can allocate page map only for groups to be released (I'm working on this). Now this is known to be benefit to Fuchsia platform so I think it'll be better to make it Fuchsia specific at this moment.

yaneury updated this revision to Diff 484045.Dec 19 2022, 12:58 PM

Readability improvements, use MmapFlags var

yaneury marked an inline comment as done.Dec 19 2022, 12:58 PM
cryptoad added inline comments.Dec 19 2022, 1:13 PM
compiler-rt/lib/scudo/standalone/release.h
114

If you go that route, const this, and also flags is a uptr in the prototype of map, so we should keep that type to avoid compiler complains.

yaneury updated this revision to Diff 484065.Dec 19 2022, 2:07 PM

Set type of MmapFlags to const uptr

yaneury marked an inline comment as done.Dec 19 2022, 2:08 PM
Chia-hungDuan accepted this revision.Dec 19 2022, 3:46 PM
Chia-hungDuan added inline comments.
compiler-rt/lib/scudo/standalone/fuchsia.cpp
106–109

Just out of curious, can this be done at _zx_vmar_map?

This revision is now accepted and ready to land.Dec 19 2022, 3:46 PM
yaneury marked an inline comment as done.Dec 19 2022, 3:53 PM
yaneury added inline comments.
compiler-rt/lib/scudo/standalone/fuchsia.cpp
106–109

It's not supported AFAIK but would be a useful addition.

Chia-hungDuan added inline comments.Dec 19 2022, 4:19 PM
compiler-rt/lib/scudo/standalone/fuchsia.cpp
106–109

Is ZX_VM_MAP_RANGE something similar? Sorry, I'm not familiar with Fuchsia, just did a random scan of that page.

yaneury marked 2 inline comments as done.Dec 19 2022, 5:42 PM
yaneury added inline comments.
compiler-rt/lib/scudo/standalone/fuchsia.cpp
106–109

Good question. Asked the kernel folks about this and there's a slight difference. ZX_VM_MAP_RANGE will only fill hardware translation for present pages. ZX_VMAR_OP_COMMIT, on the other hand, does this AND commits the absent pages into the backing VMO(s).

yaneury marked an inline comment as done.Dec 19 2022, 5:57 PM

Btw, how can I get this change to land? I don't see a submit button...

@Chia-hungDuan, would you mind submitting this change?

@Chia-hungDuan, would you mind submitting this change?

Sure, I'll do it later

compiler-rt/lib/scudo/standalone/fuchsia.cpp
106–109

Thanks for explanation!

This revision was automatically updated to reflect the committed changes.