Lines Matching refs:memory

7 This document describes generic Linux support for memory hot(un)plug with
16 memory available to a machine at runtime. In the simplest case, it consists of
22 - The physical memory available to a machine can be adjusted at runtime, up- or
23 downgrading the memory capacity. This dynamic memory resizing, sometimes
28 example is replacing failing memory modules.
30 - Reducing energy consumption either by physically unplugging memory modules or
31 by logically unplugging (parts of) memory modules from Linux.
33 Further, the basic memory hot(un)plug infrastructure in Linux is nowadays also
34 used to expose persistent memory, other performance-differentiated memory and
35 reserved memory regions as ordinary system RAM to Linux.
37 Linux only supports memory hot(un)plug on selected 64 bit architectures, such as
43 Memory hot(un)plug in Linux uses the SPARSEMEM memory model, which divides the
44 physical memory address space into chunks of the same size: memory sections. The
45 size of a memory section is architecture dependent. For example, x86_64 uses
48 Memory sections are combined into chunks referred to as "memory blocks". The
49 size of a memory block is architecture dependent and corresponds to the smallest
50 granularity that can be hot(un)plugged. The default size of a memory block is
51 the same as memory section size, unless an architecture specifies otherwise.
53 All memory blocks have the same size.
60 (1) Adding the memory to Linux
61 (2) Onlining memory blocks
63 In the first phase, metadata, such as the memory map ("memmap") and page tables
64 for the direct mapping, is allocated and initialized, and memory blocks are
65 created; the latter also creates sysfs files for managing newly created memory
68 In the second phase, added memory is exposed to the page allocator. After this
69 phase, the memory is visible in memory statistics, such as free and total
70 memory, of the system.
77 (1) Offlining memory blocks
78 (2) Removing the memory from Linux
80 In the fist phase, memory is "hidden" from the page allocator again, for
81 example, by migrating busy memory to other memory locations and removing all
82 relevant free pages from the page allocator After this phase, the memory is no
83 longer visible in memory statistics of the system.
85 In the second phase, the memory blocks are removed and metadata is freed.
90 There are various ways how Linux is notified about memory hotplug events such
91 that it can start adding hotplugged memory. This description is limited to
98 Platforms that support ACPI, such as x86_64, can support memory hotplug
101 In general, a firmware supporting memory hotplug defines a memory class object
102 HID "PNP0C80". When notified about hotplug of a new memory device, the ACPI
103 driver will hotplug the memory to Linux.
107 assigned memory devices are added to Linux by the ACPI driver.
109 Similarly, Linux can be notified about requests to hotunplug a memory device or
110 a NUMA node via ACPI. The ACPI driver will try offlining all relevant memory
111 blocks, and, if successful, hotunplug the memory from Linux.
117 system about a memory hotplug event. Instead, the memory has to be manually
122 /sys/devices/system/memory/probe
124 Only complete memory blocks can be probed. Individual memory blocks are probed
125 by providing the physical start address of the memory block::
127 % echo addr > /sys/devices/system/memory/probe
129 Which results in a memory block for the range [addr, addr + memory_block_size)
141 After a memory block has been created, Linux has to be instructed to actually
142 make use of that memory: the memory block has to be "online".
144 Before a memory block can be removed, Linux has to stop using any memory part of
145 the memory block: the memory block has to be "offlined".
147 The Linux kernel can be configured to automatically online added memory blocks
148 and drivers automatically trigger offlining of memory blocks when trying
149 hotunplug of memory. Memory blocks can only be removed once offlining succeeded
150 and drivers may trigger offlining of memory blocks when attempting hotunplug of
151 memory.
156 If auto-onlining of memory blocks isn't enabled, user-space has to manually
157 trigger onlining of memory blocks. Often, udev rules are used to automate this
160 Onlining of a memory block can be triggered via::
162 % echo online > /sys/devices/system/memory/memoryXXX/state
166 % echo 1 > /sys/devices/system/memory/memoryXXX/online
171 One can explicitly request to associate an offline memory block with
174 % echo online_movable > /sys/devices/system/memory/memoryXXX/state
178 % echo online_kernel > /sys/devices/system/memory/memoryXXX/state
180 In any case, if onlining succeeds, the state of the memory block is changed to
181 be "online". If it fails, the state of the memory block will remain unchanged
187 The kernel can be configured to try auto-onlining of newly added memory blocks.
188 If this feature is disabled, the memory blocks will stay offline until
193 % cat /sys/devices/system/memory/auto_online_blocks
198 % echo online > /sys/devices/system/memory/auto_online_blocks
204 memory blocks only.
214 memory blocks; if onlining fails, memory blocks are removed again.
219 In the current implementation, Linux's memory offlining will try migrating all
220 movable pages off the affected memory block. As most kernel allocations, such as
222 memory offlining from succeeding.
224 Having the memory provided by memory block managed by ZONE_MOVABLE significantly
225 increases memory offlining reliability; still, memory offlining can fail in
228 Further, memory offlining might retry for a long time (or even forever), until
231 Offlining of a memory block can be triggered via::
233 % echo offline > /sys/devices/system/memory/memoryXXX/state
237 % echo 0 > /sys/devices/system/memory/memoryXXX/online
239 If offlining succeeds, the state of the memory block is changed to be "offline".
240 If it fails, the state of the memory block will remain unchanged and the above
252 The state (online/offline/going-offline) of a memory block can be observed
255 % cat /sys/device/system/memory/memoryXXX/state
259 % cat /sys/device/system/memory/memoryXXX/online
261 For an online memory block, the managing zone can be observed via::
263 % cat /sys/device/system/memory/memoryXXX/valid_zones
268 There are various ways how system administrators can configure memory
269 hot(un)plug and interact with memory blocks, especially, to online them.
274 Some memory hot(un)plug properties can be configured or inspected via sysfs in::
276 /sys/devices/system/memory/
281 ``auto_online_blocks`` read-write: set or get the default state of new memory
288 See the ``state`` property of memory blocks for details.
289 ``block_size_bytes`` read-only: the size in bytes of a memory block.
290 ``probe`` write-only: add (probe) selected memory blocks manually
303 this functionality is not really related to memory hot(un)plug or actual
304 offlining of memory blocks.
309 Each memory block is represented as a memory block device that can be
310 onlined or offlined. All memory blocks have their device information located in
311 sysfs. Each present memory block is listed under
312 ``/sys/devices/system/memory`` as::
314 /sys/devices/system/memory/memoryXXX
316 where XXX is the memory block id; the number of digits is variable.
318 A present memory block indicates that some memory in the range is present;
319 however, a memory block might span memory holes. A memory block spanning memory
322 For example, assume 1 GiB memory block size. A device for a memory starting at
323 0x100000000 is ``/sys/device/system/memory/memory4``::
333 offlining and to observe the state of a memory block.
337 ``phys_index`` read-only: the memory block id (XXX).
338 ``removable`` read-only: legacy interface that indicated whether a memory
340 kernel return ``1`` if and only if it supports memory
343 offlining and to observe the state of a memory block.
350 zone for the memory block, such as ZONE_NORMAL.
360 For online memory blocks, ``DMA``, ``DMA32``, ``Normal``,
362 that memory provided by a memory block is managed by
363 multiple zones or spans multiple nodes; such memory blocks
367 For offline memory blocks, the first column shows the
368 zone the kernel would select when onlining the memory block
383 /sys/devices/system/node/node0/memory9 -> ../../memory/memory9
387 /sys/devices/system/memory/memory9/node0 -> ../../node/node0
392 Some command line parameters affect memory hot(un)plug handling. The following
397 ``/sys/devices/system/memory/auto_online_blocks``.
401 onlining a memory block, unless other zones can be kept
425 ``memmap_on_memory`` read-write: Allocate memory for the memmap from
426 the added memory block itself. Even if enabled,
431 While allocating the memmap from the memory
432 block itself makes memory hotplug less likely
435 memory in a way that huge pages in bigger
437 memory.
439 automatic zone selection when onlining memory
443 online policy was configured and memory was
448 try keeping zones contiguous. If a memory block
456 try onlining memory blocks to ZONE_MOVABLE if
458 memory device details. With this policy, one
460 hotplugging a lot of memory later and still
468 memory might be exposed via the
469 firmware-provided memory map early during boot
477 As another example, as many memory blocks
480 special-casing units of memory blocks that can
484 change the zone of memory blocks dynamically
487 memory ratio in % for the ``auto-movable``
493 All accounting is based on present memory pages
495 memory device. Memory dedicated to the CMA
502 memory to ZONE_MOVABLE in many setups. The
507 Note that ZONE_NORMAL memory provided by one
508 memory device does not allow for more
509 ZONE_MOVABLE memory for a different memory
510 device. As one example, onlining memory of a
513 ZONE_MOVABLE automatically. In contrast, memory
516 ZONE_MOVABLE memory within *the same*
526 completely hotunpluggable, onlining the memory
536 ZONE_MOVABLE is an important mechanism for more reliable memory offlining.
541 Most kernel allocations are unmovable. Important examples include the memory
542 map (usually 1/64ths of memory), page tables, and kmalloc(). Such allocations
545 Most user space pages, such as anonymous memory, and page cache pages are
550 absolutely no guarantee whether a memory block can be offlined successfully.
557 might crash because it runs out of free memory for unmovable allocations,
558 although there is still plenty of free memory left in ZONE_MOVABLE.
561 are definitely impossible due to the overhead for the memory map.
568 CMA memory part of a kernel zone essentially behaves like memory in
583 - Having a lot of offline memory blocks. Even offline memory blocks consume
584 memory for metadata and page tables in the direct map; having a lot of offline
585 memory blocks is not a typical case, though.
597 lot of unmovable memory.
603 files or ZONE_DEVICE memory can be problematic, although only really relevant
604 in corner cases. When we manage a lot of user space memory that has been
605 swapped out or is served from a file/persistent memory/... we still need a lot
606 of page tables to manage that memory once user space accessed that memory.
608 - In certain DAX configurations the memory map for the device memory will be
611 - KASAN can have a significant memory overhead, for example, consuming 1/8th of
612 the total system memory size as (unmovable) tracking metadata.
616 ZONE_MOVABLE, and therefore, memory offlining. Pinned pages cannot reside
619 even if there is plenty of free memory in ZONE_MOVABLE.
624 By default, all the memory configured at boot time is managed by the kernel
627 To enable ZONE_MOVABLE to include the memory present at boot and to control the
635 Even with ZONE_MOVABLE, there are some corner cases where offlining a memory
638 - Memory blocks with memory holes; this applies to memory blocks present during
639 boot and can apply to memory blocks hotplugged via the XEN balloon and the
642 - Mixed NUMA nodes and mixed zones within a single memory block prevent memory
643 offlining; this applies to memory blocks present during boot only.
645 - Special memory blocks prevented by the system from getting offlined. Examples
646 include any memory available during boot on arm64 or memory blocks spanning
647 the crashkernel area on s390x; this usually applies to memory blocks present
651 memory blocks present during boot only.
653 - Concurrent activity that operates on the same physical memory area, such as
656 - Out of memory when dissolving huge pages, especially when freeing unused
661 for the vmemmap, because the system might not have free memory in the kernel
664 Users that depend on memory offlining to succeed for movable zones should
665 carefully consider whether the memory savings gained from this feature are
666 worth the risk of possibly not being able to offline memory in certain
669 Further, when running into out of memory situations while migrating pages, or
671 (-> BUG), memory offlining will keep retrying until it eventually succeeds.