* [PATCH mm-unstable 0/8] convert hugepage memory failure functions to folios
@ 2023-01-12 20:46 Sidhartha Kumar
2023-01-12 20:46 ` [PATCH mm-unstable 1/8] mm/memory-failure: convert __get_huge_page_for_hwpoison() " Sidhartha Kumar
` (8 more replies)
0 siblings, 9 replies; 12+ messages in thread
From: Sidhartha Kumar @ 2023-01-12 20:46 UTC (permalink / raw)
To: linux-kernel, linux-mm
Cc: akpm, linmiaohe, naoya.horiguchi, willy, Sidhartha Kumar
============== OVERVIEW ===========================
This series contains a 1:1 straightforward page to folio conversion for
memory failure functions which deal with huge pages. I renamed a few
functions to fit with how other folio operating functions are named.
These include:
hugetlb_clear_page_hwpoison -> folio_clear_hugetlb_hwpoison
free_raw_hwp_pages -> folio_free_raw_hwp
__free_raw_hwp_pages -> __folio_free_raw_hwp
hugetlb_set_page_hwpoison -> folio_set_hugetlb_hwpoison
The goal of this series was to reduce users of the hugetlb specific
page flag macros which take in a page so users are protected by
the compiler to make sure they are operating on a head page.
Sidhartha Kumar (8):
mm/memory-failure: convert __get_huge_page_for_hwpoison() to folios
mm/memory-failure: convert try_memory_failure_hugetlb() to folios
mm/memory-failure: convert hugetlb_clear_page_hwpoison to folios
mm/memory-failure: convert free_raw_hwp_pages() to folios
mm/memory-failure: convert raw_hwp_list_head() to folios
mm/memory-failure: convert __free_raw_hwp_pages() to folios
mm/memory-failure: convert hugetlb_set_page_hwpoison() to folios
mm/memory-failure: convert unpoison_memory() to folios
include/linux/hugetlb.h | 4 +-
mm/hugetlb.c | 2 +-
mm/memory-failure.c | 116 ++++++++++++++++++++--------------------
3 files changed, 61 insertions(+), 61 deletions(-)
--
2.39.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH mm-unstable 1/8] mm/memory-failure: convert __get_huge_page_for_hwpoison() to folios
2023-01-12 20:46 [PATCH mm-unstable 0/8] convert hugepage memory failure functions to folios Sidhartha Kumar
@ 2023-01-12 20:46 ` Sidhartha Kumar
2023-01-12 20:46 ` [PATCH mm-unstable 2/8] mm/memory-failure: convert try_memory_failure_hugetlb() " Sidhartha Kumar
` (7 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Sidhartha Kumar @ 2023-01-12 20:46 UTC (permalink / raw)
To: linux-kernel, linux-mm
Cc: akpm, linmiaohe, naoya.horiguchi, willy, Sidhartha Kumar
Use a folio throughout the function rather than using a head page. This
also reduces the users of the page version of hugetlb specific page flags.
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
mm/memory-failure.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 9a80d7830b40..ee7e79ec6eaf 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1807,20 +1807,20 @@ int __get_huge_page_for_hwpoison(unsigned long pfn, int flags,
bool *migratable_cleared)
{
struct page *page = pfn_to_page(pfn);
- struct page *head = compound_head(page);
+ struct folio *folio = page_folio(page);
int ret = 2; /* fallback to normal page handling */
bool count_increased = false;
- if (!PageHeadHuge(head))
+ if (!folio_test_hugetlb(folio))
goto out;
if (flags & MF_COUNT_INCREASED) {
ret = 1;
count_increased = true;
- } else if (HPageFreed(head)) {
+ } else if (folio_test_hugetlb_freed(folio)) {
ret = 0;
- } else if (HPageMigratable(head)) {
- ret = get_page_unless_zero(head);
+ } else if (folio_test_hugetlb_migratable(folio)) {
+ ret = folio_try_get(folio);
if (ret)
count_increased = true;
} else {
@@ -1829,24 +1829,24 @@ int __get_huge_page_for_hwpoison(unsigned long pfn, int flags,
goto out;
}
- if (hugetlb_set_page_hwpoison(head, page)) {
+ if (hugetlb_set_page_hwpoison(&folio->page, page)) {
ret = -EHWPOISON;
goto out;
}
/*
- * Clearing HPageMigratable for hwpoisoned hugepages to prevent them
+ * Clearing hugetlb_migratable for hwpoisoned hugepages to prevent them
* from being migrated by memory hotremove.
*/
- if (count_increased && HPageMigratable(head)) {
- ClearHPageMigratable(head);
+ if (count_increased && folio_test_hugetlb_migratable(folio)) {
+ folio_clear_hugetlb_migratable(folio);
*migratable_cleared = true;
}
return ret;
out:
if (count_increased)
- put_page(head);
+ folio_put(folio);
return ret;
}
--
2.39.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH mm-unstable 2/8] mm/memory-failure: convert try_memory_failure_hugetlb() to folios
2023-01-12 20:46 [PATCH mm-unstable 0/8] convert hugepage memory failure functions to folios Sidhartha Kumar
2023-01-12 20:46 ` [PATCH mm-unstable 1/8] mm/memory-failure: convert __get_huge_page_for_hwpoison() " Sidhartha Kumar
@ 2023-01-12 20:46 ` Sidhartha Kumar
2023-01-12 20:46 ` [PATCH mm-unstable 3/8] mm/memory-failure: convert hugetlb_clear_page_hwpoison " Sidhartha Kumar
` (6 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Sidhartha Kumar @ 2023-01-12 20:46 UTC (permalink / raw)
To: linux-kernel, linux-mm
Cc: akpm, linmiaohe, naoya.horiguchi, willy, Sidhartha Kumar
Use a struct folio rather than a head page in try_memory_failure_hugetlb.
This converts one user of SetHPageMigratable to the folio equivalent.
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
mm/memory-failure.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index ee7e79ec6eaf..ca84b27489d0 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1860,7 +1860,7 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb
{
int res;
struct page *p = pfn_to_page(pfn);
- struct page *head;
+ struct folio *folio;
unsigned long page_flags;
bool migratable_cleared = false;
@@ -1873,8 +1873,8 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb
} else if (res == -EHWPOISON) {
pr_err("%#lx: already hardware poisoned\n", pfn);
if (flags & MF_ACTION_REQUIRED) {
- head = compound_head(p);
- res = kill_accessing_process(current, page_to_pfn(head), flags);
+ folio = page_folio(p);
+ res = kill_accessing_process(current, folio_pfn(folio), flags);
}
return res;
} else if (res == -EBUSY) {
@@ -1885,16 +1885,16 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb
return action_result(pfn, MF_MSG_UNKNOWN, MF_IGNORED);
}
- head = compound_head(p);
- lock_page(head);
+ folio = page_folio(p);
+ folio_lock(folio);
if (hwpoison_filter(p)) {
- hugetlb_clear_page_hwpoison(head);
+ hugetlb_clear_page_hwpoison(&folio->page);
if (migratable_cleared)
- SetHPageMigratable(head);
- unlock_page(head);
+ folio_set_hugetlb_migratable(folio);
+ folio_unlock(folio);
if (res == 1)
- put_page(head);
+ folio_put(folio);
return -EOPNOTSUPP;
}
@@ -1903,7 +1903,7 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb
* or demotion can be prevented by PageHWPoison flag.
*/
if (res == 0) {
- unlock_page(head);
+ folio_unlock(folio);
if (__page_handle_poison(p) >= 0) {
page_ref_inc(p);
res = MF_RECOVERED;
@@ -1913,10 +1913,10 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb
return action_result(pfn, MF_MSG_FREE_HUGE, res);
}
- page_flags = head->flags;
+ page_flags = folio->flags;
- if (!hwpoison_user_mappings(p, pfn, flags, head)) {
- unlock_page(head);
+ if (!hwpoison_user_mappings(p, pfn, flags, &folio->page)) {
+ folio_unlock(folio);
return action_result(pfn, MF_MSG_UNMAP_FAILED, MF_IGNORED);
}
--
2.39.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH mm-unstable 3/8] mm/memory-failure: convert hugetlb_clear_page_hwpoison to folios
2023-01-12 20:46 [PATCH mm-unstable 0/8] convert hugepage memory failure functions to folios Sidhartha Kumar
2023-01-12 20:46 ` [PATCH mm-unstable 1/8] mm/memory-failure: convert __get_huge_page_for_hwpoison() " Sidhartha Kumar
2023-01-12 20:46 ` [PATCH mm-unstable 2/8] mm/memory-failure: convert try_memory_failure_hugetlb() " Sidhartha Kumar
@ 2023-01-12 20:46 ` Sidhartha Kumar
2023-01-12 20:46 ` [PATCH mm-unstable 4/8] mm/memory-failure: convert free_raw_hwp_pages() " Sidhartha Kumar
` (5 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Sidhartha Kumar @ 2023-01-12 20:46 UTC (permalink / raw)
To: linux-kernel, linux-mm
Cc: akpm, linmiaohe, naoya.horiguchi, willy, Sidhartha Kumar
Change hugetlb_clear_page_hwpoison() to folio_clear_hugetlb_hwpoison() by
changing the function to take in a folio. This converts one use of
ClearPageHWPoison and HPageRawHwpUnreliable to their folio equivalents.
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
include/linux/hugetlb.h | 4 ++--
mm/hugetlb.c | 2 +-
mm/memory-failure.c | 10 +++++-----
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index befe64cb40d1..c33e36f5a1dd 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -823,9 +823,9 @@ extern int dissolve_free_huge_pages(unsigned long start_pfn,
unsigned long end_pfn);
#ifdef CONFIG_MEMORY_FAILURE
-extern void hugetlb_clear_page_hwpoison(struct page *hpage);
+extern void folio_clear_hugetlb_hwpoison(struct folio *folio);
#else
-static inline void hugetlb_clear_page_hwpoison(struct page *hpage)
+static inline void folio_clear_hugetlb_hwpoison(struct folio *folio)
{
}
#endif
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index ae9c6ba07a8a..a5d410c16cbe 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1592,7 +1592,7 @@ static void __update_and_free_hugetlb_folio(struct hstate *h,
* which makes any healthy subpages reusable.
*/
if (unlikely(folio_test_hwpoison(folio)))
- hugetlb_clear_page_hwpoison(&folio->page);
+ folio_clear_hugetlb_hwpoison(folio);
for (i = 0; i < pages_per_huge_page(h); i++) {
subpage = folio_page(folio, i);
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index ca84b27489d0..205272c64f37 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1785,12 +1785,12 @@ static unsigned long free_raw_hwp_pages(struct page *hpage, bool move_flag)
return __free_raw_hwp_pages(hpage, move_flag);
}
-void hugetlb_clear_page_hwpoison(struct page *hpage)
+void folio_clear_hugetlb_hwpoison(struct folio *folio)
{
- if (HPageRawHwpUnreliable(hpage))
+ if (folio_test_hugetlb_raw_hwp_unreliable(folio))
return;
- ClearPageHWPoison(hpage);
- free_raw_hwp_pages(hpage, true);
+ folio_clear_hwpoison(folio);
+ free_raw_hwp_pages(&folio->page, true);
}
/*
@@ -1889,7 +1889,7 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb
folio_lock(folio);
if (hwpoison_filter(p)) {
- hugetlb_clear_page_hwpoison(&folio->page);
+ folio_clear_hugetlb_hwpoison(folio);
if (migratable_cleared)
folio_set_hugetlb_migratable(folio);
folio_unlock(folio);
--
2.39.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH mm-unstable 4/8] mm/memory-failure: convert free_raw_hwp_pages() to folios
2023-01-12 20:46 [PATCH mm-unstable 0/8] convert hugepage memory failure functions to folios Sidhartha Kumar
` (2 preceding siblings ...)
2023-01-12 20:46 ` [PATCH mm-unstable 3/8] mm/memory-failure: convert hugetlb_clear_page_hwpoison " Sidhartha Kumar
@ 2023-01-12 20:46 ` Sidhartha Kumar
2023-01-12 20:46 ` [PATCH mm-unstable 5/8] mm/memory-failure: convert raw_hwp_list_head() " Sidhartha Kumar
` (4 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Sidhartha Kumar @ 2023-01-12 20:46 UTC (permalink / raw)
To: linux-kernel, linux-mm
Cc: akpm, linmiaohe, naoya.horiguchi, willy, Sidhartha Kumar
Change free_raw_hwp_pages() to folio_free_raw_hwp(), converts two users
of hugetlb specific page macro users to their folio equivalents.
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
mm/memory-failure.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 205272c64f37..d5c828328e32 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1766,23 +1766,23 @@ static int hugetlb_set_page_hwpoison(struct page *hpage, struct page *page)
return ret;
}
-static unsigned long free_raw_hwp_pages(struct page *hpage, bool move_flag)
+static unsigned long folio_free_raw_hwp(struct folio *folio, bool move_flag)
{
/*
- * HPageVmemmapOptimized hugepages can't be freed because struct
+ * hugetlb_vmemmap_optimized hugepages can't be freed because struct
* pages for tail pages are required but they don't exist.
*/
- if (move_flag && HPageVmemmapOptimized(hpage))
+ if (move_flag && folio_test_hugetlb_vmemmap_optimized(folio))
return 0;
/*
- * HPageRawHwpUnreliable hugepages shouldn't be unpoisoned by
+ * hugetlb_raw_hwp_unreliable hugepages shouldn't be unpoisoned by
* definition.
*/
- if (HPageRawHwpUnreliable(hpage))
+ if (folio_test_hugetlb_raw_hwp_unreliable(folio))
return 0;
- return __free_raw_hwp_pages(hpage, move_flag);
+ return __free_raw_hwp_pages(&folio->page, move_flag);
}
void folio_clear_hugetlb_hwpoison(struct folio *folio)
@@ -1790,7 +1790,7 @@ void folio_clear_hugetlb_hwpoison(struct folio *folio)
if (folio_test_hugetlb_raw_hwp_unreliable(folio))
return;
folio_clear_hwpoison(folio);
- free_raw_hwp_pages(&folio->page, true);
+ folio_free_raw_hwp(folio, true);
}
/*
@@ -1929,7 +1929,7 @@ static inline int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *
return 0;
}
-static inline unsigned long free_raw_hwp_pages(struct page *hpage, bool flag)
+static inline unsigned long folio_free_raw_hwp(struct folio *folio, bool flag)
{
return 0;
}
@@ -2336,6 +2336,7 @@ core_initcall(memory_failure_init);
int unpoison_memory(unsigned long pfn)
{
struct page *page;
+ struct folio *folio;
struct page *p;
int ret = -EBUSY;
unsigned long count = 1;
@@ -2348,6 +2349,7 @@ int unpoison_memory(unsigned long pfn)
p = pfn_to_page(pfn);
page = compound_head(p);
+ folio = page_folio(p);
mutex_lock(&mf_mutex);
@@ -2389,7 +2391,7 @@ int unpoison_memory(unsigned long pfn)
if (!ret) {
if (PageHuge(p)) {
huge = true;
- count = free_raw_hwp_pages(page, false);
+ count = folio_free_raw_hwp(folio, false);
if (count == 0) {
ret = -EBUSY;
goto unlock_mutex;
@@ -2405,7 +2407,7 @@ int unpoison_memory(unsigned long pfn)
} else {
if (PageHuge(p)) {
huge = true;
- count = free_raw_hwp_pages(page, false);
+ count = folio_free_raw_hwp(folio, false);
if (count == 0) {
ret = -EBUSY;
put_page(page);
--
2.39.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH mm-unstable 5/8] mm/memory-failure: convert raw_hwp_list_head() to folios
2023-01-12 20:46 [PATCH mm-unstable 0/8] convert hugepage memory failure functions to folios Sidhartha Kumar
` (3 preceding siblings ...)
2023-01-12 20:46 ` [PATCH mm-unstable 4/8] mm/memory-failure: convert free_raw_hwp_pages() " Sidhartha Kumar
@ 2023-01-12 20:46 ` Sidhartha Kumar
2023-01-12 20:46 ` [PATCH mm-unstable 6/8] mm/memory-failure: convert __free_raw_hwp_pages() " Sidhartha Kumar
` (3 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Sidhartha Kumar @ 2023-01-12 20:46 UTC (permalink / raw)
To: linux-kernel, linux-mm
Cc: akpm, linmiaohe, naoya.horiguchi, willy, Sidhartha Kumar
Change raw_hwp_list_head() to take in a folio and modify its callers to
pass in a folio. Also converts two users of hugetlb specific page macro
users to their folio equivalents.
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
mm/memory-failure.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index d5c828328e32..55f34be8ea39 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1695,9 +1695,9 @@ struct raw_hwp_page {
struct page *page;
};
-static inline struct llist_head *raw_hwp_list_head(struct page *hpage)
+static inline struct llist_head *raw_hwp_list_head(struct folio *folio)
{
- return (struct llist_head *)&page_folio(hpage)->_hugetlb_hwpoison;
+ return (struct llist_head *)&folio->_hugetlb_hwpoison;
}
static unsigned long __free_raw_hwp_pages(struct page *hpage, bool move_flag)
@@ -1705,8 +1705,9 @@ static unsigned long __free_raw_hwp_pages(struct page *hpage, bool move_flag)
struct llist_head *head;
struct llist_node *t, *tnode;
unsigned long count = 0;
+ struct folio *folio = page_folio(hpage);
- head = raw_hwp_list_head(hpage);
+ head = raw_hwp_list_head(folio);
llist_for_each_safe(tnode, t, head->first) {
struct raw_hwp_page *p = container_of(tnode, struct raw_hwp_page, node);
@@ -1727,15 +1728,16 @@ static int hugetlb_set_page_hwpoison(struct page *hpage, struct page *page)
struct raw_hwp_page *raw_hwp;
struct llist_node *t, *tnode;
int ret = TestSetPageHWPoison(hpage) ? -EHWPOISON : 0;
+ struct folio *folio = page_folio(hpage);
/*
* Once the hwpoison hugepage has lost reliable raw error info,
* there is little meaning to keep additional error info precisely,
* so skip to add additional raw error info.
*/
- if (HPageRawHwpUnreliable(hpage))
+ if (folio_test_hugetlb_raw_hwp_unreliable(folio))
return -EHWPOISON;
- head = raw_hwp_list_head(hpage);
+ head = raw_hwp_list_head(folio);
llist_for_each_safe(tnode, t, head->first) {
struct raw_hwp_page *p = container_of(tnode, struct raw_hwp_page, node);
@@ -1756,9 +1758,9 @@ static int hugetlb_set_page_hwpoison(struct page *hpage, struct page *page)
* hwpoisoned subpages, and we need refuse to free/dissolve
* this hwpoisoned hugepage.
*/
- SetHPageRawHwpUnreliable(hpage);
+ folio_set_hugetlb_raw_hwp_unreliable(folio);
/*
- * Once HPageRawHwpUnreliable is set, raw_hwp_page is not
+ * Once hugetlb_raw_hwp_unreliable is set, raw_hwp_page is not
* used any more, so free it.
*/
__free_raw_hwp_pages(hpage, false);
--
2.39.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH mm-unstable 6/8] mm/memory-failure: convert __free_raw_hwp_pages() to folios
2023-01-12 20:46 [PATCH mm-unstable 0/8] convert hugepage memory failure functions to folios Sidhartha Kumar
` (4 preceding siblings ...)
2023-01-12 20:46 ` [PATCH mm-unstable 5/8] mm/memory-failure: convert raw_hwp_list_head() " Sidhartha Kumar
@ 2023-01-12 20:46 ` Sidhartha Kumar
2023-01-12 20:46 ` [PATCH mm-unstable 7/8] mm/memory-failure: convert hugetlb_set_page_hwpoison() " Sidhartha Kumar
` (2 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Sidhartha Kumar @ 2023-01-12 20:46 UTC (permalink / raw)
To: linux-kernel, linux-mm
Cc: akpm, linmiaohe, naoya.horiguchi, willy, Sidhartha Kumar
Change __free_raw_hwp_pages() to __folio_free_raw_hwp() and modify its
callers to pass in a folio.
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
mm/memory-failure.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 55f34be8ea39..3fff073da89b 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1700,12 +1700,11 @@ static inline struct llist_head *raw_hwp_list_head(struct folio *folio)
return (struct llist_head *)&folio->_hugetlb_hwpoison;
}
-static unsigned long __free_raw_hwp_pages(struct page *hpage, bool move_flag)
+static unsigned long __folio_free_raw_hwp(struct folio *folio, bool move_flag)
{
struct llist_head *head;
struct llist_node *t, *tnode;
unsigned long count = 0;
- struct folio *folio = page_folio(hpage);
head = raw_hwp_list_head(folio);
llist_for_each_safe(tnode, t, head->first) {
@@ -1763,7 +1762,7 @@ static int hugetlb_set_page_hwpoison(struct page *hpage, struct page *page)
* Once hugetlb_raw_hwp_unreliable is set, raw_hwp_page is not
* used any more, so free it.
*/
- __free_raw_hwp_pages(hpage, false);
+ __folio_free_raw_hwp(folio, false);
}
return ret;
}
@@ -1784,7 +1783,7 @@ static unsigned long folio_free_raw_hwp(struct folio *folio, bool move_flag)
if (folio_test_hugetlb_raw_hwp_unreliable(folio))
return 0;
- return __free_raw_hwp_pages(&folio->page, move_flag);
+ return __folio_free_raw_hwp(folio, move_flag);
}
void folio_clear_hugetlb_hwpoison(struct folio *folio)
--
2.39.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH mm-unstable 7/8] mm/memory-failure: convert hugetlb_set_page_hwpoison() to folios
2023-01-12 20:46 [PATCH mm-unstable 0/8] convert hugepage memory failure functions to folios Sidhartha Kumar
` (5 preceding siblings ...)
2023-01-12 20:46 ` [PATCH mm-unstable 6/8] mm/memory-failure: convert __free_raw_hwp_pages() " Sidhartha Kumar
@ 2023-01-12 20:46 ` Sidhartha Kumar
2023-01-12 20:46 ` [PATCH mm-unstable 8/8] mm/memory-failure: convert unpoison_memory() " Sidhartha Kumar
2023-01-13 7:03 ` [PATCH mm-unstable 0/8] convert hugepage memory failure functions " HORIGUCHI NAOYA(堀口 直也)
8 siblings, 0 replies; 12+ messages in thread
From: Sidhartha Kumar @ 2023-01-12 20:46 UTC (permalink / raw)
To: linux-kernel, linux-mm
Cc: akpm, linmiaohe, naoya.horiguchi, willy, Sidhartha Kumar
Change hugetlb_set_page_hwpoison() to folio_set_hugetlb_hwpoison() and use
a folio internally.
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
mm/memory-failure.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 3fff073da89b..fb98652b211a 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1721,13 +1721,12 @@ static unsigned long __folio_free_raw_hwp(struct folio *folio, bool move_flag)
return count;
}
-static int hugetlb_set_page_hwpoison(struct page *hpage, struct page *page)
+static int folio_set_hugetlb_hwpoison(struct folio *folio, struct page *page)
{
struct llist_head *head;
struct raw_hwp_page *raw_hwp;
struct llist_node *t, *tnode;
- int ret = TestSetPageHWPoison(hpage) ? -EHWPOISON : 0;
- struct folio *folio = page_folio(hpage);
+ int ret = folio_test_set_hwpoison(folio) ? -EHWPOISON : 0;
/*
* Once the hwpoison hugepage has lost reliable raw error info,
@@ -1830,7 +1829,7 @@ int __get_huge_page_for_hwpoison(unsigned long pfn, int flags,
goto out;
}
- if (hugetlb_set_page_hwpoison(&folio->page, page)) {
+ if (folio_set_hugetlb_hwpoison(folio, page)) {
ret = -EHWPOISON;
goto out;
}
--
2.39.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH mm-unstable 8/8] mm/memory-failure: convert unpoison_memory() to folios
2023-01-12 20:46 [PATCH mm-unstable 0/8] convert hugepage memory failure functions to folios Sidhartha Kumar
` (6 preceding siblings ...)
2023-01-12 20:46 ` [PATCH mm-unstable 7/8] mm/memory-failure: convert hugetlb_set_page_hwpoison() " Sidhartha Kumar
@ 2023-01-12 20:46 ` Sidhartha Kumar
2023-07-15 4:07 ` Matthew Wilcox
2023-01-13 7:03 ` [PATCH mm-unstable 0/8] convert hugepage memory failure functions " HORIGUCHI NAOYA(堀口 直也)
8 siblings, 1 reply; 12+ messages in thread
From: Sidhartha Kumar @ 2023-01-12 20:46 UTC (permalink / raw)
To: linux-kernel, linux-mm
Cc: akpm, linmiaohe, naoya.horiguchi, willy, Sidhartha Kumar
Use a folio inside unpoison_memory which replaces a compound_head() call
with a call to page_folio().
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
mm/memory-failure.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index fb98652b211a..c53588ea5993 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -2335,7 +2335,6 @@ core_initcall(memory_failure_init);
*/
int unpoison_memory(unsigned long pfn)
{
- struct page *page;
struct folio *folio;
struct page *p;
int ret = -EBUSY;
@@ -2348,7 +2347,6 @@ int unpoison_memory(unsigned long pfn)
return -ENXIO;
p = pfn_to_page(pfn);
- page = compound_head(p);
folio = page_folio(p);
mutex_lock(&mf_mutex);
@@ -2360,31 +2358,31 @@ int unpoison_memory(unsigned long pfn)
goto unlock_mutex;
}
- if (!PageHWPoison(p)) {
+ if (!folio_test_hwpoison(folio)) {
unpoison_pr_info("Unpoison: Page was already unpoisoned %#lx\n",
pfn, &unpoison_rs);
goto unlock_mutex;
}
- if (page_count(page) > 1) {
+ if (folio_ref_count(folio) > 1) {
unpoison_pr_info("Unpoison: Someone grabs the hwpoison page %#lx\n",
pfn, &unpoison_rs);
goto unlock_mutex;
}
- if (page_mapped(page)) {
+ if (folio_mapped(folio)) {
unpoison_pr_info("Unpoison: Someone maps the hwpoison page %#lx\n",
pfn, &unpoison_rs);
goto unlock_mutex;
}
- if (page_mapping(page)) {
+ if (folio_mapping(folio)) {
unpoison_pr_info("Unpoison: the hwpoison page has non-NULL mapping %#lx\n",
pfn, &unpoison_rs);
goto unlock_mutex;
}
- if (PageSlab(page) || PageTable(page) || PageReserved(page))
+ if (folio_test_slab(folio) || PageTable(&folio->page) || folio_test_reserved(folio))
goto unlock_mutex;
ret = get_hwpoison_page(p, MF_UNPOISON);
@@ -2397,7 +2395,7 @@ int unpoison_memory(unsigned long pfn)
goto unlock_mutex;
}
}
- ret = TestClearPageHWPoison(page) ? 0 : -EBUSY;
+ ret = folio_test_clear_hwpoison(folio) ? 0 : -EBUSY;
} else if (ret < 0) {
if (ret == -EHWPOISON) {
ret = put_page_back_buddy(p) ? 0 : -EBUSY;
@@ -2410,14 +2408,14 @@ int unpoison_memory(unsigned long pfn)
count = folio_free_raw_hwp(folio, false);
if (count == 0) {
ret = -EBUSY;
- put_page(page);
+ folio_put(folio);
goto unlock_mutex;
}
}
- put_page(page);
+ folio_put(folio);
if (TestClearPageHWPoison(p)) {
- put_page(page);
+ folio_put(folio);
ret = 0;
}
}
--
2.39.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH mm-unstable 0/8] convert hugepage memory failure functions to folios
2023-01-12 20:46 [PATCH mm-unstable 0/8] convert hugepage memory failure functions to folios Sidhartha Kumar
` (7 preceding siblings ...)
2023-01-12 20:46 ` [PATCH mm-unstable 8/8] mm/memory-failure: convert unpoison_memory() " Sidhartha Kumar
@ 2023-01-13 7:03 ` HORIGUCHI NAOYA(堀口 直也)
2023-01-13 16:06 ` Sidhartha Kumar
8 siblings, 1 reply; 12+ messages in thread
From: HORIGUCHI NAOYA(堀口 直也) @ 2023-01-13 7:03 UTC (permalink / raw)
To: Sidhartha Kumar; +Cc: linux-kernel, linux-mm, akpm, linmiaohe, willy
On Thu, Jan 12, 2023 at 02:46:00PM -0600, Sidhartha Kumar wrote:
> ============== OVERVIEW ===========================
> This series contains a 1:1 straightforward page to folio conversion for
> memory failure functions which deal with huge pages. I renamed a few
> functions to fit with how other folio operating functions are named.
> These include:
>
> hugetlb_clear_page_hwpoison -> folio_clear_hugetlb_hwpoison
> free_raw_hwp_pages -> folio_free_raw_hwp
> __free_raw_hwp_pages -> __folio_free_raw_hwp
> hugetlb_set_page_hwpoison -> folio_set_hugetlb_hwpoison
>
> The goal of this series was to reduce users of the hugetlb specific
> page flag macros which take in a page so users are protected by
> the compiler to make sure they are operating on a head page.
>
> Sidhartha Kumar (8):
> mm/memory-failure: convert __get_huge_page_for_hwpoison() to folios
> mm/memory-failure: convert try_memory_failure_hugetlb() to folios
> mm/memory-failure: convert hugetlb_clear_page_hwpoison to folios
> mm/memory-failure: convert free_raw_hwp_pages() to folios
> mm/memory-failure: convert raw_hwp_list_head() to folios
> mm/memory-failure: convert __free_raw_hwp_pages() to folios
> mm/memory-failure: convert hugetlb_set_page_hwpoison() to folios
> mm/memory-failure: convert unpoison_memory() to folios
Hi Sidhartha,
I looked through the patchset and all look fine to me. And I tested the
patchset with v6.2-rc3 and no new issue is detected (I failed to boot with
latest mm-unstable, but maybe that should not be caused by your patches).
Thank you very much,
Acked-by: Naoya Horiguchi <naoya.horiguchi@nec.com>
for the whole series.
- Naoya Horiguchi
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH mm-unstable 0/8] convert hugepage memory failure functions to folios
2023-01-13 7:03 ` [PATCH mm-unstable 0/8] convert hugepage memory failure functions " HORIGUCHI NAOYA(堀口 直也)
@ 2023-01-13 16:06 ` Sidhartha Kumar
0 siblings, 0 replies; 12+ messages in thread
From: Sidhartha Kumar @ 2023-01-13 16:06 UTC (permalink / raw)
To: HORIGUCHI NAOYA(堀口 直也)
Cc: linux-kernel, linux-mm, akpm, linmiaohe, willy
On 1/13/23 1:03 AM, HORIGUCHI NAOYA(堀口 直也) wrote:
> On Thu, Jan 12, 2023 at 02:46:00PM -0600, Sidhartha Kumar wrote:
>> ============== OVERVIEW ===========================
>> This series contains a 1:1 straightforward page to folio conversion for
>> memory failure functions which deal with huge pages. I renamed a few
>> functions to fit with how other folio operating functions are named.
>> These include:
>>
>> hugetlb_clear_page_hwpoison -> folio_clear_hugetlb_hwpoison
>> free_raw_hwp_pages -> folio_free_raw_hwp
>> __free_raw_hwp_pages -> __folio_free_raw_hwp
>> hugetlb_set_page_hwpoison -> folio_set_hugetlb_hwpoison
>>
>> The goal of this series was to reduce users of the hugetlb specific
>> page flag macros which take in a page so users are protected by
>> the compiler to make sure they are operating on a head page.
>>
>> Sidhartha Kumar (8):
>> mm/memory-failure: convert __get_huge_page_for_hwpoison() to folios
>> mm/memory-failure: convert try_memory_failure_hugetlb() to folios
>> mm/memory-failure: convert hugetlb_clear_page_hwpoison to folios
>> mm/memory-failure: convert free_raw_hwp_pages() to folios
>> mm/memory-failure: convert raw_hwp_list_head() to folios
>> mm/memory-failure: convert __free_raw_hwp_pages() to folios
>> mm/memory-failure: convert hugetlb_set_page_hwpoison() to folios
>> mm/memory-failure: convert unpoison_memory() to folios
>
> Hi Sidhartha,
>
> I looked through the patchset and all look fine to me. And I tested the
> patchset with v6.2-rc3 and no new issue is detected (I failed to boot with
> latest mm-unstable, but maybe that should not be caused by your patches).
Thanks for your review and testing.
It looks like the boot failure has been described here:
https://lore.kernel.org/linux-mm/Y8FnAwWOxLrfoWTN@casper.infradead.org/T/#u
and is not caused by this patch series.
Thanks,
Sidhartha Kumar
>
> Thank you very much,
>
> Acked-by: Naoya Horiguchi <naoya.horiguchi@nec.com>
>
> for the whole series.
>
> - Naoya Horiguchi
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH mm-unstable 8/8] mm/memory-failure: convert unpoison_memory() to folios
2023-01-12 20:46 ` [PATCH mm-unstable 8/8] mm/memory-failure: convert unpoison_memory() " Sidhartha Kumar
@ 2023-07-15 4:07 ` Matthew Wilcox
0 siblings, 0 replies; 12+ messages in thread
From: Matthew Wilcox @ 2023-07-15 4:07 UTC (permalink / raw)
To: Sidhartha Kumar; +Cc: linux-kernel, linux-mm, akpm, linmiaohe, naoya.horiguchi
On Thu, Jan 12, 2023 at 02:46:08PM -0600, Sidhartha Kumar wrote:
> @@ -2348,7 +2347,6 @@ int unpoison_memory(unsigned long pfn)
> return -ENXIO;
>
> p = pfn_to_page(pfn);
> - page = compound_head(p);
> folio = page_folio(p);
>
> mutex_lock(&mf_mutex);
> @@ -2360,31 +2358,31 @@ int unpoison_memory(unsigned long pfn)
> goto unlock_mutex;
> }
>
> - if (!PageHWPoison(p)) {
> + if (!folio_test_hwpoison(folio)) {
This is wrong. You need to test the individual page for PageHWPoison()
instead of testing the folio. I understand that this will work for
hugetlbfs pages, but for THP, it's the individual pages that get poisoned,
and folio_test_hwpoison() on a THP actually only tests the head page.
Ideas for preventing this mistake in the future gratefully received.
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2023-07-15 4:07 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-12 20:46 [PATCH mm-unstable 0/8] convert hugepage memory failure functions to folios Sidhartha Kumar
2023-01-12 20:46 ` [PATCH mm-unstable 1/8] mm/memory-failure: convert __get_huge_page_for_hwpoison() " Sidhartha Kumar
2023-01-12 20:46 ` [PATCH mm-unstable 2/8] mm/memory-failure: convert try_memory_failure_hugetlb() " Sidhartha Kumar
2023-01-12 20:46 ` [PATCH mm-unstable 3/8] mm/memory-failure: convert hugetlb_clear_page_hwpoison " Sidhartha Kumar
2023-01-12 20:46 ` [PATCH mm-unstable 4/8] mm/memory-failure: convert free_raw_hwp_pages() " Sidhartha Kumar
2023-01-12 20:46 ` [PATCH mm-unstable 5/8] mm/memory-failure: convert raw_hwp_list_head() " Sidhartha Kumar
2023-01-12 20:46 ` [PATCH mm-unstable 6/8] mm/memory-failure: convert __free_raw_hwp_pages() " Sidhartha Kumar
2023-01-12 20:46 ` [PATCH mm-unstable 7/8] mm/memory-failure: convert hugetlb_set_page_hwpoison() " Sidhartha Kumar
2023-01-12 20:46 ` [PATCH mm-unstable 8/8] mm/memory-failure: convert unpoison_memory() " Sidhartha Kumar
2023-07-15 4:07 ` Matthew Wilcox
2023-01-13 7:03 ` [PATCH mm-unstable 0/8] convert hugepage memory failure functions " HORIGUCHI NAOYA(堀口 直也)
2023-01-13 16:06 ` Sidhartha Kumar
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).