2011-05-17 22:27:04

by Vivek Haldar

[permalink] [raw]
Subject: [PATCH] ext4: count hits/misses of extent cache and expose in sysfs.

The number of hits and misses for each filesystem is exposed in
/sys/fs/ext4/<dev>/extent_cache_{hits, misses}.

Tested: fsstress, manual checks.
Signed-off-by: Vivek Haldar <[email protected]>
---
fs/ext4/ext4.h | 3 +++
fs/ext4/extents.c | 7 ++++++-
fs/ext4/super.c | 16 ++++++++++++++++
3 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 47986ae..9625b19 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1144,6 +1144,9 @@ struct ext4_sb_info {
unsigned long s_ext_blocks;
unsigned long s_ext_extents;
#endif
+ /* ext4 extent cache stats */
+ unsigned long extent_cache_hits;
+ unsigned long extent_cache_misses;

/* for buddy allocator */
struct ext4_group_info ***s_group_info;
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index e363f21..1ea440a 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -2035,6 +2035,7 @@ ext4_ext_in_cache(struct inode *inode, ext4_lblk_t block,
struct ext4_extent *ex)
{
struct ext4_ext_cache *cex;
+ struct ext4_sb_info *sbi;
int ret = 0;

/*
@@ -2042,6 +2043,7 @@ ext4_ext_in_cache(struct inode *inode, ext4_lblk_t block,
*/
spin_lock(&EXT4_I(inode)->i_block_reservation_lock);
cex = &EXT4_I(inode)->i_cached_extent;
+ sbi = EXT4_SB(inode->i_sb);

/* has cache valid data? */
if (cex->ec_len == 0)
@@ -2057,6 +2059,10 @@ ext4_ext_in_cache(struct inode *inode, ext4_lblk_t block,
ret = 1;
}
errout:
+ if (!ret)
+ sbi->extent_cache_misses++;
+ else
+ sbi->extent_cache_hits++;
spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
return ret;
}
@@ -3900,4 +3906,3 @@ int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,

return error;
}
-
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index fc827bb..20cc98f 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -2439,6 +2439,18 @@ static ssize_t lifetime_write_kbytes_show(struct ext4_attr *a,
EXT4_SB(sb)->s_sectors_written_start) >> 1)));
}

