From patchwork Wed Apr 10 14:29:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624697 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCF7CCD1299 for ; Wed, 10 Apr 2024 14:38:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F2376B0087; Wed, 10 Apr 2024 10:38:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0389D6B0092; Wed, 10 Apr 2024 10:38:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B75A26B008C; Wed, 10 Apr 2024 10:38:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 92FE26B008A for ; Wed, 10 Apr 2024 10:38:36 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 54D9A807E9 for ; Wed, 10 Apr 2024 14:38:36 +0000 (UTC) X-FDA: 81993878232.27.8B4D61F Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf01.hostedemail.com (Postfix) with ESMTP id A028E40003 for ; Wed, 10 Apr 2024 14:38:31 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf01.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759914; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vlSVZYHGBCwe5po1YBBPtd9L9lS3Ca8QXEZWdubIRGM=; b=jygC124zjkUXylHPpD1kYld1Skk2jTgNjThLO+opuo6pUTBW51GfPmFMpdxgw5Iji5NmRG sDct5XdEwTuYjWQxm0VCYE+2Izie1mu8Dhiisw4Tj3GcBI3+djwYGi6ug2iTT03CN1WI+i snZRez8yVafzgi37L+58kh3glkEtDac= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf01.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759914; a=rsa-sha256; cv=none; b=egPU0yXdHjAsDnnPSc1R6IlEZ45W0HyNjcJ+vw7x3SPzJkyzrQjSsBQFJbDWte/QmmgPkE PJtwv0NwWtJl8FgvKowSuEjwD36HF4eZV7CXj/HSDPJnLRIK/BBVU+MfdJO+OiaqQIkJFZ NbTdwLXgNf67aXW+4oyvVcCgEGTUihA= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF56M4263z4f3khJ for ; Wed, 10 Apr 2024 22:38:19 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 61BDE1A0175 for ; Wed, 10 Apr 2024 22:38:26 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S5; Wed, 10 Apr 2024 22:38:26 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [PATCH v4 01/34] ext4: factor out a common helper to query extent map Date: Wed, 10 Apr 2024 22:29:15 +0800 Message-Id: <20240410142948.2817554-2-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S5 X-Coremail-Antispam: 1UD129KBjvJXoWxXr4rtF1xtFWfXw15Zry3CFg_yoW5XFWUpr ZxCryrCr1UWwsagayftr1UZFySk3W5trWqq397Wr1rA3W5CrnayF15tFySqF9rKrWxXw4Y qFWfKryrCw4fGrDanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUHGb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUGw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0V AKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1l Ox8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErc IFxwACI402YVCY1x02628vn2kIc2xKxwCY1x0262kKe7AKxVW8ZVWrXwCF04k20xvY0x0E wIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVWUXVWUAwC20s026c02F4 0E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_Wryl IxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW7JVWDJwCI42IY6xIIjxv20xvEc7CjxV AFwI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_ Gr1j6F4UJwCI42IY6I8E87Iv6xkF7I0E14v26F4UJVW0obIYCTnIWIevJa73UjIFyTuYvj TRm2NuUUUUU X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A028E40003 X-Stat-Signature: qjq7faennuryigzopowtngy58q49bpqb X-HE-Tag: 1712759911-847477 X-HE-Meta: U2FsdGVkX18lYqst2t4MOInHJbu0CVaRL0Fk9PhVeJUkIXfEp/r7sCuwzLJz8w+BS9dQWVspMjklWSKzXJsKptc0cZ0HO/f9N+wHUtAvf2jHf2CQLX7c6UMh7EI93ZugIWr/AKsTlm4COanlphGSEEqFAHJXKl+c+57V5IoeK3KyriwDIMgN7wNw690qGnhqibL2TZ8cGbBHuC2TNf5fA7uKdbHnR+Ug7hsbsXGGmMek4GEiFiQzsNeNvERsTtNP0nsjX1f7owDas1uoy2y6wKhxBwu6kDew2GzOyfSzyki2GSPO0gHIc5bULgiI1t6yENsAFBw6CpCnRAHABvL6v0sxKrK1vleeYKy6Fy8mwNPul1E+h9lmqITCoRNM1Gsq1OCii0stzDoQ5yBEkQGm09v1Yn0/9sassdDzCjgK/Q/JN1XciEmkOfFI1Nc3A9w+03woJ+0CH83e2JFt4xPWp8sKWVyUhNr+IBbvpHrIIhORKJsvCxF9YcJ/wBl+y1yrIBtvweoK8zi6piXx0avsaXTf4pUtaKmWYH8dR++J8fc+SWLyHBoJnXf8V6zq5PMCQdv9i028Icu6j7t5yf4hElI2fb+z3084zQpotXimTpgLwU3n9HMBPw9alYw7VlcbVzNmnWGTT7uIbFuIqpYw0EKKZUqyKkddhv0WQ43RhojX0Gyh2mC6/72C9MtgzuQ3ywKOHfVoh5W3Ve2fFu1kmCO89PyLU4pt38Ks7uc2F/AnkfEGFhW0hqSbvWgoUsLab9dlWSHYBOKQOrHxvnRuIfibkrKxHkrkvxsuizFAtO7SNLf0hGFL68uMCadZdZuR/mbHftB4svJELTEesQPrSAR/R4EwCCdrM6k9PCBiYoIGkIFJuKkXIRiW3KhQwyamjaSdlmw9NDIVlXTVBdIDloyMPGBV1MsLd2kp/Dq8jqbpQFmiI5iGRqR6/NcHDh0MTqpj4fodLbqsPBkQ6oQ Mh8kimz3 pKkSWmwMEMvkZfggad9nJYA+Rs6YpYrWfsn/MBMR4MKbBvNaTCiyqCiXhsglOghqYIFiwq83+eHdZbctlD2pxvUks4ru4kdkWcr5Olh0fQ1Xswj0NSUSk5arf9UFP1XHzioEkWsRq/x10GB66UXprdZZbTZqHSW4ah/lGV1lhi0eDHBXzZgtPv4SwzQk4UdlPJxIUtya+4SOTLhrM7jRnfFbpbQ4rrWcy7ZwfNTyaPYtRn9DS1otrgQT41U/pu7Znqyc0p34sP9EpNjUe0KBMO/kLqrruEegbzD1p X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Factor out a new common helper ext4_map_query_blocks() from the ext4_da_map_blocks(), it query and return the extent map status on the inode's extent path, no logic changes. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 57 +++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 537803250ca9..6a41172c06e1 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -453,6 +453,35 @@ static void ext4_map_blocks_es_recheck(handle_t *handle, } #endif /* ES_AGGRESSIVE_TEST */ +static int ext4_map_query_blocks(handle_t *handle, struct inode *inode, + struct ext4_map_blocks *map) +{ + unsigned int status; + int retval; + + if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) + retval = ext4_ext_map_blocks(handle, inode, map, 0); + else + retval = ext4_ind_map_blocks(handle, inode, map, 0); + + if (retval <= 0) + return retval; + + if (unlikely(retval != map->m_len)) { + ext4_warning(inode->i_sb, + "ES len assertion failed for inode " + "%lu: retval %d != map->m_len %d", + inode->i_ino, retval, map->m_len); + WARN_ON(1); + } + + status = map->m_flags & EXT4_MAP_UNWRITTEN ? + EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; + ext4_es_insert_extent(inode, map->m_lblk, map->m_len, + map->m_pblk, status); + return retval; +} + /* * The ext4_map_blocks() function tries to look up the requested blocks, * and returns if the blocks are already mapped. @@ -1744,33 +1773,11 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, down_read(&EXT4_I(inode)->i_data_sem); if (ext4_has_inline_data(inode)) retval = 0; - else if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) - retval = ext4_ext_map_blocks(NULL, inode, map, 0); else - retval = ext4_ind_map_blocks(NULL, inode, map, 0); - if (retval < 0) { - up_read(&EXT4_I(inode)->i_data_sem); - return retval; - } - if (retval > 0) { - unsigned int status; - - if (unlikely(retval != map->m_len)) { - ext4_warning(inode->i_sb, - "ES len assertion failed for inode " - "%lu: retval %d != map->m_len %d", - inode->i_ino, retval, map->m_len); - WARN_ON(1); - } - - status = map->m_flags & EXT4_MAP_UNWRITTEN ? - EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; - ext4_es_insert_extent(inode, map->m_lblk, map->m_len, - map->m_pblk, status); - up_read(&EXT4_I(inode)->i_data_sem); - return retval; - } + retval = ext4_map_query_blocks(NULL, inode, map); up_read(&EXT4_I(inode)->i_data_sem); + if (retval) + return retval; add_delayed: down_write(&EXT4_I(inode)->i_data_sem); From patchwork Wed Apr 10 14:29:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624701 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA445CD1299 for ; Wed, 10 Apr 2024 14:38:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B26896B0093; Wed, 10 Apr 2024 10:38:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A40BA6B0096; Wed, 10 Apr 2024 10:38:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 891866B009B; Wed, 10 Apr 2024 10:38:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3D0D76B0095 for ; Wed, 10 Apr 2024 10:38:37 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E650C1C08A7 for ; Wed, 10 Apr 2024 14:38:36 +0000 (UTC) X-FDA: 81993878232.14.7061CCE Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf08.hostedemail.com (Postfix) with ESMTP id 6C4EE160012 for ; Wed, 10 Apr 2024 14:38:31 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759914; a=rsa-sha256; cv=none; b=Jn+1+DiJet/bS3s4pXWr7gKKFRaNxnaqxS6UMXbcMyzuT1Abdx9mY1X9LjCXSahhLERZ1R FomdbUGhreNnn2UOb7kTeAe5/KDoWY1tmxzYdN2cPvNj8CDXyapeZYNgnGoeCJAnomnTgK vKlNj7MYom9EIZFTRQHpH7nCgZAHRkY= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759914; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+W5KEpg2kUY6jwif517hChT/8NlMh2IK3EzSMnHViHw=; b=E+LCOdveXV8/72NAEsC9lRrHF1ySpcdmke82VncMaCkSDDssoyX3QBB2Ul7GtxBqG/SCP5 PlkDwMxFjv/qidoHlWCVowncYJgF5KspbBQ1di4bE1YPaB0C8+GNzyOSYImSSU2jUAcbtb jZpr4XcMGjxzFMSS7oaoYqsNjp3JOzc= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56Q4Rmyz4f3jqP for ; Wed, 10 Apr 2024 22:38:22 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 0C7231A0568 for ; Wed, 10 Apr 2024 22:38:27 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S6; Wed, 10 Apr 2024 22:38:26 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [PATCH v4 02/34] ext4: check the extent status again before inserting delalloc block Date: Wed, 10 Apr 2024 22:29:16 +0800 Message-Id: <20240410142948.2817554-3-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S6 X-Coremail-Antispam: 1UD129KBjvJXoWxurykJF17GFWxuF48Jw1DZFb_yoW5Grykpa 9xCF15Cr48Wwn7Wa93XF12vr1rWa1rJrWUKFZxKr1UZFZ5JFySg3Z0vF1aqFyftrs3JFsY qFWjqry8ua1UKrDanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUH214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAa w2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrV C2j2WlYx0E2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE 7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxc IEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2AFwI0_GFv_Wryl42xK82IYc2Ij64vIr41l4I8I 3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2IqxVAqx4xG67AKxVWUJV WUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MIIYrxkI7VAK I48JMIIF0xvE2Ix0cI8IcVAFwI0_Ar0_tr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJV WxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4UJVWxJr1l IxAIcVC2z280aVCY1x0267AKxVWxJr0_GcJvcSsGvfC2KfnxnUUI43ZEXa7sRieOJ5UUUU U== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6C4EE160012 X-Stat-Signature: drze47zs5fkw8rscidfdkwuzr9mfprso X-HE-Tag: 1712759911-464358 X-HE-Meta: U2FsdGVkX19zQF3qKmah+1N+UMcO+lv+CzotBim2HsS3Of0bM+0KhrBb1g+Mygr7Fi+ii05Cm9Oc3KztKh69dA0tnh+v75cjIFY58/V9fdVPfv3535JdOgk4r9k+KMvAAmzDQTDL85ucmQEFye1to1dalfdjlfGbpSAdny3RwW+O6WjohHd6UzsyQcDmDYOPEmuXoD0m13+ToSi5CFY0a4QMo/5qZf12K2IgGPSvW1a5xf62pmSC1/JEv3i1WnY8xzZ7BLwR/I26mkD+PSpaoR/YToaHziY2tsqEFY3munBXe33UlZ1GHU8qGeQ5rszyT1RBOTIOOn0tvi1cu5/pENY+FwvvsOQoz87Ls9amVnHEmzyPWrLhjnc3zA3YATPXmXi04tW/cgCgx7eb+NMf37ICKxf1X2LJGkdwYmLLX4GBIIG8VGVJhOIzQQ0xJsr2iYgl8BPlm4EZ6ME6q2jinJs41bgWjwcjABi5/RQpSwcZlckS9DRnUSOhSpAenzLNCkrsJSVeI8EgQRh1/4QQnzx6cFUZBld2rCYHrslOaGFh05hVIOfJOXpXDSK2R0N9TKJWL2zYkBQM967Je86KUmyfJmt4s8LJVbx8gr79mey8cNMQAyVOqiXy+KqybuwU+aYVjmecbWklD9ew9ut57X9QjG7ORa0qoMZuIN6uLG3BOgNOXmpS6NxwvKwtHwYCR3/OtoTLKHCjoN+EV1BT2aMxahoAnZqteWOHV5sub3z/xBv4CPeBzAZYr+EqaOes4BFV9N0B8RPvIEKJyNDFwjJYdBsoVjSHHmROjU1z6w844ElqS/NaxilvlC7lsU9+4X7CbVaCjU49lLs9haZ7l9QJEwIjO6eHuvWiNEC/j3iy0eetIaJ28meBpj3bikStfGxVrKGUXtfjSq94r6gxuy6niKAfzdqA+rFUhy2M4DGXuzW3J075z4Y/UmmBUeofaGxgWfif5zBSdV1mTKD Cz1OXzUD mnMas X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Now we lookup extent status entry without holding the i_data_sem before inserting delalloc block, it works fine in buffered write path and because it holds i_rwsem and folio lock, and the mmap path holds folio lock, so the found extent locklessly couldn't be modified concurrently. But it could be raced by fallocate since it allocate block whitout holding i_rwsem and folio lock. ext4_page_mkwrite() ext4_fallocate() block_page_mkwrite() ext4_da_map_blocks() //find hole in extent status tree ext4_alloc_file_blocks() ext4_map_blocks() //allocate block and unwritten extent ext4_insert_delayed_block() ext4_da_reserve_space() //reserve one more block ext4_es_insert_delayed_block() //drop unwritten extent and add delayed extent by mistake Then, the delalloc extent is wrong until writeback, the one more reserved block can't be release any more and trigger below warning: EXT4-fs (pmem2): Inode 13 (00000000bbbd4d23): i_reserved_data_blocks(1) not cleared! Hold i_data_sem in write mode directly can fix the problem, but it's expansive, we should keep the lockless check and check the extent again once we need to add an new delalloc block. Cc: stable@vger.kernel.org Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 6a41172c06e1..118b0497a954 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1737,6 +1737,7 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, if (ext4_es_is_hole(&es)) goto add_delayed; +found: /* * Delayed extent could be allocated by fallocate. * So we need to check it. @@ -1781,6 +1782,24 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, add_delayed: down_write(&EXT4_I(inode)->i_data_sem); + /* + * Lookup extents tree again under i_data_sem, make sure this + * inserting delalloc range haven't been delayed or allocated + * whitout holding i_rwsem and folio lock. + */ + if (ext4_es_lookup_extent(inode, iblock, NULL, &es)) { + if (!ext4_es_is_hole(&es)) { + up_write(&EXT4_I(inode)->i_data_sem); + goto found; + } + } else if (!ext4_has_inline_data(inode)) { + retval = ext4_map_query_blocks(NULL, inode, map); + if (retval) { + up_write(&EXT4_I(inode)->i_data_sem); + return retval; + } + } + retval = ext4_insert_delayed_block(inode, map->m_lblk); up_write(&EXT4_I(inode)->i_data_sem); if (retval) From patchwork Wed Apr 10 14:29:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624694 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A103CD1299 for ; Wed, 10 Apr 2024 14:38:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84F146B007B; Wed, 10 Apr 2024 10:38:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F2496B0087; Wed, 10 Apr 2024 10:38:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 61E6F6B0088; Wed, 10 Apr 2024 10:38:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 236896B007B for ; Wed, 10 Apr 2024 10:38:36 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7C1761A05D0 for ; Wed, 10 Apr 2024 14:38:35 +0000 (UTC) X-FDA: 81993878190.21.2D995DA Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf30.hostedemail.com (Postfix) with ESMTP id 30B5380015 for ; Wed, 10 Apr 2024 14:38:31 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf30.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759913; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RuHY6VVKOxj9Xdepnr+9bRSoYO0Xxk07pmy/1ZAaEXY=; b=RszYKIctlrrjgwL3k28/HG+8gfxBItKrEz6LSfMcw3b1hrtl6fDL2UzYSadFtVGl37xgs9 UQdXLm9s1eXHX/RCuukz50aA6DH/ja+TDdANosUUHI4r0LgaJWpWKUsYg3aC6PtYw0pAR+ 5eFXa5rmHVVDdJW+9KnIN+StgNTXYBs= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf30.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759913; a=rsa-sha256; cv=none; b=X6bhFnkNW7lrsvEUpVcqLSS0pqzh/4AWRpPWgCwF8SN5LTf3phnbndfedvL3h2DH+wgVEu 35KHXeVT3NgX2wBeeoZKkBK2fzL0cZAq6gWNXhx9XpskYR1nAaVPH7rs/OWtcpVBI1qMeS OLnS7RqAD/Og/miEE2CtslvlgT/TGw4= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56M0GC2z4f3lg7 for ; Wed, 10 Apr 2024 22:38:19 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id AB9711A0568 for ; Wed, 10 Apr 2024 22:38:27 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S7; Wed, 10 Apr 2024 22:38:27 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [PATCH v4 03/34] ext4: trim delalloc extent Date: Wed, 10 Apr 2024 22:29:17 +0800 Message-Id: <20240410142948.2817554-4-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S7 X-Coremail-Antispam: 1UD129KBjvJXoW7uF1xWF1Dtr17tF15Aw4Utwb_yoW8CFyUp3 93CFn5Gr4fWw18WayxJF15XF1rK3WUKrW7GrWfKw1rZas8Gw1fKaykAF17tFyUtrZ3Xrs5 XFWDtw18Cw4ftrDanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUH214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JrWl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAa w2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrV C2j2WlYx0E2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE 7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxc IEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2AFwI0_GFv_Wryl42xK82IYc2Ij64vIr41l4I8I 3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2IqxVAqx4xG67AKxVWUJV WUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MIIYrxkI7VAK I48JMIIF0xvE2Ix0cI8IcVAFwI0_Ar0_tr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJV WxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4UJVWxJr1l IxAIcVC2z280aVCY1x0267AKxVWxJr0_GcJvcSsGvfC2KfnxnUUI43ZEXa7sRizVb3UUUU U== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Stat-Signature: ky945ittjk95ik7ew6a6na6f7nsqpbn8 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 30B5380015 X-HE-Tag: 1712759911-902849 X-HE-Meta: U2FsdGVkX18KC5dG5ZQPF8fH72Ei2AkwpYnGjM8ZZAv8RSJVh9fL1wIv7DS6Mv7r8lbq3odQ9xWemJ6+vPyTtcyu08NspR3wp+vakEqaJCKytVd+uVIk25R+8wFPXTGwup2INxUNCxNirB0oOU/xdl0JxoiACCS4LvBqAT/NFhbZqntgoxv4nCktSzPquDWjtSncyGRVLcijEC+Ok/bChd9gDGoFI/7i9cl01O8G27w91nLQuKt5yLZ5TIh4dpbVTX+xwG5ufCh/1NeUCm0n1d+o8gAtU6TdFdnfJPrWvZMH34JrasRRc4m1zgA9OIO9MH8dFf33bFQEYjOaBE82LEoBi/MOm+Gg9kvQIIJ8AqYnfD6EqSFlsPsvfubYonhJq5huV8TUDnUbMWiobmmoRLwVNVZyNs9rN96XGkBw8PNYly9ID2QvXbsYmDohsORQaJctsK3AooDm/CTd62QZuKu27pS4b3YQdmkuArGnU/P9pD6wkVtvLlsmZjncIOwyRtksT9Mmk5Bp33Qyw+WKReMbPuwnsbtmQwJQPtCpXLqObOcCIA2KnNsRIbewnZ43TgQpr0LSBb0yIZ+kVlArGsms/1ISMGG1GiPv7AwRgFMjXeG2zn7Lxw+n9johcM4cYRucir+ohF2rYgQWo6m6kUvuz1tMY8E+znDUNatKN00MkFys+fKs1iN3JJ+TWx8/ANePG0o8gQQpAILRZqEynu9YGGQ4Byz3AaSb7SlN/NcBRc5IkLn1z5cqrKcSCRt3dobDWqVlqscQJe5RqToYQNmYK+UTFOLaWZqCLuChKgI1KjtFPPVaOJuew4379isonzJxdpksDdWiwww+PsdeeoLRFb8LKqAL/7dOr36N9T7OHtUwoX3+PmusZniCxcuIcWGkdgBI1SG18Nypwz3fm704syO2DrJvufH7kk73rcSjVwZbtPbacQQs99ZFm7OlmFM5PyVuR3f/e8+HNW2 5FKayFgR 7a+kaj3xfdkOhDZZOt3avf7nc2Mvj4XUZA5XPGxNHVSfyp/Y5Q2RoO4bIfsxz1XgafDOdeMwaF2bDGWuqBKzHLty1Pa5SoZ/6EeqwS3zGBwwXG7Tr8NCGH2YPoGL6VbmR5YwnQchX8S89nT5j3JtqqFGx1YT8ZJUN/P9yvLehvMR0c3D96+jechgfbLRUd6emMKHAaD/+6b1Ro91pUhUxpy+wMwtsuh7v73QJpDly5nEYgzY0EJQ3VCsH2klCnW8HgRE8 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi The cached delalloc or hole extent should be trimed to the map->map_len if we map delalloc blocks in ext4_da_map_blocks(). But it doesn't trigger any issue now because the map->m_len is always set to one and we always insert one delayed block once a time. Fix this by trim the extent once we get one from the cached extent tree, prearing for mapping a extent with multiple delalloc blocks. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 118b0497a954..e4043ddb07a5 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1734,6 +1734,11 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, /* Lookup extent status tree firstly */ if (ext4_es_lookup_extent(inode, iblock, NULL, &es)) { + retval = es.es_len - (iblock - es.es_lblk); + if (retval > map->m_len) + retval = map->m_len; + map->m_len = retval; + if (ext4_es_is_hole(&es)) goto add_delayed; @@ -1750,10 +1755,6 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, } map->m_pblk = ext4_es_pblock(&es) + iblock - es.es_lblk; - retval = es.es_len - (iblock - es.es_lblk); - if (retval > map->m_len) - retval = map->m_len; - map->m_len = retval; if (ext4_es_is_written(&es)) map->m_flags |= EXT4_MAP_MAPPED; else if (ext4_es_is_unwritten(&es)) @@ -1788,6 +1789,11 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, * whitout holding i_rwsem and folio lock. */ if (ext4_es_lookup_extent(inode, iblock, NULL, &es)) { + retval = es.es_len - (iblock - es.es_lblk); + if (retval > map->m_len) + retval = map->m_len; + map->m_len = retval; + if (!ext4_es_is_hole(&es)) { up_write(&EXT4_I(inode)->i_data_sem); goto found; From patchwork Wed Apr 10 14:29:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624693 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DEF88CD11C2 for ; Wed, 10 Apr 2024 14:38:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 339BC6B0082; Wed, 10 Apr 2024 10:38:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D0C46B0087; Wed, 10 Apr 2024 10:38:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 189F26B0085; Wed, 10 Apr 2024 10:38:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id F09716B007B for ; Wed, 10 Apr 2024 10:38:35 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 57005407B8 for ; Wed, 10 Apr 2024 14:38:35 +0000 (UTC) X-FDA: 81993878190.10.7F131A9 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf17.hostedemail.com (Postfix) with ESMTP id 623684000E for ; Wed, 10 Apr 2024 14:38:31 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759913; a=rsa-sha256; cv=none; b=CkWgLqJaj2IJ7eXGePF0hwpseE/cfgttqs25/W6p+FaG/XXyQ1yHVC7QqdgFHAA5lbRSSG ER9IFq2vwR5rR+CraL6HB0DQoZBEtweixxig12izPTU1UBY52cj0LgwL3fSzy9MY6wsLkP CTNkKpJWgkXj59xWmEhXAqd5NgDY23w= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759913; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c4+6cURURx8jSa0D0D5ClQ4p+d2eJgRX+D3rNfqwvMk=; b=grRvoUmySgtdfTOzIfCuYDerWuncyutQdWfqjngz63yoYzc4h0q70jJsY7uX/jplNthUrk dsN5h8zVNj2Z2GnHwK/gqC/zXtekWqj0JvWgmIJhq1NS7LD3xE8/+RXoMJmO+9zjrFK+hG MlfrC1NHz9C9+JxTHF4kb7S6QH/nTDk= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56M4sBdz4f3m6S for ; Wed, 10 Apr 2024 22:38:19 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 554811A0568 for ; Wed, 10 Apr 2024 22:38:28 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S8; Wed, 10 Apr 2024 22:38:28 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [PATCH v4 04/34] ext4: drop iblock parameter Date: Wed, 10 Apr 2024 22:29:18 +0800 Message-Id: <20240410142948.2817554-5-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S8 X-Coremail-Antispam: 1UD129KBjvJXoWxJFy7ZFy7XrW5Jr1rCFW3Wrg_yoW5Gr47p3 93AF1rGr1fuw109a1xtF17ZF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_GcJvcSsGvfC2KfnxnUUI43ZEXa7sRibyCP UUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 623684000E X-Stat-Signature: mxs91of1o7tzbzp7ew74ucdk18ui6qks X-HE-Tag: 1712759911-940703 X-HE-Meta: U2FsdGVkX1/KOdevRqtcmhYFuKg9uyLaKn0N9p12wWOtP8M4k2wh8p0F7/I49ygXXtidIzk5fwW6lxB/vC0YyH515Ru7vwcKn1YK2tvoQZqhzDZGXqUv5/HP8Oe7oo+f6Q+YdwzM2lCGBn4a03oPuj6NdmAuk7VXvf61ZTE8evD+z8Ch1SnKE11otJlJ6ObEA4vr5gXgBSGlYr74P9Z1OGEcnK8WLM6oiTW8cC5wDeMTRyoLCZaY23SOH9JkFRsRKl6Iplat/C6Qpbycd21LyMm8GkYtCG3XuXpjvTpRCR4a1u08pc/pIkqeZpWAMrq6/TnGyK8MRMQN3S0N6i65s1B4s23/v4JKSdy8JZL4IGNIt+YmFvOYhHLmPMPGlTxJuTg15Q93ikiPY/D5d6IOtQJxlQfG478RrcqIlRAe700oEI4ZUqWxMrU3BGgenq23yMvJH4O45slImxvIf5xlY0HV1BwIDm973oo7k5vIeLw0fJfWp/JElOzL03+t/qqfSd0VKThDouzO+UsSYldD6oZH0/i5FoOP0q9w3iccZwMjFVb17A45RsUOU2ZZijqJ3wLBxClgIC76kYF2LgE1SIdeJClarVl2HqKsn0xmLmmcLjsdz11HMN1aIRNFRE9sCY2nNCf+VA9EmWS7swevDHdC8lNuM2DAYzg17tqn6xJsYIJOXrZGBXM83UCIpCRixLFMLjGGZDFU85iRSFBhrDyWQUgCw3yv6s6kaEpHLDX8ATsZ42zXysXKaf4AoF0S7OeSwkalrZqMikDbo3d1TxHgDGHA17P/uuosa6PMJv5JNIvoHp+C+MJITXuJJ5sdYw7o7kOV0rw/yECxTMMy/dRYHlfiiWNAFIwT6X28GWJU3LQbGgj4nrSnaGA//DkLcpDdRdPyQrq5u5lgm/QRvswkkGFJ2vOzQqL3SnX3NzJ3UnXAhy5eWPycKyWHL5hoYo1Ya70mUjpR1eeMTH/ kzLMqrf7 Da1az X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi The start block of the delalloc extent to be inserted is equal to map->m_lblk, just drop the duplicate iblock input parameter. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index e4043ddb07a5..cccc16506f5f 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1712,8 +1712,7 @@ static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk) * time. This function looks up the requested blocks and sets the * buffer delay bit under the protection of i_data_sem. */ -static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, - struct ext4_map_blocks *map, +static int ext4_da_map_blocks(struct inode *inode, struct ext4_map_blocks *map, struct buffer_head *bh) { struct extent_status es; @@ -1733,8 +1732,8 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, (unsigned long) map->m_lblk); /* Lookup extent status tree firstly */ - if (ext4_es_lookup_extent(inode, iblock, NULL, &es)) { - retval = es.es_len - (iblock - es.es_lblk); + if (ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es)) { + retval = es.es_len - (map->m_lblk - es.es_lblk); if (retval > map->m_len) retval = map->m_len; map->m_len = retval; @@ -1754,7 +1753,7 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, return 0; } - map->m_pblk = ext4_es_pblock(&es) + iblock - es.es_lblk; + map->m_pblk = ext4_es_pblock(&es) + map->m_lblk - es.es_lblk; if (ext4_es_is_written(&es)) map->m_flags |= EXT4_MAP_MAPPED; else if (ext4_es_is_unwritten(&es)) @@ -1788,8 +1787,8 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, * inserting delalloc range haven't been delayed or allocated * whitout holding i_rwsem and folio lock. */ - if (ext4_es_lookup_extent(inode, iblock, NULL, &es)) { - retval = es.es_len - (iblock - es.es_lblk); + if (ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es)) { + retval = es.es_len - (map->m_lblk - es.es_lblk); if (retval > map->m_len) retval = map->m_len; map->m_len = retval; @@ -1846,7 +1845,7 @@ int ext4_da_get_block_prep(struct inode *inode, sector_t iblock, * preallocated blocks are unmapped but should treated * the same as allocated blocks. */ - ret = ext4_da_map_blocks(inode, iblock, &map, bh); + ret = ext4_da_map_blocks(inode, &map, bh); if (ret <= 0) return ret; From patchwork Wed Apr 10 14:29:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624696 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32C2ECD128A for ; Wed, 10 Apr 2024 14:38:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E19C06B0088; Wed, 10 Apr 2024 10:38:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DBEB36B0087; Wed, 10 Apr 2024 10:38:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8AF26B0088; Wed, 10 Apr 2024 10:38:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 7BB4A6B0085 for ; Wed, 10 Apr 2024 10:38:36 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3C775160817 for ; Wed, 10 Apr 2024 14:38:36 +0000 (UTC) X-FDA: 81993878232.16.4A1A636 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf27.hostedemail.com (Postfix) with ESMTP id 85FD240016 for ; Wed, 10 Apr 2024 14:38:32 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf27.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759914; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Xt8Mfa8aHN0+/BJFIIiVVVZj3lDx/Wlzok12002g10Y=; b=LAgYZgW7u/e8RdNrE9DeiK5LiDG5360jIb7c/JS8Zabt+HxcZmTH9Bj11pYjcDbh/xqVNM pwIxK9R9RNXSn2VPrpgOckLfxtDi75SVkvvGn5GR8p5mM0IX5ExeyfVKiuSGO0SUxRMAUo dNPXoIWG5GChApkH3j3B5ebxR6Dh/no= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf27.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759914; a=rsa-sha256; cv=none; b=BUkwfO4mIE8/2NZpA2H/Bxoqr5SCjT2gNuaJzLgGZTJkkjUBStfghdFIYIbr3IYcU6fC67 vY1z1Lv9JXr0qcQWpOrmHrkz0VJNiyyM+rPQNb7kRlaIgREq3z92If/iJJ9s7UOvqUdR+h ofP9lyF8N+FpUcETmxAajjd/D7+eVhc= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF56Q13c8z4f3khg for ; Wed, 10 Apr 2024 22:38:22 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id F39AA1A0568 for ; Wed, 10 Apr 2024 22:38:28 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S9; Wed, 10 Apr 2024 22:38:28 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [PATCH v4 05/34] ext4: make ext4_es_insert_delayed_block() insert multi-blocks Date: Wed, 10 Apr 2024 22:29:19 +0800 Message-Id: <20240410142948.2817554-6-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S9 X-Coremail-Antispam: 1UD129KBjvJXoWxtFWfAw4ktw48Cw18ZF15XFb_yoWxKr4fpF Z8Ar18CrW5Xw1q93Zaqw1UXr13Xa1kGrWUGrZIvw1fZFWfJFy5KF1DtF1FvFWFyrWIy3Zx XFyjy347Ca1j9a7anT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUHS14x267AKxVWrJVCq3wAFc2x0x2IEx4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bid7KFI+jLcsSekHpMHeTJO7Fr3XQs8Q7JRzcsPC2ATtA17WLSIrZN6KdN2aVXbrsQky6Zw+xQQiyNHAiO3MVEGAZOiPghDKsPq4crVzDCXXWqems4vc34irw9o6/uueC7GGXTs/jtoD5Kn9IhmhK75jThteTmKNvM8o5hgnOAD5nRVYOQ9tYbT7yR6ekHg+XYSm9WXxQoPtGuw6DREgA1GnzW4vudeAirjnSBWUZLZ4KXayts7ad+sqaxVg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Rename ext4_es_insert_delayed_block() to ext4_es_insert_delayed_extent() and pass length parameter to make it insert multi delalloc blocks once a time. For the case of bigalloc, expand the allocated parameter to lclu_allocated and end_allocated. lclu_allocated indicates the allocate state of the cluster which containing the lblk, end_allocated represents the end, and the middle clusters must be unallocated. Signed-off-by: Zhang Yi --- fs/ext4/extents_status.c | 63 ++++++++++++++++++++++++------------- fs/ext4/extents_status.h | 5 +-- fs/ext4/inode.c | 2 +- include/trace/events/ext4.h | 16 +++++----- 4 files changed, 55 insertions(+), 31 deletions(-) diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 4a00e2f019d9..2320b0d71001 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -2052,34 +2052,42 @@ bool ext4_is_pending(struct inode *inode, ext4_lblk_t lblk) } /* - * ext4_es_insert_delayed_block - adds a delayed block to the extents status - * tree, adding a pending reservation where - * needed + * ext4_es_insert_delayed_extent - adds some delayed blocks to the extents + * status tree, adding a pending reservation + * where needed * * @inode - file containing the newly added block - * @lblk - logical block to be added - * @allocated - indicates whether a physical cluster has been allocated for - * the logical cluster that contains the block + * @lblk - start logical block to be added + * @len - length of blocks to be added + * @lclu_allocated/end_allocated - indicates whether a physical cluster has + * been allocated for the logical cluster + * that contains the block */ -void ext4_es_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk, - bool allocated) +void ext4_es_insert_delayed_extent(struct inode *inode, ext4_lblk_t lblk, + ext4_lblk_t len, bool lclu_allocated, + bool end_allocated) { struct extent_status newes; + ext4_lblk_t end = lblk + len - 1; int err1 = 0, err2 = 0, err3 = 0; struct extent_status *es1 = NULL; struct extent_status *es2 = NULL; - struct pending_reservation *pr = NULL; + struct pending_reservation *pr1 = NULL; + struct pending_reservation *pr2 = NULL; if (EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY) return; - es_debug("add [%u/1) delayed to extent status tree of inode %lu\n", - lblk, inode->i_ino); + es_debug("add [%u/%u) delayed to extent status tree of inode %lu\n", + lblk, len, inode->i_ino); + if (!len) + return; newes.es_lblk = lblk; - newes.es_len = 1; + newes.es_len = len; ext4_es_store_pblock_status(&newes, ~0, EXTENT_STATUS_DELAYED); - trace_ext4_es_insert_delayed_block(inode, &newes, allocated); + trace_ext4_es_insert_delayed_extent(inode, &newes, lclu_allocated, + end_allocated); ext4_es_insert_extent_check(inode, &newes); @@ -2088,11 +2096,15 @@ void ext4_es_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk, es1 = __es_alloc_extent(true); if ((err1 || err2) && !es2) es2 = __es_alloc_extent(true); - if ((err1 || err2 || err3) && allocated && !pr) - pr = __alloc_pending(true); + if (err1 || err2 || err3) { + if (lclu_allocated && !pr1) + pr1 = __alloc_pending(true); + if (end_allocated && !pr2) + pr2 = __alloc_pending(true); + } write_lock(&EXT4_I(inode)->i_es_lock); - err1 = __es_remove_extent(inode, lblk, lblk, NULL, es1); + err1 = __es_remove_extent(inode, lblk, end, NULL, es1); if (err1 != 0) goto error; /* Free preallocated extent if it didn't get used. */ @@ -2112,13 +2124,22 @@ void ext4_es_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk, es2 = NULL; } - if (allocated) { - err3 = __insert_pending(inode, lblk, &pr); + if (lclu_allocated) { + err3 = __insert_pending(inode, lblk, &pr1); if (err3 != 0) goto error; - if (pr) { - __free_pending(pr); - pr = NULL; + if (pr1) { + __free_pending(pr1); + pr1 = NULL; + } + } + if (end_allocated) { + err3 = __insert_pending(inode, end, &pr2); + if (err3 != 0) + goto error; + if (pr2) { + __free_pending(pr2); + pr2 = NULL; } } error: diff --git a/fs/ext4/extents_status.h b/fs/ext4/extents_status.h index d9847a4a25db..3c8e2edee5d5 100644 --- a/fs/ext4/extents_status.h +++ b/fs/ext4/extents_status.h @@ -249,8 +249,9 @@ extern void ext4_exit_pending(void); extern void ext4_init_pending_tree(struct ext4_pending_tree *tree); extern void ext4_remove_pending(struct inode *inode, ext4_lblk_t lblk); extern bool ext4_is_pending(struct inode *inode, ext4_lblk_t lblk); -extern void ext4_es_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk, - bool allocated); +extern void ext4_es_insert_delayed_extent(struct inode *inode, ext4_lblk_t lblk, + ext4_lblk_t len, bool lclu_allocated, + bool end_allocated); extern unsigned int ext4_es_delayed_clu(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t len); extern void ext4_clear_inode_es(struct inode *inode); diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index cccc16506f5f..d37233e2ed0b 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1702,7 +1702,7 @@ static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk) } } - ext4_es_insert_delayed_block(inode, lblk, allocated); + ext4_es_insert_delayed_extent(inode, lblk, 1, allocated, false); return 0; } diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h index a697f4b77162..6b41ac61310f 100644 --- a/include/trace/events/ext4.h +++ b/include/trace/events/ext4.h @@ -2478,11 +2478,11 @@ TRACE_EVENT(ext4_es_shrink, __entry->scan_time, __entry->nr_skipped, __entry->retried) ); -TRACE_EVENT(ext4_es_insert_delayed_block, +TRACE_EVENT(ext4_es_insert_delayed_extent, TP_PROTO(struct inode *inode, struct extent_status *es, - bool allocated), + bool lclu_allocated, bool end_allocated), - TP_ARGS(inode, es, allocated), + TP_ARGS(inode, es, lclu_allocated, end_allocated), TP_STRUCT__entry( __field( dev_t, dev ) @@ -2491,7 +2491,8 @@ TRACE_EVENT(ext4_es_insert_delayed_block, __field( ext4_lblk_t, len ) __field( ext4_fsblk_t, pblk ) __field( char, status ) - __field( bool, allocated ) + __field( bool, lclu_allocated ) + __field( bool, end_allocated ) ), TP_fast_assign( @@ -2501,16 +2502,17 @@ TRACE_EVENT(ext4_es_insert_delayed_block, __entry->len = es->es_len; __entry->pblk = ext4_es_show_pblock(es); __entry->status = ext4_es_status(es); - __entry->allocated = allocated; + __entry->lclu_allocated = lclu_allocated; + __entry->end_allocated = end_allocated; ), TP_printk("dev %d,%d ino %lu es [%u/%u) mapped %llu status %s " - "allocated %d", + "allocated %d %d", MAJOR(__entry->dev), MINOR(__entry->dev), (unsigned long) __entry->ino, __entry->lblk, __entry->len, __entry->pblk, show_extent_status(__entry->status), - __entry->allocated) + __entry->lclu_allocated, __entry->end_allocated) ); /* fsmap traces */ From patchwork Wed Apr 10 14:29:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624698 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C8E6CD11C2 for ; Wed, 10 Apr 2024 14:38:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3AF2A6B008A; Wed, 10 Apr 2024 10:38:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 388D16B008C; Wed, 10 Apr 2024 10:38:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D55BD6B0095; Wed, 10 Apr 2024 10:38:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9744B6B0092 for ; Wed, 10 Apr 2024 10:38:36 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5365912081E for ; Wed, 10 Apr 2024 14:38:36 +0000 (UTC) X-FDA: 81993878232.28.01BE787 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf18.hostedemail.com (Postfix) with ESMTP id 060C51C0011 for ; Wed, 10 Apr 2024 14:38:33 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf18.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759914; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wObD8zXh9fI3SG/H+pZZoJlfw14IqjpYDMmvtigX7IA=; b=r3UUHnUiSI9XjqFtR9XHflxBo30T0Vm338HivKEuotZdQfmEyXM/XxQp/UiFmyomkwMV1H aTe6M+FzYeW2pk+d0bqTTktGnO2L4Jv/+5rEaudOfTAvdW6opvwZw91vQB7VWWNXg2+Ry6 BvEh3A3jI4Bwpi8mUuLx6TWp5b/eSek= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf18.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759914; a=rsa-sha256; cv=none; b=fY9GS6+WsnZDSIf4n7e24UmvLN35wn3ZuO5Gra833bmAxiX47vey8HexlvwKwTf/+u18yx 91CvW6sJ2yODoM5426sdyaqCc3KhGp41JgdR+y8KLqI5hm1xbMT2ArjJFvC1X7Zbn3+Rhv 2gRYowylau7Cm0F+E+vfvqPGQZFhYl8= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56T1Wm7z4f3jkR for ; Wed, 10 Apr 2024 22:38:25 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 9C8481A016E for ; Wed, 10 Apr 2024 22:38:29 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S10; Wed, 10 Apr 2024 22:38:29 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [PATCH v4 06/34] ext4: make ext4_da_reserve_space() reserve multi-clusters Date: Wed, 10 Apr 2024 22:29:20 +0800 Message-Id: <20240410142948.2817554-7-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S10 X-Coremail-Antispam: 1UD129KBjvJXoWxXF1fZr4DXF48uFWrAr4kCrg_yoWrXF1xpF s8AF43WryIv34kWFWxZr4DZF1S9a4SqFWUta93WFyxXry5J3WSgF1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ibyCP UUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 060C51C0011 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: bwdic1tipr6qpsy59qbs3cxm88ftmj8n X-HE-Tag: 1712759913-857442 X-HE-Meta: U2FsdGVkX19mAk72sFA7X9oi/mOkI3EFTuuRyHazZ0DYXKd9fjZhxvk2UroC3DomaAZU6aCocpW3EZJP9jN6ssD9C3/aJPbN3z9gDJBEI3D4rSDwRwKv3wjCd3bD7UVv9QxHQYP1WuRUUVbGBxylNRLYjBu/xykz3o0mV7QpPrtsp82H8RdbrW6oOUARUPm4+SC7elf1dqMcs3+vFmOnhHIg9HY4PjBnONXJ0GGWjlsvkpt+xTbh9eGZmUPzEZLZ3lmg/qgK3tjv9K+YpycnzMqpmimh3307wEQex7mxyZAvse2ABsR/JT/z02LUDvG8CGIXWV0Lh4PFmOKMbc1cY2PtIU+zsgghhjJjVmKWFLv0piCQB6TB0FHqGeLVadis1aLgq9+OnE99v0wePG4JYf3M69ZoTtA6RwZCLOToODRRcAMx9rLKUbVKpDmsVCka0jMbrFRfgTNakMfu3jIOIyfzPohduuVkKHk9uHJ1t5CVb/TT6wcalJO8qL43dXp0UYhoIQUGeRRmlj0ApebectA9Ol26HIL4KFZHcwnYAakdk8kB0bPD8HB5oiZ2nMAcGbfSBgndUBh4xImVPLjv5mssqLsatTVIo1/atY0wumXdvzUdvdfW5NyGi4aWaHYHHQ+lhIq/CJBTaWkAqddPnsgZeDXRXll6T+EVBrNVDXK1Ao4q7ROduAU5OBbGTOpsXR9rLzLM/M2pcuKR5ogH0N6zkUgFBcjzFqo22Ghk4QTKxtX5AwbsDGYns4lOYC3mTTB2DggtaZt51heRzkbfHB3IjVLSulUyBbOKPN6csah3DwIujdON5VMuSIOd/rbip/vPJrNtyS5A9MvT/LY9Ut/kf1m8OAclCZLbDbSU6BuEbAg8wliwwlP9GTmMTHv9SaVMpra47LzMJjoe0uZjMQkDaxLO7oRkUTkregMTHbzTNv4CN8in+ZReq3gXXM6ktMWJR9hRts9vYD/o853 ePV9WORj 4+px0lI/Qu0xss7SQ9xjlzf5is0TPhMgfeeHmeOq1E2QfJoxr87PL5Kd1Pw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Add 'nr_resv' parameter to ext4_da_reserve_space(), which indicates the number of clusters wants to reserve, make it reserve multi-clusters once a time. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 18 +++++++++--------- include/trace/events/ext4.h | 10 ++++++---- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index d37233e2ed0b..1180a9eb4362 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1479,9 +1479,9 @@ static int ext4_journalled_write_end(struct file *file, } /* - * Reserve space for a single cluster + * Reserve space for 'nr_resv' clusters */ -static int ext4_da_reserve_space(struct inode *inode) +static int ext4_da_reserve_space(struct inode *inode, int nr_resv) { struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); struct ext4_inode_info *ei = EXT4_I(inode); @@ -1492,18 +1492,18 @@ static int ext4_da_reserve_space(struct inode *inode) * us from metadata over-estimation, though we may go over by * a small amount in the end. Here we just reserve for data. */ - ret = dquot_reserve_block(inode, EXT4_C2B(sbi, 1)); + ret = dquot_reserve_block(inode, EXT4_C2B(sbi, nr_resv)); if (ret) return ret; spin_lock(&ei->i_block_reservation_lock); - if (ext4_claim_free_clusters(sbi, 1, 0)) { + if (ext4_claim_free_clusters(sbi, nr_resv, 0)) { spin_unlock(&ei->i_block_reservation_lock); - dquot_release_reservation_block(inode, EXT4_C2B(sbi, 1)); + dquot_release_reservation_block(inode, EXT4_C2B(sbi, nr_resv)); return -ENOSPC; } - ei->i_reserved_data_blocks++; - trace_ext4_da_reserve_space(inode); + ei->i_reserved_data_blocks += nr_resv; + trace_ext4_da_reserve_space(inode, nr_resv); spin_unlock(&ei->i_block_reservation_lock); return 0; /* success */ @@ -1678,7 +1678,7 @@ static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk) * extents status tree doesn't get a match. */ if (sbi->s_cluster_ratio == 1) { - ret = ext4_da_reserve_space(inode); + ret = ext4_da_reserve_space(inode, 1); if (ret != 0) /* ENOSPC */ return ret; } else { /* bigalloc */ @@ -1690,7 +1690,7 @@ static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk) if (ret < 0) return ret; if (ret == 0) { - ret = ext4_da_reserve_space(inode); + ret = ext4_da_reserve_space(inode, 1); if (ret != 0) /* ENOSPC */ return ret; } else { diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h index 6b41ac61310f..cc5e9b7b2b44 100644 --- a/include/trace/events/ext4.h +++ b/include/trace/events/ext4.h @@ -1246,14 +1246,15 @@ TRACE_EVENT(ext4_da_update_reserve_space, ); TRACE_EVENT(ext4_da_reserve_space, - TP_PROTO(struct inode *inode), + TP_PROTO(struct inode *inode, int nr_resv), - TP_ARGS(inode), + TP_ARGS(inode, nr_resv), TP_STRUCT__entry( __field( dev_t, dev ) __field( ino_t, ino ) __field( __u64, i_blocks ) + __field( int, reserve_blocks ) __field( int, reserved_data_blocks ) __field( __u16, mode ) ), @@ -1262,16 +1263,17 @@ TRACE_EVENT(ext4_da_reserve_space, __entry->dev = inode->i_sb->s_dev; __entry->ino = inode->i_ino; __entry->i_blocks = inode->i_blocks; + __entry->reserve_blocks = nr_resv; __entry->reserved_data_blocks = EXT4_I(inode)->i_reserved_data_blocks; __entry->mode = inode->i_mode; ), - TP_printk("dev %d,%d ino %lu mode 0%o i_blocks %llu " + TP_printk("dev %d,%d ino %lu mode 0%o i_blocks %llu reserve_blocks %d" "reserved_data_blocks %d", MAJOR(__entry->dev), MINOR(__entry->dev), (unsigned long) __entry->ino, __entry->mode, __entry->i_blocks, - __entry->reserved_data_blocks) + __entry->reserve_blocks, __entry->reserved_data_blocks) ); TRACE_EVENT(ext4_da_release_space, From patchwork Wed Apr 10 14:29:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624700 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CB96CD11C2 for ; Wed, 10 Apr 2024 14:38:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 953166B0092; Wed, 10 Apr 2024 10:38:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E0E46B0093; Wed, 10 Apr 2024 10:38:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 581696B0096; Wed, 10 Apr 2024 10:38:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 334426B0093 for ; Wed, 10 Apr 2024 10:38:37 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id DC79A1A07B9 for ; Wed, 10 Apr 2024 14:38:36 +0000 (UTC) X-FDA: 81993878232.25.D0B6F69 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf03.hostedemail.com (Postfix) with ESMTP id 75A5520002 for ; Wed, 10 Apr 2024 14:38:34 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; spf=pass (imf03.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759915; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1B4ngafH1j/H0v6adJNVq5qXwTB2PXDJPpcTLBN4hv4=; b=yhvrzesHWqonp4t0HG/5L2RfnweU1S5vqM7K9l12gFpuxGP5b9Gegit130XzFtafafEewl u+Heh5SWZb7Z1UVlJTLBCOnMUiBe00lIXGTMYpJRHVCopZBzZGAyWBXkCDbmoK8lT+hZzf rk3kaFhfw+T2XT43jEnG95hKagtPLqI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759915; a=rsa-sha256; cv=none; b=ujOsVGGsR3RSrGAlny7ffeAKZzUdsZMfKakKJDw/soOIZ06Rah2yVUEkfghjXtZQrdf6U4 w/+BQ0BcCVAaPEU9h2AHT4Je4sXzMxmMvcapSAgUkxqAtb31Ig3GnA3HWmPhZ9dVlCBaWt /TKHpXb0t2v1pqEbb1N/tXnAO0P/1UE= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; spf=pass (imf03.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF56R2y7kz4f3khr for ; Wed, 10 Apr 2024 22:38:23 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 45CD01A0C72 for ; Wed, 10 Apr 2024 22:38:30 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S11; Wed, 10 Apr 2024 22:38:30 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [PATCH v4 07/34] ext4: factor out check for whether a cluster is allocated Date: Wed, 10 Apr 2024 22:29:21 +0800 Message-Id: <20240410142948.2817554-8-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S11 X-Coremail-Antispam: 1UD129KBjvJXoW7urW7CF45JrWUJw1kAr1UWrg_yoW8trWxpr ZxGF4rXr43Wr97WF4Sqw1DXF1Yga10q3yUJrWa93W8Zr4fJFy5KF1qyF1rXFyrKrW8A3ZI qFWUAryUCF4jka7anT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUHS14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAaw2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I 8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCF s4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFI xGxcIEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2AFwI0_GFv_Wryl42xK82IYc2Ij64vIr41l 4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2IqxVAqx4xG67AKxV WUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MIIYrxkI 7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Ar0_tr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r 4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4UJVWx Jr1lIxAIcVC2z280aVCY1x0267AKxVWxJr0_GcJvcSsGvfC2KfnxnUUI43ZEXa7sRibyCP UUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 75A5520002 X-Rspam-User: X-Stat-Signature: rqj897bycdfc9yj69ykesbjhzbxdejyi X-Rspamd-Server: rspam03 X-HE-Tag: 1712759914-733652 X-HE-Meta: U2FsdGVkX1+Quz6bFLemKYetoxtCpV+YfOEguSM67clun/Nb2xs6OaT/mikXfzKRg1+kWs60SwtmRaFU2YTaXussq2GDMVa2/3yeCg1xfNln3ZEX7eNkbFSKxLjF9pIzXFXeEvaNPelCk0j7XPHTKfaXbaFMuiQ1DB+lhS65lgHl0I6n3/MdTV/6I2uCW9oWoslecM4WM55RpPQPbRroU7WmIKfFl8iG77AcF3mdNl2Qv35qZbDJOoqP4bPKVDQQrM8IA1DNPADPpmnEAU7fZPtxdpkaiJqT3N6XiFehEUvnCTc60dKM2StiEQeDt5OSzK/L2yi/bRxbrlRkBZzuKwQvCOekxA89NcVu9G0tcxuHKoocnPYDHbCwU8clKyoPw+moSJnp/1IRIkSByirNQoiXvQ94NqdrKk2fVagiK4RIgyvsj1ka2LcGZsb4k9nqe9N8sU0HcPfWpRWrK5K39qoeW16j5SgVEj72QZkepOxGL64imlOojDEbZ7aB7zSGZKdNljr81gVEh89+hVrVeEEEh9NCXeq7L31tfpN652TMmKqJ5lwBJMidO0dK2GDH25bm81Z0EGw4oYf+SOsTIsE0iFMHTyDS/BrfhG0NvXaOM8O1d68Kxb1l9XGKStDWVL9bPYAR6XUeIEgw2PGG8zBlfFmYNrfXrZyfbbUwnsmUnDcNrr+ou+YGVXXkzYstZZlnCsPJGHX5ClFFGZoZkEHRIpW7jjiZjuLDvXFqi+mItO/kppKolUipfYwSfACgcOXwb+dDkSivJmJdTnjL99N3V6khV9Y8ygupxAS/1l44khK8vmiW5dq2odVYpckHdbp8pR3pr0l4te+EgqQ4LfbaeTceYgf3HpwmJBYC3ySaDP+u3wsYwR5Tga6hfVsZu8y0+QUSFCGAmCm4l+MRWlUTTN/BwN8QDZW6sZfpRg01gTw63QImvG3XIg5FjCYvOlJWzdN01th+i181ufk iplOquSI EJsyyYAFgtgdXIhAL/EHV0K0G2Qh4VhbfjJ291eMiBYrtbVqiJxEsEwiLPHc2UAzdaDsBvVNCFhn3YwwoNUgKDsdgUhhFteNd/1tT9OINBlpihwTdDs75EfSU3AjKHLcwyH1FW8qcXD0uFlPdayD7OOfVlaAVKqXAR367ZeFQTVmJOPbo+VoN/yaZ5m+buZi0oDi6Y7OJyqgLyP+HbhKTJdUBuwVyJ5LAS8NAU7nQ78fBIhRZShkVc+MQcIRfxXswS8C1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Factor out a common helper ext4_da_check_clu_allocated(), check whether the cluster containing a delalloc block to be added has been delayed or allocated, no logic changes. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 52 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 1180a9eb4362..46c34baa848a 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1649,6 +1649,34 @@ static void ext4_print_free_blocks(struct inode *inode) return; } +/* + * Check whether the cluster containing lblk has been delayed or allocated, + * if not, it means we should reserve a cluster when add delalloc, return 1, + * otherwise return 0 or error code. + */ +static int ext4_da_check_clu_allocated(struct inode *inode, ext4_lblk_t lblk, + bool *allocated) +{ + struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); + int ret; + + *allocated = false; + if (ext4_es_scan_clu(inode, &ext4_es_is_delonly, lblk)) + return 0; + + if (ext4_es_scan_clu(inode, &ext4_es_is_mapped, lblk)) + goto allocated; + + ret = ext4_clu_mapped(inode, EXT4_B2C(sbi, lblk)); + if (ret < 0) + return ret; + if (ret == 0) + return 1; +allocated: + *allocated = true; + return 0; +} + /* * ext4_insert_delayed_block - adds a delayed block to the extents status * tree, incrementing the reserved cluster/block @@ -1682,23 +1710,13 @@ static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk) if (ret != 0) /* ENOSPC */ return ret; } else { /* bigalloc */ - if (!ext4_es_scan_clu(inode, &ext4_es_is_delonly, lblk)) { - if (!ext4_es_scan_clu(inode, - &ext4_es_is_mapped, lblk)) { - ret = ext4_clu_mapped(inode, - EXT4_B2C(sbi, lblk)); - if (ret < 0) - return ret; - if (ret == 0) { - ret = ext4_da_reserve_space(inode, 1); - if (ret != 0) /* ENOSPC */ - return ret; - } else { - allocated = true; - } - } else { - allocated = true; - } + ret = ext4_da_check_clu_allocated(inode, lblk, &allocated); + if (ret < 0) + return ret; + if (ret > 0) { + ret = ext4_da_reserve_space(inode, 1); + if (ret != 0) /* ENOSPC */ + return ret; } } From patchwork Wed Apr 10 14:29:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624699 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5025CCD1299 for ; Wed, 10 Apr 2024 14:38:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 62C4B6B008C; Wed, 10 Apr 2024 10:38:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 53BC66B0092; Wed, 10 Apr 2024 10:38:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C35D6B0092; Wed, 10 Apr 2024 10:38:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 076566B0093 for ; Wed, 10 Apr 2024 10:38:37 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id CA395807CD for ; Wed, 10 Apr 2024 14:38:36 +0000 (UTC) X-FDA: 81993878232.10.EB33250 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf26.hostedemail.com (Postfix) with ESMTP id 5F201140023 for ; Wed, 10 Apr 2024 14:38:33 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf26.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759915; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=su8wBnthmKdxQo7o27r28TvXUm1bnpFTwPTSX4XdHa0=; b=G0QaPudbIzohBPQfU/LqZ0CjU+MeHQww/U8+apNt49edfk5oUCGSMRXgn97345ryKFJbMW b7UxQfXb3V/bNCuHe8GJ4QOJY4S3Kq/LDl/V0cDkDQU0P/D8FQufp/iJdZqPwIkoiB3Ysg JDPJmo0hKSHvhsnuNru61TkPTUqbroY= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf26.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759915; a=rsa-sha256; cv=none; b=oaIIkNcDlquIj5RdP2NGuZZcspo9QeyfCjaqqoSlTls7t7xHDlPWdPaqo2v5SsrfckVDgd wmfEI6LhhaUU0Scnd1zkC9i4HlHWHGcH6+RsbucIMLa1DVefXe5C9uODATD2YGiwNr/8Bm Y2TOcSYr3S/lMNaIh2KMPo7ys/7xFTE= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF56S0YSmz4f3kjD for ; Wed, 10 Apr 2024 22:38:24 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id E50C71A0CB6 for ; Wed, 10 Apr 2024 22:38:30 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S12; Wed, 10 Apr 2024 22:38:30 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [PATCH v4 08/34] ext4: make ext4_insert_delayed_block() insert multi-blocks Date: Wed, 10 Apr 2024 22:29:22 +0800 Message-Id: <20240410142948.2817554-9-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S12 X-Coremail-Antispam: 1UD129KBjvJXoWxAw1DuF47Aw48XFW3ZF47Jwb_yoWrJFWkpr Z8CF1fJrWagr92gF4Sqr1DXr1aga1ktrWDJFZIgw1rZrWfJFyfKF1DtF13XF1SkrWkJa1Y vFW5A34Uuan0ka7anT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUHS14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAaw2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I 8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCF s4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFI xGxcIEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2AFwI0_GFv_Wryl42xK82IYc2Ij64vIr41l 4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2IqxVAqx4xG67AKxV WUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MIIYrxkI 7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Ar0_tr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r 4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4UJVWx Jr1lIxAIcVC2z280aVCY1x0267AKxVWxJr0_GcJvcSsGvfC2KfnxnUUI43ZEXa7sRibyCP UUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Stat-Signature: yptohekta3g3h3mcibbf916oj6a3u3e6 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 5F201140023 X-HE-Tag: 1712759913-989697 X-HE-Meta: U2FsdGVkX19JbD4IgDdL/eRutvsbhaoU6PABAfYq8KZONoUG/n5G1rKtBSn3WA0lIBv4W657toOzairZcUfjCEVxjKmmZmbb8ZRZ6uNZdM9jXnbOQzks1HYham6c/eRD0O+gHaDVajXIhoBH/n7WajeTuVChkrBuTVjudsR3kYiruOQnEvibMh6XzSMgpsZta/CglcED2vtw8uhw5TvQj91CzNBvNoZj6DvAaSBgVHcQoA6KmmtPDS7K7A+ETEI4u7JlKPG5ih3iQTIyiVc8qfo4ufpb2RXvnmoMTAHDzTRsYMtIaTyuGh4hUBfbTKFPxBYQhyA483Ata9ScA/YIVPYGFldLSMNVc5lg2q+okdHO0aA2D5gQ4TN578wl8VnyEgpd9tzF+9floWZa3IrGjVVSwZkmT6vM/t6ygLJBpfmfCBWH4Tm1in/1ksJ5UkA5oMHjSwQq2GGHRtpnKB0bLTMSJgkB50LtdF7Y8X5NdxPlsktL2d9Tkm8ja/Owh7UTHRArs1xn+RWrFkL22WJrw1EDVaNZUH02dLlTpjMCZftbDart+JeHgL4TVUVnLSW8T0F/gdRJhE0vvlhqTVTm8xkgl2+6lwufC9tQJs6nQcSrDJTTijOVAD+WIohj56cQvCnl0kVW36EITcDKV8XFaZ0MANFZrsUGMlsHssxbOZaWWPN/nZmpiYN2vnYiS6zOVNqJ9yVSQBxGjopP7ILvfpp+hRlVegnWEQLwKxNDwW1k51pu29LljQ3s/1uI4cjbVxw5f51Je0KUcqoZRu9XVRPCzWl91yjOV8pSK2RykCoYn5POb3zp5Jn4cWKUqbz1GyOpo4HCzD8+77M8v+UEwENV8Z33CHPdejskHHDTrwpwgaBHZ3KlS6sSoG6HfOBiXkGKJHe/yy6dI+JchIIjfCPkDvSi73depGOOHvjaQVZwa7qG/cuFQNMGYHBtd50c+Pxa211g8dz2d/7xTCm NqVUOmNe ix1iTX2lhbZNAcMKORHAoCtyCSpMTiOnrMFjLOmtld+2UHbcFT8AxtWynU0EBXmwL6IYmB21iLIsffe4qvntpU5tERYMujAg2bB+hRiPF3RqX1Z9ZhOJuqrydLqp2Ggy8x8ueZ6EC7j0YFpXbMvdDqdQD/LfqveEt9Kax7pfJ5AN3WqV+Z/tcRIt5MAtnUkRbjno6xA+MUE2a+/gDFWx4q65CvPCu4bH8rXLbboJrYElm1zUOyJOFBUgghf3dN46YdIjfYYV38AaR0YdVA0OGNGGdC7I7lVrZwtQgt5+gT8FcmSI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Rename ext4_insert_delayed_block() to ext4_insert_delayed_blocks(), pass length parameter to make it insert multi delalloc blocks once a time. For non-bigalloc case, just reserve len blocks and insert delalloc extent. For bigalloc case, we can ensure the middle clusters are not allocated, but need to check whether the start and end clusters are delayed/allocated, if not, we should reserve more space for the start and/or end block(s). Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 51 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 46c34baa848a..08e2692b7286 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1678,24 +1678,28 @@ static int ext4_da_check_clu_allocated(struct inode *inode, ext4_lblk_t lblk, } /* - * ext4_insert_delayed_block - adds a delayed block to the extents status - * tree, incrementing the reserved cluster/block - * count or making a pending reservation - * where needed + * ext4_insert_delayed_blocks - adds a multiple delayed blocks to the extents + * status tree, incrementing the reserved + * cluster/block count or making pending + * reservations where needed * * @inode - file containing the newly added block - * @lblk - logical block to be added + * @lblk - start logical block to be added + * @len - length of blocks to be added * * Returns 0 on success, negative error code on failure. */ -static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk) +static int ext4_insert_delayed_blocks(struct inode *inode, ext4_lblk_t lblk, + ext4_lblk_t len) { struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); - int ret; - bool allocated = false; + int resv_clu, ret; + bool lclu_allocated = false; + bool end_allocated = false; + ext4_lblk_t end = lblk + len - 1; /* - * If the cluster containing lblk is shared with a delayed, + * If the cluster containing lblk or end is shared with a delayed, * written, or unwritten extent in a bigalloc file system, it's * already been accounted for and does not need to be reserved. * A pending reservation must be made for the cluster if it's @@ -1706,21 +1710,38 @@ static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk) * extents status tree doesn't get a match. */ if (sbi->s_cluster_ratio == 1) { - ret = ext4_da_reserve_space(inode, 1); + ret = ext4_da_reserve_space(inode, len); if (ret != 0) /* ENOSPC */ return ret; } else { /* bigalloc */ - ret = ext4_da_check_clu_allocated(inode, lblk, &allocated); + resv_clu = EXT4_B2C(sbi, end) - EXT4_B2C(sbi, lblk) - 1; + if (resv_clu < 0) + resv_clu = 0; + + ret = ext4_da_check_clu_allocated(inode, lblk, &lclu_allocated); if (ret < 0) return ret; - if (ret > 0) { - ret = ext4_da_reserve_space(inode, 1); + if (ret > 0) + resv_clu++; + + if (EXT4_B2C(sbi, lblk) != EXT4_B2C(sbi, end)) { + ret = ext4_da_check_clu_allocated(inode, end, + &end_allocated); + if (ret < 0) + return ret; + if (ret > 0) + resv_clu++; + } + + if (resv_clu) { + ret = ext4_da_reserve_space(inode, resv_clu); if (ret != 0) /* ENOSPC */ return ret; } } - ext4_es_insert_delayed_extent(inode, lblk, 1, allocated, false); + ext4_es_insert_delayed_extent(inode, lblk, len, lclu_allocated, + end_allocated); return 0; } @@ -1823,7 +1844,7 @@ static int ext4_da_map_blocks(struct inode *inode, struct ext4_map_blocks *map, } } - retval = ext4_insert_delayed_block(inode, map->m_lblk); + retval = ext4_insert_delayed_blocks(inode, map->m_lblk, map->m_len); up_write(&EXT4_I(inode)->i_data_sem); if (retval) return retval; From patchwork Wed Apr 10 14:29:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624707 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D841ACD1299 for ; Wed, 10 Apr 2024 14:39:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A5BE6B009E; Wed, 10 Apr 2024 10:38:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 92D086B00A1; Wed, 10 Apr 2024 10:38:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 560616B009E; Wed, 10 Apr 2024 10:38:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 3401D6B009D for ; Wed, 10 Apr 2024 10:38:41 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 058FE407B8 for ; Wed, 10 Apr 2024 14:38:41 +0000 (UTC) X-FDA: 81993878442.23.2654D6F Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf14.hostedemail.com (Postfix) with ESMTP id 9FCA710000A for ; Wed, 10 Apr 2024 14:38:38 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf14.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759919; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NWWJ/TtS7KxCApEyA1tLfqTmPi9I7WG2hMKNz938sdA=; b=aiQvFZ99y2QnocGTxHT5U9MBSmmLswGzi9F7J363/bwMOxIvXBShcBHMjrVTZQBz4O6Jkv BTJmv5TALpNq3yYBfKLxBSV0vJnqEV49dbd+5n8v9ah8lMghmOYbgxVk8AJSH0MsubN2FJ DvGIwGFkmA9suX9SGMXlCFJn4fDY4xk= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf14.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759919; a=rsa-sha256; cv=none; b=6SMlqsj2j1irTkuqCcD2F8tMlX9r9SXG8ngy+7aCeZRx237JY4PmyGkth3tZM1x2A/ldlx e+lKDIm+5UwtMgVFbEzeDorlQ1wIVboLxT2bWjR0ot8XwqRwB3Ihn2UF62f9L4Yhp4ohyq 1+vLo0egxlxfId1Vo70a77zPXmxm1IE= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF56S5GMfz4f3kjF for ; Wed, 10 Apr 2024 22:38:24 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 900961A016E for ; Wed, 10 Apr 2024 22:38:31 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S13; Wed, 10 Apr 2024 22:38:31 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [PATCH v4 09/34] ext4: make ext4_da_map_blocks() buffer_head unaware Date: Wed, 10 Apr 2024 22:29:23 +0800 Message-Id: <20240410142948.2817554-10-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S13 X-Coremail-Antispam: 1UD129KBjvJXoW3WF4kCw1kAF4fJr1xJF1xuFg_yoW7Wr1Up3 93AF1rGr13Ww18ua1ftr15ZF1fK3WUtFW7Kr93GryrA34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FGCN538bCxtiUfn61JfIUIG65jmZftviqp1KzjJ+2+oPMy7rncOqZVcZ/C8pQwl7GNdFNzkjOdC78VaTlRvbS zkvEgqml twm2Bk8cREqs6ap/Z/hXohJ1NObNqDhi0hc+VZeZxYXzqIIGnkqqAVykeIxVzgRIBMKI0n0CpLyniDJNlCtkQT/mRSV1gACoB3M/Y0BI7Xafd1xrIhxT+69WjjTItn3nLZfvjlx2ku0wWMoYLC/OdLJGWBF70Nh586IxVL9ejFbFnUxvU2sw57dyo4eNFFg2cc+6uKyiyshufU4Ml37RyRVsPIQhS3IZHIJJo3keMxL503baHDQC3HwhdiBcOmcu0bmchdwbkhtrO+yQ+mB1ucO4XtbNsiblTmBx/8fW+tOCQCjk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi After calling ext4_da_map_blocks(), a delalloc extent state could be distinguished through EXT4_MAP_DELAYED flag in map. So factor out buffer_head related handles in ext4_da_map_blocks(), make it buffer_head unaware, make it become a common helper, it could be used for iomap in the future. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 54 +++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 08e2692b7286..1731c1d24362 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1749,33 +1749,26 @@ static int ext4_insert_delayed_blocks(struct inode *inode, ext4_lblk_t lblk, * This function is grabs code from the very beginning of * ext4_map_blocks, but assumes that the caller is from delayed write * time. This function looks up the requested blocks and sets the - * buffer delay bit under the protection of i_data_sem. + * delalloc extent map under the protection of i_data_sem. */ -static int ext4_da_map_blocks(struct inode *inode, struct ext4_map_blocks *map, - struct buffer_head *bh) +static int ext4_da_map_blocks(struct inode *inode, struct ext4_map_blocks *map) { struct extent_status es; int retval; - sector_t invalid_block = ~((sector_t) 0xffff); #ifdef ES_AGGRESSIVE_TEST struct ext4_map_blocks orig_map; memcpy(&orig_map, map, sizeof(*map)); #endif - if (invalid_block < ext4_blocks_count(EXT4_SB(inode->i_sb)->s_es)) - invalid_block = ~0; - map->m_flags = 0; ext_debug(inode, "max_blocks %u, logical block %lu\n", map->m_len, (unsigned long) map->m_lblk); /* Lookup extent status tree firstly */ if (ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es)) { - retval = es.es_len - (map->m_lblk - es.es_lblk); - if (retval > map->m_len) - retval = map->m_len; - map->m_len = retval; + map->m_len = min_t(unsigned int, map->m_len, + es.es_len - (map->m_lblk - es.es_lblk)); if (ext4_es_is_hole(&es)) goto add_delayed; @@ -1785,10 +1778,8 @@ static int ext4_da_map_blocks(struct inode *inode, struct ext4_map_blocks *map, * Delayed extent could be allocated by fallocate. * So we need to check it. */ - if (ext4_es_is_delayed(&es) && !ext4_es_is_unwritten(&es)) { - map_bh(bh, inode->i_sb, invalid_block); - set_buffer_new(bh); - set_buffer_delay(bh); + if (ext4_es_is_delonly(&es)) { + map->m_flags |= EXT4_MAP_DELAYED; return 0; } @@ -1803,7 +1794,7 @@ static int ext4_da_map_blocks(struct inode *inode, struct ext4_map_blocks *map, #ifdef ES_AGGRESSIVE_TEST ext4_map_blocks_es_recheck(NULL, inode, map, &orig_map, 0); #endif - return retval; + return 0; } /* @@ -1817,7 +1808,7 @@ static int ext4_da_map_blocks(struct inode *inode, struct ext4_map_blocks *map, retval = ext4_map_query_blocks(NULL, inode, map); up_read(&EXT4_I(inode)->i_data_sem); if (retval) - return retval; + return retval < 0 ? retval : 0; add_delayed: down_write(&EXT4_I(inode)->i_data_sem); @@ -1827,10 +1818,8 @@ static int ext4_da_map_blocks(struct inode *inode, struct ext4_map_blocks *map, * whitout holding i_rwsem and folio lock. */ if (ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es)) { - retval = es.es_len - (map->m_lblk - es.es_lblk); - if (retval > map->m_len) - retval = map->m_len; - map->m_len = retval; + map->m_len = min_t(unsigned int, map->m_len, + es.es_len - (map->m_lblk - es.es_lblk)); if (!ext4_es_is_hole(&es)) { up_write(&EXT4_I(inode)->i_data_sem); @@ -1840,18 +1829,14 @@ static int ext4_da_map_blocks(struct inode *inode, struct ext4_map_blocks *map, retval = ext4_map_query_blocks(NULL, inode, map); if (retval) { up_write(&EXT4_I(inode)->i_data_sem); - return retval; + return retval < 0 ? retval : 0; } } + map->m_flags |= EXT4_MAP_DELAYED; retval = ext4_insert_delayed_blocks(inode, map->m_lblk, map->m_len); up_write(&EXT4_I(inode)->i_data_sem); - if (retval) - return retval; - map_bh(bh, inode->i_sb, invalid_block); - set_buffer_new(bh); - set_buffer_delay(bh); return retval; } @@ -1871,11 +1856,15 @@ int ext4_da_get_block_prep(struct inode *inode, sector_t iblock, struct buffer_head *bh, int create) { struct ext4_map_blocks map; + sector_t invalid_block = ~((sector_t) 0xffff); int ret = 0; BUG_ON(create == 0); BUG_ON(bh->b_size != inode->i_sb->s_blocksize); + if (invalid_block < ext4_blocks_count(EXT4_SB(inode->i_sb)->s_es)) + invalid_block = ~0; + map.m_lblk = iblock; map.m_len = 1; @@ -1884,10 +1873,17 @@ int ext4_da_get_block_prep(struct inode *inode, sector_t iblock, * preallocated blocks are unmapped but should treated * the same as allocated blocks. */ - ret = ext4_da_map_blocks(inode, &map, bh); - if (ret <= 0) + ret = ext4_da_map_blocks(inode, &map); + if (ret < 0) return ret; + if (map.m_flags & EXT4_MAP_DELAYED) { + map_bh(bh, inode->i_sb, invalid_block); + set_buffer_new(bh); + set_buffer_delay(bh); + return 0; + } + map_bh(bh, inode->i_sb, map.m_pblk); ext4_update_bh_state(bh, map.m_flags); From patchwork Wed Apr 10 14:29:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624703 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1879CD128A for ; Wed, 10 Apr 2024 14:39:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 758A76B0096; Wed, 10 Apr 2024 10:38:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 709366B009B; Wed, 10 Apr 2024 10:38:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 55CA36B009C; Wed, 10 Apr 2024 10:38:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0805F6B0096 for ; Wed, 10 Apr 2024 10:38:39 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id CC7D91606E8 for ; Wed, 10 Apr 2024 14:38:38 +0000 (UTC) X-FDA: 81993878316.21.02EE43A Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf24.hostedemail.com (Postfix) with ESMTP id 591C4180002 for ; Wed, 10 Apr 2024 14:38:35 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf24.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759917; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6ReeJeOwpbhiEfhURT2cYsdi8myn0n3Tt43JRBAlL3I=; b=P1AyD5czxdb9UHqe/UpQjpRH4TPHxQEu6QiBf61do+yeVgmweBEHCLc24sfMMFjOGpZu2/ zgv8cccBRZ4Yym5gWmGUIzeuIfkRd0uIGrMv2cAg34Try29jaYnkEMSfMlUmOZfgBBIWzL VOrzwNLPPb9SU/1JwQR6PW8ugvu2Yy4= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf24.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759917; a=rsa-sha256; cv=none; b=u9GtH3148iijZ+RXaAQV7kcAZlg3UQ3iYtUSWCcgxI5eSoAhqgH89vCHehvqgJti8ED6Ep LR2hfD4pubDqhrpWMQ78okugpcZ76VYGb3sFbiv8pIKZjeJ5CrWlbEMveoHkFdDWN/uNHd ppw6XHNAy6J790fgmz/uePc3lFIJ/pA= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56W5m2Fz4f3k6V for ; Wed, 10 Apr 2024 22:38:27 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 3A56E1A0D45 for ; Wed, 10 Apr 2024 22:38:32 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S14; Wed, 10 Apr 2024 22:38:31 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 10/34] ext4: factor out ext4_map_create_blocks() to allocate new blocks Date: Wed, 10 Apr 2024 22:29:24 +0800 Message-Id: <20240410142948.2817554-11-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S14 X-Coremail-Antispam: 1UD129KBjvJXoW3XF17GrWUWFy8Jw4kJryxKrg_yoW7Kr47pr WfCFyrGr4jgw1qg3ySyr48XF1Yk3WFkrWUC3yfWryrZ345CrySyF15AFy3JF9rKrWxZw1Y qFWFy348Ca95GrDanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUHS14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAaw2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I 8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCF s4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFI xGxcIEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2AFwI0_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gGJFU629EH+HmjppnSM3BdesNUh3a8lsaILIBfxduAM9PTWHVdDwNFYJwohza6bklqfvS+pJ4jfBJJwYUj5RIAGupP5QglY2XN6u4FbX9pyp1b0D/JYbPLso2HVh/73QKmY2tE09VGT5nNDgHUTMNdUOTuHIdjCWr1EJV4h/SH9awuzVTtGz/+tx80DXVxdcx7Tc9YAu8cZGWryfUJY9rGtW0llJoWyRpOhkgSE5VnOHUMRvd/f91dsNvL7kPDiwHndOlOfmw2VF6V0dV5W8MgbAZ3Tcgj2+gUzD61fX0H2lh8YZjRsmVqthUdrHAR4U6iMO8IzYRewx0Xxu4taO9LK/ZGL4e2OAYWUZ5G4UJfeNdjLlvKoCM0aH1MxFzvsUatQQp6jRuNQurlTk8BC5qygSREFv8DKqfX7zYoKkP7sNpUPRbavCSQwcb/+hX14A3ofFGS0 Te+3VVWi 3FjuIVH+NO805ItL+TG6d5deoGTPHpnJyFgm+7iXkDPMNBUdVhpPgISx5SUk6Qz/Lr0Hf613++PFPDzihqvL1QZLBeZx6I3HQAUq+0rhgxChKOT3+MbB66JMb6bt/H1DQCEjUOGoMB2Ev5o62KAPyHpstEtdL8aXc5ZqLVHx89c+NzXgB3L4g0i0jSdro6poS/D4Ic/RlsrmviMFUHOq+HbhTF7OBGG8T+JnEPa71de0MHv06yCWzQgWJq/UIS56fkp0A X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Factor out a common helper ext4_map_create_blocks() from ext4_map_blocks(), it allocate new blocks and create a new extent, no logic changes. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 157 +++++++++++++++++++++++++----------------------- 1 file changed, 81 insertions(+), 76 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 1731c1d24362..10a256cfcaa1 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -482,6 +482,86 @@ static int ext4_map_query_blocks(handle_t *handle, struct inode *inode, return retval; } +static int ext4_map_create_blocks(handle_t *handle, struct inode *inode, + struct ext4_map_blocks *map, int flags) +{ + struct extent_status es; + unsigned int status; + int err, retval = 0; + + /* + * Here we clear m_flags because after allocating an new extent, + * it will be set again. + */ + map->m_flags &= ~EXT4_MAP_FLAGS; + + /* + * We need to check for EXT4 here because migrate could have + * changed the inode type in between. + */ + if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) { + retval = ext4_ext_map_blocks(handle, inode, map, flags); + } else { + retval = ext4_ind_map_blocks(handle, inode, map, flags); + + /* + * We allocated new blocks which will result in i_data's + * format changing. Force the migrate to fail by clearing + * migrate flags. + */ + if (retval > 0 && map->m_flags & EXT4_MAP_NEW) + ext4_clear_inode_state(inode, EXT4_STATE_EXT_MIGRATE); + } + if (retval <= 0) + return retval; + + if (unlikely(retval != map->m_len)) { + ext4_warning(inode->i_sb, + "ES len assertion failed for inode %lu: " + "retval %d != map->m_len %d", + inode->i_ino, retval, map->m_len); + WARN_ON(1); + } + + /* + * We have to zeroout blocks before inserting them into extent + * status tree. Otherwise someone could look them up there and + * use them before they are really zeroed. We also have to + * unmap metadata before zeroing as otherwise writeback can + * overwrite zeros with stale data from block device. + */ + if (flags & EXT4_GET_BLOCKS_ZERO && + map->m_flags & EXT4_MAP_MAPPED && map->m_flags & EXT4_MAP_NEW) { + err = ext4_issue_zeroout(inode, map->m_lblk, map->m_pblk, + map->m_len); + if (err) + return err; + } + + /* + * If the extent has been zeroed out, we don't need to update + * extent status tree. + */ + if (flags & EXT4_GET_BLOCKS_PRE_IO && + ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es)) { + if (ext4_es_is_written(&es)) + return retval; + } + + status = map->m_flags & EXT4_MAP_UNWRITTEN ? + EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; + if (!(flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) && + !(status & EXTENT_STATUS_WRITTEN) && + ext4_es_scan_range(inode, &ext4_es_is_delayed, map->m_lblk, + map->m_lblk + map->m_len - 1)) + status |= EXTENT_STATUS_DELAYED; + + ext4_es_insert_extent(inode, map->m_lblk, map->m_len, + map->m_pblk, status); + + return retval; +} + /* * The ext4_map_blocks() function tries to look up the requested blocks, * and returns if the blocks are already mapped. @@ -630,12 +710,6 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, if (!(flags & EXT4_GET_BLOCKS_CONVERT_UNWRITTEN)) return retval; - /* - * Here we clear m_flags because after allocating an new extent, - * it will be set again. - */ - map->m_flags &= ~EXT4_MAP_FLAGS; - /* * New blocks allocate and/or writing to unwritten extent * will possibly result in updating i_data, so we take @@ -643,76 +717,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, * with create == 1 flag. */ down_write(&EXT4_I(inode)->i_data_sem); - - /* - * We need to check for EXT4 here because migrate - * could have changed the inode type in between - */ - if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) { - retval = ext4_ext_map_blocks(handle, inode, map, flags); - } else { - retval = ext4_ind_map_blocks(handle, inode, map, flags); - - if (retval > 0 && map->m_flags & EXT4_MAP_NEW) { - /* - * We allocated new blocks which will result in - * i_data's format changing. Force the migrate - * to fail by clearing migrate flags - */ - ext4_clear_inode_state(inode, EXT4_STATE_EXT_MIGRATE); - } - } - - if (retval > 0) { - unsigned int status; - - if (unlikely(retval != map->m_len)) { - ext4_warning(inode->i_sb, - "ES len assertion failed for inode " - "%lu: retval %d != map->m_len %d", - inode->i_ino, retval, map->m_len); - WARN_ON(1); - } - - /* - * We have to zeroout blocks before inserting them into extent - * status tree. Otherwise someone could look them up there and - * use them before they are really zeroed. We also have to - * unmap metadata before zeroing as otherwise writeback can - * overwrite zeros with stale data from block device. - */ - if (flags & EXT4_GET_BLOCKS_ZERO && - map->m_flags & EXT4_MAP_MAPPED && - map->m_flags & EXT4_MAP_NEW) { - ret = ext4_issue_zeroout(inode, map->m_lblk, - map->m_pblk, map->m_len); - if (ret) { - retval = ret; - goto out_sem; - } - } - - /* - * If the extent has been zeroed out, we don't need to update - * extent status tree. - */ - if ((flags & EXT4_GET_BLOCKS_PRE_IO) && - ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es)) { - if (ext4_es_is_written(&es)) - goto out_sem; - } - status = map->m_flags & EXT4_MAP_UNWRITTEN ? - EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; - if (!(flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) && - !(status & EXTENT_STATUS_WRITTEN) && - ext4_es_scan_range(inode, &ext4_es_is_delayed, map->m_lblk, - map->m_lblk + map->m_len - 1)) - status |= EXTENT_STATUS_DELAYED; - ext4_es_insert_extent(inode, map->m_lblk, map->m_len, - map->m_pblk, status); - } - -out_sem: + retval = ext4_map_create_blocks(handle, inode, map, flags); up_write((&EXT4_I(inode)->i_data_sem)); if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) { ret = check_block_validity(inode, map); From patchwork Wed Apr 10 14:29:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624702 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C76CCD11C2 for ; Wed, 10 Apr 2024 14:39:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 166036B0095; Wed, 10 Apr 2024 10:38:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0EE5D6B009C; Wed, 10 Apr 2024 10:38:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E5D1A6B009B; Wed, 10 Apr 2024 10:38:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C56E66B0095 for ; Wed, 10 Apr 2024 10:38:38 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8CCEE1407DB for ; Wed, 10 Apr 2024 14:38:38 +0000 (UTC) X-FDA: 81993878316.11.FCE057A Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf16.hostedemail.com (Postfix) with ESMTP id 4F7EF180010 for ; Wed, 10 Apr 2024 14:38:35 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf16.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759917; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UtblERf2SjZldtLbjWMgxYmXdH99mF3nTKBUxIYqrQE=; b=RkHW3YI1qMQINoknhMXMtO3yEPKscG2EH+ZYgzW1EWaWAqzKzaFSXawvTYrXTRvtxWvi/X cpCGR+FMyrYfY1Y4Iq9Mbjv3Nbu707RcuUM8C4zvEy2hpJzqfLog4rz64RUz0XBguh/4Vm Vph++SCew5Pgh3tJjGO4Da1VxJBDKAg= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf16.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759917; a=rsa-sha256; cv=none; b=ZsnFWjgW4+MebS/Hwr9FcRcDTE6Ryq7oGTF9d5XaLdXp7IZqkNVsEQaodKhLq5cmuiAJjL U9u9oRMjkybUvM1HC/wofksDZLXDzQL+P2jLkq/ORW8uCAP0dwGNMP8KUjqgo0GZT95Rma 5W5QhwhK70pyQ5z+yk+xey/fjrJA6cg= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56X36bcz4f3k6L for ; Wed, 10 Apr 2024 22:38:28 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id D40391A016E for ; Wed, 10 Apr 2024 22:38:32 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S15; Wed, 10 Apr 2024 22:38:32 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 11/34] ext4: optimize the EXT4_GET_BLOCKS_DELALLOC_RESERVE flag set Date: Wed, 10 Apr 2024 22:29:25 +0800 Message-Id: <20240410142948.2817554-12-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S15 X-Coremail-Antispam: 1UD129KBjvJXoWxZrWUuryxGrWDCFy3CFyrtFb_yoW5XryDpr WfCFyrGan2ga45Za93Ww18Wr1akan7GF4UArWS93yUZ3yakryfKF98tFyrZFyxK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eDY8AewJ0yueQ/V0sLPWjLzpWprXHgLrL4HxCsdrgSTmKyI6hSmhd+jErGOwIc/luPG4 RlfrAoFX 7fymALbORiQi2+OlMyd7AX1A9xfNjDLsjyVg9N1vf3FRHI0hbBJAK6ycPag== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Magic EXT4_GET_BLOCKS_DELALLOC_RESERVE means caller is from the delayed allocation writeout path, and the blocks and quotas has already been checked when the data was copied into the page cache, there is no need to check them again when we do the real allocation. But now we only set this magic when allocating delayed allocated clusters, it makes things complicated because we have to deal with the case of allocating non-delayed allocated clusters, e.g. from fallocate, because in this case, free space has already been claimed by ext4_mb_new_blocks(), we shouldn't claim it again. Move setting EXT4_GET_BLOCKS_DELALLOC_RESERVE to where we actually do block allocation could simplify the handling process a lot, it means that we always set this magic once the allocation range covers delalloc blocks, don't distinguish the allocation path. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 10a256cfcaa1..fd5a27db62c0 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -489,6 +489,14 @@ static int ext4_map_create_blocks(handle_t *handle, struct inode *inode, unsigned int status; int err, retval = 0; + /* + * We pass in the magic EXT4_GET_BLOCKS_DELALLOC_RESERVE + * indicates that the blocks and quotas has already been + * checked when the data was copied into the page cache. + */ + if (map->m_flags & EXT4_MAP_DELAYED) + flags |= EXT4_GET_BLOCKS_DELALLOC_RESERVE; + /* * Here we clear m_flags because after allocating an new extent, * it will be set again. @@ -2216,11 +2224,6 @@ static int mpage_map_one_extent(handle_t *handle, struct mpage_da_data *mpd) * writeback and there is nothing we can do about it so it might result * in data loss. So use reserved blocks to allocate metadata if * possible. - * - * We pass in the magic EXT4_GET_BLOCKS_DELALLOC_RESERVE if - * the blocks in question are delalloc blocks. This indicates - * that the blocks and quotas has already been checked when - * the data was copied into the page cache. */ get_blocks_flags = EXT4_GET_BLOCKS_CREATE | EXT4_GET_BLOCKS_METADATA_NOFAIL | @@ -2228,8 +2231,6 @@ static int mpage_map_one_extent(handle_t *handle, struct mpage_da_data *mpd) dioread_nolock = ext4_should_dioread_nolock(inode); if (dioread_nolock) get_blocks_flags |= EXT4_GET_BLOCKS_IO_CREATE_EXT; - if (map->m_flags & BIT(BH_Delay)) - get_blocks_flags |= EXT4_GET_BLOCKS_DELALLOC_RESERVE; err = ext4_map_blocks(handle, inode, map, get_blocks_flags); if (err < 0) From patchwork Wed Apr 10 14:29:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624705 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F7F2CD1299 for ; Wed, 10 Apr 2024 14:39:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E37406B009C; Wed, 10 Apr 2024 10:38:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DE8406B009D; Wed, 10 Apr 2024 10:38:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C38676B009E; Wed, 10 Apr 2024 10:38:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A05F36B009D for ; Wed, 10 Apr 2024 10:38:40 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 41F4E1C0BB2 for ; Wed, 10 Apr 2024 14:38:40 +0000 (UTC) X-FDA: 81993878400.28.62CD446 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf22.hostedemail.com (Postfix) with ESMTP id BB9FEC000F for ; Wed, 10 Apr 2024 14:38:37 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf22.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759918; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SaKnKlF3eQCLh/1aZzbgmKRzj7eierdhG1udWlWN5gs=; b=U+dUqs1pp+n2F0HMN1pye5Y5K/On9SMEIOfPtIAuocndxrN0ZFXZb9arhRQr12kJWFlGxu azN3y5mhQ+Uj9C/w6tInZKR8juqQOqJqwenBvWsZCXt4gcbj3IXprKb16hoov3zkd13zxT L4H23TkU0uDbkJec4ey2yRaEIoP3AcU= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf22.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759918; a=rsa-sha256; cv=none; b=eveLCMspBAttFV5Po60+xq9bzDXnXW3Ewsdzg9MKvISbosVOQ1mt6XHq2xwSAjiRhfJSBD rirZG+YciQxhQ0rhXHYdAoKsCH3As298kAdLANK8gam7K/74m82SetOwlMwxGsJOlrWf4a d7lIK57xqUU9CVYRo7XkzgJ+CUECtek= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56S64j2z4f3lft for ; Wed, 10 Apr 2024 22:38:24 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 806841A0568 for ; Wed, 10 Apr 2024 22:38:33 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S16; Wed, 10 Apr 2024 22:38:33 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 12/34] ext4: don't set EXTENT_STATUS_DELAYED on allocated blocks Date: Wed, 10 Apr 2024 22:29:26 +0800 Message-Id: <20240410142948.2817554-13-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S16 X-Coremail-Antispam: 1UD129KBjvJXoW7ury7tw17uryDWrW3uFWUCFg_yoW8KF48p3 sxAr1rWF4UWw1UuayI9r48ur15GayjkrWDur4rur1rWayfCrySkF1qyFW0gF9FqrW8Z3WY qFWru34DCayfGa7anT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUHS14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAaw2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I 8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCF s4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFI xGxcIEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2AFwI0_GFv_Wryl42xK82IYc2Ij64vIr41l 4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2IqxVAqx4xG67AKxV WUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MIIYrxkI 7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_tr0E3s1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r 4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4UJVWx Jr1lIxAIcVC2z280aVCY1x0267AKxVWxJr0_GcJvcSsGvfC2KfnxnUUI43ZEXa7sRibyCP UUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: BB9FEC000F X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: epdzafmcmpknws97uojyh86ufuqjqcer X-HE-Tag: 1712759917-112495 X-HE-Meta: U2FsdGVkX1/ItFgnAaq3gpi7LI8iG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B24EEJuKjaZ4E+44XB2ryTlVnhJFTjpxMjc+ERtlPwI1Qf1uSuUDdztgPi7EQl4HT6i5q6URzowzZLikv3WJTJVOfZ6PockMvQ7vD4Jo/+SPuvNYa3/clqYTfd8c3LJzZg4VVtPl9t+/cyilS9h/xRVjrKhRLqtTz X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Since we always set EXT4_GET_BLOCKS_DELALLOC_RESERVE when allocating delalloc blocks, no matter whether allocating delayed or non-delayed allocated blocks. There is no need to keep delayed flag on unwritten extent status entry, so just drop it after blocks have been allocated. Signed-off-by: Zhang Yi --- fs/ext4/extents_status.c | 9 +-------- fs/ext4/inode.c | 11 ----------- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 2320b0d71001..952a38eaea0f 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -867,14 +867,7 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, return; BUG_ON(end < lblk); - - if ((status & EXTENT_STATUS_DELAYED) && - (status & EXTENT_STATUS_WRITTEN)) { - ext4_warning(inode->i_sb, "Inserting extent [%u/%u] as " - " delayed and written which can potentially " - " cause data loss.", lblk, len); - WARN_ON(1); - } + WARN_ON_ONCE(status & EXTENT_STATUS_DELAYED); newes.es_lblk = lblk; newes.es_len = len; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index fd5a27db62c0..752fc0555dc0 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -558,12 +558,6 @@ static int ext4_map_create_blocks(handle_t *handle, struct inode *inode, status = map->m_flags & EXT4_MAP_UNWRITTEN ? EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; - if (!(flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) && - !(status & EXTENT_STATUS_WRITTEN) && - ext4_es_scan_range(inode, &ext4_es_is_delayed, map->m_lblk, - map->m_lblk + map->m_len - 1)) - status |= EXTENT_STATUS_DELAYED; - ext4_es_insert_extent(inode, map->m_lblk, map->m_len, map->m_pblk, status); @@ -682,11 +676,6 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, status = map->m_flags & EXT4_MAP_UNWRITTEN ? EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; - if (!(flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) && - !(status & EXTENT_STATUS_WRITTEN) && - ext4_es_scan_range(inode, &ext4_es_is_delayed, map->m_lblk, - map->m_lblk + map->m_len - 1)) - status |= EXTENT_STATUS_DELAYED; ext4_es_insert_extent(inode, map->m_lblk, map->m_len, map->m_pblk, status); } From patchwork Wed Apr 10 14:29:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624704 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4D32CD11C2 for ; Wed, 10 Apr 2024 14:39:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 843586B009B; Wed, 10 Apr 2024 10:38:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F3B86B009C; Wed, 10 Apr 2024 10:38:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 695576B009D; Wed, 10 Apr 2024 10:38:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 47ADA6B009B for ; Wed, 10 Apr 2024 10:38:40 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 15FBA1207C3 for ; Wed, 10 Apr 2024 14:38:40 +0000 (UTC) X-FDA: 81993878400.18.FEF269C Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf04.hostedemail.com (Postfix) with ESMTP id AA38E40006 for ; Wed, 10 Apr 2024 14:38:37 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759918; a=rsa-sha256; cv=none; b=JkA1EE9uZ1lKZspJN9Xhj4rTbBDHmdV1N9oB+QMVIriSiK1ntj2TJdh3rDVH6PydLJgW9Y xB1COkfS24ZZnJppWSJu7APAluiwJ2+VOjyjZxSRp2dvBNJ8flno2sMFl9+/4iYlZ7Qfl4 3MYNlv5oU8eEDDgaJ6Hy1wbTzzJp4Vs= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759918; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XmGlqO05uCWAx2h9YEVVAjwERSqwY7O+ms/+oS1z0DE=; b=5P63+hmKHr+2U/LsUwHvfBJ3qWdxvrE3wxZ+lQhwm39hjeqelZ98Q+bIhYT4jNYC7kt9O3 sFCTOPJfAQKJKy+YBsZgWWhewoGmL1p0+bOmJtw+MffE0PcQaUMn3V82cb+YPjTnWrYjrg +2iGUjPo/7NTYc+FXlCtld95U0wBfoo= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56Y5BL6z4f3jkk for ; Wed, 10 Apr 2024 22:38:29 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 267CC1A016E for ; Wed, 10 Apr 2024 22:38:34 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S17; Wed, 10 Apr 2024 22:38:33 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 13/34] ext4: let __revise_pending() return newly inserted pendings Date: Wed, 10 Apr 2024 22:29:27 +0800 Message-Id: <20240410142948.2817554-14-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S17 X-Coremail-Antispam: 1UD129KBjvJXoWxKFyfXw47WrWkWF15AryrJFb_yoW7GF1xp3 yY9as8CryrXw1jg3yFyF4UZr1Yg3W8JFWDXrZakrySkFyrJFyYkF10yF1avF1rCrWxJw13 XFWjk34Uu3WUKaDanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBId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FzPkj4wUNFgmdk2ePruE4pU5aeV5jknJbA2Jjx+uQI0I8m6OjHLPZjzYuxxkmGkqV4hSsI0sdGj4jFMqI/c0UZsx5K4h3eEi45mtjDGzQPZIxvdQ02ZiTASQVuAIRYsUOGu3Ht42UvCJK1D27VXzC+JFQ9EsW5u+5QIn4LxGkR47Vskxy5bEgbq7nbmi1txThZ8+qVG79sLNMELy1YsBnXIoTmhspeWSzkxku7731M7gJkUIkrR3wIVREygv1VdcvZ3GUhj1cJIGSqZNbInY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Let __insert_pending() return 1 after successfully inserting a new pending cluster, and also let __revise_pending() to return the number of of newly inserted pendings. Signed-off-by: Zhang Yi --- fs/ext4/extents_status.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 952a38eaea0f..382a96c1bc5c 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -885,7 +885,7 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, es1 = __es_alloc_extent(true); if ((err1 || err2) && !es2) es2 = __es_alloc_extent(true); - if ((err1 || err2 || err3) && revise_pending && !pr) + if ((err1 || err2 || err3 < 0) && revise_pending && !pr) pr = __alloc_pending(true); write_lock(&EXT4_I(inode)->i_es_lock); @@ -913,7 +913,7 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, if (revise_pending) { err3 = __revise_pending(inode, lblk, len, &pr); - if (err3 != 0) + if (err3 < 0) goto error; if (pr) { __free_pending(pr); @@ -922,7 +922,7 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, } error: write_unlock(&EXT4_I(inode)->i_es_lock); - if (err1 || err2 || err3) + if (err1 || err2 || err3 < 0) goto retry; ext4_es_print_tree(inode); @@ -1931,7 +1931,7 @@ static struct pending_reservation *__get_pending(struct inode *inode, * @lblk - logical block in the cluster to be added * @prealloc - preallocated pending entry * - * Returns 0 on successful insertion and -ENOMEM on failure. If the + * Returns 1 on successful insertion and -ENOMEM on failure. If the * pending reservation is already in the set, returns successfully. */ static int __insert_pending(struct inode *inode, ext4_lblk_t lblk, @@ -1975,6 +1975,7 @@ static int __insert_pending(struct inode *inode, ext4_lblk_t lblk, rb_link_node(&pr->rb_node, parent, p); rb_insert_color(&pr->rb_node, &tree->root); + ret = 1; out: return ret; @@ -2089,7 +2090,7 @@ void ext4_es_insert_delayed_extent(struct inode *inode, ext4_lblk_t lblk, es1 = __es_alloc_extent(true); if ((err1 || err2) && !es2) es2 = __es_alloc_extent(true); - if (err1 || err2 || err3) { + if (err1 || err2 || err3 < 0) { if (lclu_allocated && !pr1) pr1 = __alloc_pending(true); if (end_allocated && !pr2) @@ -2119,7 +2120,7 @@ void ext4_es_insert_delayed_extent(struct inode *inode, ext4_lblk_t lblk, if (lclu_allocated) { err3 = __insert_pending(inode, lblk, &pr1); - if (err3 != 0) + if (err3 < 0) goto error; if (pr1) { __free_pending(pr1); @@ -2128,7 +2129,7 @@ void ext4_es_insert_delayed_extent(struct inode *inode, ext4_lblk_t lblk, } if (end_allocated) { err3 = __insert_pending(inode, end, &pr2); - if (err3 != 0) + if (err3 < 0) goto error; if (pr2) { __free_pending(pr2); @@ -2137,7 +2138,7 @@ void ext4_es_insert_delayed_extent(struct inode *inode, ext4_lblk_t lblk, } error: write_unlock(&EXT4_I(inode)->i_es_lock); - if (err1 || err2 || err3) + if (err1 || err2 || err3 < 0) goto retry; ext4_es_print_tree(inode); @@ -2247,7 +2248,9 @@ unsigned int ext4_es_delayed_clu(struct inode *inode, ext4_lblk_t lblk, * * Used after a newly allocated extent is added to the extents status tree. * Requires that the extents in the range have either written or unwritten - * status. Must be called while holding i_es_lock. + * status. Must be called while holding i_es_lock. Returns number of new + * inserts pending cluster on insert pendings, returns 0 on remove pendings, + * return -ENOMEM on failure. */ static int __revise_pending(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t len, @@ -2257,6 +2260,7 @@ static int __revise_pending(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t end = lblk + len - 1; ext4_lblk_t first, last; bool f_del = false, l_del = false; + int pendings = 0; int ret = 0; if (len == 0) @@ -2284,6 +2288,7 @@ static int __revise_pending(struct inode *inode, ext4_lblk_t lblk, ret = __insert_pending(inode, first, prealloc); if (ret < 0) goto out; + pendings += ret; } else { last = EXT4_LBLK_CMASK(sbi, end) + sbi->s_cluster_ratio - 1; @@ -2295,6 +2300,7 @@ static int __revise_pending(struct inode *inode, ext4_lblk_t lblk, ret = __insert_pending(inode, last, prealloc); if (ret < 0) goto out; + pendings += ret; } else __remove_pending(inode, last); } @@ -2307,6 +2313,7 @@ static int __revise_pending(struct inode *inode, ext4_lblk_t lblk, ret = __insert_pending(inode, first, prealloc); if (ret < 0) goto out; + pendings += ret; } else __remove_pending(inode, first); @@ -2318,9 +2325,10 @@ static int __revise_pending(struct inode *inode, ext4_lblk_t lblk, ret = __insert_pending(inode, last, prealloc); if (ret < 0) goto out; + pendings += ret; } else __remove_pending(inode, last); } out: - return ret; + return (ret < 0) ? ret : pendings; } From patchwork Wed Apr 10 14:29:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624706 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B93A0CD128A for ; Wed, 10 Apr 2024 14:39:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5639F6B00A3; Wed, 10 Apr 2024 10:38:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 49F006B00A1; Wed, 10 Apr 2024 10:38:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 276BD6B00A0; Wed, 10 Apr 2024 10:38:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id ECE536B009E for ; Wed, 10 Apr 2024 10:38:40 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BEBFA120801 for ; Wed, 10 Apr 2024 14:38:40 +0000 (UTC) X-FDA: 81993878400.27.0E68869 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf10.hostedemail.com (Postfix) with ESMTP id 5B34BC0006 for ; Wed, 10 Apr 2024 14:38:37 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf10.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759919; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CnEJxFuFA75awkrxT4BgGRVQ2Ql24WzoSibwoIc+OZo=; b=pgRYXFkTVknXgY50wJtUBTGBpYXpKBBRPbAT9F4t0xsOh+tLU436uqbUjEB4VMwceaF7E4 2yYasuvdH+W81u4aSfaxK2OVvyI1/hrrq9D5izNF4HAcNizPaAEHeliNgVNY3sGwH+wGal VDa1v1+vN28H55j2t8//vMKrkR/0Y6o= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf10.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759919; a=rsa-sha256; cv=none; b=fOSXOZ6JdfV1LSKImUyIVM2E9SgldJwMKg8VfCHRqPLxyLg+bm88yNZW9PDP2qrDl2OxJK QNijnAo7vgkmY0EDzrqJ+JIt8iP5BOX2p2kDw6P4qC9KhAqzlT3qcy+Clbq3mGDJRxDjdr EGZP7MGJ1TzuTV4qFwbS61Qq536fnt4= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56V17yBz4f3m7N for ; Wed, 10 Apr 2024 22:38:26 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id C81041A0568 for ; Wed, 10 Apr 2024 22:38:34 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S18; Wed, 10 Apr 2024 22:38:34 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 14/34] ext4: count removed reserved blocks for delalloc only extent entry Date: Wed, 10 Apr 2024 22:29:28 +0800 Message-Id: <20240410142948.2817554-15-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6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oETpdDNqAEJ8d17LGO4JWc8481DjbE6QK7l32s7koVAqwjRL8EQ8T/quW3EPLnwfs1i+TwB8zlfenpCEd6KV8MTNtAKCBH+qtwZHX2T+8r+CPxariEKu6wioN/0EObCv1eb+fT9O/ho5Cxer1VgQ3zDuD/W+lZd3kWaW970QiCNkPsd5qtomaVQMxjZk/SxJ4oVUy5PR4BsUmSqYEWp /cng1eYu QvjZ/nLhojMNujkHu+zlZSJbOtJxuk6+F5m4xkOgMCcqhqCrP1fah6ykeRv3qrjm1dHKzNoRQl8PnqFQhAz75tgQsnm1WHm59zo7rEz0oMOx5uV9ugwt++6JGLPNtYW6Mvf0eEQn1q4gR6iKq92vjovuEKOXVleS4odGlJ5OjOI97z4fxOleHGDLZkZCaPHLw+K+tSx7+qax4GJJJ+eXDfqg7Mv/6iknnpIeGL+19nZzF9h9e4b3ewtAcp3cqvuZfWSUp X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Current __es_remove_extent() only count reserved clusters if the removed extent entry is delalloc, it doesn't count reserved blocks if the bigalloc feature is enabled, so we can't get reserved block number. However, it's useful to distinguish whether we are allocating delalloc range in one cluster, so add a parameter to count the reserved blocks number too. Signed-off-by: Zhang Yi --- fs/ext4/extents_status.c | 64 +++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 382a96c1bc5c..38ec2cc5ae3b 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -141,13 +141,18 @@ * -- Extent-level locking */ +struct rsvd_info { + int delonly_cluster; /* reserved clusters for delalloc es entry */ + int delonly_block; /* reserved blocks for delalloc es entry */ +}; + static struct kmem_cache *ext4_es_cachep; static struct kmem_cache *ext4_pending_cachep; static int __es_insert_extent(struct inode *inode, struct extent_status *newes, struct extent_status *prealloc); static int __es_remove_extent(struct inode *inode, ext4_lblk_t lblk, - ext4_lblk_t end, int *reserved, + ext4_lblk_t end, struct rsvd_info *rinfo, struct extent_status *prealloc); static int es_reclaim_extents(struct ext4_inode_info *ei, int *nr_to_scan); static int __es_shrink(struct ext4_sb_info *sbi, int nr_to_scan, @@ -1042,7 +1047,8 @@ int ext4_es_lookup_extent(struct inode *inode, ext4_lblk_t lblk, } struct rsvd_count { - int ndelonly; + int ndelonly_cluster; + int ndelonly_block; bool first_do_lblk_found; ext4_lblk_t first_do_lblk; ext4_lblk_t last_do_lblk; @@ -1068,7 +1074,8 @@ static void init_rsvd(struct inode *inode, ext4_lblk_t lblk, struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); struct rb_node *node; - rc->ndelonly = 0; + rc->ndelonly_cluster = 0; + rc->ndelonly_block = 0; /* * for bigalloc, note the first delonly block in the range has not @@ -1116,11 +1123,13 @@ static void count_rsvd(struct inode *inode, ext4_lblk_t lblk, long len, WARN_ON(len <= 0); if (sbi->s_cluster_ratio == 1) { - rc->ndelonly += (int) len; + rc->ndelonly_cluster += (int) len; + rc->ndelonly_block = rc->ndelonly_cluster; return; } /* bigalloc */ + rc->ndelonly_block += (int)len; i = (lblk < es->es_lblk) ? es->es_lblk : lblk; end = lblk + (ext4_lblk_t) len - 1; @@ -1140,7 +1149,7 @@ static void count_rsvd(struct inode *inode, ext4_lblk_t lblk, long len, * doesn't start with it, count it and stop tracking */ if (rc->partial && (rc->lclu != EXT4_B2C(sbi, i))) { - rc->ndelonly++; + rc->ndelonly_cluster++; rc->partial = false; } @@ -1150,7 +1159,7 @@ static void count_rsvd(struct inode *inode, ext4_lblk_t lblk, long len, */ if (EXT4_LBLK_COFF(sbi, i) != 0) { if (end >= EXT4_LBLK_CFILL(sbi, i)) { - rc->ndelonly++; + rc->ndelonly_cluster++; rc->partial = false; i = EXT4_LBLK_CFILL(sbi, i) + 1; } @@ -1162,7 +1171,7 @@ static void count_rsvd(struct inode *inode, ext4_lblk_t lblk, long len, */ if ((i + sbi->s_cluster_ratio - 1) <= end) { nclu = (end - i + 1) >> sbi->s_cluster_bits; - rc->ndelonly += nclu; + rc->ndelonly_cluster += nclu; i += nclu << sbi->s_cluster_bits; } @@ -1242,9 +1251,9 @@ static unsigned int get_rsvd(struct inode *inode, ext4_lblk_t end, if (sbi->s_cluster_ratio > 1) { /* count any remaining partial cluster */ if (rc->partial) - rc->ndelonly++; + rc->ndelonly_cluster++; - if (rc->ndelonly == 0) + if (rc->ndelonly_cluster == 0) return 0; first_lclu = EXT4_B2C(sbi, rc->first_do_lblk); @@ -1261,7 +1270,7 @@ static unsigned int get_rsvd(struct inode *inode, ext4_lblk_t end, while (es && ext4_es_end(es) >= EXT4_LBLK_CMASK(sbi, rc->first_do_lblk)) { if (ext4_es_is_delonly(es)) { - rc->ndelonly--; + rc->ndelonly_cluster--; left_delonly = true; break; } @@ -1281,7 +1290,7 @@ static unsigned int get_rsvd(struct inode *inode, ext4_lblk_t end, while (es && es->es_lblk <= EXT4_LBLK_CFILL(sbi, rc->last_do_lblk)) { if (ext4_es_is_delonly(es)) { - rc->ndelonly--; + rc->ndelonly_cluster--; right_delonly = true; break; } @@ -1327,7 +1336,7 @@ static unsigned int get_rsvd(struct inode *inode, ext4_lblk_t end, if (count_pending) { pr = __pr_tree_search(&tree->root, first_lclu); while (pr && pr->lclu <= last_lclu) { - rc->ndelonly--; + rc->ndelonly_cluster--; node = rb_next(&pr->rb_node); rb_erase(&pr->rb_node, &tree->root); __free_pending(pr); @@ -1338,7 +1347,7 @@ static unsigned int get_rsvd(struct inode *inode, ext4_lblk_t end, } } } - return rc->ndelonly; + return rc->ndelonly_cluster; } @@ -1348,16 +1357,17 @@ static unsigned int get_rsvd(struct inode *inode, ext4_lblk_t end, * @inode - file containing range * @lblk - first block in range * @end - last block in range - * @reserved - number of cluster reservations released + * @rinfo - reserved information collected, includes number of + * block/cluster reservations released * @prealloc - pre-allocated es to avoid memory allocation failures * - * If @reserved is not NULL and delayed allocation is enabled, counts + * If @rinfo is not NULL and delayed allocation is enabled, counts * block/cluster reservations freed by removing range and if bigalloc * enabled cancels pending reservations as needed. Returns 0 on success, * error code on failure. */ static int __es_remove_extent(struct inode *inode, ext4_lblk_t lblk, - ext4_lblk_t end, int *reserved, + ext4_lblk_t end, struct rsvd_info *rinfo, struct extent_status *prealloc) { struct ext4_es_tree *tree = &EXT4_I(inode)->i_es_tree; @@ -1367,11 +1377,15 @@ static int __es_remove_extent(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t len1, len2; ext4_fsblk_t block; int err = 0; - bool count_reserved = true; + bool count_reserved = false; struct rsvd_count rc; - if (reserved == NULL || !test_opt(inode->i_sb, DELALLOC)) - count_reserved = false; + if (rinfo) { + rinfo->delonly_cluster = 0; + rinfo->delonly_block = 0; + if (test_opt(inode->i_sb, DELALLOC)) + count_reserved = true; + } es = __es_tree_search(&tree->root, lblk); if (!es) @@ -1469,8 +1483,10 @@ static int __es_remove_extent(struct inode *inode, ext4_lblk_t lblk, } out_get_reserved: - if (count_reserved) - *reserved = get_rsvd(inode, end, es, &rc); + if (count_reserved) { + rinfo->delonly_cluster = get_rsvd(inode, end, es, &rc); + rinfo->delonly_block = rc.ndelonly_block; + } out: return err; } @@ -1489,8 +1505,8 @@ void ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t len) { ext4_lblk_t end; + struct rsvd_info rinfo; int err = 0; - int reserved = 0; struct extent_status *es = NULL; if (EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY) @@ -1515,7 +1531,7 @@ void ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk, * is reclaimed. */ write_lock(&EXT4_I(inode)->i_es_lock); - err = __es_remove_extent(inode, lblk, end, &reserved, es); + err = __es_remove_extent(inode, lblk, end, &rinfo, es); /* Free preallocated extent if it didn't get used. */ if (es) { if (!es->es_len) @@ -1527,7 +1543,7 @@ void ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk, goto retry; ext4_es_print_tree(inode); - ext4_da_release_space(inode, reserved); + ext4_da_release_space(inode, rinfo.delonly_cluster); return; } From patchwork Wed Apr 10 14:29:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624708 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E5E9CD11C2 for ; Wed, 10 Apr 2024 14:39:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E37856B009D; Wed, 10 Apr 2024 10:38:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DC19F6B00A0; Wed, 10 Apr 2024 10:38:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC5846B00A1; Wed, 10 Apr 2024 10:38:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8A9A76B009D for ; Wed, 10 Apr 2024 10:38:41 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 54CB2807DC for ; Wed, 10 Apr 2024 14:38:41 +0000 (UTC) X-FDA: 81993878442.13.17E2E43 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf27.hostedemail.com (Postfix) with ESMTP id E003D4000C for ; Wed, 10 Apr 2024 14:38:38 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759919; a=rsa-sha256; cv=none; b=uz3qzLphFMjoNb71q70oZyHWAuJAGdBJVMY5P2M9hbyojbCP6w8IcYrm6KRanlvqNy0iv2 b1MkSVqQ9SNLr8bTRpBfqsBmdxTtHSELDc/WBAnX1crnG0Ohpec4CAL5POnYn0KQE+g5jG MDJ0FPswf2sZ1VrI7q++FghT/73TE0M= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759919; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=upAYWM8WgHqo23GX2mAxJ5/S2qs3yjrM0C+UPUpJNSw=; b=zkmdnKi1H64irJold7ewgm/VBOl/hrHNhUWIO6WL5dOl1u5J4VCtQv/5rtdogHRisqmQLV HKhcY6VdypP0jpMWztVp+DUhXxMVF7qK+wdVVaRXd/zHLMAZ11nMWSO5Fn7Oo7mzZECcNA ORqVEizxczwBNCQg7EqXHGTcXh0GpYU= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56b0BQmz4f3kKP for ; Wed, 10 Apr 2024 22:38:31 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 6EE231A0D97 for ; Wed, 10 Apr 2024 22:38:35 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S19; Wed, 10 Apr 2024 22:38:35 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 15/34] ext4: update delalloc data reserve spcae in ext4_es_insert_extent() Date: Wed, 10 Apr 2024 22:29:29 +0800 Message-Id: <20240410142948.2817554-16-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S19 X-Coremail-Antispam: 1UD129KBjvJXoW3JryxCFy7GFy8tr1kWF13CFg_yoW7ZF47pr ZxCr1fJw1rXw1qgrZ3Xw1UWr15Way8Gr4UGrZaqry8uFW3AF1fKF1DtF1rZFWY9rW8WFn8 XFyUCw17ua98Ca7anT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUHS14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAaw2AFwI0_Jr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nOlFHLmV5rJ+UYi4L2l9RIveOwqYU1kK/uhKGJTYFqOAP+9/Ri1W13KsY111tubK1pYky73j+hYWjU2BmuUxO2traV+9zNXlLulpWJSLlnr6YX2agykcbCHXxmoEvH3wqz6eDh3sJ/LXjmlMFWFdu6cWsI8R5eRcZwEALQ6GQkhVf2lJnj/OVrnmDcowpaS5dcN7B/kok3sVrE5yjwnzotGq0zXtOh1aAcQ1VKCRvfyHvAHjFsY1vMPnhyVjZrB868xUwz4dL3icr5EV5RtR65IXIYRAoJ681+p5e87PwflELN0CdMezKVYJwKUItFFZ5dJT/uVBm5zN70ovpssne7O/q2l6xLUDanfQdwBFXGtJmx3KxvQxSW1RY5ZMPbEy3zsaETQhBjqApXeIHOxbudDYyiSiBYXqvZ+uomWZNOlwrLXXjPhCVGueGbzQcLgv/Z3oTUkm7AGnaCXr4w/IXbIVgKQgwT5lUhGuaZ4YgyJYQBR3XL2zSvfMOuosnD1hAOxSk2bHbEkjfAoKV3XzvUNTfbiNOTN61zSWUXYyQTYVX6cjIkvVe6KXjv9UZTNYKpiiNNrfzAyqan3l5PTeHQz0k94nIXdn58IEOhaFJO4YP2n8XlvvAbxwPdp/2KpCC/2LkRO97LsyTtbJaCV+gyuHMTCoryoVHz1TOl1k6Gk6Zof0Ub0iVW oRGTE/Vc RoMvuU7vOBtWfjWLsKS/c9XQVlvjIRd98H+cwb1rX4IGYszLbzM/toPcEc6NT7FISD1qi+39mcbJuL65YNrroK5zUPGBpAhk1rGpB6AnCVjPEJoehL3WbIvrfyq8sJdxK1XF6VvCGRpFDuNlA9SMxXicqkRBxGX78MGkkU3wjry1bI8N3qby16RCAalGo/14istfdEbuIVnW2JpqvU/ljE18pNFdatvaCnfmcV/q3c96nhbsLMaN6DHvgZbGgERoCNSZgd7Bp5lI6OSR13oYsEYoUEuwlTymh5qmcT+1MLED6l34= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Now we update data reserved space for delalloc after allocating new blocks in ext4_{ind|ext}_map_blocks(). If bigalloc feature is enabled, we also need to query the extents_status tree and calculate the exact reserved clusters. This is complicated and it appears ext4_es_insert_extent() is a better place to do this job, it could make things simple because __es_remove_extent() could count delalloc blocks and __revise_pending() and return newly added pending count. One special case needs to concern is the quota claiming, when bigalloc is enabled, if the delayed cluster allocation has been raced by another no-delayed allocation which doesn't overlap the delayed blocks (from fallocate, filemap, DIO...) , we cannot claim quota as usual because the racer have already done it, so we also need to check the counted reserved blocks. | one cluster | ------------------------------------------- | | delayed es | ------------------------------------------- ^ ^ | fallocate | <- don't claim quota Signed-off-by: Zhang Yi --- fs/ext4/extents.c | 37 ------------------------------------- fs/ext4/extents_status.c | 22 +++++++++++++++++++++- fs/ext4/indirect.c | 7 ------- 3 files changed, 21 insertions(+), 45 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index e57054bdc5fd..8bc8a519f745 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -4355,43 +4355,6 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, goto out; } - /* - * Reduce the reserved cluster count to reflect successful deferred - * allocation of delayed allocated clusters or direct allocation of - * clusters discovered to be delayed allocated. Once allocated, a - * cluster is not included in the reserved count. - */ - if (test_opt(inode->i_sb, DELALLOC) && allocated_clusters) { - if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) { - /* - * When allocating delayed allocated clusters, simply - * reduce the reserved cluster count and claim quota - */ - ext4_da_update_reserve_space(inode, allocated_clusters, - 1); - } else { - ext4_lblk_t lblk, len; - unsigned int n; - - /* - * When allocating non-delayed allocated clusters - * (from fallocate, filemap, DIO, or clusters - * allocated when delalloc has been disabled by - * ext4_nonda_switch), reduce the reserved cluster - * count by the number of allocated clusters that - * have previously been delayed allocated. Quota - * has been claimed by ext4_mb_new_blocks() above, - * so release the quota reservations made for any - * previously delayed allocated clusters. - */ - lblk = EXT4_LBLK_CMASK(sbi, map->m_lblk); - len = allocated_clusters << sbi->s_cluster_bits; - n = ext4_es_delayed_clu(inode, lblk, len); - if (n > 0) - ext4_da_update_reserve_space(inode, (int) n, 0); - } - } - /* * Cache the extent and update transaction to commit on fdatasync only * when it is _not_ an unwritten extent. diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 38ec2cc5ae3b..75227f151b8f 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -856,6 +856,8 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, struct extent_status newes; ext4_lblk_t end = lblk + len - 1; int err1 = 0, err2 = 0, err3 = 0; + struct rsvd_info rinfo; + int resv_used, pending = 0; struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); struct extent_status *es1 = NULL; struct extent_status *es2 = NULL; @@ -894,7 +896,7 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, pr = __alloc_pending(true); write_lock(&EXT4_I(inode)->i_es_lock); - err1 = __es_remove_extent(inode, lblk, end, NULL, es1); + err1 = __es_remove_extent(inode, lblk, end, &rinfo, es1); if (err1 != 0) goto error; /* Free preallocated extent if it didn't get used. */ @@ -924,9 +926,27 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, __free_pending(pr); pr = NULL; } + pending = err3; } error: write_unlock(&EXT4_I(inode)->i_es_lock); + /* + * Reduce the reserved cluster count to reflect successful deferred + * allocation of delayed allocated clusters or direct allocation of + * clusters discovered to be delayed allocated. Once allocated, a + * cluster is not included in the reserved count. + * + * When bigalloc is enabled, allocating non-delayed allocated blocks + * which belong to delayed allocated clusters (from fallocate, filemap, + * DIO, or clusters allocated when delalloc has been disabled by + * ext4_nonda_switch()). Quota has been claimed by ext4_mb_new_blocks(), + * so release the quota reservations made for any previously delayed + * allocated clusters. + */ + resv_used = rinfo.delonly_cluster + pending; + if (resv_used) + ext4_da_update_reserve_space(inode, resv_used, + rinfo.delonly_block); if (err1 || err2 || err3 < 0) goto retry; diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c index d8ca7f64f952..7404f0935c90 100644 --- a/fs/ext4/indirect.c +++ b/fs/ext4/indirect.c @@ -652,13 +652,6 @@ int ext4_ind_map_blocks(handle_t *handle, struct inode *inode, ext4_update_inode_fsync_trans(handle, inode, 1); count = ar.len; - /* - * Update reserved blocks/metadata blocks after successful block - * allocation which had been deferred till now. - */ - if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) - ext4_da_update_reserve_space(inode, count, 1); - got_it: map->m_flags |= EXT4_MAP_MAPPED; map->m_pblk = le32_to_cpu(chain[depth-1].key); From patchwork Wed Apr 10 14:29:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624709 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA8A3CD1299 for ; Wed, 10 Apr 2024 14:39:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4E7DA6B00A0; Wed, 10 Apr 2024 10:38:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 498A56B00A1; Wed, 10 Apr 2024 10:38:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3399F6B00A4; Wed, 10 Apr 2024 10:38:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 127296B00A0 for ; Wed, 10 Apr 2024 10:38:42 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D9540A0830 for ; Wed, 10 Apr 2024 14:38:41 +0000 (UTC) X-FDA: 81993878442.12.EBAC76C Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf22.hostedemail.com (Postfix) with ESMTP id 80D26C0007 for ; Wed, 10 Apr 2024 14:38:39 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf22.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759920; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LEsKMnu4ZxGTSHADa+88HaCdv8sKMA3qv/R1KjbnuXU=; b=0rxcKPQ5/LrQnPK79juXITq+uvxJMHNX2dgcmXayv2HU+GuQfx4QxcjpggNWw6tTpvcGK0 VTuufsOK6fwV0M0qllsvOg68PCu3C5CEHw6qcxHiFEIX1cO3CI+C2SxbLw3TsuycxOkVQW wgdDbsc8zeUknh/p137K4dVTHu39nH8= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf22.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759920; a=rsa-sha256; cv=none; b=h8hG0YY3SLS0a+bg/uJZZi/8dtUy2H3mX/V6sB9s/GvEl9x5tyL04AcC4KlXC73VsEJUSr NflCFxB5tgqMi2ZXFeMqwmCb1VTFexWdfZz6phsrGMdSicmcBy2qbmC52ZHZLc+VRs98mg d89Lo8HtJQAkT160a+NKa2k1iTCJEQw= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF56Y1lKTz4f3knN for ; Wed, 10 Apr 2024 22:38:29 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 18B741A0947 for ; Wed, 10 Apr 2024 22:38:36 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S20; Wed, 10 Apr 2024 22:38:35 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 16/34] ext4: drop ext4_es_delayed_clu() Date: Wed, 10 Apr 2024 22:29:30 +0800 Message-Id: <20240410142948.2817554-17-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S20 X-Coremail-Antispam: 1UD129KBjvJXoWxZw1fZw45Xw1xGrWrJF1rXrb_yoWrJFWDp3 43try7JrW3Xw4v9a1xtw18Xr15t3Wqk3yUGr93t3WFkFyrAr1SkFnYyryfZFyrtrWxZF1Y qFWj9a4UCF4jgFDanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUHa14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKw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asRJbTwetzA1xd3ttl3C8mXbc/e4Ny5GQp+MKM5LPz4jfrCT7h196mS/WxS52r2rYy+j1Y/byYhgv8+Hiw+HeFCL2pw+IkFm+nUr2p2UwSdnjB/kJEzBSxwd1jXqiwazCtkBy2Dvph9pq3AFnlhqm6gBoU5Ml2p1kt9tvvm2p2eGy9YvlHD5wZfLUQ8xj1cDUHc4Ik4Jmzl8503hNNS6AUW7brxLxKj3qu5nksQvYFAdQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi ext4_es_delayed_clu() and __es_delayed_clu() are not used, drop them. Signed-off-by: Zhang Yi --- fs/ext4/extents_status.c | 88 ---------------------------------------- fs/ext4/extents_status.h | 2 - 2 files changed, 90 deletions(-) diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 75227f151b8f..9cac4ea57b73 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -2182,94 +2182,6 @@ void ext4_es_insert_delayed_extent(struct inode *inode, ext4_lblk_t lblk, return; } -/* - * __es_delayed_clu - count number of clusters containing blocks that - * are delayed only - * - * @inode - file containing block range - * @start - logical block defining start of range - * @end - logical block defining end of range - * - * Returns the number of clusters containing only delayed (not delayed - * and unwritten) blocks in the range specified by @start and @end. Any - * cluster or part of a cluster within the range and containing a delayed - * and not unwritten block within the range is counted as a whole cluster. - */ -static unsigned int __es_delayed_clu(struct inode *inode, ext4_lblk_t start, - ext4_lblk_t end) -{ - struct ext4_es_tree *tree = &EXT4_I(inode)->i_es_tree; - struct extent_status *es; - struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); - struct rb_node *node; - ext4_lblk_t first_lclu, last_lclu; - unsigned long long last_counted_lclu; - unsigned int n = 0; - - /* guaranteed to be unequal to any ext4_lblk_t value */ - last_counted_lclu = ~0ULL; - - es = __es_tree_search(&tree->root, start); - - while (es && (es->es_lblk <= end)) { - if (ext4_es_is_delonly(es)) { - if (es->es_lblk <= start) - first_lclu = EXT4_B2C(sbi, start); - else - first_lclu = EXT4_B2C(sbi, es->es_lblk); - - if (ext4_es_end(es) >= end) - last_lclu = EXT4_B2C(sbi, end); - else - last_lclu = EXT4_B2C(sbi, ext4_es_end(es)); - - if (first_lclu == last_counted_lclu) - n += last_lclu - first_lclu; - else - n += last_lclu - first_lclu + 1; - last_counted_lclu = last_lclu; - } - node = rb_next(&es->rb_node); - if (!node) - break; - es = rb_entry(node, struct extent_status, rb_node); - } - - return n; -} - -/* - * ext4_es_delayed_clu - count number of clusters containing blocks that - * are both delayed and unwritten - * - * @inode - file containing block range - * @lblk - logical block defining start of range - * @len - number of blocks in range - * - * Locking for external use of __es_delayed_clu(). - */ -unsigned int ext4_es_delayed_clu(struct inode *inode, ext4_lblk_t lblk, - ext4_lblk_t len) -{ - struct ext4_inode_info *ei = EXT4_I(inode); - ext4_lblk_t end; - unsigned int n; - - if (len == 0) - return 0; - - end = lblk + len - 1; - WARN_ON(end < lblk); - - read_lock(&ei->i_es_lock); - - n = __es_delayed_clu(inode, lblk, end); - - read_unlock(&ei->i_es_lock); - - return n; -} - /* * __revise_pending - makes, cancels, or leaves unchanged pending cluster * reservations for a specified block range depending diff --git a/fs/ext4/extents_status.h b/fs/ext4/extents_status.h index 3c8e2edee5d5..5b49cb3b9aff 100644 --- a/fs/ext4/extents_status.h +++ b/fs/ext4/extents_status.h @@ -252,8 +252,6 @@ extern bool ext4_is_pending(struct inode *inode, ext4_lblk_t lblk); extern void ext4_es_insert_delayed_extent(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t len, bool lclu_allocated, bool end_allocated); -extern unsigned int ext4_es_delayed_clu(struct inode *inode, ext4_lblk_t lblk, - ext4_lblk_t len); extern void ext4_clear_inode_es(struct inode *inode); #endif /* _EXT4_EXTENTS_STATUS_H */ From patchwork Wed Apr 10 14:29:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624710 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDA13CD11C2 for ; Wed, 10 Apr 2024 14:39:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FE286B00A1; Wed, 10 Apr 2024 10:38:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5AA4D6B00A4; Wed, 10 Apr 2024 10:38:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3FD856B00A5; Wed, 10 Apr 2024 10:38:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1C8F36B00A1 for ; Wed, 10 Apr 2024 10:38:43 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id DA333120815 for ; Wed, 10 Apr 2024 14:38:42 +0000 (UTC) X-FDA: 81993878484.25.3739CB8 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf28.hostedemail.com (Postfix) with ESMTP id 7A811C0015 for ; Wed, 10 Apr 2024 14:38:40 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759921; a=rsa-sha256; cv=none; b=Da6SNr6HRYtKfCljYPlNQlhFx4HqI1OZ1YdYqtkByz6eU1rKN+OO6jQO1v3NOrFwMGtgDe enN727Win+vkH8hrbNEjkOD2Ynq9CoJ5AFspFxoHAzot/ERDCBBl2cbcfPPyYrVUm8AUSd J/A0Nqv/bGD2/ThKiSINzfIGtsAsiVk= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759921; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DHxnVt2eCkNob2fbYWCpZnvTmN8bZoEP4xQkUMxT9ko=; b=Kte6NfGnBmXj1kdYQJsiDW9dWDReJKs4b9bgRlffLJ6ViVWjuenL3LoAcapFyAArXE8Qmv dWv332KIk96xRJ0/DGfAFmEysG9XnweY/0BlRGAF6naB/quokTCEN2XkRslKyOfYqgXxiZ /Ewkl6RTseHscmXQVVOfHmBu6Cjha+s= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF56Y6RGrz4f3knS for ; Wed, 10 Apr 2024 22:38:29 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id B92D51A016E for ; Wed, 10 Apr 2024 22:38:36 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S21; Wed, 10 Apr 2024 22:38:36 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 17/34] ext4: use ext4_map_query_blocks() in ext4_map_blocks() Date: Wed, 10 Apr 2024 22:29:31 +0800 Message-Id: <20240410142948.2817554-18-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S21 X-Coremail-Antispam: 1UD129KBjvJXoWxJryxuryUKF13tF13AFy8AFb_yoW8Gry3p3 sxAryfCw1UWr1q9a1xtr48Zry8K3WUKrWqqrWxGr1rA345Crn3tF45tFyfAFWDKrZ7Xw1Y qFWrKry8C3yrGrDanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUHa14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAaw2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I 8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCF s4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFI xGxcIEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2AFwI0_GFv_Wryl42xK82IYc2Ij64vIr41l 4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2IqxVAqx4xG67AKxV WUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MIIYrxkI 7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_tr0E3s1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r 4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4UJVWx Jr1lIxAIcVC2z280aVCY1x0267AKxVW0oVCq3bIYCTnIWIevJa73UjIFyTuYvjTRtOzsDU UUU X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 7A811C0015 X-Stat-Signature: 616fzwicwu8keg4i6hg61h69hb3g698e X-HE-Tag: 1712759920-351980 X-HE-Meta: U2FsdGVkX18MQdAX+6J1lpVNhqc3k8UdKmXszNg4rhtQK4ShV3wLHzlO9Exh9OagolaZOKF4wfXEyXEAcri2Sy74quPHR0zUU7I8LjCYa2bIlJuDgFKqZVazCvxM4XezVWwETQf8AnEzGhV/MwUrWTf0tYD2XJZZ5RI3par8UNeInMAWqjRtXfORaBoR1aMkuEqos+gZCv+gPzLeon4ccIg1nsxlsdZ49H6oDrj9pKHElLjxMysgTTfnA8x9oSC3uK+Mf68IMDWoRI1yRtKeRdPuQMXqFc4h39HQA5/fODdOullxIlgfKc6+/zQSkW97zS81HK+6Ij17/9sxFfkRdMSzgmOUEEmdVLN8v9ClzISSDe91//z40ivb78n2Rnt5F/SP/SiqAMd1DnALYtfn7e6EOrfT8iR9kiExBjsJdXlHsuK14K+rl7waZapYGo+OJQ6YJ/FE0tW16H32vF+RdQH4VmgiUJnvyhFEmt0N7wFBuOuLB5LJ3yW6Q2Tvl5decAVUX0Uf4CGyMNHRtZR7SP1P9FxyfL3aEpBvlBVQe5Us0YVaUB6tswyEu7NnwSgJWqNcWMHHC4ZNfL2AXBTupmr+H9THGqCTOQ5Y4wZh9H/LKfY+RrXzlW7VO2XYb/m9dt+DbKv4JYFNu7TXAyiLanHaxB/gnKLRBRQaq4wt5I/8EPaJ18APRY3fg5xLqqOfGvoUktHSoMeoq7EXD5KtBOXy7nBTKD69M7QqFiURojYlVMnG+qGhIOKEr9T2Y+uyp+rRQ/4C1O8kL+FX8srgtQjsnNyPr3jWLcJJwk4W1hGeAlLP5L/89YMP33geFvMrsfqzXag2IX/Razyy8EMzyLmPjnRUH2UDrLkvQvdPO0NgdsXdUxqHWVt8ClhV9YVhJyHrVGGOu3Plz8CySKEVSEXJjAtdHElt6z0Z7HkegHB7DL21p5G7rEOhufGKoDjBh8+CA7cLQEXusDelx1V 6hnuOchE XFAaiLKaS4PzD3zEKIE3ysnDz34d8BIpm3us5aL0etaysVIYT7fjJH9Dr7OtNAFG/96Aguzdf+DwtkHb+/vmMfx8LvTI5/fI+QY1lx8TiEZX6gw2gUiVMc+ChjchajQklnEDJlkBGhFJ8puogrVCib4A/6fN0sR1BWCLbU/p0WjqDfVpqzcg5p5FiG6x6So0HY0pVTYJbAWydpJ8kQrTi2XePChwzqr6mDvVeqPslAzFnfYq+oY7jX+Wz+eWsue5cMmJVhrezqV1uWpfkhISmvtTz4X+7EfM/jwnyE+Rx4LoA5aI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi The blocks map querying logic in ext4_map_blocks() are the same with ext4_map_query_blocks(), so use it directly. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 752fc0555dc0..64bdfa9e06b2 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -658,27 +658,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, * file system block. */ down_read(&EXT4_I(inode)->i_data_sem); - if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) { - retval = ext4_ext_map_blocks(handle, inode, map, 0); - } else { - retval = ext4_ind_map_blocks(handle, inode, map, 0); - } - if (retval > 0) { - unsigned int status; - - if (unlikely(retval != map->m_len)) { - ext4_warning(inode->i_sb, - "ES len assertion failed for inode " - "%lu: retval %d != map->m_len %d", - inode->i_ino, retval, map->m_len); - WARN_ON(1); - } - - status = map->m_flags & EXT4_MAP_UNWRITTEN ? - EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; - ext4_es_insert_extent(inode, map->m_lblk, map->m_len, - map->m_pblk, status); - } + retval = ext4_map_query_blocks(handle, inode, map); up_read((&EXT4_I(inode)->i_data_sem)); found: From patchwork Wed Apr 10 14:29:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624711 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CFE5CD1299 for ; Wed, 10 Apr 2024 14:39:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 007BE6B00A4; Wed, 10 Apr 2024 10:38:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EABED6B00A5; Wed, 10 Apr 2024 10:38:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CFAF96B00A6; Wed, 10 Apr 2024 10:38:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id AF9506B00A4 for ; Wed, 10 Apr 2024 10:38:43 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 48D51A0826 for ; Wed, 10 Apr 2024 14:38:43 +0000 (UTC) X-FDA: 81993878526.18.701E474 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf29.hostedemail.com (Postfix) with ESMTP id D9D06120026 for ; Wed, 10 Apr 2024 14:38:40 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf29.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759921; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TzYic44zaqX+U3I1GiheRJSXRGXxUJKuQ9Wjk84O6qE=; b=UnVVCL3vKYPRzAci7tRYnlS0jHKzC4TsPtPXFWT49DrVijnq1a2lcYWyPCOcMs1Q0fIDNn lXi8JbOkcsi26E9RSX9mvu8+iWIJmzrdjO64pKZMwUPen/8Q7Hw2P8X4mq6zcd89llfXB+ uVw+gE5C9UZ8fKJ79XFVpbNrcQ7iPmY= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf29.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759921; a=rsa-sha256; cv=none; b=VLYxUHpVRWvghOmgJJQF7IEM3ur/0WvpeKgJYhhnO3gqg0NosU7DMRHWNB3/KXBisN4HEI kKC8fex87WDDGgJXp2KcKolxtnrHlLXcT5BeG20zFej9FgHOwudvfytytQ5DFrhnuwBM5t JxypxZEXZTakQJNb/WVPBcWU26iKTPQ= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56X5GmZz4f3m7d for ; Wed, 10 Apr 2024 22:38:28 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 63F061A058D for ; Wed, 10 Apr 2024 22:38:37 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S22; Wed, 10 Apr 2024 22:38:37 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 18/34] ext4: drop ext4_es_is_delonly() Date: Wed, 10 Apr 2024 22:29:32 +0800 Message-Id: <20240410142948.2817554-19-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S22 X-Coremail-Antispam: 1UD129KBjvJXoWxXF18AFWxKrW3CrWUJr17Awb_yoWrKryfpF Z8J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DPSXuMF/CC0kKPmCck387I7g2YEov4jqPCCFJO+BViyTYqgL0dauhIGllbgRazgHVsowSeGtX2Z0yNYsvF1W1toPit16bHmKLN2oTMqDhcD3HulcN5veMt2ZEb6B KBjEV1HZ ysgs8Qy3/YMDWwmNJ/s4j5ipR2hEVyuWtMEOn3pZduq2g/zcG6rpUdPbRyJunXFT9EwybU2Tqv9zaFLeYNBLBGBV7NFW+nxuClwXPWTfQ6D4WfDSCSZegmaScPLUN0YDxunT63q/ESyiFvJ+7DCkC/w7B8gG8qgO7SnmNr55btdHNGyg5G/1pATGI5HvOuzcTmgrAWIGbnhiDuN/H9m+a5wqzgaH+PEekA2YOY4qXaUDqXu7mBi7/j0BM2btzxHGJuGHP X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Since we don't add delayed flag in unwritten extent status entry, so there is no difference between ext4_es_is_delayed() and ext4_es_is_delonly(), just drop ext4_es_is_delonly(). Signed-off-by: Zhang Yi --- fs/ext4/extents_status.c | 18 +++++++++--------- fs/ext4/extents_status.h | 5 ----- fs/ext4/inode.c | 4 ++-- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 9cac4ea57b73..062293e739cc 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -561,8 +561,8 @@ static int ext4_es_can_be_merged(struct extent_status *es1, if (ext4_es_is_hole(es1)) return 1; - /* we need to check delayed extent is without unwritten status */ - if (ext4_es_is_delayed(es1) && !ext4_es_is_unwritten(es1)) + /* we need to check delayed extent */ + if (ext4_es_is_delayed(es1)) return 1; return 0; @@ -1137,7 +1137,7 @@ static void count_rsvd(struct inode *inode, ext4_lblk_t lblk, long len, struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); ext4_lblk_t i, end, nclu; - if (!ext4_es_is_delonly(es)) + if (!ext4_es_is_delayed(es)) return; WARN_ON(len <= 0); @@ -1289,7 +1289,7 @@ static unsigned int get_rsvd(struct inode *inode, ext4_lblk_t end, es = rc->left_es; while (es && ext4_es_end(es) >= EXT4_LBLK_CMASK(sbi, rc->first_do_lblk)) { - if (ext4_es_is_delonly(es)) { + if (ext4_es_is_delayed(es)) { rc->ndelonly_cluster--; left_delonly = true; break; @@ -1309,7 +1309,7 @@ static unsigned int get_rsvd(struct inode *inode, ext4_lblk_t end, } while (es && es->es_lblk <= EXT4_LBLK_CFILL(sbi, rc->last_do_lblk)) { - if (ext4_es_is_delonly(es)) { + if (ext4_es_is_delayed(es)) { rc->ndelonly_cluster--; right_delonly = true; break; @@ -2230,7 +2230,7 @@ static int __revise_pending(struct inode *inode, ext4_lblk_t lblk, if (EXT4_B2C(sbi, lblk) == EXT4_B2C(sbi, end)) { first = EXT4_LBLK_CMASK(sbi, lblk); if (first != lblk) - f_del = __es_scan_range(inode, &ext4_es_is_delonly, + f_del = __es_scan_range(inode, &ext4_es_is_delayed, first, lblk - 1); if (f_del) { ret = __insert_pending(inode, first, prealloc); @@ -2242,7 +2242,7 @@ static int __revise_pending(struct inode *inode, ext4_lblk_t lblk, sbi->s_cluster_ratio - 1; if (last != end) l_del = __es_scan_range(inode, - &ext4_es_is_delonly, + &ext4_es_is_delayed, end + 1, last); if (l_del) { ret = __insert_pending(inode, last, prealloc); @@ -2255,7 +2255,7 @@ static int __revise_pending(struct inode *inode, ext4_lblk_t lblk, } else { first = EXT4_LBLK_CMASK(sbi, lblk); if (first != lblk) - f_del = __es_scan_range(inode, &ext4_es_is_delonly, + f_del = __es_scan_range(inode, &ext4_es_is_delayed, first, lblk - 1); if (f_del) { ret = __insert_pending(inode, first, prealloc); @@ -2267,7 +2267,7 @@ static int __revise_pending(struct inode *inode, ext4_lblk_t lblk, last = EXT4_LBLK_CMASK(sbi, end) + sbi->s_cluster_ratio - 1; if (last != end) - l_del = __es_scan_range(inode, &ext4_es_is_delonly, + l_del = __es_scan_range(inode, &ext4_es_is_delayed, end + 1, last); if (l_del) { ret = __insert_pending(inode, last, prealloc); diff --git a/fs/ext4/extents_status.h b/fs/ext4/extents_status.h index 5b49cb3b9aff..e484c60e55e3 100644 --- a/fs/ext4/extents_status.h +++ b/fs/ext4/extents_status.h @@ -184,11 +184,6 @@ static inline int ext4_es_is_mapped(struct extent_status *es) return (ext4_es_is_written(es) || ext4_es_is_unwritten(es)); } -static inline int ext4_es_is_delonly(struct extent_status *es) -{ - return (ext4_es_is_delayed(es) && !ext4_es_is_unwritten(es)); -} - static inline void ext4_es_set_referenced(struct extent_status *es) { es->es_pblk |= ((ext4_fsblk_t)EXTENT_STATUS_REFERENCED) << ES_SHIFT; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 64bdfa9e06b2..2704dca96ee7 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1643,7 +1643,7 @@ static int ext4_da_check_clu_allocated(struct inode *inode, ext4_lblk_t lblk, int ret; *allocated = false; - if (ext4_es_scan_clu(inode, &ext4_es_is_delonly, lblk)) + if (ext4_es_scan_clu(inode, &ext4_es_is_delayed, lblk)) return 0; if (ext4_es_scan_clu(inode, &ext4_es_is_mapped, lblk)) @@ -1760,7 +1760,7 @@ static int ext4_da_map_blocks(struct inode *inode, struct ext4_map_blocks *map) * Delayed extent could be allocated by fallocate. * So we need to check it. */ - if (ext4_es_is_delonly(&es)) { + if (ext4_es_is_delayed(&es)) { map->m_flags |= EXT4_MAP_DELAYED; return 0; } From patchwork Wed Apr 10 14:29:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624714 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 808D6CD128A for ; Wed, 10 Apr 2024 14:39:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 29D606B00A7; Wed, 10 Apr 2024 10:38:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2761D6B00A8; Wed, 10 Apr 2024 10:38:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02B566B00AB; Wed, 10 Apr 2024 10:38:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D79BB6B00A7 for ; Wed, 10 Apr 2024 10:38:45 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9ADC81207D9 for ; Wed, 10 Apr 2024 14:38:45 +0000 (UTC) X-FDA: 81993878610.27.FCAFA8D Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf01.hostedemail.com (Postfix) with ESMTP id 37B3440010 for ; Wed, 10 Apr 2024 14:38:41 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759922; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F73bRhzyAqTv8RlvS6VyAtdVlk2QAA7OxfuJ/koKbrY=; b=tm/UGrE/6EUF2II6J5AgnrPxu2z8YuFQVmeSWwmWLlAct5E9YgiQ+9ChFX94O/QkRpOSIM i8ZrQTj5zrFb9jENObYzcz5IE5YdfOKmsH1C8rLxPczUn/cB7yYVIl0EjoirYedoMjgbM3 MiBQzNDCRD8MrgJevboXSju+s41J+uM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759922; a=rsa-sha256; cv=none; b=wheYUqOi2nU9Xz15JlQI4WylmCMq25Rel+4I+Z/sm7QrNTO0kYXc/v3wP9E3R1jX/9HeCx Mj/IFAD+I61Bblfe3kCbf/jr40zOYfv5QA1rOd52T3ybsJyB7K6l35g9OHEvgxr349lQD+ ev4a3QIjMpxv9fpas0SXWy1vOdRQU9I= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF56b1WHyz4f3kng for ; Wed, 10 Apr 2024 22:38:31 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 0FF381A0568 for ; Wed, 10 Apr 2024 22:38:38 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S23; Wed, 10 Apr 2024 22:38:37 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 19/34] ext4: drop all delonly descriptions Date: Wed, 10 Apr 2024 22:29:33 +0800 Message-Id: <20240410142948.2817554-20-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S23 X-Coremail-Antispam: 1UD129KBjvJXoW3WFW8Cw43JrykWw4ftFyfCrg_yoWDXr1Upr W5KF13twn8Xryv9r4ftwn7Xr1fWa4vqFWUt34fJFyFkFn5Jr1S9F1qkryFvFy8GrWxAw1q qF45u34Uua1qgFDanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUHI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j6r xdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4 xG6I80ewAv7VC0I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCa FVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI4 02YVCY1x02628vn2kIc2xKxwCY1x0262kKe7AKxVW8ZVWrXwCF04k20xvY0x0EwIxGrwCF x2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVWUXVWUAwC20s026c02F40E14v26r 1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIxkGc2Ij 64vIr41lIxAIcVC0I7IYx2IY67AKxVWDJVCq3wCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr 1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr1j6F4U JwCI42IY6I8E87Iv6xkF7I0E14v26rxl6s0DYxBIdaVFxhVjvjDU0xZFpf9x0pRDPE-UUU UU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 37B3440010 X-Rspam-User: X-Stat-Signature: efscdtrddcncb13cpasykq97x1rij6tf X-Rspamd-Server: rspam03 X-HE-Tag: 1712759921-943119 X-HE-Meta: U2FsdGVkX19Lp71e82ZFL99gEoVZlzzOo4kipXiLybrPlfXnsH1L4frn0vkE5zSvjx7YPWd10VNRH7WI2xrAovYHdLBayJlRLHQxQ8Bt/MZc4Jdi6mH9eMqJQvGtHgOag219HZLZMlYbTnx1vEecPZ5r1A5tfIGBadvfjxTu7X9GS4glThvOlrwz/0a/I4hiSGhSOB/iD6Txe/ZmdbHOvzJmR9megfBimbCubeGKnHhhHrRQR05oFCjjGkCLXNyyscuF3aGvW5jo7ZnSTZbCdbE+8lMSDJVf7CaPaLTkhhNDCWczZGXwFykgyf3T3FIHkkfUwk0Z+MCTxdp4zrwCzbh/U10CQnCXifaJLmMFbkv2MO4NpkBYffuBZXDBfFBO5ImqyiknN8gqrcthZjzACoFmTK/V19rJBoO+6q1vay5JrxzmzLXgVRDf4y/CZvv65OycdlyXE9NUdjhVyZJwJ7R0k/ACDeA05bZzv54NnNzr5kdOsaamVJHd+KD4lLXXzyOPd9VkU39kCDJPTs70jWGtquYklBbmeS+p9gjcQwXRaTSIHHlZIdZdSSSg5c6lGvlHiiNlDzUa8AM4glk2Zwc3AIoE0Bj3W8J1qgSl5mKwTiQy/Auw5ZUgWo5VaoNSbjgfnCyjolOPqtOe+Y/t8+ir5b3hLPtE5dQ1KtSrGUONDMa3ud9FVc5wVOaA6BOOX18gK5ofrejeI16MtsWANNlSTju0N+1A394YjAAsFKMwiDXk2/NBMMpnubfHKuy4r+fZC+xGQRxjAJvF/wzvZeVtzCtNWsVtmWvDeNAbs5KsnPENIDCA3R5f52tLIQLQBsSTiMUQUxktp8HsZU2GsZaF63sbXf10cFPrLud1A7Pexf5cVEPnCElMypnSuCN6iAtomm6AT+2l7slIGi44G8imc7cqNBTjDB5lWi3dRs0n2znsug77lplHVSPCtm0vZ48oACZY01bH4k+iM8W wlBZX4NJ FvY2L29HupE45hc2IBZzBTW6M0vNXOeidtMmzUjGmaaj/06tuDmZvHkqyNFXSLBS/SkewXyclq50Dj+rsUUf1Gx6XoxPL7vJnmMN0Nvhh8GKCHRqTblJRU3PMb1GG4HPB+3eQnEIcdHvNX1hQ09bvcEgISsMp0p07MbB/DWbBjsN9ffYim1DYp6ZNmeG9yR0Q2YXXdBfkbzZVW92DCGpIVxwft8HmdJ4EhWzOcm1fAouJWG8LkONyK4P4E3GV+56nkYO7 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Drop all delonly descriptions in parameters and comments. Signed-off-by: Zhang Yi --- fs/ext4/extents_status.c | 92 ++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 47 deletions(-) diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 062293e739cc..926669d8eb3e 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -142,8 +142,8 @@ */ struct rsvd_info { - int delonly_cluster; /* reserved clusters for delalloc es entry */ - int delonly_block; /* reserved blocks for delalloc es entry */ + int delayed_cluster; /* reserved clusters for delalloc es entry */ + int delayed_block; /* reserved blocks for delalloc es entry */ }; static struct kmem_cache *ext4_es_cachep; @@ -943,10 +943,10 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, * so release the quota reservations made for any previously delayed * allocated clusters. */ - resv_used = rinfo.delonly_cluster + pending; + resv_used = rinfo.delayed_cluster + pending; if (resv_used) ext4_da_update_reserve_space(inode, resv_used, - rinfo.delonly_block); + rinfo.delayed_block); if (err1 || err2 || err3 < 0) goto retry; @@ -1067,8 +1067,8 @@ int ext4_es_lookup_extent(struct inode *inode, ext4_lblk_t lblk, } struct rsvd_count { - int ndelonly_cluster; - int ndelonly_block; + int ndelayed_cluster; + int ndelayed_block; bool first_do_lblk_found; ext4_lblk_t first_do_lblk; ext4_lblk_t last_do_lblk; @@ -1094,11 +1094,11 @@ static void init_rsvd(struct inode *inode, ext4_lblk_t lblk, struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); struct rb_node *node; - rc->ndelonly_cluster = 0; - rc->ndelonly_block = 0; + rc->ndelayed_cluster = 0; + rc->ndelayed_block = 0; /* - * for bigalloc, note the first delonly block in the range has not + * for bigalloc, note the first delayed block in the range has not * been found, record the extent containing the block to the left of * the region to be removed, if any, and note that there's no partial * cluster to track @@ -1118,9 +1118,8 @@ static void init_rsvd(struct inode *inode, ext4_lblk_t lblk, } /* - * count_rsvd - count the clusters containing delayed and not unwritten - * (delonly) blocks in a range within an extent and add to - * the running tally in rsvd_count + * count_rsvd - count the clusters containing delayed blocks in a range + * within an extent and add to the running tally in rsvd_count * * @inode - file containing extent * @lblk - first block in range @@ -1143,19 +1142,19 @@ static void count_rsvd(struct inode *inode, ext4_lblk_t lblk, long len, WARN_ON(len <= 0); if (sbi->s_cluster_ratio == 1) { - rc->ndelonly_cluster += (int) len; - rc->ndelonly_block = rc->ndelonly_cluster; + rc->ndelayed_cluster += (int) len; + rc->ndelayed_block = rc->ndelayed_cluster; return; } /* bigalloc */ - rc->ndelonly_block += (int)len; + rc->ndelayed_block += (int)len; i = (lblk < es->es_lblk) ? es->es_lblk : lblk; end = lblk + (ext4_lblk_t) len - 1; end = (end > ext4_es_end(es)) ? ext4_es_end(es) : end; - /* record the first block of the first delonly extent seen */ + /* record the first block of the first delayed extent seen */ if (!rc->first_do_lblk_found) { rc->first_do_lblk = i; rc->first_do_lblk_found = true; @@ -1169,7 +1168,7 @@ static void count_rsvd(struct inode *inode, ext4_lblk_t lblk, long len, * doesn't start with it, count it and stop tracking */ if (rc->partial && (rc->lclu != EXT4_B2C(sbi, i))) { - rc->ndelonly_cluster++; + rc->ndelayed_cluster++; rc->partial = false; } @@ -1179,7 +1178,7 @@ static void count_rsvd(struct inode *inode, ext4_lblk_t lblk, long len, */ if (EXT4_LBLK_COFF(sbi, i) != 0) { if (end >= EXT4_LBLK_CFILL(sbi, i)) { - rc->ndelonly_cluster++; + rc->ndelayed_cluster++; rc->partial = false; i = EXT4_LBLK_CFILL(sbi, i) + 1; } @@ -1187,11 +1186,11 @@ static void count_rsvd(struct inode *inode, ext4_lblk_t lblk, long len, /* * if the current cluster starts on a cluster boundary, count the - * number of whole delonly clusters in the extent + * number of whole delayed clusters in the extent */ if ((i + sbi->s_cluster_ratio - 1) <= end) { nclu = (end - i + 1) >> sbi->s_cluster_bits; - rc->ndelonly_cluster += nclu; + rc->ndelayed_cluster += nclu; i += nclu << sbi->s_cluster_bits; } @@ -1251,10 +1250,9 @@ static struct pending_reservation *__pr_tree_search(struct rb_root *root, * @rc - pointer to reserved count data * * The number of reservations to be released is equal to the number of - * clusters containing delayed and not unwritten (delonly) blocks within - * the range, minus the number of clusters still containing delonly blocks - * at the ends of the range, and minus the number of pending reservations - * within the range. + * clusters containing delayed blocks within the range, minus the number of + * clusters still containing delayed blocks at the ends of the range, and + * minus the number of pending reservations within the range. */ static unsigned int get_rsvd(struct inode *inode, ext4_lblk_t end, struct extent_status *right_es, @@ -1265,33 +1263,33 @@ static unsigned int get_rsvd(struct inode *inode, ext4_lblk_t end, struct ext4_pending_tree *tree = &EXT4_I(inode)->i_pending_tree; struct rb_node *node; ext4_lblk_t first_lclu, last_lclu; - bool left_delonly, right_delonly, count_pending; + bool left_delayed, right_delayed, count_pending; struct extent_status *es; if (sbi->s_cluster_ratio > 1) { /* count any remaining partial cluster */ if (rc->partial) - rc->ndelonly_cluster++; + rc->ndelayed_cluster++; - if (rc->ndelonly_cluster == 0) + if (rc->ndelayed_cluster == 0) return 0; first_lclu = EXT4_B2C(sbi, rc->first_do_lblk); last_lclu = EXT4_B2C(sbi, rc->last_do_lblk); /* - * decrease the delonly count by the number of clusters at the - * ends of the range that still contain delonly blocks - + * decrease the delayed count by the number of clusters at the + * ends of the range that still contain delayed blocks - * these clusters still need to be reserved */ - left_delonly = right_delonly = false; + left_delayed = right_delayed = false; es = rc->left_es; while (es && ext4_es_end(es) >= EXT4_LBLK_CMASK(sbi, rc->first_do_lblk)) { if (ext4_es_is_delayed(es)) { - rc->ndelonly_cluster--; - left_delonly = true; + rc->ndelayed_cluster--; + left_delayed = true; break; } node = rb_prev(&es->rb_node); @@ -1299,7 +1297,7 @@ static unsigned int get_rsvd(struct inode *inode, ext4_lblk_t end, break; es = rb_entry(node, struct extent_status, rb_node); } - if (right_es && (!left_delonly || first_lclu != last_lclu)) { + if (right_es && (!left_delayed || first_lclu != last_lclu)) { if (end < ext4_es_end(right_es)) { es = right_es; } else { @@ -1310,8 +1308,8 @@ static unsigned int get_rsvd(struct inode *inode, ext4_lblk_t end, while (es && es->es_lblk <= EXT4_LBLK_CFILL(sbi, rc->last_do_lblk)) { if (ext4_es_is_delayed(es)) { - rc->ndelonly_cluster--; - right_delonly = true; + rc->ndelayed_cluster--; + right_delayed = true; break; } node = rb_next(&es->rb_node); @@ -1325,21 +1323,21 @@ static unsigned int get_rsvd(struct inode *inode, ext4_lblk_t end, /* * Determine the block range that should be searched for * pending reservations, if any. Clusters on the ends of the - * original removed range containing delonly blocks are + * original removed range containing delayed blocks are * excluded. They've already been accounted for and it's not * possible to determine if an associated pending reservation * should be released with the information available in the * extents status tree. */ if (first_lclu == last_lclu) { - if (left_delonly | right_delonly) + if (left_delayed | right_delayed) count_pending = false; else count_pending = true; } else { - if (left_delonly) + if (left_delayed) first_lclu++; - if (right_delonly) + if (right_delayed) last_lclu--; if (first_lclu <= last_lclu) count_pending = true; @@ -1350,13 +1348,13 @@ static unsigned int get_rsvd(struct inode *inode, ext4_lblk_t end, /* * a pending reservation found between first_lclu and last_lclu * represents an allocated cluster that contained at least one - * delonly block, so the delonly total must be reduced by one + * delayed block, so the delayed total must be reduced by one * for each pending reservation found and released */ if (count_pending) { pr = __pr_tree_search(&tree->root, first_lclu); while (pr && pr->lclu <= last_lclu) { - rc->ndelonly_cluster--; + rc->ndelayed_cluster--; node = rb_next(&pr->rb_node); rb_erase(&pr->rb_node, &tree->root); __free_pending(pr); @@ -1367,7 +1365,7 @@ static unsigned int get_rsvd(struct inode *inode, ext4_lblk_t end, } } } - return rc->ndelonly_cluster; + return rc->ndelayed_cluster; } @@ -1401,8 +1399,8 @@ static int __es_remove_extent(struct inode *inode, ext4_lblk_t lblk, struct rsvd_count rc; if (rinfo) { - rinfo->delonly_cluster = 0; - rinfo->delonly_block = 0; + rinfo->delayed_cluster = 0; + rinfo->delayed_block = 0; if (test_opt(inode->i_sb, DELALLOC)) count_reserved = true; } @@ -1504,8 +1502,8 @@ static int __es_remove_extent(struct inode *inode, ext4_lblk_t lblk, out_get_reserved: if (count_reserved) { - rinfo->delonly_cluster = get_rsvd(inode, end, es, &rc); - rinfo->delonly_block = rc.ndelonly_block; + rinfo->delayed_cluster = get_rsvd(inode, end, es, &rc); + rinfo->delayed_block = rc.ndelayed_block; } out: return err; @@ -1563,7 +1561,7 @@ void ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk, goto retry; ext4_es_print_tree(inode); - ext4_da_release_space(inode, rinfo.delonly_cluster); + ext4_da_release_space(inode, rinfo.delayed_cluster); return; } From patchwork Wed Apr 10 14:29:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624712 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE36ECD128A for ; Wed, 10 Apr 2024 14:39:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 229E96B00A5; Wed, 10 Apr 2024 10:38:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C6FE6B00A6; Wed, 10 Apr 2024 10:38:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA9756B00A7; Wed, 10 Apr 2024 10:38:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id CACE16B00A5 for ; Wed, 10 Apr 2024 10:38:44 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9EB95A1244 for ; Wed, 10 Apr 2024 14:38:44 +0000 (UTC) X-FDA: 81993878568.01.2CC0833 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf11.hostedemail.com (Postfix) with ESMTP id 346B740007 for ; Wed, 10 Apr 2024 14:38:41 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759922; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=37SfuM5G3Dj7+7QLVyT1la8ndDsI8tsv6jHJ3LlC8EU=; b=pDU34vg1E7ST+FYGzYWVQyTuXBjwU3x+YBYZb2WjTOY+dExf2Wenz23LZDaAmy9+F/xhJ+ 1Dbuo2GNTk/NXuD3hCuRGFfISjKYCaIsvUWKdH/TLE5/sHpqfjGusoiesP8rH3/RI0j/Hp pmTwfMHgr54RFnmUpbU3sQvKW5xU3GI= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759922; a=rsa-sha256; cv=none; b=qwrHxubmyUpkhINMw9HOmGalaq5i4F9VMWN8mKoz6sT/E+LRgkOLf/T/OSx9dS1KjjBslH DDQjUgbBnWGaq3F4tpkMnkxkNBkP1meLXuqXqmNBX0AJvbpvsLtUhmzfKAUUsNptupo15F DyGu5oRvrIp9uUI7QCUKvpAChDYZqiI= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56Z0BXxz4f3lfY for ; Wed, 10 Apr 2024 22:38:30 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id AAB4B1A058D for ; Wed, 10 Apr 2024 22:38:38 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S24; Wed, 10 Apr 2024 22:38:38 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 20/34] ext4: use reserved metadata blocks when splitting extent on endio Date: Wed, 10 Apr 2024 22:29:34 +0800 Message-Id: <20240410142948.2817554-21-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S24 X-Coremail-Antispam: 1UD129KBjvJXoW7tr1UXw4xWrW5ZFy8Ary5Jwb_yoW8Wryfpr 9rAF1xWr40v3Wj9FW8u3WUJryrC3WUWF47GrZ8t3y29ay7Jr1ruF47K3WrZFyFqrZ7Xw4j vr40qa48Zwn5Aa7anT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUHI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j6r xdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4 xG6I80ewAv7VC0I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCa FVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI4 02YVCY1x02628vn2kIc2xKxwCY1x0262kKe7AKxVW8ZVWrXwCF04k20xvY0x0EwIxGrwCF x2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVWUXVWUAwC20s026c02F40E14v26r 1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIxkGc2Ij 64vIr41lIxAIcVC0I7IYx2IY67AKxVWDJVCq3wCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr 1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr1j6F4U JwCI42IY6I8E87Iv6xkF7I0E14v26rxl6s0DYxBIdaVFxhVjvjDU0xZFpf9x0pRDPE-UUU UU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 346B740007 X-Rspam-User: X-Stat-Signature: 1jwemzcc47pgou4or5odd5qf8pqos7rr X-Rspamd-Server: rspam01 X-HE-Tag: 1712759921-63103 X-HE-Meta: U2FsdGVkX19hXh0DMuhu8bLXUfJO90dPhuW+ty1Dq50bftKQ2yvGjYrFUGLxoyO7+Djj6IlwLIvVgfS1655UGoc4Cff8J3D+aJkojTC8x0TABhXL7iSbyrVaTekf5s+F4/lRJ0WlhyHJFkuo7i+B459DI+DDX2B34W4OM5/jqAbkqyK0QSrGLzYquxCg/SWwwCRuiXZL9KVq+OHZa6qmUAT68YT2ubY1NX678QpKRPyh+37fh+esw484jhFv86Qk0c5Q3tBFgeJ/h2hLG0TfjR/tkyLMUKC5DIQMzQ4T7MNEg+CF1ecS51+2yZcZWM49522dQC2ZDbDkoZgWUclj0cS4q7mdavOoQ9XisIbC8LXWtt2W9fxSZU2tfgofsh20uEEK74FGof+R/2wiylHuZIFbahjN3zKjnaUpVUlv3pWVAMof5xvMOKFqD5Q9G6k8CCA171Ao0F3OsCjKHLenNmeHxQuE7PnJbsEB/nkO0KE/Ce80nc23cXvqeLnjMQUh2mrEOzSHGKnqP+AvjiRRF9+p3S2DAe6k+3J7VpLVOFgj0u5jDNfv1DE9G1Ot1DV0JtWhdJXgHaS1SsG0AZ1SOk7PFVVEmj/UrnZIlYovLnxCXFDveEaGKSzXP5c+MvgO0Bm0VBdRxZz/QoQz8AE6mlO2Vd7V4eEnyrL4WZq+A8qGI63qnwG+rKl1jIKt8cbgHHHZVJu8tKLsASQjut+VA3kh6CDhvWlwROJFun3GeyF6zx7woiweJqbd7dFubEoVjL6m9ZOD5u10Sq0Rmf+WRgMWYleNziUwHd6OwsycsJuX9iN+YnEj9K/W0oxiTKn9SEGG7g3mYltQTMbxU5iphXRqlzEA+h3OdJ5WmTmHGxtwAtag+n2p08TsX3/M77lS2xYedvrYz6zIGep8t2cCLMjdU7asoVmoE/Lf74rxR+bUo4o1rFX4aZ5hxJH+gY/qIwPDfC90gK8Jp3IUPc3 iHOlIL2Z qULjrufFfW8wd4UDGFhiOC8U4nsvB2OmDFKPJ190ZqTXnPlV+z2hJQmKuGYRnV4MWQ3+oZVFS6pNXObx5Iug1nFW8cBE1EbWvSwoZuK/dZQ3/O2MqxU7zXZsg1dkkvvOweHPq6XtkK5AL7zhu7FIEZ2MsFr37jJPEGtkq6IAI+Ux05o/cKOxANxRQb/OJT6d1CYVY0dJ0LCF/hd+rYZuy8yaSJeUtiJkqkj4Jbvy6H1VeoCqvf1Cgr270V9KcxTzKAXhu1NRfgI96xubYUscYXEvQaJuHBD7eyB+p X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi ext4 only reserved space for delalloc for data blocks, doesn't reserve space for metadata blocks in ext4_da_reserve_space(). Besides, if we enable dioread_nolock mount option, it also doesn't reserve metadata blocks for the extent status conversion. In order to prevent data loss caused by fail to allocate metadata blocks on writeback, we reserve 2% space or 4096 blocks for meta data, and use EXT4_GET_BLOCKS_PRE_IO to do the potential split in advance. But all these two methods were just best efforts, if it's really running out of sapce, there is no difference between splitting extent on writeback and on IO completed, both will lead to data loss. The best way is to reserve enough space for metadata. Before that, we can at least make sure that things won't get worse if we postpone splitting extent to endio. So let's use reserved sapce in endio too. Signed-off-by: Zhang Yi --- fs/ext4/extents.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 8bc8a519f745..fcb1916a7c29 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -3722,7 +3722,8 @@ static int ext4_convert_unwritten_extents_endio(handle_t *handle, (unsigned long long)map->m_lblk, map->m_len); #endif err = ext4_split_convert_extents(handle, inode, map, ppath, - EXT4_GET_BLOCKS_CONVERT); + EXT4_GET_BLOCKS_CONVERT | + EXT4_GET_BLOCKS_METADATA_NOFAIL); if (err < 0) return err; path = ext4_find_extent(inode, map->m_lblk, ppath, 0); From patchwork Wed Apr 10 14:29:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624713 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 317D5CD1299 for ; Wed, 10 Apr 2024 14:39:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 780386B00A6; Wed, 10 Apr 2024 10:38:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 72FB46B00A7; Wed, 10 Apr 2024 10:38:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 55B986B00A8; Wed, 10 Apr 2024 10:38:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2EDE16B00A7 for ; Wed, 10 Apr 2024 10:38:45 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id EDFCF140728 for ; Wed, 10 Apr 2024 14:38:44 +0000 (UTC) X-FDA: 81993878568.05.C517DF2 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf15.hostedemail.com (Postfix) with ESMTP id B8C56A000C for ; Wed, 10 Apr 2024 14:38:42 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759923; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ct7Xick/zg301j7PA0oFeix3cSWAuGYjkxRWkYIH3P4=; b=vP3KyKfr2+yGkKsUIc5nBlhPUkyfxCwvNndkfv6A8bwXV89i4Rg7VUzp8TA9XGMw1AwldX ABwIL7NV1AwrGf+q+5TtjwVsUvTAg9KEBG0+oyj8mIw0v5BLw1YWPw0sAT3F5Sd3HPlb+L Gy3J7uHHJaK3Y1E3O59KmIkWkwyqvbk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759923; a=rsa-sha256; cv=none; b=3O6jRWTeMxyKIEl+73ng4UGD03knvNzv6vaqkmed2yO7/waHvuf4XPZzooI5kQO7WzPLNV 7c0isfVhckvamgmmqPpjOX0K/6xXQ3mCLdojDmysmUW0+kFxnQOY590caVkZSIXr6zUjby Vvn8TRkld5ZN0wZWYp2AM0U0EHHYHXo= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF56c3MT4z4f3kns for ; Wed, 10 Apr 2024 22:38:32 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 4FF471A016E for ; Wed, 10 Apr 2024 22:38:39 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S25; Wed, 10 Apr 2024 22:38:39 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 21/34] ext4: introduce seq counter for the extent status entry Date: Wed, 10 Apr 2024 22:29:35 +0800 Message-Id: <20240410142948.2817554-22-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S25 X-Coremail-Antispam: 1UD129KBjvJXoW3Wry3GrW7GF18AF4xJw4ruFg_yoW7uFWfpa s7ArWUWrZ5Xw4j9a1xXw10qr43Xa48WrW7Gr9IgryrZFWftrn8WF1DtFyjvF90qFW0kr17 XFW0kryDA3W7WFDanT9S1TB71UUUUUJqnTZ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X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Add a modify counter for the extent status entry, which indicates the version of extent status of one inode, increase it once extent changes. It it a preparation for the conversion of the regular file's buffered write path from bh to iomap. Signed-off-by: Zhang Yi --- fs/ext4/ext4.h | 1 + fs/ext4/extents_status.c | 13 ++++++++++++- fs/ext4/super.c | 1 + include/trace/events/ext4.h | 20 ++++++++++++++------ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 8d126654019e..7e27e1e7c579 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1115,6 +1115,7 @@ struct ext4_inode_info { ext4_lblk_t i_es_shrink_lblk; /* Offset where we start searching for extents to shrink. Protected by i_es_lock */ + unsigned int i_es_seq; /* modify counter for extents */ /* ialloc */ ext4_group_t i_last_alloc_group; diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 926669d8eb3e..90b58cf42cdd 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -209,6 +209,13 @@ static inline ext4_lblk_t ext4_es_end(struct extent_status *es) return es->es_lblk + es->es_len - 1; } +static inline void ext4_es_inc_seq(struct inode *inode) +{ + struct ext4_inode_info *ei = EXT4_I(inode); + + WRITE_ONCE(ei->i_es_seq, READ_ONCE(ei->i_es_seq) + 1); +} + /* * search through the tree for an delayed extent with a given offset. If * it can't be found, try to find next extent. @@ -876,6 +883,7 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, BUG_ON(end < lblk); WARN_ON_ONCE(status & EXTENT_STATUS_DELAYED); + ext4_es_inc_seq(inode); newes.es_lblk = lblk; newes.es_len = len; ext4_es_store_pblock_status(&newes, pblk, status); @@ -1530,13 +1538,15 @@ void ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk, if (EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY) return; - trace_ext4_es_remove_extent(inode, lblk, len); es_debug("remove [%u/%u) from extent status tree of inode %lu\n", lblk, len, inode->i_ino); if (!len) return; + ext4_es_inc_seq(inode); + trace_ext4_es_remove_extent(inode, lblk, len); + end = lblk + len - 1; BUG_ON(end < lblk); @@ -2111,6 +2121,7 @@ void ext4_es_insert_delayed_extent(struct inode *inode, ext4_lblk_t lblk, if (!len) return; + ext4_es_inc_seq(inode); newes.es_lblk = lblk; newes.es_len = len; ext4_es_store_pblock_status(&newes, ~0, EXTENT_STATUS_DELAYED); diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 044135796f2b..5fce4d2b3b87 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1421,6 +1421,7 @@ static struct inode *ext4_alloc_inode(struct super_block *sb) ei->i_es_all_nr = 0; ei->i_es_shk_nr = 0; ei->i_es_shrink_lblk = 0; + ei->i_es_seq = 0; ei->i_reserved_data_blocks = 0; spin_lock_init(&(ei->i_block_reservation_lock)); ext4_init_pending_tree(&ei->i_pending_tree); diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h index cc5e9b7b2b44..4d583d0248d9 100644 --- a/include/trace/events/ext4.h +++ b/include/trace/events/ext4.h @@ -2183,6 +2183,7 @@ DECLARE_EVENT_CLASS(ext4__es_extent, __field( ext4_lblk_t, len ) __field( ext4_fsblk_t, pblk ) __field( char, status ) + __field( unsigned int, seq ) ), TP_fast_assign( @@ -2192,13 +2193,15 @@ DECLARE_EVENT_CLASS(ext4__es_extent, __entry->len = es->es_len; __entry->pblk = ext4_es_show_pblock(es); __entry->status = ext4_es_status(es); + __entry->seq = EXT4_I(inode)->i_es_seq; ), - TP_printk("dev %d,%d ino %lu es [%u/%u) mapped %llu status %s", + TP_printk("dev %d,%d ino %lu es [%u/%u) mapped %llu status %s seq %u", MAJOR(__entry->dev), MINOR(__entry->dev), (unsigned long) __entry->ino, __entry->lblk, __entry->len, - __entry->pblk, show_extent_status(__entry->status)) + __entry->pblk, show_extent_status(__entry->status), + __entry->seq) ); DEFINE_EVENT(ext4__es_extent, ext4_es_insert_extent, @@ -2223,6 +2226,7 @@ TRACE_EVENT(ext4_es_remove_extent, __field( ino_t, ino ) __field( loff_t, lblk ) __field( loff_t, len ) + __field( unsigned int, seq ) ), TP_fast_assign( @@ -2230,12 +2234,13 @@ TRACE_EVENT(ext4_es_remove_extent, __entry->ino = inode->i_ino; __entry->lblk = lblk; __entry->len = len; + __entry->seq = EXT4_I(inode)->i_es_seq; ), - TP_printk("dev %d,%d ino %lu es [%lld/%lld)", + TP_printk("dev %d,%d ino %lu es [%lld/%lld) seq %u", MAJOR(__entry->dev), MINOR(__entry->dev), (unsigned long) __entry->ino, - __entry->lblk, __entry->len) + __entry->lblk, __entry->len, __entry->seq) ); TRACE_EVENT(ext4_es_find_extent_range_enter, @@ -2495,6 +2500,7 @@ TRACE_EVENT(ext4_es_insert_delayed_extent, __field( char, status ) __field( bool, lclu_allocated ) __field( bool, end_allocated ) + __field( unsigned int, seq ) ), TP_fast_assign( @@ -2506,15 +2512,17 @@ TRACE_EVENT(ext4_es_insert_delayed_extent, __entry->status = ext4_es_status(es); __entry->lclu_allocated = lclu_allocated; __entry->end_allocated = end_allocated; + __entry->seq = EXT4_I(inode)->i_es_seq; ), TP_printk("dev %d,%d ino %lu es [%u/%u) mapped %llu status %s " - "allocated %d %d", + "allocated %d %d seq %u", MAJOR(__entry->dev), MINOR(__entry->dev), (unsigned long) __entry->ino, __entry->lblk, __entry->len, __entry->pblk, show_extent_status(__entry->status), - __entry->lclu_allocated, __entry->end_allocated) + __entry->lclu_allocated, __entry->end_allocated, + __entry->seq) ); /* fsmap traces */ From patchwork Wed Apr 10 14:29:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4F7ACD1299 for ; Wed, 10 Apr 2024 14:39:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DEE246B00AB; Wed, 10 Apr 2024 10:38:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D98A86B00AD; Wed, 10 Apr 2024 10:38:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C3A536B00AC; Wed, 10 Apr 2024 10:38:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A6C196B00A8 for ; Wed, 10 Apr 2024 10:38:46 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7D3B51407DB for ; Wed, 10 Apr 2024 14:38:46 +0000 (UTC) X-FDA: 81993878652.06.37C2A68 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf16.hostedemail.com (Postfix) with ESMTP id 37DF718000F for ; Wed, 10 Apr 2024 14:38:43 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759924; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fOgEdgws1v255Vbot+gwvOYlz1LDBoFxwezUsQaS9kk=; b=y4D0iPtvipWNQgPlsYDtXz5RcU2obVTdy2UeykfZJs9nHaQoKK1PYmBfgQxK9N+71MLaa3 2dCD0sVhXgIPAJ3xmhwqbstocMoMxpcfrCEXWGfPGtLkqkh6mdCP8zFXcrQn7/eQcsV4wi k2fv26E2cd3akN5EOvJD02Lm2q4TSs0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759924; a=rsa-sha256; cv=none; b=JEg9O7uA9LC/85CKDKou3Iu1t7Ft8n1fGJ5Vqt1XMtXno8sIjXXxAUp5G/3Kg+xCyE9nAk kDEgJpPQysrbQqREV5JR5m6403N1b4jw/YQtuEbPYqtbKtPpb8TN0N1Z5g0EY/WwaDoaF+ zoWwrBjO600wJfxPxK9t6BG63/kH0rQ= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF56d0ycXz4f3knl for ; Wed, 10 Apr 2024 22:38:33 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id F18D01A0DF5 for ; Wed, 10 Apr 2024 22:38:39 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S26; Wed, 10 Apr 2024 22:38:39 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 22/34] ext4: add a new iomap aops for regular file's buffered IO path Date: Wed, 10 Apr 2024 22:29:36 +0800 Message-Id: <20240410142948.2817554-23-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S26 X-Coremail-Antispam: 1UD129KBjvJXoWxCryDCFWrXrWrZr17Kr17KFg_yoW5CF17pF Z8Kas3Gr18Zr9F9a1fXayDZF4Yya4fGw4UKFW3G3WavFyrGrW7KFWvk3WjkFy5t3y8Ar17 XF4jkry7WF17CrDanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUHI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j6r xdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4 xG6I80ewAv7VC0I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCa FVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI4 02YVCY1x02628vn2kIc2xKxwCY1x0262kKe7AKxVW8ZVWrXwCF04k20xvY0x0EwIxGrwCF x2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVWUXVWUAwC20s026c02F40E14v26r 1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIxkGc2Ij 64vIr41lIxAIcVC0I7IYx2IY67AKxVWDJVCq3wCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr 1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr1j6F4U JwCI42IY6I8E87Iv6xkF7I0E14v26rxl6s0DYxBIdaVFxhVjvjDU0xZFpf9x0pRDPE-UUU UU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 37DF718000F X-Rspam-User: X-Stat-Signature: kos6yige6s69nq9etb8e9txgnihpwi5s X-Rspamd-Server: rspam03 X-HE-Tag: 1712759923-864652 X-HE-Meta: U2FsdGVkX18gHCI5LgzTZDHNw6mknt6exk9gTWvNL+ZXot4AOXZkINFgqV6n6ERSOysU1bo5izC7He+e6CsgMN66omj9KYkFwFCOyY85t+aBqYVOdudn6RQpikyon0DM+0nlXPMp7L2V+vtn+/OYm6u6URkUZcXQABox4FZj424/TEQ25xTHdEaFuctEJoRJqR2TPO2zT+3KnODPlH5h2CPvs+KJR/dok4ME4NGLwNo5GqRKTepRfvue5kQfTRSyUar9zb9E7GAITcybPt6TBlCbHpBl0n1itoahl8CLseu2Mc1OEl24zRdcgruWsLknTyNtt2zPXKd0+3abFm053lCkBAmlGV6tEcE9arZVkIxkc93QIVz/rK2l4f7Gh9I0DQ9FINYXuvl8mzPohwUUsU6MFZfhwzi6mR+IJd0RBnISO89HMWlkWmaIOE2Qro/e7VN/JiGLf9QxvTnbmRp3fweGopKByXLYZugu7qxQZxuHLuSAafMYSdBfLmRwSnIG8xUW2n90gJvU0B4bphVBtWAUFeivbU02tnKjp//fvoo7uhUt15pDcax+znuSnEZiuKjKQCK1HZMJFM+06JaB2H4BFPzACSO+DfWOHZYFZcTKGUyEpDvNlOMj3Eh6/XNzh/qQyydQu3kNm59laFhhGJtwBlsdMcA1qeo6d+3M5SrgqmlCb3vYoI3Cu2FA1i5KTkniAzX4c9U+QGiBpKmUcxbSzxHCg9KPRwa0/Ew5lpjiMZ6sOl2WvBP0OeZJyBji1iDYIn6Q1Tk1DtWO5dpVQy8T6KSgchyaIRXG5fPfIULRRslRibxe72ZytQcbF2G9+Gz8pcdCRM8kKVv5H7OKifRUar4ob5LJg8Rc4CFZd5yRxcenHriykDLRyewiTskTouU5SjUZ3mvhNm/dKsDZEAzN7glFDaTYitU13gx4PVIlaw5BkX5Axwahk5ZvZjxM3QpIrTn93094+jonP2P iKEzAHK/ qUH/+md27Meu/N6o= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Introduce a new iomap address space operations ext4_iomap_aops to support regular file's buffered IO path, also add an inode state flag EXT4_STATE_BUFFERED_IOMAP, if it was set on an inode, it means that inode use the iomap path instead of buffer_head path for buffered IO. Most of their callbacks can use generic implementations, the left over read_folio, readahead and writepages will be implemented later. Signed-off-by: Zhang Yi --- fs/ext4/ext4.h | 1 + fs/ext4/inode.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 7e27e1e7c579..05949a8136ae 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1913,6 +1913,7 @@ enum { EXT4_STATE_VERITY_IN_PROGRESS, /* building fs-verity Merkle tree */ EXT4_STATE_FC_COMMITTING, /* Fast commit ongoing */ EXT4_STATE_ORPHAN_FILE, /* Inode orphaned in orphan file */ + EXT4_STATE_BUFFERED_IOMAP, /* Inode use iomap for buffered IO */ }; #define EXT4_INODE_BIT_FNS(name, field, offset) \ diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 2704dca96ee7..4c1fed516d9e 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3523,6 +3523,22 @@ const struct iomap_ops ext4_iomap_report_ops = { .iomap_begin = ext4_iomap_begin_report, }; +static int ext4_iomap_read_folio(struct file *file, struct folio *folio) +{ + return 0; +} + +static void ext4_iomap_readahead(struct readahead_control *rac) +{ + +} + +static int ext4_iomap_writepages(struct address_space *mapping, + struct writeback_control *wbc) +{ + return 0; +} + /* * For data=journal mode, folio should be marked dirty only when it was * writeably mapped. When that happens, it was already attached to the @@ -3612,6 +3628,21 @@ static const struct address_space_operations ext4_da_aops = { .swap_activate = ext4_iomap_swap_activate, }; +static const struct address_space_operations ext4_iomap_aops = { + .read_folio = ext4_iomap_read_folio, + .readahead = ext4_iomap_readahead, + .writepages = ext4_iomap_writepages, + .dirty_folio = iomap_dirty_folio, + .bmap = ext4_bmap, + .invalidate_folio = iomap_invalidate_folio, + .release_folio = iomap_release_folio, + .direct_IO = noop_direct_IO, + .migrate_folio = filemap_migrate_folio, + .is_partially_uptodate = iomap_is_partially_uptodate, + .error_remove_folio = generic_error_remove_folio, + .swap_activate = ext4_iomap_swap_activate, +}; + static const struct address_space_operations ext4_dax_aops = { .writepages = ext4_dax_writepages, .direct_IO = noop_direct_IO, @@ -3634,6 +3665,8 @@ void ext4_set_aops(struct inode *inode) } if (IS_DAX(inode)) inode->i_mapping->a_ops = &ext4_dax_aops; + else if (ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP)) + inode->i_mapping->a_ops = &ext4_iomap_aops; else if (test_opt(inode->i_sb, DELALLOC)) inode->i_mapping->a_ops = &ext4_da_aops; else From patchwork Wed Apr 10 14:29:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624716 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE1D1CD11C2 for ; Wed, 10 Apr 2024 14:39:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 251916B00A8; Wed, 10 Apr 2024 10:38:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 22D0C6B00AC; Wed, 10 Apr 2024 10:38:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 077F36B00AD; Wed, 10 Apr 2024 10:38:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C8F536B00A8 for ; Wed, 10 Apr 2024 10:38:46 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 90E8FA07E0 for ; Wed, 10 Apr 2024 14:38:46 +0000 (UTC) X-FDA: 81993878652.22.CCF8433 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf27.hostedemail.com (Postfix) with ESMTP id 25A5440017 for ; Wed, 10 Apr 2024 14:38:43 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf27.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759924; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fpA/4lqRQbydf8z9xn3F9nf8xQRgGteQQM2P1EKzZvU=; b=SXDG5XixMuxezMUUhMaOGMs6/glxmCKVhiSJ2vLv4TYCj8Ekasud2XtV95GZSanWm8ou4x B/qGoLpudkeomYGO5v5M6SFOr3ZXxbGlbt9aZnwF6yZxK/euqTirnmwTbSEeFTe0mZMZlp VCbmoQd4TNVHWfI7cLOkcdKE+mEPnM0= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf27.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759924; a=rsa-sha256; cv=none; b=5zDgWkuiu68Oi+mMKEXSbe1pZSnFdklN6HOpd+yxVSpy1gDVwMk6ddcPeg5K7GpbrVxHPw LRj235G+ZDex5nXJUoCHPYoTqusfHrKk02Wwgak3kiGcPkzePF4OVyHbC6o6OdncSTuV7l YqlSyG4Jtl/MJ8RYc7QFRLnFJoR/QRE= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF56d5f4kz4f3kp1 for ; Wed, 10 Apr 2024 22:38:33 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 9DDDE1A0DFA for ; Wed, 10 Apr 2024 22:38:40 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S27; Wed, 10 Apr 2024 22:38:40 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 23/34] ext4: implement buffered read iomap path Date: Wed, 10 Apr 2024 22:29:37 +0800 Message-Id: <20240410142948.2817554-24-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S27 X-Coremail-Antispam: 1UD129KBjvJXoW7urW3XF4fAFy7KF1UXrW7XFb_yoW8uFy3pF 98KFy5GF47XrnI9F4SgFZrJr1Yk3Wxtr4UZrWfWasxGFyYkrW2gayjgFyYyF1Yq3y7Ary8 WF1jkr18GF4UArDanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUH214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j6r xdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4 xG6I80ewAv7VC0I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCa FVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI4 02YVCY1x02628vn2kIc2xKxwCY1x0262kKe7AKxVW8ZVWrXwCF04k20xvY0x0EwIxGrwCF x2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVWUXVWUAwC20s026c02F40E14v26r 1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIxkGc2Ij 64vIr41lIxAIcVC0I7IYx2IY67AKxVWDJVCq3wCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr 1j6rxdMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8Jr0_Cr1U MIIF0xvEx4A2jsIEc7CjxVAFwI0_GcCE3sUvcSsGvfC2KfnxnUUI43ZEXa7sRibyCPUUUU U== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Stat-Signature: crw1wmuocsee864q9xndcko56gepk5sy X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 25A5440017 X-HE-Tag: 1712759923-676001 X-HE-Meta: U2FsdGVkX19KR6f8ZCjWwiP8LYwQUg2XyQ2+l37ONcrTOcjhrUpbB5fiLicrLYjbJHRJkUsndx1fnS8klQJA/tOI+BhdhkpwW9k+k4lcdKBksOxAXSS73B6rmwB0DCBMjEazuhZER5cyNEYs8Fets8P7gEvIDsB53c/qQwDw/0V5Pb79nySBns/VBOI4Cs+Yt7ATZW//Tk6g5yheIi/1vZt/4VNvC28TXuguSj59HxF8CDQokrjZtTluNVmIrWMEj4p21NA68/mWW43lsYNE0RS6Z9gOwO5JWxipR0RIJAy84uK3BLLpxkdgElTUuccdW+IFkKRTJr1Hx5GxoNW00bAlN5kqq5IlpjKa72F7lI5IK+UpGtLQWCvr2NtF0W3ooEHVi42FLQDJ3FPqon4ctikPbSjZ5FktBZzdQszjo4ENUqYFhZ75m0gTbqPt8A1NcMnp/ee/B/ehpuGK2G4knAzcX/MuIDeqWIcnhBrCpXnYLBpthCXMmrmrJ0UWPM5jCGmnQaTttlZH4+qyXhXxJTWzcGG5r0WaoS/o/rFkwtLEM34De6BcwAVg9Dq8Y5z4RtilfaN9MxfL9ZvRjOlJBXAh3iw7/YKl4r0AD5C76hBrF7kvAzuljRyGSrZt1uUKIAk8cNlHPLcGsSN4BGO0EUtHs9WRbkrYvHqtqDqYFsHo5cJ65HUd2BZD/9XKcmlB6eTUJsBpgZhSnjU4fVpcbcEUXV9FRCHuJ1l+4OuP+2yFMCMKC0LDrwkesE7nv6VIpWkLfGDWusgeABFTW3dm8Ldgb8D7jH4YopiBB3Hx9KLSRvn/xxVsKmN2UVPvJsWfH8QH7D0V8bTruSp0GhGbTK1VaJqclXXKVNaVRQIzEQjh8/v2BOuyeIcGVtLVzQt00Q0ecP+9QRf8TuDJv8dKML9fbNIeDKjCjafVE/4fXzkw8X+qaykQf+jdIVaec78YjYmJdzsw1Aob65HG5ix /ifhTu2t 0wBllDFS1pUmZ28UBuH8cWXBX8tN9rpyT6GJYaXf3koZqbSUqmuquM6x4EW62D3ry1TymLHYCMG+C1Q4/1dJ/IxCrRmZk8scWHX2TVyxgbQx/uQLRJxWgyGQGrtUZ8Prm6F3+Nov4s/cVrCBp/I1y/PZRk77fG/CgbT7HfsTw+5OZid1eJheoyzurGEuqpeLpL3DpQOo4LyQD+lM/9mDhzKmhZwchPjzqXnmyfW2wuPCHPjQM/47GwH8Vb0gfbLFnPBOm X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Add ext4_iomap_buffered_io_begin() for the iomap read path, it call ext4_map_blocks() to query map status and call ext4_set_iomap() to convert ext4 map to iomap. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 4c1fed516d9e..20eb772f4f62 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3523,14 +3523,46 @@ const struct iomap_ops ext4_iomap_report_ops = { .iomap_begin = ext4_iomap_begin_report, }; -static int ext4_iomap_read_folio(struct file *file, struct folio *folio) +static int ext4_iomap_buffered_io_begin(struct inode *inode, loff_t offset, + loff_t length, unsigned int iomap_flags, + struct iomap *iomap, struct iomap *srcmap) { + int ret; + struct ext4_map_blocks map; + u8 blkbits = inode->i_blkbits; + + if (unlikely(ext4_forced_shutdown(inode->i_sb))) + return -EIO; + if ((offset >> blkbits) > EXT4_MAX_LOGICAL_BLOCK) + return -EINVAL; + if (WARN_ON_ONCE(ext4_has_inline_data(inode))) + return -ERANGE; + + /* Calculate the first and last logical blocks respectively. */ + map.m_lblk = offset >> blkbits; + map.m_len = min_t(loff_t, (offset + length - 1) >> blkbits, + EXT4_MAX_LOGICAL_BLOCK) - map.m_lblk + 1; + + ret = ext4_map_blocks(NULL, inode, &map, 0); + if (ret < 0) + return ret; + + ext4_set_iomap(inode, iomap, &map, offset, length, iomap_flags); return 0; } -static void ext4_iomap_readahead(struct readahead_control *rac) +const struct iomap_ops ext4_iomap_buffered_read_ops = { + .iomap_begin = ext4_iomap_buffered_io_begin, +}; + +static int ext4_iomap_read_folio(struct file *file, struct folio *folio) { + return iomap_read_folio(folio, &ext4_iomap_buffered_read_ops); +} +static void ext4_iomap_readahead(struct readahead_control *rac) +{ + iomap_readahead(rac, &ext4_iomap_buffered_read_ops); } static int ext4_iomap_writepages(struct address_space *mapping, From patchwork Wed Apr 10 14:29:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624717 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08921CD1299 for ; Wed, 10 Apr 2024 14:39:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B03056B00AC; Wed, 10 Apr 2024 10:38:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A8D9D6B00AD; Wed, 10 Apr 2024 10:38:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 840F96B00AE; Wed, 10 Apr 2024 10:38:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 67A496B00AC for ; Wed, 10 Apr 2024 10:38:47 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 31B92407DE for ; Wed, 10 Apr 2024 14:38:47 +0000 (UTC) X-FDA: 81993878694.20.D2D0C15 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf25.hostedemail.com (Postfix) with ESMTP id B8AD0A000A for ; Wed, 10 Apr 2024 14:38:44 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759925; a=rsa-sha256; cv=none; b=Ki+EEY/6FQqw9JfKpwL9Qxh5E399+BXShJZh8JOpuDQypLhxIBdvcCaW5xaoSPmeeewcIo e9sd8r8SQFRUPPBByFgIDQU7uGCCWrcq6Ff5KSoqWllqpRC68yWtqarQiWLYDPAsz8rDpx GWiGUidu1Qe7dDGaS/7eVDC//e3iIoI= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759925; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+Dl+Sp16iwPGEM291aD8i3KdfNPti5kFCMg2YVKMdO4=; b=p91w9k4ZZDLD3N5+/gUk1JlQe0DIa3vdmpbLCQq7Lbu5IBQGXfxvcTNCyBlAz/i9oOHcsm uTq4/N8zGTa0yRkDwXQ6J7Ra7bmGq5w0SuW+Hh+o4SSXFMoWrvimHW8Uj/bqp71KXzktL2 pIIJ8fJ+hVesCyQLVxfhVI79XQQYYxE= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56c4P8rz4f3m7g for ; Wed, 10 Apr 2024 22:38:32 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 4698A1A0CBF for ; Wed, 10 Apr 2024 22:38:41 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S28; Wed, 10 Apr 2024 22:38:41 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 24/34] ext4: implement buffered write iomap path Date: Wed, 10 Apr 2024 22:29:38 +0800 Message-Id: <20240410142948.2817554-25-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S28 X-Coremail-Antispam: 1UD129KBjvJXoWxtw43trWDZFy5ur4xZF1DJrb_yoWDGr1DpF Z0kry5GF47XF929F4ftF4UZr1ak3Wxtr4UCrW3Wrn8Xr9FyrWIqF40gFyayF45J3yxCr4j qF4jkry8WF47CrDanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUH214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j6r xdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4 xG6I80ewAv7VC0I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCa FVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI4 02YVCY1x02628vn2kIc2xKxwCY1x0262kKe7AKxVW8ZVWrXwCF04k20xvY0x0EwIxGrwCF x2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVWUXVWUAwC20s026c02F40E14v26r 1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0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rLehptNBd3jFrHYaQu1CqMECVPgFQvz2v927TSjEx4whwzFGMWHtyQgdg3C9e0D5AVkPr0irgOWSNicMGIITg0+qfpPzxTcOP/BMuE5OBCcifk59p4Y4vPOVC1237Pd7jEDT2nA/Dl9+hHGWugxnlRI2DcvHqrNrAfj8Le6dmyzpKoPqgmKqnLAaCXbr3yfewRSwYv0IgsMKzoVW5u7U3QfElJ0/NAizla9c1GW4xRyMlKo3eh0rGh+XkPNj7G5b3/7s8jQGZLlmebV1qkjE0zSJfsQy4+sS+liBEGI4Mdi47huFp3Qt3tePpOOASsC ZXeA02lC q3vklp0v12ArQpoZ14nZnoms4/u1zFfi71gzt2ky/LxmO5b5rmIOEigCljbGEJcVEptT9otuGow+z+A1M+25glUS989VOS7y+O2Sa0KWiGlvEuV9eZfSIjM1FcFD4j+3/XE1gf0iPBnPGwrQLea29VG8SDzN8E3vtsPBvrbV3rtvvZWE3TsEum03IesXqEjE+Uw3VrDCAEYSUXyUccEFKlAGJUhi5ZAQwnuj4LKKn7c6mazw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Implement buffered write iomap path, use ext4_da_map_blocks() to map delalloc extents and add ext4_iomap_get_blocks() to allocate blocks if delalloc is disabled or free space is about to run out. Note that we always allocate unwritten extents for new blocks in the iomap write path, this means that the allocation type is no longer controlled by the dioread_nolock mount option. After that, we could postpone the i_disksize updating to the writeback path, and drop journal handle in the buffered dealloc write path completely. Signed-off-by: Zhang Yi --- fs/ext4/ext4.h | 3 + fs/ext4/file.c | 19 +++++- fs/ext4/inode.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 183 insertions(+), 7 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 05949a8136ae..2bd543c43341 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2970,6 +2970,7 @@ int ext4_walk_page_buffers(handle_t *handle, struct buffer_head *bh)); int do_journal_get_write_access(handle_t *handle, struct inode *inode, struct buffer_head *bh); +int ext4_nonda_switch(struct super_block *sb); #define FALL_BACK_TO_NONDELALLOC 1 #define CONVERT_INLINE_DATA 2 @@ -3827,6 +3828,8 @@ static inline void ext4_clear_io_unwritten_flag(ext4_io_end_t *io_end) extern const struct iomap_ops ext4_iomap_ops; extern const struct iomap_ops ext4_iomap_overwrite_ops; extern const struct iomap_ops ext4_iomap_report_ops; +extern const struct iomap_ops ext4_iomap_buffered_write_ops; +extern const struct iomap_ops ext4_iomap_buffered_da_write_ops; static inline int ext4_buffer_uptodate(struct buffer_head *bh) { diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 54d6ff22585c..52f37c49572a 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -282,6 +282,20 @@ static ssize_t ext4_write_checks(struct kiocb *iocb, struct iov_iter *from) return count; } +static ssize_t ext4_iomap_buffered_write(struct kiocb *iocb, + struct iov_iter *from) +{ + struct inode *inode = file_inode(iocb->ki_filp); + const struct iomap_ops *iomap_ops; + + if (test_opt(inode->i_sb, DELALLOC) && !ext4_nonda_switch(inode->i_sb)) + iomap_ops = &ext4_iomap_buffered_da_write_ops; + else + iomap_ops = &ext4_iomap_buffered_write_ops; + + return iomap_file_buffered_write(iocb, from, iomap_ops); +} + static ssize_t ext4_buffered_write_iter(struct kiocb *iocb, struct iov_iter *from) { @@ -296,7 +310,10 @@ static ssize_t ext4_buffered_write_iter(struct kiocb *iocb, if (ret <= 0) goto out; - ret = generic_perform_write(iocb, from); + if (ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP)) + ret = ext4_iomap_buffered_write(iocb, from); + else + ret = generic_perform_write(iocb, from); out: inode_unlock(inode); diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 20eb772f4f62..e825ed16fd60 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -2857,7 +2857,7 @@ static int ext4_dax_writepages(struct address_space *mapping, return ret; } -static int ext4_nonda_switch(struct super_block *sb) +int ext4_nonda_switch(struct super_block *sb) { s64 free_clusters, dirty_clusters; struct ext4_sb_info *sbi = EXT4_SB(sb); @@ -3254,6 +3254,15 @@ static bool ext4_inode_datasync_dirty(struct inode *inode) return inode->i_state & I_DIRTY_DATASYNC; } +static bool ext4_iomap_valid(struct inode *inode, const struct iomap *iomap) +{ + return iomap->validity_cookie == READ_ONCE(EXT4_I(inode)->i_es_seq); +} + +static const struct iomap_folio_ops ext4_iomap_folio_ops = { + .iomap_valid = ext4_iomap_valid, +}; + static void ext4_set_iomap(struct inode *inode, struct iomap *iomap, struct ext4_map_blocks *map, loff_t offset, loff_t length, unsigned int flags) @@ -3284,6 +3293,9 @@ static void ext4_set_iomap(struct inode *inode, struct iomap *iomap, !ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) iomap->flags |= IOMAP_F_MERGED; + iomap->validity_cookie = READ_ONCE(EXT4_I(inode)->i_es_seq); + iomap->folio_ops = &ext4_iomap_folio_ops; + /* * Flags passed to ext4_map_blocks() for direct I/O writes can result * in m_flags having both EXT4_MAP_MAPPED and EXT4_MAP_UNWRITTEN bits @@ -3523,11 +3535,42 @@ const struct iomap_ops ext4_iomap_report_ops = { .iomap_begin = ext4_iomap_begin_report, }; -static int ext4_iomap_buffered_io_begin(struct inode *inode, loff_t offset, +static int ext4_iomap_get_blocks(struct inode *inode, + struct ext4_map_blocks *map) +{ + handle_t *handle; + int ret, needed_blocks; + + /* + * Reserve one block more for addition to orphan list in case + * we allocate blocks but write fails for some reason. + */ + needed_blocks = ext4_writepage_trans_blocks(inode) + 1; + handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, needed_blocks); + if (IS_ERR(handle)) + return PTR_ERR(handle); + + ret = ext4_map_blocks(handle, inode, map, + EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT); + /* + * Have to stop journal here since there is a potential deadlock + * caused by later balance_dirty_pages(), it might wait on the + * ditry pages to be written back, which might start another + * handle and wait this handle stop. + */ + ext4_journal_stop(handle); + + return ret; +} + +#define IOMAP_F_EXT4_DELALLOC IOMAP_F_PRIVATE + +static int __ext4_iomap_buffered_io_begin(struct inode *inode, loff_t offset, loff_t length, unsigned int iomap_flags, - struct iomap *iomap, struct iomap *srcmap) + struct iomap *iomap, struct iomap *srcmap, + bool delalloc) { - int ret; + int ret, retries = 0; struct ext4_map_blocks map; u8 blkbits = inode->i_blkbits; @@ -3537,20 +3580,133 @@ static int ext4_iomap_buffered_io_begin(struct inode *inode, loff_t offset, return -EINVAL; if (WARN_ON_ONCE(ext4_has_inline_data(inode))) return -ERANGE; - +retry: /* Calculate the first and last logical blocks respectively. */ map.m_lblk = offset >> blkbits; map.m_len = min_t(loff_t, (offset + length - 1) >> blkbits, EXT4_MAX_LOGICAL_BLOCK) - map.m_lblk + 1; + if (iomap_flags & IOMAP_WRITE) { + if (delalloc) + ret = ext4_da_map_blocks(inode, &map); + else + ret = ext4_iomap_get_blocks(inode, &map); - ret = ext4_map_blocks(NULL, inode, &map, 0); + if (ret == -ENOSPC && + ext4_should_retry_alloc(inode->i_sb, &retries)) + goto retry; + } else { + ret = ext4_map_blocks(NULL, inode, &map, 0); + } if (ret < 0) return ret; ext4_set_iomap(inode, iomap, &map, offset, length, iomap_flags); + if (delalloc) + iomap->flags |= IOMAP_F_EXT4_DELALLOC; + + return 0; +} + +static inline int ext4_iomap_buffered_io_begin(struct inode *inode, + loff_t offset, loff_t length, unsigned int flags, + struct iomap *iomap, struct iomap *srcmap) +{ + return __ext4_iomap_buffered_io_begin(inode, offset, length, flags, + iomap, srcmap, false); +} + +static inline int ext4_iomap_buffered_da_write_begin(struct inode *inode, + loff_t offset, loff_t length, unsigned int flags, + struct iomap *iomap, struct iomap *srcmap) +{ + return __ext4_iomap_buffered_io_begin(inode, offset, length, flags, + iomap, srcmap, true); +} + +/* + * Drop the staled delayed allocation range from the write failure, + * including both start and end blocks. If not, we could leave a range + * of delayed extents covered by a clean folio, it could lead to + * inaccurate space reservation. + */ +static int ext4_iomap_punch_delalloc(struct inode *inode, loff_t offset, + loff_t length) +{ + ext4_es_remove_extent(inode, offset >> inode->i_blkbits, + DIV_ROUND_UP_ULL(length, EXT4_BLOCK_SIZE(inode->i_sb))); return 0; } +static int ext4_iomap_buffered_write_end(struct inode *inode, loff_t offset, + loff_t length, ssize_t written, + unsigned int flags, + struct iomap *iomap) +{ + handle_t *handle; + loff_t end; + int ret = 0, ret2; + + /* delalloc */ + if (iomap->flags & IOMAP_F_EXT4_DELALLOC) { + ret = iomap_file_buffered_write_punch_delalloc(inode, iomap, + offset, length, written, ext4_iomap_punch_delalloc); + if (ret) + ext4_warning(inode->i_sb, + "Failed to clean up delalloc for inode %lu, %d", + inode->i_ino, ret); + return ret; + } + + /* nodelalloc */ + end = offset + length; + if (!(iomap->flags & IOMAP_F_SIZE_CHANGED) && end <= inode->i_size) + return 0; + + handle = ext4_journal_start(inode, EXT4_HT_INODE, 2); + if (IS_ERR(handle)) + return PTR_ERR(handle); + + if (iomap->flags & IOMAP_F_SIZE_CHANGED) { + ext4_update_i_disksize(inode, inode->i_size); + ret = ext4_mark_inode_dirty(handle, inode); + } + + /* + * If we have allocated more blocks and copied less. + * We will have blocks allocated outside inode->i_size, + * so truncate them. + */ + if (end > inode->i_size) + ext4_orphan_add(handle, inode); + + ret2 = ext4_journal_stop(handle); + ret = ret ? : ret2; + + if (end > inode->i_size) { + ext4_truncate_failed_write(inode); + /* + * If truncate failed early the inode might still be + * on the orphan list; we need to make sure the inode + * is removed from the orphan list in that case. + */ + if (inode->i_nlink) + ext4_orphan_del(NULL, inode); + } + + return ret; +} + + +const struct iomap_ops ext4_iomap_buffered_write_ops = { + .iomap_begin = ext4_iomap_buffered_io_begin, + .iomap_end = ext4_iomap_buffered_write_end, +}; + +const struct iomap_ops ext4_iomap_buffered_da_write_ops = { + .iomap_begin = ext4_iomap_buffered_da_write_begin, + .iomap_end = ext4_iomap_buffered_write_end, +}; + const struct iomap_ops ext4_iomap_buffered_read_ops = { .iomap_begin = ext4_iomap_buffered_io_begin, }; From patchwork Wed Apr 10 14:29:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624718 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DF84CD128A for ; Wed, 10 Apr 2024 14:39:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 50F4C6B00AD; Wed, 10 Apr 2024 10:38:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4BFF16B00AE; Wed, 10 Apr 2024 10:38:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3125A6B00AF; Wed, 10 Apr 2024 10:38:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 0FD2C6B00AD for ; Wed, 10 Apr 2024 10:38:48 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id CB2FF140728 for ; Wed, 10 Apr 2024 14:38:47 +0000 (UTC) X-FDA: 81993878694.21.CF6C603 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf26.hostedemail.com (Postfix) with ESMTP id 667E014001E for ; Wed, 10 Apr 2024 14:38:45 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759926; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WEJAj3Xwv6fpHpwn6QNVi9oIwy4JAAB23PIthCp/oWU=; b=Z2CV8woMrs+cgtXmUMmKg3AM/tkdd7fxPl5K8oP6UdFMbdu83eDq/jrwyA1Jxabc7XB7rz RfIodzckXRsxtWPtefXRPOBei/ni/Y/kWe3YdU/Ksad9x4H8KlyJIWQ8kZ+4VbbnATydDO 554c8IGfrUupIrLmddGU11XbStvwI3Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759926; a=rsa-sha256; cv=none; b=8A1UQspdlAK2v7cTc63/slQ8zdt7AIzOO9cUZ081huVFwSCDmYskVveCSWVdAzf/ovgnCX a6Qaeccbq3yPHg9mUUVTsO6Y+8p4rJXElRuDGAblKcu5KBfbH7V7Jpt80KnvF+sI6kAccL QW7QD0mOFQ6uCOpWSFcgHbiyP5TLwIU= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF56g0lXbz4f3knL for ; Wed, 10 Apr 2024 22:38:35 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id E8CF21A0568 for ; Wed, 10 Apr 2024 22:38:41 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S29; Wed, 10 Apr 2024 22:38:41 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 25/34] ext4: implement writeback iomap path Date: Wed, 10 Apr 2024 22:29:39 +0800 Message-Id: <20240410142948.2817554-26-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S29 X-Coremail-Antispam: 1UD129KBjvAXoW3ur17CryDKFWUXFykuFWUXFb_yoW8Wr4DJo WavF43Xr48Jr98ta95Cr1fJFyUuan7Ga1rJr15ur4FqFy3AF1a9w4xK3y3W3W3Ww4Fkr4x ZryxJF45Gr4kJF4rn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UjIYCTnIWjp_UUUOA7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20EY4v20xva j40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r126s0DM28Irc Ia0xkI8VCY1x0267AKxVW5JVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK021l 84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4UJV W0owA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAaw2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I 8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCF s4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFI xGxcIEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2AFwI0_GFv_Wryl42xK82IYc2Ij64vIr41l 4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2IqxVAqx4xG67AKxV WUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MIIYrxkI 7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_tr0E3s1lIxAIcVC0I7IYx2IY6xkF7I0E14v26F 4UJVW0owCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr1j6F4U JwCI42IY6I8E87Iv6xkF7I0E14v26rxl6s0DYxBIdaVFxhVjvjDU0xZFpf9x0pRDPE-UUU UU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 667E014001E X-Rspam-User: X-Stat-Signature: gwrpb3b1wjhrx17back1q55jyot1qf9z X-Rspamd-Server: rspam03 X-HE-Tag: 1712759925-282880 X-HE-Meta: U2FsdGVkX1/hDUaYI5s9gPa5RIR6IVL1xjfa63lhADhZGe+x7iAL1xpiKiLO9EuFzyFzv8ONsjdoOjc5B+zdzqA1ARvTQLFD14kOqH+JczzHFiUkyEyVhKx26ApGT1wQmthVCWkAKTxexsehkPUjsvdDGFtb6anTEgwI4TkM4WRmdkGPJB4wdvg3Q8H96bC693HjgAD4aWEM89tmHe/hKhL0j4G5BMp86Kl8WR9pkJ14z5flYcn6moDD7P4nlIoPQEzY0goHHwGdAS713AlNzYYC5z3AQNxMYTw6OgqUgOmw4TecwbsqZGvQzB3aF6hrHX03fdueQSTpO1F3yN/fNBPrkchJwayotxkyEINSSMJZ3azr34u5DaQsUNkjFJ4wZaF7Qx89Ev7V+mVOcOTIRJJVWJBaTYLBsGFWtrGoMnEn/TIt/rT4YY8Pk2tW6PPqjFmg/DAaAwMTNKCoxqpP2ntmK7ZTyEw1obyZJeWpyrD4tk8DRdGM1WXDTDBtnV05U2B2z2Los3V8/Ptq0+AA+zPKyIp0oQXbCHhZlah+nV1eprRF27rbdhN3d8b3Ts6blly4FzPZt+CNqRKAP5y/eIJxP5IqYtcV4KtcUkT6jcL3/tEBoIBUrrA0S0nQsySEfM9o/nehCgiaK32EUheLsVSRQdXzCCS0++PPp+u7q7+Di3XWG4JfQiKvhVbNHJj0ua0aoa0tPeQe3mIO7ZFTInf5TGUoEyn/ZgiJOA2764xlfAGgALLBhmtPjwBY3RYgWrnGihnyYGvVx642uWK7KwzSVYsszXe2RciLLKQR/xpG6c7/eaAJLMfk4UGJfjo7GLCWDrW/GBHNdPxt8jMPhem24DIJk6zHW9k/baZVzdsJ3e8qZTCf5iznjgJlLQrCV6a4YGPCzRxQMNYdJ92SPOMaxHFNt0V8IlUMDnJcOY0NDoo0AF3hVyXLstCv2nPlWOn4l95peJejgH3XPKS hCV2XevS u+tlFWtbb8Uwy485cGn9Oswyq9kMiuGlov8oJ2pxZiAfqeGDcSVs9hFq9OBqmsa30SJMyZF0HeqNAKTCbuCzNXw7INED1XwEoQ38Yx3lHRVCxkT16MkmNToZVDYTADBq4z+05QFAzAubqBBcwy6ZrsqkrhF72lr2K7NeNZ0kOduyHZTmh9xIsZS5zzEa/alEtRUxZR3J7KboDOFK6PCJ893acKPhOvkv5C61glYH/ZDTd+ypUUiQVYOKXmqsETSniiXPP X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Implement the buffered writeback iomap path, including the map_blocks() and the prepare_ioend() callback in iomap_writeback_ops and the corresponding end io path. Add ext4_iomap_map_blocks() to dirty map status before writeback, start journal handle and allocate new blocks if it's not been allocated. Add ext4_iomap_prepare_ioend() to register the end io handler of converting unwritten extents to mapped extents. Note that current iomap call iomap_do_writepage() to write back dirty folios one by one, but we can't map or allocate block(s) for dirty folio one by one because it's expensive if folio size is small. In order to reduce the number of blocks mapping times, we can calculate the length through wbc->range_end carefully and map an entire delayed extent on the first call. Besides, since we always allocate unwritten extents for the new allocated blocks, there are other 4 processes are different from the buffered_head writeback path, which could be more simple. 1. We have to allow splitting extents in endio during the unwritten to written conversion. 2. We don't need to write back the data before the metadata, there is no risk of exposing stale data, the data=ordered journal mode becomes useless. So we don't need to attach data to the jinode, and the journal thread doesn't need to write data. 3. Since data=ordered is not used, we don't need to reserve journal credits and use reserved handle for the extent status conversion. 4. We can postpone the i_disksize updating to endio path. Signed-off-by: Zhang Yi --- fs/ext4/ext4.h | 4 + fs/ext4/ext4_jbd2.c | 6 ++ fs/ext4/extents.c | 23 +++--- fs/ext4/inode.c | 186 +++++++++++++++++++++++++++++++++++++++++++- fs/ext4/page-io.c | 107 +++++++++++++++++++++++++ fs/ext4/super.c | 2 + 6 files changed, 318 insertions(+), 10 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 2bd543c43341..2ec6c7884e9a 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1147,6 +1147,8 @@ struct ext4_inode_info { */ struct list_head i_rsv_conversion_list; struct work_struct i_rsv_conversion_work; + struct list_head i_iomap_ioend_list; + struct work_struct i_iomap_ioend_work; atomic_t i_unwritten; /* Nr. of inflight conversions pending */ spinlock_t i_block_reservation_lock; @@ -3755,6 +3757,8 @@ int ext4_bio_write_folio(struct ext4_io_submit *io, struct folio *page, size_t len); extern struct ext4_io_end_vec *ext4_alloc_io_end_vec(ext4_io_end_t *io_end); extern struct ext4_io_end_vec *ext4_last_io_end_vec(ext4_io_end_t *io_end); +extern void ext4_iomap_end_io(struct work_struct *work); +extern void ext4_iomap_end_bio(struct bio *bio); /* mmp.c */ extern int ext4_multi_mount_protect(struct super_block *, ext4_fsblk_t); diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c index 5d8055161acd..2f83cd90e132 100644 --- a/fs/ext4/ext4_jbd2.c +++ b/fs/ext4/ext4_jbd2.c @@ -11,6 +11,12 @@ int ext4_inode_journal_mode(struct inode *inode) { if (EXT4_JOURNAL(inode) == NULL) return EXT4_INODE_WRITEBACK_DATA_MODE; /* writeback */ + /* + * Ordered mode is no longer needed for the inode that use the + * iomap path, always use writeback mode. + */ + if (ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP)) + return EXT4_INODE_WRITEBACK_DATA_MODE; /* writeback */ /* We do not support data journalling with delayed allocation */ if (!S_ISREG(inode->i_mode) || ext4_test_inode_flag(inode, EXT4_INODE_EA_INODE) || diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index fcb1916a7c29..9849947cec56 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -3708,18 +3708,23 @@ static int ext4_convert_unwritten_extents_endio(handle_t *handle, ext_debug(inode, "logical block %llu, max_blocks %u\n", (unsigned long long)ee_block, ee_len); - /* If extent is larger than requested it is a clear sign that we still - * have some extent state machine issues left. So extent_split is still - * required. - * TODO: Once all related issues will be fixed this situation should be - * illegal. + /* + * For the inodes that use the buffered iomap path need to split + * extents in endio, other inodes not. + * + * TODO: Reserve enough sapce for splitting extents, always split + * extents here, and totally remove this warning. */ if (ee_block != map->m_lblk || ee_len > map->m_len) { #ifdef CONFIG_EXT4_DEBUG - ext4_warning(inode->i_sb, "Inode (%ld) finished: extent logical block %llu," - " len %u; IO logical block %llu, len %u", - inode->i_ino, (unsigned long long)ee_block, ee_len, - (unsigned long long)map->m_lblk, map->m_len); + if (!ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP)) { + ext4_warning(inode->i_sb, + "Inode (%ld) finished: extent logical block %llu, " + "len %u; IO logical block %llu, len %u", + inode->i_ino, (unsigned long long)ee_block, + ee_len, (unsigned long long)map->m_lblk, + map->m_len); + } #endif err = ext4_split_convert_extents(handle, inode, map, ppath, EXT4_GET_BLOCKS_CONVERT | diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index e825ed16fd60..55a4d293177d 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -43,6 +43,7 @@ #include #include "ext4_jbd2.h" +#include "ext4_extents.h" #include "xattr.h" #include "acl.h" #include "truncate.h" @@ -3721,10 +3722,193 @@ static void ext4_iomap_readahead(struct readahead_control *rac) iomap_readahead(rac, &ext4_iomap_buffered_read_ops); } +struct ext4_writeback_ctx { + struct iomap_writepage_ctx ctx; + struct writeback_control *wbc; + unsigned int data_seq; +}; + +static int ext4_iomap_map_one_extent(struct inode *inode, + struct ext4_map_blocks *map) +{ + struct extent_status es; + handle_t *handle = NULL; + int credits, map_flags; + int retval; + + credits = ext4_da_writepages_trans_blocks(inode); + handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, credits); + if (IS_ERR(handle)) + return PTR_ERR(handle); + + map->m_flags = 0; + /* + * In order to protect from the race of truncate, we have to lookup + * extent stats and map blocks under i_data_sem, otherwise the + * delalloc extent could be stale. + */ + down_write(&EXT4_I(inode)->i_data_sem); + if (likely(ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es))) { + retval = es.es_len - (map->m_lblk - es.es_lblk); + map->m_len = min_t(unsigned int, retval, map->m_len); + + if (likely(ext4_es_is_delayed(&es))) { + map->m_flags |= EXT4_MAP_DELAYED; + trace_ext4_da_write_pages_extent(inode, map); + /* + * Call ext4_map_create_blocks() to allocate any delayed + * allocation blocks. It is possible that we're going to + * need more metadata blocks, however we must not fail + * because we're in writeback and there is nothing we + * can do so it might result in data loss. So use + * reserved blocks to allocate metadata if possible. + */ + map_flags = EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT | + EXT4_GET_BLOCKS_METADATA_NOFAIL; + + retval = ext4_map_create_blocks(handle, inode, map, + map_flags); + } + if (ext4_es_is_written(&es) || ext4_es_is_unwritten(&es)) { + map->m_pblk = ext4_es_pblock(&es) + map->m_lblk - + es.es_lblk; + map->m_flags = ext4_es_is_written(&es) ? + EXT4_MAP_MAPPED : EXT4_MAP_UNWRITTEN; + } + } else { + retval = ext4_map_query_blocks(handle, inode, map); + } + + up_write(&EXT4_I(inode)->i_data_sem); + ext4_journal_stop(handle); + return retval < 0 ? retval : 0; +} + +static int ext4_iomap_map_blocks(struct iomap_writepage_ctx *wpc, + struct inode *inode, loff_t offset, + unsigned int dirty_len) +{ + struct ext4_writeback_ctx *ewpc = + container_of(wpc, struct ext4_writeback_ctx, ctx); + struct super_block *sb = inode->i_sb; + struct journal_s *journal = EXT4_SB(sb)->s_journal; + struct ext4_inode_info *ei = EXT4_I(inode); + struct ext4_map_blocks map; + unsigned int blkbits = inode->i_blkbits; + unsigned int index = offset >> blkbits; + unsigned int end, len; + int ret; + + if (unlikely(ext4_forced_shutdown(inode->i_sb))) + return -EIO; + + /* Check validity of the cached writeback mapping. */ + if (offset >= wpc->iomap.offset && + offset < wpc->iomap.offset + wpc->iomap.length && + ewpc->data_seq == READ_ONCE(ei->i_es_seq)) + return 0; + + end = min_t(unsigned int, + (ewpc->wbc->range_end >> blkbits), (UINT_MAX - 1)); + len = (end > index + dirty_len) ? end - index + 1 : dirty_len; + +retry: + map.m_lblk = index; + map.m_len = min_t(unsigned int, EXT_UNWRITTEN_MAX_LEN, len); + ret = ext4_map_blocks(NULL, inode, &map, 0); + if (ret < 0) + return ret; + + /* + * The map isn't a delalloc extent, it must be a hole or have + * already been allocated. + */ + if (!(map.m_flags & EXT4_MAP_DELAYED)) + goto out; + + /* Map one delalloc extent. */ + ret = ext4_iomap_map_one_extent(inode, &map); + if (ret < 0) { + if (ext4_forced_shutdown(sb)) + return ret; + + /* + * Retry transient ENOSPC errors, if + * ext4_count_free_blocks() is non-zero, a commit + * should free up blocks. + */ + if (ret == -ENOSPC && ext4_count_free_clusters(sb)) { + jbd2_journal_force_commit_nested(journal); + goto retry; + } + + ext4_msg(sb, KERN_CRIT, + "Delayed block allocation failed for " + "inode %lu at logical offset %llu with " + "max blocks %u with error %d", + inode->i_ino, (unsigned long long)map.m_lblk, + (unsigned int)map.m_len, -ret); + ext4_msg(sb, KERN_CRIT, + "This should not happen!! Data will " + "be lost\n"); + if (ret == -ENOSPC) + ext4_print_free_blocks(inode); + return ret; + } +out: + ewpc->data_seq = READ_ONCE(ei->i_es_seq); + ext4_set_iomap(inode, &wpc->iomap, &map, offset, + map.m_len << blkbits, 0); + return 0; +} + +static int ext4_iomap_prepare_ioend(struct iomap_ioend *ioend, int status) +{ + struct ext4_inode_info *ei = EXT4_I(ioend->io_inode); + + /* Need to convert unwritten extents when I/Os are completed. */ + if (ioend->io_type == IOMAP_UNWRITTEN || + ioend->io_offset + ioend->io_size > READ_ONCE(ei->i_disksize)) + ioend->io_bio.bi_end_io = ext4_iomap_end_bio; + + return status; +} + +static void ext4_iomap_discard_folio(struct folio *folio, loff_t pos) +{ + struct inode *inode = folio->mapping->host; + + ext4_iomap_punch_delalloc(inode, pos, + folio_pos(folio) + folio_size(folio) - pos); +} + +static const struct iomap_writeback_ops ext4_writeback_ops = { + .map_blocks = ext4_iomap_map_blocks, + .prepare_ioend = ext4_iomap_prepare_ioend, + .discard_folio = ext4_iomap_discard_folio, +}; + static int ext4_iomap_writepages(struct address_space *mapping, struct writeback_control *wbc) { - return 0; + struct inode *inode = mapping->host; + struct super_block *sb = inode->i_sb; + long nr = wbc->nr_to_write; + int alloc_ctx, ret; + struct ext4_writeback_ctx ewpc = { + .wbc = wbc, + }; + + if (unlikely(ext4_forced_shutdown(sb))) + return -EIO; + + alloc_ctx = ext4_writepages_down_read(sb); + trace_ext4_writepages(inode, wbc); + ret = iomap_writepages(mapping, wbc, &ewpc.ctx, &ext4_writeback_ops); + trace_ext4_writepages_result(inode, wbc, ret, nr - wbc->nr_to_write); + ext4_writepages_up_read(sb, alloc_ctx); + + return ret; } /* diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c index 312bc6813357..5ad72f725e0c 100644 --- a/fs/ext4/page-io.c +++ b/fs/ext4/page-io.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -565,3 +566,109 @@ int ext4_bio_write_folio(struct ext4_io_submit *io, struct folio *folio, return 0; } + +static void ext4_iomap_finish_ioend(struct iomap_ioend *ioend) +{ + struct inode *inode = ioend->io_inode; + struct ext4_inode_info *ei = EXT4_I(inode); + loff_t pos = ioend->io_offset; + size_t size = ioend->io_size; + loff_t new_disksize; + handle_t *handle; + int credits; + int ret, err; + + ret = blk_status_to_errno(ioend->io_bio.bi_status); + if (unlikely(ret)) + goto out; + + /* + * We may need to convert up to one extent per block in + * the page and we may dirty the inode. + */ + credits = ext4_chunk_trans_blocks(inode, + EXT4_MAX_BLOCKS(size, pos, inode->i_blkbits)); + handle = ext4_journal_start(inode, EXT4_HT_EXT_CONVERT, credits); + if (IS_ERR(handle)) { + ret = PTR_ERR(handle); + goto out_err; + } + + if (ioend->io_type == IOMAP_UNWRITTEN) { + ret = ext4_convert_unwritten_extents(handle, inode, pos, size); + if (ret) + goto out_journal; + } + + /* + * Update on-disk size after IO is completed. Races with + * truncate are avoided by checking i_size under i_data_sem. + */ + new_disksize = pos + size; + if (new_disksize > READ_ONCE(ei->i_disksize)) { + down_write(&ei->i_data_sem); + new_disksize = min(new_disksize, i_size_read(inode)); + if (new_disksize > ei->i_disksize) + ei->i_disksize = new_disksize; + up_write(&ei->i_data_sem); + ret = ext4_mark_inode_dirty(handle, inode); + if (ret) + EXT4_ERROR_INODE_ERR(inode, -ret, + "Failed to mark inode dirty"); + } + +out_journal: + err = ext4_journal_stop(handle); + if (!ret) + ret = err; +out_err: + if (ret < 0 && !ext4_forced_shutdown(inode->i_sb)) { + ext4_msg(inode->i_sb, KERN_EMERG, + "failed to convert unwritten extents to " + "written extents or update inode size -- " + "potential data loss! (inode %lu, error %d)", + inode->i_ino, ret); + } +out: + iomap_finish_ioends(ioend, ret); +} + +/* + * Work on buffered iomap completed IO, to convert unwritten extents to + * mapped extents + */ +void ext4_iomap_end_io(struct work_struct *work) +{ + struct ext4_inode_info *ei = container_of(work, struct ext4_inode_info, + i_iomap_ioend_work); + struct iomap_ioend *ioend; + struct list_head ioend_list; + unsigned long flags; + + spin_lock_irqsave(&ei->i_completed_io_lock, flags); + list_replace_init(&ei->i_iomap_ioend_list, &ioend_list); + spin_unlock_irqrestore(&ei->i_completed_io_lock, flags); + + iomap_sort_ioends(&ioend_list); + while (!list_empty(&ioend_list)) { + ioend = list_entry(ioend_list.next, struct iomap_ioend, io_list); + list_del_init(&ioend->io_list); + iomap_ioend_try_merge(ioend, &ioend_list); + ext4_iomap_finish_ioend(ioend); + } +} + +void ext4_iomap_end_bio(struct bio *bio) +{ + struct iomap_ioend *ioend = iomap_ioend_from_bio(bio); + struct ext4_inode_info *ei = EXT4_I(ioend->io_inode); + struct ext4_sb_info *sbi = EXT4_SB(ioend->io_inode->i_sb); + unsigned long flags; + + /* Only reserved conversions from writeback should enter here */ + spin_lock_irqsave(&ei->i_completed_io_lock, flags); + if (list_empty(&ei->i_iomap_ioend_list)) + queue_work(sbi->rsv_conversion_wq, &ei->i_iomap_ioend_work); + list_add_tail(&ioend->io_list, &ei->i_iomap_ioend_list); + spin_unlock_irqrestore(&ei->i_completed_io_lock, flags); +} diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 5fce4d2b3b87..6410918161a0 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1431,11 +1431,13 @@ static struct inode *ext4_alloc_inode(struct super_block *sb) #endif ei->jinode = NULL; INIT_LIST_HEAD(&ei->i_rsv_conversion_list); + INIT_LIST_HEAD(&ei->i_iomap_ioend_list); spin_lock_init(&ei->i_completed_io_lock); ei->i_sync_tid = 0; ei->i_datasync_tid = 0; atomic_set(&ei->i_unwritten, 0); INIT_WORK(&ei->i_rsv_conversion_work, ext4_end_io_rsv_work); + INIT_WORK(&ei->i_iomap_ioend_work, ext4_iomap_end_io); ext4_fc_init_inode(&ei->vfs_inode); mutex_init(&ei->i_fc_lock); return &ei->vfs_inode; From patchwork Wed Apr 10 14:29:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624720 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FE65CD11C2 for ; Wed, 10 Apr 2024 14:39:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A5A96B00AF; Wed, 10 Apr 2024 10:38:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 92CC56B00B0; Wed, 10 Apr 2024 10:38:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A79E6B00B1; Wed, 10 Apr 2024 10:38:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 586AC6B00B0 for ; Wed, 10 Apr 2024 10:38:49 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 270ABC05EF for ; Wed, 10 Apr 2024 14:38:49 +0000 (UTC) X-FDA: 81993878778.09.C31F3C2 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf14.hostedemail.com (Postfix) with ESMTP id C063C10000D for ; Wed, 10 Apr 2024 14:38:46 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759927; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DmeNzuRS0UtAzCMbn3rP62UIT6+e3MYM855nqaJqZuc=; b=jt7Hnvh4G7rIVTbju5vo7FfHo5wnsRXO0E/pPWEgZYPwEjtKwSa4XhbFlx/rgCwQx1Zfam XBu6HlKl+3cq2UU+kKbOaoV3399GLM/O4JXwW4kwEOEnpxyuTs/2wVV6iVCdzYpQMgJDXh 0feFxFnhhJCTKDrqGbdvcgjFYTKfzxU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759927; a=rsa-sha256; cv=none; b=OvPn49QsNtdEcrqxL8B3b0Xd2uGwlipUQtTYo96ErnYfrgUrlFa4ev4RkkCfeNiszkpNhP 4x+ChKHaUe6DlqrZNl/10w88aVaTq8m2SQn0CEh+1EyE049ZK5Zd04OWZczjRCBCLcByyu 5+HZvTgLYRG7a7OXOJ4iY13KqntUml8= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56k17L0z4f3kJr for ; Wed, 10 Apr 2024 22:38:38 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 8E1101A0568 for ; Wed, 10 Apr 2024 22:38:42 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S30; Wed, 10 Apr 2024 22:38:42 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 26/34] ext4: implement mmap iomap path Date: Wed, 10 Apr 2024 22:29:40 +0800 Message-Id: <20240410142948.2817554-27-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S30 X-Coremail-Antispam: 1UD129KBjvJXoW7urW3tr48Kr4rGryUWrWxWFg_yoW8Ar48pF 9akrWrGr4xXwnI9FsagFn8ZFyYy3WrWr4UXrW3CFn5Zrnruw45Ka18WFn5ZF45J3yxZw4U Jr45Cry8u34a9rDanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUH214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j6r xdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4 xG6I80ewAv7VC0I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCa FVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI4 02YVCY1x02628vn2kIc2xKxwCY1x0262kKe7AKxVW8ZVWrXwCF04k20xvY0x0EwIxGrwCF x2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVWUXVWUAwC20s026c02F40E14v26r 1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIxkGc2Ij 64vIr41lIxAIcVC0I7IYx2IY67AKxVWDJVCq3wCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr 1j6rxdMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8Jr0_Cr1U MIIF0xvEx4A2jsIEc7CjxVAFwI0_GcCE3sUvcSsGvfC2KfnxnUUI43ZEXa7sRibyCPUUUU U== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: C063C10000D X-Rspam-User: X-Stat-Signature: wqpwdfjxyhe5p73ii5ykxcedybadewg7 X-Rspamd-Server: rspam03 X-HE-Tag: 1712759926-197425 X-HE-Meta: U2FsdGVkX19XATwsOGTKsQPc0ble7qhsObCXEaJMj3km7xasFl5JGIQjoDY808y5lnwD3SBJhVIkyuOqyQVgkh6hXmIv0ScC/QcsOLh6CntNSSOQzM5rREB1te+W75Z7ChHOyQq6wTQ8/ppHZJLdha4Fwuk1MNIX1p2gITz02zjZvYQOjZqzXITEj0fqhl7FkjcDoaot6C0RJd3lcv5L6j31wRlwcQ6LADb3IMQicQA+qhW52krCAuL4Jb08i1ZfGQRq7NR2jM7hp7RaPV4TfI3Azz/UMPahzZwut0Z/BhyNkep9t9v52fE6PzC3UgEKiJmUN7N9NSMJcJxB2aS5eK7kSPossyexPs/NMUmke+OGLip6MjhqluBlUF+n7SbZ58fzUd/eqi31L6SsDr2edkKFWQPDjTV2aSIlHdgiRLkd3TnzcqhPk1QjIUHsEkdEZ9yDYNymAKeZ74JLjiqvzb/oakkzio6CTEHRcY3anoK23xhoh7WifEVmnZnAIxX69sdziazs0DaIC2AMdc7xkGS2EkQTifaZfQq66U6z84tw9vk3tKbB2+lvm9zG+QJwQcH+fdI7lOQFt6F/jaAopmxPjKKrcje6SyFQfxCyRocKctt8GchI084KAjp84XbijGWOzAvPt5yh0mQgn3159q3fFZQyYD64CWvT870e8JdA9cI/kYUFK1B3hHnfqUM+n1nBhqg5e1LQLucDpShqtKvWwBJP4HsFhkni4VFIfcKpcgiX4Nxs0ymsVAQ0BgKAVGvYovp87ll2sKXZG3HuZ9cSmP6o9upEJq39Ts/n/HG83TvmCDFOEP9WiLqZXPPHEFos/iKAI67JlWQBQOgByXP7bhajETIERs/djgOTmmZQ2aX+cL39LYoflptck5vKzpad4QL1t5Fyr4MkKWfhZQgn1xXemAFEmXpQsCLj66gH/lV9k+0Vvyaf3HRUin3eOa+qlmMf1h4uDS8zngk ttPOR61c lvoypD46c++eyX4K7S9sb69UtRAGROEpmEK3zWGADp6/rzlCd3+K1Xuk0HYgWAFsLkhvU2VdsKBbZ2e2NpflWYJXJteoVOQBZE0Whfo6HPTqyFTq6lusYHi2o1+tmV9lJVjtUpbNTGFglqGlUWQrBSeBJ9dByAFKZInc8/POPGVp4OC8rDsNxizBJK/42NTNVhGzFJsgAdWhQhnI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Add ext4_iomap_page_mkwrite() for the mmap iomap path. It dirty folio and map blocks, almost all work have been done in iomap_page_mkwrite(), so call it directly. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 55a4d293177d..9d694c780007 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -6484,6 +6484,26 @@ static int ext4_bh_unmapped(handle_t *handle, struct inode *inode, return !buffer_mapped(bh); } +static vm_fault_t ext4_iomap_page_mkwrite(struct vm_fault *vmf) +{ + struct inode *inode = file_inode(vmf->vma->vm_file); + const struct iomap_ops *iomap_ops; + + /* + * ext4_nonda_switch() could writeback this folio, so have to + * call it before lock folio. + * + * TODO: drop ext4_nonda_switch() after reserving enough sapce + * for metadata and merge delalloc and nodelalloc operations. + */ + if (test_opt(inode->i_sb, DELALLOC) && !ext4_nonda_switch(inode->i_sb)) + iomap_ops = &ext4_iomap_buffered_da_write_ops; + else + iomap_ops = &ext4_iomap_buffered_write_ops; + + return iomap_page_mkwrite(vmf, iomap_ops); +} + vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; @@ -6507,6 +6527,11 @@ vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf) filemap_invalidate_lock_shared(mapping); + if (ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP)) { + ret = ext4_iomap_page_mkwrite(vmf); + goto out; + } + err = ext4_convert_inline_data(inode); if (err) goto out_ret; From patchwork Wed Apr 10 14:29:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624719 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8DC6CD1299 for ; Wed, 10 Apr 2024 14:39:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 33A136B00AE; Wed, 10 Apr 2024 10:38:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2C5E76B00AF; Wed, 10 Apr 2024 10:38:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13CD66B00B0; Wed, 10 Apr 2024 10:38:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E9D006B00AE for ; Wed, 10 Apr 2024 10:38:48 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BBF8EC05EF for ; Wed, 10 Apr 2024 14:38:48 +0000 (UTC) X-FDA: 81993878736.21.6BFC016 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf05.hostedemail.com (Postfix) with ESMTP id 96FED100005 for ; Wed, 10 Apr 2024 14:38:46 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf05.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759927; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6CZLF2scSej3kVTtlU6Wdwgq92cG9Myex7yJb2oFIwQ=; b=0qL6Na/s91BI4JfMO8nSQJxVw2jPA90YzEUkIVVkSqFsB1pSWfd5AQF75bO33rxwDlcOSW pIbZBiVmmyUAf5Png4nJk+tAGSXWRsXgD/Gqe0qALF0JEfvhL/Ujrok2eSKT+NDtt8Sr7E Ba1Uv13Lk3E28XuoZ4VNUH4IdmjrwA4= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf05.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759927; a=rsa-sha256; cv=none; b=0rKq23Y0wlCB/AhlNPPV9UsLtuZPj0rj9k06IV92Lez2KXI0/oindkImLxxwLkXtjWIVZK aIJoZVvcJnv5pS1CmHVkhojNOIn9GlYF32Q0PUeH7n4/8n0iK6QifnveJUX/kHPyv/vcFk af979/F44/85iW2Bn6CIVDAofbdZcks= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56f3rPcz4f3lgJ for ; Wed, 10 Apr 2024 22:38:34 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 352D11A0E0D for ; Wed, 10 Apr 2024 22:38:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S31; Wed, 10 Apr 2024 22:38:42 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 27/34] ext4: implement zero_range iomap path Date: Wed, 10 Apr 2024 22:29:41 +0800 Message-Id: <20240410142948.2817554-28-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S31 X-Coremail-Antispam: 1UD129KBjvJXoW7urW7CrW8XF1rKFW7Gr1rJFb_yoW8JFWDpr n5K34UCr47Wr9F9F4IgF9rXr1Iy3W5Gw48WryfGrn8Z3yfW34xKFWrK3WFvF4jg3y7Jayj qF45try8Kw17AaDanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUH214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j6r xdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4 xG6I80ewAv7VC0I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCa FVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI4 02YVCY1x02628vn2kIc2xKxwCY1x0262kKe7AKxVW8ZVWrXwCF04k20xvY0x0EwIxGrwCF x2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVWUXVWUAwC20s026c02F40E14v26r 1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIxkGc2Ij 64vIr41lIxAIcVC0I7IYx2IY67AKxVWDJVCq3wCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr 1j6rxdMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8Jr0_Cr1U MIIF0xvEx4A2jsIEc7CjxVAFwI0_GcCE3sUvcSsGvfC2KfnxnUUI43ZEXa7sRibyCPUUUU U== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 96FED100005 X-Stat-Signature: xeq8jpg6c855bcwekujxernuja94fjgw X-HE-Tag: 1712759926-521411 X-HE-Meta: U2FsdGVkX1+fqAKSzgbH2A92T2d1RYdE2QdtI4arlkQI++yA5c4fI+K6Uo9PzWrfo5yGSX3eSSPSV5OrtyN5oILBMzv1xlZJ06ax0hAOV2wsYz3wDmPwTgKSfaOVmT5kcEMnMB+u2CuQyHA397gdU7omeftgySlcqyZnKZqHeSYgJmawnVWAB2y56YTDH8oKCWENEO763fW/CmD8biefUP6kLv5ZPxeG3PAPGgXhtu59KTHVvfuku0NCaVcxA18YhhhYi8k8QOIxK0xM5qPXLpLiSbjJ93bzTZT8May5i88BHcy68k1OG6DT9L6OlRcejpE5beE1MUtV4d3J4ga/DEQv7mP9NSM2+My3j+mIgguT/tgEhv0hn2BlCztC1HDsvuFdJVyCC6BJNDwnGcJ99GSMtZbzhB2ixoAGLOhDmcx107NG7X5B1I4Ju/oo/S42UEblyT24oDYYc7N7Vrif3GoHEpbZ/8tOrFERtxLY5ESO3SU9aCMOTPye+RwTP970tW0Z7K141T8UuJSeSQdN784+yseHbTuqZp/35VOG1ymQBXd9BOmVNjZlVu54pqAWywww591AnmF7yujOXz3ruy8DZoFa7jjZPddpdyVkhBi3B3t7E+plyfMPBSJblJaTWkduD64SFW3uf3Reov/cnW3QxNVzNypNlN9LHnCs8cNlccA5ljJub3aKZ3K5Bb4v39Hw0oftzaa2KQvB2NAySTQ0jWwEkn+UGGbKwShm3AMx+WKwf4UV+oU0q8sGA+cva0xSrCNqfgqdq4w36jTh72MEf3N7tzWq+gCCeXuF2mJKzC+HrK7nPcoBl4Gt4ux1K2amuCoGWgB9VUocRiId/Qv2jhT9pyFs5B4MV4MTt6WxyahyC83ZNABduxw73VyPrDYyGeqSQpMYuKtwzXrdaming6fZOMU4j77It7yKD7gSJvj+1c3S+wrbp7Qs59DsrP/HoYYZcFg0nUEWSA/ k+27kGcI EF+LZJo8b4LkFKP5ye0WDu1IU7GABVS89AEE9DWlUg/H+pObye1aEFRcPWDRfXJacXlM3XHNUuJQXI85R8xwbVuxckpIZwXjNFL3wY3SDQDd2uAYcALSTxswka8EQumGsour4Ohu+llDoa1/GwMCehoHGJQ7NkZFJG6j4gaauDKBCoxZxvPImXT0TDrG0DLiiP7n7HNwnykVnlSZcs10HqjmEvtLyqdA+cLaSrltTpnciBBv2tXkJbLIDRyaxli/46OLX X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Add ext4_iomap_zero_range() for the zero_range iomap path, it zero out the mapped blocks, all work have been done in iomap_zero_range(), so call it directly. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 9d694c780007..5af3b8acf1b9 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4144,6 +4144,13 @@ static int __ext4_block_zero_page_range(handle_t *handle, return err; } +static int ext4_iomap_zero_range(struct inode *inode, + loff_t from, loff_t length) +{ + return iomap_zero_range(inode, from, length, NULL, + &ext4_iomap_buffered_read_ops); +} + /* * ext4_block_zero_page_range() zeros out a mapping of length 'length' * starting from file offset 'from'. The range to be zero'd must @@ -4169,6 +4176,8 @@ static int ext4_block_zero_page_range(handle_t *handle, if (IS_DAX(inode)) { return dax_zero_range(inode, from, length, NULL, &ext4_iomap_ops); + } else if (ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP)) { + return ext4_iomap_zero_range(inode, from, length); } return __ext4_block_zero_page_range(handle, mapping, from, length); } From patchwork Wed Apr 10 14:29:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624721 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DE80CD1299 for ; Wed, 10 Apr 2024 14:39:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 92FC16B00B0; Wed, 10 Apr 2024 10:38:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8684F6B00B1; Wed, 10 Apr 2024 10:38:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7083E6B00B2; Wed, 10 Apr 2024 10:38:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 53DB96B00B0 for ; Wed, 10 Apr 2024 10:38:50 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1AE44407CB for ; Wed, 10 Apr 2024 14:38:50 +0000 (UTC) X-FDA: 81993878820.19.24FFF7B Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf08.hostedemail.com (Postfix) with ESMTP id 17FF516000A for ; Wed, 10 Apr 2024 14:38:47 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf08.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759928; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1rfO3bDUWjwaLs+wdCUIuN/1ZGWNGlnDZNmsSH0BvMA=; b=wYY9dj5x0n4YXWVcioJ4VwMSTGRWWGSWeCV4L9wya4NAUQ9dXLeCj2RJq0x/E7M65K2d+d DqzGHHwH+JGgire7wWnfpSMznvHPA7sHtS2mFuPrfxT0jOEahYyMdyvlwbsywwbGkDDRef qSwfeAi4z7Z+aoJoLhOnQSBJd0fPNQo= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf08.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759928; a=rsa-sha256; cv=none; b=JD9xhVio19Lc+nKT3WT+TqGlQSbhQP/Ux0L1TL43pQpPZRqOdrBic1icrtvSibfR2PHJ4G 2gXEgz1Zs51vviWng5GWg1T2isU5SJzRoiOeLD7V/F1Kyu5RHvSL8fEbTNSMJ6D25asvkg yXj/FgSonlkv7fiX3DoWURh8ybWEP1k= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF56h75Rsz4f3knR for ; Wed, 10 Apr 2024 22:38:36 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id D1FDD1A0E12 for ; Wed, 10 Apr 2024 22:38:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S32; Wed, 10 Apr 2024 22:38:43 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 28/34] ext4: writeback partial blocks before zeroing out range Date: Wed, 10 Apr 2024 22:29:42 +0800 Message-Id: <20240410142948.2817554-29-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S32 X-Coremail-Antispam: 1UD129KBjvdXoW7JrW5Aw4UXw1DtFy5XF47Jwb_yoWkZrc_Xa 4rJr1kWrWftr92g3s7Cry3ArWIyw409r1fuFy0y3s5ZFy5Kws2k3s5Ar4xZrZ5WFy2gry3 Cr4qqF48WF9rujkaLaAFLSUrUUUU1b8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbl8FF20E14v26rWj6s0DM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAVCq3wA2048vs2 IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28E F7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWxJr0_Gc Wl84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s1l n4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F4 0Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC 6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI 8v6xkF7I0E8cxan2IY04v7MxkF7I0En4kS14v26r4a6rW5MxAIw28IcxkI7VAKI48JMxC2 0s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v26r1Y6r17MI8I3I0E5I8CrVAFwI0_Jr 0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc40Y0x0E wIxGrwCI42IY6xIIjxv20xvE14v26w1j6s0DMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWxJr 0_GcWlIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4UJVWxJr1l IxAIcVC2z280aVCY1x0267AKxVW0oVCq3bIYCTnIWIevJa73UjIFyTuYvjTRtOzsDUUUU X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 17FF516000A X-Stat-Signature: n7jxr4334e1jz1q8chedh6u793xzuhmi X-HE-Tag: 1712759927-362985 X-HE-Meta: U2FsdGVkX19X7814TPO6s3sh3QIWDjjiNVhUBILcSXNDdaDe9hO7LQUu1N+ItlzgT0xb/cnEG1lpiJp2hXnKiYv+Hlg4K5Lga6MbYtUQ/9/Shzi6k71fBqwaKVlRivnWzkjxVhFCOocWH7o9aLXoTwziSDej3Wv8MR8Z0dvOlew6jmI6uqIu+ULDkJJzooM2okKphKQb8BYL+USwxXCvdkVy4QnG+rvavGgtmXAiM8CRmRk733zDFw4YQXzNPQr2ALW8QZXiLu6pkMnpsvl1CWLkldL428fKVaw8NY7dhRk34qUq2Ey8CMrHX0vj+OYlEmOoxgJjTUR3bLXUwBswp+oHB0Ocky063Z3ntl4CtZFsZyMOr7wC0m31SkBy3TgcnMQMRywcuShB5nCm9aMaaJGtQni7nw3lSo2c8LV2KSW+Hm0+O8O8IY/1DlPsYARD7lp0GEjmPGRDL2xcRvkIkUy4+nkOxQobQ1rSgACWD7EGJtVV1trA0fER4U3svwLxxlGzcSH3WcYrT6BcKnnNlRlAp/QhJLSI/qfeN/C1cpvF7DtmCunoAeS8ZwZ4RfBKPbjQ2H6oVTfwvNDD5t0qZvflu4ookaaeahnu5YEhyzCMFDizINQcEBFc4xEL1XgrPVaiJWTQlQTuJ++Wy5gD/dnGzs8iC7JkVIzf0C3zGoPEbLvjwAg7uZ9FGfbtzgHwIKoYHV+tu7Nx0ozWB/soXwYqfIop6wt/PpuoAyG/bM3TJoNhebeN6EHgBvG9/2ZkzH1ksWLq+zLb5DLt8Wpay+uaDeFXYTJp4dTjlC8SqJBmGaFZXtpVW0HwM11VuAjubxNeIuODudG97lUhLNiKiGOlpjAcbQEFLJo5CR58DhB4UsrulCuff4f66Kr1XJN2qB6c5M9/7jXIIeohWenVvF6jmXyucgSMpiffheZzwGsyxXLiz2l2l3CQ8jocFFo27kGz8ekpaO6rjNsUcI+ oZLLtfPu Mr8q17T2HR0IsV4I= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi If we zero partial blocks, iomap_zero_iter() will skip zeroing out the IOMAP_UNWRITTEN srcmap, it works fine in xfs because this type means the block is pure unwritten and doesn't contain any delayed data. But it doesn't work in ext4, because IOMAP_UNWRITTEN may contain delayed data in ext4. For now it's hard to unify the meaning of this flag, so just fix it by writeback partial blocks before zeroing out. Signed-off-by: Zhang Yi --- fs/ext4/extents.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 9849947cec56..c4c38a323ff7 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -4580,6 +4580,15 @@ static long ext4_zero_range(struct file *file, loff_t offset, if (ret) goto out_mutex; + ret = filemap_write_and_wait_range(mapping, + round_down(offset, 1 << blkbits), offset); + if (ret) + goto out_mutex; + + ret = filemap_write_and_wait_range(mapping, offset + len, + round_up((offset + len), 1 << blkbits)); + if (ret) + goto out_mutex; } /* Zero range excluding the unaligned edges */ From patchwork Wed Apr 10 15:03:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624740 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD0D3CD11C2 for ; Wed, 10 Apr 2024 15:11:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4FE0F6B00BF; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 45E396B00C2; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 107296B00C0; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E12C86B00BF for ; Wed, 10 Apr 2024 11:11:56 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A57101A07D6 for ; Wed, 10 Apr 2024 15:11:56 +0000 (UTC) X-FDA: 81993962232.10.8A37B5C Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf11.hostedemail.com (Postfix) with ESMTP id 40D024000A for ; Wed, 10 Apr 2024 15:11:52 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf11.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712761914; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G63A/1vzHT8HBZ1GnRpYOGjnssd8Ud0KFI6wZDe0IEA=; b=pvPHcI0qKWBFAhGn6zlJ/zk/aixTKDHeIT6cfwLL7zJSh68AR4v3Rfm3DMig2YQx7n6so8 6/UPToyJEDa/FOLm/h7lV6tUSFa1LQ9pVV47wJqWSeqE62QH557UOmWx6BIr+rChduZp9q K0LhCg3t0B4y/HMOBvlkhim8OPmyhfc= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf11.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712761914; a=rsa-sha256; cv=none; b=pE9NNhpaZXogMHBasXSbb/RJ1/6nyUM08Lkyfcwqml42Wdyao8sJiBxwGfreoPenAVjn1+ ADqaWCAS0BDs7cCvd1dZgdrJ/BoahFCOXp+GCGrhwnV0JBD/a6iZt3HKOgzAyuvrdOjpRX VMYjP/SE+q/sjxQmfF2+6PCYHoyD49E= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF5rw0bS5z4f3kKj for ; Wed, 10 Apr 2024 23:11:44 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 7F0E11A0D0E for ; Wed, 10 Apr 2024 23:11:48 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn9g4orBZmFSt+Jg--.51485S4; Wed, 10 Apr 2024 23:11:48 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 29/34] ext4: fall back to buffer_head path for defrag Date: Wed, 10 Apr 2024 23:03:08 +0800 Message-Id: <20240410150313.2820364-1-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn9g4orBZmFSt+Jg--.51485S4 X-Coremail-Antispam: 1UD129KBjvJXoW7uw45KryfZr4UWr15ZF1xuFg_yoW8Kry5pr 9Ikr15Kr4DXas29Fn3ta4UZr1rKa10g3y7urWfW3WxJFWDA34IgFyjkF1UAFW5trZ7JrWa qF40kr17W347G3DanT9S1TB71UUUUjUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQ0b4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAaw2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG 64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JF0_Jw1lYx0Ex4A2jsIE14v26r 4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACjcxG6xCI17CEII8v rVW3JVW8Jr1lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2IY04v7Mx kF7I0En4kS14v26r4a6rW5MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4U MxCIbckI1I0E14v26r1Y6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI 0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE 14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20x vaj40_Zr0_Wr1UMIIF0xvEx4A2jsIE14v26r4UJVWxJr1lIxAIcVC2z280aVCY1x0267AK xVW0oVCq3bIYCTnIWIevJa73UjIFyTuYvjxU0dgAUUUUU X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 40D024000A X-Stat-Signature: hfsaooduzmsguem4biszopeo3xet8eio X-HE-Tag: 1712761912-480857 X-HE-Meta: U2FsdGVkX1/6GabdYecMtJgyBgMDKHedJ62PGr9YD11gad3J9bRr7MvWaVhY/7yCDv36sak9Abew4V7PeOnmatzzku6JCHX9HIKKBphGcftmDqQt+lz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m5uapab0rDjC6DSD6KSCCGqLXkArrYqw44XxsjHepmVGWk00++jYktf787uys/Xy04Ctf+WoWPC3HDnUhcwx/WCd/lwdiCbptfpkzN7pwXPyW2U4UtFA1+zIqzlVeTqI71lgSwGTevQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Online defrag doesn't support iomap path yet, we have to fall back to buffer_head path for the inode which has been using iomap. Changing active inode is dangerous, before we start, we must hold the inode lock and the mapping->invalidate_lock, and writeback all dirty folios and drop the inode's pagecache. Signed-off-by: Zhang Yi --- fs/ext4/move_extent.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c index 7cd4afa4de1d..3db255385367 100644 --- a/fs/ext4/move_extent.c +++ b/fs/ext4/move_extent.c @@ -538,6 +538,34 @@ mext_check_arguments(struct inode *orig_inode, return 0; } +/* + * Disable buffered iomap path for the inode that requiring move extents, + * fallback to buffer_head path. + */ +static int ext4_disable_buffered_iomap_aops(struct inode *inode) +{ + int err; + + /* + * The buffered_head aops don't know how to handle folios + * dirtied by iomap, so before falling back, flush all dirty + * folios the inode has. + */ + filemap_invalidate_lock(inode->i_mapping); + err = filemap_write_and_wait(inode->i_mapping); + if (err < 0) { + filemap_invalidate_unlock(inode->i_mapping); + return err; + } + truncate_inode_pages(inode->i_mapping, 0); + + ext4_clear_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP); + ext4_set_aops(inode); + filemap_invalidate_unlock(inode->i_mapping); + + return 0; +} + /** * ext4_move_extents - Exchange the specified range of a file * @@ -609,6 +637,12 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk, inode_dio_wait(orig_inode); inode_dio_wait(donor_inode); + /* Fallback to buffer_head aops for inodes with buffered iomap aops */ + if (ext4_test_inode_state(orig_inode, EXT4_STATE_BUFFERED_IOMAP)) + ext4_disable_buffered_iomap_aops(orig_inode); + if (ext4_test_inode_state(donor_inode, EXT4_STATE_BUFFERED_IOMAP)) + ext4_disable_buffered_iomap_aops(donor_inode); + /* Protect extent tree against block allocations via delalloc */ ext4_double_down_write_data_sem(orig_inode, donor_inode); /* Check the filesystem environment whether move_extent can be done */ From patchwork Wed Apr 10 15:03:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624739 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A94C1CD128A for ; Wed, 10 Apr 2024 15:11:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 28D3A6B00BE; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 215B26B00BF; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 042666B00C1; Wed, 10 Apr 2024 11:11:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D3D3C6B00BE for ; Wed, 10 Apr 2024 11:11:56 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 92547140816 for ; Wed, 10 Apr 2024 15:11:56 +0000 (UTC) X-FDA: 81993962232.18.875EB83 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf02.hostedemail.com (Postfix) with ESMTP id 3C8BD80009 for ; Wed, 10 Apr 2024 15:11:52 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf02.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712761914; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RZrNAfKqPKEAjMF5Y3M7foneYQpwHm5h4BORCNdEvbw=; b=7nA2Ld1rny0LZvChuauOG4PwVf18n5eLg524tpRI2FabsH2gNa6qPctqTYAplLrrQBaPj3 Aw3JxAdFaMw99/j1kQsVIWZC5tZRlu4aBsrRRVtOkGCHchBW8LyLpeKz+txGrFh5yeqWpe X7j99fvzCGHqIEbqvFJWD/wsmy3Lu4U= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf02.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712761914; a=rsa-sha256; cv=none; b=QtMkbxFhiQkifg+hkjm4xrLAs9+ziETWMK1OoG+L6iiw+wgkcR/jf99qbONf85DAvq9OGu /XRnpQE2MzEngzbEk2QG9D3s+beGZ0m48KZCa55p9wpdgeIoekeZT5dh2mBAZbDuODK5Ms O/igmnv10mM0PQ1g8RrHJRp0ob5CXUE= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF5rw5SZHz4f3kKp for ; Wed, 10 Apr 2024 23:11:44 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 308CC1A016E for ; Wed, 10 Apr 2024 23:11:49 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn9g4orBZmFSt+Jg--.51485S5; Wed, 10 Apr 2024 23:11:48 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 30/34] ext4: partial enable iomap for regular file's buffered IO path Date: Wed, 10 Apr 2024 23:03:09 +0800 Message-Id: <20240410150313.2820364-2-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn9g4orBZmFSt+Jg--.51485S5 X-Coremail-Antispam: 1UD129KBjvJXoWxGw1kKrWrCw1DtF43GFW7Jwb_yoWrGr4UpF ZIkryrJr4Y93s29a1ftF48Zr1Sv3WxKw4UG3yS9wn5XFy8J34SqF1jyF15A3WrJrZ5ua4S qF4jkr1Uuw43urDanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUdEb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUGw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcV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pAbCtkOI6GgvDUohE6dDqI9QVJTXzq9/tBRACL9tBEtYqMlahuGpRuk8LuCWZn3JzBdADWFUYYzr8GmljXHlCFHwo+q1/OQfJbxbUf4xMvaooafsi3KftqEfUBEwosvam/q4afngTjnHz90PVO406Y6y1NUBSTBIAh6oQ3eMK0vmj2Fl4KmhsRIA6g5/kwpU5O8o/6DD4M0mDepHpPjfzPvUIhT5kGy+H3B/Vmrn6XzYipAP1/KMgQ5MAzxkImS8tIB2VxvEfykZI7aRXR4nfZfExPoIxn0LKxp9aWFpW+HanSGow/dgBxZRc76IhiVuf5XDVOIEYku9jus7V+vFdYlyEmSitgCV0fmIBNitp7xfaRXzNsj2jiyAr/X1R219xuOZhWaNQqmpWaY4A6dZ5PzVFuD/5qXOX1O+/wgWcsnXF7gPI//HSkjUYXQIOpmiuKDA5ztmN+FyWqtbOM/q4dSmeWDWBGo+DLtstk9WzUbnbwu8KasQ00utgic4RAKE06abWNAjhXbrbH9b5dDtiApGflOgXvYq0Vhj2tVS0fXKrdBTHMlgex0J84mj1RmbIAhJvoVmB17l+u1+3hcUbUww9wZ8dOYyJkedFQGUobWUCcDwzHWpgIMrsPjFQlCUGU9xHje81cLjkNTgyj8cDHPnk5io+ixc1N/ZvwC56LGL00etdE0lDpG8d7+hhHUKCnFlBGkFxYrTLktwfpeue31s5dubLgqnneXpDhj4yio11a6PzcOzBHNzizLbpKgIZutWmxySJ1DxeZxEqxYUFTzRZ1juNt3sJyW84GFgYYrBPBRZBD4QbmCeiVU auAiJsRY B7Uh3 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Partial enable iomap for regular file's buffered IO path on default mount option, support default filesystem features and bigalloc feature, doesn't support inline data, fs_verity, fs_crypt, defrag and data=journal mode yet (these would be supported gradually in the future). ext4 will fallback to buffered_head path automatically if these options or features are enable. Signed-off-by: Zhang Yi --- fs/ext4/ext4.h | 1 + fs/ext4/ialloc.c | 3 +++ fs/ext4/inode.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 2ec6c7884e9a..4e7667b21c2f 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2972,6 +2972,7 @@ int ext4_walk_page_buffers(handle_t *handle, struct buffer_head *bh)); int do_journal_get_write_access(handle_t *handle, struct inode *inode, struct buffer_head *bh); +bool ext4_should_use_buffered_iomap(struct inode *inode); int ext4_nonda_switch(struct super_block *sb); #define FALL_BACK_TO_NONDELALLOC 1 #define CONVERT_INLINE_DATA 2 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index e9bbb1da2d0a..956b9d69c559 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c @@ -1336,6 +1336,9 @@ struct inode *__ext4_new_inode(struct mnt_idmap *idmap, } } + if (ext4_should_use_buffered_iomap(inode)) + ext4_set_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP); + if (ext4_handle_valid(handle)) { ei->i_sync_tid = handle->h_transaction->t_tid; ei->i_datasync_tid = handle->h_transaction->t_tid; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 5af3b8acf1b9..624eac0cc705 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -770,6 +770,8 @@ static int _ext4_get_block(struct inode *inode, sector_t iblock, if (ext4_has_inline_data(inode)) return -ERANGE; + if (WARN_ON(ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP))) + return -EINVAL; map.m_lblk = iblock; map.m_len = bh->b_size >> inode->i_blkbits; @@ -2567,6 +2569,9 @@ static int ext4_do_writepages(struct mpage_da_data *mpd) trace_ext4_writepages(inode, wbc); + if (WARN_ON(ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP))) + return -EINVAL; + /* * No pages to write? This is mainly a kludge to avoid starting * a transaction for special inodes like journal inode on last iput() @@ -5107,6 +5112,30 @@ static const char *check_igot_inode(struct inode *inode, ext4_iget_flags flags) return NULL; } +bool ext4_should_use_buffered_iomap(struct inode *inode) +{ + struct super_block *sb = inode->i_sb; + + if (ext4_has_feature_inline_data(sb)) + return false; + if (ext4_has_feature_verity(sb)) + return false; + if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) + return false; + if (!S_ISREG(inode->i_mode)) + return false; + if (IS_DAX(inode)) + return false; + if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) + return false; + if (ext4_test_inode_flag(inode, EXT4_INODE_EA_INODE)) + return false; + if (ext4_test_inode_flag(inode, EXT4_INODE_ENCRYPT)) + return false; + + return true; +} + struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, ext4_iget_flags flags, const char *function, unsigned int line) @@ -5371,6 +5400,9 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, if (ret) goto bad_inode; + if (ext4_should_use_buffered_iomap(inode)) + ext4_set_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP); + if (S_ISREG(inode->i_mode)) { inode->i_op = &ext4_file_inode_operations; inode->i_fop = &ext4_file_operations; From patchwork Wed Apr 10 15:03:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624741 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68B74CD128A for ; Wed, 10 Apr 2024 15:12:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDE486B00C4; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B65E36B00C1; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B7766B00C3; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 7721F6B00C0 for ; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 34D25C0822 for ; Wed, 10 Apr 2024 15:11:57 +0000 (UTC) X-FDA: 81993962274.29.E893862 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf16.hostedemail.com (Postfix) with ESMTP id 2BF58180015 for ; Wed, 10 Apr 2024 15:11:53 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf16.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712761914; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xeRFAEtTB6ifOA0Xty8nltqQ4YmeM2x0oln0yUmLntk=; b=S8j5cIltyo/sYdz2y6VAdKx3xwEg51Clwaa71vox3NmB0V9480t6/g0Y2W7sQBh8SbE7Uj vQA5mBAhAJpfb0a8PhtkcJNd6pOEchLVWE1mZQ168SdiwC7sj3HhHy6kgT7WZfu0g6HwdR AdSj4BZ6H0HM5a8q7z91+8JnKjMAUh8= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf16.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712761914; a=rsa-sha256; cv=none; b=ov0rwAGaG9XJUzotyz0PzvTmwgJSzyY1DTpasRlx4tfdk1zaogwTomMrEXVPNKB3f9GCQC Ha3OyXEGwC/dSNoOyt8ytkV2O/13y1gamBfABI2f5e6FWQMFp3ZmdFSZhU2FR0DqubSlyT AsJMEcEn3sktuaBJ4ZU2fvph97najCc= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF5rv05QXz4f3kj7 for ; Wed, 10 Apr 2024 23:11:43 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id D454F1A0D11 for ; Wed, 10 Apr 2024 23:11:49 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn9g4orBZmFSt+Jg--.51485S6; Wed, 10 Apr 2024 23:11:49 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 31/34] filemap: support disable large folios on active inode Date: Wed, 10 Apr 2024 23:03:10 +0800 Message-Id: <20240410150313.2820364-3-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn9g4orBZmFSt+Jg--.51485S6 X-Coremail-Antispam: 1UD129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CI42IY6xAIw20EY4v20xvaj40_ Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr1j6F4UJwCI42IY6I8E87Iv6xkF7I0E14v26rxl6s 0DYxBIdaVFxhVjvjDU0xZFpf9x0zRjNtcUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 2BF58180015 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: nrxzmzdx1ixug5kzjkn59bfdua4w8t37 X-HE-Tag: 1712761913-614367 X-HE-Meta: U2FsdGVkX19djdFHnaxRwlkhaVvM2Sijp/i0CCPCLu7WgA/jhZuhL2r9su/ao6YH2E9G8YJta2DNYON44aA9rd73TRhfyAth9nmEP9+ciUF/Pe7Y4HldH4E24dJCi2Tz2NfBHQrI1a6PLH49d4ZDQtjvbiCiItYvw9Tx6d6H57s/VMd8Vqbg7UxkrR4jVMG6bbfP4IJpeRwfGr8jxdFN3cdTV04Mt+tTywYO7yBdU9pIkWAugQdNaxx7SaGmP3no28HAL5R/LP8ox0R4fdAEbWE6UYPwsboW7jlH4xmgYEPMmZrZUAdRKs3ZNqXLf2f0MkLITaTiN2dkWzK65aTDAfP2QUJEV9wn1zcFY0Eath1lwIvzi4gevceMmRv5w3NCjCaZ3dZmHoUydpHHAcingJyjtNLBUp6/M9FwqAviAMgDE5awMSGt/j38nK5FG6017bsmGYvSerKZYcsO50BZVDcz4ibL6qhTyK0F4goleFUYxsopuiwbAslCizTlZrzY5aO7gehwBnEa6XB0p9DSDDRuZhA6P+g7IEtG6gRnFquNhPId1nKBuYxaXXbiLY7Y8rzDezurURlXdW/dkv9ZBd2I4E+yNjAUDsQpCkpBA7Btu13a6IdxirtReWhNrP0iErhHMHMqTiziMTZ9VKJESlp8/d/stMjwjf3u6PABQIl2HEJi4dlw/voAxQWBt8vNFKvtVgCOcjVWCYMpk8pGnIZsuB8DVkDB+odRm8nabaJ9NipoyQZb2hPxb22G8aSUp+J7FTEi3fnOi0zH0FRanHz/AfqIDvRVjJr91SkKvWXXO24MAwGnNLVc5MwZw+wGoG1C8TiU45zB9B1RmID9pvloNvjSp5NLbrc7vh/2xAmCH9E11jntM+otTvqH8QdpsFLY4xwRqNLeSA09yC6ipFBPEXVj4hXfYXvz9GiWtUQwfZlurNvXYywvfWWVpFtjE6YsDRjs2PtPPOFn3+m kDed7q3z TK7DhSn2XPM9rKWO4z4hBb85TzcCBz04azhnk0dWKms/xc93DlGsctQQ8bdzEAp6scylYcraBKLpOh/anKy7LyETrAyLn/n2VZzMONVLMaE027R3GBB7FjOsYdFT8GteIpTH/X0PwTKdcVOtlKYinekjPKYKlKPFOPzzPM+msTZzneN1edrlcnSwatIMjub6yM3H+LfFkctMWAc01k0BewkMJQg6oEBYr3XOMJN+9HAc38olIpVPgyr79ghwqcvAcgWIE X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Since commit 730633f0b7f9 ("mm: Protect operations adding pages to page cache with invalidate_lock"), mapping->invalidate_lock can protect us from adding new folios into page cache. So it's possible to disable active inodes' large folios support, even through it might be dangerous. Filesystems can disable it under mapping->invalidate_lock and drop all page cache before dropping AS_LARGE_FOLIO_SUPPORT. Signed-off-by: Zhang Yi --- include/linux/pagemap.h | 14 ++++++++++++++ mm/readahead.c | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 2df35e65557d..7e963bc64158 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -360,6 +360,20 @@ static inline void mapping_set_large_folios(struct address_space *mapping) __set_bit(AS_LARGE_FOLIO_SUPPORT, &mapping->flags); } +/** + * mapping_clear_large_folios() - The file disable supports large folios. + * @mapping: The file. + * + * The filesystem have to make sure the file is in atomic context and all + * cached folios have been cleared under mapping->invalidate_lock before + * calling this function. + */ +static inline void mapping_clear_large_folios(struct address_space *mapping) +{ + WARN_ON_ONCE(!rwsem_is_locked(&mapping->invalidate_lock)); + __clear_bit(AS_LARGE_FOLIO_SUPPORT, &mapping->flags); +} + /* * Large folio support currently depends on THP. These dependencies are * being worked on but are not yet fixed. diff --git a/mm/readahead.c b/mm/readahead.c index 130c0e7df99f..481fe355485c 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -505,6 +505,12 @@ void page_cache_ra_order(struct readahead_control *ractl, } filemap_invalidate_lock_shared(mapping); + + if (unlikely(!mapping_large_folio_support(mapping))) { + filemap_invalidate_unlock_shared(mapping); + goto fallback; + } + while (index <= limit) { unsigned int order = new_order; From patchwork Wed Apr 10 15:03:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624743 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78083CD11C2 for ; Wed, 10 Apr 2024 15:12:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 770436B00C0; Wed, 10 Apr 2024 11:11:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F9846B00C5; Wed, 10 Apr 2024 11:11:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4135E6B00C3; Wed, 10 Apr 2024 11:11:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 05B266B00C0 for ; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BE226C0811 for ; Wed, 10 Apr 2024 15:11:57 +0000 (UTC) X-FDA: 81993962274.24.8B0C9B0 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf28.hostedemail.com (Postfix) with ESMTP id 6C4C6C000C for ; Wed, 10 Apr 2024 15:11:55 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712761916; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2EX0DhK7voSCRxND5BJ/bGeHGzBW62o7p09t5EWBBJo=; b=uojDI1OE1NqKWEAr+XNPOuOjUcreHGiZYamj7LaKbP2KlX1JxTvGsIHFvumm/17Fd8IpBV FGiS9rIHcNL7BDlp48KHn83oNkj7jXq+B72y3VRCL3QyIr9A2qqg1WI33nTa7RHvaE4fio KlQdik1W2RfM/qT7iUZUUvkefJmQApY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712761916; a=rsa-sha256; cv=none; b=kVbLJeOoeRz3R70ZmUFITYT5161vEmIMcBytgGe6A7aCte7YcJWS+sttV/+g3hebejz20h 2Nkf7CGDV2OIlju2+RuuddGwSKSI2rRjOIqvCh0qikbYIpTbmsU5NA+0SCXXXzqof33bnw qdz5Lq6laDrRMjNIodjLPPserfOEoEI= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF5ry0llwz4f3kjY for ; Wed, 10 Apr 2024 23:11:46 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 82E021A0175 for ; Wed, 10 Apr 2024 23:11:50 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn9g4orBZmFSt+Jg--.51485S7; Wed, 10 Apr 2024 23:11:50 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 32/34] ext4: enable large folio for regular file with iomap buffered IO path Date: Wed, 10 Apr 2024 23:03:11 +0800 Message-Id: <20240410150313.2820364-4-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn9g4orBZmFSt+Jg--.51485S7 X-Coremail-Antispam: 1UD129KBjvJXoWxGw17XrWxCFWrtF17ur4xCrg_yoW5uF1Upr nIkF1fGrW8X34DuFs5Kr1jqr1Ut3W8Kw4Uu3yS93WkuryDAryIqF1jgF48AFW2yrW8Aw4I gFW0kr1UZr1fKrJanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmEb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r126r1DMcIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7xvrVCFI7AF6II2Y40_Zr0_Gr1UM4x0x7Aq67IIx4 CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2Iq xVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r 106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AK xVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcI k0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8Jr0_Cr1UMIIF0xvEx4A2jsIEc7CjxVAFwI0_ GcCE3sUvcSsGvfC2KfnxnUUI43ZEXa7xRN0PSUUUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 6C4C6C000C X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: itys1qq5m54fbabphn3wtscn8hs33x4y X-HE-Tag: 1712761915-975689 X-HE-Meta: U2FsdGVkX19p+GHETbjrUm4sSy3gQWiroSXz2BRM6N1ilTJ8p/fT21KkxbyRIHb86uHg+87ELHXI8qQ0boaFcLzd+JOUgAIIrH7pAk3vxCNRJX3sa/Bz892DGs+o3XxU5NXaDNihnTGQ4IFpo7Lgp5Bk4TwL27MSlgtUk4RSAdji9+7jHyp1hSZ7DMDekNiHFnT7mfduK3SOHWPYSb8t56E/4G2/yRjoPVJN6GI46jh2VLxAVgQOmGHdw/VqSoRjvjGMA8X6leKj1Z+jCQ94IynKatNG1M16c5DRdb3+ZPr0DyU99WLU1mrTS2dial2HBBIu5aqJZqzD5s8O3zxTCXantA3LNuvRIzuzY3SqJZkleOsG5LBCHcHBUfC/4SgqG8Hg9JbSjulV7JFwr332CUzDQout7eXojss/h4hntSgrkAB4ZarHJ0Q42etG7RFhwAQqv22plZyVZJCOrxwAjkoCCbZHa9QpcmK5LPnxGYU5vtYQd3XZsWlYs7+VjKxuqsFzyAOXwusApy5ieLfdLIoWGBezN1k2q6mxxXNMg1w40RS5PxA1qSRGj3mBjz3nf71n8uU9SPmn9bgLQl8JQZouGfWMvx7pPnZTAZpS+Tb8Ho/u7tEa3rfa8lOeKODsvOx2z6i5ZLaXBNhmAjdUbnBbcTfh7t8eRRO27ka9OK+mjDLms4oBTOfNJM37kIGK6SdAhpP64JnuXQjCQzdCrBoiaxKC0IZ3465bjZarKh7jv+xbfhYf92nQhTRioIouPNRg+1wVsZ0wDiOpZZsV3gKN7kogKILBc9idzf3fl86juzdIzV1HTJ5PUAfpll6KP220MxGwPtmeG1lUozJPMgtmHH8ns9w8q1v0DKnbG+FBprRlzv655S0+AxpMyb78jbBPrXSkjslZQHKFHVnbsXcNfDIT7x1AN/eFD0PCN4mEdq0CNXJfVjEjv7cxftqxYHNiuPIjTeuHLEBfI8m jZk6F18S lUvau X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Since we've convert buffered IO path to iomap for regular files, we can enable large foilo together, that should be able to bring a lot of performance gains for large IO. These are fio tests with psync on Intel Xeon Gold 6240 CPU with 400GB system ram, 200GB ramdisk and 1TB nvme ssd disk. buffer read: buffer head iomap + large folio type bs IOPS BW(MiB/s) IOPS BW(MiB/s) ---------------------------------------------------- hole 64K 45.1k 2820 78.1k 4879 hole 1M 2744 2744 4890 4891 ramdisk 64K 29.6k 1848 44.0k 2747 ramdisk 1M 1994 1995 2809 2809 nvme 64K 19.3k 1208 24.3k 1517 nvme 1M 1694 1694 2256 2256 buffer write: buffer head iomap + large folio type Overwrite Sync Writeback bs IOPS BW IOPS BW ------------------------------------------------------------- cache N N N 64K 30.8k 1928 80.1k 5005 cache N N N 1M 1963 1963 5641 5642 cache Y N N 64K 33.0k 2063 80.8k 5051 cache Y N N 1M 2103 2103 5588 5589 ramdisk N N Y 64K 22.4k 1399 64.8k 4050 ramdisk N N Y 1M 1670 1670 4559 4560 ramdisk N Y N 64K 5834 365 10.1k 629 ramdisk N Y N 1M 1011 1011 2064 2064 ramdisk Y N Y 64K 29.2k 1827 73.6k 4597 ramdisk Y N Y 1M 1837 1837 4985 4985 ramdisk Y Y N 64K 17.7k 1109 33.7k 2105 ramdisk Y Y N 1M 1128 1129 1790 1791 nvme N N Y 64K 21.5k 1343 57.4k 3590 nvme N N Y 1M 1308 1308 3664 3664 nvme N Y N 64K 5962 373 8598 537 nvme N Y N 1M 676 677 1417 1418 nvme Y N Y 64K 26.7k 1670 56.8k 3547 nvme Y N Y 1M 1745 1746 3586 3586 nvme Y Y N 64K 13.0k 813 21.0k 1311 nvme Y Y N 1M 683 683 1368 1369 Signed-off-by: Zhang Yi --- fs/ext4/ialloc.c | 4 +++- fs/ext4/inode.c | 4 +++- fs/ext4/move_extent.c | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index 956b9d69c559..5a22fe5aa46b 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c @@ -1336,8 +1336,10 @@ struct inode *__ext4_new_inode(struct mnt_idmap *idmap, } } - if (ext4_should_use_buffered_iomap(inode)) + if (ext4_should_use_buffered_iomap(inode)) { ext4_set_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP); + mapping_set_large_folios(inode->i_mapping); + } if (ext4_handle_valid(handle)) { ei->i_sync_tid = handle->h_transaction->t_tid; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 624eac0cc705..1cb219d347af 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5400,8 +5400,10 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, if (ret) goto bad_inode; - if (ext4_should_use_buffered_iomap(inode)) + if (ext4_should_use_buffered_iomap(inode)) { ext4_set_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP); + mapping_set_large_folios(inode->i_mapping); + } if (S_ISREG(inode->i_mode)) { inode->i_op = &ext4_file_inode_operations; diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c index 3db255385367..6722b39049cf 100644 --- a/fs/ext4/move_extent.c +++ b/fs/ext4/move_extent.c @@ -560,6 +560,7 @@ static int ext4_disable_buffered_iomap_aops(struct inode *inode) truncate_inode_pages(inode->i_mapping, 0); ext4_clear_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP); + mapping_clear_large_folios(inode->i_mapping); ext4_set_aops(inode); filemap_invalidate_unlock(inode->i_mapping); From patchwork Wed Apr 10 15:03:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624742 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D3ACCD1299 for ; Wed, 10 Apr 2024 15:12:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0BCE76B00C1; Wed, 10 Apr 2024 11:11:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EE8496B00C2; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDD566B00C0; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 96D9C6B00C2 for ; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 695331A06E8 for ; Wed, 10 Apr 2024 15:11:57 +0000 (UTC) X-FDA: 81993962274.19.ACF8C93 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf09.hostedemail.com (Postfix) with ESMTP id 11C0414000E for ; Wed, 10 Apr 2024 15:11:54 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf09.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712761915; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=awtaJ2SqnA4A8f2ON8uwJypWC8BJFCrmyAz2ICqAyvI=; b=WUEQxgX0pXLLqilvQqZtjZsbS9IelAhVMPYjjRbiq3Smq4EaqXmDybkA0nMRAbhV7WNlEL RjzHizctIpD0WuQJ1ZdD13VOihmwK7pKksEm8yPGHUkbhXurmLMkzhPckYqUbrl1A1cF7z eCL3EeV4veg2Iym3SvpAt5idalD21hc= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf09.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712761915; a=rsa-sha256; cv=none; b=PWChEaNmyYSnolUK3Ty3sl3vzr9alg4K+Yra6ZSETNUK84PFI4LDhY89Uo52NrreNyba3s t/w4CH2qYIXHUeZhZp1O8Zi26HdUULE176hqYEltX4SsSya8bFXISu8T4PAEr4JcE/hQAe g8tZc2gPzMceJeI/DcSb2UFpzG3rieM= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF5rt3pXYz4f3mHV for ; Wed, 10 Apr 2024 23:11:42 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 322CC1A0568 for ; Wed, 10 Apr 2024 23:11:51 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn9g4orBZmFSt+Jg--.51485S8; Wed, 10 Apr 2024 23:11:50 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 33/34] ext4: don't mark IOMAP_F_DIRTY for buffer write Date: Wed, 10 Apr 2024 23:03:12 +0800 Message-Id: <20240410150313.2820364-5-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn9g4orBZmFSt+Jg--.51485S8 X-Coremail-Antispam: 1UD129KBjvJXoW7Ww1ftw1xCr1fGr13ury3Arb_yoW8CF17pr s7tFZ5X3WkXr9F9F4IqrW3ZFWrKa1xKFWUArWIka12v3sxJw1xtrsYgFyrZFZxGFyfAaya qF1jq34xWw4xCrJanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQYb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r126r1DMcIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7xvrVCFI7AF6II2Y40_Zr0_Gr1UM4x0x7Aq67 IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2xKxwCF04k20xvY0x0EwIxGrwCF x2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14 v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY 67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI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noIA55n+53g6XjzCf10XhuEauf8v/ti8uq/ZTBq4NUBzG/tGel6y02tWiuUZ93S58iKIgv10bJiPspyrh6xDWFh13bYYpB/gXxDChITRyfRudLFI1/oQrlu6JJurdSGJik4iznwzQyVjJYdGdE9+WwapcsHeydhvv7eGwoESEwXv+Z/1w3+TETaMo4cmtFItVr8Z8JS2nKvqALn+Kz1Bo7K 0x7dHDux mznwnV6gWi83J2HB7zYzw3m4/++oN9iK5c0O8w+/KSlC/RIdQIWP9cnLNI5/j9LDX5kqg+x41Cs13BOG96H8YT1+nteIcDlgZp5FmudW9VnonJqO9Efn/qGoXMI/STtF6cyZClaopjqhe77h5To9DsGKhOsJAJIGzRz1NjVZ8CQnFGMsgV2s04yqivEmhPFwyyxEGxt010AVm1np1Eh9ePUkbXTT+4Jh5z8VRaJEjoaTJ9G6OITX30EJaYw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi The data sync dirty check in ext4_inode_datasync_dirty() is expansive since jbd2_transaction_committed() holds journal->j_state lock when journal is enabled, it costs a lot in high-concurrency iomap buffered read/write paths, but we never check IOMAP_F_DIRTY in these cases, so let's check it only in swap file, dax and direct IO cases. Tested by Unixbench on 100GB ramdisk: ./Run -c 128 -i 10 fstime fsbuffer fsdisk == without this patch == 128 CPUs in system; running 128 parallel copies of tests File Copy 1024 bufsize 2000 maxblocks 6332521.0 KBps File Copy 256 bufsize 500 maxblocks 1639726.0 KBps File Copy 4096 bufsize 8000 maxblocks 24018572.0 KBps == with this patch == 128 CPUs in system; running 128 parallel copies of tests File Copy 1024 bufsize 2000 maxblocks 49229257.0 KBps File Copy 256 bufsize 500 maxblocks 24057510.0 KBps File Copy 4096 bufsize 8000 maxblocks 75704437.0 KBps Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 1cb219d347af..269503749ef5 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3281,9 +3281,13 @@ static void ext4_set_iomap(struct inode *inode, struct iomap *iomap, * there is no other metadata changes being made or are pending. */ iomap->flags = 0; - if (ext4_inode_datasync_dirty(inode) || - offset + length > i_size_read(inode)) - iomap->flags |= IOMAP_F_DIRTY; + if ((flags & (IOMAP_DAX | IOMAP_REPORT)) || + ((flags & (IOMAP_WRITE | IOMAP_DIRECT)) == + (IOMAP_WRITE | IOMAP_DIRECT))) { + if (offset + length > i_size_read(inode) || + ext4_inode_datasync_dirty(inode)) + iomap->flags |= IOMAP_F_DIRTY; + } if (map->m_flags & EXT4_MAP_NEW) iomap->flags |= IOMAP_F_NEW; From patchwork Wed Apr 10 15:03:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624744 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56F63CD11C2 for ; Wed, 10 Apr 2024 15:12:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D14F16B00C2; Wed, 10 Apr 2024 11:11:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C9E6F6B00C3; Wed, 10 Apr 2024 11:11:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B176B6B00C5; Wed, 10 Apr 2024 11:11:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6628A6B00C2 for ; Wed, 10 Apr 2024 11:11:58 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 375C016082B for ; Wed, 10 Apr 2024 15:11:58 +0000 (UTC) X-FDA: 81993962316.29.FC348F1 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf01.hostedemail.com (Postfix) with ESMTP id B6BF140027 for ; Wed, 10 Apr 2024 15:11:55 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf01.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712761916; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rOISLZvWRRFPAoNVpRKCtz5oaelI0ZZn5x96xzrs6Pk=; b=j7Pto404k+GtV2Rx5fCo6ltzQA8TmfbGzTkmkdARxFeZpAg9vmMTnX91e7QxlsUfqXN1pp NzklUWgADgDPHL9qpZ0wLGl1xDhG8D6GhjJtTtOhuVYsr9rKYMSzSBctFTbdXgmh+cg4/T awi3HrW0D4Kb7zq4mEBerC31H8dwvhM= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf01.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712761916; a=rsa-sha256; cv=none; b=VUU11HNQwDPwuWPVcF0CLcLgogFdhpFUB6uR6qzMk93B663CnV4DpWl5063FsHCg1ENKq1 TcG7MKm232bb5tceMcC2cJ87VNMWzCM2GVqNSy5SV2NpNTMK4GAakN9jdoRCyVys0RjtN2 4ACQbNlW/dz7Lb/u4LKF9SDZW1R6Cyg= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF5rz3CSGz4f3kjp for ; Wed, 10 Apr 2024 23:11:47 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id D6AF71A0175 for ; Wed, 10 Apr 2024 23:11:51 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn9g4orBZmFSt+Jg--.51485S9; Wed, 10 Apr 2024 23:11:51 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 34/34] ext4: add mount option for buffered IO iomap path Date: Wed, 10 Apr 2024 23:03:13 +0800 Message-Id: <20240410150313.2820364-6-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn9g4orBZmFSt+Jg--.51485S9 X-Coremail-Antispam: 1UD129KBjvJXoWxCw13GF15ur4fGw47KF4kWFg_yoWrJr4xp3 s0gFWrGw1vvryj9FWI9Fs3Xr1Sya1Fka1UCrW09w17XFZrAryIgFyfKF1akF4aqrW8XFyI qF1rKF17WFW2krDanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQFb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r126r1DMcIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7xvrVCFI7AF6II2Y40_Zr0_Gr1UM4x0x7Aq67 IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2xKxwCF04k20xvY0x0EwIxGrwCF x2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14 v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY 67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAIw20EY4 v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr1j6F4UJwCI42IY6I8E87Iv6xkF7I0E 14v26rxl6s0DYxBIdaVFxhVjvjDU0xZFpf9x0ziBWlDUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: B6BF140027 X-Stat-Signature: pek7ehmms3n49fhzy63rrwdu5rhsxc1q X-HE-Tag: 1712761915-96725 X-HE-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Xk3Ob7rvsS32jbetpYo7MkYsx37Tfun3n9GmU84W1bc/Q55VRp0jFaooxpHOrXi/O3LVE1UCAHwl5leEaffxwFxNns2GGcWiXhpc3FPuoUjVGg0DI/zBrC2NyuQrSfhVJrxBNhDuUiDJtjDbQarphXvUb3p X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Add buffered_io_iomap mount option to enable buffered IO iomap path for regular file, this option is disabled by default now. Signed-off-by: Zhang Yi --- fs/ext4/ext4.h | 1 + fs/ext4/inode.c | 2 ++ fs/ext4/super.c | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 4e7667b21c2f..fef609e6ba7d 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1254,6 +1254,7 @@ struct ext4_inode_info { * scanning in mballoc */ #define EXT4_MOUNT2_ABORT 0x00000100 /* Abort filesystem */ +#define EXT4_MOUNT2_BUFFERED_IOMAP 0x00000200 /* Use iomap for buffered IO */ #define clear_opt(sb, opt) EXT4_SB(sb)->s_mount_opt &= \ ~EXT4_MOUNT_##opt diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 269503749ef5..c930108f11dd 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5120,6 +5120,8 @@ bool ext4_should_use_buffered_iomap(struct inode *inode) { struct super_block *sb = inode->i_sb; + if (!test_opt2(sb, BUFFERED_IOMAP)) + return false; if (ext4_has_feature_inline_data(sb)) return false; if (ext4_has_feature_verity(sb)) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 6410918161a0..c8b691e605f1 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1685,7 +1685,7 @@ enum { Opt_dioread_nolock, Opt_dioread_lock, Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable, Opt_max_dir_size_kb, Opt_nojournal_checksum, Opt_nombcache, - Opt_no_prefetch_block_bitmaps, Opt_mb_optimize_scan, + Opt_no_prefetch_block_bitmaps, Opt_mb_optimize_scan, Opt_buffered_iomap, Opt_errors, Opt_data, Opt_data_err, Opt_jqfmt, Opt_dax_type, #ifdef CONFIG_EXT4_DEBUG Opt_fc_debug_max_replay, Opt_fc_debug_force @@ -1828,6 +1828,7 @@ static const struct fs_parameter_spec ext4_param_specs[] = { fsparam_flag ("no_prefetch_block_bitmaps", Opt_no_prefetch_block_bitmaps), fsparam_s32 ("mb_optimize_scan", Opt_mb_optimize_scan), + fsparam_flag ("buffered_iomap", Opt_buffered_iomap), fsparam_string ("check", Opt_removed), /* mount option from ext2/3 */ fsparam_flag ("nocheck", Opt_removed), /* mount option from ext2/3 */ fsparam_flag ("reservation", Opt_removed), /* mount option from ext2/3 */ @@ -1922,6 +1923,8 @@ static const struct mount_opts { {Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET}, {Opt_no_prefetch_block_bitmaps, EXT4_MOUNT_NO_PREFETCH_BLOCK_BITMAPS, MOPT_SET}, + {Opt_buffered_iomap, EXT4_MOUNT2_BUFFERED_IOMAP, + MOPT_SET | MOPT_2 | MOPT_EXT4_ONLY}, #ifdef CONFIG_EXT4_DEBUG {Opt_fc_debug_force, EXT4_MOUNT2_JOURNAL_FAST_COMMIT, MOPT_SET | MOPT_2 | MOPT_EXT4_ONLY}, @@ -2408,6 +2411,11 @@ static int ext4_parse_param(struct fs_context *fc, struct fs_parameter *param) return -EINVAL; } return 0; + case Opt_buffered_iomap: + ext4_msg(NULL, KERN_WARNING, + "iomap for buffered enabled. Warning: EXPERIMENTAL, use at your own risk"); + ctx_set_mount_opt2(ctx, EXT4_MOUNT2_BUFFERED_IOMAP); + return 0; } /* @@ -2838,6 +2846,12 @@ static int ext4_check_opt_consistency(struct fs_context *fc, !(sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_INODE))) { goto fail_dax_change_remount; } + + if (ctx_test_mount_opt2(ctx, EXT4_MOUNT2_BUFFERED_IOMAP) && + !test_opt2(sb, BUFFERED_IOMAP)) { + ext4_msg(NULL, KERN_ERR, "can't enable iomap for buffered IO on remount"); + return -EINVAL; + } } return ext4_check_quota_consistency(fc, sb);