]> Git Repo - linux.git/commitdiff
memory-hotplug: more general validation of zone during online
authorReza Arbab <[email protected]>
Tue, 26 Jul 2016 22:22:23 +0000 (15:22 -0700)
committerLinus Torvalds <[email protected]>
Tue, 26 Jul 2016 23:19:19 +0000 (16:19 -0700)
When memory is onlined, we are only able to rezone from ZONE_MOVABLE to
ZONE_KERNEL, or from (ZONE_MOVABLE - 1) to ZONE_MOVABLE.

To be more flexible, use the following criteria instead; to online
memory from zone X into zone Y,

* Any zones between X and Y must be unused.
* If X is lower than Y, the onlined memory must lie at the end of X.
* If X is higher than Y, the onlined memory must lie at the start of X.

Add zone_can_shift() to make this determination.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Reza Arbab <[email protected]>
Reviewd-by: Yasuaki Ishimatsu <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Daniel Kiper <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: Tang Chen <[email protected]>
Cc: Joonsoo Kim <[email protected]>
Cc: David Vrabel <[email protected]>
Cc: Vitaly Kuznetsov <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Andrew Banman <[email protected]>
Cc: Chen Yucong <[email protected]>
Cc: Yasunori Goto <[email protected]>
Cc: Zhang Zhen <[email protected]>
Cc: Shaohua Li <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
include/linux/memory_hotplug.h
mm/memory_hotplug.c

index 5145620ba48a9572a94315b91265c5e657b78e17..01033fadea4766d5e6efddc78ca595d68c021464 100644 (file)
@@ -284,5 +284,7 @@ extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms,
                unsigned long map_offset);
 extern struct page *sparse_decode_mem_map(unsigned long coded_mem_map,
                                          unsigned long pnum);
+extern int zone_can_shift(unsigned long pfn, unsigned long nr_pages,
+                         enum zone_type target);
 
 #endif /* __LINUX_MEMORY_HOTPLUG_H */
index a86a66cbef77b37900fde34fb470fecbc2aad98d..82d0b98d27f878015153dd4d360ad7825bab9c48 100644 (file)
@@ -1047,6 +1047,37 @@ static void node_states_set_node(int node, struct memory_notify *arg)
        node_set_state(node, N_MEMORY);
 }
 
+int zone_can_shift(unsigned long pfn, unsigned long nr_pages,
+                  enum zone_type target)
+{
+       struct zone *zone = page_zone(pfn_to_page(pfn));
+       enum zone_type idx = zone_idx(zone);
+       int i;
+
+       if (idx < target) {
+               /* pages must be at end of current zone */
+               if (pfn + nr_pages != zone_end_pfn(zone))
+                       return 0;
+
+               /* no zones in use between current zone and target */
+               for (i = idx + 1; i < target; i++)
+                       if (zone_is_initialized(zone - idx + i))
+                               return 0;
+       }
+
+       if (target < idx) {
+               /* pages must be at beginning of current zone */
+               if (pfn != zone->zone_start_pfn)
+                       return 0;
+
+               /* no zones in use between current zone and target */
+               for (i = target + 1; i < idx; i++)
+                       if (zone_is_initialized(zone - idx + i))
+                               return 0;
+       }
+
+       return target - idx;
+}
 
 /* Must be protected by mem_hotplug_begin() */
 int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_type)
@@ -1072,13 +1103,10 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_typ
            !can_online_high_movable(zone))
                return -EINVAL;
 
-       if (online_type == MMOP_ONLINE_KERNEL &&
-           zone_idx(zone) == ZONE_MOVABLE)
-               zone_shift = -1;
-
-       if (online_type == MMOP_ONLINE_MOVABLE &&
-           zone_idx(zone) == ZONE_MOVABLE - 1)
-               zone_shift = 1;
+       if (online_type == MMOP_ONLINE_KERNEL)
+               zone_shift = zone_can_shift(pfn, nr_pages, ZONE_NORMAL);
+       else if (online_type == MMOP_ONLINE_MOVABLE)
+               zone_shift = zone_can_shift(pfn, nr_pages, ZONE_MOVABLE);
 
        zone = move_pfn_range(zone_shift, pfn, pfn + nr_pages);
        if (!zone)
This page took 0.063186 seconds and 4 git commands to generate.