Vincent Donnefort | 538a2c6 | 2024-03-20 16:01:10 +0000 | [diff] [blame] | 1 | # Huge Pages |
| 2 | |
| 3 | From Android 15, the pKVM hypervisor supports Transparent Hugepages. This is a |
| 4 | Linux 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, |
| 6 | the hypervisor can leverage this allocation to also use a block mapping |
| 7 | in the stage-2 page tables, instead of 512 individual contiguous single page |
| 8 | mappings. |
| 9 | |
| 10 | Using block mappings brings a significant performance improvement by reducing |
| 11 | the number of stage-2 page faults as well as the TLB pressure. However, finding |
| 12 | a huge-page can be difficult on a system where the memory is fragmented. |
| 13 | |
| 14 | By default, huge-pages are disabled. |
| 15 | |
| 16 | ## Enabling THP |
| 17 | |
| 18 | ### 1. Sysfs configuration |
| 19 | |
| 20 | The sysfs configuration file that will enable THP for AVF is |
| 21 | |
| 22 | ``` |
| 23 | /sys/kernel/mm/transparent_hugepages/shmem_enabled |
| 24 | ``` |
| 25 | |
| 26 | This always defaults to `never`. It is recommended to set it to `advise` to |
| 27 | benefit from the THP performance improvement. |
| 28 | |
| 29 | THPs can have an impact on the system depending on the chosen policy. The |
| 30 | policy is configured with the following sysfs file: |
| 31 | |
| 32 | ``` |
| 33 | /sys/kernel/mm/transparent_hugepages/defrag |
| 34 | ``` |
| 35 | |
| 36 | The recommended policy is `never` as this has zero impact on the system. THPs |
| 37 | would be used only if some are available. |
| 38 | |
| 39 | More 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 | |
| 44 | The guest VM configuration can select huge-pages with the `vm_config.json` |
| 45 | option `"hugepages": true`. |
| 46 | |
| 47 | Alternatively, the `vm` command can also pass `--hugepages`. |