lkml.org 
[lkml]   [2015]   [Jun]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[RFC v2 PATCH 3/8] mm: find mirrored memory in memblock
Add a macro for_each_mirror_pfn_range() to find mirrored memory in memblock.
This patch is based on Tony's patchset "Find mirrored memory, use for boot time
allocations"

Signed-off-by: Xishi Qiu <qiuxishi@huawei.com>
---
include/linux/memblock.h | 25 ++++++++++++++++++++++---
mm/memblock.c | 6 +++++-
2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index 0215ffd..97f71ca 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -171,7 +171,8 @@ static inline bool memblock_is_mirror(struct memblock_region *m)
#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
int memblock_search_pfn_nid(unsigned long pfn, unsigned long *start_pfn,
unsigned long *end_pfn);
-void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn,
+void __next_mem_pfn_range(int *idx, int nid, ulong flags,
+ unsigned long *out_start_pfn,
unsigned long *out_end_pfn, int *out_nid);

/**
@@ -185,8 +186,26 @@ void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn,
* Walks over configured memory ranges.
*/
#define for_each_mem_pfn_range(i, nid, p_start, p_end, p_nid) \
- for (i = -1, __next_mem_pfn_range(&i, nid, p_start, p_end, p_nid); \
- i >= 0; __next_mem_pfn_range(&i, nid, p_start, p_end, p_nid))
+ for (i = -1, __next_mem_pfn_range(&i, nid, MEMBLOCK_NONE, \
+ p_start, p_end, p_nid); \
+ i >= 0; __next_mem_pfn_range(&i, nid, MEMBLOCK_NONE, \
+ p_start, p_end, p_nid))
+
+/**
+ * for_each_mirror_pfn_range - early mirrored memory pfn range iterator
+ * @i: an integer used as loop variable
+ * @nid: node selector, %MAX_NUMNODES for all nodes
+ * @p_start: ptr to ulong for start pfn of the range, can be %NULL
+ * @p_end: ptr to ulong for end pfn of the range, can be %NULL
+ * @p_nid: ptr to int for nid of the range, can be %NULL
+ *
+ * Walks over configured mirrored memory ranges.
+ */
+#define for_each_mirror_pfn_range(i, nid, p_start, p_end, p_nid) \
+ for (i = -1, __next_mem_pfn_range(&i, nid, MEMBLOCK_MIRROR, \
+ p_start, p_end, p_nid); \
+ i >= 0; __next_mem_pfn_range(&i, nid, MEMBLOCK_MIRROR, \
+ p_start, p_end, p_nid))
#endif /* CONFIG_HAVE_MEMBLOCK_NODE_MAP */

/**
diff --git a/mm/memblock.c b/mm/memblock.c
index 1b444c7..7612876 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -1040,7 +1040,7 @@ void __init_memblock __next_mem_range_rev(u64 *idx, int nid, ulong flags,
/*
* Common iterator interface used to define for_each_mem_range().
*/
-void __init_memblock __next_mem_pfn_range(int *idx, int nid,
+void __init_memblock __next_mem_pfn_range(int *idx, int nid, ulong flags,
unsigned long *out_start_pfn,
unsigned long *out_end_pfn, int *out_nid)
{
@@ -1050,6 +1050,10 @@ void __init_memblock __next_mem_pfn_range(int *idx, int nid,
while (++*idx < type->cnt) {
r = &type->regions[*idx];

+ /* if we want mirror memory skip non-mirror memory regions */
+ if ((flags & MEMBLOCK_MIRROR) && !memblock_is_mirror(r))
+ continue;
+
if (PFN_UP(r->base) >= PFN_DOWN(r->base + r->size))
continue;
if (nid == MAX_NUMNODES || nid == r->nid)
--
2.0.0



\
 
 \ /
  Last update: 2015-06-27 04:41    [W:0.129 / U:0.544 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site