(1) The system defined in init. RC
The values in lowmeme_adj represent the threshold value warning level, and lowmem_minfree represents the remaining memory of the corresponding level.
When the remaining system memory is less than 6 MB, the warning level is 0. When the remaining system memory is less than 8 MB and greater than 6 MB, the warning level is 1, when the memory size is smaller than 64 MB and greater than 16 MB, the rule that sets the alert level to 12.low memory killer is to obtain the current alert level based on the amount of memory remaining in the current system, if the oom_adj value of a process is greater than the alert level and the maximum value, the process will be killed (if the omm_adj value is the same, the process will consume a large amount of memory ). The smaller the omm_adj, the more important the process is. Some front-end processes, oom_adj will be relatively small, while the background services, omm_adj will be relatively large, so when the memory is insufficient, low memory killer must first kill background services rather than foreground processes.
# Define the oom_adj values for the classes of processes that can be
# Killed by the kernel. These are used in activitymanagerservice.
Setprop Ro. foreground_app_adj 0
Setprop Ro. visible_app_adj 1
Setprop Ro. perceptible_app_adj 2
Setprop Ro. heavy_weight_app_adj 3
Setprop Ro. secondary_server_adj 4
Setprop Ro. backup_app_adj 5
Setprop Ro. home_app_adj 6
Setprop Ro. hidden_app_min_adj 7
Setprop Ro. empty_app_adj 15
# Define the memory thresholds at which the above process classes will
# Be killed. These numbers are in pages (4 K ).
Setprop Ro. foreground_app_mem 2048
Setprop Ro. visible_app_mem 3072
Setprop Ro. perceptible_app_mem 4096
Setprop Ro. heavy_weight_app_mem 4096
Setprop Ro. secondary_server_mem 6144
Setprop Ro. backup_app_mem 6144
Setprop Ro. home_app_mem 6144
Setprop Ro. hidden_app_mem 7168
Setprop Ro. empty_app_mem 8192
(2) The GC list of VMS is one-minute round-robin.
Memory will be reclaimed when the following conditions are met
While (mprocessestogc. Size ()> 0 ){
Processrecord proc = mprocessestogc. Remove (0 );
If (Proc. currawadj> perceptible_app_adj | Proc. reportlowmemory ){
If (Proc. lastrequestedgc + gc_min_interval)
<= Systemclock. uptimemillis ()){
// To avoid spamming the system, we will GC processes one
// At a time, waiting a few seconds between each.
Performappgclocked (Proc );
Scheduleappgcslocked ();
Return;
} Else {
// It hasn' t been long enough since we last gced this
// Process... put it in the list to wait for its time.
Addprocesstogclistlocked (Proc );
Break;
}
}
}
1. If a process is not a foreground process and has a lower priority than perceptible, you can close the background program of the process and release its memory.
2. Process disconnects the binder before the process is closed, and notifies the VM to close the memory requested by the Java program.
(3) VM reclaim memory type
/* Not enough space for an "ordinary" object to be allocated .*/
Gc_for_malloc,
/* Automatic GC triggered by exceeding a heap occupancy threshold .*/
Gc_concurrent,
/* Explicit GC via runtime. GC (), vmruntime. GC (), or sigusr1 .*/
Gc_explicit,
/* GC to try to reduce heap footprint to allow more non-GC 'ed memory .*/
Gc_external_alloc,
/* GC to dump heap contents to a file, only used under with_hprof */
Gc_hprof_dump_heap