* [PATCH v5 30/45] ext4: dynamically allocate the ext4-es shrinker
[not found] <20230824034304.37411-1-zhengqi.arch@bytedance.com>
@ 2023-08-24 3:42 ` Qi Zheng
2023-08-24 3:42 ` [PATCH v5 31/45] jbd2,ext4: dynamically allocate the jbd2-journal shrinker Qi Zheng
1 sibling, 0 replies; 3+ messages in thread
From: Qi Zheng @ 2023-08-24 3:42 UTC (permalink / raw)
To: akpm, david, tkhai, vbabka, roman.gushchin, djwong, brauner,
paulmck, tytso, steven.price, cel, senozhatsky, yujie.liu, gregkh,
muchun.song
Cc: linux-kernel, linux-mm, linux-fsdevel, Qi Zheng, Muchun Song,
Andreas Dilger, linux-ext4
In preparation for implementing lockless slab shrink, use new APIs to
dynamically allocate the ext4-es shrinker, so that it can be freed
asynchronously via RCU. Then it doesn't need to wait for RCU read-side
critical section when releasing the struct ext4_sb_info.
Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
Reviewed-by: Muchun Song <songmuchun@bytedance.com>
CC: "Theodore Ts'o" <tytso@mit.edu>
CC: Andreas Dilger <adilger.kernel@dilger.ca>
CC: linux-ext4@vger.kernel.org
---
fs/ext4/ext4.h | 2 +-
fs/ext4/extents_status.c | 24 ++++++++++++++----------
2 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index e5055eac42f6..353a7fcd609a 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1653,7 +1653,7 @@ struct ext4_sb_info {
__u32 s_csum_seed;
/* Reclaim extents from extent status tree */
- struct shrinker s_es_shrinker;
+ struct shrinker *s_es_shrinker;
struct list_head s_es_list; /* List of inodes with reclaimable extents */
long s_es_nr_inode;
struct ext4_es_stats s_es_stats;
diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
index 9b5b8951afb4..0532a81a7669 100644
--- a/fs/ext4/extents_status.c
+++ b/fs/ext4/extents_status.c
@@ -1596,7 +1596,7 @@ static unsigned long ext4_es_count(struct shrinker *shrink,
unsigned long nr;
struct ext4_sb_info *sbi;
- sbi = container_of(shrink, struct ext4_sb_info, s_es_shrinker);
+ sbi = shrink->private_data;
nr = percpu_counter_read_positive(&sbi->s_es_stats.es_stats_shk_cnt);
trace_ext4_es_shrink_count(sbi->s_sb, sc->nr_to_scan, nr);
return nr;
@@ -1605,8 +1605,7 @@ static unsigned long ext4_es_count(struct shrinker *shrink,
static unsigned long ext4_es_scan(struct shrinker *shrink,
struct shrink_control *sc)
{
- struct ext4_sb_info *sbi = container_of(shrink,
- struct ext4_sb_info, s_es_shrinker);
+ struct ext4_sb_info *sbi = shrink->private_data;
int nr_to_scan = sc->nr_to_scan;
int ret, nr_shrunk;
@@ -1690,13 +1689,18 @@ int ext4_es_register_shrinker(struct ext4_sb_info *sbi)
if (err)
goto err3;
- sbi->s_es_shrinker.scan_objects = ext4_es_scan;
- sbi->s_es_shrinker.count_objects = ext4_es_count;
- sbi->s_es_shrinker.seeks = DEFAULT_SEEKS;
- err = register_shrinker(&sbi->s_es_shrinker, "ext4-es:%s",
- sbi->s_sb->s_id);
- if (err)
+ sbi->s_es_shrinker = shrinker_alloc(0, "ext4-es:%s", sbi->s_sb->s_id);
+ if (!sbi->s_es_shrinker) {
+ err = -ENOMEM;
goto err4;
+ }
+
+ sbi->s_es_shrinker->scan_objects = ext4_es_scan;
+ sbi->s_es_shrinker->count_objects = ext4_es_count;
+ sbi->s_es_shrinker->seeks = DEFAULT_SEEKS;
+ sbi->s_es_shrinker->private_data = sbi;
+
+ shrinker_register(sbi->s_es_shrinker);
return 0;
err4:
@@ -1716,7 +1720,7 @@ void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi)
percpu_counter_destroy(&sbi->s_es_stats.es_stats_cache_misses);
percpu_counter_destroy(&sbi->s_es_stats.es_stats_all_cnt);
percpu_counter_destroy(&sbi->s_es_stats.es_stats_shk_cnt);
- unregister_shrinker(&sbi->s_es_shrinker);
+ shrinker_free(sbi->s_es_shrinker);
}
/*
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v5 31/45] jbd2,ext4: dynamically allocate the jbd2-journal shrinker
[not found] <20230824034304.37411-1-zhengqi.arch@bytedance.com>
2023-08-24 3:42 ` [PATCH v5 30/45] ext4: dynamically allocate the ext4-es shrinker Qi Zheng
@ 2023-08-24 3:42 ` Qi Zheng
2023-08-24 9:49 ` Jan Kara
1 sibling, 1 reply; 3+ messages in thread
From: Qi Zheng @ 2023-08-24 3:42 UTC (permalink / raw)
To: akpm, david, tkhai, vbabka, roman.gushchin, djwong, brauner,
paulmck, tytso, steven.price, cel, senozhatsky, yujie.liu, gregkh,
muchun.song
Cc: linux-kernel, linux-mm, linux-fsdevel, Qi Zheng, Muchun Song,
Jan Kara, linux-ext4
In preparation for implementing lockless slab shrink, use new APIs to
dynamically allocate the jbd2-journal shrinker, so that it can be freed
asynchronously via RCU. Then it doesn't need to wait for RCU read-side
critical section when releasing the struct journal_s.
Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
Reviewed-by: Muchun Song <songmuchun@bytedance.com>
CC: "Theodore Ts'o" <tytso@mit.edu>
CC: Jan Kara <jack@suse.com>
CC: linux-ext4@vger.kernel.org
---
fs/jbd2/journal.c | 30 +++++++++++++++++++-----------
include/linux/jbd2.h | 2 +-
2 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 768fa05bcbed..75692baa76e8 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -1290,7 +1290,7 @@ static int jbd2_min_tag_size(void)
static unsigned long jbd2_journal_shrink_scan(struct shrinker *shrink,
struct shrink_control *sc)
{
- journal_t *journal = container_of(shrink, journal_t, j_shrinker);
+ journal_t *journal = shrink->private_data;
unsigned long nr_to_scan = sc->nr_to_scan;
unsigned long nr_shrunk;
unsigned long count;
@@ -1316,7 +1316,7 @@ static unsigned long jbd2_journal_shrink_scan(struct shrinker *shrink,
static unsigned long jbd2_journal_shrink_count(struct shrinker *shrink,
struct shrink_control *sc)
{
- journal_t *journal = container_of(shrink, journal_t, j_shrinker);
+ journal_t *journal = shrink->private_data;
unsigned long count;
count = percpu_counter_read_positive(&journal->j_checkpoint_jh_count);
@@ -1588,14 +1588,22 @@ static journal_t *journal_init_common(struct block_device *bdev,
goto err_cleanup;
journal->j_shrink_transaction = NULL;
- journal->j_shrinker.scan_objects = jbd2_journal_shrink_scan;
- journal->j_shrinker.count_objects = jbd2_journal_shrink_count;
- journal->j_shrinker.seeks = DEFAULT_SEEKS;
- journal->j_shrinker.batch = journal->j_max_transaction_buffers;
- err = register_shrinker(&journal->j_shrinker, "jbd2-journal:(%u:%u)",
- MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev));
- if (err)
+
+ journal->j_shrinker = shrinker_alloc(0, "jbd2-journal:(%u:%u)",
+ MAJOR(bdev->bd_dev),
+ MINOR(bdev->bd_dev));
+ if (!journal->j_shrinker) {
+ err = -ENOMEM;
goto err_cleanup;
+ }
+
+ journal->j_shrinker->scan_objects = jbd2_journal_shrink_scan;
+ journal->j_shrinker->count_objects = jbd2_journal_shrink_count;
+ journal->j_shrinker->seeks = DEFAULT_SEEKS;
+ journal->j_shrinker->batch = journal->j_max_transaction_buffers;
+ journal->j_shrinker->private_data = journal;
+
+ shrinker_register(journal->j_shrinker);
return journal;
@@ -2170,9 +2178,9 @@ int jbd2_journal_destroy(journal_t *journal)
brelse(journal->j_sb_buffer);
}
- if (journal->j_shrinker.flags & SHRINKER_REGISTERED) {
+ if (journal->j_shrinker) {
percpu_counter_destroy(&journal->j_checkpoint_jh_count);
- unregister_shrinker(&journal->j_shrinker);
+ shrinker_free(journal->j_shrinker);
}
if (journal->j_proc_entry)
jbd2_stats_proc_exit(journal);
diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
index 52772c826c86..6dcbb4eb80fb 100644
--- a/include/linux/jbd2.h
+++ b/include/linux/jbd2.h
@@ -886,7 +886,7 @@ struct journal_s
* Journal head shrinker, reclaim buffer's journal head which
* has been written back.
*/
- struct shrinker j_shrinker;
+ struct shrinker *j_shrinker;
/**
* @j_checkpoint_jh_count:
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v5 31/45] jbd2,ext4: dynamically allocate the jbd2-journal shrinker
2023-08-24 3:42 ` [PATCH v5 31/45] jbd2,ext4: dynamically allocate the jbd2-journal shrinker Qi Zheng
@ 2023-08-24 9:49 ` Jan Kara
0 siblings, 0 replies; 3+ messages in thread
From: Jan Kara @ 2023-08-24 9:49 UTC (permalink / raw)
To: Qi Zheng
Cc: akpm, david, tkhai, vbabka, roman.gushchin, djwong, brauner,
paulmck, tytso, steven.price, cel, senozhatsky, yujie.liu, gregkh,
muchun.song, linux-kernel, linux-mm, linux-fsdevel, Muchun Song,
Jan Kara, linux-ext4
On Thu 24-08-23 11:42:50, Qi Zheng wrote:
> In preparation for implementing lockless slab shrink, use new APIs to
> dynamically allocate the jbd2-journal shrinker, so that it can be freed
> asynchronously via RCU. Then it doesn't need to wait for RCU read-side
> critical section when releasing the struct journal_s.
>
> Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
> Reviewed-by: Muchun Song <songmuchun@bytedance.com>
> CC: "Theodore Ts'o" <tytso@mit.edu>
> CC: Jan Kara <jack@suse.com>
> CC: linux-ext4@vger.kernel.org
Looks good to me. Feel free to add:
Acked-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/jbd2/journal.c | 30 +++++++++++++++++++-----------
> include/linux/jbd2.h | 2 +-
> 2 files changed, 20 insertions(+), 12 deletions(-)
>
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index 768fa05bcbed..75692baa76e8 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -1290,7 +1290,7 @@ static int jbd2_min_tag_size(void)
> static unsigned long jbd2_journal_shrink_scan(struct shrinker *shrink,
> struct shrink_control *sc)
> {
> - journal_t *journal = container_of(shrink, journal_t, j_shrinker);
> + journal_t *journal = shrink->private_data;
> unsigned long nr_to_scan = sc->nr_to_scan;
> unsigned long nr_shrunk;
> unsigned long count;
> @@ -1316,7 +1316,7 @@ static unsigned long jbd2_journal_shrink_scan(struct shrinker *shrink,
> static unsigned long jbd2_journal_shrink_count(struct shrinker *shrink,
> struct shrink_control *sc)
> {
> - journal_t *journal = container_of(shrink, journal_t, j_shrinker);
> + journal_t *journal = shrink->private_data;
> unsigned long count;
>
> count = percpu_counter_read_positive(&journal->j_checkpoint_jh_count);
> @@ -1588,14 +1588,22 @@ static journal_t *journal_init_common(struct block_device *bdev,
> goto err_cleanup;
>
> journal->j_shrink_transaction = NULL;
> - journal->j_shrinker.scan_objects = jbd2_journal_shrink_scan;
> - journal->j_shrinker.count_objects = jbd2_journal_shrink_count;
> - journal->j_shrinker.seeks = DEFAULT_SEEKS;
> - journal->j_shrinker.batch = journal->j_max_transaction_buffers;
> - err = register_shrinker(&journal->j_shrinker, "jbd2-journal:(%u:%u)",
> - MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev));
> - if (err)
> +
> + journal->j_shrinker = shrinker_alloc(0, "jbd2-journal:(%u:%u)",
> + MAJOR(bdev->bd_dev),
> + MINOR(bdev->bd_dev));
> + if (!journal->j_shrinker) {
> + err = -ENOMEM;
> goto err_cleanup;
> + }
> +
> + journal->j_shrinker->scan_objects = jbd2_journal_shrink_scan;
> + journal->j_shrinker->count_objects = jbd2_journal_shrink_count;
> + journal->j_shrinker->seeks = DEFAULT_SEEKS;
> + journal->j_shrinker->batch = journal->j_max_transaction_buffers;
> + journal->j_shrinker->private_data = journal;
> +
> + shrinker_register(journal->j_shrinker);
>
> return journal;
>
> @@ -2170,9 +2178,9 @@ int jbd2_journal_destroy(journal_t *journal)
> brelse(journal->j_sb_buffer);
> }
>
> - if (journal->j_shrinker.flags & SHRINKER_REGISTERED) {
> + if (journal->j_shrinker) {
> percpu_counter_destroy(&journal->j_checkpoint_jh_count);
> - unregister_shrinker(&journal->j_shrinker);
> + shrinker_free(journal->j_shrinker);
> }
> if (journal->j_proc_entry)
> jbd2_stats_proc_exit(journal);
> diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
> index 52772c826c86..6dcbb4eb80fb 100644
> --- a/include/linux/jbd2.h
> +++ b/include/linux/jbd2.h
> @@ -886,7 +886,7 @@ struct journal_s
> * Journal head shrinker, reclaim buffer's journal head which
> * has been written back.
> */
> - struct shrinker j_shrinker;
> + struct shrinker *j_shrinker;
>
> /**
> * @j_checkpoint_jh_count:
> --
> 2.30.2
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-08-24 9:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20230824034304.37411-1-zhengqi.arch@bytedance.com>
2023-08-24 3:42 ` [PATCH v5 30/45] ext4: dynamically allocate the ext4-es shrinker Qi Zheng
2023-08-24 3:42 ` [PATCH v5 31/45] jbd2,ext4: dynamically allocate the jbd2-journal shrinker Qi Zheng
2023-08-24 9:49 ` Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox