linux/Documentation/memory-hotplug.txt
<<
>>
Prefs
   1==============
   2Memory Hotplug
   3==============
   4
   5Created:                                        Jul 28 2007
   6Add description of notifier of memory hotplug   Oct 11 2007
   7
   8This document is about memory hotplug including how-to-use and current status.
   9Because Memory Hotplug is still under development, contents of this text will
  10be changed often.
  11
  121. Introduction
  13  1.1 purpose of memory hotplug
  14  1.2. Phases of memory hotplug
  15  1.3. Unit of Memory online/offline operation
  162. Kernel Configuration
  173. sysfs files for memory hotplug
  184. Physical memory hot-add phase
  19  4.1 Hardware(Firmware) Support
  20  4.2 Notify memory hot-add event by hand
  215. Logical Memory hot-add phase
  22  5.1. State of memory
  23  5.2. How to online memory
  246. Logical memory remove
  25  6.1 Memory offline and ZONE_MOVABLE
  26  6.2. How to offline memory
  277. Physical memory remove
  288. Memory hotplug event notifier
  299. Future Work List
  30
  31Note(1): x86_64's has special implementation for memory hotplug.
  32         This text does not describe it.
  33Note(2): This text assumes that sysfs is mounted at /sys.
  34
  35
  36---------------
  371. Introduction
  38---------------
  39
  401.1 purpose of memory hotplug
  41------------
  42Memory Hotplug allows users to increase/decrease the amount of memory.
  43Generally, there are two purposes.
  44
  45(A) For changing the amount of memory.
  46    This is to allow a feature like capacity on demand.
  47(B) For installing/removing DIMMs or NUMA-nodes physically.
  48    This is to exchange DIMMs/NUMA-nodes, reduce power consumption, etc.
  49
  50(A) is required by highly virtualized environments and (B) is required by
  51hardware which supports memory power management.
  52
  53Linux memory hotplug is designed for both purpose.
  54
  55
  561.2. Phases of memory hotplug
  57---------------
  58There are 2 phases in Memory Hotplug.
  59  1) Physical Memory Hotplug phase
  60  2) Logical Memory Hotplug phase.
  61
  62The First phase is to communicate hardware/firmware and make/erase
  63environment for hotplugged memory. Basically, this phase is necessary
  64for the purpose (B), but this is good phase for communication between
  65highly virtualized environments too.
  66
  67When memory is hotplugged, the kernel recognizes new memory, makes new memory
  68management tables, and makes sysfs files for new memory's operation.
  69
  70If firmware supports notification of connection of new memory to OS,
  71this phase is triggered automatically. ACPI can notify this event. If not,
  72"probe" operation by system administration is used instead.
  73(see Section 4.).
  74
  75Logical Memory Hotplug phase is to change memory state into
  76available/unavailable for users. Amount of memory from user's view is
  77changed by this phase. The kernel makes all memory in it as free pages
  78when a memory range is available.
  79
  80In this document, this phase is described as online/offline.
  81
  82Logical Memory Hotplug phase is triggered by write of sysfs file by system
  83administrator. For the hot-add case, it must be executed after Physical Hotplug
  84phase by hand.
  85(However, if you writes udev's hotplug scripts for memory hotplug, these
  86 phases can be execute in seamless way.)
  87
  88
  891.3. Unit of Memory online/offline operation
  90------------
  91Memory hotplug uses SPARSEMEM memory model. SPARSEMEM divides the whole memory
  92into chunks of the same size. The chunk is called a "section". The size of
  93a section is architecture dependent. For example, power uses 16MiB, ia64 uses
  941GiB. The unit of online/offline operation is "one section". (see Section 3.)
  95
  96To determine the size of sections, please read this file:
  97
  98/sys/devices/system/memory/block_size_bytes
  99
 100This file shows the size of sections in byte.
 101
 102-----------------------
 1032. Kernel Configuration
 104-----------------------
 105To use memory hotplug feature, kernel must be compiled with following
 106config options.
 107
 108- For all memory hotplug
 109    Memory model -> Sparse Memory  (CONFIG_SPARSEMEM)
 110    Allow for memory hot-add       (CONFIG_MEMORY_HOTPLUG)
 111
 112- To enable memory removal, the followings are also necessary
 113    Allow for memory hot remove    (CONFIG_MEMORY_HOTREMOVE)
 114    Page Migration                 (CONFIG_MIGRATION)
 115
 116- For ACPI memory hotplug, the followings are also necessary
 117    Memory hotplug (under ACPI Support menu) (CONFIG_ACPI_HOTPLUG_MEMORY)
 118    This option can be kernel module.
 119
 120- As a related configuration, if your box has a feature of NUMA-node hotplug
 121  via ACPI, then this option is necessary too.
 122    ACPI0004,PNP0A05 and PNP0A06 Container Driver (under ACPI Support menu)
 123    (CONFIG_ACPI_CONTAINER).
 124    This option can be kernel module too.
 125
 126--------------------------------
 1274 sysfs files for memory hotplug
 128--------------------------------
 129All sections have their device information in sysfs.  Each section is part of
 130a memory block under /sys/devices/system/memory as
 131
 132/sys/devices/system/memory/memoryXXX
 133(XXX is the section id.)
 134
 135Now, XXX is defined as (start_address_of_section / section_size) of the first
 136section contained in the memory block.  The files 'phys_index' and
 137'end_phys_index' under each directory report the beginning and end section id's
 138for the memory block covered by the sysfs directory.  It is expected that all
 139memory sections in this range are present and no memory holes exist in the
 140range. Currently there is no way to determine if there is a memory hole, but
 141the existence of one should not affect the hotplug capabilities of the memory
 142block.
 143
 144For example, assume 1GiB section size. A device for a memory starting at
 1450x100000000 is /sys/device/system/memory/memory4
 146(0x100000000 / 1Gib = 4)
 147This device covers address range [0x100000000 ... 0x140000000)
 148
 149Under each section, you can see 4 or 5 files, the end_phys_index file being
 150a recent addition and not present on older kernels.
 151
 152/sys/devices/system/memory/memoryXXX/start_phys_index
 153/sys/devices/system/memory/memoryXXX/end_phys_index
 154/sys/devices/system/memory/memoryXXX/phys_device
 155/sys/devices/system/memory/memoryXXX/state
 156/sys/devices/system/memory/memoryXXX/removable
 157
 158'phys_index'      : read-only and contains section id of the first section
 159                    in the memory block, same as XXX.
 160'end_phys_index'  : read-only and contains section id of the last section
 161                    in the memory block.
 162'state'           : read-write
 163                    at read:  contains online/offline state of memory.
 164                    at write: user can specify "online_kernel",
 165                    "online_movable", "online", "offline" command
 166                    which will be performed on al sections in the block.
 167'phys_device'     : read-only: designed to show the name of physical memory
 168                    device.  This is not well implemented now.
 169'removable'       : read-only: contains an integer value indicating
 170                    whether the memory block is removable or not
 171                    removable.  A value of 1 indicates that the memory
 172                    block is removable and a value of 0 indicates that
 173                    it is not removable. A memory block is removable only if
 174                    every section in the block is removable.
 175
 176NOTE:
 177  These directories/files appear after physical memory hotplug phase.
 178
 179If CONFIG_NUMA is enabled the memoryXXX/ directories can also be accessed
 180via symbolic links located in the /sys/devices/system/node/node* directories.
 181
 182For example:
 183/sys/devices/system/node/node0/memory9 -> ../../memory/memory9
 184
 185A backlink will also be created:
 186/sys/devices/system/memory/memory9/node0 -> ../../node/node0
 187
 188--------------------------------
 1894. Physical memory hot-add phase
 190--------------------------------
 191
 1924.1 Hardware(Firmware) Support
 193------------
 194On x86_64/ia64 platform, memory hotplug by ACPI is supported.
 195
 196In general, the firmware (ACPI) which supports memory hotplug defines
 197memory class object of _HID "PNP0C80". When a notify is asserted to PNP0C80,
 198Linux's ACPI handler does hot-add memory to the system and calls a hotplug udev
 199script. This will be done automatically.
 200
 201But scripts for memory hotplug are not contained in generic udev package(now).
 202You may have to write it by yourself or online/offline memory by hand.
 203Please see "How to online memory", "How to offline memory" in this text.
 204
 205If firmware supports NUMA-node hotplug, and defines an object _HID "ACPI0004",
 206"PNP0A05", or "PNP0A06", notification is asserted to it, and ACPI handler
 207calls hotplug code for all of objects which are defined in it.
 208If memory device is found, memory hotplug code will be called.
 209
 210
 2114.2 Notify memory hot-add event by hand
 212------------
 213In some environments, especially virtualized environment, firmware will not
 214notify memory hotplug event to the kernel. For such environment, "probe"
 215interface is supported. This interface depends on CONFIG_ARCH_MEMORY_PROBE.
 216
 217Now, CONFIG_ARCH_MEMORY_PROBE is supported only by powerpc but it does not
 218contain highly architecture codes. Please add config if you need "probe"
 219interface.
 220
 221Probe interface is located at
 222/sys/devices/system/memory/probe
 223
 224You can tell the physical address of new memory to the kernel by
 225
 226% echo start_address_of_new_memory > /sys/devices/system/memory/probe
 227
 228Then, [start_address_of_new_memory, start_address_of_new_memory + section_size)
 229memory range is hot-added. In this case, hotplug script is not called (in
 230current implementation). You'll have to online memory by yourself.
 231Please see "How to online memory" in this text.
 213entation/me1tart_address_of_new_memory, startthis 3entation/me1taory rathntation/memory-hotplug.txt#L163" id="L163" class="2" class="line" name="L132"> 132
 132No----------------------------
 132se Logical Memory hot-add phase
 1323/a>---------------
