linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] mm/page_poison: slightly optimize check_poison_mem()
@ 2024-08-21  7:53 Zhen Lei
  2024-08-21 11:28 ` David Hildenbrand
  0 siblings, 1 reply; 3+ messages in thread
From: Zhen Lei @ 2024-08-21  7:53 UTC (permalink / raw)
  To: Andrew Morton, linux-mm, linux-kernel; +Cc: Zhen Lei

When the debug information needs to be suppressed due to ratelimit,
it is unnecessary to determine the end of the corrupted memory.

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
 mm/page_poison.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/mm/page_poison.c b/mm/page_poison.c
index 3e9037363cf9d85..23fa799214720f1 100644
--- a/mm/page_poison.c
+++ b/mm/page_poison.c
@@ -55,14 +55,15 @@ static void check_poison_mem(struct page *page, unsigned char *mem, size_t bytes
 	if (!start)
 		return;
 
+	if (!__ratelimit(&ratelimit))
+		return;
+
 	for (end = mem + bytes - 1; end > start; end--) {
 		if (*end != PAGE_POISON)
 			break;
 	}
 
-	if (!__ratelimit(&ratelimit))
-		return;
-	else if (start == end && single_bit_flip(*start, PAGE_POISON))
+	if (start == end && single_bit_flip(*start, PAGE_POISON))
 		pr_err("pagealloc: single bit error\n");
 	else
 		pr_err("pagealloc: memory corruption\n");
-- 
2.34.1



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

* Re: [PATCH 1/1] mm/page_poison: slightly optimize check_poison_mem()
  2024-08-21  7:53 [PATCH 1/1] mm/page_poison: slightly optimize check_poison_mem() Zhen Lei
@ 2024-08-21 11:28 ` David Hildenbrand
  2024-08-22  1:27   ` Leizhen (ThunderTown)
  0 siblings, 1 reply; 3+ messages in thread
From: David Hildenbrand @ 2024-08-21 11:28 UTC (permalink / raw)
  To: Zhen Lei, Andrew Morton, linux-mm, linux-kernel

On 21.08.24 09:53, Zhen Lei wrote:
> When the debug information needs to be suppressed due to ratelimit,
> it is unnecessary to determine the end of the corrupted memory.
> 
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> ---
>   mm/page_poison.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/mm/page_poison.c b/mm/page_poison.c
> index 3e9037363cf9d85..23fa799214720f1 100644
> --- a/mm/page_poison.c
> +++ b/mm/page_poison.c
> @@ -55,14 +55,15 @@ static void check_poison_mem(struct page *page, unsigned char *mem, size_t bytes
>   	if (!start)
>   		return;
>   
> +	if (!__ratelimit(&ratelimit))
> +		return;
> +
>   	for (end = mem + bytes - 1; end > start; end--) {
>   		if (*end != PAGE_POISON)
>   			break;
>   	}
>   
> -	if (!__ratelimit(&ratelimit))
> -		return;
> -	else if (start == end && single_bit_flip(*start, PAGE_POISON))
> +	if (start == end && single_bit_flip(*start, PAGE_POISON))
>   		pr_err("pagealloc: single bit error\n");
>   	else
>   		pr_err("pagealloc: memory corruption\n");

This way, you will be ratelimiting on every function call, possibly 
skipping PAGE_POISON checks even if there was no prior corruption detected?

-- 
Cheers,

David / dhildenb



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

* Re: [PATCH 1/1] mm/page_poison: slightly optimize check_poison_mem()
  2024-08-21 11:28 ` David Hildenbrand
@ 2024-08-22  1:27   ` Leizhen (ThunderTown)
  0 siblings, 0 replies; 3+ messages in thread
From: Leizhen (ThunderTown) @ 2024-08-22  1:27 UTC (permalink / raw)
  To: David Hildenbrand, Andrew Morton, linux-mm, linux-kernel



On 2024/8/21 19:28, David Hildenbrand wrote:
> On 21.08.24 09:53, Zhen Lei wrote:
>> When the debug information needs to be suppressed due to ratelimit,
>> it is unnecessary to determine the end of the corrupted memory.
>>
>> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
>> ---
>>   mm/page_poison.c | 7 ++++---
>>   1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/mm/page_poison.c b/mm/page_poison.c
>> index 3e9037363cf9d85..23fa799214720f1 100644
>> --- a/mm/page_poison.c
>> +++ b/mm/page_poison.c
>> @@ -55,14 +55,15 @@ static void check_poison_mem(struct page *page, unsigned char *mem, size_t bytes
>>       if (!start)
>>           return;
>>   +    if (!__ratelimit(&ratelimit))
>> +        return;
>> +
>>       for (end = mem + bytes - 1; end > start; end--) {
>>           if (*end != PAGE_POISON)
>>               break;
>>       }
>>   -    if (!__ratelimit(&ratelimit))
>> -        return;
>> -    else if (start == end && single_bit_flip(*start, PAGE_POISON))
>> +    if (start == end && single_bit_flip(*start, PAGE_POISON))
>>           pr_err("pagealloc: single bit error\n");
>>       else
>>           pr_err("pagealloc: memory corruption\n");
> 
> This way, you will be ratelimiting on every function call, possibly skipping PAGE_POISON checks even if there was no prior corruption detected?
> 

No, the previous memchr_inv() does the PAGE_POISON check, determine the start of the corrupted memory. !start means no corruption.

	start = memchr_inv(mem, PAGE_POISON, bytes);
	if (!start)
		return;

+	if (!__ratelimit(&ratelimit))
+		return;

	for (end = mem + bytes - 1; end > start; end--) {
		if (*end != PAGE_POISON)
			break;
	}



-- 
Regards,
  Zhen Lei


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

end of thread, other threads:[~2024-08-22  1:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-21  7:53 [PATCH 1/1] mm/page_poison: slightly optimize check_poison_mem() Zhen Lei
2024-08-21 11:28 ` David Hildenbrand
2024-08-22  1:27   ` Leizhen (ThunderTown)

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