linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/5] Add zone overlapping check
@ 2016-04-01  2:06 js1304
  2016-04-01  2:06 ` [PATCH v2 1/5] mm/hugetlb: add same zone check in pfn_range_valid_gigantic() js1304
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: js1304 @ 2016-04-01  2:06 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Rik van Riel, Johannes Weiner, Mel Gorman, Laura Abbott,
	Minchan Kim, Marek Szyprowski, Michal Nazarewicz,
	Aneesh Kumar K.V, Vlastimil Babka, Rafael J. Wysocki, linux-mm,
	linux-kernel, Joonsoo Kim

From: Joonsoo Kim <iamjoonsoo.kim@lge.com>

Change from v1
o drop patch 1 ("mm/page_alloc: fix same zone check in
__pageblock_pfn_to_page()") per Mel's comment

Hello, all.

This patchset deals with some problematic sites that iterate pfn range.

There is a system that node's pfn are overlapped like as following.

-----pfn-------->
N0 N1 N2 N0 N1 N2

Therefore, we need to care this overlapping when iterating pfn range.

I audit many iterating sites that uses pfn_valid(), pfn_valid_within(),
zone_start_pfn and etc. and others looks safe for me. This is
a preparation step for new CMA implementation, ZONE_CMA [1], because
it would be easily overlapped with other zones. But, zone overlap
check is also needed for general case so I send it separately.

This is based on next-20160330.

Thanks.

[1]: https://lkml.org/lkml/2015/2/12/95

Joonsoo Kim (5):
  mm/hugetlb: add same zone check in pfn_range_valid_gigantic()
  mm/memory_hotplug: add comment to some functions related to memory
    hotplug
  mm/vmstat: add zone range overlapping check
  mm/page_owner: add zone range overlapping check
  power: add zone range overlapping check

 mm/hugetlb.c        | 9 ++++++---
 mm/page_alloc.c     | 7 ++++++-
 mm/page_isolation.c | 1 +
 mm/page_owner.c     | 3 +++
 mm/vmstat.c         | 7 +++++++
 5 files changed, 23 insertions(+), 4 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 1/5] mm/hugetlb: add same zone check in pfn_range_valid_gigantic()
  2016-04-01  2:06 [PATCH v2 0/5] Add zone overlapping check js1304
@ 2016-04-01  2:06 ` js1304
  2016-04-01  2:06 ` [PATCH v2 2/5] mm/memory_hotplug: add comment to some functions related to memory hotplug js1304
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: js1304 @ 2016-04-01  2:06 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Rik van Riel, Johannes Weiner, Mel Gorman, Laura Abbott,
	Minchan Kim, Marek Szyprowski, Michal Nazarewicz,
	Aneesh Kumar K.V, Vlastimil Babka, Rafael J. Wysocki, linux-mm,
	linux-kernel, Joonsoo Kim

From: Joonsoo Kim <iamjoonsoo.kim@lge.com>

alloc_gigantic_page() uses alloc_contig_range() and this
requires that requested range is in a single zone. To satisfy
that requirement, add this check to pfn_range_valid_gigantic().

Acked-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
---
 mm/hugetlb.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 2c7f304..6bc7e9e 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1031,8 +1031,8 @@ static int __alloc_gigantic_page(unsigned long start_pfn,
 	return alloc_contig_range(start_pfn, end_pfn, MIGRATE_MOVABLE);
 }
 
-static bool pfn_range_valid_gigantic(unsigned long start_pfn,
-				unsigned long nr_pages)
+static bool pfn_range_valid_gigantic(struct zone *z,
+			unsigned long start_pfn, unsigned long nr_pages)
 {
 	unsigned long i, end_pfn = start_pfn + nr_pages;
 	struct page *page;
@@ -1043,6 +1043,9 @@ static bool pfn_range_valid_gigantic(unsigned long start_pfn,
 
 		page = pfn_to_page(i);
 
+		if (page_zone(page) != z)
+			return false;
+
 		if (PageReserved(page))
 			return false;
 
@@ -1075,7 +1078,7 @@ static struct page *alloc_gigantic_page(int nid, unsigned int order)
 
 		pfn = ALIGN(z->zone_start_pfn, nr_pages);
 		while (zone_spans_last_pfn(z, pfn, nr_pages)) {
-			if (pfn_range_valid_gigantic(pfn, nr_pages)) {
+			if (pfn_range_valid_gigantic(z, pfn, nr_pages)) {
 				/*
 				 * We release the zone lock here because
 				 * alloc_contig_range() will also lock the zone
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 2/5] mm/memory_hotplug: add comment to some functions related to memory hotplug
  2016-04-01  2:06 [PATCH v2 0/5] Add zone overlapping check js1304
  2016-04-01  2:06 ` [PATCH v2 1/5] mm/hugetlb: add same zone check in pfn_range_valid_gigantic() js1304
@ 2016-04-01  2:06 ` js1304
  2016-04-01  2:06 ` [PATCH v2 3/5] mm/vmstat: add zone range overlapping check js1304
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: js1304 @ 2016-04-01  2:06 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Rik van Riel, Johannes Weiner, Mel Gorman, Laura Abbott,
	Minchan Kim, Marek Szyprowski, Michal Nazarewicz,
	Aneesh Kumar K.V, Vlastimil Babka, Rafael J. Wysocki, linux-mm,
	linux-kernel, Joonsoo Kim

From: Joonsoo Kim <iamjoonsoo.kim@lge.com>

__offline_isolated_pages() and test_pages_isolated() are used by memory
hotplug. These functions require that range is in a single zone but
there is no code about it because memory hotplug checks it before calling
these functions. Not to confuse future user of these functions,
this patch adds comment on them.

Acked-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
---
 mm/page_alloc.c     | 3 ++-
 mm/page_isolation.c | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index b563403..0cfee62 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -7280,7 +7280,8 @@ void zone_pcp_reset(struct zone *zone)
 
 #ifdef CONFIG_MEMORY_HOTREMOVE
 /*
- * All pages in the range must be isolated before calling this.
+ * All pages in the range must be in a single zone and isolated
+ * before calling this.
  */
 void
 __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn)
diff --git a/mm/page_isolation.c b/mm/page_isolation.c
index 67bedd1..612122b 100644
--- a/mm/page_isolation.c
+++ b/mm/page_isolation.c
@@ -246,6 +246,7 @@ __test_page_isolated_in_pageblock(unsigned long pfn, unsigned long end_pfn,
 	return pfn;
 }
 
+/* Caller should ensure that requested range is in a single zone */
 int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn,
 			bool skip_hwpoisoned_pages)
 {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 3/5] mm/vmstat: add zone range overlapping check
  2016-04-01  2:06 [PATCH v2 0/5] Add zone overlapping check js1304
  2016-04-01  2:06 ` [PATCH v2 1/5] mm/hugetlb: add same zone check in pfn_range_valid_gigantic() js1304
  2016-04-01  2:06 ` [PATCH v2 2/5] mm/memory_hotplug: add comment to some functions related to memory hotplug js1304
@ 2016-04-01  2:06 ` js1304
  2016-04-01  8:19   ` Vlastimil Babka
  2016-04-01  2:06 ` [PATCH v2 4/5] mm/page_owner: " js1304
  2016-04-01  2:06 ` [PATCH v2 5/5] power: " js1304
  4 siblings, 1 reply; 9+ messages in thread
From: js1304 @ 2016-04-01  2:06 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Rik van Riel, Johannes Weiner, Mel Gorman, Laura Abbott,
	Minchan Kim, Marek Szyprowski, Michal Nazarewicz,
	Aneesh Kumar K.V, Vlastimil Babka, Rafael J. Wysocki, linux-mm,
	linux-kernel, Joonsoo Kim

From: Joonsoo Kim <iamjoonsoo.kim@lge.com>

There is a system that node's pfn are overlapped like as following.

-----pfn-------->
N0 N1 N2 N0 N1 N2

Therefore, we need to care this overlapping when iterating pfn range.

There are two places in vmstat.c that iterates pfn range and
they don't consider this overlapping. Add it.

Without this patch, above system could over count pageblock number
on a zone.

Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
---
 mm/vmstat.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/mm/vmstat.c b/mm/vmstat.c
