Lines Matching full:memory
4 Memory Hotplug
10 This document is about memory hotplug including how-to-use and current status.
11 Because Memory Hotplug is still under development, contents of this text will
18 (1) x86_64's has special implementation for memory hotplug.
26 Purpose of memory hotplug
29 Memory Hotplug allows users to increase/decrease the amount of memory.
32 (A) For changing the amount of memory.
38 hardware which supports memory power management.
40 Linux memory hotplug is designed for both purpose.
42 Phases of memory hotplug
45 There are 2 phases in Memory Hotplug:
47 1) Physical Memory Hotplug phase
48 2) Logical Memory Hotplug phase.
51 environment for hotplugged memory. Basically, this phase is necessary
55 When memory is hotplugged, the kernel recognizes new memory, makes new memory
56 management tables, and makes sysfs files for new memory's operation.
58 If firmware supports notification of connection of new memory to OS,
63 Logical Memory Hotplug phase is to change memory state into
64 available/unavailable for users. Amount of memory from user's view is
65 changed by this phase. The kernel makes all memory in it as free pages
66 when a memory range is available.
70 Logical Memory Hotplug phase is triggered by write of sysfs file by system
73 (However, if you writes udev's hotplug scripts for memory hotplug, these
76 Unit of Memory online/offline operation
79 Memory hotplug uses SPARSEMEM memory model which allows memory to be divided
81 a memory section is architecture dependent. For example, power uses 16MiB, ia64
84 Memory sections are combined into chunks referred to as "memory blocks". The
85 size of a memory block is architecture dependent and represents the logical
86 unit upon which memory online/offline operations are to be performed. The
87 default size of a memory block is the same as memory section size unless an
90 To determine the size (in bytes) of a memory block please read this file::
92 /sys/devices/system/memory/block_size_bytes
97 To use memory hotplug feature, kernel must be compiled with following
100 - For all memory hotplug:
101 - Memory model -> Sparse Memory (``CONFIG_SPARSEMEM``)
102 - Allow for memory hot-add (``CONFIG_MEMORY_HOTPLUG``)
104 - To enable memory removal, the following are also necessary:
105 - Allow for memory hot remove (``CONFIG_MEMORY_HOTREMOVE``)
108 - For ACPI memory hotplug, the following are also necessary:
109 - Memory hotplug (under ACPI Support menu) (``CONFIG_ACPI_HOTPLUG_MEMORY``)
123 sysfs files for memory hotplug
126 All memory blocks have their device information in sysfs. Each memory block
127 is described under ``/sys/devices/system/memory`` as::
129 /sys/devices/system/memory/memoryXXX
131 where XXX is the memory block id.
133 For the memory block covered by the sysfs directory. It is expected that all
134 memory sections in this range are present and no memory holes exist in the
135 range. Currently there is no way to determine if there is a memory hole, but
136 the existence of one should not affect the hotplug capabilities of the memory
139 For example, assume 1GiB memory block size. A device for a memory starting at
140 0x100000000 is ``/sys/device/system/memory/memory4``::
146 Under each memory block, you can see 5 files:
148 - ``/sys/devices/system/memory/memoryXXX/phys_index``
149 - ``/sys/devices/system/memory/memoryXXX/phys_device``
150 - ``/sys/devices/system/memory/memoryXXX/state``
151 - ``/sys/devices/system/memory/memoryXXX/removable``
152 - ``/sys/devices/system/memory/memoryXXX/valid_zones``
155 ``phys_index`` read-only and contains memory block id, same as XXX.
158 - at read: contains online/offline state of memory.
163 ``phys_device`` read-only: designed to show the name of physical memory
166 whether the memory block is removable or not
167 removable. A value of 1 indicates that the memory
169 it is not removable. A memory block is removable only if
171 ``valid_zones`` read-only: designed to show which zones this memory block
187 These directories/files appear after physical memory hotplug phase.
194 /sys/devices/system/node/node0/memory9 -> ../../memory/memory9
198 /sys/devices/system/memory/memory9/node0 -> ../../node/node0
202 Physical memory hot-add phase
208 On x86_64/ia64 platform, memory hotplug by ACPI is supported.
210 In general, the firmware (ACPI) which supports memory hotplug defines
211 memory class object of _HID "PNP0C80". When a notify is asserted to PNP0C80,
212 Linux's ACPI handler does hot-add memory to the system and calls a hotplug udev
215 But scripts for memory hotplug are not contained in generic udev package(now).
216 You may have to write it by yourself or online/offline memory by hand.
223 If memory device is found, memory hotplug code will be called.
225 Notify memory hot-add event by hand
228 On some architectures, the firmware may not notify the kernel of a memory
229 hotplug event. Therefore, the memory "probe" interface is supported to
237 /sys/devices/system/memory/probe
239 You can tell the physical address of new memory to the kernel by::
241 % echo start_address_of_new_memory > /sys/devices/system/memory/probe
244 memory_block_size] memory range is hot-added. In this case, hotplug script is
245 not called (in current implementation). You'll have to online memory by
248 Logical Memory hot-add phase
251 State of memory
254 To see (online/offline) state of a memory block, read 'state' file::
256 % cat /sys/device/system/memory/memoryXXX/state
259 - If the memory block is online, you'll read "online".
260 - If the memory block is offline, you'll read "offline".
265 How to online memory
268 When the memory is hot-added, the kernel decides whether or not to "online"
271 % cat /sys/devices/system/memory/auto_online_blocks
275 memory is not in a ready-to-use state and you have to "online" the newly added
276 memory blocks manually. Automatic onlining can be requested by writing "online"
279 % echo online > /sys/devices/system/memory/auto_online_blocks
281 This sets a global policy and impacts all memory blocks that will subsequently
283 certain circumstances, that some memory blocks will be added but will fail to
285 (``/sys/devices/system/memory/memoryXXX/state``) and try to online them manually.
287 If the automatic onlining wasn't requested, failed, or some memory block was
291 % echo online > /sys/devices/system/memory/memoryXXX/state
293 This onlining will not change the ZONE type of the target memory block,
294 If the memory block doesn't belong to any zone an appropriate kernel zone
300 % echo online_movable > /sys/devices/system/memory/memoryXXX/state
302 .. note:: current limit: this memory block must be adjacent to ZONE_MOVABLE
306 % echo online_kernel > /sys/devices/system/memory/memoryXXX/state
308 .. note:: current limit: this memory block must be adjacent to ZONE_NORMAL
313 After this, memory block XXX's state will be 'online' and the amount of
314 available memory will be increased.
318 Logical memory remove
321 Memory offline and ZONE_MOVABLE
324 Memory offlining is more complicated than memory online. Because memory offline
325 has to make the whole memory block be unused, memory offline can fail if
326 the memory block includes memory which cannot be freed.
328 In general, memory offline can use 2 techniques.
330 (1) reclaim and free all memory in the memory block.
331 (2) migrate all pages in the memory block.
333 In the current implementation, Linux's memory offline uses method (2), freeing
334 all pages in the memory block by page migration. But not all pages are
336 page caches. For offlining a memory block by migration, the kernel has to
337 guarantee that the memory block contains only migratable pages.
339 Now, a boot option for making a memory block which consists of migratable pages
344 Assume the system has "TOTAL" amount of memory at boot time, this boot option
348 Size of memory not for movable pages (not for offline) is YYYY.
349 Size of memory for movable pages (for offline) is TOTAL-YYYY.
352 Size of memory not for movable pages (not for offline) is TOTAL - ZZZZ.
353 Size of memory for movable pages (for offline) is ZZZZ.
357 Unfortunately, there is no information to show which memory block belongs
362 How to offline memory
365 You can offline a memory block by using the same sysfs interface that was used
366 in memory onlining::
368 % echo offline > /sys/devices/system/memory/memoryXXX/state
370 If offline succeeds, the state of the memory block is changed to be "offline".
372 Even if a memory block does not belong to ZONE_MOVABLE, you can try to offline
373 it. If it doesn't contain 'unmovable' memory, you'll get success.
375 A memory block under ZONE_MOVABLE is considered to be able to be offlined
376 easily. But under some busy state, it may return -EBUSY. Even if a memory
382 Memory hotplug's design direction is to make the possibility of memory
383 offlining higher and to guarantee unplugging memory under any situation. But
385 the user can decide to retry more or not by himself. Currently, memory
388 Physical memory remove
399 When adding/removing memory that uses memory block devices (i.e. ordinary RAM),
402 - synchronize against online/offline requests (e.g. via sysfs). This way, memory
404 space once memory has been fully added. And when removing memory, we
409 device_hotplug_lock when adding memory and user space tries to online that
410 memory faster than expected:
420 onlining/offlining of memory should be done via device_online()/
424 When adding/removing/onlining/offlining memory or adding/removing
425 heterogeneous/device memory, we should always hold the mem_hotplug_lock in
426 write mode to serialise memory hotplug (e.g. access to global/zone
431 implementation, so code accessing memory can protect from that memory
438 - allowing memory hot-add to ZONE_MOVABLE. maybe we need some switch like
440 - showing memory block and physical device relationship.
441 - test and make it better memory offlining.
443 - memmap removing at memory offline.
444 - physical remove memory.