All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: sashiko-reviews@lists.linux.dev
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
	 Andrew Morton <akpm@linux-foundation.org>,
	Nhat Pham <nphamcs@gmail.com>, Yosry Ahmed <yosry@kernel.org>,
	 Hongfeng Chen <hongfengchen@xiaomi.com>,
	Brian Geffon <bgeffon@google.com>,
	 Minchan Kim <minchan@kernel.org>,
	linux-mm@kvack.org
Subject: Re: [PATCH 2/2] zram: keep the hot statistics per CPU
Date: Mon, 23 Nov 2026 14:27:43 +0900	[thread overview]
Message-ID: <awPN3Fiwcej4_IU7@google.com> (raw)
In-Reply-To: <sashiko-outbox-228621@kernel.org>

On (26/11/23 03:55), sashiko-bot@kernel.org wrote:
> CPU0                              CPU1
> zram_write_page()
>   slot_lock(zram, index)
>   zs_store(...)
>   set_slot_size(zram, index, len)
>   slot_unlock(zram, index)
>   <preempted>
>                                   zram_slot_free_notify()
>                                     slot_trylock(zram, index)
>                                     slot_free(zram, index)
>                                       zram_stat_sub(..., 1)
>                                     slot_unlock(zram, index)
>                                   mm_stat_show()
>                                     zram_stat_read()
>                                       sum < 0  <-- loops until CPU0 runs
> 
> While the writer on CPU0 remains preempted, the true sum across all CPUs
> is negative, not just a transient artifact of racing with the summation
> loop.  Any reader in mm_stat_show() will busy-loop across all possible
> CPUs with zram->dev_lock held until the writer runs, and a higher-priority
> SCHED_FIFO reader on the same CPU as the preempted writer will never yield
> via cond_resched(), livelocking the CPU.

I high prio mm_stats reader is an unlikely scnerio, but yes, okay.

> Clamping negative sums to 0 in a single pass (like
> percpu_counter_sum_positive()) and moving zram_stat_add() before
> slot_unlock() would avoid the unbounded loop.

I disliked the clamping approach when I looked at it.  But thinking
about it more, I think it is the right thing to do.  It's perfectly
legal for zram to return 0 for those dynamic stats: no data stored,
no incompressible pages, no same-filled pages, no slot-free, etc.
So userspace should not be surprised to occasionally see zeroes for
those stats.


  reply	other threads:[~2026-11-23  5:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  3:10 [PATCH 1/2] zsmalloc: free a zspage's pages in one batch Sergey Senozhatsky
2026-11-23  3:10 ` [PATCH 2/2] zram: keep the hot statistics per CPU Sergey Senozhatsky
2026-11-23  3:55   ` sashiko-bot
2026-11-23  5:27     ` Sergey Senozhatsky [this message]
2026-11-23  3:14 ` [PATCH 1/2] zsmalloc: free a zspage's pages in one batch Sergey Senozhatsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=awPN3Fiwcej4_IU7@google.com \
    --to=senozhatsky@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=bgeffon@google.com \
    --cc=hongfengchen@xiaomi.com \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=nphamcs@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=yosry@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.