* Re: [PATCH 2/2] mm: fix contiguous memmap assumptions about alloc/free pages
2022-03-29 13:09 ` [PATCH 2/2] mm: fix contiguous memmap assumptions about alloc/free pages Chen Wandun
@ 2022-03-29 13:08 ` Matthew Wilcox
2022-03-29 13:27 ` Chen Wandun
0 siblings, 1 reply; 5+ messages in thread
From: Matthew Wilcox @ 2022-03-29 13:08 UTC (permalink / raw)
To: Chen Wandun; +Cc: linux-mm, linux-kernel, akpm
On Tue, Mar 29, 2022 at 09:09:28PM +0800, Chen Wandun wrote:
> +#define page_nth(head, tail) (page_to_pfn(tail) - page_to_pfn(head))
Could we avoid reintroducing page_nth()? It is a terrible name.
> @@ -1213,7 +1213,7 @@ static int free_tail_pages_check(struct page *head_page, struct page *page)
> ret = 0;
> goto out;
> }
> - switch (page - head_page) {
> + switch (page_nth(head_page, page)) {
> case 1:
> /* the first tail page: ->mapping may be compound_mapcount() */
> if (unlikely(compound_mapcount(page))) {
This is the only place you use it. I'd suggest free_tail_pages_check()
should take 'i' as its second parameter instead of 'page + i', then
there's no need to convert back to i.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 0/2] fix several contiguous memmap assumptions
@ 2022-03-29 13:09 Chen Wandun
2022-03-29 13:09 ` [PATCH 1/2] mm: fix contiguous memmap assumptions about split page Chen Wandun
2022-03-29 13:09 ` [PATCH 2/2] mm: fix contiguous memmap assumptions about alloc/free pages Chen Wandun
0 siblings, 2 replies; 5+ messages in thread
From: Chen Wandun @ 2022-03-29 13:09 UTC (permalink / raw)
To: linux-mm, linux-kernel, akpm
It isn't true for only SPARSEMEM configs to assume that a compound page
has virtually contiguous page structs, so use nth_page to iterate each
page.
Inspired by:
https://lore.kernel.org/linux-mm/20220204195852.1751729-8-willy@infradead.org/
Chen Wandun (2):
mm: fix contiguous memmap assumptions about split page
mm: fix contiguous memmap assumptions about alloc/free pages
include/linux/mm.h | 2 ++
mm/compaction.c | 6 +++---
mm/huge_memory.c | 2 +-
mm/page_alloc.c | 14 ++++++++------
4 files changed, 14 insertions(+), 10 deletions(-)
--
2.18.0.huawei.25
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] mm: fix contiguous memmap assumptions about split page
2022-03-29 13:09 [PATCH 0/2] fix several contiguous memmap assumptions Chen Wandun
@ 2022-03-29 13:09 ` Chen Wandun
2022-03-29 13:09 ` [PATCH 2/2] mm: fix contiguous memmap assumptions about alloc/free pages Chen Wandun
1 sibling, 0 replies; 5+ messages in thread
From: Chen Wandun @ 2022-03-29 13:09 UTC (permalink / raw)
To: linux-mm, linux-kernel, akpm
It isn't true for only SPARSEMEM configs to assume that a compound page
has virtually contiguous page structs, so use nth_page to iterate each
page.
Inspired by:
https://lore.kernel.org/linux-mm/20220204195852.1751729-8-willy@infradead.org/
Signed-off-by: Chen Wandun <chenwandun@huawei.com>
---
mm/compaction.c | 6 +++---
mm/huge_memory.c | 2 +-
mm/page_alloc.c | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/mm/compaction.c b/mm/compaction.c
index c3e37aa9ff9e..ddff13b968a2 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -87,7 +87,7 @@ static unsigned long release_freepages(struct list_head *freelist)
static void split_map_pages(struct list_head *list)
{
unsigned int i, order, nr_pages;
- struct page *page, *next;
+ struct page *page, *next, *tmp;
LIST_HEAD(tmp_list);
list_for_each_entry_safe(page, next, list, lru) {
@@ -101,8 +101,8 @@ static void split_map_pages(struct list_head *list)
split_page(page, order);
for (i = 0; i < nr_pages; i++) {
- list_add(&page->lru, &tmp_list);
- page++;
+ tmp = nth_page(page, i);
+ list_add(&tmp->lru, &tmp_list);
}
}
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 2fe38212e07c..d77fc2ad581d 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2297,7 +2297,7 @@ static void lru_add_page_tail(struct page *head, struct page *tail,
static void __split_huge_page_tail(struct page *head, int tail,
struct lruvec *lruvec, struct list_head *list)
{
- struct page *page_tail = head + tail;
+ struct page *page_tail = nth_page(head, tail);
VM_BUG_ON_PAGE(atomic_read(&page_tail->_mapcount) != -1, page_tail);
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index f648decfe39d..855211dea13e 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3513,7 +3513,7 @@ void split_page(struct page *page, unsigned int order)
VM_BUG_ON_PAGE(!page_count(page), page);
for (i = 1; i < (1 << order); i++)
- set_page_refcounted(page + i);
+ set_page_refcounted(nth_page(page, i));
split_page_owner(page, 1 << order);
split_page_memcg(page, 1 << order);
}
--
2.18.0.huawei.25
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] mm: fix contiguous memmap assumptions about alloc/free pages
2022-03-29 13:09 [PATCH 0/2] fix several contiguous memmap assumptions Chen Wandun
2022-03-29 13:09 ` [PATCH 1/2] mm: fix contiguous memmap assumptions about split page Chen Wandun
@ 2022-03-29 13:09 ` Chen Wandun
2022-03-29 13:08 ` Matthew Wilcox
1 sibling, 1 reply; 5+ messages in thread
From: Chen Wandun @ 2022-03-29 13:09 UTC (permalink / raw)
To: linux-mm, linux-kernel, akpm
It isn't true for only SPARSEMEM configs to assume that a compound page
has virtually contiguous page structs, so use nth_page to iterate each
page.
Signed-off-by: Chen Wandun <chenwandun@huawei.com>
---
include/linux/mm.h | 2 ++
mm/page_alloc.c | 12 +++++++-----
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 355075fb2654..ef48cfef7c67 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -212,9 +212,11 @@ int overcommit_policy_handler(struct ctl_table *, int, void *, size_t *,
#if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
#define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n))
+#define page_nth(head, tail) (page_to_pfn(tail) - page_to_pfn(head))
#define folio_page_idx(folio, p) (page_to_pfn(p) - folio_pfn(folio))
#else
#define nth_page(page,n) ((page) + (n))
+#define page_nth(head, tail) ((tail) - (head))
#define folio_page_idx(folio, p) ((p) - &(folio)->page)
#endif
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 855211dea13e..09bc63992d20 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -721,7 +721,7 @@ static void prep_compound_head(struct page *page, unsigned int order)
static void prep_compound_tail(struct page *head, int tail_idx)
{
- struct page *p = head + tail_idx;
+ struct page *p = nth_page(head, tail_idx);
p->mapping = TAIL_MAPPING;
set_compound_head(p, head);
@@ -1213,7 +1213,7 @@ static int free_tail_pages_check(struct page *head_page, struct page *page)
ret = 0;
goto out;
}
- switch (page - head_page) {
+ switch (page_nth(head_page, page)) {
case 1:
/* the first tail page: ->mapping may be compound_mapcount() */
if (unlikely(compound_mapcount(page))) {
@@ -1322,6 +1322,7 @@ static __always_inline bool free_pages_prepare(struct page *page,
if (unlikely(order)) {
bool compound = PageCompound(page);
int i;
+ struct page *tail_page;
VM_BUG_ON_PAGE(compound && compound_order(page) != order, page);
@@ -1330,13 +1331,14 @@ static __always_inline bool free_pages_prepare(struct page *page,
ClearPageHasHWPoisoned(page);
}
for (i = 1; i < (1 << order); i++) {
+ tail_page = nth_page(page, i);
if (compound)
- bad += free_tail_pages_check(page, page + i);
- if (unlikely(check_free_page(page + i))) {
+ bad += free_tail_pages_check(page, tail_page);
+ if (unlikely(check_free_page(tail_page))) {
bad++;
continue;
}
- (page + i)->flags &= ~PAGE_FLAGS_CHECK_AT_PREP;
+ tail_page->flags &= ~PAGE_FLAGS_CHECK_AT_PREP;
}
}
if (PageMappingFlags(page))
--
2.18.0.huawei.25
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] mm: fix contiguous memmap assumptions about alloc/free pages
2022-03-29 13:08 ` Matthew Wilcox
@ 2022-03-29 13:27 ` Chen Wandun
0 siblings, 0 replies; 5+ messages in thread
From: Chen Wandun @ 2022-03-29 13:27 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: linux-mm, linux-kernel, akpm
on 2022/3/29 21:08, Matthew Wilcox wrote:
> On Tue, Mar 29, 2022 at 09:09:28PM +0800, Chen Wandun wrote:
>> +#define page_nth(head, tail) (page_to_pfn(tail) - page_to_pfn(head))
> Could we avoid reintroducing page_nth()? It is a terrible name.
how about compound_index ?
>> @@ -1213,7 +1213,7 @@ static int free_tail_pages_check(struct page *head_page, struct page *page)
>> ret = 0;
>> goto out;
>> }
>> - switch (page - head_page) {
>> + switch (page_nth(head_page, page)) {
>> case 1:
>> /* the first tail page: ->mapping may be compound_mapcount() */
>> if (unlikely(compound_mapcount(page))) {
> This is the only place you use it. I'd suggest free_tail_pages_check()
> should take 'i' as its second parameter instead of 'page + i', then
> there's no need to convert back to i.
OK, I will send v2, but I'm not sure whether similar function like
page_nth is needed elsewhere
>
> .
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-03-29 13:27 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-29 13:09 [PATCH 0/2] fix several contiguous memmap assumptions Chen Wandun
2022-03-29 13:09 ` [PATCH 1/2] mm: fix contiguous memmap assumptions about split page Chen Wandun
2022-03-29 13:09 ` [PATCH 2/2] mm: fix contiguous memmap assumptions about alloc/free pages Chen Wandun
2022-03-29 13:08 ` Matthew Wilcox
2022-03-29 13:27 ` Chen Wandun
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.