aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTang Chen <tangchen@cn.fujitsu.com>2014-01-21 18:49:23 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-01-21 19:19:44 -0500
commit66b16edf9eafc3291cabb2253d0f342a847656b7 (patch)
tree199bd4e4caf0b24102764740ae5e620a7018103d
parent66a20757214d94b915f2d2aada1384dead9ab18d (diff)
memblock, mem_hotplug: introduce MEMBLOCK_HOTPLUG flag to mark hotpluggable regions
In find_hotpluggable_memory, once we find out a memory region which is hotpluggable, we want to mark them in memblock.memory. So that we could control memblock allocator not to allocte hotpluggable memory for the kernel later. To achieve this goal, we introduce MEMBLOCK_HOTPLUG flag to indicate the hotpluggable memory regions in memblock and a function memblock_mark_hotplug() to mark hotpluggable memory if we find one. [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com> Reviewed-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: "Rafael J . Wysocki" <rjw@sisk.pl> Cc: Chen Tang <imtangchen@gmail.com> Cc: Gong Chen <gong.chen@linux.intel.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Jiang Liu <jiang.liu@huawei.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Lai Jiangshan <laijs@cn.fujitsu.com> Cc: Larry Woodman <lwoodman@redhat.com> Cc: Len Brown <lenb@kernel.org> Cc: Liu Jiang <jiang.liu@huawei.com> Cc: Mel Gorman <mgorman@suse.de> Cc: Michal Nazarewicz <mina86@mina86.com> Cc: Minchan Kim <minchan@kernel.org> Cc: Prarit Bhargava <prarit@redhat.com> Cc: Rik van Riel <riel@redhat.com> Cc: Taku Izumi <izumi.taku@jp.fujitsu.com> Cc: Tejun Heo <tj@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Thomas Renninger <trenn@suse.de> Cc: Toshi Kani <toshi.kani@hp.com> Cc: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com> Cc: Wanpeng Li <liwanp@linux.vnet.ibm.com> Cc: Wen Congyang <wency@cn.fujitsu.com> Cc: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com> Cc: Yinghai Lu <yinghai@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--include/linux/memblock.h17
-rw-r--r--mm/memblock.c53
2 files changed, 70 insertions, 0 deletions
diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index 9a805ec6e794..b788faa71563 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -19,6 +19,9 @@
19 19
20#define INIT_MEMBLOCK_REGIONS 128 20#define INIT_MEMBLOCK_REGIONS 128
21 21
22/* Definition of memblock flags. */
23#define MEMBLOCK_HOTPLUG 0x1 /* hotpluggable region */
24
22struct memblock_region { 25struct memblock_region {
23 phys_addr_t base; 26 phys_addr_t base;
24 phys_addr_t size; 27 phys_addr_t size;
@@ -60,6 +63,8 @@ int memblock_remove(phys_addr_t base, phys_addr_t size);
60int memblock_free(phys_addr_t base, phys_addr_t size); 63int memblock_free(phys_addr_t base, phys_addr_t size);
61int memblock_reserve(phys_addr_t base, phys_addr_t size); 64int memblock_reserve(phys_addr_t base, phys_addr_t size);
62void memblock_trim_memory(phys_addr_t align); 65void memblock_trim_memory(phys_addr_t align);
66int memblock_mark_hotplug(phys_addr_t base, phys_addr_t size);
67int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size);
63 68
64#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP 69#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
65int memblock_search_pfn_nid(unsigned long pfn, unsigned long *start_pfn, 70int memblock_search_pfn_nid(unsigned long pfn, unsigned long *start_pfn,
@@ -122,6 +127,18 @@ void __next_free_mem_range_rev(u64 *idx, int nid, phys_addr_t *out_start,
122 i != (u64)ULLONG_MAX; \ 127 i != (u64)ULLONG_MAX; \
123 __next_free_mem_range_rev(&i, nid, p_start, p_end, p_nid)) 128 __next_free_mem_range_rev(&i, nid, p_start, p_end, p_nid))
124 129
130static inline void memblock_set_region_flags(struct memblock_region *r,
131 unsigned long flags)
132{
133 r->flags |= flags;
134}
135
136static inline void memblock_clear_region_flags(struct memblock_region *r,
137 unsigned long flags)
138{
139 r->flags &= ~flags;
140}
141
125#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP 142#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
126int memblock_set_node(phys_addr_t base, phys_addr_t size, int nid); 143int memblock_set_node(phys_addr_t base, phys_addr_t size, int nid);
127 144
diff --git a/mm/memblock.c b/mm/memblock.c
index 270b005ca964..2121ec4c7fa0 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -683,6 +683,59 @@ int __init_memblock memblock_reserve(phys_addr_t base, phys_addr_t size)
683} 683}
684 684
685/** 685/**
686 * memblock_mark_hotplug - Mark hotpluggable memory with flag MEMBLOCK_HOTPLUG.
687 * @base: the base phys addr of the region
688 * @size: the size of the region
689 *
690 * This function isolates region [@base, @base + @size), and mark it with flag
691 * MEMBLOCK_HOTPLUG.
692 *
693 * Return 0 on succees, -errno on failure.
694 */
695int __init_memblock memblock_mark_hotplug(phys_addr_t base, phys_addr_t size)
696{
697 struct memblock_type *type = &memblock.memory;
698 int i, ret, start_rgn, end_rgn;
699
700 ret = memblock_isolate_range(type, base, size, &start_rgn, &end_rgn);
701 if (ret)
702 return ret;
703
704 for (i = start_rgn; i < end_rgn; i++)
705 memblock_set_region_flags(&type->regions[i], MEMBLOCK_HOTPLUG);
706
707 memblock_merge_regions(type);
708 return 0;
709}
710
711/**
712 * memblock_clear_hotplug - Clear flag MEMBLOCK_HOTPLUG for a specified region.
713 * @base: the base phys addr of the region
714 * @size: the size of the region
715 *
716 * This function isolates region [@base, @base + @size), and clear flag
717 * MEMBLOCK_HOTPLUG for the isolated regions.
718 *
719 * Return 0 on succees, -errno on failure.
720 */
721int __init_memblock memblock_clear_hotplug(phys_addr_t base, phys_addr_t size)
722{
723 struct memblock_type *type = &memblock.memory;
724 int i, ret, start_rgn, end_rgn;
725
726 ret = memblock_isolate_range(type, base, size, &start_rgn, &end_rgn);
727 if (ret)
728 return ret;
729
730 for (i = start_rgn; i < end_rgn; i++)
731 memblock_clear_region_flags(&type->regions[i],
732 MEMBLOCK_HOTPLUG);
733
734 memblock_merge_regions(type);
735 return 0;
736}
737
738/**
686 * __next_free_mem_range - next function for for_each_free_mem_range() 739 * __next_free_mem_range - next function for for_each_free_mem_range()
687 * @idx: pointer to u64 loop variable 740 * @idx: pointer to u64 loop variable
688 * @nid: node selector, %MAX_NUMNODES for all nodes 741 * @nid: node selector, %MAX_NUMNODES for all nodes