memory-hotplug.rst 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. ==================
  2. Memory Hot(Un)Plug
  3. ==================
  4. This document describes generic Linux support for memory hot(un)plug with
  5. a focus on System RAM, including ZONE_MOVABLE support.
  6. .. contents:: :local:
  7. Introduction
  8. ============
  9. Memory hot(un)plug allows for increasing and decreasing the size of physical
  10. memory available to a machine at runtime. In the simplest case, it consists of
  11. physically plugging or unplugging a DIMM at runtime, coordinated with the
  12. operating system.
  13. Memory hot(un)plug is used for various purposes:
  14. - The physical memory available to a machine can be adjusted at runtime, up- or
  15. downgrading the memory capacity. This dynamic memory resizing, sometimes
  16. referred to as "capacity on demand", is frequently used with virtual machines
  17. and logical partitions.
  18. - Replacing hardware, such as DIMMs or whole NUMA nodes, without downtime. One
  19. example is replacing failing memory modules.
  20. - Reducing energy consumption either by physically unplugging memory modules or
  21. by logically unplugging (parts of) memory modules from Linux.
  22. Further, the basic memory hot(un)plug infrastructure in Linux is nowadays also
  23. used to expose persistent memory, other performance-differentiated memory and
  24. reserved memory regions as ordinary system RAM to Linux.
  25. Linux only supports memory hot(un)plug on selected 64 bit architectures, such as
  26. x86_64, arm64, ppc64 and s390x.
  27. Memory Hot(Un)Plug Granularity
  28. ------------------------------
  29. Memory hot(un)plug in Linux uses the SPARSEMEM memory model, which divides the
  30. physical memory address space into chunks of the same size: memory sections. The
  31. size of a memory section is architecture dependent. For example, x86_64 uses
  32. 128 MiB and ppc64 uses 16 MiB.
  33. Memory sections are combined into chunks referred to as "memory blocks". The
  34. size of a memory block is architecture dependent and corresponds to the smallest
  35. granularity that can be hot(un)plugged. The default size of a memory block is
  36. the same as memory section size, unless an architecture specifies otherwise.
  37. All memory blocks have the same size.
  38. Phases of Memory Hotplug
  39. ------------------------
  40. Memory hotplug consists of two phases:
  41. (1) Adding the memory to Linux
  42. (2) Onlining memory blocks
  43. In the first phase, metadata, such as the memory map ("memmap") and page tables
  44. for the direct mapping, is allocated and initialized, and memory blocks are
  45. created; the latter also creates sysfs files for managing newly created memory
  46. blocks.
  47. In the second phase, added memory is exposed to the page allocator. After this
  48. phase, the memory is visible in memory statistics, such as free and total
  49. memory, of the system.
  50. Phases of Memory Hotunplug
  51. --------------------------
  52. Memory hotunplug consists of two phases:
  53. (1) Offlining memory blocks
  54. (2) Removing the memory from Linux
  55. In the first phase, memory is "hidden" from the page allocator again, for
  56. example, by migrating busy memory to other memory locations and removing all
  57. relevant free pages from the page allocator After this phase, the memory is no
  58. longer visible in memory statistics of the system.
  59. In the second phase, the memory blocks are removed and metadata is freed.
  60. Memory Hotplug Notifications
  61. ============================
  62. There are various ways how Linux is notified about memory hotplug events such
  63. that it can start adding hotplugged memory. This description is limited to
  64. systems that support ACPI; mechanisms specific to other firmware interfaces or
  65. virtual machines are not described.
  66. ACPI Notifications
  67. ------------------
  68. Platforms that support ACPI, such as x86_64, can support memory hotplug
  69. notifications via ACPI.
  70. In general, a firmware supporting memory hotplug defines a memory class object
  71. HID "PNP0C80". When notified about hotplug of a new memory device, the ACPI
  72. driver will hotplug the memory to Linux.
  73. If the firmware supports hotplug of NUMA nodes, it defines an object _HID
  74. "ACPI0004", "PNP0A05", or "PNP0A06". When notified about an hotplug event, all
  75. assigned memory devices are added to Linux by the ACPI driver.
  76. Similarly, Linux can be notified about requests to hotunplug a memory device or
  77. a NUMA node via ACPI. The ACPI driver will try offlining all relevant memory
  78. blocks, and, if successful, hotunplug the memory from Linux.
  79. Manual Probing
  80. --------------
  81. On some architectures, the firmware may not be able to notify the operating
  82. system about a memory hotplug event. Instead, the memory has to be manually
  83. probed from user space.
  84. The probe interface is located at::
  85. /sys/devices/system/memory/probe
  86. Only complete memory blocks can be probed. Individual memory blocks are probed
  87. by providing the physical start address of the memory block::
  88. % echo addr > /sys/devices/system/memory/probe
  89. Which results in a memory block for the range [addr, addr + memory_block_size)
  90. being created.
  91. .. note::
  92. Using the probe interface is discouraged as it is easy to crash the kernel,
  93. because Linux cannot validate user input; this interface might be removed in
  94. the future.
  95. Onlining and Offlining Memory Blocks
  96. ====================================
  97. After a memory block has been created, Linux has to be instructed to actually
  98. make use of that memory: the memory block has to be "online".
  99. Before a memory block can be removed, Linux has to stop using any memory part of
  100. the memory block: the memory block has to be "offlined".
  101. The Linux kernel can be configured to automatically online added memory blocks
  102. and drivers automatically trigger offlining of memory blocks when trying
  103. hotunplug of memory. Memory blocks can only be removed once offlining succeeded
  104. and drivers may trigger offlining of memory blocks when attempting hotunplug of
  105. memory.
  106. Onlining Memory Blocks Manually
  107. -------------------------------
  108. If auto-onlining of memory blocks isn't enabled, user-space has to manually
  109. trigger onlining of memory blocks. Often, udev rules are used to automate this
  110. task in user space.
  111. Onlining of a memory block can be triggered via::
  112. % echo online > /sys/devices/system/memory/memoryXXX/state
  113. Or alternatively::
  114. % echo 1 > /sys/devices/system/memory/memoryXXX/online
  115. The kernel will select the target zone automatically, depending on the
  116. configured ``online_policy``.
  117. One can explicitly request to associate an offline memory block with
  118. ZONE_MOVABLE by::
  119. % echo online_movable > /sys/devices/system/memory/memoryXXX/state
  120. Or one can explicitly request a kernel zone (usually ZONE_NORMAL) by::
  121. % echo online_kernel > /sys/devices/system/memory/memoryXXX/state
  122. In any case, if onlining succeeds, the state of the memory block is changed to
  123. be "online". If it fails, the state of the memory block will remain unchanged
  124. and the above commands will fail.
  125. Onlining Memory Blocks Automatically
  126. ------------------------------------
  127. The kernel can be configured to try auto-onlining of newly added memory blocks.
  128. If this feature is disabled, the memory blocks will stay offline until
  129. explicitly onlined from user space.
  130. The configured auto-online behavior can be observed via::
  131. % cat /sys/devices/system/memory/auto_online_blocks
  132. Auto-onlining can be enabled by writing ``online``, ``online_kernel`` or
  133. ``online_movable`` to that file, like::
  134. % echo online > /sys/devices/system/memory/auto_online_blocks
  135. Similarly to manual onlining, with ``online`` the kernel will select the
  136. target zone automatically, depending on the configured ``online_policy``.
  137. Modifying the auto-online behavior will only affect all subsequently added
  138. memory blocks only.
  139. .. note::
  140. In corner cases, auto-onlining can fail. The kernel won't retry. Note that
  141. auto-onlining is not expected to fail in default configurations.
  142. .. note::
  143. DLPAR on ppc64 ignores the ``offline`` setting and will still online added
  144. memory blocks; if onlining fails, memory blocks are removed again.
  145. Offlining Memory Blocks
  146. -----------------------
  147. In the current implementation, Linux's memory offlining will try migrating all
  148. movable pages off the affected memory block. As most kernel allocations, such as
  149. page tables, are unmovable, page migration can fail and, therefore, inhibit
  150. memory offlining from succeeding.
  151. Having the memory provided by memory block managed by ZONE_MOVABLE significantly
  152. increases memory offlining reliability; still, memory offlining can fail in
  153. some corner cases.
  154. Further, memory offlining might retry for a long time (or even forever), until
  155. aborted by the user.
  156. Offlining of a memory block can be triggered via::
  157. % echo offline > /sys/devices/system/memory/memoryXXX/state
  158. Or alternatively::
  159. % echo 0 > /sys/devices/system/memory/memoryXXX/online
  160. If offlining succeeds, the state of the memory block is changed to be "offline".
  161. If it fails, the state of the memory block will remain unchanged and the above
  162. commands will fail, for example, via::
  163. bash: echo: write error: Device or resource busy
  164. or via::
  165. bash: echo: write error: Invalid argument
  166. Observing the State of Memory Blocks
  167. ------------------------------------
  168. The state (online/offline/going-offline) of a memory block can be observed
  169. either via::
  170. % cat /sys/devices/system/memory/memoryXXX/state
  171. Or alternatively (1/0) via::
  172. % cat /sys/devices/system/memory/memoryXXX/online
  173. For an online memory block, the managing zone can be observed via::
  174. % cat /sys/devices/system/memory/memoryXXX/valid_zones
  175. Configuring Memory Hot(Un)Plug
  176. ==============================
  177. There are various ways how system administrators can configure memory
  178. hot(un)plug and interact with memory blocks, especially, to online them.
  179. Memory Hot(Un)Plug Configuration via Sysfs
  180. ------------------------------------------
  181. Some memory hot(un)plug properties can be configured or inspected via sysfs in::
  182. /sys/devices/system/memory/
  183. The following files are currently defined:
  184. ====================== =========================================================
  185. ``auto_online_blocks`` read-write: set or get the default state of new memory
  186. blocks; configure auto-onlining.
  187. The default value depends on the
  188. CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE kernel configuration
  189. option.
  190. See the ``state`` property of memory blocks for details.
  191. ``block_size_bytes`` read-only: the size in bytes of a memory block.
  192. ``probe`` write-only: add (probe) selected memory blocks manually
  193. from user space by supplying the physical start address.
  194. Availability depends on the CONFIG_ARCH_MEMORY_PROBE
  195. kernel configuration option.
  196. ``uevent`` read-write: generic udev file for device subsystems.
  197. ``crash_hotplug`` read-only: when changes to the system memory map
  198. occur due to hot un/plug of memory, this file contains
  199. '1' if the kernel updates the kdump capture kernel memory
  200. map itself (via elfcorehdr and other relevant kexec
  201. segments), or '0' if userspace must update the kdump
  202. capture kernel memory map.
  203. Availability depends on the CONFIG_MEMORY_HOTPLUG kernel
  204. configuration option.
  205. ====================== =========================================================
  206. .. note::
  207. When the CONFIG_MEMORY_FAILURE kernel configuration option is enabled, two
  208. additional files ``hard_offline_page`` and ``soft_offline_page`` are available
  209. to trigger hwpoisoning of pages, for example, for testing purposes. Note that
  210. this functionality is not really related to memory hot(un)plug or actual
  211. offlining of memory blocks.
  212. Memory Block Configuration via Sysfs
  213. ------------------------------------
  214. Each memory block is represented as a memory block device that can be
  215. onlined or offlined. All memory blocks have their device information located in
  216. sysfs. Each present memory block is listed under
  217. ``/sys/devices/system/memory`` as::
  218. /sys/devices/system/memory/memoryXXX
  219. where XXX is the memory block id; the number of digits is variable.
  220. A present memory block indicates that some memory in the range is present;
  221. however, a memory block might span memory holes. A memory block spanning memory
  222. holes cannot be offlined.
  223. For example, assume 1 GiB memory block size. A device for a memory starting at
  224. 0x100000000 is ``/sys/devices/system/memory/memory4``::
  225. (0x100000000 / 1Gib = 4)
  226. This device covers address range [0x100000000 ... 0x140000000)
  227. The following files are currently defined:
  228. =================== ============================================================
  229. ``online`` read-write: simplified interface to trigger onlining /
  230. offlining and to observe the state of a memory block.
  231. When onlining, the zone is selected automatically.
  232. ``phys_device`` read-only: legacy interface only ever used on s390x to
  233. expose the covered storage increment.
  234. ``phys_index`` read-only: the memory block id (XXX).
  235. ``removable`` read-only: legacy interface that indicated whether a memory
  236. block was likely to be offlineable or not. Nowadays, the
  237. kernel return ``1`` if and only if it supports memory
  238. offlining.
  239. ``state`` read-write: advanced interface to trigger onlining /
  240. offlining and to observe the state of a memory block.
  241. When writing, ``online``, ``offline``, ``online_kernel`` and
  242. ``online_movable`` are supported.
  243. ``online_movable`` specifies onlining to ZONE_MOVABLE.
  244. ``online_kernel`` specifies onlining to the default kernel
  245. zone for the memory block, such as ZONE_NORMAL.
  246. ``online`` let's the kernel select the zone automatically.
  247. When reading, ``online``, ``offline`` and ``going-offline``
  248. may be returned.
  249. ``uevent`` read-write: generic uevent file for devices.
  250. ``valid_zones`` read-only: when a block is online, shows the zone it
  251. belongs to; when a block is offline, shows what zone will
  252. manage it when the block will be onlined.
  253. For online memory blocks, ``DMA``, ``DMA32``, ``Normal``,
  254. ``Movable`` and ``none`` may be returned. ``none`` indicates
  255. that memory provided by a memory block is managed by
  256. multiple zones or spans multiple nodes; such memory blocks
  257. cannot be offlined. ``Movable`` indicates ZONE_MOVABLE.
  258. Other values indicate a kernel zone.
  259. For offline memory blocks, the first column shows the
  260. zone the kernel would select when onlining the memory block
  261. right now without further specifying a zone.
  262. Availability depends on the CONFIG_MEMORY_HOTREMOVE
  263. kernel configuration option.
  264. =================== ============================================================
  265. .. note::
  266. If the CONFIG_NUMA kernel configuration option is enabled, the memoryXXX/
  267. directories can also be accessed via symbolic links located in the
  268. ``/sys/devices/system/node/node*`` directories.
  269. For example::
  270. /sys/devices/system/node/node0/memory9 -> ../../memory/memory9
  271. A backlink will also be created::
  272. /sys/devices/system/memory/memory9/node0 -> ../../node/node0
  273. Command Line Parameters
  274. -----------------------
  275. Some command line parameters affect memory hot(un)plug handling. The following
  276. command line parameters are relevant:
  277. ======================== =======================================================
  278. ``memhp_default_state`` configure auto-onlining by essentially setting
  279. ``/sys/devices/system/memory/auto_online_blocks``.
  280. ``movable_node`` configure automatic zone selection in the kernel when
  281. using the ``contig-zones`` online policy. When
  282. set, the kernel will default to ZONE_MOVABLE when
  283. onlining a memory block, unless other zones can be kept
  284. contiguous.
  285. ======================== =======================================================
  286. See Documentation/admin-guide/kernel-parameters.txt for a more generic
  287. description of these command line parameters.
  288. Module Parameters
  289. ------------------
  290. Instead of additional command line parameters or sysfs files, the
  291. ``memory_hotplug`` subsystem now provides a dedicated namespace for module
  292. parameters. Module parameters can be set via the command line by predicating
  293. them with ``memory_hotplug.`` such as::
  294. memory_hotplug.memmap_on_memory=1
  295. and they can be observed (and some even modified at runtime) via::
  296. /sys/module/memory_hotplug/parameters/
  297. The following module parameters are currently defined:
  298. ================================ ===============================================
  299. ``memmap_on_memory`` read-write: Allocate memory for the memmap from
  300. the added memory block itself. Even if enabled,
  301. actual support depends on various other system
  302. properties and should only be regarded as a
  303. hint whether the behavior would be desired.
  304. While allocating the memmap from the memory
  305. block itself makes memory hotplug less likely
  306. to fail and keeps the memmap on the same NUMA
  307. node in any case, it can fragment physical
  308. memory in a way that huge pages in bigger
  309. granularity cannot be formed on hotplugged
  310. memory.
  311. With value "force" it could result in memory
  312. wastage due to memmap size limitations. For
  313. example, if the memmap for a memory block
  314. requires 1 MiB, but the pageblock size is 2
  315. MiB, 1 MiB of hotplugged memory will be wasted.
  316. Note that there are still cases where the
  317. feature cannot be enforced: for example, if the
  318. memmap is smaller than a single page, or if the
  319. architecture does not support the forced mode
  320. in all configurations.
  321. ``online_policy`` read-write: Set the basic policy used for
  322. automatic zone selection when onlining memory
  323. blocks without specifying a target zone.
  324. ``contig-zones`` has been the kernel default
  325. before this parameter was added. After an
  326. online policy was configured and memory was
  327. online, the policy should not be changed
  328. anymore.
  329. When set to ``contig-zones``, the kernel will
  330. try keeping zones contiguous. If a memory block
  331. intersects multiple zones or no zone, the
  332. behavior depends on the ``movable_node`` kernel
  333. command line parameter: default to ZONE_MOVABLE
  334. if set, default to the applicable kernel zone
  335. (usually ZONE_NORMAL) if not set.
  336. When set to ``auto-movable``, the kernel will
  337. try onlining memory blocks to ZONE_MOVABLE if
  338. possible according to the configuration and
  339. memory device details. With this policy, one
  340. can avoid zone imbalances when eventually
  341. hotplugging a lot of memory later and still
  342. wanting to be able to hotunplug as much as
  343. possible reliably, very desirable in
  344. virtualized environments. This policy ignores
  345. the ``movable_node`` kernel command line
  346. parameter and isn't really applicable in
  347. environments that require it (e.g., bare metal
  348. with hotunpluggable nodes) where hotplugged
  349. memory might be exposed via the
  350. firmware-provided memory map early during boot
  351. to the system instead of getting detected,
  352. added and onlined later during boot (such as
  353. done by virtio-mem or by some hypervisors
  354. implementing emulated DIMMs). As one example, a
  355. hotplugged DIMM will be onlined either
  356. completely to ZONE_MOVABLE or completely to
  357. ZONE_NORMAL, not a mixture.
  358. As another example, as many memory blocks
  359. belonging to a virtio-mem device will be
  360. onlined to ZONE_MOVABLE as possible,
  361. special-casing units of memory blocks that can
  362. only get hotunplugged together. *This policy
  363. does not protect from setups that are
  364. problematic with ZONE_MOVABLE and does not
  365. change the zone of memory blocks dynamically
  366. after they were onlined.*
  367. ``auto_movable_ratio`` read-write: Set the maximum MOVABLE:KERNEL
  368. memory ratio in % for the ``auto-movable``
  369. online policy. Whether the ratio applies only
  370. for the system across all NUMA nodes or also
  371. per NUMA nodes depends on the
  372. ``auto_movable_numa_aware`` configuration.
  373. All accounting is based on present memory pages
  374. in the zones combined with accounting per
  375. memory device. Memory dedicated to the CMA
  376. allocator is accounted as MOVABLE, although
  377. residing on one of the kernel zones. The
  378. possible ratio depends on the actual workload.
  379. The kernel default is "301" %, for example,
  380. allowing for hotplugging 24 GiB to a 8 GiB VM
  381. and automatically onlining all hotplugged
  382. memory to ZONE_MOVABLE in many setups. The
  383. additional 1% deals with some pages being not
  384. present, for example, because of some firmware
  385. allocations.
  386. Note that ZONE_NORMAL memory provided by one
  387. memory device does not allow for more
  388. ZONE_MOVABLE memory for a different memory
  389. device. As one example, onlining memory of a
  390. hotplugged DIMM to ZONE_NORMAL will not allow
  391. for another hotplugged DIMM to get onlined to
  392. ZONE_MOVABLE automatically. In contrast, memory
  393. hotplugged by a virtio-mem device that got
  394. onlined to ZONE_NORMAL will allow for more
  395. ZONE_MOVABLE memory within *the same*
  396. virtio-mem device.
  397. ``auto_movable_numa_aware`` read-write: Configure whether the
  398. ``auto_movable_ratio`` in the ``auto-movable``
  399. online policy also applies per NUMA
  400. node in addition to the whole system across all
  401. NUMA nodes. The kernel default is "Y".
  402. Disabling NUMA awareness can be helpful when
  403. dealing with NUMA nodes that should be
  404. completely hotunpluggable, onlining the memory
  405. completely to ZONE_MOVABLE automatically if
  406. possible.
  407. Parameter availability depends on CONFIG_NUMA.
  408. ================================ ===============================================
  409. ZONE_MOVABLE
  410. ============
  411. ZONE_MOVABLE is an important mechanism for more reliable memory offlining.
  412. Further, having system RAM managed by ZONE_MOVABLE instead of one of the
  413. kernel zones can increase the number of possible transparent huge pages and
  414. dynamically allocated huge pages.
  415. Most kernel allocations are unmovable. Important examples include the memory
  416. map (usually 1/64ths of memory), page tables, and kmalloc(). Such allocations
  417. can only be served from the kernel zones.
  418. Most user space pages, such as anonymous memory, and page cache pages are
  419. movable. Such allocations can be served from ZONE_MOVABLE and the kernel zones.
  420. Only movable allocations are served from ZONE_MOVABLE, resulting in unmovable
  421. allocations being limited to the kernel zones. Without ZONE_MOVABLE, there is
  422. absolutely no guarantee whether a memory block can be offlined successfully.
  423. Zone Imbalances
  424. ---------------
  425. Having too much system RAM managed by ZONE_MOVABLE is called a zone imbalance,
  426. which can harm the system or degrade performance. As one example, the kernel
  427. might crash because it runs out of free memory for unmovable allocations,
  428. although there is still plenty of free memory left in ZONE_MOVABLE.
  429. Usually, MOVABLE:KERNEL ratios of up to 3:1 or even 4:1 are fine. Ratios of 63:1
  430. are definitely impossible due to the overhead for the memory map.
  431. Actual safe zone ratios depend on the workload. Extreme cases, like excessive
  432. long-term pinning of pages, might not be able to deal with ZONE_MOVABLE at all.
  433. .. note::
  434. CMA memory part of a kernel zone essentially behaves like memory in
  435. ZONE_MOVABLE and similar considerations apply, especially when combining
  436. CMA with ZONE_MOVABLE.
  437. ZONE_MOVABLE Sizing Considerations
  438. ----------------------------------
  439. We usually expect that a large portion of available system RAM will actually
  440. be consumed by user space, either directly or indirectly via the page cache. In
  441. the normal case, ZONE_MOVABLE can be used when allocating such pages just fine.
  442. With that in mind, it makes sense that we can have a big portion of system RAM
  443. managed by ZONE_MOVABLE. However, there are some things to consider when using
  444. ZONE_MOVABLE, especially when fine-tuning zone ratios:
  445. - Having a lot of offline memory blocks. Even offline memory blocks consume
  446. memory for metadata and page tables in the direct map; having a lot of offline
  447. memory blocks is not a typical case, though.
  448. - Memory ballooning without balloon compaction is incompatible with
  449. ZONE_MOVABLE. Only some implementations, such as virtio-balloon and
  450. pseries CMM, fully support balloon compaction.
  451. Further, the CONFIG_BALLOON_COMPACTION kernel configuration option might be
  452. disabled. In that case, balloon inflation will only perform unmovable
  453. allocations and silently create a zone imbalance, usually triggered by
  454. inflation requests from the hypervisor.
  455. - Gigantic pages are unmovable, resulting in user space consuming a
  456. lot of unmovable memory.
  457. - Huge pages are unmovable when an architectures does not support huge
  458. page migration, resulting in a similar issue as with gigantic pages.
  459. - Page tables are unmovable. Excessive swapping, mapping extremely large
  460. files or ZONE_DEVICE memory can be problematic, although only really relevant
  461. in corner cases. When we manage a lot of user space memory that has been
  462. swapped out or is served from a file/persistent memory/... we still need a lot
  463. of page tables to manage that memory once user space accessed that memory.
  464. - In certain DAX configurations the memory map for the device memory will be
  465. allocated from the kernel zones.
  466. - KASAN can have a significant memory overhead, for example, consuming 1/8th of
  467. the total system memory size as (unmovable) tracking metadata.
  468. - Long-term pinning of pages. Techniques that rely on long-term pinnings
  469. (especially, RDMA and vfio/mdev) are fundamentally problematic with
  470. ZONE_MOVABLE, and therefore, memory offlining. Pinned pages cannot reside
  471. on ZONE_MOVABLE as that would turn these pages unmovable. Therefore, they
  472. have to be migrated off that zone while pinning. Pinning a page can fail
  473. even if there is plenty of free memory in ZONE_MOVABLE.
  474. In addition, using ZONE_MOVABLE might make page pinning more expensive,
  475. because of the page migration overhead.
  476. By default, all the memory configured at boot time is managed by the kernel
  477. zones and ZONE_MOVABLE is not used.
  478. To enable ZONE_MOVABLE to include the memory present at boot and to control the
  479. ratio between movable and kernel zones there are two command line options:
  480. ``kernelcore=`` and ``movablecore=``. See
  481. Documentation/admin-guide/kernel-parameters.rst for their description.
  482. Memory Offlining and ZONE_MOVABLE
  483. ---------------------------------
  484. Even with ZONE_MOVABLE, there are some corner cases where offlining a memory
  485. block might fail:
  486. - Memory blocks with memory holes; this applies to memory blocks present during
  487. boot and can apply to memory blocks hotplugged via the XEN balloon and the
  488. Hyper-V balloon.
  489. - Mixed NUMA nodes and mixed zones within a single memory block prevent memory
  490. offlining; this applies to memory blocks present during boot only.
  491. - Special memory blocks prevented by the system from getting offlined. Examples
  492. include any memory available during boot on arm64 or memory blocks spanning
  493. the crashkernel area on s390x; this usually applies to memory blocks present
  494. during boot only.
  495. - Memory blocks overlapping with CMA areas cannot be offlined, this applies to
  496. memory blocks present during boot only.
  497. - Concurrent activity that operates on the same physical memory area, such as
  498. allocating gigantic pages, can result in temporary offlining failures.
  499. - Out of memory when dissolving huge pages, especially when HugeTLB Vmemmap
  500. Optimization (HVO) is enabled.
  501. Offlining code may be able to migrate huge page contents, but may not be able
  502. to dissolve the source huge page because it fails allocating (unmovable) pages
  503. for the vmemmap, because the system might not have free memory in the kernel
  504. zones left.
  505. Users that depend on memory offlining to succeed for movable zones should
  506. carefully consider whether the memory savings gained from this feature are
  507. worth the risk of possibly not being able to offline memory in certain
  508. situations.
  509. Further, when running into out of memory situations while migrating pages, or
  510. when still encountering permanently unmovable pages within ZONE_MOVABLE
  511. (-> BUG), memory offlining will keep retrying until it eventually succeeds.
  512. When offlining is triggered from user space, the offlining context can be
  513. terminated by sending a signal. A timeout based offlining can easily be
  514. implemented via::
  515. % timeout $TIMEOUT offline_block | failure_handling