+static ssize_t extent_cache_hits_show(struct ext4_attr *a,
+ struct ext4_sb_info *sbi, char *buf)
+{
+ return snprintf(buf, PAGE_SIZE, "%lu\n", sbi->extent_cache_hits);
+}
+
+static ssize_t extent_cache_misses_show(struct ext4_attr *a,
+ struct ext4_sb_info *sbi, char *buf)
+{
+ return snprintf(buf, PAGE_SIZE, "%lu\n", sbi->extent_cache_misses);
+}
+
static ssize_t inode_readahead_blks_store(struct ext4_attr *a,
struct ext4_sb_info *sbi,
const char *buf, size_t count)
@@ -2496,6 +2508,8 @@ static struct ext4_attr ext4_attr_##name = __ATTR(name, mode, show, store)
EXT4_RO_ATTR(delayed_allocation_blocks);
EXT4_RO_ATTR(session_write_kbytes);
EXT4_RO_ATTR(lifetime_write_kbytes);
+EXT4_RO_ATTR(extent_cache_hits);
+EXT4_RO_ATTR(extent_cache_misses);
EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, sbi_ui_show,
inode_readahead_blks_store, s_inode_readahead_blks);
EXT4_RW_ATTR_SBI_UI(inode_goal, s_inode_goal);
@@ -2511,6 +2525,8 @@ static struct attribute *ext4_attrs[] = {
ATTR_LIST(delayed_allocation_blocks),
ATTR_LIST(session_write_kbytes),
ATTR_LIST(lifetime_write_kbytes),
+ ATTR_LIST(extent_cache_hits),
+ ATTR_LIST(extent_cache_misses),
ATTR_LIST(inode_readahead_blks),
ATTR_LIST(inode_goal),
ATTR_LIST(mb_stats),
--
1.7.3.1



2011-05-17 22:57:45

by Andreas Dilger

[permalink] [raw]
Subject: Re: [PATCH] ext4: count hits/misses of extent cache and expose in sysfs.

On May 17, 2011, at 16:26, Vivek Haldar wrote:
> The number of hits and misses for each filesystem is exposed in
> /sys/fs/ext4/<dev>/extent_cache_{hits, misses}.

There was some discussion on the ext4 concall whether the use of the ext4 extent cache is preventing extent and/or index blocks from being "touched", and possibly causing them to be dropped from cache prematurely.

If you are currently investigating this area of the code it would be good if you could take a look at the code to determine if this is the case or not.

> Tested: fsstress, manual checks.
> Signed-off-by: Vivek Haldar <[email protected]>
> ---
> fs/ext4/ext4.h | 3 +++
> fs/ext4/extents.c | 7 ++++++-
> fs/ext4/super.c | 16 ++++++++++++++++
> 3 files changed, 25 insertions(+), 1 deletions(-)
>
> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
> index 47986ae..9625b19 100644
> --- a/fs/ext4/ext4.h
> +++ b/fs/ext4/ext4.h
> @@ -1144,6 +1144,9 @@ struct ext4_sb_info {
> unsigned long s_ext_blocks;
> unsigned long s_ext_extents;
> #endif
> + /* ext4 extent cache stats */
> + unsigned long extent_cache_hits;
> + unsigned long extent_cache_misses;
>
> /* for buddy allocator */
> struct ext4_group_info ***s_group_info;
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index e363f21..1ea440a 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -2035,6 +2035,7 @@ ext4_ext_in_cache(struct inode *inode, ext4_lblk_t block,
> struct ext4_extent *ex)
> {
> struct ext4_ext_cache *cex;
> + struct ext4_sb_info *sbi;
> int ret = 0;
>
> /*
> @@ -2042,6 +2043,7 @@ ext4_ext_in_cache(struct inode *inode, ext4_lblk_t block,
> */
> spin_lock(&EXT4_I(inode)->i_block_reservation_lock);
> cex = &EXT4_I(inode)->i_cached_extent;
> + sbi = EXT4_SB(inode->i_sb);
>
> /* has cache valid data? */
> if (cex->ec_len == 0)
> @@ -2057,6 +2059,10 @@ ext4_ext_in_cache(struct inode *inode, ext4_lblk_t block,
> ret = 1;
> }
> errout:
> + if (!ret)
> + sbi->extent_cache_misses++;
> + else
> + sbi->extent_cache_hits++;
> spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
> return ret;
> }
> @@ -3900,4 +3906,3 @@ int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
>
> return error;
> }
> -
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index fc827bb..20cc98f 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -2439,6 +2439,18 @@ static ssize_t lifetime_write_kbytes_show(struct ext4_attr *a,
> EXT4_SB(sb)->s_sectors_written_start) >> 1)));
> }
>
> +static ssize_t extent_cache_hits_show(struct ext4_attr *a,
> + struct ext4_sb_info *sbi, char *buf)
> +{
> + return snprintf(buf, PAGE_SIZE, "%lu\n", sbi->extent_cache_hits);
> +}
> +
> +static ssize_t extent_cache_misses_show(struct ext4_attr *a,
> + struct ext4_sb_info *sbi, char *buf)
> +{
> + return snprintf(buf, PAGE_SIZE, "%lu\n", sbi->extent_cache_misses);
> +}
> +
> static ssize_t inode_readahead_blks_store(struct ext4_attr *a,
> struct ext4_sb_info *sbi,
> const char *buf, size_t count)
> @@ -2496,6 +2508,8 @@ static struct ext4_attr ext4_attr_##name = __ATTR(name, mode, show, store)
> EXT4_RO_ATTR(delayed_allocation_blocks);
> EXT4_RO_ATTR(session_write_kbytes);
> EXT4_RO_ATTR(lifetime_write_kbytes);
> +EXT4_RO_ATTR(extent_cache_hits);
> +EXT4_RO_ATTR(extent_cache_misses);
> EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, sbi_ui_show,
> inode_readahead_blks_store, s_inode_readahead_blks);
> EXT4_RW_ATTR_SBI_UI(inode_goal, s_inode_goal);
> @@ -2511,6 +2525,8 @@ static struct attribute *ext4_attrs[] = {
> ATTR_LIST(delayed_allocation_blocks),
> ATTR_LIST(session_write_kbytes),
> ATTR_LIST(lifetime_write_kbytes),
> + ATTR_LIST(extent_cache_hits),
> + ATTR_LIST(extent_cache_misses),
> ATTR_LIST(inode_readahead_blks),
> ATTR_LIST(inode_goal),
> ATTR_LIST(mb_stats),
> --
> 1.7.3.1
>


Cheers, Andreas






2011-05-17 23:06:09

by Vivek Haldar

[permalink] [raw]
Subject: Re: [PATCH] ext4: count hits/misses of extent cache and expose in sysfs.

On Tue, May 17, 2011 at 3:57 PM, Andreas Dilger
<[email protected]> wrote:
> On May 17, 2011, at 16:26, Vivek Haldar wrote:
>> The number of hits and misses for each filesystem is exposed in
>> /sys/fs/ext4/<dev>/extent_cache_{hits, misses}.
>
> There was some discussion on the ext4 concall whether the use of the ext4 extent cache is preventing extent and/or index blocks from being "touched", and possibly causing them to be dropped from cache prematurely.
>
> If you are currently investigating this area of the code it would be good if you could take a look at the code to determine if this is the case or not.

I wasn't looking at that issue specifically, but now that you mention
it, I'll keep an eye out for it.

>
>> Tested: fsstress, manual checks.
>> Signed-off-by: Vivek Haldar <[email protected]>
>> ---
>> fs/ext4/ext4.h ? ?| ? ?3 +++
>> fs/ext4/extents.c | ? ?7 ++++++-
>> fs/ext4/super.c ? | ? 16 ++++++++++++++++
>> 3 files changed, 25 insertions(+), 1 deletions(-)
>>
>> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
>> index 47986ae..9625b19 100644
>> --- a/fs/ext4/ext4.h
>> +++ b/fs/ext4/ext4.h
>> @@ -1144,6 +1144,9 @@ struct ext4_sb_info {
>> ? ? ? unsigned long s_ext_blocks;
>> ? ? ? unsigned long s_ext_extents;
>> #endif
>> + ? ? /* ext4 extent cache stats */
>> + ? ? unsigned long extent_cache_hits;
>> + ? ? unsigned long extent_cache_misses;
>>
>> ? ? ? /* for buddy allocator */
>> ? ? ? struct ext4_group_info ***s_group_info;
>> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
>> index e363f21..1ea440a 100644
>> --- a/fs/ext4/extents.c
>> +++ b/fs/ext4/extents.c
>> @@ -2035,6 +2035,7 @@ ext4_ext_in_cache(struct inode *inode, ext4_lblk_t block,
>> ? ? ? ? ? ? ? ? ? ? ? struct ext4_extent *ex)
>> {
>> ? ? ? struct ext4_ext_cache *cex;
>> + ? ? struct ext4_sb_info *sbi;
>> ? ? ? int ret = 0;
>>
>> ? ? ? /*
>> @@ -2042,6 +2043,7 @@ ext4_ext_in_cache(struct inode *inode, ext4_lblk_t block,
>> ? ? ? ?*/
>> ? ? ? spin_lock(&EXT4_I(inode)->i_block_reservation_lock);
>> ? ? ? cex = &EXT4_I(inode)->i_cached_extent;
>> + ? ? sbi = EXT4_SB(inode->i_sb);
>>
>> ? ? ? /* has cache valid data? */
>> ? ? ? if (cex->ec_len == 0)
>> @@ -2057,6 +2059,10 @@ ext4_ext_in_cache(struct inode *inode, ext4_lblk_t block,
>> ? ? ? ? ? ? ? ret = 1;
>> ? ? ? }
>> errout:
>> + ? ? if (!ret)
>> + ? ? ? ? ? ? sbi->extent_cache_misses++;
>> + ? ? else
>> + ? ? ? ? ? ? sbi->extent_cache_hits++;
>> ? ? ? spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
>> ? ? ? return ret;
>> }
>> @@ -3900,4 +3906,3 @@ int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
>>
>> ? ? ? return error;
>> }
>> -
>> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
>> index fc827bb..20cc98f 100644
>> --- a/fs/ext4/super.c
>> +++ b/fs/ext4/super.c
>> @@ -2439,6 +2439,18 @@ static ssize_t lifetime_write_kbytes_show(struct ext4_attr *a,
>> ? ? ? ? ? ? ? ? ? ? ? ? EXT4_SB(sb)->s_sectors_written_start) >> 1)));
>> }
>>
>> +static ssize_t extent_cache_hits_show(struct ext4_attr *a,
>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? struct ext4_sb_info *sbi, char *buf)
>> +{
>> + ? ? return snprintf(buf, PAGE_SIZE, "%lu\n", sbi->extent_cache_hits);
>> +}
>> +
>> +static ssize_t extent_cache_misses_show(struct ext4_attr *a,
>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? struct ext4_sb_info *sbi, char *buf)
>> +{
>> + ? ? return snprintf(buf, PAGE_SIZE, "%lu\n", sbi->extent_cache_misses);
>> +}
>> +
>> static ssize_t inode_readahead_blks_store(struct ext4_attr *a,
>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? struct ext4_sb_info *sbi,
>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? const char *buf, size_t count)
>> @@ -2496,6 +2508,8 @@ static struct ext4_attr ext4_attr_##name = __ATTR(name, mode, show, store)
>> EXT4_RO_ATTR(delayed_allocation_blocks);
>> EXT4_RO_ATTR(session_write_kbytes);
>> EXT4_RO_ATTR(lifetime_write_kbytes);
>> +EXT4_RO_ATTR(extent_cache_hits);
>> +EXT4_RO_ATTR(extent_cache_misses);
>> EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, sbi_ui_show,
>> ? ? ? ? ? ? ? ?inode_readahead_blks_store, s_inode_readahead_blks);
>> EXT4_RW_ATTR_SBI_UI(inode_goal, s_inode_goal);
>> @@ -2511,6 +2525,8 @@ static struct attribute *ext4_attrs[] = {
>> ? ? ? ATTR_LIST(delayed_allocation_blocks),
>> ? ? ? ATTR_LIST(session_write_kbytes),
>> ? ? ? ATTR_LIST(lifetime_write_kbytes),
>> + ? ? ATTR_LIST(extent_cache_hits),
>> + ? ? ATTR_LIST(extent_cache_misses),
>> ? ? ? ATTR_LIST(inode_readahead_blks),
>> ? ? ? ATTR_LIST(inode_goal),
>> ? ? ? ATTR_LIST(mb_stats),
>> --
>> 1.7.3.1
>>
>
>
> Cheers, Andreas
>
>
>
>
>
>



--
Regards,
Vivek

2011-05-18 15:14:53

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH] ext4: count hits/misses of extent cache and expose in sysfs.

On Tue, May 17, 2011 at 04:05:51PM -0700, Vivek Haldar wrote:
>
> I wasn't looking at that issue specifically, but now that you mention
> it, I'll keep an eye out for it.

Vivek,

There's an internal Google bug that mentioned this; look at the
extent.c optimization feature request bugs that I had filed...

- Ted

2011-05-23 01:30:33

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH] ext4: count hits/misses of extent cache and expose in sysfs.

On Tue, May 17, 2011 at 03:26:53PM -0700, Vivek Haldar wrote:
> The number of hits and misses for each filesystem is exposed in
> /sys/fs/ext4/<dev>/extent_cache_{hits, misses}.
>
> Tested: fsstress, manual checks.
> Signed-off-by: Vivek Haldar <[email protected]>

Added to the ext4 tree, thanks.

-- Ted