mm/memory_failure: use bool for hugetlb indicator in try_memory_failure_hugetlb
Subsystems (2)
PATCH RESEND 1/1 mm/memory_failure: use bool for hugetlb indicator in try_memory_failure_hugetlb
From: Ye Liu <[email protected]>
The hugetlb indicator in try_memory_failure_hugetlb is a Boolean flag, but was declared and assigned as int/0/1. Convert to bool and true/false for clarity and type safety.
- try_memory_failure_hugetlb(unsigned long pfn, int flags, bool *hugetlb)
- testcase path in memory_failure(): bool hugetlb = false
- clear semantic conversion in MF_HUGETLB_NON_HUGEPAGE
- preserve behavior (no functional change)
--- mm/memory-failure.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
mm/memory-failure.c +5 -5
@@ -2032,7 +2032,7 @@ int __get_huge_page_for_hwpoison(unsigned long pfn, int flags,* -EHWPOISON - folio or exact page already poisoned * -EFAULT - kill_accessing_process finds current->mm null */ -static int try_memory_failure_hugetlb (unsigned long pfn,int flags,int *hugetlb) +static int try_memory_failure_hugetlb (unsigned long pfn,int flags,bool *hugetlb) {int res, rv;struct page *p =pfn_to_page (pfn);
@@ -2040,12 +2040,12 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlbunsigned long page_flags;bool migratable_cleared = false; - *hugetlb =1 ; + *hugetlb = true; retry: res =get_huge_page_for_hwpoison (pfn, flags, &migratable_cleared);switch (res) {case MF_HUGETLB_NON_HUGEPAGE :/* fallback to normal page handling */ - *hugetlb =0 ; + *hugetlb = false;return 0 ;case MF_HUGETLB_RETRY :if (!(flags &MF_NO_RETRY )) {
@@ -2107,7 +2107,7 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb }#else -static inline int try_memory_failure_hugetlb (unsigned long pfn,int flags,int *hugetlb) +static inline int try_memory_failure_hugetlb (unsigned long pfn,int flags,bool *hugetlb) {return 0 ; }
@@ -2347,7 +2347,7 @@ int memory_failure(unsigned long pfn, int flags)int res =0 ;unsigned long page_flags;bool retry = true; -int hugetlb =0 ; +bool hugetlb = false;if (!sysctl_memory_failure_recovery)panic ("Memory failure on page %lx" , pfn);
Signature · 1 line
2.43.0
Quoted 32 lines · Ye Liu
From: Ye Liu <[email protected]>
The hugetlb indicator in
try_memory_failure_hugetlbis a Boolean flag, but was declared and assigned as int/0/1. Convert toboolandtrue/falsefor clarity and type safety.-
try_memory_failure_hugetlb(unsigned long pfn, int flags, bool *hugetlb)
- testcase path inmemory_failure(): bool hugetlb = false
- clear semantic conversion inMF_HUGETLB_NON_HUGEPAGE
- preserve behavior (no functional change)Signed-off-by Ye Liu <[email protected]>Acked-by Miaohe Lin <[email protected]>--- mm/memory-failure.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)mm/memory-failure.c +1
-1@@ -2032,7 +2032,7 @@ int __get_huge_page_for_hwpoison(unsigned long pfn, int flags,* -EHWPOISON - folio or exact page already poisoned * -EFAULT - kill_accessing_process finds current->mm null */ -static int try_memory_failure_hugetlb (unsigned long pfn,int flags,int *hugetlb) +static int try_memory_failure_hugetlb (unsigned long pfn,int flags,bool *hugetlb) {int res, rv;struct page *p =pfn_to_page (pfn);@@ -2040,12 +2040,12 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlbunsigned long page_flags;
mm/memory-failure.c static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb · line 2048
Quoted 10 lines
mm/memory-failure.c +2
-2bool migratable_cleared = false; - *hugetlb =1 ; + *hugetlb = true; retry: res =get_huge_page_for_hwpoison (pfn, flags, &migratable_cleared);switch (res) {case MF_HUGETLB_NON_HUGEPAGE :/* fallback to normal page handling */ - *hugetlb =0 ; + *hugetlb = false;
Do we really need this boolean though?
Why do not simply return ENOENT when we find a non-hugetlb page, and then the caller knows that if we get ENOENT, it can proceed with normal page handling?
I might be missing something, but is not the following more cleaer?
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index ee42d4361309..44f388df5731 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -2026,13 +2026,14 @@ int __get_huge_page_for_hwpoison(unsigned long pfn, int flags,
* So some of prechecks for hwpoison (pinning, and testing/setting
* PageHWPoison) should be done in single hugetlb_lock range.
* Returns:
- * 0 - not hugetlb, or recovered
+ * 0 - recovered
+ * -ENOENT - no hugetlb page
* -EBUSY - not recovered
* -EOPNOTSUPP - hwpoison_filter'ed
* -EHWPOISON - folio or exact page already poisoned
* -EFAULT - kill_accessing_process finds current->mm null
*/
-static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb)
+static int try_memory_failure_hugetlb(unsigned long pfn, int flags)
{
int res, rv;
struct page *p = pfn_to_page(pfn);
@@ -2040,13 +2041,11 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb
unsigned long page_flags;
bool migratable_cleared = false; - *hugetlb = 1;
retry:
res = get_huge_page_for_hwpoison(pfn, flags, &migratable_cleared);
switch (res) {
case MF_HUGETLB_NON_HUGEPAGE: /* fallback to normal page handling */
- *hugetlb = 0;
- return 0;
+ return -ENOENT;
case MF_HUGETLB_RETRY:
if (!(flags & MF_NO_RETRY)) {
flags |= MF_NO_RETRY; @@ -2107,7 +2106,7 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb
}
#else
-static inline int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb) +static inline int try_memory_failure_hugetlb(unsigned long pfn, int flags)
{
return 0;
}
@@ -2386,8 +2385,11 @@ int memory_failure(unsigned long pfn, int flags)
} try_again:
- res = try_memory_failure_hugetlb(pfn, flags, &hugetlb);
- if (hugetlb)
+ res = try_memory_failure_hugetlb(pfn, flags);
+ /*
+ * -ENOENT means the page we found is not hugetlb, so proceed with normal page handling
+ */
+ if (res != -ENOENT)
goto unlock_mutex;
if (TestSetPageHWPoison(p)) {Signature · 2 lines
Oscar Salvador SUSE Labs
Quoted 99 lines · Oscar Salvador
Quoted 32 lines · Ye Liu
From: Ye Liu <[email protected]>
The hugetlb indicator in
try_memory_failure_hugetlbis a Boolean flag, but was declared and assigned as int/0/1. Convert toboolandtrue/falsefor clarity and type safety.-
try_memory_failure_hugetlb(unsigned long pfn, int flags, bool *hugetlb)
- testcase path inmemory_failure(): bool hugetlb = false
- clear semantic conversion inMF_HUGETLB_NON_HUGEPAGE
- preserve behavior (no functional change)Signed-off-by Ye Liu <[email protected]>Acked-by Miaohe Lin <[email protected]>--- mm/memory-failure.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)mm/memory-failure.c +1
-1@@ -2032,7 +2032,7 @@ int __get_huge_page_for_hwpoison(unsigned long pfn, int flags,* -EHWPOISON - folio or exact page already poisoned * -EFAULT - kill_accessing_process finds current->mm null */ -static int try_memory_failure_hugetlb (unsigned long pfn,int flags,int *hugetlb) +static int try_memory_failure_hugetlb (unsigned long pfn,int flags,bool *hugetlb) {int res, rv;struct page *p =pfn_to_page (pfn);@@ -2040,12 +2040,12 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlbunsigned long page_flags;mm/memory-failure.c static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb · line 2048
Quoted 10 lines
mm/memory-failure.c +2
-2bool migratable_cleared = false; - *hugetlb =1 ; + *hugetlb = true; retry: res =get_huge_page_for_hwpoison (pfn, flags, &migratable_cleared);switch (res) {case MF_HUGETLB_NON_HUGEPAGE :/* fallback to normal page handling */ - *hugetlb =0 ; + *hugetlb = false;Do we really need this boolean though?
Why do not simply return ENOENT when we find a non-hugetlb page, and then the caller knows that if we get ENOENT, it can proceed with normal page handling?I might be missing something, but is not the following more cleaer?
diff --git
a/mm/memory-failure.cb/mm/memory-failure.c
indexee42d4361309..44f388df5731100644
---a/mm/memory-failure.c
+++b/mm/memory-failure.c
@@ -2026,13 +2026,14 @@ int __get_huge_page_for_hwpoison(unsigned long pfn, int flags,
* So some of prechecks for hwpoison (pinning, and testing/setting
* PageHWPoison) should be done in singlehugetlb_lockrange.
* Returns:- * 0 - not hugetlb, or recovered + * 0 - recovered + * -ENOENT - no hugetlb page * -EBUSY - not recovered * -EOPNOTSUPP - hwpoison_filter'ed * -EHWPOISON - folio or exact page already poisoned * -EFAULT - kill_accessing_process finds current->mm null */ -static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb) +static int try_memory_failure_hugetlb(unsigned long pfn, int flags) { int res, rv; struct page *p = pfn_to_page(pfn); @@ -2040,13 +2041,11 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb unsigned long page_flags; bool migratable_cleared = false;- *hugetlb = 1;
retry:res = get_huge_page_for_hwpoison(pfn, flags, &migratable_cleared); switch (res) { case MF_HUGETLB_NON_HUGEPAGE: /* fallback to normal page handling */ - *hugetlb = 0; - return 0; + return -ENOENT; case MF_HUGETLB_RETRY: if (!(flags & MF_NO_RETRY)) { flags |= MF_NO_RETRY;@@ -2107,7 +2106,7 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb
}#else
-static inline inttry_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb)+static inline inttry_memory_failure_hugetlb(unsigned long pfn, int flags){ return 0; } @@ -2386,8 +2385,11 @@ int memory_failure(unsigned long pfn, int flags) }
try_again:
Quoted 12 lines
- res = try_memory_failure_hugetlb(pfn, flags, &hugetlb);
- if (hugetlb)
+ res = try_memory_failure_hugetlb(pfn, flags);
+ /*
+ * -ENOENT means the page we found is not hugetlb, so proceed with normal page handling
+ */
+ if (res != -ENOENT)
goto unlock_mutex;
if (TestSetPageHWPoison(p)) {Hi Oscar,
Good point. Using -ENOENT to distinguish "not a hugetlb page" from "hugetlb handled" is indeed cleaner than carrying an extra output parameter.
One thing to note: the #else stub when CONFIG_HUGETLB_PAGE is not set currently does:
return 0;
which with your change would mean "hugetlb handled, skip normal path" instead of the intended "not hugetlb, proceed with normal handling". It should be changed to:
return -ENOENT;
Otherwise the non-hugetlb config would silently skip all normal page failure processing.
Signature · 2 lines
Thanks, Ye Liu
Quoted 32 lines · Ye Liu
Quoted 9 lines
-static inline int
try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb)+static inline inttry_memory_failure_hugetlb(unsigned long pfn, int flags){ return 0; } @@ -2386,8 +2385,11 @@ int memory_failure(unsigned long pfn, int flags) }
try_again:Quoted 12 lines
- res = try_memory_failure_hugetlb(pfn, flags, &hugetlb); - if (hugetlb) + res = try_memory_failure_hugetlb(pfn, flags); + /* + * -ENOENT means the page we found is not hugetlb, so proceed with normal page handling + */ + if (res != -ENOENT) goto unlock_mutex; if (TestSetPageHWPoison(p)) {Hi Oscar,
Good point. Using
-ENOENTto distinguish "not a hugetlb page" from "hugetlb handled" is indeed cleaner than carrying an extra output parameter.One thing to note: the #else stub when
CONFIG_HUGETLB_PAGEis not set currently does:
Quoted 7 lines
return 0;which with your change would mean "hugetlb handled, skip normal path" instead of the intended "not hugetlb, proceed with normal handling". It should be changed to:
return -ENOENT;
Right, let us see if Miaohe sees any issue with that approach.
Signature · 2 lines
Oscar Salvador SUSE Labs
Miaohe Lin
maintainerQuoted 35 lines · Oscar Salvador
Quoted 34 lines · Ye Liu
Quoted 9 lines
-static inline int
try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb)+static inline inttry_memory_failure_hugetlb(unsigned long pfn, int flags){ return 0; } @@ -2386,8 +2385,11 @@ int memory_failure(unsigned long pfn, int flags) }
try_again:Quoted 12 lines
- res = try_memory_failure_hugetlb(pfn, flags, &hugetlb); - if (hugetlb) + res = try_memory_failure_hugetlb(pfn, flags); + /* + * -ENOENT means the page we found is not hugetlb, so proceed with normal page handling + */ + if (res != -ENOENT) goto unlock_mutex; if (TestSetPageHWPoison(p)) {Hi Oscar,
Good point. Using
-ENOENTto distinguish "not a hugetlb page" from "hugetlb handled" is indeed cleaner than carrying an extra output parameter.One thing to note: the #else stub when
CONFIG_HUGETLB_PAGEis not set currently does:return 0;
Quoted 7 lines
Quoted 5 lines
which with your change would mean "hugetlb handled, skip normal path" instead of the intended "not hugetlb, proceed with normal handling". It should be changed to:
return -ENOENT;Right, let us see if Miaohe sees any issue with that approach.
This should work for me. Thanks both.