From patchwork Sat Mar 16 00:13:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 10855641 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3AE771575 for ; Sat, 16 Mar 2019 00:13:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FB0A2ACCE for ; Sat, 16 Mar 2019 00:13:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 10E002ACD5; Sat, 16 Mar 2019 00:13:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FCF12ACCE for ; Sat, 16 Mar 2019 00:13:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726695AbfCPAN1 (ORCPT ); Fri, 15 Mar 2019 20:13:27 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:41058 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726513AbfCPAN1 (ORCPT ); Fri, 15 Mar 2019 20:13:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1552695205; x=1584231205; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VppVveBRCxRf2ZlZK3zeqnVja3muc+IROeo/1FZBpOk=; b=P6iG1DPaTaMB3xIQ76hqNDnV1udfprfC6Dwaw5kqiUSAt6Y7Lxi4o8Dl ME98nn0FomLbsHLlow4NOqrRKTiMY115WJAtHu84jyx1lIsEl2uHJiVdV ruShDZ5YYxOsskElPZOK0mREAX4wuzmbWKtINFQ9M9ybIfeqFEOi4Oa92 o9NwEDcZP13RK0swzi/jJQOzI97Eu+/POyAoAn623eBN/2tZCMn+C96IO u/N8ySOoN3vOb0ofdlYuIhc8s9mxR57AniHlsjzfvpcZUEC54T2Qvk9Vm kCTyx/WZNxXVeqrvtkQxyM2j//8prXoMi31wAzJv9gzoDd9L4LJPeNLb3 g==; X-IronPort-AV: E=Sophos;i="5.58,483,1544457600"; d="scan'208";a="209047191" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 16 Mar 2019 08:13:25 +0800 IronPort-SDR: HiH9tkZxdiq+Aqt7ibY+3WVfiYMbXpeYFAmUJHuP3qFOQQ+NwtOXRtaOd/2QqHNKGP7/fHH0yb 1DxGWKGU4JunWVnP6crXnpfirqeL1JYEQFsJXuv1MDiP3P+Ta4PSmWLktHL9WRtWJeUlUm2DX3 AINvdRaN/MfRBwo7BUM9/9Q1iOhs/tHTyqjTToBvM5GonwAbXlQ44Ves45rI95EChD4vHsbBwP SClehIFD9MDN7ZgqYtm4PovqD06Cdyo5xm+fa0YwRGPw9hxD7NTpW/Ug3eXSVz45Wrd0xCHNWO tbaOj9Y5B9f3wxk5bjRoqgfQ Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 15 Mar 2019 16:51:09 -0700 IronPort-SDR: mxbemdLZA4eRWRYkgg3LvmajVa1J2TOOjd86JYFE9NXxEc/ukVFhlhCzjKaM1YxaDyXCWrMvZq jN7YJ+bymhasjL7kR9a3ySEi5JrPIdsgqVgVYIAbHn9imgl/P/wQoTgEV66VBmiIQhcVGZrYxa fz28E4FikawpqQ5omiyIGEZnmnUi9qTZRmscOxB1K7NK1twIa7R2WrzNpFtiFM9VObY8VLOhRo N/i0/rIYS371wufbm2N5pGocmAMZy/l1LvI4cGk0vvrHJtGaFRx99o1cDcST3lbdXbKCP8YAuq 2Gg= Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 15 Mar 2019 17:13:25 -0700 From: Damien Le Moal To: Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net Cc: linux-fsdevel@vger.kernel.org, Matias Bjorling , Masato Suzuki Subject: [PATCH 1/3] f2fs: Fix use of number of devices Date: Sat, 16 Mar 2019 09:13:06 +0900 Message-Id: <20190316001308.18115-2-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190316001308.18115-1-damien.lemoal@wdc.com> References: <20190316001308.18115-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For a single device mount using a zoned block device, the zone information for the device is stored in the sbi->devs single entry array and sbi->s_ndevs is set to 1. This differs from a single device mount using a regular block device which does not allocate sbi->devs and sets sbi->s_ndevs to 0. However, sbi->s_devs == 0 condition is used throughout the code to differentiate a single device mount from a multi-device mount where sbi->s_ndevs is always larger than 1. This results in problems with single zoned block device volumes as these are treated as multi-device mounts but do not have the start_blk and end_blk information set. One of the problem observed is skipping of zone discard issuing resulting in write commands being issued to full zones or unaligned to a zone write pointer. Fix this problem by simply treating the cases sbi->s_ndevs == 0 (single regular block device mount) and sbi->s_ndevs == 1 (single zoned block device mount) in the same manner. This is done by introducing the helper function f2fs_is_multi_device() and using this helper in place of direct tests of sbi->s_ndevs value, improving code readability. Fixes: 7bb3a371d199 ("f2fs: Fix zoned block device support") Cc: Signed-off-by: Damien Le Moal Reviewed-by: Chao Yu --- fs/f2fs/data.c | 17 +++++++++++------ fs/f2fs/f2fs.h | 13 ++++++++++++- fs/f2fs/file.c | 2 +- fs/f2fs/gc.c | 2 +- fs/f2fs/segment.c | 13 +++++++------ 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 568e1d09eb48..91dd8407ba86 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -220,12 +220,14 @@ struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, struct block_device *bdev = sbi->sb->s_bdev; int i; - for (i = 0; i < sbi->s_ndevs; i++) { - if (FDEV(i).start_blk <= blk_addr && - FDEV(i).end_blk >= blk_addr) { - blk_addr -= FDEV(i).start_blk; - bdev = FDEV(i).bdev; - break; + if (f2fs_is_multi_device(sbi)) { + for (i = 0; i < sbi->s_ndevs; i++) { + if (FDEV(i).start_blk <= blk_addr && + FDEV(i).end_blk >= blk_addr) { + blk_addr -= FDEV(i).start_blk; + bdev = FDEV(i).bdev; + break; + } } } if (bio) { @@ -239,6 +241,9 @@ int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr) { int i; + if (!f2fs_is_multi_device(sbi)) + return 0; + for (i = 0; i < sbi->s_ndevs; i++) if (FDEV(i).start_blk <= blkaddr && FDEV(i).end_blk >= blkaddr) return i; diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 7ea5c9cede37..e79f426a9f2f 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1364,6 +1364,17 @@ static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) } #endif +/* + * Test if the mounted volume is a multi-device volume. + * - For a single regular disk volume, sbi->s_ndevs is 0. + * - For a single zoned disk volume, sbi->s_ndevs is 1. + * - For a multi-device volume, sbi->s_ndevs is always 2 or more. + */ +static inline bool f2fs_is_multi_device(struct f2fs_sb_info *sbi) +{ + return sbi->s_ndevs > 1; +} + /* For write statistics. Suppose sector size is 512 bytes, * and the return value is in kbytes. s is of struct f2fs_sb_info. */ @@ -3586,7 +3597,7 @@ static inline bool f2fs_force_buffered_io(struct inode *inode, if (f2fs_post_read_required(inode)) return true; - if (sbi->s_ndevs) + if (f2fs_is_multi_device(sbi)) return true; /* * for blkzoned device, fallback direct IO to buffered IO, so diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index ba5954f41e14..1e3a78bf7a66 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -2571,7 +2571,7 @@ static int f2fs_ioc_flush_device(struct file *filp, unsigned long arg) sizeof(range))) return -EFAULT; - if (sbi->s_ndevs <= 1 || sbi->s_ndevs - 1 <= range.dev_num || + if (!f2fs_is_multi_device(sbi) || sbi->s_ndevs - 1 <= range.dev_num || __is_large_section(sbi)) { f2fs_msg(sbi->sb, KERN_WARNING, "Can't flush %u in %d for segs_per_sec %u != 1\n", diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 195cf0f9d9ef..ab764bd106de 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1346,7 +1346,7 @@ void f2fs_build_gc_manager(struct f2fs_sb_info *sbi) sbi->gc_pin_file_threshold = DEF_GC_FAILED_PINNED_FILES; /* give warm/cold data area from slower device */ - if (sbi->s_ndevs && !__is_large_section(sbi)) + if (f2fs_is_multi_device(sbi) && !__is_large_section(sbi)) SIT_I(sbi)->last_victim[ALLOC_NEXT] = GET_SEGNO(sbi, FDEV(0).end_blk) + 1; } diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 9b79056d705d..d8f531b33350 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -560,7 +560,7 @@ static int submit_flush_wait(struct f2fs_sb_info *sbi, nid_t ino) int ret = 0; int i; - if (!sbi->s_ndevs) + if (!f2fs_is_multi_device(sbi)) return __submit_flush_wait(sbi, sbi->sb->s_bdev); for (i = 0; i < sbi->s_ndevs; i++) { @@ -628,7 +628,8 @@ int f2fs_issue_flush(struct f2fs_sb_info *sbi, nid_t ino) return ret; } - if (atomic_inc_return(&fcc->queued_flush) == 1 || sbi->s_ndevs > 1) { + if (atomic_inc_return(&fcc->queued_flush) == 1 || + f2fs_is_multi_device(sbi)) { ret = submit_flush_wait(sbi, ino); atomic_dec(&fcc->queued_flush); @@ -734,7 +735,7 @@ int f2fs_flush_device_cache(struct f2fs_sb_info *sbi) { int ret = 0, i; - if (!sbi->s_ndevs) + if (!f2fs_is_multi_device(sbi)) return 0; for (i = 1; i < sbi->s_ndevs; i++) { @@ -1343,7 +1344,7 @@ static int __queue_discard_cmd(struct f2fs_sb_info *sbi, trace_f2fs_queue_discard(bdev, blkstart, blklen); - if (sbi->s_ndevs) { + if (f2fs_is_multi_device(sbi)) { int devi = f2fs_target_device_index(sbi, blkstart); blkstart -= FDEV(devi).start_blk; @@ -1698,7 +1699,7 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi, block_t lblkstart = blkstart; int devi = 0; - if (sbi->s_ndevs) { + if (f2fs_is_multi_device(sbi)) { devi = f2fs_target_device_index(sbi, blkstart); blkstart -= FDEV(devi).start_blk; } @@ -3055,7 +3056,7 @@ static void update_device_state(struct f2fs_io_info *fio) struct f2fs_sb_info *sbi = fio->sbi; unsigned int devidx; - if (!sbi->s_ndevs) + if (!f2fs_is_multi_device(sbi)) return; devidx = f2fs_target_device_index(sbi, fio->new_blkaddr); From patchwork Sat Mar 16 00:13:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 10855643 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4C9C81515 for ; Sat, 16 Mar 2019 00:13:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31A322ACCF for ; Sat, 16 Mar 2019 00:13:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 25C0D2ACD8; Sat, 16 Mar 2019 00:13:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AB2A2ACCF for ; Sat, 16 Mar 2019 00:13:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726697AbfCPAN1 (ORCPT ); Fri, 15 Mar 2019 20:13:27 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:41060 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726638AbfCPAN1 (ORCPT ); Fri, 15 Mar 2019 20:13:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1552695207; x=1584231207; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Z98vNC96F5GZHJ7IuN1a+JKlKGjAXQCU2uqCJSzFmoI=; b=Q97p96alKXTuUPYlrRAyhmscusGWSjZ15yazATxh5VU+lbL8z+Vr7n9h 4ZfnUs44w5uKb5eXP9js63OVbYe9yt7PcW5Hh5CU9HIxScik03q47wNxX oUPbS3iXkPsuorrVugKryJvWShxo78MTJ773pffJx94fQQ/Rjhjsjrg2R I4OeT3oeNIX9IqBDzFvhvsYu/GPxaxhlvzNFM7OmW2NCGNPH5e2vc1Twr Hml4/9tgoP8ur7lWv2SYiuU9yWBorr9P9CJphsz5+AmqUxltIPHJh0rRT oAGcxUZU/QyMqdWtmTqTnGI9SDvpk88Mr7WvLYlMQcZSMnTIsoR2MsvOg g==; X-IronPort-AV: E=Sophos;i="5.58,483,1544457600"; d="scan'208";a="209047193" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 16 Mar 2019 08:13:26 +0800 IronPort-SDR: nfe99g8Slk3/Pycc5JFpyQqZl65B899IJoxA+dllkoO6Ml2RCF/dRcGMYluZxyxcdzZklc+eoz E0jsryt9OBjUy9heDNf6TWU09JmvvDl20aKkyQemsMu3aRa+23Pr5KN9hRKnfE3p+yInwT1lg7 qtxJWWiGLbpc16DvXA5SoOY2nftVpe717KnpwiUzVOohJxUD4+EPY5/TE57QYz6ptkje6ecYBN 4cxdbSUU7oMPAxt1DGfpRlPNd/l30O5586YHLyvbKee7RNcFIfACkn3gbG5KANWnNr/DSgsLv9 d6R9dCe6xOIAsfKi07QUcBjh Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 15 Mar 2019 16:51:10 -0700 IronPort-SDR: LqNFPWh3IMZ63J4nSnx6naiKn98vi+94x2hfLu+0Xh6zzXgpybfi6uApMr78e5K+Uwrv1DxazY sN3FJ/6nXgIhHnugAk5zc8ZZTO2Mj7IWVz/sSWw3mIVJ8zGZwXnfO15UEL/vNC9OdyJ18LnrFP D399CUFIby82bdGhjI+skL6HY4a+TavXvr3wkDffvlf35AI+uqAHv4HXufYwiYmO7oUzNqajEA wZCRYS1fnXvr1o/RqBeArjJFphPUiv8TYYFrG8nSYCb1k7xcjZ4ljI/JarrgvU27PnZCUNcNFP YJw= Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 15 Mar 2019 17:13:26 -0700 From: Damien Le Moal To: Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net Cc: linux-fsdevel@vger.kernel.org, Matias Bjorling , Masato Suzuki Subject: [PATCH 2/3] f2fs: Reduce zoned block device memory usage Date: Sat, 16 Mar 2019 09:13:07 +0900 Message-Id: <20190316001308.18115-3-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190316001308.18115-1-damien.lemoal@wdc.com> References: <20190316001308.18115-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For zoned block devices, an array of zone types for each device is allocated and initialized in order to determine if a section is stored on a sequential zone (zone reset needed) or a conventional zone (no zone reset needed and regular discard applies). Considering this usage, the zone types stored in memory can be replaced with a bitmap to indicate an equivalent information, that is, if a zone is sequential or not. This reduces the memory usage for each zoned device by roughly 8: on a 14TB disk with zones of 256 MB, the zone type array consumes 13x4KB pages while the bitmap uses only 2x4KB pages. This patch changes the f2fs_dev_info structure blkz_type field to the bitmap blkz_seq. Access to this bitmap is done using the helper function f2fs_blkz_is_seq(), which is a rewrite of the function get_blkz_type(). Signed-off-by: Damien Le Moal Reviewed-by: Chao Yu --- fs/f2fs/f2fs.h | 14 +++++--------- fs/f2fs/segment.c | 36 ++++++++++++++++-------------------- fs/f2fs/super.c | 13 ++++++++----- 3 files changed, 29 insertions(+), 34 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index e79f426a9f2f..576e637ef568 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1066,8 +1066,8 @@ struct f2fs_dev_info { block_t start_blk; block_t end_blk; #ifdef CONFIG_BLK_DEV_ZONED - unsigned int nr_blkz; /* Total number of zones */ - u8 *blkz_type; /* Array of zones type */ + unsigned int nr_blkz; /* Total number of zones */ + unsigned long *blkz_seq; /* Bitmap indicating sequential zones */ #endif }; @@ -3513,16 +3513,12 @@ F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND); F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM); #ifdef CONFIG_BLK_DEV_ZONED -static inline int get_blkz_type(struct f2fs_sb_info *sbi, - struct block_device *bdev, block_t blkaddr) +static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi, + block_t blkaddr) { unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; - int i; - for (i = 0; i < sbi->s_ndevs; i++) - if (FDEV(i).bdev == bdev) - return FDEV(i).blkz_type[zno]; - return -EINVAL; + return test_bit(zno, FDEV(devi).blkz_seq); } #endif diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index d8f531b33350..f40148b735d7 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -1701,40 +1701,36 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi, if (f2fs_is_multi_device(sbi)) { devi = f2fs_target_device_index(sbi, blkstart); + if (blkstart < FDEV(devi).start_blk || + blkstart > FDEV(devi).end_blk) { + f2fs_msg(sbi->sb, KERN_ERR, "Invalid block %x", + blkstart); + return -EIO; + } blkstart -= FDEV(devi).start_blk; } - /* - * We need to know the type of the zone: for conventional zones, - * use regular discard if the drive supports it. For sequential - * zones, reset the zone write pointer. - */ - switch (get_blkz_type(sbi, bdev, blkstart)) { - - case BLK_ZONE_TYPE_CONVENTIONAL: - if (!blk_queue_discard(bdev_get_queue(bdev))) - return 0; - return __queue_discard_cmd(sbi, bdev, lblkstart, blklen); - case BLK_ZONE_TYPE_SEQWRITE_REQ: - case BLK_ZONE_TYPE_SEQWRITE_PREF: + /* For sequential zones, reset the zone write pointer */ + if (f2fs_blkz_is_seq(sbi, devi, blkstart)) { sector = SECTOR_FROM_BLOCK(blkstart); nr_sects = SECTOR_FROM_BLOCK(blklen); if (sector & (bdev_zone_sectors(bdev) - 1) || nr_sects != bdev_zone_sectors(bdev)) { - f2fs_msg(sbi->sb, KERN_INFO, - "(%d) %s: Unaligned discard attempted (block %x + %x)", + f2fs_msg(sbi->sb, KERN_ERR, + "(%d) %s: Unaligned zone reset attempted (block %x + %x)", devi, sbi->s_ndevs ? FDEV(devi).path: "", blkstart, blklen); return -EIO; } trace_f2fs_issue_reset_zone(bdev, blkstart); - return blkdev_reset_zones(bdev, sector, - nr_sects, GFP_NOFS); - default: - /* Unknown zone type: broken device ? */ - return -EIO; + return blkdev_reset_zones(bdev, sector, nr_sects, GFP_NOFS); } + + /* For conventional zones, use regular discard if supported */ + if (!blk_queue_discard(bdev_get_queue(bdev))) + return 0; + return __queue_discard_cmd(sbi, bdev, lblkstart, blklen); } #endif diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index d1ccc52afc93..8d0caf4c5f2b 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1017,7 +1017,7 @@ static void destroy_device_list(struct f2fs_sb_info *sbi) for (i = 0; i < sbi->s_ndevs; i++) { blkdev_put(FDEV(i).bdev, FMODE_EXCL); #ifdef CONFIG_BLK_DEV_ZONED - kvfree(FDEV(i).blkz_type); + kvfree(FDEV(i).blkz_seq); #endif } kvfree(sbi->devs); @@ -2765,9 +2765,11 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) if (nr_sectors & (bdev_zone_sectors(bdev) - 1)) FDEV(devi).nr_blkz++; - FDEV(devi).blkz_type = f2fs_kmalloc(sbi, FDEV(devi).nr_blkz, - GFP_KERNEL); - if (!FDEV(devi).blkz_type) + FDEV(devi).blkz_seq = f2fs_kzalloc(sbi, + BITS_TO_LONGS(FDEV(devi).nr_blkz) + * sizeof(unsigned long), + GFP_KERNEL); + if (!FDEV(devi).blkz_seq) return -ENOMEM; #define F2FS_REPORT_NR_ZONES 4096 @@ -2794,7 +2796,8 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) } for (i = 0; i < nr_zones; i++) { - FDEV(devi).blkz_type[n] = zones[i].type; + if (zones[i].type != BLK_ZONE_TYPE_CONVENTIONAL) + set_bit(n, FDEV(devi).blkz_seq); sector += zones[i].len; n++; } From patchwork Sat Mar 16 00:13:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 10855645 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B423A1515 for ; Sat, 16 Mar 2019 00:13:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BCEE2ACCE for ; Sat, 16 Mar 2019 00:13:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9011C2ACD2; Sat, 16 Mar 2019 00:13:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EFA62ACCE for ; Sat, 16 Mar 2019 00:13:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726713AbfCPAN3 (ORCPT ); Fri, 15 Mar 2019 20:13:29 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:41062 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726638AbfCPAN3 (ORCPT ); Fri, 15 Mar 2019 20:13:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1552695208; x=1584231208; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8psBenVmCFv+KbSfKoJAunmGftzD40Z9Zs8c3WtqROI=; b=BlST9sAxfRBDBDJIVTNEwmVZCrTf8Qc/oJEZrol5r4TOSCP7jQG7pqR1 qgUev4Wr5N7+8DyDB/j/NmrjzH/g9KywZPCEDOOEjSCLjIU4MaMk7RatJ iYtL9SSs5MuLR8KLKFZXPteARGtldCs7esshIak5PEPXIfNS3AHy3LNn2 UJQrle4AqDFbgagrNFv02fxk0LSgw2qsSiGUiqkrFhIoQVLaBtk0qXMko tfl6nMSD1ZMLugozYE4n837XFvl6+qj4izXyuz7M4yHQO4oXKZ+oOsC0O knh7xLDIUi1vxWhGw1oOp1qYqCeMv8NF2VVTor70TqaPEpmLPXH0AZP1R Q==; X-IronPort-AV: E=Sophos;i="5.58,483,1544457600"; d="scan'208";a="209047197" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 16 Mar 2019 08:13:27 +0800 IronPort-SDR: sML72nlTR8fCUyoLi2LAzXQj8PCekyalRXOcAno2tHjdmc0ZDTEhqHojfPd3hfWDmnggRCo5V0 LDZaDK2EIKlpEpaO2/d7APg/tgNaawQ2hQF/sAhWiaiI5L8JlXz1W2IlPpf/v2UQySgaMr9zjd 9PQaP4jG6pqn2D8RQwY+ZuDWFtYR7zOP7G/py+L4OcgP8V6sv+EdOiisNSK3OkEXDlBLjcVpwb 79t8KS8QoEW7gbeb6ON3qhssL4OVYY4DJHVrCiCXmli+Udr3zh6tAEqr8VsEZqD5PtgNLIZuM9 MdGWJp885XtuAA39Tl3nC4q2 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 15 Mar 2019 16:51:11 -0700 IronPort-SDR: MmUb3ChbK2jMf/cJeRVeLEhZhFfDvsbKALLQCVo1XAmXYFZa8XXXTkln3sivh0eZNJSBT/H5sL JaZDw4IrBIsG3Z7J9Ryv+64g97yV2vJLhuyov8heWIIH+cPkBA81puSXKWk8HYtNQt/Y5bXSaC 21Cf1EizGQUGG/p5GZ1nhW5PFdTCcIvB3Lciqp5dnPP2ESyMCgN2Od5LuR1xhV7sFbf5wPes4h oxVreqU4MlgFzvn1bQqzdVPH/zUujxvFPyLO4KrLxnPNAzk/2L18QUHAHB3aLSbYqO7CJYqfWe 9RQ= Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 15 Mar 2019 17:13:27 -0700 From: Damien Le Moal To: Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net Cc: linux-fsdevel@vger.kernel.org, Matias Bjorling , Masato Suzuki Subject: [PATCH 3/3] f2fs: improve discard handling with multi-device volumes Date: Sat, 16 Mar 2019 09:13:08 +0900 Message-Id: <20190316001308.18115-4-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190316001308.18115-1-damien.lemoal@wdc.com> References: <20190316001308.18115-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP f2fs_hw_support_discard() only tests if the super block device supports discard. However, for a multi-device volume, not all disks used may support discard. Improve the check performed to test all devices of the volume and report discard as supported if at least one device of the volume supports discard. To implement this, introduce the helper function f2fs_bdev_support_discard(), which returns true for zoned block devices (where discard is processed as a zone reset) and for regular disks supporting the discard command. f2fs_bdev_support_discard() is also used in __queue_discard_cmd() to handle discard command issuing for a particular device of the volume. That is, prevent issuing a discard command for block devices that do not support it. Signed-off-by: Damien Le Moal Reviewed-by: Chao Yu --- fs/f2fs/f2fs.h | 16 +++++++++++++++- fs/f2fs/segment.c | 8 ++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 576e637ef568..db4564c6531d 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3527,9 +3527,23 @@ static inline bool f2fs_hw_should_discard(struct f2fs_sb_info *sbi) return f2fs_sb_has_blkzoned(sbi); } +static inline bool f2fs_bdev_support_discard(struct block_device *bdev) +{ + return blk_queue_discard(bdev_get_queue(bdev)) || + bdev_is_zoned(bdev); +} + static inline bool f2fs_hw_support_discard(struct f2fs_sb_info *sbi) { - return blk_queue_discard(bdev_get_queue(sbi->sb->s_bdev)); + int i; + + if (!f2fs_is_multi_device(sbi)) + return f2fs_bdev_support_discard(sbi->sb->s_bdev); + + for (i = 0; i < sbi->s_ndevs; i++) + if (f2fs_bdev_support_discard(FDEV(i).bdev)) + return true; + return false; } static inline bool f2fs_realtime_discard_enable(struct f2fs_sb_info *sbi) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index f40148b735d7..9b320dd1c9d7 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -1342,6 +1342,9 @@ static int __queue_discard_cmd(struct f2fs_sb_info *sbi, { block_t lblkstart = blkstart; + if (!f2fs_bdev_support_discard(bdev)) + return 0; + trace_f2fs_queue_discard(bdev, blkstart, blklen); if (f2fs_is_multi_device(sbi)) { @@ -1728,8 +1731,6 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi, } /* For conventional zones, use regular discard if supported */ - if (!blk_queue_discard(bdev_get_queue(bdev))) - return 0; return __queue_discard_cmd(sbi, bdev, lblkstart, blklen); } #endif @@ -1738,8 +1739,7 @@ static int __issue_discard_async(struct f2fs_sb_info *sbi, struct block_device *bdev, block_t blkstart, block_t blklen) { #ifdef CONFIG_BLK_DEV_ZONED - if (f2fs_sb_has_blkzoned(sbi) && - bdev_zoned_model(bdev) != BLK_ZONED_NONE) + if (f2fs_sb_has_blkzoned(sbi) && bdev_is_zoned(bdev)) return __f2fs_issue_discard_zone(sbi, bdev, blkstart, blklen); #endif return __queue_discard_cmd(sbi, bdev, blkstart, blklen);