From: Eric Sandeen <sandeen@redhat.com>
To: "Theodore Ts'o" <tytso@mit.edu>
Cc: Dave Jones <davej@redhat.com>,
"gnehzuil.liu" <gnehzuil.liu@gmail.com>,
Zheng Liu <wenqing.lz@taobao.com>,
"linux-ext4@vger.kernel.org" <linux-ext4@vger.kernel.org>
Subject: [PATCH] ext4: use percpu counter for extent cache count
Date: Fri, 01 Mar 2013 10:42:25 -0600 [thread overview]
Message-ID: <5130DA71.4040808@redhat.com> (raw)
In-Reply-To: <20130301050029.GB4452@thunk.org>
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>
---
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 96c1093..4a01ba3 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1268,7 +1268,6 @@ struct ext4_sb_info {
atomic_t s_mb_preallocated;
atomic_t s_mb_discarded;
atomic_t s_lock_busy;
- atomic_t s_extent_cache_cnt;
/* locality groups */
struct ext4_locality_group __percpu *s_locality_groups;
@@ -1310,6 +1309,7 @@ struct ext4_sb_info {
/* Reclaim extents from extent status tree */
struct shrinker s_es_shrinker;
struct list_head s_es_lru;
+ struct percpu_counter s_extent_cache_cnt;
spinlock_t s_es_lru_lock ____cacheline_aligned_in_smp;
};
diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
index 27fcdd2..95796a1 100644
--- a/fs/ext4/extents_status.c
+++ b/fs/ext4/extents_status.c
@@ -305,7 +305,7 @@ ext4_es_alloc_extent(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t len,
*/
if (!ext4_es_is_delayed(es)) {
EXT4_I(inode)->i_es_lru_nr++;
- atomic_inc(&EXT4_SB(inode->i_sb)->s_extent_cache_cnt);
+ percpu_counter_inc(&EXT4_SB(inode->i_sb)->s_extent_cache_cnt);
}
return es;
@@ -317,7 +317,7 @@ static void ext4_es_free_extent(struct inode *inode, struct extent_status *es)
if (!ext4_es_is_delayed(es)) {
BUG_ON(EXT4_I(inode)->i_es_lru_nr == 0);
EXT4_I(inode)->i_es_lru_nr--;
- atomic_dec(&EXT4_SB(inode->i_sb)->s_extent_cache_cnt);
+ percpu_counter_dec(&EXT4_SB(inode->i_sb)->s_extent_cache_cnt);
}
kmem_cache_free(ext4_es_cachep, es);
@@ -678,7 +678,7 @@ static int ext4_es_shrink(struct shrinker *shrink, struct shrink_control *sc)
int nr_to_scan = sc->nr_to_scan;
int ret, nr_shrunk = 0;
- ret = atomic_read(&sbi->s_extent_cache_cnt);
+ ret = percpu_counter_read_positive(&sbi->s_extent_cache_cnt);
trace_ext4_es_shrink_enter(sbi->s_sb, nr_to_scan, ret);
if (!nr_to_scan)
@@ -711,7 +711,7 @@ static int ext4_es_shrink(struct shrinker *shrink, struct shrink_control *sc)
list_splice_tail(&scanned, &sbi->s_es_lru);
spin_unlock(&sbi->s_es_lru_lock);
- ret = atomic_read(&sbi->s_extent_cache_cnt);
+ ret = percpu_counter_read_positive(&sbi->s_extent_cache_cnt);
trace_ext4_es_shrink_exit(sbi->s_sb, nr_shrunk, ret);
return ret;
}
next prev parent reply other threads:[~2013-03-01 16:42 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-26 20:39 [GIT PULL] ext4 updates for 3.9 Theodore Ts'o
2013-02-27 12:47 ` Markus Trippelsdorf
2013-02-27 15:34 ` Theodore Ts'o
2013-02-27 15:44 ` Markus Trippelsdorf
2013-02-27 17:01 ` Markus Trippelsdorf
2013-02-27 17:10 ` gnehzuil.liu
2013-02-27 17:10 ` gnehzuil.liu
2013-02-27 17:22 ` Markus Trippelsdorf
2013-02-27 17:38 ` gnehzuil.liu
2013-02-27 17:38 ` gnehzuil.liu
2013-02-27 17:45 ` Markus Trippelsdorf
2013-02-27 17:52 ` Linus Torvalds
2013-02-27 18:49 ` Theodore Ts'o
2013-02-27 18:56 ` Markus Trippelsdorf
2013-02-27 19:19 ` Dave Jones
2013-02-27 19:27 ` Zheng Liu
2013-02-27 19:29 ` Theodore Ts'o
2013-02-27 20:12 ` [GIT PULL URGENT] ext4 regression fix " Linus Torvalds
2013-02-27 20:15 ` Theodore Ts'o
2013-02-27 20:23 ` Linus Torvalds
2013-02-27 20:41 ` Borislav Petkov
2013-03-01 3:30 ` Dave Jones
2013-03-01 4:00 ` Theodore Ts'o
2013-03-01 5:00 ` [PATCH] ext4: optimize ext4_es_shrink() Theodore Ts'o
2013-03-01 16:11 ` Dave Jones
2013-03-01 16:26 ` Theodore Ts'o
2013-03-01 16:40 ` Dave Jones
2013-03-01 16:40 ` Eric Sandeen
2013-03-01 16:42 ` Eric Sandeen [this message]
2013-03-01 18:00 ` [PATCH] ext4: use percpu counter for extent cache count Theodore Ts'o
2013-03-01 18:02 ` Eric Sandeen
2013-03-02 15:26 ` Theodore Ts'o
2013-03-03 16:39 ` Zheng Liu
2013-03-04 16:11 ` Eric Sandeen
2013-03-02 19:54 ` [GIT PULL URGENT] ext4 regression fix for 3.9 Linus Torvalds
2013-03-02 23:15 ` Theodore Ts'o
2013-02-27 20:14 ` Theodore Ts'o
2013-02-27 20:58 ` [GIT PULL] ext4 updates " Dmitry Monakhov
2013-02-27 21:30 ` Theodore Ts'o
2013-03-01 15:41 ` Eric Sandeen
2013-02-28 13:18 ` Dave Chinner
2013-02-27 18:57 ` Dave Jones
2013-02-27 19:04 ` Theodore Ts'o
2013-02-27 19:11 ` Dave Jones
2013-02-27 19:19 ` Theodore Ts'o
2013-02-27 18:59 ` Zheng Liu
2013-02-27 19:06 ` Borislav Petkov
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=5130DA71.4040808@redhat.com \
--to=sandeen@redhat.com \
--cc=davej@redhat.com \
--cc=gnehzuil.liu@gmail.com \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=wenqing.lz@taobao.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.