Skip to contentSkip to conversation

mm/memory_failure: use bool for hugetlb indicator in try_memory_failure_hugetlb

PATCH Superseded Ye Liu 3 participants 8 messages Apr 7 – May 9 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Ye Liu

author
#1 lore raw

PATCH 1/2 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
index ee42d4361309..d25adb390c3e 100644
@@ -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 *hugetlb
 	unsigned 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
maintainer Acked-by on v1 1/2
#2 lore raw
Quoted 6 lines · Ye Liu

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.

Quoted 6 lines

- 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)

Thanks.
.

author
#3 lore raw

Friendly ping.

Quoted 18 lines · Miaohe Lin
Quoted 6 lines · Ye Liu

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.

Quoted 6 lines

- 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)

Thanks.
.

Signature · 2 lines
Thanks,
Ye Liu
author
#4 lore raw

PATCH 2/2 mm/memory-failure: use bool for forcekill state

In reply to a message not in the archive

From: Ye Liu <[email protected]>

'forcekill' is used as a boolean flag to control whether processes should be forcibly killed. It is only assigned from boolean expressions and never used in arithmetic or bitmask operations.

Convert it from int to bool.

No functional change intended.

---
 mm/memory-failure.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/memory-failure.c +2 -2
index d25adb390c3e..f355642bc2b6 100644
@@ -459,7 +459,7 @@ void add_to_kill_ksm(struct task_struct *tsk, const struct page *p,
  * Only do anything when FORCEKILL is set, otherwise just free the
  * list (this is used for clean pages which do not need killing)
  */
-static void kill_procs(struct list_head *to_kill, int forcekill,
+static void kill_procs(struct list_head *to_kill, bool forcekill,
 		unsigned long pfn, int flags)
 {
 	struct to_kill *tk, *next;
@@ -1582,7 +1582,7 @@ static bool hwpoison_user_mappings(struct folio *folio, struct page *p,
 {
 	LIST_HEAD(tokill);
 	bool unmap_success;
-	int forcekill;
+	bool forcekill;
 	bool mlocked = folio_test_mlocked(folio);
 
 	/*
Signature · 1 line
2.43.0
maintainer
#5 lore raw

Re: [PATCH 2/2] mm/memory-failure: use bool for forcekill state

Quoted 30 lines · Ye Liu

From: Ye Liu <[email protected]>

'forcekill' is used as a boolean flag to control whether processes should be forcibly killed. It is only assigned from boolean expressions and never used in arithmetic or bitmask operations.

Convert it from int to bool.

No functional change intended.

---
 mm/memory-failure.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/memory-failure.c +1 -1
index d25adb390c3e..f355642bc2b6 100644
@@ -459,7 +459,7 @@ void add_to_kill_ksm(struct task_struct *tsk, const struct page *p,
  * Only do anything when FORCEKILL is set, otherwise just free the
  * list (this is used for clean pages which do not need killing)
  */
-static void kill_procs(struct list_head *to_kill, int forcekill,
+static void kill_procs(struct list_head *to_kill, bool forcekill,
 		unsigned long pfn, int flags)
 {
 	struct to_kill *tk, *next;

mm/memory-failure.c static bool hwpoison_user_mappings(struct folio *folio, struct page *p, · line 1586

Quoted 6 lines
mm/memory-failure.c +1 -1
@@ -1582,7 +1582,7 @@ static bool hwpoison_user_mappings(struct folio *folio, struct page *p,
 {
 	LIST_HEAD(tokill);
 	bool unmap_success;
-	int forcekill;
+	bool forcekill;
 	bool mlocked = folio_test_mlocked(folio);

There is one caller in unmap_and_kill():

	kill_procs(to_kill, flags & MF_MUST_KILL, pfn, flags);

It seems flags & MF_MUST_KILL does not return bool. So maybe we should change it to clear semantic conversion?

Thanks.
.

author
#6 lore raw

Re: [PATCH 2/2] mm/memory-failure: use bool for forcekill state

Quoted 39 lines · Miaohe Lin
Quoted 30 lines · Ye Liu

From: Ye Liu <[email protected]>

'forcekill' is used as a boolean flag to control whether processes should be forcibly killed. It is only assigned from boolean expressions and never used in arithmetic or bitmask operations.

Convert it from int to bool.

No functional change intended.

---
 mm/memory-failure.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/memory-failure.c +1 -1
index d25adb390c3e..f355642bc2b6 100644
@@ -459,7 +459,7 @@ void add_to_kill_ksm(struct task_struct *tsk, const struct page *p,
  * Only do anything when FORCEKILL is set, otherwise just free the
  * list (this is used for clean pages which do not need killing)
  */
-static void kill_procs(struct list_head *to_kill, int forcekill,
+static void kill_procs(struct list_head *to_kill, bool forcekill,
 		unsigned long pfn, int flags)
 {
 	struct to_kill *tk, *next;

mm/memory-failure.c static bool hwpoison_user_mappings(struct folio *folio, struct page *p, · line 1586

Quoted 6 lines
mm/memory-failure.c +1 -1
@@ -1582,7 +1582,7 @@ static bool hwpoison_user_mappings(struct folio *folio, struct page *p,
 {
 	LIST_HEAD(tokill);
 	bool unmap_success;
-	int forcekill;
+	bool forcekill;
 	bool mlocked = folio_test_mlocked(folio);

There is one caller in unmap_and_kill():

Quoted 5 lines
	kill_procs(to_kill, flags & MF_MUST_KILL, pfn, flags);

It seems flags & MF_MUST_KILL does not return bool. So maybe we should change it to clear semantic conversion?

Thanks, that's a good point.

While the current call relies on the implicit scalar-to-bool conversion,
making it explicit at the call site better reflects the intent of this bool conversion cleanup.

I'll switch it to !!(flags & MF_MUST_KILL) in v2 for clarity.

Appreciate the review.

Quoted 2 lines

Thanks.
.

Signature · 2 lines
Thanks,
Ye Liu
maintainer
#7 lore raw

Re: [PATCH 2/2] mm/memory-failure: use bool for forcekill state

In reply to Miaohe Lin
Quoted 39 lines · On Fri, 10 Apr 2026 14:45:47 +0800 Miaohe Lin <[email protected]> wrote:
Quoted 30 lines · Ye Liu

From: Ye Liu <[email protected]>

'forcekill' is used as a boolean flag to control whether processes should be forcibly killed. It is only assigned from boolean expressions and never used in arithmetic or bitmask operations.

Convert it from int to bool.

No functional change intended.

---
 mm/memory-failure.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/memory-failure.c +1 -1
index d25adb390c3e..f355642bc2b6 100644
@@ -459,7 +459,7 @@ void add_to_kill_ksm(struct task_struct *tsk, const struct page *p,
  * Only do anything when FORCEKILL is set, otherwise just free the
  * list (this is used for clean pages which do not need killing)
  */
-static void kill_procs(struct list_head *to_kill, int forcekill,
+static void kill_procs(struct list_head *to_kill, bool forcekill,
 		unsigned long pfn, int flags)
 {
 	struct to_kill *tk, *next;

mm/memory-failure.c static bool hwpoison_user_mappings(struct folio *folio, struct page *p, · line 1586

Quoted 6 lines
mm/memory-failure.c +1 -1
@@ -1582,7 +1582,7 @@ static bool hwpoison_user_mappings(struct folio *folio, struct page *p,
 {
 	LIST_HEAD(tokill);
 	bool unmap_success;
-	int forcekill;
+	bool forcekill;
 	bool mlocked = folio_test_mlocked(folio);

There is one caller in unmap_and_kill():

Quoted 4 lines
	kill_procs(to_kill, flags & MF_MUST_KILL, pfn, flags);

It seems flags & MF_MUST_KILL does not return bool. So maybe we should change it to clear semantic conversion?

AI review was wondering the same thing ;) And possibly a changelog glitch.

	https://sashiko.dev/#/patchset/[email protected]
maintainer
#8 lore raw

Re: [PATCH 2/2] mm/memory-failure: use bool for forcekill state

Quoted 43 lines · Andrew Morton
Quoted 41 lines · On Fri, 10 Apr 2026 14:45:47 +0800 Miaohe Lin <[email protected]> wrote:
Quoted 30 lines · Ye Liu

From: Ye Liu <[email protected]>

'forcekill' is used as a boolean flag to control whether processes should be forcibly killed. It is only assigned from boolean expressions and never used in arithmetic or bitmask operations.

Convert it from int to bool.

No functional change intended.

---
 mm/memory-failure.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/memory-failure.c +1 -1
index d25adb390c3e..f355642bc2b6 100644
@@ -459,7 +459,7 @@ void add_to_kill_ksm(struct task_struct *tsk, const struct page *p,
  * Only do anything when FORCEKILL is set, otherwise just free the
  * list (this is used for clean pages which do not need killing)
  */
-static void kill_procs(struct list_head *to_kill, int forcekill,
+static void kill_procs(struct list_head *to_kill, bool forcekill,
 		unsigned long pfn, int flags)
 {
 	struct to_kill *tk, *next;

mm/memory-failure.c static bool hwpoison_user_mappings(struct folio *folio, struct page *p, · line 1586

Quoted 6 lines
mm/memory-failure.c +1 -1
@@ -1582,7 +1582,7 @@ static bool hwpoison_user_mappings(struct folio *folio, struct page *p,
 {
 	LIST_HEAD(tokill);
 	bool unmap_success;
-	int forcekill;
+	bool forcekill;
 	bool mlocked = folio_test_mlocked(folio);

There is one caller in unmap_and_kill():

	kill_procs(to_kill, flags & MF_MUST_KILL, pfn, flags);
Quoted 7 lines
Quoted 2 lines

It seems flags & MF_MUST_KILL does not return bool. So maybe we should change it to clear semantic conversion?

AI review was wondering the same thing ;) And possibly a changelog glitch.

	https://sashiko.dev/#/patchset/[email protected]

Thanks Andrew. I see there is a v2 patch [1] that has used a boolean expression to align with the commit's stated intent as AI requested. I guess you might missed that thread.

[1] https://lore.kernel.org/all/[email protected]/

Thanks.
.

Quoted 3 lines

.