Commit 63f1d16e authored by Bartek Nowierski's avatar Bartek Nowierski Committed by Chromium LUCI CQ

[PartitionAlloc] Make pages inaccessible *after* discarding

crrev.com/c/2550119 caused a surprising memory regression on Mac.
It was taken care of in crrev.com/c/2563038, by "relaxing" one caller,
but the question of other caller remained. Turns out that reordering
SetSystemPagesAccess past DiscardSystemPages in DecommitSystemPages also
takes care of that regression:
https://pinpoint-dot-chromeperf.appspot.com/job/1425cfb7520000

This is unfortunate, as preferably we'd want to avoid a window when
discarded pages can be faulted in. However, prior to crrev.com/c/2550119
almost all callers (except one) would call SetSystemPagesAccess after
DiscardSystemPages, so in that sense this CL brings back the old, well
tested behavior.

Similarly reorder operations in RecommitSystemPages. The callers were
split 50/50 on this prior to crrev.com/c/2550119 and no regressions
were observed, so it likely doesn't matter either way. It just seems
to make more sense to have operations in the opposite order to
DecommitSystemPages.

PS
This CL doesn't change memory usage on Linux or Android, but also no
regressions were observed there to begin with.
https://pinpoint-dot-chromeperf.appspot.com/job/172620fb520000
https://pinpoint-dot-chromeperf.appspot.com/job/15212cd7520000

PS2
It has been confirmed theoretically that ordering on Fuchsia shouldn't
matter, so stick to the preferred ordering.

Bug: 1153021
Change-Id: Icb937ffed2420859e6006aa2e1af555661bfe541
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2563052Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Commit-Queue: Bartek Nowierski <bartekn@chromium.org>
Auto-Submit: Bartek Nowierski <bartekn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833631}
parent 44783281
...@@ -247,14 +247,20 @@ void DecommitSystemPagesInternal( ...@@ -247,14 +247,20 @@ void DecommitSystemPagesInternal(
void* address, void* address,
size_t length, size_t length,
PageAccessibilityDisposition accessibility_disposition) { PageAccessibilityDisposition accessibility_disposition) {
if (accessibility_disposition == PageUpdatePermissions) {
SetSystemPagesAccess(address, length, PageInaccessible);
}
// In POSIX, there is no decommit concept. Discarding is an effective way of // In POSIX, there is no decommit concept. Discarding is an effective way of
// implementing the Windows semantics where the OS is allowed to not swap the // implementing the Windows semantics where the OS is allowed to not swap the
// pages in the region. // pages in the region.
DiscardSystemPages(address, length); DiscardSystemPages(address, length);
// Make pages inaccessible, unless the caller requested to keep permissions.
//
// Note, there is a small window between these calls when the pages can be
// incorrectly touched and brought back to memory. Not ideal, but doing those
// operaions in the opposite order resulted in PMF regression on Mac (see
// crbug.com/1153021).
if (accessibility_disposition == PageUpdatePermissions) {
SetSystemPagesAccess(address, length, PageInaccessible);
}
} }
void RecommitSystemPagesInternal( void RecommitSystemPagesInternal(
...@@ -262,12 +268,6 @@ void RecommitSystemPagesInternal( ...@@ -262,12 +268,6 @@ void RecommitSystemPagesInternal(
size_t length, size_t length,
PageAccessibilityConfiguration accessibility, PageAccessibilityConfiguration accessibility,
PageAccessibilityDisposition accessibility_disposition) { PageAccessibilityDisposition accessibility_disposition) {
#if defined(OS_APPLE)
// On macOS, to update accounting, we need to make another syscall. For more
// details, see https://crbug.com/823915.
madvise(address, length, MADV_FREE_REUSE);
#endif
// On POSIX systems, the caller need simply read the memory to recommit it. // On POSIX systems, the caller need simply read the memory to recommit it.
// This has the correct behavior because the API requires the permissions to // This has the correct behavior because the API requires the permissions to
// be the same as before decommitting and all configurations can read. // be the same as before decommitting and all configurations can read.
...@@ -276,6 +276,12 @@ void RecommitSystemPagesInternal( ...@@ -276,6 +276,12 @@ void RecommitSystemPagesInternal(
if (accessibility_disposition == PageUpdatePermissions) { if (accessibility_disposition == PageUpdatePermissions) {
SetSystemPagesAccess(address, length, accessibility); SetSystemPagesAccess(address, length, accessibility);
} }
#if defined(OS_APPLE)
// On macOS, to update accounting, we need to make another syscall. For more
// details, see https://crbug.com/823915.
madvise(address, length, MADV_FREE_REUSE);
#endif
} }
void DiscardSystemPagesInternal(void* address, size_t length) { void DiscardSystemPagesInternal(void* address, size_t length) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment