linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: remove redundant if overhead
@ 2024-09-10 14:39 Zhiguo Jiang
  2024-09-10 16:03 ` Matthew Wilcox
  0 siblings, 1 reply; 4+ messages in thread
From: Zhiguo Jiang @ 2024-09-10 14:39 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle),
	Andrew Morton, linux-fsdevel, linux-mm, linux-kernel
  Cc: opensource.kernel, Zhiguo Jiang

Remove redundant if judgment overhead.

Signed-off-by: Zhiguo Jiang <justinjiang@vivo.com>
---
 mm/page-writeback.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index fcd4c1439cb9..2d2c3f4e640d
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2715,9 +2715,7 @@ int do_writepages(struct address_space *mapping, struct writeback_control *wbc)
  */
 bool noop_dirty_folio(struct address_space *mapping, struct folio *folio)
 {
-	if (!folio_test_dirty(folio))
-		return !folio_test_set_dirty(folio);
-	return false;
+	return !folio_test_set_dirty(folio);
 }
 EXPORT_SYMBOL(noop_dirty_folio);
 
-- 
2.39.0



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

* Re: [PATCH] mm: remove redundant if overhead
  2024-09-10 14:39 [PATCH] mm: remove redundant if overhead Zhiguo Jiang
@ 2024-09-10 16:03 ` Matthew Wilcox
  2024-09-11  1:14   ` zhiguojiang
  0 siblings, 1 reply; 4+ messages in thread
From: Matthew Wilcox @ 2024-09-10 16:03 UTC (permalink / raw)
  To: Zhiguo Jiang
  Cc: Andrew Morton, linux-fsdevel, linux-mm, linux-kernel, opensource.kernel

On Tue, Sep 10, 2024 at 10:39:45PM +0800, Zhiguo Jiang wrote:
> Remove redundant if judgment overhead.

It's not redundant; it avoids dirtying the cacheline if the folio
is already marked as dirty.

>  bool noop_dirty_folio(struct address_space *mapping, struct folio *folio)
>  {
> -	if (!folio_test_dirty(folio))
> -		return !folio_test_set_dirty(folio);
> -	return false;
> +	return !folio_test_set_dirty(folio);
>  }


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

* Re: [PATCH] mm: remove redundant if overhead
  2024-09-10 16:03 ` Matthew Wilcox
@ 2024-09-11  1:14   ` zhiguojiang
  2024-09-11  1:34     ` Matthew Wilcox
  0 siblings, 1 reply; 4+ messages in thread
From: zhiguojiang @ 2024-09-11  1:14 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Andrew Morton, linux-fsdevel, linux-mm, linux-kernel, opensource.kernel



在 2024/9/11 0:03, Matthew Wilcox 写道:
> On Tue, Sep 10, 2024 at 10:39:45PM +0800, Zhiguo Jiang wrote:
>> Remove redundant if judgment overhead.
> It's not redundant; it avoids dirtying the cacheline if the folio
> is already marked as dirty.
Ok, Is it necessary to add comments here to explain and avoid readers'
misunderstandings? E.g. 'Avoid dirtying the cacheline if the folio is
already marked as dirty.'
>>   bool noop_dirty_folio(struct address_space *mapping, struct folio *folio)
>>   {
>> -	if (!folio_test_dirty(folio))
>> -		return !folio_test_set_dirty(folio);
>> -	return false;
>> +	return !folio_test_set_dirty(folio);
>>   }
Thanks
Zhiguo


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

* Re: [PATCH] mm: remove redundant if overhead
  2024-09-11  1:14   ` zhiguojiang
@ 2024-09-11  1:34     ` Matthew Wilcox
  0 siblings, 0 replies; 4+ messages in thread
From: Matthew Wilcox @ 2024-09-11  1:34 UTC (permalink / raw)
  To: zhiguojiang
  Cc: Andrew Morton, linux-fsdevel, linux-mm, linux-kernel, opensource.kernel

On Wed, Sep 11, 2024 at 09:14:10AM +0800, zhiguojiang wrote:
> 在 2024/9/11 0:03, Matthew Wilcox 写道:
> > On Tue, Sep 10, 2024 at 10:39:45PM +0800, Zhiguo Jiang wrote:
> > > Remove redundant if judgment overhead.
> > It's not redundant; it avoids dirtying the cacheline if the folio
> > is already marked as dirty.

> Ok, Is it necessary to add comments here to explain and avoid readers'
> misunderstandings? E.g. 'Avoid dirtying the cacheline if the folio is
> already marked as dirty.'

No, it's a fairly common pattern to test-and-test-and-set(or clear)


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

end of thread, other threads:[~2024-09-11  1:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-10 14:39 [PATCH] mm: remove redundant if overhead Zhiguo Jiang
2024-09-10 16:03 ` Matthew Wilcox
2024-09-11  1:14   ` zhiguojiang
2024-09-11  1:34     ` Matthew Wilcox

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