2014-08-13 13:37:23

by Chin-Tsung Cheng

[permalink] [raw]
Subject: [PATCH] ext4: include journal blocks of internal journal in df overhead calcs

The journal blocks of external journal device should not
be counted as overhead.

Signed-off-by: Chin-Tsung Cheng <[email protected]>
---
fs/ext4/super.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 32b43ad..03b2f62 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -3316,9 +3316,10 @@ int ext4_calculate_overhead(struct super_block *sb)
memset(buf, 0, PAGE_SIZE);
cond_resched();
}
- /* Add the journal blocks as well */
- if (sbi->s_journal)
- overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_maxlen);
+ /* Add the internal journal blocks as well */
+ if ((sbi->s_journal) &&
+ (sbi->s_journal->j_fs_dev == sbi->s_journal->j_dev))
+ overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_maxlen);

sbi->s_overhead = overhead;
smp_wmb();
--
1.9.3


2014-08-13 22:55:43

by Darrick J. Wong

[permalink] [raw]
Subject: Re: [PATCH] ext4: include journal blocks of internal journal in df overhead calcs

On Wed, Aug 13, 2014 at 09:37:23PM +0800, Chin-Tsung Cheng wrote:
> The journal blocks of external journal device should not
> be counted as overhead.
>
> Signed-off-by: Chin-Tsung Cheng <[email protected]>
> ---
> fs/ext4/super.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 32b43ad..03b2f62 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -3316,9 +3316,10 @@ int ext4_calculate_overhead(struct super_block *sb)
> memset(buf, 0, PAGE_SIZE);
> cond_resched();
> }
> - /* Add the journal blocks as well */
> - if (sbi->s_journal)
> - overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_maxlen);
> + /* Add the internal journal blocks as well */
> + if ((sbi->s_journal) &&
> + (sbi->s_journal->j_fs_dev == sbi->s_journal->j_dev))
> + overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_maxlen);

I think you have some whitespace issues here, but otherwise this seems ok.

External journals aren't counted towards the total blocks count, correct?

--D
>
> sbi->s_overhead = overhead;
> smp_wmb();
> --
> 1.9.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2014-08-14 03:21:07

by Eric Sandeen

[permalink] [raw]
Subject: Re: [PATCH] ext4: include journal blocks of internal journal in df overhead calcs

On 8/13/14, 6:37 AM, Chin-Tsung Cheng wrote:
> The journal blocks of external journal device should not
> be counted as overhead.
>
> Signed-off-by: Chin-Tsung Cheng <[email protected]>

Yep, I added this and didn't consider external journals, oops.

Agree with Darrick that whitespace (and parens) aren't ideal...

Is this a shorter test?

if (sbi->s_journal && !sbi->journal_bdev) {
overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_maxlen);


*sbi gets kzalloced and I *think* journal_bdev is only filled in for
external journals...

ext3_statfs probably needs the same treatment, it unconditionally does:


/* Add the journal blocks as well */
overhead += sbi->s_journal->j_maxlen;

-Eric

> ---
> fs/ext4/super.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 32b43ad..03b2f62 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -3316,9 +3316,10 @@ int ext4_calculate_overhead(struct super_block *sb)
> memset(buf, 0, PAGE_SIZE);
> cond_resched();
> }
> - /* Add the journal blocks as well */
> - if (sbi->s_journal)
> - overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_maxlen);
> + /* Add the internal journal blocks as well */
> + if ((sbi->s_journal) &&
> + (sbi->s_journal->j_fs_dev == sbi->s_journal->j_dev))
> + overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_maxlen);
>
> sbi->s_overhead = overhead;
> smp_wmb();
>


2014-08-14 06:56:26

by Chin-Tsung Cheng

[permalink] [raw]
Subject: Re: [PATCH] ext4: include journal blocks of internal journal in df overhead calcs

2014-08-14 11:21 GMT+08:00 Eric Sandeen <[email protected]>:
> On 8/13/14, 6:37 AM, Chin-Tsung Cheng wrote:
>> The journal blocks of external journal device should not
>> be counted as overhead.
>>
>> Signed-off-by: Chin-Tsung Cheng <[email protected]>
>
> Yep, I added this and didn't consider external journals, oops.
>
> Agree with Darrick that whitespace (and parens) aren't ideal...
>
OK. I will fix it.
> Is this a shorter test?
>
> if (sbi->s_journal && !sbi->journal_bdev) {
> overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_maxlen);
>
>
> *sbi gets kzalloced and I *think* journal_bdev is only filled in for
> external journals...

Yes, journal_bdev is only filled in ext4_get_dev_journal() function
for external journal device.
>
> ext3_statfs probably needs the same treatment, it unconditionally does:
>
>
> /* Add the journal blocks as well */
> overhead += sbi->s_journal->j_maxlen;
>
Yes, it also miscalculates the number of file system overhead blocks
for external journal device. This causes the f_blocks field in the
statfs
structure to be smaller than it should be.

This would cause the "df" output to show the number of data blocks in
the file system smaller than they should be, and the number of used
blocks might be negative.

> -Eric
>
>> ---
>> fs/ext4/super.c | 7 ++++---
>> 1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
>> index 32b43ad..03b2f62 100644
>> --- a/fs/ext4/super.c
>> +++ b/fs/ext4/super.c
>> @@ -3316,9 +3316,10 @@ int ext4_calculate_overhead(struct super_block *sb)
>> memset(buf, 0, PAGE_SIZE);
>> cond_resched();
>> }
>> - /* Add the journal blocks as well */
>> - if (sbi->s_journal)
>> - overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_maxlen);
>> + /* Add the internal journal blocks as well */
>> + if ((sbi->s_journal) &&
>> + (sbi->s_journal->j_fs_dev == sbi->s_journal->j_dev))
>> + overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_maxlen);
>>
>> sbi->s_overhead = overhead;
>> smp_wmb();
>>
>