* [PATCH] ext4: issue aligned discards
@ 2020-06-05 22:28 Harshad Shirwadkar
2020-06-08 7:35 ` Christoph Hellwig
0 siblings, 1 reply; 4+ messages in thread
From: Harshad Shirwadkar @ 2020-06-05 22:28 UTC (permalink / raw)
To: linux-ext4; +Cc: Harshad Shirwadkar
Ext4 before this patch can issue discards without respecting block
device's discard alignment. Such a discard results in EIO and
kernel logs.
Verified that there were no regressions in xfstests smoke tests.
Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
---
fs/ext4/mballoc.c | 32 +++++++++++++++++++++-----------
include/linux/blkdev.h | 7 +++++++
2 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 30d5d97548c4..a591a3ab93d3 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -2786,20 +2786,30 @@ static inline int ext4_issue_discard(struct super_block *sb,
ext4_group_t block_group, ext4_grpblk_t cluster, int count,
struct bio **biop)
{
- ext4_fsblk_t discard_block;
-
- discard_block = (EXT4_C2B(EXT4_SB(sb), cluster) +
- ext4_group_first_block_no(sb, block_group));
- count = EXT4_C2B(EXT4_SB(sb), count);
+ unsigned long long discard_start, discard_len, alignment, granularity,
+ aligned_discard_start;
+
+ granularity = max(bdev_discard_granularity(sb->s_bdev), 1 << 9);
+ alignment = max_t(int, bdev_logical_block_size(sb->s_bdev),
+ bdev_discard_alignment(sb->s_bdev));
+ discard_start = (EXT4_C2B(EXT4_SB(sb), cluster) +
+ ext4_group_first_block_no(sb, block_group)) <<
+ sb->s_blocksize_bits;
+ discard_len = EXT4_C2B(EXT4_SB(sb), count) << sb->s_blocksize_bits;
+ aligned_discard_start = round_up(discard_start, alignment);
+ discard_len -= min(discard_len, aligned_discard_start - discard_start);
+ discard_len = round_down(discard_len, granularity);
+ if (discard_len >> 9 == 0)
+ return 0;
trace_ext4_discard_blocks(sb,
- (unsigned long long) discard_block, count);
- if (biop) {
+ aligned_discard_start >> sb->s_blocksize_bits,
+ discard_len >> (sb->s_blocksize_bits));
+ if (biop)
return __blkdev_issue_discard(sb->s_bdev,
- (sector_t)discard_block << (sb->s_blocksize_bits - 9),
- (sector_t)count << (sb->s_blocksize_bits - 9),
+ aligned_discard_start >> 9, discard_len >> 9,
GFP_NOFS, 0, biop);
- } else
- return sb_issue_discard(sb, discard_block, count, GFP_NOFS, 0);
+ return sb_issue_discard(sb, aligned_discard_start, discard_len,
+ GFP_NOFS, 0);
}
static void ext4_free_data_in_buddy(struct super_block *sb,
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 8fd900998b4e..f448b3498336 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1431,6 +1431,13 @@ static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector
return offset << SECTOR_SHIFT;
}
+static inline int bdev_discard_granularity(struct block_device *bdev)
+{
+ struct request_queue *q = bdev_get_queue(bdev);
+
+ return q ? q->limits.discard_granularity : 0;
+}
+
static inline int bdev_discard_alignment(struct block_device *bdev)
{
struct request_queue *q = bdev_get_queue(bdev);
--
2.27.0.278.ge193c7cf3a9-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ext4: issue aligned discards
2020-06-05 22:28 [PATCH] ext4: issue aligned discards Harshad Shirwadkar
@ 2020-06-08 7:35 ` Christoph Hellwig
2020-06-12 17:31 ` harshad shirwadkar
0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2020-06-08 7:35 UTC (permalink / raw)
To: Harshad Shirwadkar; +Cc: linux-ext4
On Fri, Jun 05, 2020 at 03:28:19PM -0700, Harshad Shirwadkar wrote:
> Ext4 before this patch can issue discards without respecting block
> device's discard alignment. Such a discard results in EIO and
> kernel logs.
No, that is not how discard works. The granularity is a hint and
blk_bio_discard_split already does all the work to align to it. If
you have a make_request based driver that doesn't do that you need
to fix that driver instead.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ext4: issue aligned discards
2020-06-08 7:35 ` Christoph Hellwig
@ 2020-06-12 17:31 ` harshad shirwadkar
0 siblings, 0 replies; 4+ messages in thread
From: harshad shirwadkar @ 2020-06-12 17:31 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Ext4 Developers List
On Mon, Jun 8, 2020 at 12:35 AM Christoph Hellwig <hch@infradead.org> wrote:
>
> On Fri, Jun 05, 2020 at 03:28:19PM -0700, Harshad Shirwadkar wrote:
> > Ext4 before this patch can issue discards without respecting block
> > device's discard alignment. Such a discard results in EIO and
> > kernel logs.
>
> No, that is not how discard works. The granularity is a hint and
> blk_bio_discard_split already does all the work to align to it. If
> you have a make_request based driver that doesn't do that you need
> to fix that driver instead.
Thanks for the clarification, my commit message was wrong. Fixing the
driver instead is the right solution here. But, if doing discard
alignment in Ext4 can increase the chances of discards being
successful, is there any harm in doing it in Ext4 too?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ext4: issue aligned discards
@ 2020-06-06 8:04 kernel test robot
0 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2020-06-06 8:04 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 4885 bytes --]
CC: kbuild-all(a)lists.01.org
In-Reply-To: <20200605222819.19762-1-harshadshirwadkar@gmail.com>
References: <20200605222819.19762-1-harshadshirwadkar@gmail.com>
TO: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
TO: linux-ext4(a)vger.kernel.org
CC: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Hi Harshad,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on ext4/dev]
[also build test WARNING on linus/master v5.7 next-20200605]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Harshad-Shirwadkar/ext4-issue-aligned-discards/20200606-062859
base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
:::::: branch date: 10 hours ago
:::::: commit date: 10 hours ago
config: x86_64-randconfig-m001-20200606 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-13) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
New smatch warnings:
fs/ext4/mballoc.c:2892 ext4_issue_discard() warn: should '(count << (EXT4_SB(sb))->s_cluster_bits) << sb->s_blocksize_bits' be a 64 bit type?
Old smatch warnings:
fs/ext4/mballoc.c:1513 mb_free_blocks() warn: should 'block << sbi->s_cluster_bits' be a 64 bit type?
fs/ext4/mballoc.c:4572 ext4_mb_release_context() warn: should '(ac->ac_b_ex.fe_len) << sbi->s_cluster_bits' be a 64 bit type?
# https://github.com/0day-ci/linux/commit/0f8171737cc63a003f5ea31602ff655601770350
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout 0f8171737cc63a003f5ea31602ff655601770350
vim +2892 fs/ext4/mballoc.c
c9de560ded61fa Alex Tomas 2008-01-29 2878
77ca6cdf0ab8a4 Lukas Czerner 2010-10-27 2879 static inline int ext4_issue_discard(struct super_block *sb,
a015434480dcdb Daeho Jeong 2017-06-22 2880 ext4_group_t block_group, ext4_grpblk_t cluster, int count,
a015434480dcdb Daeho Jeong 2017-06-22 2881 struct bio **biop)
5c521830cf3dfc Jiaying Zhang 2010-07-27 2882 {
0f8171737cc63a Harshad Shirwadkar 2020-06-05 2883 unsigned long long discard_start, discard_len, alignment, granularity,
0f8171737cc63a Harshad Shirwadkar 2020-06-05 2884 aligned_discard_start;
0f8171737cc63a Harshad Shirwadkar 2020-06-05 2885
0f8171737cc63a Harshad Shirwadkar 2020-06-05 2886 granularity = max(bdev_discard_granularity(sb->s_bdev), 1 << 9);
0f8171737cc63a Harshad Shirwadkar 2020-06-05 2887 alignment = max_t(int, bdev_logical_block_size(sb->s_bdev),
0f8171737cc63a Harshad Shirwadkar 2020-06-05 2888 bdev_discard_alignment(sb->s_bdev));
0f8171737cc63a Harshad Shirwadkar 2020-06-05 2889 discard_start = (EXT4_C2B(EXT4_SB(sb), cluster) +
0f8171737cc63a Harshad Shirwadkar 2020-06-05 2890 ext4_group_first_block_no(sb, block_group)) <<
0f8171737cc63a Harshad Shirwadkar 2020-06-05 2891 sb->s_blocksize_bits;
0f8171737cc63a Harshad Shirwadkar 2020-06-05 @2892 discard_len = EXT4_C2B(EXT4_SB(sb), count) << sb->s_blocksize_bits;
0f8171737cc63a Harshad Shirwadkar 2020-06-05 2893 aligned_discard_start = round_up(discard_start, alignment);
0f8171737cc63a Harshad Shirwadkar 2020-06-05 2894 discard_len -= min(discard_len, aligned_discard_start - discard_start);
0f8171737cc63a Harshad Shirwadkar 2020-06-05 2895 discard_len = round_down(discard_len, granularity);
0f8171737cc63a Harshad Shirwadkar 2020-06-05 2896 if (discard_len >> 9 == 0)
0f8171737cc63a Harshad Shirwadkar 2020-06-05 2897 return 0;
5c521830cf3dfc Jiaying Zhang 2010-07-27 2898 trace_ext4_discard_blocks(sb,
0f8171737cc63a Harshad Shirwadkar 2020-06-05 2899 aligned_discard_start >> sb->s_blocksize_bits,
0f8171737cc63a Harshad Shirwadkar 2020-06-05 2900 discard_len >> (sb->s_blocksize_bits));
0f8171737cc63a Harshad Shirwadkar 2020-06-05 2901 if (biop)
a015434480dcdb Daeho Jeong 2017-06-22 2902 return __blkdev_issue_discard(sb->s_bdev,
0f8171737cc63a Harshad Shirwadkar 2020-06-05 2903 aligned_discard_start >> 9, discard_len >> 9,
a015434480dcdb Daeho Jeong 2017-06-22 2904 GFP_NOFS, 0, biop);
0f8171737cc63a Harshad Shirwadkar 2020-06-05 2905 return sb_issue_discard(sb, aligned_discard_start, discard_len,
0f8171737cc63a Harshad Shirwadkar 2020-06-05 2906 GFP_NOFS, 0);
5c521830cf3dfc Jiaying Zhang 2010-07-27 2907 }
5c521830cf3dfc Jiaying Zhang 2010-07-27 2908
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 39290 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-06-12 17:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-05 22:28 [PATCH] ext4: issue aligned discards Harshad Shirwadkar
2020-06-08 7:35 ` Christoph Hellwig
2020-06-12 17:31 ` harshad shirwadkar
2020-06-06 8:04 kernel test robot
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.