BKK16-206 AOSP RAM reduction project retrospective
-
Upload
linaro -
Category
Technology
-
view
454 -
download
5
Transcript of BKK16-206 AOSP RAM reduction project retrospective
![Page 1: BKK16-206 AOSP RAM reduction project retrospective](https://reader034.fdocuments.in/reader034/viewer/2022042706/58a335ca1a28ab9b6d8b5861/html5/thumbnails/1.jpg)
Presented by
Date
Event
AOSP RAM reduction project retrospective
Bernhard “Bero” Rosenkränzer,YongQin Liu
BKK16-206 March 8, 2016
Linaro Connect BKK16
![Page 2: BKK16-206 AOSP RAM reduction project retrospective](https://reader034.fdocuments.in/reader034/viewer/2022042706/58a335ca1a28ab9b6d8b5861/html5/thumbnails/2.jpg)
The Goal:
Reduce AOSP memory requirements without hurting performance too badly
![Page 3: BKK16-206 AOSP RAM reduction project retrospective](https://reader034.fdocuments.in/reader034/viewer/2022042706/58a335ca1a28ab9b6d8b5861/html5/thumbnails/3.jpg)
What did we try?
● Update toolchains● Make use of new features in
updated toolchains● Split libraries into smaller parts● Tweak settings● Replace the memory allocator
![Page 4: BKK16-206 AOSP RAM reduction project retrospective](https://reader034.fdocuments.in/reader034/viewer/2022042706/58a335ca1a28ab9b6d8b5861/html5/thumbnails/4.jpg)
Update Toolchains
In Android M, gcc 4.9 is used to compile most parts of the OS.
We’ve replaced it with Linaro gcc 5.3 and updated binutils to 2.26 to go along with it.
![Page 5: BKK16-206 AOSP RAM reduction project retrospective](https://reader034.fdocuments.in/reader034/viewer/2022042706/58a335ca1a28ab9b6d8b5861/html5/thumbnails/5.jpg)
Make use of new toolchain features
New toolchains give us new features that aren’t activated by default - e.g. -mcpu=cortex-a57
-mfpu=neon-fp16 etc. can generate faster and smaller code (for maximum effect, needs -ffast-math so regular FP instructions can be offloaded to the NEON unit)
![Page 6: BKK16-206 AOSP RAM reduction project retrospective](https://reader034.fdocuments.in/reader034/viewer/2022042706/58a335ca1a28ab9b6d8b5861/html5/thumbnails/6.jpg)
Make use of new toolchain features
Some helpful toolchain features exist even in 4.9, but aren’t used…
![Page 7: BKK16-206 AOSP RAM reduction project retrospective](https://reader034.fdocuments.in/reader034/viewer/2022042706/58a335ca1a28ab9b6d8b5861/html5/thumbnails/7.jpg)
Make use of new toolchain features
-Bsymbolic - binds references to global symbols to the definition within the shared library.Generates smaller and more memory efficient code, at the cost of breaking LD_PRELOAD etc. (which isn’t used in regular AOSP use anyway)
![Page 8: BKK16-206 AOSP RAM reduction project retrospective](https://reader034.fdocuments.in/reader034/viewer/2022042706/58a335ca1a28ab9b6d8b5861/html5/thumbnails/8.jpg)
Make use of new toolchain features
-fvisibility=hidden/-fvisibility=protectedHide symbols to the outside world - allows throwing some code away
![Page 9: BKK16-206 AOSP RAM reduction project retrospective](https://reader034.fdocuments.in/reader034/viewer/2022042706/58a335ca1a28ab9b6d8b5861/html5/thumbnails/9.jpg)
Split libraries into smaller parts
Many libraries combine very commonly used functionality and rarely used functionality, e.g.libpng/libjpeg/libgif:Decoder: Used by launcher (icons), gallery, browser, …Encoder: Rarely used
![Page 10: BKK16-206 AOSP RAM reduction project retrospective](https://reader034.fdocuments.in/reader034/viewer/2022042706/58a335ca1a28ab9b6d8b5861/html5/thumbnails/10.jpg)
Split libraries into smaller parts
zlib:Decompression: Used frequently (esp. as part of libpng)Compression: rarely used
![Page 11: BKK16-206 AOSP RAM reduction project retrospective](https://reader034.fdocuments.in/reader034/viewer/2022042706/58a335ca1a28ab9b6d8b5861/html5/thumbnails/11.jpg)
Tweak settings
ART has numerous settings that affect its memory use - e.g.:dalvik.vm.heapstartsize=8m
dalvik.vm.heapgrowthlimit=64m
dalvik.vm.heapsize=174m
dalvik.vm.heaptargetutilization=0.75
dalvik.vm.heapminfree=512k
dalvik.vm.heapmaxfree=2m
![Page 12: BKK16-206 AOSP RAM reduction project retrospective](https://reader034.fdocuments.in/reader034/viewer/2022042706/58a335ca1a28ab9b6d8b5861/html5/thumbnails/12.jpg)
Replace the memory allocator
Bionic comes with two allocators - jemalloc and dlmalloc.jemalloc:● default malloc● scales well with many CPU cores
![Page 13: BKK16-206 AOSP RAM reduction project retrospective](https://reader034.fdocuments.in/reader034/viewer/2022042706/58a335ca1a28ab9b6d8b5861/html5/thumbnails/13.jpg)
Replace the memory allocator
dlmalloc:● much more efficient with low
memory devices● doesn’t scale well with many CPU
cores● likely to be removed for Android N
![Page 14: BKK16-206 AOSP RAM reduction project retrospective](https://reader034.fdocuments.in/reader034/viewer/2022042706/58a335ca1a28ab9b6d8b5861/html5/thumbnails/14.jpg)
Replace the memory allocator
Is there a best of both worlds?We’ve investigated jemalloc, dlmalloc, ptmalloc2, ptmalloc3.Followup projects still in progress: TLSF malloc, tcmalloc, nedmalloc, musl’s malloc (essentially dlmalloc algorithm with better locking)
![Page 15: BKK16-206 AOSP RAM reduction project retrospective](https://reader034.fdocuments.in/reader034/viewer/2022042706/58a335ca1a28ab9b6d8b5861/html5/thumbnails/15.jpg)
Overall results
performance nearly constant (actually slightly increasing)
memory use down by 250 MB
![Page 16: BKK16-206 AOSP RAM reduction project retrospective](https://reader034.fdocuments.in/reader034/viewer/2022042706/58a335ca1a28ab9b6d8b5861/html5/thumbnails/16.jpg)
Results
Toolchain features, malloc implementation, settings were all more effective than splitting libraries (which was most work).Smaller changes can be more effective.
![Page 17: BKK16-206 AOSP RAM reduction project retrospective](https://reader034.fdocuments.in/reader034/viewer/2022042706/58a335ca1a28ab9b6d8b5861/html5/thumbnails/17.jpg)
More room for optimizations
● Kernel features like zramfs and KSM (kernel samepage merging) have not been used in tests (postponed until new enough kernels can boot to UI on Nexus 7)
● SLOB allocator should probably be used in low-RAM kernels
![Page 18: BKK16-206 AOSP RAM reduction project retrospective](https://reader034.fdocuments.in/reader034/viewer/2022042706/58a335ca1a28ab9b6d8b5861/html5/thumbnails/18.jpg)
More room for optimizations
● Investigate more malloc implementations
● Reimplement some Java based components in C/C++
● Check memory efficiency of various filesystems
● Repeat investigations in 64-bit world