All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Zhang Yi <yi.zhang@huawei.com>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu,
	adilger.kernel@dilger.ca, jack@suse.cz, yukuai3@huawei.com
Subject: Re: [RFC PATCH v3 5/8] jbd2,ext4: add a shrinker to release checkpointed buffers
Date: Wed, 9 Jun 2021 13:00:39 +1000	[thread overview]
Message-ID: <20210609030039.GB2419729@dread.disaster.area> (raw)
In-Reply-To: <20210527135641.420514-6-yi.zhang@huawei.com>

On Thu, May 27, 2021 at 09:56:38PM +0800, Zhang Yi wrote:
> +/**
> + * jbd2_journal_shrink_scan()
> + *
> + * Scan the checkpointed buffer on the checkpoint list and release the
> + * journal_head.
> + */
> +unsigned long jbd2_journal_shrink_scan(struct shrinker *shrink,
> +				       struct shrink_control *sc)
> +{
> +	journal_t *journal = container_of(shrink, journal_t, j_shrinker);
> +	unsigned long nr_to_scan = sc->nr_to_scan;
> +	unsigned long nr_shrunk;
> +	unsigned long count;
> +
> +	count = percpu_counter_sum_positive(&journal->j_jh_shrink_count);
> +	trace_jbd2_shrink_scan_enter(journal, sc->nr_to_scan, count);
> +
> +	nr_shrunk = jbd2_journal_shrink_checkpoint_list(journal, &nr_to_scan);
> +
> +	count = percpu_counter_sum_positive(&journal->j_jh_shrink_count);
> +	trace_jbd2_shrink_scan_exit(journal, nr_to_scan, nr_shrunk, count);
> +
> +	return nr_shrunk;
> +}
> +
> +/**
> + * jbd2_journal_shrink_scan()
> + *
> + * Count the number of checkpoint buffers on the checkpoint list.
> + */
> +unsigned long jbd2_journal_shrink_count(struct shrinker *shrink,
> +					struct shrink_control *sc)
> +{
> +	journal_t *journal = container_of(shrink, journal_t, j_shrinker);
> +	unsigned long count;
> +
> +	count = percpu_counter_sum_positive(&journal->j_jh_shrink_count);
> +	trace_jbd2_shrink_count(journal, sc->nr_to_scan, count);
> +
> +	return count;
> +}

NACK.

You should not be putting an expensive percpu counter sum in a
shrinker object count routine. These gets called a *lot* under
memory pressure, and summing over hundreds/thousands of CPUs on
every direct reclaim instance over every mounted filesystem
instance that uses jbd2 is really, really going to hurt system
performance under memory pressure.

And, quite frankly, summing twice in the scan routine just to trace
the result with no other purpose is unnecessary and excessive CPU
overhead for a shrinker.

Just use percpu_counter_read() in all cases here - it is more than
accurate enough for the purposes of both tracing and memory reclaim.

-Dave.
-- 
Dave Chinner
david@fromorbit.com

  parent reply	other threads:[~2021-06-09  3:01 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-27 13:56 [RFC PATCH v3 0/8] ext4, jbd2: fix 3 issues about bdev_try_to_free_page() Zhang Yi
2021-05-27 13:56 ` [RFC PATCH v3 1/8] jbd2: remove the out label in __jbd2_journal_remove_checkpoint() Zhang Yi
2021-05-27 13:56 ` [RFC PATCH v3 2/8] jbd2: ensure abort the journal if detect IO error when writing original buffer back Zhang Yi
2021-06-03 16:21   ` Jan Kara
2021-05-27 13:56 ` [RFC PATCH v3 3/8] jbd2: don't abort the journal when freeing buffers Zhang Yi
2021-05-27 13:56 ` [RFC PATCH v3 4/8] jbd2: remove redundant buffer io error checks Zhang Yi
2021-06-03 16:28   ` Jan Kara
2021-06-10  2:05     ` Zhang Yi
2021-05-27 13:56 ` [RFC PATCH v3 5/8] jbd2,ext4: add a shrinker to release checkpointed buffers Zhang Yi
2021-05-27 15:10   ` [RFC PATCH v3 5/8] jbd2, ext4: " kernel test robot
2021-05-27 15:41   ` kernel test robot
2021-05-27 18:25   ` kernel test robot
2021-05-27 18:25   ` [RFC PATCH] jbd2, ext4: jbd2_journal_shrink_scan() can be static kernel test robot
2021-06-07 15:45   ` [RFC PATCH v3 5/8] jbd2,ext4: add a shrinker to release checkpointed buffers Jan Kara
2021-06-09  3:00   ` Dave Chinner [this message]
2021-06-10  2:38     ` Zhang Yi
2021-05-27 13:56 ` [RFC PATCH v3 6/8] jbd2: simplify journal_clean_one_cp_list() Zhang Yi
2021-06-07 15:50   ` Jan Kara
2021-05-27 13:56 ` [RFC PATCH v3 7/8] ext4: remove bdev_try_to_free_page() callback Zhang Yi
2021-06-07 15:50   ` Jan Kara
2021-05-27 13:56 ` [RFC PATCH v3 8/8] fs: remove bdev_try_to_free_page callback Zhang Yi
2021-06-07 15:50   ` Jan Kara

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=20210609030039.GB2419729@dread.disaster.area \
    --to=david@fromorbit.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai3@huawei.com \
    /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.