1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/*
* Copyright (C) 2022 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <sys/sysinfo.h>
#include <libinit_utils.h>
#include <libinit_dalvik_heap.h>
#define HEAPSTARTSIZE_PROP "dalvik.vm.heapstartsize"
#define HEAPGROWTHLIMIT_PROP "dalvik.vm.heapgrowthlimit"
#define HEAPSIZE_PROP "dalvik.vm.heapsize"
#define HEAPMINFREE_PROP "dalvik.vm.heapminfree"
#define HEAPMAXFREE_PROP "dalvik.vm.heapmaxfree"
#define HEAPTARGETUTILIZATION_PROP "dalvik.vm.heaptargetutilization"
#define GB(b) (b * 1024ull * 1024 * 1024)
static const dalvik_heap_info_t dalvik_heap_info_6144 = {
.heapstartsize = "16m",
.heapgrowthlimit = "256m",
.heapsize = "512m",
.heapminfree = "8m",
.heapmaxfree = "32m",
.heaptargetutilization = "0.5",
};
static const dalvik_heap_info_t dalvik_heap_info_4096 = {
.heapstartsize = "8m",
.heapgrowthlimit = "256m",
.heapsize = "512m",
.heapminfree = "8m",
.heapmaxfree = "16m",
.heaptargetutilization = "0.6",
};
static const dalvik_heap_info_t dalvik_heap_info_2048 = {
.heapstartsize = "8m",
.heapgrowthlimit = "192m",
.heapsize = "512m",
.heapminfree = "512k",
.heapmaxfree = "8m",
.heaptargetutilization = "0.75",
};
void set_dalvik_heap() {
struct sysinfo sys;
const dalvik_heap_info_t *dhi;
sysinfo(&sys);
if (sys.totalram > GB(5))
dhi = &dalvik_heap_info_6144;
else if (sys.totalram > GB(3))
dhi = &dalvik_heap_info_4096;
else
dhi = &dalvik_heap_info_2048;
property_override(HEAPSTARTSIZE_PROP, dhi->heapstartsize);
property_override(HEAPGROWTHLIMIT_PROP, dhi->heapgrowthlimit);
property_override(HEAPSIZE_PROP, dhi->heapsize);
property_override(HEAPTARGETUTILIZATION_PROP, dhi->heaptargetutilization);
property_override(HEAPMINFREE_PROP, dhi->heapminfree);
property_override(HEAPMAXFREE_PROP, dhi->heapmaxfree);
}
|