All of lore.kernel.org
 help / color / mirror / Atom feed
* + zram-use-try_cmpxchg-in-update_used_max.patch added to mm-unstable branch
@ 2022-10-18 20:50 Andrew Morton
  2022-10-26 10:31 ` Sergey Senozhatsky
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Morton @ 2022-10-18 20:50 UTC (permalink / raw)
  To: mm-commits, senozhatsky, ngupta, minchan, ubizjak, akpm


The patch titled
     Subject: zram: use try_cmpxchg in update_used_max
has been added to the -mm mm-unstable branch.  Its filename is
     zram-use-try_cmpxchg-in-update_used_max.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/zram-use-try_cmpxchg-in-update_used_max.patch

This patch will later appear in the mm-unstable branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via the mm-everything
branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days

------------------------------------------------------
From: Uros Bizjak <ubizjak@gmail.com>
Subject: zram: use try_cmpxchg in update_used_max
Date: Tue, 18 Oct 2022 16:51:54 +0200

Use try_cmpxchg instead of cmpxchg (*ptr, old, new) == old in
update_used_max.  x86 CMPXCHG instruction returns success in ZF flag, so
this change saves a compare after cmpxchg (and related move instruction in
front of cmpxchg).

Also, reorder code a bit to remove additional compare and conditional jump
from the assembly code.  Together, hese two changes save 15 bytes from the
function when compiled for x86_64.

No functional change intended.

Link: https://lkml.kernel.org/r/20221018145154.3699-1-ubizjak@gmail.com
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 drivers/block/zram/zram_drv.c |   13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

--- a/drivers/block/zram/zram_drv.c~zram-use-try_cmpxchg-in-update_used_max
+++ a/drivers/block/zram/zram_drv.c
@@ -193,16 +193,13 @@ static void update_position(u32 *index,
 static inline void update_used_max(struct zram *zram,
 					const unsigned long pages)
 {
-	unsigned long old_max, cur_max;
-
-	old_max = atomic_long_read(&zram->stats.max_used_pages);
+	unsigned long cur_max = atomic_long_read(&zram->stats.max_used_pages);
 
 	do {
-		cur_max = old_max;
-		if (pages > cur_max)
-			old_max = atomic_long_cmpxchg(
-				&zram->stats.max_used_pages, cur_max, pages);
-	} while (old_max != cur_max);
+		if (cur_max >= pages)
+			return;
+	} while (!atomic_long_try_cmpxchg(&zram->stats.max_used_pages,
+					  &cur_max, pages));
 }
 
 static inline void zram_fill_page(void *ptr, unsigned long len,
_

Patches currently in -mm which might be from ubizjak@gmail.com are

zram-use-try_cmpxchg-in-update_used_max.patch
llist-avoid-extra-memory-read-in-llist_add_batch.patch


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

* Re: + zram-use-try_cmpxchg-in-update_used_max.patch added to mm-unstable branch
  2022-10-18 20:50 + zram-use-try_cmpxchg-in-update_used_max.patch added to mm-unstable branch Andrew Morton
@ 2022-10-26 10:31 ` Sergey Senozhatsky
  0 siblings, 0 replies; 2+ messages in thread
From: Sergey Senozhatsky @ 2022-10-26 10:31 UTC (permalink / raw)
  To: Andrew Morton; +Cc: mm-commits, senozhatsky, ngupta, minchan, ubizjak

On (22/10/18 13:50), Andrew Morton wrote:
> Use try_cmpxchg instead of cmpxchg (*ptr, old, new) == old in
> update_used_max.  x86 CMPXCHG instruction returns success in ZF flag, so
> this change saves a compare after cmpxchg (and related move instruction in
> front of cmpxchg).
> 
> Also, reorder code a bit to remove additional compare and conditional jump
> from the assembly code.  Together, hese two changes save 15 bytes from the
> function when compiled for x86_64.
> 
> No functional change intended.
> 
> Link: https://lkml.kernel.org/r/20221018145154.3699-1-ubizjak@gmail.com
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
> Cc: Minchan Kim <minchan@kernel.org>
> Cc: Nitin Gupta <ngupta@vflare.org>
> Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

I totally missed that patch.

Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>

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

end of thread, other threads:[~2022-10-26 10:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-18 20:50 + zram-use-try_cmpxchg-in-update_used_max.patch added to mm-unstable branch Andrew Morton
2022-10-26 10:31 ` Sergey Senozhatsky

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.