index 5e43004..0a726e3 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1010,6 +1010,9 @@ static void pagetypeinfo_showblockcount_print(struct seq_file *m,
 		if (!memmap_valid_within(pfn, page, zone))
 			continue;
 
+		if (page_zone(page) != zone)
+			continue;
+
 		mtype = get_pageblock_migratetype(page);
 
 		if (mtype < MIGRATE_TYPES)
@@ -1076,6 +1079,10 @@ static void pagetypeinfo_showmixedcount_print(struct seq_file *m,
 				continue;
 
 			page = pfn_to_page(pfn);
+
+			if (page_zone(page) != zone)
+				continue;
+
 			if (PageBuddy(page)) {
 				pfn += (1UL << page_order(page)) - 1;
 				continue;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 4/5] mm/page_owner: add zone range overlapping check
  2016-04-01  2:06 [PATCH v2 0/5] Add zone overlapping check js1304
                   ` (2 preceding siblings ...)
  2016-04-01  2:06 ` [PATCH v2 3/5] mm/vmstat: add zone range overlapping check js1304
@ 2016-04-01  2:06 ` js1304
  2016-04-01  8:19   ` Vlastimil Babka
  2016-04-01  2:06 ` [PATCH v2 5/5] power: " js1304
  4 siblings, 1 reply; 9+ messages in thread
From: js1304 @ 2016-04-01  2:06 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Rik van Riel, Johannes Weiner, Mel Gorman, Laura Abbott,
	Minchan Kim, Marek Szyprowski, Michal Nazarewicz,
	Aneesh Kumar K.V, Vlastimil Babka, Rafael J. Wysocki, linux-mm,
	linux-kernel, Joonsoo Kim

From: Joonsoo Kim <iamjoonsoo.kim@lge.com>

There is a system that node's pfn are overlapped like as following.

-----pfn-------->
N0 N1 N2 N0 N1 N2

Therefore, we need to care this overlapping when iterating pfn range.

There are one place in page_owner.c that iterates pfn range and
it doesn't consider this overlapping. Add it.

Without this patch, above system could over count early allocated
page number before page_owner is activated.

Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
---
 mm/page_owner.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/page_owner.c b/mm/page_owner.c
index ac3d8d1..438768c 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -301,6 +301,9 @@ static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone)
 
 			page = pfn_to_page(pfn);
 
+			if (page_zone(page) != zone)
+				continue;
+
 			/*
 			 * We are safe to check buddy flag and order, because
 			 * this is init stage and only single thread runs.
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 5/5] power: add zone range overlapping check
  2016-04-01  2:06 [PATCH v2 0/5] Add zone overlapping check js1304
                   ` (3 preceding siblings ...)
  2016-04-01  2:06 ` [PATCH v2 4/5] mm/page_owner: " js1304
@ 2016-04-01  2:06 ` js1304
  2016-04-01  8:19   ` Vlastimil Babka
  4 siblings, 1 reply; 9+ messages in thread
From: js1304 @ 2016-04-01  2:06 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Rik van Riel, Johannes Weiner, Mel Gorman, Laura Abbott,
	Minchan Kim, Marek Szyprowski, Michal Nazarewicz,
	Aneesh Kumar K.V, Vlastimil Babka, Rafael J. Wysocki, linux-mm,
	linux-kernel, Joonsoo Kim

From: Joonsoo Kim <iamjoonsoo.kim@lge.com>

There is a system that node's pfn are overlapped like as following.

-----pfn-------->
N0 N1 N2 N0 N1 N2

Therefore, we need to care this overlapping when iterating pfn range.

mark_free_pages() iterates requested zone's pfn range and unset
all range's bitmap first. And then it marks freepages in a zone
to the bitmap. If there is an overlapping zone, above unset could
clear previous marked bit and reference to this bitmap in the future
will cause the problem. To prevent it, this patch adds a zone check
in mark_free_pages().

Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
---
 mm/page_alloc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 0cfee62..437a934 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -2156,6 +2156,10 @@ void mark_free_pages(struct zone *zone)
 	for (pfn = zone->zone_start_pfn; pfn < max_zone_pfn; pfn++)
 		if (pfn_valid(pfn)) {
 			page = pfn_to_page(pfn);
+
+			if (page_zone(page) != zone)
+				continue;
+
 			if (!swsusp_page_is_forbidden(page))
 				swsusp_unset_page_free(page);
 		}
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 3/5] mm/vmstat: add zone range overlapping check
  2016-04-01  2:06 ` [PATCH v2 3/5] mm/vmstat: add zone range overlapping check js1304
@ 2016-04-01  8:19   ` Vlastimil Babka
  0 siblings, 0 replies; 9+ messages in thread
From: Vlastimil Babka @ 2016-04-01  8:19 UTC (permalink / raw)
  To: js1304, Andrew Morton
  Cc: Rik van Riel, Johannes Weiner, Mel Gorman, Laura Abbott,
	Minchan Kim, Marek Szyprowski, Michal Nazarewicz,
	Aneesh Kumar K.V, Rafael J. Wysocki, linux-mm, linux-kernel,
	Joonsoo Kim

On 1.4.2016 4:06, js1304@gmail.com wrote:
> From: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> 
> There is a system that node's pfn are overlapped like as following.
> 
> -----pfn-------->
> N0 N1 N2 N0 N1 N2
> 
> Therefore, we need to care this overlapping when iterating pfn range.
> 
> There are two places in vmstat.c that iterates pfn range and
> they don't consider this overlapping. Add it.
> 
> Without this patch, above system could over count pageblock number
> on a zone.
> 
> Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 4/5] mm/page_owner: add zone range overlapping check
  2016-04-01  2:06 ` [PATCH v2 4/5] mm/page_owner: " js1304
@ 2016-04-01  8:19   ` Vlastimil Babka
  0 siblings, 0 replies; 9+ messages in thread
From: Vlastimil Babka @ 2016-04-01  8:19 UTC (permalink / raw)
  To: js1304, Andrew Morton
  Cc: Rik van Riel, Johannes Weiner, Mel Gorman, Laura Abbott,
	Minchan Kim, Marek Szyprowski, Michal Nazarewicz,
	Aneesh Kumar K.V, Rafael J. Wysocki, linux-mm, linux-kernel,
	Joonsoo Kim

On 1.4.2016 4:06, js1304@gmail.com wrote:
> From: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> 
> There is a system that node's pfn are overlapped like as following.
> 
> -----pfn-------->
> N0 N1 N2 N0 N1 N2
> 
> Therefore, we need to care this overlapping when iterating pfn range.
> 
> There are one place in page_owner.c that iterates pfn range and
> it doesn't consider this overlapping. Add it.
> 
> Without this patch, above system could over count early allocated
> page number before page_owner is activated.
> 
> Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>  mm/page_owner.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/mm/page_owner.c b/mm/page_owner.c
> index ac3d8d1..438768c 100644
> --- a/mm/page_owner.c
> +++ b/mm/page_owner.c
> @@ -301,6 +301,9 @@ static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone)
>  
>  			page = pfn_to_page(pfn);
>  
> +			if (page_zone(page) != zone)
> +				continue;
> +
>  			/*
>  			 * We are safe to check buddy flag and order, because
>  			 * this is init stage and only single thread runs.
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 5/5] power: add zone range overlapping check
  2016-04-01  2:06 ` [PATCH v2 5/5] power: " js1304
@ 2016-04-01  8:19   ` Vlastimil Babka
  0 siblings, 0 replies; 9+ messages in thread
From: Vlastimil Babka @ 2016-04-01  8:19 UTC (permalink / raw)
  To: js1304, Andrew Morton
  Cc: Rik van Riel, Johannes Weiner, Mel Gorman, Laura Abbott,
	Minchan Kim, Marek Szyprowski, Michal Nazarewicz,
	Aneesh Kumar K.V, Rafael J. Wysocki, linux-mm, linux-kernel,
	Joonsoo Kim

On 1.4.2016 4:06, js1304@gmail.com wrote:
> From: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> 
> There is a system that node's pfn are overlapped like as following.
> 
> -----pfn-------->
> N0 N1 N2 N0 N1 N2
> 
> Therefore, we need to care this overlapping when iterating pfn range.
> 
> mark_free_pages() iterates requested zone's pfn range and unset
> all range's bitmap first. And then it marks freepages in a zone
> to the bitmap. If there is an overlapping zone, above unset could
> clear previous marked bit and reference to this bitmap in the future
> will cause the problem. To prevent it, this patch adds a zone check
> in mark_free_pages().
> 
> Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>  mm/page_alloc.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 0cfee62..437a934 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -2156,6 +2156,10 @@ void mark_free_pages(struct zone *zone)
>  	for (pfn = zone->zone_start_pfn; pfn < max_zone_pfn; pfn++)
>  		if (pfn_valid(pfn)) {
>  			page = pfn_to_page(pfn);
> +
> +			if (page_zone(page) != zone)
> +				continue;
> +
>  			if (!swsusp_page_is_forbidden(page))
>  				swsusp_unset_page_free(page);
>  		}
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-04-01  8:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-01  2:06 [PATCH v2 0/5] Add zone overlapping check js1304
2016-04-01  2:06 ` [PATCH v2 1/5] mm/hugetlb: add same zone check in pfn_range_valid_gigantic() js1304
2016-04-01  2:06 ` [PATCH v2 2/5] mm/memory_hotplug: add comment to some functions related to memory hotplug js1304
2016-04-01  2:06 ` [PATCH v2 3/5] mm/vmstat: add zone range overlapping check js1304
2016-04-01  8:19   ` Vlastimil Babka
2016-04-01  2:06 ` [PATCH v2 4/5] mm/page_owner: " js1304
2016-04-01  8:19   ` Vlastimil Babka
2016-04-01  2:06 ` [PATCH v2 5/5] power: " js1304
2016-04-01  8:19   ` Vlastimil Babka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).