Commit 27b544b
committed
base: mitigate system_server boot OOM on 512 MB heaps
Insert three explicit GC passes at strategic points during
system_server boot to relieve heap pressure from transient service
allocations:
1. After PHASE_SYSTEM_SERVICES_READY — reclaims garbage accumulated
during startBootstrapServices and startCoreServices.
2. Before AMS.systemReady() — reclaims transient allocations from
startOtherServices before the heaviest boot phase begins.
3. Before PHASE_THIRD_PARTY_APPS_CAN_START — reclaims 100-300 MB
of garbage from service-ready callbacks that spike heap usage
after Phase 550, preventing OOM during app launch ramp-up.
Additionally, tune the AppsFilter boot cache rebuild:
- Defer the initial cache build by 20 seconds so transient boot
allocations can be collected first.
- Build the cache in small chunks with brief lock releases between
them, preceded by an explicit GC, so the work does not spike
heap usage.
- Remove upfront setCapacity() from the boot path so the filter
matrix grows incrementally instead of pre-allocating.
- Avoid repeated ArraySet allocation in shouldFilterApplication()
for non-shared-user packages by using a static empty instance.
On memory-constrained devices the boot allocation storm can exhaust
a 512 MB system_server heap within 20 seconds. These changes give
the garbage collector enough breathing room to keep up.
Tested: 6 consecutive reboots with zero OOM events, heap peak
197/228 MB (vs. OOM crash within 20s pre-patch), PMS init ~31s.
Change-Id: Iee1253f2b01d5d018f377bf10ff3fe338b240bac
Signed-off-by: Quince <quinceroms@gmail.com>1 parent 8d67df6 commit 27b544b
3 files changed
Lines changed: 104 additions & 22 deletions
File tree
- services
- core/java/com/android/server/pm
- java/com/android/server
Lines changed: 19 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
75 | 84 | | |
76 | 85 | | |
77 | 86 | | |
| |||
428 | 437 | | |
429 | 438 | | |
430 | 439 | | |
431 | | - | |
| 440 | + | |
432 | 441 | | |
433 | 442 | | |
434 | 443 | | |
| |||
437 | 446 | | |
438 | 447 | | |
439 | 448 | | |
| 449 | + | |
440 | 450 | | |
| 451 | + | |
| 452 | + | |
441 | 453 | | |
442 | 454 | | |
443 | 455 | | |
| 456 | + | |
444 | 457 | | |
445 | 458 | | |
446 | 459 | | |
| 460 | + | |
447 | 461 | | |
448 | 462 | | |
449 | 463 | | |
| |||
Lines changed: 59 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
804 | 804 | | |
805 | 805 | | |
806 | 806 | | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
807 | 837 | | |
808 | 838 | | |
809 | 839 | | |
810 | 840 | | |
811 | | - | |
812 | | - | |
813 | | - | |
814 | | - | |
815 | | - | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
816 | 856 | | |
817 | 857 | | |
818 | 858 | | |
| |||
829 | 869 | | |
830 | 870 | | |
831 | 871 | | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
832 | 885 | | |
833 | | - | |
834 | | - | |
835 | 886 | | |
836 | 887 | | |
837 | 888 | | |
838 | 889 | | |
839 | 890 | | |
840 | | - | |
841 | | - | |
842 | | - | |
843 | | - | |
844 | | - | |
845 | | - | |
846 | | - | |
847 | | - | |
848 | | - | |
849 | | - | |
| 891 | + | |
850 | 892 | | |
851 | 893 | | |
852 | 894 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3253 | 3253 | | |
3254 | 3254 | | |
3255 | 3255 | | |
| 3256 | + | |
| 3257 | + | |
| 3258 | + | |
| 3259 | + | |
| 3260 | + | |
| 3261 | + | |
| 3262 | + | |
| 3263 | + | |
| 3264 | + | |
3256 | 3265 | | |
3257 | 3266 | | |
3258 | 3267 | | |
| |||
3428 | 3437 | | |
3429 | 3438 | | |
3430 | 3439 | | |
| 3440 | + | |
| 3441 | + | |
| 3442 | + | |
| 3443 | + | |
| 3444 | + | |
| 3445 | + | |
| 3446 | + | |
| 3447 | + | |
3431 | 3448 | | |
3432 | 3449 | | |
3433 | 3450 | | |
| |||
3563 | 3580 | | |
3564 | 3581 | | |
3565 | 3582 | | |
| 3583 | + | |
| 3584 | + | |
| 3585 | + | |
| 3586 | + | |
| 3587 | + | |
| 3588 | + | |
| 3589 | + | |
| 3590 | + | |
| 3591 | + | |
3566 | 3592 | | |
3567 | 3593 | | |
3568 | 3594 | | |
| |||
0 commit comments