Enable code ordering on ARM64 |
|||
Issue descriptionCode ordering is only enabled on ARM, not on 64 bit devices. As the ordering is likely also useful for Webview to reduce memory usage, we should enable it on ARM64 as well. To start with, using the ARM orderfile should be enough, as we don't instrument ASM functions anyway. The inaccuracy would come from C/C++ functions that are called on ARM64, and not on ARM. Other source of inaccuracies would be due to different ICF / inlining decisions on ARM and ARM64. Note: This may increase binary size, as code ordering constraints may force the linker to generate worse code. For ARM, we force the linker to generate more long jump/call thunks, but on ARM64 PC-relative calls have a range of +/-128MB, so this should not be an issue.
,
Jan 24 2018
tl;dr: With minimal modifications, we get a 6966kB PSS improvement with 0 binary size cost on Chrome 64 bit.
Simply enabling the existing ordering we have for ARM on ARM64, we see (with extract_symbols.py above) that code ordering works in master.
Then, building chrome_apk, and using this function:
function cold_start {
url=$1
echo $url
adb shell 'am force-stop com.google.android.apps.chrome'
adb shell "echo 3 > /proc/sys/vm/drop_caches; am start -a 'android.intent.action.VIEW' -n com.google.android.apps.chrome/.Main -d $url"
}
to start chrome with a URL, and this script to get PSS coming from the native library:
#!/usr/bin/python
import subprocess
_PACKAGE_NAME = 'com.google.android.apps.chrome'
def GetPids():
command_template = 'adb shell ps | grep %s | sed -e "s/ \+/,/g" | cut -f2 -d,'
p = subprocess.Popen(command_template % _PACKAGE_NAME, shell=True,
stdout=subprocess.PIPE)
(out, _) = p.communicate()
pids = [int(line) for line in out.split('\n') if line]
return pids
def GetPssFromProcSmaps(pid):
command = 'adb shell cat /proc/%d/smaps' % pid
p = subprocess.Popen(command.split(' '), stdout=subprocess.PIPE)
(out, _) = p.communicate()
lines = out.split('\n')[:-1]
for (index, line) in enumerate(lines):
if 'r-xp' in line and 'base.apk' in line:
print '\n'.join(lines[index:index + 17])
pss_line = lines[index + 3]
assert pss_line.startswith('Pss:')
pss = int(pss_line[len('Pss:'):-2])
return pss
return -1
def main():
pids = GetPids()
print pids
total_pss = 0
for pid in pids:
pss = GetPssFromProcSmaps(pid)
assert pss != -1
total_pss += pss
print 'Total PSS from libchrome.so = %s kB' % total_pss
if __name__ == '__main__':
main()
We get without ordering:
$ cold_start "https://www.google.fr/search?q=babar"
https://www.google.fr/search?q=babar
Starting: Intent { act=android.intent.action.VIEW dat=https://www.google.fr/... cmp=com.google.android.apps.chrome/.Main }
$ python ~/Documents/get_pss.py
[8698, 8729, 8767]
70df1f2000-70e23f4000 r-xp 014c5000 fd:02 310697 /data/app/com.google.android.apps.chrome-eh7VUTd8lMl-4U7pbyMN2w==/base.apk
Size: 51208 kB
Rss: 16024 kB
Pss: 12475 kB
Shared_Clean: 6240 kB
Shared_Dirty: 0 kB
Private_Clean: 9784 kB
Private_Dirty: 0 kB
Referenced: 16024 kB
Anonymous: 0 kB
AnonHugePages: 0 kB
Swap: 0 kB
SwapPss: 0 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
Locked: 0 kB
VmFlags: rd ex mr mw me
70dfb40000-70e2d42000 r-xp 014c5000 fd:02 310697 /data/app/com.google.android.apps.chrome-eh7VUTd8lMl-4U7pbyMN2w==/base.apk
Size: 51208 kB
Rss: 21852 kB
Pss: 18321 kB
Shared_Clean: 6204 kB
Shared_Dirty: 0 kB
Private_Clean: 15648 kB
Private_Dirty: 0 kB
Referenced: 21852 kB
Anonymous: 0 kB
AnonHugePages: 0 kB
Swap: 0 kB
SwapPss: 0 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
Locked: 0 kB
VmFlags: rd ex mr mw me
70dfa4a000-70e2c4c000 r-xp 014c5000 fd:02 310697 /data/app/com.google.android.apps.chrome-eh7VUTd8lMl-4U7pbyMN2w==/base.apk
Size: 51208 kB
Rss: 3876 kB
Pss: 1991 kB
Shared_Clean: 2912 kB
Shared_Dirty: 0 kB
Private_Clean: 964 kB
Private_Dirty: 0 kB
Referenced: 3876 kB
Anonymous: 0 kB
AnonHugePages: 0 kB
Swap: 0 kB
SwapPss: 0 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
Locked: 0 kB
VmFlags: rd ex mr mw me
Total PSS from libchrome.so = 32787 kB
And with ordering:
$ cold_start "https://www.google.fr/search?q=babar"
https://www.google.fr/search?q=babar
Starting: Intent { act=android.intent.action.VIEW dat=https://www.google.fr/... cmp=com.google.android.apps.chrome/.Main }
$ python ~/Documents/get_pss.py
[9357, 9389, 9424]
70df300000-70e2502000 r-xp 014cf000 fd:02 310722 /data/app/com.google.android.apps.chrome-dQmS7APWSreNqUd1-VATnA==/base.apk
Size: 51208 kB
Rss: 11636 kB
Pss: 8439 kB
Shared_Clean: 5620 kB
Shared_Dirty: 0 kB
Private_Clean: 6016 kB
Private_Dirty: 0 kB
Referenced: 11636 kB
Anonymous: 0 kB
AnonHugePages: 0 kB
Swap: 0 kB
SwapPss: 0 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
Locked: 0 kB
VmFlags: rd ex mr mw me
70dfb22000-70e2d24000 r-xp 014cf000 fd:02 310722 /data/app/com.google.android.apps.chrome-dQmS7APWSreNqUd1-VATnA==/base.apk
Size: 51208 kB
Rss: 18952 kB
Pss: 15753 kB
Shared_Clean: 5624 kB
Shared_Dirty: 0 kB
Private_Clean: 13328 kB
Private_Dirty: 0 kB
Referenced: 18952 kB
Anonymous: 0 kB
AnonHugePages: 0 kB
Swap: 0 kB
SwapPss: 0 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
Locked: 0 kB
VmFlags: rd ex mr mw me
70dfa48000-70e2c4a000 r-xp 014cf000 fd:02 310722 /data/app/com.google.android.apps.chrome-dQmS7APWSreNqUd1-VATnA==/base.apk
Size: 51208 kB
Rss: 3372 kB
Pss: 1629 kB
Shared_Clean: 2712 kB
Shared_Dirty: 0 kB
Private_Clean: 660 kB
Private_Dirty: 0 kB
Referenced: 3372 kB
Anonymous: 0 kB
AnonHugePages: 0 kB
Swap: 0 kB
SwapPss: 0 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
Locked: 0 kB
VmFlags: rd ex mr mw me
Total PSS from libchrome.so = 25821 kB
,
Feb 2 2018
With WebView results now. Test: Look for "babar" in AGSA, get the PSS from chrome's native library on the SERP from /proc/$PID/smaps. tl;dr: ~5MB on Android N, ~2.5MB on Android O for PSS. Note that actual PSS gains will be lower in the field, as these are clean pages that are shared with the rest of webview apps currently resident in memory. Nexus 5X, Android N: Before: $ python ~/Documents/get_pss.py com.google.android.googlequicksearchbox:search com.google.android.googlequicksearchbox:search [11049] 72b753f000-72b7621000 r-xp 007c3000 fd:02 294418 /data/app/com.google.android.apps.chrome-1/oat/arm64/base.odex Size: 904 kB Rss: 360 kB Pss: 360 kB Shared_Clean: 0 kB Shared_Dirty: 0 kB Private_Clean: 360 kB Private_Dirty: 0 kB Referenced: 360 kB Anonymous: 0 kB AnonHugePages: 0 kB Swap: 0 kB SwapPss: 0 kB KernelPageSize: 4 kB MMUPageSize: 4 kB Locked: 0 kB VmFlags: rd ex mr mw me 72c47b7000-72c72c7000 r-xp 01522000 fd:02 294377 /data/app/com.google.android.apps.chrome-1/base.apk Size: 44096 kB Rss: 24764 kB Pss: 24764 kB Shared_Clean: 0 kB Shared_Dirty: 0 kB Private_Clean: 24764 kB Private_Dirty: 0 kB Referenced: 23796 kB Anonymous: 0 kB AnonHugePages: 0 kB Swap: 0 kB SwapPss: 0 kB KernelPageSize: 4 kB MMUPageSize: 4 kB Locked: 0 kB VmFlags: rd ex mr mw me Total PSS from libchrome.so = 25124 kB After: $ python ~/Documents/get_pss.py com.google.android.googlequicksearchbox:search com.google.android.googlequicksearchbox:search [13839] 72b713f000-72b7221000 r-xp 007c3000 fd:02 294796 /data/app/com.google.android.apps.chrome-2/oat/arm64/base.odex Size: 904 kB Rss: 360 kB Pss: 360 kB Shared_Clean: 0 kB Shared_Dirty: 0 kB Private_Clean: 360 kB Private_Dirty: 0 kB Referenced: 360 kB Anonymous: 0 kB AnonHugePages: 0 kB Swap: 0 kB SwapPss: 0 kB KernelPageSize: 4 kB MMUPageSize: 4 kB Locked: 0 kB VmFlags: rd ex mr mw me 72c47bf000-72c72cf000 r-xp 0152a000 fd:02 294780 /data/app/com.google.android.apps.chrome-2/base.apk Size: 44096 kB Rss: 19724 kB Pss: 19724 kB Shared_Clean: 0 kB Shared_Dirty: 0 kB Private_Clean: 19724 kB Private_Dirty: 0 kB Referenced: 19724 kB Anonymous: 0 kB AnonHugePages: 0 kB Swap: 0 kB SwapPss: 0 kB KernelPageSize: 4 kB MMUPageSize: 4 kB Locked: 0 kB VmFlags: rd ex mr mw me Total PSS from libchrome.so = 20084 kB For Android O+, only the "browser" process side is ARM64 and was unordered, the renderer side is ordered. Nexus 5X, Android O: Before: $ python ~/Documents/get_pss.py com.google.android.googlequicksearchbox:search com.google.android.googlequicksearchbox:search [9553] 70d9b19000-70d9c00000 r-xp 00058000 fd:02 310971 /data/app/com.google.android.apps.chrome-nrmtUtiSdYIwCJaaPDY9fw==/oat/arm64/base.odex Size: 924 kB Rss: 368 kB Pss: 368 kB Shared_Clean: 0 kB Shared_Dirty: 0 kB Private_Clean: 368 kB Private_Dirty: 0 kB Referenced: 368 kB Anonymous: 0 kB AnonHugePages: 0 kB Swap: 0 kB SwapPss: 0 kB KernelPageSize: 4 kB MMUPageSize: 4 kB Locked: 0 kB VmFlags: rd ex mr mw me 70e4bea000-70e76fa000 r-xp 01522000 fd:02 310782 /data/app/com.google.android.apps.chrome-nrmtUtiSdYIwCJaaPDY9fw==/base.apk Size: 44096 kB Rss: 10396 kB Pss: 10396 kB Shared_Clean: 0 kB Shared_Dirty: 0 kB Private_Clean: 10396 kB Private_Dirty: 0 kB Referenced: 10396 kB Anonymous: 0 kB AnonHugePages: 0 kB Swap: 0 kB SwapPss: 0 kB KernelPageSize: 4 kB MMUPageSize: 4 kB Locked: 0 kB VmFlags: rd ex mr mw me Total PSS from libchrome.so = 10764 kB After: $ python ~/Documents/get_pss.py com.google.android.googlequicksearchbox:search com.google.android.googlequicksearchbox:search [7659] 70d9a29000-70d9b10000 r-xp 00058000 fd:02 310967 /data/app/com.google.android.apps.chrome-TFT_7xI8NlgiaJQ3ke5G1g==/oat/arm64/base.odex Size: 924 kB Rss: 368 kB Pss: 368 kB Shared_Clean: 0 kB Shared_Dirty: 0 kB Private_Clean: 368 kB Private_Dirty: 0 kB Referenced: 368 kB Anonymous: 0 kB AnonHugePages: 0 kB Swap: 0 kB SwapPss: 0 kB KernelPageSize: 4 kB MMUPageSize: 4 kB Locked: 0 kB VmFlags: rd ex mr mw me 70e4bf2000-70e7702000 r-xp 0152a000 fd:02 310949 /data/app/com.google.android.apps.chrome-TFT_7xI8NlgiaJQ3ke5G1g==/base.apk Size: 44096 kB Rss: 7880 kB Pss: 7880 kB Shared_Clean: 0 kB Shared_Dirty: 0 kB Private_Clean: 7880 kB Private_Dirty: 0 kB Referenced: 7880 kB Anonymous: 0 kB AnonHugePages: 0 kB Swap: 0 kB SwapPss: 0 kB KernelPageSize: 4 kB MMUPageSize: 4 kB Locked: 0 kB VmFlags: rd ex mr mw me Total PSS from libchrome.so = 8248 kB
,
Feb 2 2018
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/fbe04e51d41b59d61f26a9ddd671c35eb1c1b6e5 commit fbe04e51d41b59d61f26a9ddd671c35eb1c1b6e5 Author: Benoit Lize <lizeb@chromium.org> Date: Fri Feb 02 17:09:19 2018 aw: Add support for code ordering in monochrome 64bit. "extra_chrome_shared_library_configs" is used to enable code ordering, but is only added for 32 bit webview. Add this config. A downstream change will enable ordering for ARM64, saving: - ~6.9MB of PSS for Chrome ARM64 (not widely released) - ~5MB of PSS in Android Search App on Android N - ~2.5MB of PSS in Android Search App on Android O Similar gains are expected for other webview apps, see attached bug. Bug: 803866 Change-Id: If15d319bf7fbc58c3ac76898a5d7893ba0ade32c Reviewed-on: https://chromium-review.googlesource.com/899362 Reviewed-by: agrieve <agrieve@chromium.org> Reviewed-by: Bo <boliu@chromium.org> Commit-Queue: Benoit L <lizeb@chromium.org> Cr-Commit-Position: refs/heads/master@{#534078} [modify] https://crrev.com/fbe04e51d41b59d61f26a9ddd671c35eb1c1b6e5/android_webview/BUILD.gn
,
Feb 3 2018
The following revision refers to this bug: https://chrome-internal.googlesource.com/clank/internal/apps/+/3da7451687eaeea7d7a41f3003e85b933e7c8a20 commit 3da7451687eaeea7d7a41f3003e85b933e7c8a20 Author: Benoît Lizé <lizeb@google.com> Date: Sat Feb 03 03:30:17 2018
,
Feb 20 2018
,
Feb 20 2018
perezju: do we have downstream webview memory coverage that could notice an improvement from this code reordering optimization? (in magnitude of 2+ MiB) Would be great to associate an alert with this improvement, but I am not sure where to look.
,
Feb 20 2018
Yes, we do, e.g. here: https://chromeperf.appspot.com/report?sid=421ed9b2d95aa5c4feb57f04fbbc32973d9573341765ca9a01bcc1b2cf97aac9&start_rev=1516156182&end_rev=1519128143 There is also a health-plan-clankium-low-end-phone, and we also run system_health.memory_mobile on those bots.
,
Feb 20 2018
Thanks! From a random build page, looks like this bot is running Nexus 5 (hammerhead), is this the case? If so, then seeing no change is expected, as it runs 32 bit code only.
,
Feb 20 2018
This is correct we run: - health-plan-webview-phone - Nexus 5 (hammerhead) - Android M - health-plan-webview-low-end-phone - Nexus 4 (occam-svelte) - Android M both using 32 bit only AFAIK. There is also: - perf-monochrome-n-phone - Nexus 5X (bullhead) - Android N which should be using 64 bit from Monochrome.apk See e.g.: https://chromeperf.appspot.com/report?sid=f67b1672ca5e1f890c23ecdc981852e89b2e2989a04c935a860e8bc821d5df89&start_rev=1516156182&end_rev=1519128143 Note: when looking at metrics from that bot be careful that (1) the metric name says "memory:webview:*" and you are looking at stories in the "on_webview" bucket. (The benchmark runs both chrome and webview simultaneously.)
,
Mar 2 2018
The following revision refers to this bug: https://chrome-internal.googlesource.com/clank/internal/apps/+/932aca3cb0b0baf9a3df9534669316da4b2c74be commit 932aca3cb0b0baf9a3df9534669316da4b2c74be Author: Benoit Lize <lizeb@google.com> Date: Fri Mar 02 12:41:39 2018
,
Mar 5 2018
Time to reland the patch, perf bots show a very clear memory regression in the commit range of the revert landing. This confirms that the initial commit helped. See https://chromeperf.appspot.com/report?sid=56e5aed9c1d10408dc8ca0d2e660e95d24866f98b41c15262762999b72b9f7ed&start_rev=1517017740&end_rev=1520235578 The last jump there corresponds to the revert, the magnitude of which is ~5.4MB, in line with (although a bit higher than) the estimate from local experiments.
,
Mar 5 2018
The following revision refers to this bug: https://chrome-internal.googlesource.com/clank/internal/apps/+/3546b2301252b454caf7d2baef518aff7fb5ca55 commit 3546b2301252b454caf7d2baef518aff7fb5ca55 Author: Benoit Lize <lizeb@google.com> Date: Mon Mar 05 11:07:29 2018 |
|||
►
Sign in to add a comment |
|||
Comment 1 by bugdroid1@chromium.org
, Jan 24 2018