All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Hongfeng Chen <hongfengchen@xiaomi.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	 Barry Song <baohua@kernel.org>,
	Chengming Zhou <chengming.zhou@linux.dev>,
	 Jens Axboe <axboe@kernel.dk>,
	Johannes Weiner <hannes@cmpxchg.org>,
	 Minchan Kim <minchan@kernel.org>, Nhat Pham <nphamcs@gmail.com>,
	 Sergey Senozhatsky <senozhatsky@chromium.org>,
	Yosry Ahmed <yosry@kernel.org>,
	 Wenchao Hao <haowenchao@xiaomi.com>,
	Wenchao Hao <haowenchao22@gmail.com>,
	linux-mm@kvack.org,  linux-kernel@vger.kernel.org,
	linux-block@vger.kernel.org, chenhongfeng0212@gmail.com
Subject: Re: [RFC PATCH v4 2/2] zram: keep the hot statistics per cpu
Date: Sat, 21 Nov 2026 17:35:54 +0900	[thread overview]
Message-ID: <awFXOyeELHgLfy_D@google.com> (raw)
In-Reply-To: <20261017031542.3504947-1-hongfengchen@xiaomi.com>

Once again, recovered from the SPAM folder.  Sorry for the delay.

On (26/10/17 11:15), Hongfeng Chen wrote:
[..]
> +#define zram_pcpu_add(zram_dev, field, val)					\
> +do {									\
> +	struct zram *__zram = (zram_dev);				\
> +	struct zram_pcpu_stats *__stats;				\
> +									\
> +	__stats = get_cpu_ptr(__zram->pcpu_stats);			\
> +	u64_stats_update_begin(&__stats->syncp);			\
> +	WRITE_ONCE(__stats->field, __stats->field + (val));		\
> +	u64_stats_update_end(&__stats->syncp);			\
> +	put_cpu_ptr(__zram->pcpu_stats);				\
> +} while (0)
> +
> +static void zram_pcpu_sum(struct zram *zram, struct zram_stats_sum *sum)
> +{
> +	int cpu;
> +
> +	memset(sum, 0, sizeof(*sum));
> +
> +	for_each_possible_cpu(cpu) {
> +		struct zram_pcpu_stats *stats;
> +		unsigned int start;
> +		s64 pages, bytes, same, huge;
> +		u64 notify;
> +
> +		stats = per_cpu_ptr(zram->pcpu_stats, cpu);
> +		do {
> +			start = u64_stats_fetch_begin(&stats->syncp);
> +			pages = READ_ONCE(stats->pages_stored);
> +			bytes = READ_ONCE(stats->compr_data_size);
> +			same = READ_ONCE(stats->same_pages);
> +			huge = READ_ONCE(stats->huge_pages);
> +			notify = READ_ONCE(stats->notify_free);
> +		} while (u64_stats_fetch_retry(&stats->syncp, start));
> +
> +		sum->pages_stored += pages;
> +		sum->compr_data_size += bytes;
> +		sum->same_pages += same;
> +		sum->huge_pages += huge;
> +		sum->notify_free += notify;
> +	}
> +}
> +
>  #ifdef CONFIG_ZRAM_WRITEBACK
>  #define INVALID_BDEV_BLOCK		(~0UL)
>  
> @@ -919,6 +969,8 @@ static void zram_account_writeback_submit(struct zram *zram)
>  static int zram_writeback_complete(struct zram *zram, struct zram_wb_req *req)
>  {
>  	unsigned long index = req->pps->index;
> +	struct zram_pcpu_stats *stats;
> +	s64 huge, size;
>  	int err;
>  
>  	err = blk_status_to_errno(req->bio.bi_status);
> @@ -947,9 +999,14 @@ static int zram_writeback_complete(struct zram *zram, struct zram_wb_req *req)
>  	}
>  
>  	clear_slot_flag(zram, index, ZRAM_IDLE);
> -	if (test_slot_flag(zram, index, ZRAM_HUGE))
> -		atomic64_dec(&zram->stats.huge_pages);
> -	atomic64_sub(get_slot_size(zram, index), &zram->stats.compr_data_size);
> +	huge = test_slot_flag(zram, index, ZRAM_HUGE) ? -1 : 0;
> +	size = get_slot_size(zram, index);
> +	stats = get_cpu_ptr(zram->pcpu_stats);
> +	u64_stats_update_begin(&stats->syncp);
> +	WRITE_ONCE(stats->huge_pages, stats->huge_pages + huge);
> +	WRITE_ONCE(stats->compr_data_size, stats->compr_data_size - size);
> +	u64_stats_update_end(&stats->syncp);
> +	put_cpu_ptr(zram->pcpu_stats);

Thanks for reminding me that I actually looked into per-CPU stats a while
ago.  And I had much less code, IIRC, let me find and rebase that patch,
these WRITE_ONCE()-s, etc. are hard to maintain.  Let me find my patch.

      reply	other threads:[~2026-11-21  8:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16 12:09 [RFC PATCH v4 0/2] mm/zsmalloc: defer object free to per-cpu batches Hongfeng Chen
2026-10-16 12:09 ` [RFC PATCH v4 1/2] mm/zsmalloc: defer object free to per-cpu batches and a drain worker Hongfeng Chen
2026-10-16 16:09 ` [RFC PATCH v4 0/2] mm/zsmalloc: defer object free to per-cpu batches Nhat Pham
2026-10-22  2:55   ` Sergey Senozhatsky
2026-10-23 12:37   ` Hongfeng Chen
2026-10-23 18:19     ` Nhat Pham
2026-11-09 10:59       ` Hongfeng Chen
2026-11-19  5:35         ` Sergey Senozhatsky
2026-11-20  1:44           ` Sergey Senozhatsky
2026-11-20  7:48             ` Sergey Senozhatsky
2026-10-17  3:15 ` [RFC PATCH v4 2/2] zram: keep the hot statistics per cpu Hongfeng Chen
2026-11-21  8:35   ` Sergey Senozhatsky [this message]

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=awFXOyeELHgLfy_D@google.com \
    --to=senozhatsky@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=baohua@kernel.org \
    --cc=chengming.zhou@linux.dev \
    --cc=chenhongfeng0212@gmail.com \
    --cc=hannes@cmpxchg.org \
    --cc=haowenchao22@gmail.com \
    --cc=haowenchao@xiaomi.com \
    --cc=hongfengchen@xiaomi.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=nphamcs@gmail.com \
    --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.