- 论坛徽章:
- 16
|
本帖最后由 embeddedlwp 于 2013-12-19 09:39 编辑
回复 5# humjb_1983
The memory hotplug add memory consists two steps: online and add
add —— alloc memmap, if we using vmemmap, we also need alloc pagetables for it.
Online ——
The Memory hotplug remove memory consists two steps: offline and remove
offline —— Offline just migrates user pages to somewhere else, and isolates the pages from buddy
system so that no one can use them any more.
remove —— Remove will free kernel direct mapping pagetables, and memmap. If we are using
vmemmap, we also free the pagetables of vmemmap.
lock_memory_hotplug() will protect logical and physical add/removy memory
Logical add memory
lock_memory_hotplug()
Send memory hotplug event MEM_GOING_ONLINE
If zone is not present, setup zone's pcp(next step free pages to buddy will need it)
Online all pages, actually is clear PG_reserved flag, just like early allocator free
pages to buddy system
Update zone's field, manged_pages, present_pages and node's present pages
If zone is not present before, build all zonelists in order that other zone can fallback
to this zone, otherwise update zone's pcp since pcp's batch is acculated according
to zone's present pages and this value change during online pages
update watermark, lowmem reservation, inactive ratio
If the node is not present before, create kswapd
Recaculate total pages
Send memory hotplug event MEM_ONLINE
unlock_memory_hotplug()
Logical remove memory
lock_memory_hotplug()
Making page-allocation-type to be MIGRATE_ISOLATE in order that free pages in the
range will never be allocated.
Send memory hotplug event MEM_GOING_OFFLINE
Memory offline code does 5 times of retry with 120 seconds timeout
Drain pagevec and pageset
Scan range and migrate pages if they are on lru
Test if all pageblock are MIGRATE_ISOLATE type
Offline pages, actually is set PG_reserved flag, then buddy system can't use them
Rechange all pageblocks to MIGRATE_MOVABLE
Update watermark, lowmem reservation, inactive ratio
Build all zonelists f zone is not present any more, otherwise update zone's pcp
If node is not present any more, stop kswapd
Update total memory
unlock_memory_hotplug()
Physical add memory
lock_memory_hotplug()
If node is not present before, hotadd_new_pgdat
Add memory section one by one
Create section decriptor mem_section, add memmap, usemap(bitmap for pageblock migration
type), alloc pagetables and populate them if config sparse-vmemmap
Grow zone/pgdat span
Set PG_reserved flag
Register memory section one by one to memory block
Add firmware memmap entry
unlock_memory_hotplug()
Physical remove memory
Offline memory blocks in range one by one
lock_memory_hotplug()
Check if all memory blocks are offline(logic remove)
Remove firmware memmap entry
Remove memory
Remove sections from memory block one by one
Free memmap, usemap, free pagetables if config sparse-vmemmap
Try to offline node if all cpu/memory are offline
unlock_memory_hotplug()
|
|