<-------------
 1323/a>
 132me1. State of memory
 1424/a>------------
 142thToee &q(line/offline m)tate of memory.
ection, yoad th39;state'   les  1424g.txt#L136" iame="L213"> 213entation/me1tart_addre" id="L142" class="line" name="L142"> 142
<37; ecc /sys.
evice/system/memory/memory4
X/state
 142
 1424/a>
 142(0Ithe memory
 142ThIthe memory
 142
 142
 152a 2. How to online memory
 1525/a>------------
 152/sEvenf thereemory is hotpldded. ,t is not re read: yo-use anate
< 152/sF userg atw_m arced. emory, mau neve to on3ot;online", he memory
 152
 152/sF online/g amau neve to onite it3ot;online", heohe section i39;s ACate ofle beas 1525/a>
 15257a>% echo stline met; /sys/devices/system/memory/prmory4
X/state
 1525/a>
 152  is optine/g aill not
 16260a>ThIthe memory
 162
 162' echo stline movable&qet; /sys/devices/system/memory/prmory4
X/state
 162  (TE:
< rrent imlimit:his temory
 1626/a>
 162  Andf thereemory isction is pa thNE_MOVABLE
> 152
 16267a>% echo stline mernel&qet; /sys/devices/system/memory/prmory4
X/state
 162  (TE:
< rrent imlimit:his temory
 162
 172  Aer phis t,ection issory4
X/s39;s ACate ofll be ca39;s line&qu9; and
 172  ailable fomory
 1727g.txt#L136" iame="L213"> 213entation/me1tart_addre" id="L172" class="line" name="L172"> 172  rrently t,tw_m arced. emory, s assed. eashNE_MONORMAL (r alwerpc b,hNE_MODMA
 172  is opy ha calnged by thfure W 172
 1727/a>
 1727/a>
 1727/a>--------------------------a href="Documentation/memory-hotplug.txt#L228" id="L152" class="line" name="L172"> 172If6Logical Memory raneve  a href="Documentation/memory-hotplug.txt#L228" id="L182" class="line" name="L182"> 1828/a>--------------------------a href="Documentation/memory-hotplug.txt#L228" id="L162" class="line" name="L182"> 182
 182Fo6.1emory onlline med
 1727/a>a 28G6a>--------------------------a href="Documentation/memory-hotplug.#L24"" id="L152" .2a>---------------------21umentation/memoryid="L1eu-----d="L182"g
 185A backlink 2ill a2so be de h"Dos frf="Documentation/ ACate ofb opeocum, kernel 
 186/sys/device2/syst2m/memo="Documentatincluhrefd
 187
 188-----------2-----2------ (ACPI) whickernel 
 1894. Physical2memor28tion/memory-hotplug.txt#L702" id="L172" class="line" name="2190"> 190-----------2-----2------(1) prelaiev
 191
 1924.1 Hardwar2(Firm29"> 213entation/me1tart_addre" id="L172" class="line" name="2193"> 193-----------2
 194On x86_64/i264 pl2tform, paggtion/href="Documentanot
<    m (CONFIG. Butte
< 195
 196In general,2the f2rmware<    cach youo onieu-----d=aocumentanot
m (CONFIGnew memory, mde h"Doguaranteeef="Documentation/memory-hotplug.#L24"" id="Le" name="2197"> 197memory clas2 obje2t of _"Document memory block. sdoes nm (CONremogtion//memory-hotplug.txt#L181" id="L181" class="li2e" name="2198"> 198Linux's2ACPI 29tion/memory-hotplug.txt#L142" id="L152" class="line" name="2199"> 199script. Thi2 will2be donPROBEa bo
< 200
 191
 202You may hav3 to w3ite it(Se="Documplug.txt#L181"mory, -paramemorsss="/memory-hotplug.txt#L229" id="L152" class="li3e" name="3203"> 203Please see 3quot;30y-hotplug.txt#L163" id="L163" class="2" class="li3e" name="3204"> 204
 195
 196In general,35&quo30tion/memory-hotplug.txt#L672" id="L172" class="li3e" name="3207"> 207calls hotpl3g cod3 for a1) d to mory, c2"g=YYYY bo
< 208If memory d3vice 30 deviceS
 199script. Thi3cumen3> SpaS
 210
 2114.2 Notify 3emory3hot-ad2) d to s/systec2"g=ZZZZ bo
< 212-----------3
 213In some env3ronme3ry hot rS
 214notify memo3y hot31tion/memory-hotplug.txt#L552" id="L162" class="li3e" name="3215"> 215interface i3 supp3ation/memory-hotplug.txt#L116" id="L116" class="li3e" name="3216"> 216
 217Now, CONFIG3ARCH_3EMORY_="Documentation.ented nowTBD/memory-hotplug.txt#L181" id="L181" class="li3e" name="3218"> 218contain hig3ly ar31tion/memory-hotplug.txt#L142" id="L152" class="li3e" name="3219"> 219interface.
3a hre3ation/memory-hotplug.txt#L120" id="L120" class="li3e" name="3220"> 220
 221Probe inter3ace i32f="Documentation/memory-hotplug.txt#L422" id="L152" class="li3e" name="3222"> 222/sys/device3/syst32te it by NORM
 223
 224You can tel3 the 32tion/memory-hotplug.txt#L552" id="L162" class="li3e" name="3225"> 225
 226% echo 3tart_32tion/memory-hotplug.txt#L672" id="L172" class="li3e" name="3227"> 227
 228Then, [star3_addr32 found, itMfacr;s Aolly rrt cc2"g (like -EBUSY)ref="Docureturny.  It is ment, &memory-hotplug.txt#L232" id="L228" class="li3e" name="3229"> 229memory rang3 is h3t-addetpldded.=ocumentanntation/fb longf="DocumentationhNE_MONORMtref="D
 230current imp3ement330found, itMntata hrefdev packae amouund-only: contat;online&qune"ref==ucces//memory-hotplug.txt#L181" id="L181" class="li3e" name="3231"> 231Please see 3quot;3ation/memory-hotplug.txt#L132" id="L132" class="li3otplug.t.3_of_notplug.txt#L136" ia3e="L233"> 21Aocumentanort thcumentation/Dcaneonsidory. tocumeystemtocume
 132
 132No---------3-----3------
 132se Logical 3emory3hot-ad( section size.
<    ocumef rry. tocuyhAollymory, m 1323/a>-----------3---
<3------hAoonn/memory-hotplug.txt#L134" id="L134" class="li3e" name="3132"> 1323/a>
 132me1. State 3f mem3ry
 1424/a>-----------3
 142thToee &q(l3ne/of3line ms. P thf="DoDoguaranteetor clag--d=iew is
ort thanyhAituONFIG. Button a hr/memory-hotplug.txt#L77" id="L77" class="line3e" name="3142"> 1424g.txt#L136" ia3e="L233"> 2182"g
work. Return--d=-EBUSYtort thAollyAituONFIGn W 142
<37; ecc /3ys.
e3ice/syNORMdecidoDoDoret="L82"g
ation/ntatiimtion/ emory, s asiew is
1eu-----dg if memory-hotplug.txt#L77" id="L77" class="line3e" name="3142"> 142
 1424/a>
 142(0Ithe memo3y
 142ThIthe memo3y
 142
 142
 152a 2. How to3onlin3 memor -vent bt, and A 1525/a>-----------3
 152/sEvenf the3eemor35"> 213entation/me1tart_addre" id="L172" class="li3e" name="3152"> 152/sF userg a3w_m a35-------------a hr---
 152
 152/sF online/3 amau35-----------
 1525/a>
 15257a>% echo 3tline3ation/memory-hotplug.txt#L158" id="L158" class="li3e" name="3152"> 1525/a>
 152  is optine3g ail3  in theGPI) watiobef2"g
 by
 16260a>ThIthe memo3y
 162
 162' echo 3tline36"> 213entation/me1tart_addre" id="L172" class="li3e" name="3162"> 162  (TE:
< rr3nt im3imit:hd only CANCEL_ONLIN/memory-hotplug.txt#L182" id="L172otplug.txt#3e" name="3162"> 1626/a>
 162  Andf ther3emory36tion/memory-hotplug.txt#L226" id="L142" class="li3e" name="326">> 152
 16267a>% echo 3tline367at wriGPI) watiow to sI Suppoas==ucces/fuent,broughttnt of . xmenteaten W 162  (TE:
< rr3nt im3  deviceententae tion/ meomvory
 162
 172  Aer phis 3,ecti3n issod only GOING_OFFLIN/memory-hotplug.txt#L182" id="L172otplug.txt#3e" name="3172"> 172  ailable f3mory
3  removaGPI) watiotocumgref="Doproc kernel1eu-----dgtation/eAntentaif="Deric umemory-hotplug.txt#L182" id="L172otplug.txt#3e" name="3172"> 1727g.txt#L136" ia3e="L23  block longug possiale meomvory
 172  rrently t3tw_m 3  it is erpctf="DiRMre,. xmenteatenNORMbeDocum oDofentaE_MOVABknown icaamemory-hotplug.txt#L182" id="L172otplug.txt#3e" name="3172"> 172  is opy ha3calng3  every ugbstate
 meomvory
DocumentdoE_MOVABLE
 172
 1727/a>
 1727/a>
 1727/a>-----------3-----37 devicement memory "Docuwe/atte
patiotoc
 172If6Logical 3emory37tion/memory-hotplug.txt#L702" id="L172" class="li3e" name="3182"> 1828/a>-----------3-----38 issod only OFFLIN/memory-hotplug.txt#L182" id="L172otplug.txt#3e" name="3182"> 182
 182Fo6.1emory 3nllin38"> 213entation/me1tart_addre" id="L172" class="li3672" i"L132"> 1727/a>a 28G6a>-----3-----3------A3menteatenrouthreONORMocuregt afry.  I3entation/me1tart_addre" id="L172" class="li36" name="3--------------------21um3ntati38 every 72" cla_ id="L_ to itin(menteate_func,opriority/memory-hotplug.txt#L134" id="L134" class="li31" name="3185"> 185A backlink 3ill a38tion/memory-hotplug.txt#L172" id="L172" class="li3e" name="3186"> 186/sys/device3/syst3m/memoTent meos thrgg.txt th3menteatenfuncmory (acmoryn,="D such e.
eernelabove.memory-hotplug.txt#L228" id="L182" class="li3e" name="3187"> 187
 188-----------3-----38tion/memory-hotplug.txt#L172" id="L132" class="li3e" name="3189"> 1894. Physical3memor38tion/strucf="Docum_ to ie {memory-hotplug.txt#L172" id="L132" class="li3e" name="3190"> 190-----------3-----39 whether theunof physlongf="Documfn/memory-hotplug.txt#L219" id="L219" class="li3e" name="3191"> 191
 1924.1 Hardwar3(Firm39 block is re 193-----------3
 194On x86_64/i364 pl394block is re 195
 196In general,3the f39tion/memory-hotplug.txt#L672" id="L172" class="li3e" name="3197"> 197memory clas3 obje3t of _="Documfn erpctDocumfn nel1hand.
 198Linux's3ACPI 39tion/nr_tion/ erp#ref="ion/ nel1hand.
 199script. Thi3 will3be doneyoaus_ef="Do_nid_ trmal erpceh  tdy
Diow to NNE_MODMed onlyrnel ndemaskmemory-hotplug.txt#L228" id="L182" class="li4e" name="4200"> 200
 191
 1924.1 Hardwar4 to w4ite iterp(ef="Doc)pceh/clear,s pa ted now-1e beinl ndemaskn yoausef="Documf="Doc.memory-hotplug.txt#L228" id="L182" class="li4e3 name="4293"> 193-----------4quot;40y-hot yoaus_ef="Do_nid erpceh  tdy
Diow to NNd onlyrnel ndemask erp(ef="Doc)memory-hotplug.txt#L228" id="L182" class="li4e4 name="4294"> 194On x86_64/i4cumen4ation/ceh/clear. If="Da="De
 195
 196In general,45&quo40on is pa yoaus_ef="Dod_nid*f/mem= 0,3menteatenshouldentatio/discara strucfure not cbeimemory-hotplug.txt#L228" id="L182" class="li4e7 name="4297"> 197memory clas4g cod4 for a tdy
Del bc keaum.memory-hotplug.txt#L228" id="L182" class="li4e" name="4208"> 208If memory d4vice 40tion/memory-hotplug.txt#L172" id="L132" class="li4e9 name="4299"> 199script. Thi4cumen4> Scumentation/enmemory-hotplug.txt#L228" id="L182" class="li4e" name="4210"> 210
 2114.2 Notify 4emory41f="Documentation/enmemory-hotplug.txt#L228" id="L182" class="li4e2 name="4212"> 212-----------4
 213In some env4ronme413block issysctl
atioby
v parolation/memory-hotplug.txt#L232" id="L142" class="li4e" name="4214"> 214notify memo4y hot414device-el me--dgtationD memory es tmemory tohotplugreltaif="hip/memory-hotplug.txt#L232" id="L142" class="li4e5 name="4215"> 215interface i4 supp4ation/ce-el me--dgtationD memory ="Dort thcumentation/Dation/memory-hotplug.txt#L171" id="L171" class="li4e" name="4216"> 216
 217Now, CONFIG4ARCH_417ion/ce-el depen HugeTLB
<    m (CONFIGst in1eu-----d/memory-hotplug.txt#L232" id="L142" class="li4e" name="4218"> 218contain hig4ly ar418ion/ce-e idmapvreOTR--d=atriew is
1eu---n/memory-hotplug.txt#L232" id="L142" class="li4e9 name="4219"> 219interface.
4a hre419ion/ce-ememory toreOTREM"Docum.memory-hotplug.txt#L228" id="L182" class="li4e" name="4220"> 220
 221Probe inter4ace i42f="Do


221 TentoriginaluLXReAoftocume It is emory-hothttp://sourcef2"ge.neh/proin it/lxr">LXRecommunity="Dod as onexperi.txt#l versntanot emory-hotmailto:lxr@ldoes.no">lxr@ldoes.no="Do.
221 lxr.ldoes.no kindlnDhcstn/not emory-hothttp://www.redpf="-ldopro.no">Redpf="9 dopro AS="Dod providorrnelLdoesneonsult--d=a in1por#L172rpcerry4 X sinlug1995.