• Wei Yang's avatar
    mm/page_alloc.c: fix calculation of pgdat->nr_zones · 8f416836
    Wei Yang authored
    init_currently_empty_zone() will adjust pgdat->nr_zones and set it to
    'zone_idx(zone) + 1' unconditionally.  This is correct in the normal
    case, while not exact in hot-plug situation.
    
    This function is used in two places:
    
      * free_area_init_core()
      * move_pfn_range_to_zone()
    
    In the first case, we are sure zone index increase monotonically.  While
    in the second one, this is under users control.
    
    One way to reproduce this is:
    ----------------------------
    
    1. create a virtual machine with empty node1
    
       -m 4G,slots=32,maxmem=32G \
       -smp 4,maxcpus=8          \
       -numa node,nodeid=0,mem=4G,cpus=0-3 \
       -numa node,nodeid=1,mem=0G,cpus=4-7
    
    2. hot-add cpu 3-7
    
       cpu-add [3-7]
    
    2. hot-add memory to nod1
    
       object_add memory-backend-ram,id=ram0,size=1G
       device_add pc-dimm,id=dimm0,memdev=ram0,node=1
    
    3. online memory with following order
    
       echo online_movable > memory47/state
       echo online > memory40/state
    
    After this, node1 will have its nr_zones ...
    8f416836
page_alloc.c 225 KB