1# Huge Pages
2
3From Android 15, the pKVM hypervisor supports Transparent Hugepages. This is a
4Linux feature which allows the kernel to allocate, when possible, a huge-page
5(typically, 2MiB on a 4K system). This huge-page being the size of a block,
6the hypervisor can leverage this allocation to also use a block mapping
7in the stage-2 page tables, instead of 512 individual contiguous single page
8mappings.
9
10Using block mappings brings a significant performance improvement by reducing
11the number of stage-2 page faults as well as the TLB pressure. However, finding
12a huge-page can be difficult on a system where the memory is fragmented.
13
14By default, huge-pages are disabled.
15
16## Enabling THP
17
18### 1. Sysfs configuration
19
20The sysfs configuration file that will enable THP for AVF is
21
22```
23/sys/kernel/mm/transparent_hugepages/shmem_enabled
24```
25
26This always defaults to `never`. It is recommended to set it to `advise` to
27benefit from the THP performance improvement.
28
29THPs can have an impact on the system depending on the chosen policy. The
30policy is configured with the following sysfs file:
31
32```
33/sys/kernel/mm/transparent_hugepages/defrag
34```
35
36The recommended policy is `never` as this has zero impact on the system. THPs
37would be used only if some are available.
38
39More information can be found in the Linux
40[admin guide](https://docs.kernel.org/admin-guide/mm/transhuge.html).
41
42### 2. AVF configuration
43
44The guest VM configuration can select huge-pages with the `vm_config.json`
45option `"hugepages": true`.
46
47Alternatively, the `vm` command can also pass `--hugepages`.
48