linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] mm/memory_failure: use bool for hugetlb indicator in try_memory_failure_hugetlb
       [not found] <20260407020715.2269255-1-ye.liu@linux.dev>
@ 2026-04-07  2:07 ` Ye Liu
  2026-04-10  6:38   ` Miaohe Lin
  2026-04-07  2:07 ` [PATCH 2/2] mm/memory-failure: use bool for forcekill state Ye Liu
  1 sibling, 1 reply; 5+ messages in thread
From: Ye Liu @ 2026-04-07  2:07 UTC (permalink / raw)
  To: Miaohe Lin, Andrew Morton; +Cc: Ye Liu, Naoya Horiguchi, linux-mm, linux-kernel

From: Ye Liu <liuye@kylinos.cn>

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)

Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
 mm/memory-failure.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index ee42d4361309..d25adb390c3e 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -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);
-- 
2.43.0



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

* [PATCH 2/2] mm/memory-failure: use bool for forcekill state
       [not found] <20260407020715.2269255-1-ye.liu@linux.dev>
  2026-04-07  2:07 ` [PATCH 1/2] mm/memory_failure: use bool for hugetlb indicator in try_memory_failure_hugetlb Ye Liu
@ 2026-04-07  2:07 ` Ye Liu
  2026-04-10  6:45   ` Miaohe Lin
  1 sibling, 1 reply; 5+ messages in thread
From: Ye Liu @ 2026-04-07  2:07 UTC (permalink / raw)
  To: Miaohe Lin, Andrew Morton; +Cc: Ye Liu, Naoya Horiguchi, linux-mm, linux-kernel

From: Ye Liu <liuye@kylinos.cn>

'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.

Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
 mm/memory-failure.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index d25adb390c3e..f355642bc2b6 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -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);
 
 	/*
-- 
2.43.0



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

* Re: [PATCH 1/2] mm/memory_failure: use bool for hugetlb indicator in try_memory_failure_hugetlb
  2026-04-07  2:07 ` [PATCH 1/2] mm/memory_failure: use bool for hugetlb indicator in try_memory_failure_hugetlb Ye Liu
@ 2026-04-10  6:38   ` Miaohe Lin
  0 siblings, 0 replies; 5+ messages in thread
From: Miaohe Lin @ 2026-04-10  6:38 UTC (permalink / raw)
  To: Ye Liu; +Cc: Ye Liu, Naoya Horiguchi, linux-mm, linux-kernel, Andrew Morton

On 2026/4/7 10:07, Ye Liu wrote:
> From: Ye Liu <liuye@kylinos.cn>
> 
> 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)
> 
> Signed-off-by: Ye Liu <liuye@kylinos.cn>

Acked-by: Miaohe Lin <linmiaohe@huawei.com>

Thanks.
.


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

* Re: [PATCH 2/2] mm/memory-failure: use bool for forcekill state
  2026-04-07  2:07 ` [PATCH 2/2] mm/memory-failure: use bool for forcekill state Ye Liu
@ 2026-04-10  6:45   ` Miaohe Lin
  2026-04-10  7:17     ` Ye Liu
  0 siblings, 1 reply; 5+ messages in thread
From: Miaohe Lin @ 2026-04-10  6:45 UTC (permalink / raw)
  To: Ye Liu; +Cc: Ye Liu, Naoya Horiguchi, linux-mm, linux-kernel, Andrew Morton

On 2026/4/7 10:07, Ye Liu wrote:
> From: Ye Liu <liuye@kylinos.cn>
> 
> '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.
> 
> Signed-off-by: Ye Liu <liuye@kylinos.cn>
> ---
>  mm/memory-failure.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/memory-failure.c b/mm/memory-failure.c
> index d25adb390c3e..f355642bc2b6 100644
> --- a/mm/memory-failure.c
> +++ b/mm/memory-failure.c
> @@ -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);

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


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

* Re: [PATCH 2/2] mm/memory-failure: use bool for forcekill state
  2026-04-10  6:45   ` Miaohe Lin
@ 2026-04-10  7:17     ` Ye Liu
  0 siblings, 0 replies; 5+ messages in thread
From: Ye Liu @ 2026-04-10  7:17 UTC (permalink / raw)
  To: Miaohe Lin; +Cc: Ye Liu, Naoya Horiguchi, linux-mm, linux-kernel, Andrew Morton



在 2026/4/10 14:45, Miaohe Lin 写道:
> On 2026/4/7 10:07, Ye Liu wrote:
>> From: Ye Liu <liuye@kylinos.cn>
>>
>> '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.
>>
>> Signed-off-by: Ye Liu <liuye@kylinos.cn>
>> ---
>>  mm/memory-failure.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/mm/memory-failure.c b/mm/memory-failure.c
>> index d25adb390c3e..f355642bc2b6 100644
>> --- a/mm/memory-failure.c
>> +++ b/mm/memory-failure.c
>> @@ -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);
> 
> 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, 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.                                                                         

> Thanks.
> .

-- 
Thanks,
Ye Liu



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

end of thread, other threads:[~2026-04-10  7:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20260407020715.2269255-1-ye.liu@linux.dev>
2026-04-07  2:07 ` [PATCH 1/2] mm/memory_failure: use bool for hugetlb indicator in try_memory_failure_hugetlb Ye Liu
2026-04-10  6:38   ` Miaohe Lin
2026-04-07  2:07 ` [PATCH 2/2] mm/memory-failure: use bool for forcekill state Ye Liu
2026-04-10  6:45   ` Miaohe Lin
2026-04-10  7:17     ` Ye Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox