Skip to content

Commit 1ac6466

Browse files
committed
ext4: use percpu counter for extent cache count
Use a percpu counter rather than atomic types for shrinker accounting. There's no need for ultimate accuracy in the shrinker, so this should come a little more cheaply. The percpu struct is somewhat large, but there was a big gap before the cache-aligned s_es_lru_lock anyway, and it fits nicely in there. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent 2463077 commit 1ac6466

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

fs/ext4/ext4.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,6 @@ struct ext4_sb_info {
12681268
atomic_t s_mb_preallocated;
12691269
atomic_t s_mb_discarded;
12701270
atomic_t s_lock_busy;
1271-
atomic_t s_extent_cache_cnt;
12721271

12731272
/* locality groups */
12741273
struct ext4_locality_group __percpu *s_locality_groups;
@@ -1310,6 +1309,7 @@ struct ext4_sb_info {
13101309
/* Reclaim extents from extent status tree */
13111310
struct shrinker s_es_shrinker;
13121311
struct list_head s_es_lru;
1312+
struct percpu_counter s_extent_cache_cnt;
13131313
spinlock_t s_es_lru_lock ____cacheline_aligned_in_smp;
13141314
};
13151315

fs/ext4/extents_status.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ ext4_es_alloc_extent(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t len,
305305
*/
306306
if (!ext4_es_is_delayed(es)) {
307307
EXT4_I(inode)->i_es_lru_nr++;
308-
atomic_inc(&EXT4_SB(inode->i_sb)->s_extent_cache_cnt);
308+
percpu_counter_inc(&EXT4_SB(inode->i_sb)->s_extent_cache_cnt);
309309
}
310310

311311
return es;
@@ -317,7 +317,7 @@ static void ext4_es_free_extent(struct inode *inode, struct extent_status *es)
317317
if (!ext4_es_is_delayed(es)) {
318318
BUG_ON(EXT4_I(inode)->i_es_lru_nr == 0);
319319
EXT4_I(inode)->i_es_lru_nr--;
320-
atomic_dec(&EXT4_SB(inode->i_sb)->s_extent_cache_cnt);
320+
percpu_counter_dec(&EXT4_SB(inode->i_sb)->s_extent_cache_cnt);
321321
}
322322

323323
kmem_cache_free(ext4_es_cachep, es);
@@ -678,7 +678,7 @@ static int ext4_es_shrink(struct shrinker *shrink, struct shrink_control *sc)
678678
int nr_to_scan = sc->nr_to_scan;
679679
int ret, nr_shrunk = 0;
680680

681-
ret = atomic_read(&sbi->s_extent_cache_cnt);
681+
ret = percpu_counter_read_positive(&sbi->s_extent_cache_cnt);
682682
trace_ext4_es_shrink_enter(sbi->s_sb, nr_to_scan, ret);
683683

684684
if (!nr_to_scan)
@@ -711,7 +711,7 @@ static int ext4_es_shrink(struct shrinker *shrink, struct shrink_control *sc)
711711
list_splice_tail(&scanned, &sbi->s_es_lru);
712712
spin_unlock(&sbi->s_es_lru_lock);
713713

714-
ret = atomic_read(&sbi->s_extent_cache_cnt);
714+
ret = percpu_counter_read_positive(&sbi->s_extent_cache_cnt);
715715
trace_ext4_es_shrink_exit(sbi->s_sb, nr_shrunk, ret);
716716
return ret;
717717
}

fs/ext4/super.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ static void ext4_put_super(struct super_block *sb)
783783
percpu_counter_destroy(&sbi->s_freeinodes_counter);
784784
percpu_counter_destroy(&sbi->s_dirs_counter);
785785
percpu_counter_destroy(&sbi->s_dirtyclusters_counter);
786+
percpu_counter_destroy(&sbi->s_extent_cache_cnt);
786787
brelse(sbi->s_sbh);
787788
#ifdef CONFIG_QUOTA
788789
for (i = 0; i < MAXQUOTAS; i++)
@@ -3688,6 +3689,9 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
36883689
if (!err) {
36893690
err = percpu_counter_init(&sbi->s_dirtyclusters_counter, 0);
36903691
}
3692+
if (!err) {
3693+
err = percpu_counter_init(&sbi->s_extent_cache_cnt, 0);
3694+
}
36913695
if (err) {
36923696
ext4_msg(sb, KERN_ERR, "insufficient memory");
36933697
goto failed_mount3;
@@ -3993,6 +3997,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
39933997
percpu_counter_destroy(&sbi->s_freeinodes_counter);
39943998
percpu_counter_destroy(&sbi->s_dirs_counter);
39953999
percpu_counter_destroy(&sbi->s_dirtyclusters_counter);
4000+
percpu_counter_destroy(&sbi->s_extent_cache_cnt);
39964001
if (sbi->s_mmp_tsk)
39974002
kthread_stop(sbi->s_mmp_tsk);
39984003
failed_mount2:

0 commit comments

Comments
 (0)