From patchwork Wed Apr 10 13:27:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624537 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 03F26CD11C2 for ; Wed, 10 Apr 2024 13:37:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F1AAE6B0089; Wed, 10 Apr 2024 09:36:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C8A336B0095; Wed, 10 Apr 2024 09:36:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8CE76B0093; Wed, 10 Apr 2024 09:36:57 -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 3CEB46B0089 for ; Wed, 10 Apr 2024 09:36:57 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id DCBF7404B3 for ; Wed, 10 Apr 2024 13:36:56 +0000 (UTC) X-FDA: 81993722832.16.55ABD9F Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf25.hostedemail.com (Postfix) with ESMTP id 210C9A0021 for ; Wed, 10 Apr 2024 13:36:52 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712756215; 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=0NcDJzi+oHok5v1XXTc1uIQyEi2HTgAvDFVOLk43aV7eRTnWSNlfiA6Kh5qXzSkrKD7to+ YKG8FK7z0Bmm6XtHtjHP4c2Tt0sBE3tyWjmO/zyILXKcxWpOZFJVZSq8x49QocX28v3xey 70FoLARxak81N5V1Ld+BsU3n5siy7+I= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756215; a=rsa-sha256; cv=none; b=2ZN+54/34056WC2v8bd7BUd8xK8NfeGFyQ4Qzh0ulLQcYqbl+9cTWLn3EkIMM+noraMGMs VHJ7eRqEOYN1cXBib7VGM/OD69rCe6s6aY+MrBGpe8p9JS/4gOWqdNwN6QQ4+0D98jz/g0 7UUCkWl9T9bFAgG7Y/tk0KPWofX9se0= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lJ1DGyz4f3jjj for ; Wed, 10 Apr 2024 21:36:44 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 938751A0C52 for ; Wed, 10 Apr 2024 21:36:48 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S5; Wed, 10 Apr 2024 21:36: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, 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 21:27:45 +0800 Message-Id: <20240410132818.2812377-2-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S5 X-Coremail-Antispam: 1UD129KBjvJXoWxXr4rtF1xtFWfXw15Zry3CFg_yoW5XFWUpr ZxCryrCr1UWwsagayftr1UZFySk3W5trWqq397Wr1rA3W5CrnayF15tFySqF9rKrWxXw4Y qFWfKryrCw4fGrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBE14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UM2 8EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AI xVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20x vE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF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totXbmqw1ulnEi9z1pEgZHUGqTvaC2kO5eNjD57L4wDjT8jHf5rFT1bc1gkjUmsyeqba5jjoeXhxdyzoUUFHddHHqKFX1lm5M7UEz18oA/GkhkSlMDpOtNirvY3IuT2Yu+FNQ9LAdlGqTre7q3flwClpqNqkzyEr/Ce7JqETYGPN1oXd3H+sBsdCPsLi2EnIzjgE/GghYJ+BWA4IjL1ewxyH62z49QHv6aVZi0hz9tGm/aFVuvTFTh9CBArlIK1STjKmDWJ4i0g9hC4hQf2Kq0coQJoCny51kz1z6eoh7kD7tEe6gz8JI0HCHOjVd8xqKvMOJq0r7nbfafXNHLLBDObhusa671vlvFB4841pqFv0wBiI2NBE5C3eiGZGCshwd5Z5gIWFTVHXb3yeiIqNwO9G4IoX+Wq0if4kcx3UgBp2ZGzNQeo7icN8iMRjaAjuRbeAe0lvfucY6nqy+4Zg9hSRtUBlzuN2ENCIrk1oeAypdhy xCECo3io PoiK0NsBimrdZU1htRoh6UbbFP/OlK+LzPulY+xkG1cu7v3zOaHrHqfxmYWwrMOEu6BYyry5i4O2Jq/iWwF5NtjPShiRaJBhUzFQvYCDKsaV0hlGl+U0hMV26+s4BV//XtIwmArpVXLeIZ0WuiA+lhvILOGa8f5gyRa7SVOGFtTieTjU8qYpPnJSVNbJBmIBN1ttxOph8zkGJBjImQz4LmvDnMwwkKBVn8mE65jub5cGVcbBJbgIW0bzmb9B3Lrq3kLfLyUUPdRaaRC6MJppocTJ02voCNfLUkLo9 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 13:27:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624536 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 91D7FCD128A for ; Wed, 10 Apr 2024 13:37:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CCDAD6B008C; Wed, 10 Apr 2024 09:36:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B54036B0089; Wed, 10 Apr 2024 09:36:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 957E66B0095; Wed, 10 Apr 2024 09:36: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 3C3516B0088 for ; Wed, 10 Apr 2024 09:36:57 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C052B1C099E for ; Wed, 10 Apr 2024 13:36:56 +0000 (UTC) X-FDA: 81993722832.02.F94CD54 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf16.hostedemail.com (Postfix) with ESMTP id 38CD018000F for ; Wed, 10 Apr 2024 13:36:52 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=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; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712756215; 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=wsyRqEPZmyUgfqgkXiFmmPNnmRjew3QJdedz7/yL7LeE98Pc2Qg3+CcsuIDot5HL7HrPwR DrOQAxsoI7kiEZd6stt0+ONZgPBT4s0drD/ZtGxNAop6jTPX3Df9PH8l2ZpW6XjGgl5pZq rNAUrj2pTtIrKCYAdBU8cnFJTylapGg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756215; a=rsa-sha256; cv=none; b=wZfz8uVsoYbcsw+fJ2DW0KUYXQW5y/HU9u2/P5qxhnh1SfBE1h6y6CEKTtBbeYIzg/7DHJ jJM+WU18QKFXNb+m+mhHsSFigvTzWM9nxabP2PLalNQAATJB1bsZmZnG6lDGFvAqiipklV eJGpZZq0YcjqtBidOK9zw84i/1ui7dE= 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.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lD3mlxz4f3m7L for ; Wed, 10 Apr 2024 21:36:40 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 315281A0D65 for ; Wed, 10 Apr 2024 21:36:49 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S6; Wed, 10 Apr 2024 21:36: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, 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 21:27:46 +0800 Message-Id: <20240410132818.2812377-3-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S6 X-Coremail-Antispam: 1UD129KBjvJXoWxurykJF17GFWxuF48Jw1DZFb_yoW5Grykpa 9xCF15Cr48Wwn7Wa93XF12vr1rWa1rJrWUKFZxKr1UZFZ5JFySg3Z0vF1aqFyftrs3JFsY qFWjqry8ua1UKrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP014x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJw CI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VU1489tUU UUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Stat-Signature: kcw5zhwjj6p6smpp5dxy5iw49yk4gk48 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 38CD018000F X-Rspam-User: X-HE-Tag: 1712756212-177529 X-HE-Meta: U2FsdGVkX1+1hc6IL0OUqLSkYl7qVQ0qXyIhTHPTxouaG81dCstbVrql3ulLM/NcVa2o1BtSaNPWw4N20g83PT2e7z+8h2WqN8RDcB/xqp09Mo2us1JNjzqWWmcg1wIXRF9fycGTowwHCG1REVV/jiFIl4IL/1rLvaUXJt6znhSUxUyZ0eeOiZqZnT+MtPFqpM0LRNDBlhHAAdGOkZolOottneO64zZZV1aarNUcj7+nFEsf/q3M4aj2yudeX982vZL+b4JvZ537APom9mXQOS99i2ruxoVPbtY983hA9uWY1oo+4MwJYe41cd4pYd0RpOl3/luX5yASIMYsyJIyOqgbcMO+PZ7jXS0kIUBsVPthk2uiv5gEUnR0DBABVPcF6gqV8zjpMpI0oeZe8tZwtK5HzNNYNWCNtDhIe3iT1r2ezW37MJOoMKEQAroT5Lf60YYeXkvtwMMt/OZM1OIBIhRpe9NbP+YKpTu3aSavJKU37UThw4rNfvuoqMaYverAY/vRtrOBScwU+R0YIVa2zceCO5s+4f3GjjmJOVMBWNVlXXinbaQ34dJTHs8lcb4QG2lLeeeHIroQmH5OeQthv8CAOnM/prNcBO+2+WYPyASaqEYfV4UCMQ0iaqyTatyWsApR+PmA3/0RuFm4sTFS3AykcAeh0bhhDimmUmeTly56i/s9RhhR0MeQkrw9qfHX1H4L9d96a6gAmx0PVYy4HUX885taHhWampzHt8lLLWA8M2UtsGAvqNwkP/nwLVmg5q/+Tznf4HGkICkbh6/8Cp1vvT9HFTnZi9Sx5jagxayWLLClYR4dBlOUDY311yNgr5BmUKASZRc+ZTobYkYAgkEHAmn8Dauv9TAsOSPjzv30Pdawch67ydmU43l41iS0oZ6KevcDo1KIouMSoX8Q5OkKmso+2JF9Z4QLppKEd4kGqdGN9wwQcgnmZSGis8q5Ssb6yW4JHbhH6g6EcOV WC2+yPbv /O5+mFleAw66vbydoFm7UVGHn5wjwaLlGPs2JDmaszYQ/FbdmllLZNFJzRvr6nEuPhUyyWKEnDVivORZzEDdysJjISEF64hKzewGvXRBLfowAfgeklumHFwn5NAV4UJsZFfKgrQm5/H6BYMusERss9N5H8PtHnr6YV0gcoTIDouyK4r6CP/7OmeV0LkjKuAePKC7P8jnnw8TZQqZeZkG2P0x9nSPg1mu6Q8hmC42XZyOiM7GhJ2n8b16F1/iF1YDnqrFMn4D07S0XAitLlrp+CoOiHsjpIt6HO+/4E9P5aj693xV+hEY6m2dK3A== 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 13:27:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624534 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 31C07CD11C2 for ; Wed, 10 Apr 2024 13:36:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E1A06B008A; Wed, 10 Apr 2024 09:36:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7598A6B0092; Wed, 10 Apr 2024 09:36:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 621886B0093; Wed, 10 Apr 2024 09:36:57 -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 41D796B008C for ; Wed, 10 Apr 2024 09:36:57 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id EAA731C09ED for ; Wed, 10 Apr 2024 13:36:56 +0000 (UTC) X-FDA: 81993722832.10.AAC7E6A Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf26.hostedemail.com (Postfix) with ESMTP id 9CF8E14001B for ; Wed, 10 Apr 2024 13:36:53 +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.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=1712756215; 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=aQpz+83kqZr5Y9dotrz/JW5gN6YE1HDHQXhrd8uaICj7SsK2q6XGiupETpbY7J2ZAHwEB5 OgJ41rmLinAKjC92rUMepD0sUnIxdK6+EePR297EpTwcx5K1/kvwB1zRITf8GNwvBvsTpA rappG2oArJbMQM2kZrjoHYwbfjSJmWU= 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.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756215; a=rsa-sha256; cv=none; b=ygmT8H8XTQoMcDRoey5Rdxvn7w99B0GX8Aboj6aLnO9GiH7wxqoxeq/0ukuZZjek7vSMRU Fo1BCN73f35aiU4GAbsUEBzznUGhijZshbgDE0r4a8wbyWbovC+xc723ZQxxlNKzWCkBtp 2b+oSlmRJvb1gqaW8Tx4YtDttv7kEVY= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lF18ynz4f3mHF for ; Wed, 10 Apr 2024 21:36:41 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id CC1091A0D6D for ; Wed, 10 Apr 2024 21:36:49 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S7; Wed, 10 Apr 2024 21:36: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, 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 21:27:47 +0800 Message-Id: <20240410132818.2812377-4-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S7 X-Coremail-Antispam: 1UD129KBjvJXoW7uF1xWF1Dtr17tF15Aw4Utwb_yoW8CFyUp3 93CFn5Gr4fWw18WayxJF15XF1rK3WUKrW7GrWfKw1rZas8Gw1fKaykAF17tFyUtrZ3Xrs5 XFWDtw18Cw4ftrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP014x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JrWl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJw CI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VU1VOJ5UU UUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 9CF8E14001B X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: a4m4wsmieyhrqmc83mabkcghn3c4pui3 X-HE-Tag: 1712756213-484378 X-HE-Meta: U2FsdGVkX1+oKwAFoi88djIGmMEYpsle3CFadapKlbjyzGcoIh05hAOiFxAn/bubsLGIGrE91d0gS54LZ9XZDkeQ8I81ZwL/yErQc3qsITgkvUZsWzT1n0q+aLq3wrW0ORYRqoCytLKIAtYFN1eUQLyC67tObNC6qQxF41zpb/F5/UwyHNeCME7u5EhpbPzzg+Z9ReoGwGyAgUUE30kJMCv+tVitByZ0IVkUrpzU/NX2RZ119Wf9dF6tLlXeUsLncZRB1xGej3Mba/hbpooJPd0y3RVeS1FDCMtkInpRfpkJ0yfAkgKr3UVBRbZ4tzNIn0+9FW/I3wT5jRKB0EmL5Qx4gMMXIkBW+u+N8Eh95fv48lmRC0QOKiJ1KAsbIAqDYwUldoUCyv/SoAO5XwnWX+F4B9uEIheAnVYWrS6wemOSGM0mbHjrkepINhYjSUrIq1M4x/nkVyjNQqTeFvVApCm3qYFn16cD7w/hizF2OIHM6UeJZXzlh7d4ca3AZBKYhyrpYH6PAqL0wnc7Vluhjc7IOGG7431/R683SgsMh+lHyyylUJClRzphaeOYBnGZSYbXLXevdsBmRQxMhGKfoDGl/8dtIwALCcmlWBgrwfEut9o4KJaynPW3unpFjMdoi5Lbdhwjy2syW/vnfaSzSYRg6SSNLT3LcArRV3B4wUHBquet2HA9gDRN5MtmyncbzvDO7OX54BFBLCHCnUN/ciF7qLFtabfoLmDOY+uwLgZKEuTPsHtgCtcTkESPmA1FuC1BHkbdADheELFwcJvIq+C9Nv+z/19pTd40Bnam6IBGsYu6gbKpPBeXeX+l9JxnRzz4zqmLPbeOVfe7sFBOzn9eYznbISAbMJK9h3SZYhEA7MLRSXywRTevazBjykDEwMOA4laZlp+jT7v7J8hravpBRHM3xTTKmu/irBsC2VJpvPjCCPJ+l207MPKZ15XPMwQ3yh73fLGCrAK91/M gu2Q/+La dc2KrK2224tOUmpAZm+5QvWo+doz9Fh9adaujNrjfnGAfrW4VYXBadEZTwQfWHPk0WUMxFj9pdEBj6jVa7aUqLnW8QjJaHjhqPYqxH5VL6FZjtgg20dPf3RXUtJZDXwPVEI6ja9uLdnui82BI/hB0D5Q1uS6prBrU1lm5920e19OoVsUHzXdB78G/ggS9Vjb+ybbdSrEjiKTJJac2mGL0BItG2wkI8EHHWwQafqyiwTRSe00iptOFPkL0OuQcrV3gJVhq 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 13:27:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624543 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 DF048CD1299 for ; Wed, 10 Apr 2024 13:37:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4760D6B0099; Wed, 10 Apr 2024 09:37:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D8966B009A; Wed, 10 Apr 2024 09:37:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 203C66B009B; Wed, 10 Apr 2024 09:37:00 -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 E3D196B009A for ; Wed, 10 Apr 2024 09:36:59 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A871D1C09ED for ; Wed, 10 Apr 2024 13:36:59 +0000 (UTC) X-FDA: 81993722958.16.F428D07 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf09.hostedemail.com (Postfix) with ESMTP id 4D02A140015 for ; Wed, 10 Apr 2024 13:36:56 +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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756218; a=rsa-sha256; cv=none; b=7mCK5fnZxtOlqEwuUESy6JmM5vxlJRsbYDS/nkLWs8CrdQvjYxDuRMclig4GSyTRx+GEyQ 8yeK52leEQ9Sk2E4niRA4MJJ8bNowOqNsc5dcay/hToCVrR/XQg68oLAhaoxFxkIJqDwLC LxRSJhnyTBmn+1olz9gVWnCDVA4e9Uk= 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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712756218; 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=aSxO8Fiq++K91yeg7tgbOlTRVem3EJ6LRJsCaAp2MVnMjUCisi9tmjFWCB4H4viOmu82YC /DXBnb1ZcrSiQsfgHqK8nsA+IoI9yaq/o8m/ArSgW7depGG0hT0WZUahMUIweIoVlhIRVy QVPohidgNXArFGJmAyULt1f/tetip5k= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lF5Yt8z4f3mHG for ; Wed, 10 Apr 2024 21:36:41 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 6CB4B1A0572 for ; Wed, 10 Apr 2024 21:36:50 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S8; Wed, 10 Apr 2024 21:36: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, 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 21:27:48 +0800 Message-Id: <20240410132818.2812377-5-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S8 X-Coremail-Antispam: 1UD129KBjvJXo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17G YJUUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 4D02A140015 X-Stat-Signature: hmez3n71cbhgoz5uqjomwm99du5wyms7 X-Rspam-User: X-HE-Tag: 1712756216-556432 X-HE-Meta: U2FsdGVkX1+9W4rkIGP22RsL0qI1J4ne6W2P9gYlXDxxGcw0cgAilz5ECz0FZIDwae1TBGPVRPtMFFwY5quCeurzRbDDO/UlT3/TQ27iJr1dDIc6Kae05XypoT1k1oeBFgfW1odHBBHhigu9ePsUIDCHjQitR8syKX8mGK7dRSQ1uRLXZDXzjlDRb60/aO2i+lR3aFTikAVqrsom9whu0fgEQ0eEwl0oh8PcBoNo6pfTyzlHN39J2YrvioVghCxDoYiTSeJMY5H1bvtYvZNDo81LGVAxLicTEwcA98DZYA+ug3RuPGyenhiZ1DoGcAV+MMRulvVIWMj8GmLOIHuQOYUjZ/QuhchidWKIeAdw4dE6TFDIyTMKTYzfVMJk4zzmeukKcOPjkdvgU/fx3301+T3fBcBxFljEcWCVhH3CNsu98Qea7QHVrwGI1fj62z2vSnBKH5h2jJAUcfD7/k9W4hZYUELnravBCW81/GEZyW0xay+gxhRqNgr6sbemK7gTfjnHm9++kSliIGcQoxM6YgzWYhDwEAPQ+zxpQWfCbtK+qWoJZWIKLaRkeHy0e6rK1OVetDdG4B1XPevoXaIlkvsqShtZ1ealzcg4399AgjcjvSYsMFx7ELcxiS+dp1bWKswi+0RkVrQ3ZRpZzG+GFKiNUZqKMy8d8QVamht4ZsQIEl/VikCbcIypal1wPIZ9u1uF8y62brAV3J5wXzBnxq/kQH+YYmI1I4YaGkzjlzdMcUUm3rZc5/XEaxA3E50DHELb7XKUMYmXNEBd9qAtthMmEPDIa5sg6ehy6uhhMqoeFt/YTRBKbiN63jdbm4cfcMBqCOoMXVnXLuqjUASMpmH5Zu6z6wHP3Z/m37zGxl24iMZtqHoOJ6Q09BDRkUueVHq15SHGFEQY0SitpGPFUTf0WUDioxcGj664Uupt0VVQbTDKbJTcjCNkdyLkVI3K3+SCjiKfYZz1LbvFId+ EiNSOQwP keg12NMISP+BKamRvp1jmd3qT9YIkH5jqNmUbZu3Up1gpV7ChkA7hCYvTYFQ/3INZQNq889Dr9fNfYRsaeQYLwDxs2gUlCNfw4bDtDffSDqKEXVha8T3wPP4auifShS8DdGII9iCqS6GgQP0FZrsjZn7lllBnHKFU6zPRQNK93yHEN/KiNSKpXhvtUtKwWHtEH45GsY62xtFlU7M= 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 13:27:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624539 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 7D391CD128A for ; Wed, 10 Apr 2024 13:37:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 38CE66B0093; Wed, 10 Apr 2024 09:36:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2EED96B0095; Wed, 10 Apr 2024 09:36:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B5B46B0096; Wed, 10 Apr 2024 09:36:59 -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 F36F66B0093 for ; Wed, 10 Apr 2024 09:36:58 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B4FCD140244 for ; Wed, 10 Apr 2024 13:36:58 +0000 (UTC) X-FDA: 81993722916.29.E8010F0 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf04.hostedemail.com (Postfix) with ESMTP id 4D98640005 for ; Wed, 10 Apr 2024 13:36:54 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756216; a=rsa-sha256; cv=none; b=yf5Ox5k7MEHC2q2qO+QOi5ol/S6QyAuIXIy1IA8DVLSHJ+w1M6Fw2Ezjqh+mpRoiIz7kaV pKlnGEhPKCUcJZaDlWLpHDH5yP+0PIrzzzboYDia1GS/OIMLfd3iS1QAc2h5QutRWf7wGd 7pA94CD+56jL7QCj40UhqAMSn2dVCUM= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; dmarc=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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712756216; 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=hXgBZtDkZNTkpL9is7a3dtQKT3/31X9934ixR/hsk6/Xedwqnc3zl6VrRuO6uWq2n/IsZw 4CO/xT7MAA1u5rHv9DSpp6D+T6uVXIjgY+ULxGez6m8CNbKoC9JZUfmGZ9762iz7+G/gjJ zUwHHTjAlepOtmJ71cxVWYmyXmsquyA= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lG2m46z4f3m7f for ; Wed, 10 Apr 2024 21:36:42 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 0E0C81A09EE for ; Wed, 10 Apr 2024 21:36:51 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S9; Wed, 10 Apr 2024 21:36: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, 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 21:27:49 +0800 Message-Id: <20240410132818.2812377-6-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S9 X-Coremail-Antispam: 1UD129KBjvJXoWxtFWfAw4ktw48Cw18ZF15XFb_yoWxKr4fpF Z8Ar18CrW5Xw1q93Zaqw1UXr13Xa1kGrWUGrZIvw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J+UW k/ukkHrUaZGbrCtbf3xLHyhm8Rbsc8y5U3nnqDSfJ0wJeP+UXWvJJBHU1EzuxJr4gpWB3KtHAG2A+nnoUgKzi+T6rXXfcPuZkSCLZg33WKB3BsYPgaMSB/rj+7ThnARX/5YR1DgmJR3T0jqEc0FVl8XDR3q8fnV3P3it0dhXYiJsa480uspPtYtnharszKoF/CvBR4Xf0lDSSfRiVgWRYk5spafSrmRkI5tMqJ1nkvIGPZfzRl7adtiXVvo6a2Wa8qelVHar2E46K4AZAPh4r+FRUKuMhRCBoogeeZjJjM7Ajdk8= 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 13:27:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624540 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 02C09CD129A for ; Wed, 10 Apr 2024 13:37:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7D2C56B0095; Wed, 10 Apr 2024 09:36:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 780946B0096; Wed, 10 Apr 2024 09:36:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 648EB6B0098; Wed, 10 Apr 2024 09:36:59 -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 3C5466B0096 for ; Wed, 10 Apr 2024 09:36:59 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E7EBB140654 for ; Wed, 10 Apr 2024 13:36:58 +0000 (UTC) X-FDA: 81993722916.28.3DB3FB3 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by imf27.hostedemail.com (Postfix) with ESMTP id 6F14B40008 for ; Wed, 10 Apr 2024 13:36:56 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=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; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756217; a=rsa-sha256; cv=none; b=4tNiNc4YQiBY0Lh+67P67iielmG7ENoYCilEshmqv+y1kYMjr7YIgDWSa6uMVQkH+gCHps FYEAXqktMPh+z3fes0DoEo6uuxDIYVykB4vrJtknYae8WpjsbHST0RGP1AV69AHNdUtaNL WDed7TREcsxASsrWTBr2BDQSKuYkU4Q= 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.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=1712756217; 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=esgEfyHo84+rLpEGi4dxG8EAOaxEHbTtwHK9si/kuunTNRuP9M1LfG+cVu+wyXS0xdV/uM KLhogOVryGZVDNVT8NmilVfop7AVvbwBhJZ624xMoEukfg2ZeKaai+joG79ebzDgvGInT1 UytO/PuFTXP5a732baoRXwGuSukehEA= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF3lJ5xG4z4f3jHf for ; Wed, 10 Apr 2024 21:36:44 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id A8FE81A0D6B for ; Wed, 10 Apr 2024 21:36:51 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S10; Wed, 10 Apr 2024 21:36: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, 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 21:27:50 +0800 Message-Id: <20240410132818.2812377-7-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S10 X-Coremail-Antispam: 1UD129KBjvJXoWxXF1fZr4DXF48uFWrAr4kCrg_yoWrXF1xpF s8A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amAUYfbf0L4LnJD42tkyCIaxv+gczu EB9WcLfv i024Vf19XRU76l//MiD7vzD/BU0oE2VVz8tl+/kjsq+3PiKG1ZY0f3zeK+gst7XK9K1kiTKP2iRmOLoxYFReE8MQdYLHY3GvVSETWEDZoxj8WAcivl8Ux4pKlMvnOP9LK8vC1BaO0niaPIACRiwl3BkR9/nBdbqTuK1Ql614ZPEznY4ksW0Kjo08FsK2CtzZ1sJ5VT3IJ/6w1HSGaf2ufkTBFkbTYPJnuljGKMh5HmxyI3AucLj0Zu36+DUIjT9V+OgCq 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 13:27:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624538 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 2C94FCD1299 for ; Wed, 10 Apr 2024 13:37:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A1A426B0092; Wed, 10 Apr 2024 09:36:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C9C06B0093; Wed, 10 Apr 2024 09:36:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8919B6B0095; Wed, 10 Apr 2024 09:36: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 6D0376B0092 for ; Wed, 10 Apr 2024 09:36:58 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 32C021A069C for ; Wed, 10 Apr 2024 13:36:58 +0000 (UTC) X-FDA: 81993722916.21.25A1066 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf05.hostedemail.com (Postfix) with ESMTP id C73F210001E for ; Wed, 10 Apr 2024 13:36:55 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=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; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712756216; 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=hl2GTHN3eWa7fTBXcLa78LLcVq+wXmCFpQfBJ/GP8yKQ30qEsOMlvN7snYQ1SE61M5o3uS wJ24gn67Jfp2aEFAJsLmIi595+DoIs04bez11yFRZ4MQh2mxsz1VoSYNuypbMDEsa+C1oV 78AY1jYVjRFPtacg32OIHfgfXBENL1Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756216; a=rsa-sha256; cv=none; b=yHpiQNZ5ccxsTIywP9qbbMydP73sj4UGFHhskmnSUN0UrhqVen7Qbf1m9WSmP517jaJtkJ SmHdA4WMpIxDBjfB7aVlC04VoNl92QJFFEABhhG9JIclIxmNm9F5WymYCpHnDQEh3y18N0 1CRmw/xNh3Diqish1H2kaDpvK72v4cs= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=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; dmarc=none Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lM6SFrz4f3jpq for ; Wed, 10 Apr 2024 21:36:47 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 4ACAE1A0568 for ; Wed, 10 Apr 2024 21:36:52 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S11; Wed, 10 Apr 2024 21:36:52 +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, 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 21:27:51 +0800 Message-Id: <20240410132818.2812377-8-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S11 X-Coremail-Antispam: 1UD129KBjvJXoW7urW7CF45JrWUJw1kAr1UWrg_yoW8trWxpr ZxGF4rXr43Wr97WF4Sqw1DXF1Yga10q3yUJrWa93W8Zr4fJFy5KF1qyF1rXFyrKrW8A3ZI qFWUAryUCF4jka7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUA rcfUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: C73F210001E X-Rspam-User: X-Stat-Signature: se6sdkpjmimkh7dmmziauqg9ta47eios X-Rspamd-Server: rspam03 X-HE-Tag: 1712756215-874771 X-HE-Meta: U2FsdGVkX18HI+fuqqw7zUcggx/jFlENXTz4gFcPMrBJRByhNzZyNmd/05xxOpD50UMy9g9mkxvXcB6iTy+m6TVkGs6cWfUBB5QzF+DdkipxFlPYe92FHSga7fZMFWpgoEZv1pzdUcByY5fGRwNv0j6SuvHB5AG1fVtqZYRZ+jUsIsnYCw4qDg6DoWxWngcCz3devRHddkEzjRoUNCig2Neej6qvd7UNrT8czfqdHyxEYFXgplOIQ1kjj0FOYtUSkgU/3T9FAgVHLGYtvj1S2J9zonOyTqjv74h05KNpivKOAV/ROZNhN91QwYTTKHTcivvDfOGyAv3VZ8ndE6jbwb4SvE7m5MIXZDVmT4QNAMfzzyI2vkM1El6tK+yBgYNKQ2cnF5/S1KySox4+7eZtlrqqlhR3EiYkhV9fPZWPgOKFCKVcjI27K1OIS5VwJpPAHtbQR7mwuj5HyzUwOfCLQjLKBItyVXUxrTp/1RX25VIvk3yH+UtmIG9BubfE3OsxAzMNx7Nr4724si2u83rOwrAiKClRZfM/xClXPmrDCqSGLba5j7IFeYCR+NyA6LD/xYBv9jNhodiMceN+7r9VPWMvMkCBj9Tlin99zefcgduwGgTC8BX9yzuRc1u8B8gnparmZ9AcgEuSz1BwDuNm3d1XXDiGKFc5aqg/qxNzXcgsoQ3MxRpnYwmCW4RZBWXgc/FliGu/rVR5cQ1Fwj33/pB/LvoMzYfSZa//7+OdrdwB0O6HUNlPPbpAeII2ZwQde0tKYsfzAwJGU4aKidQjpXV0OWKfnMugpavj2AmaY0Tw1GDeEctb5zK0LBCQ0jsCp0f9BGhkCarXovZQ0vnE6znl10NXZBGbzDuXbPHM6bRopb/ZUSU3mNFx26FCN5/BblnSrQdvXJcARAakbbyfIrzbCFsyqizwogMgAsjtQM/i87pVhiORNf6D5T46RxkpX+vSGcVMiUM2vJCTuY+ 0CF7jjT5 SmpgiMf2lZEqkbQb0QQ4IPFHdXkva89I9Qiq1R0j/UFl7iTlG++dQrzxfKFAmXiwUz2LsSBgPxQxOiwdf8pRmzbpm7XeVpr1PzPmU9Euxf4t64YV+zqPxScxhxyCjeXXoy/jbKv//qoKSfluZeTVPMDyO4PHXbaBjwJRa+dex5gFeEKnTFueXpldU9jdhDhyA26hAthfxW3MdV9zM5Y0loCl4/DNUA2yDriKGNAdwY8zp1SlR65z8UYM4SxCooGexgkLZ 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 13:27:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624542 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 AD3E0CD11C2 for ; Wed, 10 Apr 2024 13:37:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 089456B0096; Wed, 10 Apr 2024 09:37:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F00046B009C; Wed, 10 Apr 2024 09:36:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C8AD16B0099; Wed, 10 Apr 2024 09:36:59 -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 94E7E6B0098 for ; Wed, 10 Apr 2024 09:36:59 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5BF63C06D8 for ; Wed, 10 Apr 2024 13:36:59 +0000 (UTC) X-FDA: 81993722958.22.CCE5261 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf22.hostedemail.com (Postfix) with ESMTP id 10B1AC0015 for ; Wed, 10 Apr 2024 13:36:56 +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=1712756217; 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=tX15oH9jDWAh9znLKlI6OWWhlLuS1+UZ6C+0BgiyiR8gonfkKOk6JaYsY6oimZ6ucvGfpa mGZ1BUmKmg/aLox5sspL+TUKVBr2R24nYjm4NsJ8BY1KLMzJYDBeKVaNAMZJ4TnUWP7Izd qk/WE77WqfnqnyIvcuoonGJ+QcOq2o4= 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=1712756217; a=rsa-sha256; cv=none; b=g2Xi2J81f9DuE7gOhMG/5t/SY9y8rVqLVxiDVmj7pA4miAH/zzaf57u6t92RXpyOmX9pzv BcKBxNaR1mhSCZdiq0PAXKW4/gCvQ7R+Xhhx1VDB4A1eiG4fe8Q/yUmjvlPD4xxWBRzhvc 1QqOgr676sldEZ9pphY9/4fDKkOWNKA= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF3lL0KyLz4f3khM for ; Wed, 10 Apr 2024 21:36:46 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id DDD211A016E for ; Wed, 10 Apr 2024 21:36:52 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S12; Wed, 10 Apr 2024 21:36:52 +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, 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 21:27:52 +0800 Message-Id: <20240410132818.2812377-9-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S12 X-Coremail-Antispam: 1UD129KBjvJXoWxAw1DuF47Aw48XFW3ZF47Jwb_yoWrJFWkpr Z8CF1fJrWagr92gF4Sqr1DXr1aga1ktrWDJFZIgw1rZrWfJFyfKF1DtF13XF1SkrWkJa1Y vFW5A34Uuan0ka7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUA rcfUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 10B1AC0015 X-Stat-Signature: mrzysf5rqzaj7shn94ygu1k3kh736gyf X-HE-Tag: 1712756216-789420 X-HE-Meta: U2FsdGVkX18OmyD7/oWndKyxWCa2W+67naplWk5qPI92JYfqeVqn4OoiPICSyvQsTTUxeZl8MZ2WeJoo2L4K2eJUFDnGrSG63H/kBvBvd+B/4m6QJXMWZpR47wXlZM8Tv+AvHHpHpvKRfV2jaWZ0w1oXyFIDldfau5xBBv7Wzi/ix9XfKf+me6SZohQRXYidVSeC0LxpljmGTkrUj/0bOBNTtK5WuhCzbdbYCYLm5dtOAcfFy7Y0DbfegQO6znHnlEUJnteKg43aV7yMX1TZkrlqt7F03WRzHfh16xE3H7FGlpLN61TOqhP0WeYUrQXR3FdcBgbaVxDaHMgRIEolChIDJFqRhSXwP7rxM77uTj6jE/pQMDnW3rt3/JreU/ItXVE/52V8X141JrgN4MPKLBjz6H4Zyd8bNDGfZn9kV6NVZ5ywmBWdTTYqKg1XqEzJgUpB+wZERDO4wMRMldMcrxFHAJSKvA79j5KpG9K17Jw8uTqkdYeKgEjvepjjrdk3FHR1OCTo75QeSAJ+blbYpsv6abAtGTDr/XQC9vhIwP385eQ1Q2SAUeUQdS3dqRzRb67/klR61KfPu1PWrp9l/sr7MwbwlWyB2BRYZZttvNt2Aaw0IkvHFGfcJDkA+oWLhGSd6Yrq07XOChmWtWxdeLAy7dHd0YiXP4Rzud8x8Ken4rkM1aplnvYlDZC1Zuq1mcBx225+1Yb0nsRPvPYn/ERXZeSGZKveqQ73b0BRqxxHNMZpd0aqc2eWz9yBwtmsYhme/q867w00jaqUDRvN4rFLLQp0tfmmRAfsahS+bPzEsMSJqxKGV7gVeKNwyEszYWEy3+qRm0Xp/eU4fs625+iqCk/Wx07CGpexx2ctjpHD4UolwHLLmdbanwhT4tOsLUT3CU582Bj3KUhyx3d9qfCkIp6jHkFdWUFmHTQ8yjdnC7mu7IDVYEmoKbGrn7Lx9UECcbyCZQCf0VE9V6l 2T4SzVBJ Hw1qEUPu+Jg5f5G6CI+gZXXyjwjjZVo8eCE3mnFq8ChEGFRJt4emc3UlFTw== 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 13:27:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624541 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 5C274CD1299 for ; Wed, 10 Apr 2024 13:37:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA0626B0098; Wed, 10 Apr 2024 09:36:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D03116B0096; Wed, 10 Apr 2024 09:36:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B505B6B009A; Wed, 10 Apr 2024 09:36:59 -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 978376B0099 for ; Wed, 10 Apr 2024 09:36:59 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 60FE41606F2 for ; Wed, 10 Apr 2024 13:36:59 +0000 (UTC) X-FDA: 81993722958.17.83F403A Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf23.hostedemail.com (Postfix) with ESMTP id 01A58140012 for ; Wed, 10 Apr 2024 13:36:56 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf23.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=1712756217; a=rsa-sha256; cv=none; b=i2NhUdGjJqXCmjaVDv2uHBiMkHPnLfhfgkPL+NnjmK2TX7MisaEzR5BPJSpXsSQlTWPeWy 9URu74bKVfG40oSaPxFWVbfms3LP2H076TpEjeOxI8sgJTN+cjAX4ljZysHkXd0cwKWRMU vHtgVm02pZzrB9M0WJNF6f1g33dZBwk= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf23.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=1712756217; 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=hoVd8TX3djmtYFhM1CCmI1O8bSqHWoY9b58lm80KazLRdvE6fZNgpG1pjmeyW2LbRGHnaM 2sQAlorgux2U+gW4N8Qm3KBaX4rdhpZLEXomBzFWW61c2ToexgBR4Mkpw1h8dBp7pKIGlV nyAK7AMc4XmvP7K43U2j7jvhp8KxZKM= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lP0hRrz4f3k6V for ; Wed, 10 Apr 2024 21:36:49 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 7FA9A1A0175 for ; Wed, 10 Apr 2024 21:36:53 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S13; Wed, 10 Apr 2024 21:36:53 +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, 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 21:27:53 +0800 Message-Id: <20240410132818.2812377-10-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S13 X-Coremail-Antispam: 1UD129KBjvJXoW3WF4kCw1kAF4fJr1xJF1xuFg_yoW7Wr1Up3 93AF1rGr13Ww18ua1ftr15ZF1fK3WUtFW7Kr93GryrA34DCrnaqF1DJF1avF98trZ7Xr1r XF45try8ua1IkrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUA rcfUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 01A58140012 X-Stat-Signature: bwdcjeedir8is19bkb7kz689cndw9jnq X-Rspam-User: X-HE-Tag: 1712756216-334269 X-HE-Meta: U2FsdGVkX18004qvyQEay93mluoE5HpUcJAvWd7xBJTS3Y7rRLDmSHsf/GCnLC1/mGlLl6XViizxdKu3DiQxUNah6k2iAVBKB8nvG8UP1gjHfuRbojX9skwpTkUzJMnqLx+QM5Qqr3yFUxx+J9FE7Nswp+Aha254YEOh7WLQSaMFH5UK2J2tgzqnFPVyLQ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omyFR0d8jwsz5Au90NL63SRU= 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 13:27:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624546 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 2CCD1CD1299 for ; Wed, 10 Apr 2024 13:37:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3DD396B009D; Wed, 10 Apr 2024 09:37:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 389EE6B009F; Wed, 10 Apr 2024 09:37:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 202286B009E; Wed, 10 Apr 2024 09:37:02 -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 06D036B009C for ; Wed, 10 Apr 2024 09:37:02 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CD0E2A04F5 for ; Wed, 10 Apr 2024 13:37:01 +0000 (UTC) X-FDA: 81993723042.09.97D2EA1 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf22.hostedemail.com (Postfix) with ESMTP id 5A17CC000B for ; Wed, 10 Apr 2024 13:36:59 +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=1712756220; 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=og/0yj7BlrmqQlW2CHtSZoF7pnSwBscPOcPEBTlpbYpHILTsr9n4RdEjX35uOd7IhDLW8W 9qFtQ7v9qVylne57M0BllBd89wScpiMy8+sV+xYlEqNlTt7uGUdCbfYEu8tBtE8QnCSXlY sScQIRAWE95IG+AMY5+TRaInXXgrIDU= 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=1712756220; a=rsa-sha256; cv=none; b=49xTVVS/NbAhYs5vroeLw0myR+0VE9kuEBoZplN15oeaiV7JLoKw2fdy0IrQD/xULwxFc1 9cJftE3St9ue2UwIY7sikUfRaXIGDVsgwRzQ8pit71ax0g4HWspic3oiCf50KD2EUpyEi/ vXNVkmsSl383tnm+1jmNoc9KWr3DNM0= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lK3T9wz4f3mHf for ; Wed, 10 Apr 2024 21:36:45 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 269671A016E for ; Wed, 10 Apr 2024 21:36:54 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S14; Wed, 10 Apr 2024 21:36:53 +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, 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 21:27:54 +0800 Message-Id: <20240410132818.2812377-11-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S14 X-Coremail-Antispam: 1UD129KBjvJXoW3XF17GrWUWFy8Jw4kJryxKrg_yoW7Kr47pr WfCFyrGr4jgw1qg3ySyr48XF1Yk3WFkrWUC3yfWryrZ345CrySyF15AFy3JF9rKrWxZw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b05AzuFCO3fMLh47egfKCUkFVaeon/onlddl3qH7SOIUS125wzQ2qRBZWZNXM1il50miQWlg8rmH1R5Bk4by3gIfiCCDwth0S0NDpuEDruyQk3Q8+wB0M/4k7lf8MO3I+6aULp2MStEx4kvH4XhORl5QZ762qpTXZh7bX/KZUYt5rq20u+WtwaX6UGZgGwyTlYQytdTrmBvkA19MUXXD4k1OPwjfquRnnj 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 13:27:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624544 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 38803CD128A for ; Wed, 10 Apr 2024 13:37:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 428746B009A; Wed, 10 Apr 2024 09:37:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3B1586B009B; Wed, 10 Apr 2024 09:37:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 278026B009C; Wed, 10 Apr 2024 09:37:01 -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 0D6976B009A for ; Wed, 10 Apr 2024 09:37:01 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C0EBA1206EE for ; Wed, 10 Apr 2024 13:37:00 +0000 (UTC) X-FDA: 81993723000.20.C361592 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf18.hostedemail.com (Postfix) with ESMTP id 83ADD1C0012 for ; Wed, 10 Apr 2024 13:36:58 +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.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756219; a=rsa-sha256; cv=none; b=2jO07HHfLlydqyq2LsSsaRtu7Qjv5dMpyAicgQg8blks5Hs4mhZgWmVG6uOsRpj6CKKa1l EXrHkz4S4WtcdQB4qjdLyE0uCXjfa6D7IAf6lIAaRs92brlAVikMH4ORud6F05aealN7lW e/67IhVgDQsC6JkOCffetpKP3+A7aqQ= 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.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=1712756219; 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=6dX5+YGYViML2npEIJ/9k/a5104vCxCqMNfvn5mVR/nBOeLw5crWFLDTxCPX9bcisj7xGi EQ8tebXz6XE22u5e8QSi4CT9VRCAXNzYp0p39xeEa6ddnCvWl/kbwLjDww92ZL+owPaoFR +GCdd7e/a/dAdh8GeS2SjEgpMAl/MJc= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF3lM6Pwpz4f3khl for ; Wed, 10 Apr 2024 21:36:47 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id B96EB1A0175 for ; Wed, 10 Apr 2024 21:36:54 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S15; Wed, 10 Apr 2024 21:36:54 +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, 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 21:27:55 +0800 Message-Id: <20240410132818.2812377-12-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S15 X-Coremail-Antispam: 1UD129KBjvJXoWxZrWUuryxGrWDCFy3CFyrtFb_yoW5XryDpr WfCFyrGan2ga45Za93Ww18Wr1akan7GF4UArWS93yUZ3yakryfKF98tFyrZFyxKrsxZ3Z0 qF15u34xCFykCaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUA rcfUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 83ADD1C0012 X-Stat-Signature: imuexxnr9qxfpgjgrf57mb5jwj8xubn4 X-Rspam-User: X-HE-Tag: 1712756218-152429 X-HE-Meta: U2FsdGVkX19GbbDDNskL0eIMVURF48ZFWomiJi0fHvcjW521+Q6j3tfSqskAWZN9Oh/XaBOCBTtHgKmVV4f3dybxr6DlaXrqYSN1/7P0JBW0kUdBoqyi2lY7Scpg0x01E+MGXzTwJ1vVBWgNCIhGHH6CGaFg48koTadqj1J+0iXUvWk55dtJPAqB2KrbPHQUpgGsnOXG3TmcSZBaIRVDtNm4mLna2qFo/sai1uq35kEd0kdJt5VXlkT+Iv3KKcBVE5QbTkoHe7OvGr2bX+5pT/Y/VC4fFzLTsVo0AnjCc9tVG6bgAABz2K2cXSE7Cc15RK+Sv1bY4Fi2V38qgtF5ee/KVXCQ+YiJhzQIkR+3w1VDDQ8aOrvbe1n4PhctvxDVFsGg/BmteleKjmFJWEFrfk5vU2npYdw3A4n88TLesewccNT46c48x3Xz+OG+zjuwD89B2ejIfRKMu2VLI7caPRR1Wsml9CTHB9eDKsVTm/ZLWic6fKPXGyU448TI3qIrWIr59GvZMSlOCc5mqwXVn8p9PAhAfPm9/KCPsBBNAZG6bsFitv/FqS/qe4vtyJgaEuoy3yNfecxdaMAIheXqVkgNqiWg3sUL+TUMpCgqqicC+IuBeq9p76Dpkg4iIRSDJxNWzcGDT98nK+oAO/M+w5PBZjfEwsXxwzdw9xvMLj7JlSV49diciVNVDSv7nempKeqJnkE+H7T3UI93jeaGTCYtxe8xTNAtTOWC4JDcS47p+Now166bMkYNiopO1yshsiSuIoUqLc13BJjj04OseSZ/c00Q8pkR83d0KHupEjtLDMYZqCttuaHNNQu/K4xi7OrQnvm35VCf1CG20vwT38GE7tzYQIXlap4jfOSqr77EQBj4Q1nFtbDh8hlgEVtCx/UrrjnILplmLdtagCpTg3nO7Cn1vlatvMTxccJjvDq5roKzm75dukvmtQ/ZjZqffXEx2XQKKqOwxwWf2s2 swZt8LsQ OgQXWvWJCVR2VnrjMiaBVoenTf1I1ji5WydbbzcFAG0jYZgorFFuZFD4S3A== 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 13:27:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624545 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 7C6E1CD11C2 for ; Wed, 10 Apr 2024 13:37:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C18186B009B; Wed, 10 Apr 2024 09:37:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BA22B6B009C; Wed, 10 Apr 2024 09:37:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8D456B009D; Wed, 10 Apr 2024 09:37:01 -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 8C0766B009B for ; Wed, 10 Apr 2024 09:37:01 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 55A8B80321 for ; Wed, 10 Apr 2024 13:37:01 +0000 (UTC) X-FDA: 81993723042.19.F9E4A84 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf24.hostedemail.com (Postfix) with ESMTP id E1B7B18001B for ; Wed, 10 Apr 2024 13:36:58 +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.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756219; a=rsa-sha256; cv=none; b=O0p+MJ1W3zekwJjFjKLBt+simMx6KJ5oJrUjWJxdR+VMGabUlKV2j7xBaQN1Nh1a7c/7jS AsN3LRBNWOu/56oeT7QxKZSoqCt3dbxvFy+amuAFt6h4ldjfowmzkZh9GHw3Asxip0viCM BESBxrCmqWn1xpTkwnLEAmZ0GthbNLc= 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.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=1712756219; 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=ec+KTPKhy417WlQ9GMdeQxWoyCMLF3r9csQ0Aia1ignAji9vz6utGTsbN1xHfkzv7L62/1 BtSZRBJMYXmibkbkIFtGYEyd2KW5jzlPHc8H3LijRnVEhSfKpx9d14rVacwm2VvYDXjSDa hJRK/R39e6ZtSnlgc4cgSEPACuTz/Ds= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF3lN3dZfz4f3kGJ for ; Wed, 10 Apr 2024 21:36:48 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 59A581A0179 for ; Wed, 10 Apr 2024 21:36:55 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S16; Wed, 10 Apr 2024 21:36:55 +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, 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 21:27:56 +0800 Message-Id: <20240410132818.2812377-13-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S16 X-Coremail-Antispam: 1UD129KBjvJXoW7ury7tw17uryDWrW3uFWUCFg_yoW8KF48p3 sxAr1rWF4UWw1UuayI9r48ur15GayjkrWDur4rur1rWayfCrySkF1qyFW0gF9FqrW8Z3WY qFWru34DCayfGa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7Cjx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gxVgyWydzT0uD+R3i/bnwDef7f0rKYm5WzlaNw2UiiWYAA6fyHOp2ZkpWF5XkHMCt4FHG0P1eXbLr3EIItJz9xS95cPL4uxRJhK0lppkG+wxpft9HD/AcE8qy8wIE9qHDFFZsxECzfO5Z2w2s7wTy4qpwIebFh4WhdPcbyKnVgSH1nbPhyT9b7fehk18xQjKSrDV4y40EjigXojY5GqVTx/8Q igJZx4Tm CmHkhu2VJgqioUVQUl2niDVrmFaM3kyP/0zdIUpLZOHQY0qKdLWPnnU4y8QmLM98hA14cOsOfm/65VOPPi6mS7JUudtc7ux7E/PmPUv4uCFOuNo1plAE7l+D9Yo+lHqnA3FHb0YvkCSFV7UzNOzUWo/lTdkH02DAR0nZ1xyYxcuoul8jem7rQFDklMExG0bCdxVPPfU+ycw0Ju61KDG+SfmHusc5wxQZqWSGySESojsBZV+Zt1LJEf2OnMOXAhyjVWMVmH0Hms1lDU2X2InB/G0PljB7+zjlIhZ8Bo2tPdF7plChBdlvNzo2voYwYPllhqevVPEh5VLdw6NfsXh8RHOeNPQ== 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 13:27:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624547 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 E5F80CD11C2 for ; Wed, 10 Apr 2024 13:37:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A9E36B009C; Wed, 10 Apr 2024 09:37:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 75C9C6B009E; Wed, 10 Apr 2024 09:37:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 586BD6B00A0; Wed, 10 Apr 2024 09:37:02 -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 2E87A6B009C for ; Wed, 10 Apr 2024 09:37:02 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id EEC0CA1164 for ; Wed, 10 Apr 2024 13:37:01 +0000 (UTC) X-FDA: 81993723042.29.A604A7B Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf19.hostedemail.com (Postfix) with ESMTP id 8A8B41A000D for ; Wed, 10 Apr 2024 13:36:59 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf19.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=1712756220; a=rsa-sha256; cv=none; b=lIcUVJDU0Bot5gsgXFA+CLP2ytrIalJv/pmX00fxubDV/tQ7ctE/So+iTv5ivLeQlTO2Eh Z7UKtvhSN4NphXHpsx8MrSZ/shKvSVYlqG/4PWo9VIR4Evw4sntlblWRSgKMA5cpqHPE8G 7vAE+/5JRg18w5UZsftfnVgYnukB37s= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf19.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=1712756220; 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=h9bCBB9D0c0S8LXC1YTro2ukoYubDV9FfSr2GTGFZEHKYJNgC7ODURF1KfsBqsjd5WzZ6Z YXbp9/Q4cC6XidblZs/vmIERts7h5vpsn62+l6DDCqpjOk1rqPamvSTAvUrqzmducH+FZp DSU0oaY3MqQxu7jZ1f4tNvfGzeelsRE= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lR4GDLz4f3jkH for ; Wed, 10 Apr 2024 21:36:51 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 045231A016E for ; Wed, 10 Apr 2024 21:36:56 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S17; Wed, 10 Apr 2024 21:36:55 +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, 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 21:27:57 +0800 Message-Id: <20240410132818.2812377-14-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S17 X-Coremail-Antispam: 1UD129KBjvJXoWxKFyfXw47WrWkWF15AryrJFb_yoW7GF1xp3 yY9as8CryrXw1jg3yFyF4UZr1Yg3W8JFWDXrZakrySkFyrJFyYkF10yF1avF1rCrWxJw13 XFWjk34Uu3WUKaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUA rcfUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 8A8B41A000D X-Stat-Signature: r8ddt13y37ks719si8c84abs1wkzowji X-Rspam-User: X-HE-Tag: 1712756219-958022 X-HE-Meta: U2FsdGVkX1/yfA+gXdvyQbMFNhJeodf1l+p1Dcx//ABPUqsgZ1ZUmxCInqhc4lTzMnQjA65AXeRgRiqY2ayklJAyOIxD37ppt10AOZM48IHRh2LjRz1s2DTT5JSJEpqysSoRP5qkral/A3VjWNAHtCFKdiaeFMmy51WBSGeGDjaVGiWv79efDg4pOtD/8yAnmhRTXQCdGodmyD+3CMFyt6zzLwMZJSsGkDXarnqW1dku2d0QypjtRvgIKTOJd/ukc7BiKreGpPmjYrVw6AyKZD1oYLsKM2DANNSfbB4wcPfCaVOBDdCfhqpBD9dHQA1J/YoSgv6VP69d77uXBt6/4KmB8y0glG4OqE5sgiB10s9H+sbWAlv56E9nQ0pEWwITTlvmZqjHxSKbOfg+8wb9oxky4LmsoYqehSGoUaMJ3a6mzfTBO/yeRChEjXCi4ziyR9AZXyjX72I+GSXn8aoReTgLRp+x2i4ufJbbW7KrTVQUg8i6iTVsP7WUpRY7mbX+prhcKoaPo6GG+Y4iM1zNlj9QgSHSIJJA2RaJh1Reu6mJX4OEjxn+Vii0+bp0uj+wwdGtMu69oWJvJyhuztTJMU8Cci1kV1zlPkucWj5eoTxFHLH+ymg3rhEZmgEJLaqc926mphEgnXON2fZdhkYkcwdV/yN+wLHQuEeUKshWXsYuTVwqQU45/u53FzIHt/A6HZ2S9tVTyQXInTg4ldttK3c56OzIunxxgFLUVBcizmI6zfC5HySUf37DsV7KFlqCvF17V6RMuY2pWOnJzqnSm2ARjCFCRHKcJYFbxiwg+R7yYmv484RVDZMPV3wQ640uX5Ntzjpvz6rqtVSOOGgjfwsbFflHkXtnEJLaU/FFGet44sd7Xm4pWmUm2aDSU4la3RqnI8U02EBkyzNW+cPic5OM+0XiokEqr3G5cj3FAMTIuIe80eTeiqRu1hL+HbyWV/SaYe0O0olnQe5oASn WKXFFd0F 10FNqusSth4mZ5+wNZR6kMzRyoRDWCxsZKhumFkJHQsotrEfmq32MlB596za9BTeukVPDB2DKxdIo3gcvQOyqFeGlkxURnV7fH392adBxOcvX1OEl9OjCysCbphT0AVk4MRs7hIhGFksQzJsYxJfbM6DZHie9voFYHxWmyZvBn3keaSLE/LIeC1xGMd+sWcxaj0pLnP5KL3fafEW4J/vd3Jzrxmtn5UqEgCJMd+KqH4Y57a/9lsJeA1xrlx3/FAdxF5o9 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 13:27:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624548 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 1A49BCD1299 for ; Wed, 10 Apr 2024 13:37:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 542356B009E; Wed, 10 Apr 2024 09:37:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3624F6B009F; Wed, 10 Apr 2024 09:37:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 166176B00A0; Wed, 10 Apr 2024 09:37:03 -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 EA47C6B009E for ; Wed, 10 Apr 2024 09:37:02 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B7C3180321 for ; Wed, 10 Apr 2024 13:37:02 +0000 (UTC) X-FDA: 81993723084.18.D3E7B20 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf11.hostedemail.com (Postfix) with ESMTP id 5AF8540013 for ; Wed, 10 Apr 2024 13:36:59 +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=1712756221; 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=YkjF+M7kmT+g5SH63TPj4zOc+6K5tlkTonfjyoPK/upaqSCXxEQ2/TcUJC0F93pr5HrnNG fzR+FfgMIx+OxLbzMJOdWXP/93fKPS7jW0dGgKsgASL2bxkUk2X7EuuEfBk9dJ+Tv0ret+ Zs1qWvHbpM5jlIEIPSm4dERthO80qZE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756221; a=rsa-sha256; cv=none; b=AnsPJvOXQ0CPlo/WQnqDusl54F39nvwbKEnmna2IZl+Hjjc2Bfk89pw1BzQP+u898p3Rd3 F/d/NBHqyEjGSvgR+ZKvZEBjdqL1lGO61+ENcYfEdujbufWsOgP+9AFXo/++foVFXXMMHw jw2doJdpiTughYQLqPlQKatTmJnw3RI= 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 Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lS1KnPz4f3k5n for ; Wed, 10 Apr 2024 21:36:52 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 94EEF1A016E for ; Wed, 10 Apr 2024 21:36:56 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S18; Wed, 10 Apr 2024 21:36:56 +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, 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 21:27:58 +0800 Message-Id: <20240410132818.2812377-15-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S18 X-Coremail-Antispam: 1UD129KBjvJXoWxtF1xKrWDWry7Ww4DCF1DAwb_yoW3XFyDpF W5uF15KFnxZ3409r4ftws7Zr1Sga40qayUJ34ak34ruF1rtrySvF18CFyavFyrKrW8uw4Y qFWYk34Uua1jga7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUA rcfUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Stat-Signature: cfy4ctz44m13u3u4i5g1jhbnhf1en16d X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 5AF8540013 X-Rspam-User: X-HE-Tag: 1712756219-811828 X-HE-Meta: U2FsdGVkX1+3LMaZYYpvfNxeGFpHVenjIoHzLICrMVpdX2YS6xx4T63bXL9yqMlSchuK+K2Q37Swed7J1yh5OByR+ZZEu4IZ3vgB5ZH8Ccdn3OQzEHQIyibZJe4zh32CsV9KWLdJTTQf3AGd0psZDAnknyqKOis5/PLf5XMjTxSZvsDENGv4yx2PEfgWFSsSZK3TiPASwXn4ADDx/Ini8k11mcbHNxY/by2LQLRI8dVm+xzSayxwLXgJTAJje3LTzoq/TDn94I4yHfa4is+uwbtd1Jgj8xumF1ZGc5G6Lumk4+s3xM7/EQjVrVAQVn4h9E1pOCb0W5KN3tcrvFAuOxYLZjxzp8k/22+XVYNFul+Hl92zrdor5lMY5MPxHI/lgGq76uwggwsFpcmvAVnR0gl6BU+HBXwLPQqmi55dNSKsnt+T+Pck3uRxP/iJew+TEKeXmOCFl291m+2dFnVSiGg/wi/USicitEzGwFOx2w5EKWKEOBcYPEDFT8Ikzzgw06bOZxqxTrw+EhtXhPtfnVgeOOn8Lg9gYhn989e+xDUJ3mPhUhsEAz6bLQNGhj+4JYZ1OvgoKi+lZtAR8D3E+J/+pK9v7xSGPOrL44UlWkKWDoFPLyzh+Vc9uMYaDGLq3D98Bm2FN2z7TpDQI7kJr5T/5YbKoyBxIFP2k4Ph1x9vBKoBkLbSQ+L++N7zrINWOdGOjpBJMRf5r9YU+GoOCPH2zlIt7bSucrraLfNqlXMPKsjVfhJtrUPl9prhijsQycg/o04mAfHzVZvWw4cPyvBPcZbf5SW47+07XZMCHkAAGPfIVjJgv8eqTa5VO0GZ+tLD+L7tpHm+nj7Z+wtSN/4NwTIjxdhPzUEZATD7dy/6nGuCnYyFJKJZ/KYip84OtXq41t3/Izds4i+t1KmpjAz7QyGxq9chvdB2/Cx4XIKePOs9DoHMJQhBVb7i/WvK2MPQO6lxi+4IcKieSk/ T0RKlKaO TOFkCyajMN7grrIAH43WrUwr8/OsWuIAdg4MfIOO9AVMmUh5f9ru2NetUDjVAQGSGZhM7kYEtdFOhHt/YDuAlZOexEyPK37ybRkvCclLEmwba/sfbRNV1asgzwt9f8dNZRL1bMa/o2WBWyz96eFlvqQyG2kuxPUm31h2f6dvwLhgMKiTwzNMTo1EkGrsM0XuGDt1hBEZ0h7zXMrie98WaJQXmRYGQo/zBAHpW7X4md3B30CiL2DE7j2nYXdPaFX3Y2jMQ 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 13:27:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624549 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 27C82CD11C2 for ; Wed, 10 Apr 2024 13:37:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8E3256B009F; Wed, 10 Apr 2024 09:37:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 891D66B00A0; Wed, 10 Apr 2024 09:37:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 623BB6B00A2; Wed, 10 Apr 2024 09:37:03 -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 3D2FB6B00A0 for ; Wed, 10 Apr 2024 09:37:03 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0CADF12073B for ; Wed, 10 Apr 2024 13:37:03 +0000 (UTC) X-FDA: 81993723126.11.592C453 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf20.hostedemail.com (Postfix) with ESMTP id C50281C0016 for ; Wed, 10 Apr 2024 13:37:00 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf20.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=1712756221; 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=rPgpfUlV8q9YzLrDjg6pWgIupDlfjC+WNUi2jGF0/CmQiYu3EZzsZ3JpYvv1Pb4OuV2CDS gu121iajy3LULZn/fv1PZGRToWxTo4j8MvB7nXYd3bMV6fClYAfPEg042GyzU9nSJQd+dY f5QawD4bsc5DqRhAfjtYlbhQpXJz2es= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf20.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=1712756221; a=rsa-sha256; cv=none; b=Aga/5k51q7UnnuNkDPVb1FK1ygIg08E2b5D6xe6wREmP6ocAKeHEZzj5FziqtUAO/oV4OK MWzo4LC3vg1rEVn0n0XdwCUeoIiBJDQVpNfjnHU47rIyhREXDY93wYxy4pg6e+pKonzh8v nFiClc6JaVBoCeFnAPewTDB/5DyxSZY= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF3lQ2hkJz4f3khw for ; Wed, 10 Apr 2024 21:36:50 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 3839F1A0568 for ; Wed, 10 Apr 2024 21:36:57 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S19; Wed, 10 Apr 2024 21:36:57 +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, 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 21:27:59 +0800 Message-Id: <20240410132818.2812377-16-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S19 X-Coremail-Antispam: 1UD129KBjvJXoW3JryxCFy7GFy8tr1kWF13CFg_yoW7ZF47pr ZxCr1fJw1rXw1qgrZ3Xw1UWr15Way8Gr4UGrZaqry8uFW3AF1fKF1DtF1rZFWY9rW8WFn8 XFyUCw17ua98Ca7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUA rcfUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: C50281C0016 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 99zm9jke3rk5h6cxmbj6y8x3mf6kkwy8 X-HE-Tag: 1712756220-873876 X-HE-Meta: U2FsdGVkX1/DM1a5X9/gY/vxOfoPPIjL8bgxA1o9o1z0dhu75fQnyOkvNRzpYsBK+CDVEY16VOIQYRn7GBLMXWp2IGEt39Af45v7voh4tgQFttxicqkivX7ayUMBOOZRgzHxNKJcslU36Is7Ji9JPTh/Sj0MWQ06wdYTVfftMzaP9aRtOr2dj8dlUCkC6CtpWOE99K3pieQInJq0eXazytfsrPJhNJjZlCN+kcojpNpKjy/LzYB6RK30jHaC8G/fKPwnC3TxsARDr9e384xMWcjFmnY1YfxqoHE/z3NhDVEPwtOBtt0Kux/cx+ztirk8671B0O3dQqqH9SpbPRmz+sDzKMeTJsAj++cyslKIWZBmYZBiQs3++vxyKRVSYf51CiRpck4aWi+RVlqVtuISzedBvCvWryUrMdYRrzw/oemNxbpT8Ha490XGtDQ1VCcNiq8YXqu5QIIcTwnwgCOPewIZfdQDlJpai981cwtPdAh2ppKUUc3xrRx782gSn0//UY9Db5xJEnirEnLWEEX0gp4cXo8bjAOlqdUn7fJ4i2rg9/hpjPBwZY4nVMW7JLqdSDGl8PzsfVQRSWmadqs25+QS9qhhZLSa3J/tvwUsLioz4EhEl9SZ8U1tmkb5DTjsZsY13SxH3JSlw/WCsInIgCWjJ/yDdMxHtuULatfdCfnpATFna1UUWvR+fvY7Muw1zcs3le79SNNe7gutr9HtDjx3ojry30Fm2YEJf2u2fTanGEs1IAlksS1ZXM4LZOC7nmkKUqqk2hlWzFKBFoOl3yZ4K+NtCB7fFBRXfpZDr+p5ERxc6bCzhV+NMx4VyMepNVBG426Ej9sz1cRCUJAOq+fIY98Poe84Ea+HtF/QHCbRufyswIKR3r/jXvmTxabj8FWAe+Iw5alM1Mw6kko0ynk31D1zSas2vYYCZxJmNhlyR3iReFI5u1mOGLR7Mx4Op7iVl754wMOI7epC+Xv Bnlv6aX0 ebC6sCM5EkPrVN17r+XUGfac6fvs+vsoZk/fziFxOLIr6xFuNU6a1Dgt9qA== 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 13:28:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624550 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 4FE6FCD1299 for ; Wed, 10 Apr 2024 13:37:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 27B986B00A0; Wed, 10 Apr 2024 09:37:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 252A76B00A1; Wed, 10 Apr 2024 09:37:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C9DE6B00A2; Wed, 10 Apr 2024 09:37:04 -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 E08476B00A0 for ; Wed, 10 Apr 2024 09:37:03 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B4F08A0736 for ; Wed, 10 Apr 2024 13:37:03 +0000 (UTC) X-FDA: 81993723126.15.33E3405 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf08.hostedemail.com (Postfix) with ESMTP id 5030E16000B for ; Wed, 10 Apr 2024 13:37:00 +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.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=1712756222; 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=fOrDktD0E/1nr4//R8EIRj0+EMZ2UXPTviCdTf2kBLPyLGvAxUnjRpwFQArTh80MRgxfwq P0pwk47bo4+aQNM6o786IaggAdLbjo0qY7Ua2tlRwfV7DCxar3rCIy8eHAF2EN5Dc/WdkT Pu8AElaoWMTVCBhtvcJmfcM1kdGRjvs= 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.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756222; a=rsa-sha256; cv=none; b=BrDKDBDC3lZSSxR4oClQGPgId1HCRsVvliFirwmCQkw5YFd4uxvREec4GG3sdZajxfyjj1 fNtbN4inbkfjUt6JdXGLP3OqayY2wb8oc+K/0PFmiBKVYbdD/44ayAY/P8yucZdtQy+53R WyUyjQxomhJvafP5QaS76Ravp3dq+uM= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lT2tmZz4f3jkj for ; Wed, 10 Apr 2024 21:36:53 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id CAFEF1A0572 for ; Wed, 10 Apr 2024 21:36:57 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S20; Wed, 10 Apr 2024 21:36:57 +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, 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 21:28:00 +0800 Message-Id: <20240410132818.2812377-17-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S20 X-Coremail-Antispam: 1UD129KBjvJXoWxZw1fZw45Xw1xGrWrJF1rXrb_yoWrJFWDp3 43try7JrW3Xw4v9a1xtw18Xr15t3Wqk3yUGr93t3WFkFyrAr1SkFnYyryfZFyrtrWxZF1Y qFWj9a4UCF4jgFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUA rcfUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 5030E16000B X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 547ftc3f4hkisueai4w1pno3f5i97kte X-HE-Tag: 1712756220-757836 X-HE-Meta: U2FsdGVkX1/K8ds9nUiKwowllQ7uDi9IwOCYX0OzpRnEv85/ax4cC9dlAa4FtTBbyzctDJ0WfPerGyrhiGKBYZChgc6YddvV2ugfbLc9eJsCHTh/jiVfAfbTJWZKnlNDoZ63QbxC/E3ecy6MBomKBan+1Ax5WsMOatpaYVS56Y5ENzWGO3pnS9DuC9saAMEv3RqXqn64VAfda4hSu7xCgGIu/3IXXzy/unnitma/wV6QXosy01sxq3dSAEkBmYA7c+41QA9YC46AwWL0CuU3NF92taAl1swGu0ZX4vN7gIYg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.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 13:28:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624551 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 15BEBCD11C2 for ; Wed, 10 Apr 2024 13:37:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8205B6B00A3; Wed, 10 Apr 2024 09:37:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7CDB46B00A2; Wed, 10 Apr 2024 09:37:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 587286B00A4; Wed, 10 Apr 2024 09:37:05 -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 3AFC36B00A1 for ; Wed, 10 Apr 2024 09:37:05 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 06C5C80693 for ; Wed, 10 Apr 2024 13:37:05 +0000 (UTC) X-FDA: 81993723210.27.F623FF0 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by imf21.hostedemail.com (Postfix) with ESMTP id C29D81C000A for ; Wed, 10 Apr 2024 13:37:02 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf21.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=1712756223; 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=ilM/HVTpXEBO9TVP0nn/GccNrRHCoPt0ucUuMKUeNbm+houy2G9w+gZl4fS3uhT5JoHj+P c8K7O68Ny4wxh+IAu1qh49jADhvyBbs7NizylbMjf+VBA++akbQBhzin+hEruqi/KDkJO9 1ONgS9+Io2O/sVpQctTccfl3ZP7Vb00= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf21.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=1712756223; a=rsa-sha256; cv=none; b=NcZgtBTdt6krASIQ0OA+bf9NmyN8jfTgc11Y9mB1j+Vh+9RItyZVqQ3/0TCWBSg7h8j2Im EUAxMdPA9171MpZ0Pm6BNhSGIc33yVgg11mW9cp+TtoPPoXCNHe3O0MdiCf8bg8oW5u2O6 v6HrM5ZEtOLEI5huRusVbf9KnN4oG5U= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF3lR4Jqzz4f3kjJ for ; Wed, 10 Apr 2024 21:36:51 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 6F9EC1A058E for ; Wed, 10 Apr 2024 21:36:58 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S21; Wed, 10 Apr 2024 21:36:58 +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, 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 21:28:01 +0800 Message-Id: <20240410132818.2812377-18-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S21 X-Coremail-Antispam: 1UD129KBjvJXoWxJryxuryUKF13tF13AFy8AFb_yoW8Gry3p3 sxAryfCw1UWr1q9a1xtr48Zry8K3WUKrWqqrWxGr1rA345Crn3tF45tFyfAFWDKrZ7Xw1Y qFWrKry8C3yrGrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUA rcfUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: C29D81C000A X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: wjgk6z331y6qcgawaembqoh69w1j3ism X-HE-Tag: 1712756222-495275 X-HE-Meta: U2FsdGVkX1/q5Ut25ek0MH/a5APaHe0JTAujoL6qeKQcRz6L7bzN7ckxXlXBk4J6uw5Qhda2smfsHiE8KswBHscSOI5mK0xXTFVuU65RnBw8Bcg/ukAm/GrP92GBAkbPcJ/hAKNK5+6cYlb1kfXERPjzD9z8Mm+7hKy/wgYXzU4RXBjFmI0iUOLu/wL11Dt0vZ3InrZEXu2qScdci5asog+qSPwFPwZQ/FGaQJqrtca8beIY800dkF5MJLCV0niFgDc3Dg0mHS1teurm3KQFyzuK7OjJ4HWNISl4+59A+WrwbmtoL7aEHQpynWNrcqCsbj1aGF86vwOBfy67ADhYF/tDckUPcZgdVKocZZbe3bQFPwxcuQw51YG/Nk9t073oC10EyC79qvAIUcpmHMKtZFGFfXUQhAHOMxt4UNq+dGVqZhMr7l+1LY2N8zlJoFA1GUjiNKHcDANGIEgRvGRNbzTwD6ay0dv7f5Lk+WSV4RmFjIr8h1+06lwu6SiPHhl+eZDgzu+nylf5B4vLzF1pSuBeEISxNAZ1kSmHPqZrefz79c01U0k9hp0C0EPUwdbk2SvlisP/3ZmsgJzDpfUea4uLR+rEc/31hTs6ULhxl8yERMDeuqFCfra+4MlqSHXE5NehuGbOmfsDk1enVnhcC7Fb7dDwO9y75iVrJ1yBgzICG66dTWQ+MLYH19rY0+0QVn/6tu1vfw3cmCJ+FYVSdQHMVAwuTAnD+MlB4UiMgMyG9t7btx31qwah4VctwriV0cFLEsP/hOJFkofrRpJ9ZdQEDNkrH65LgsxPJHZt38drTRoFblKW8UK2iI7AMc/6pF7+PjMz/2yT+G2kO4Jxuh7mRguzcHOSvKDM/z8JfwHRFOGWboVTIZPAayLxc1G2BG5V69fny9ylmQzN2nCUJX78ibDbHqvv0z/FJ1Buy7QVgHLCiNqFpbvem6Yb5H8XXB9fBD8R2TkEM+6fAFx +Ri/xfMT BJhRr 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 13:28:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624552 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 E7F91CD1299 for ; Wed, 10 Apr 2024 13:37:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB8626B00A1; Wed, 10 Apr 2024 09:37:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B1E66B00A4; Wed, 10 Apr 2024 09:37:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7598B6B00A5; Wed, 10 Apr 2024 09:37:05 -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 4E3A26B00A2 for ; Wed, 10 Apr 2024 09:37:05 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1E938406CE for ; Wed, 10 Apr 2024 13:37:05 +0000 (UTC) X-FDA: 81993723210.20.4D7CF9C Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf01.hostedemail.com (Postfix) with ESMTP id A92264001F for ; Wed, 10 Apr 2024 13:37:02 +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=1712756223; 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=hJ3mn71IzcyEI1inWsQHxjRWqhNpmf/aQzqyrM4mbKHYvKTHvdi+Cf9JKB/w7Tzfx2+5Rk 4PBG9wg7RGbnNMhAkba6pYKTAOg6RhVcBoz1dw+l7GZo4i9k5UvVw+epmvO9FEKTQd8x7o C+aK++alnBCYSLXMo1WwA1/x2zxjo8g= 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=1712756223; a=rsa-sha256; cv=none; b=oEZeRqgdxDNL5LI2POokLKqSYg4e6VexjWnWUfOyB4Pz1TYjZXZK1agP6W2wdtrf30Den8 l+A49CnCeLWMOvPncvLAlBcy7753pg+c9oAoMPkiBC/NNqOskvYiUmYpSWmF4u8ums0pOp nDWfuYxZ9U+VG8FGPa4dN0dgwaEbO/0= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lQ32Krz4f3mHF for ; Wed, 10 Apr 2024 21:36:50 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 165B11A016E for ; Wed, 10 Apr 2024 21:36:59 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S22; Wed, 10 Apr 2024 21:36:58 +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, 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 21:28:02 +0800 Message-Id: <20240410132818.2812377-19-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S22 X-Coremail-Antispam: 1UD129KBjvJXoWxXF18AFWxKrW3CrWUJr17Awb_yoWrKryfpF Z8JF18Gr43u34DW3yxtw1UXr1rKa10qFWjgrySkF1fWFyrXryS9F10yFyrAFyrKrW8ZF13 XFWjy34jka17Ka7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUA rcfUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: A92264001F X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: x7niabcdcu65rwt9yofzto6o9zh916zk X-HE-Tag: 1712756222-920787 X-HE-Meta: U2FsdGVkX18S3hbpK5yNW7llVMKjGcK1EkLUSRbtoSoGm25a1vIcYkHDeyKh+dU9nsDxRS+6fIKctV846MEuA8ZTuNrbzQ67kpqzIL9A6/Bnwdd6orikIkZQhb6WOe2oUItnUj/0gTh5H7/3+eOoga67vvcjjqqApWgUULKpfL+cZRqj6ohXkFu00sQRpNVyfbs/BrEx3sID7x9eG4uZ2wea4ENzkeFh85pY+RrII+tzFn+0W57Gcwo7kGR2/EL3UQqRtso7xCeHrExyFqna1r92Yrw4jgREkDF1y3ndvYnPi77uw9TWHcsRNrWE9aAVgp8w9fe57YZmSpKekMunqvZSELhVf3kOAnyhym4hiBSS2IrZaMWZsGY8nC+ocyHVJNFPIYhqf0BsQuZJNM18IvC60Vy8WUbh1A4HwPVQryjRVcP3x4EEcfr/i8Sg9FOqaSfy/Ey6aoSq76JKTYjSj651Kj+VpeukfORxz0QhekVfQTNRStWlXSVDOfzvnpAsSmMT8b1T4zirKMMYRbY1e/i6g1E9xyVh8pRZm3fLU5gqUix+MTqw6T8G/DQX1wm1h6sfq+FrOxWJm6qXzuGZVjhQNx+G83Uy1BojVFH+iHHZh/bkXqzSpTmVRlEPy5OP4h6g6nN5kdPoNVBKUQYPVceewF6MDEi44H8H0MLwaj/Q7/tEIIjK9643arWHSZtpLe8nz4LHWJ8Rb/IFeP14wfpStR9z0I+yUPxThgmdVdGHcR+cRuuurUSwomoXSdT1MI8oV1OcCLWNUlc3D+AsRgXOkxfaS2Dp24oMRotXLnmddLKakfsBCPVgxspfJQW8Qok0+90jmHLjfj3a9mushFp+Hyy7CLv4Q6RDNq/bMMKQ1aQxIj3YEtBFPhJBCSAFcgsPKUtxTrdTLdQhftHtdCWFTj2C1VMtFoZBu5fH1wqMg1joq8zT460+B4c/4FzL4lzKpaDhKPal742TV0n lfdyeu/v bWt+dUqIticH5lbU6d62j3vZPZxNit5txjtBta0TEWsj6Xl8NceA2heMoPRXbYzLw4fypFfx/NdguXpKnYkzO3B43d3yuZw2QYk0Oj4BRYJ2EGjRX43VKtjV1zvAmCerrwA+c1CMVHL0NVWDRj/kD7XKMDQxZzbDf9GOAbU+hQCecYaxrc1rtSk44ck7sXJgcaEQJrO8Yls6Hyg6LVtHzi10ilcHMN4zldo3G87A1vz9cRlslaXCMhwhTC7kJCnZC9c2/Z8JtJE8oPAnlI73qpBZgt15Q2KAI+ZkpCVv0FPE8kEk= 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 13:28:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624553 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 705E4CD11C2 for ; Wed, 10 Apr 2024 13:37:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F247E6B00A2; Wed, 10 Apr 2024 09:37:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E86A36B00A5; Wed, 10 Apr 2024 09:37:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D2AB26B00A4; Wed, 10 Apr 2024 09:37:05 -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 9BDE06B00A6 for ; Wed, 10 Apr 2024 09:37:05 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6E47B1A06C3 for ; Wed, 10 Apr 2024 13:37:05 +0000 (UTC) X-FDA: 81993723210.09.0C28DF8 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf07.hostedemail.com (Postfix) with ESMTP id 24F2E40014 for ; Wed, 10 Apr 2024 13:37:02 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; spf=pass (imf07.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=1712756223; 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=zMYXAahurRGho3tMGJB+NPkmw1vjljgZmzzBmW9u+QtacG6vQwEfyvXC5AZgEC/ht1+VzQ wPbizmc/NK/Fs9zRRzkDp7VZC2rQ242lDNARFW7ITC5YwLguS38peJVT78ejODahK7xnIE PnJIihxsi8QaiIJfAuy9/1FO5HRVtwk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756223; a=rsa-sha256; cv=none; b=b1hCocMAF9j7qKSENasakKG2sxxC5MDyyVCMvNnWgd/NSHDA/uTyPRyqep05bnDwSwSew+ 5edrsybRrPCJvSJtjal5D3LCRoWKqWXPZtUOYl8SjwD6hGXG/Mtfg0KJ0kWgiA+iI4QgGE a8m/cck4aCzP1MosC/a4Y+rY8AW9NaU= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; spf=pass (imf07.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 4VF3lW1wL3z4f3k6L for ; Wed, 10 Apr 2024 21:36:55 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id A9E651A0179 for ; Wed, 10 Apr 2024 21:36:59 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S23; Wed, 10 Apr 2024 21:36:59 +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, 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 21:28:03 +0800 Message-Id: <20240410132818.2812377-20-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S23 X-Coremail-Antispam: 1UD129KBjvJXoW3WFW8Cw43JrykWw4ftFyfCrg_yoWDXr1Upr W5KF13twn8Xryv9r4ftwn7Xr1fWa4vqFWUt34fJFyFkFn5Jr1S9F1qkryFvFy8GrWxAw1q qF45u34Uua1qgFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUA rcfUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 24F2E40014 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: pgfaseff3z889gsozm7h5cbag9r83ipa X-HE-Tag: 1712756222-640718 X-HE-Meta: U2FsdGVkX1+cU+2wDSdlCZGiiQdQNRbQT6KKC5hkXvOWKE9vkwnqamqgg2hawfdl7BZpC5Xlze0rhCEsc72ih825KyO4WyGwRAdHQds72MsqZg1njcYFtLwXvag2X4XllfU+IRYWpl9EXHFn0qWPO3gD0MIpwy0zLH5V4d4azB0WYBRkGdfOJ0a1Huv1TTc4+kCRJf5nbo93kjcxqNGQsGFlctcvet+1sVbzeqS+BBPVPfJPymQyYrZXHv5Kd+jhIp2oQjXK6iCQV1qBcm/d5Jdrpn2oxslyHEEN7nNBW2gUbARv+7KXAJXn5D2sdj1Q87snq7G7BeFifQBVFeH+v16AGa9cpR1upjZYH1AK9NjWFK/WRUrWeP7oa+Umk8h5CbBuKifSoTblLczqOTGHbYFN66D/DMUe3mF6mDwcvYyY2iyhXMDuNWnjkE2bxbyD7QxunHEwxre58GyAPaGNH2YtVRUCHpsWRa8ECoHFAkjj0qh/7L6gs2HvHLWnHCGrP303TCnTwVJe1LtO34672X6kmd6K3X128JTuxeg8Mt8gppvXRgBmAw9kLEXfbRH2NBqVzMMd+lrjIMR/TRBvGfMwUn4bQ+ju/5vETCkDp814FQHO+P4vIwmpjQsJBQB9YVegiODbaUBhMxUlZyBMtk9AF1nkY/e3gZ/zqGpRVF8aijflcI66YmDtoIVXD3SXUz91+bLyKGrH7uFf5fSF/7kJJvLLYhFzYxG8o3f3LSKgqWcL9U8835NoUnLdEaCPjStq51LyDAzz0/jbV2J2wXiK3ZcP8xlXcgCQjLs+bm6n4VrcY6/sc3lj1bDZejrrbGTN74bK1Ge+nn07QOENJOtuvArIYwe5+/BSwPfVxYP/Inrse0rs36m61s4bNW8Wkhs5qEkQUvZ9va+CEx0cuUeua51T+zSUkFvdo/+TGlUmnoHyn2Ri1g== 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 13:28:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624554 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 5D83FCD1299 for ; Wed, 10 Apr 2024 13:37:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 70DF66B00A4; Wed, 10 Apr 2024 09:37:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6BE346B00A5; Wed, 10 Apr 2024 09:37:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 585376B00A6; Wed, 10 Apr 2024 09:37:06 -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 3F75F6B00A4 for ; Wed, 10 Apr 2024 09:37:06 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 07706A072D for ; Wed, 10 Apr 2024 13:37:06 +0000 (UTC) X-FDA: 81993723252.14.F0657BD Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf25.hostedemail.com (Postfix) with ESMTP id BB497A0027 for ; Wed, 10 Apr 2024 13:37:03 +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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712756224; 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=nMDJs31hhmVsCuKbpJ1Bfp54eUAPrWUEpsttIwvcWo4uwob5E7ANt9PdAWL4d6Ch7Z0Lrf rL8KXbv/YsyLcY7XCiEp40BSlldiJzLVE+j8szHAGUlIdCXTFESKlbCjXXMjp4cJH8sR4m sUtyKEwogxgkQqA2GiiLNHlqIzrDlRQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756224; a=rsa-sha256; cv=none; b=8Exhtb7brKCBafEScDYRMJOWl1xHkgVkitTph9IDHg54So4TJRJPV4obF68tSpubZjW/vP 2DBXQE3/KWbLhF7I7GWF/8aRtJGFD6znhzAaufer+OmuFZoTrE45UVz8BkZXuV9U324pFa iRoCTuZyKo4jlWQMlBzF52PCZDwwWCU= 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 Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lR4d7dz4f3mHL for ; Wed, 10 Apr 2024 21:36:51 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 4E4231A0E1F for ; Wed, 10 Apr 2024 21:37:00 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S24; Wed, 10 Apr 2024 21:37:00 +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, 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 21:28:04 +0800 Message-Id: <20240410132818.2812377-21-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S24 X-Coremail-Antispam: 1UD129KBjvJXoW7tr1UXw4xWrW5ZFy8Ary5Jwb_yoW8Wryfpr 9rAF1xWr40v3Wj9FW8u3WUJryrC3WUWF47GrZ8t3y29ay7Jr1ruF47K3WrZFyFqrZ7Xw4j vr40qa48Zwn5Aa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW5JVW7JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUA rcfUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: BB497A0027 X-Rspam-User: X-Stat-Signature: 9etdyizrho6fggqtgn6uwxpngnzx9t7i X-Rspamd-Server: rspam03 X-HE-Tag: 1712756223-621935 X-HE-Meta: U2FsdGVkX19TyITEFxWj8IFOb6EKHnvGI4495vtTGezv4TIuUyNAm7v890DYZi1682gy0YbVbIuRKepCwCjPIVIWYouCFx7fhnFiFr5tOF6RftFwDVcGSsem3eyfENjYqEPyahWRYjfkPYRqlON2f8QpfVpi2aVqmLk+FEFSBYmndpZUBBGgMYCSIN4c8RjoF7OKLRALELw002RzHBrOnjUNg1zEXk2iCof4UgNWBA5TfIek5ClTy1wmfFoQ51KKwbqwKxmcd2J0NOoG43w9d0Wgp4CMezVpinMFVeuq5hqHj/+Wk43/CaHQXL+B61m8KwpCM+5IAD4XPSaGKL+Y6C5AEYPD+xUs8ZFyb/CMcdD8tDBpOs2eKiMduYuJjfBY6YGEIwUeDo+S9bfLriGGeNmb1QPgvHo2h7LpCwz+t3LIlnNUuh5M0bcxmtrBmIVFjg/F6FUW2oLjtHHImyIqgR9zxKPw/1QBeAvCd+Y2ERwXePV5Rp/Fkaa5VJhBl6ofN+c+Dg+Ppco5s/BV2N9MLmoCKqdcfNbI+LAuZhe4WPnDFq/3qBvWERsL60/eIlC3eNvNguzpwHAKQGkSfES9TZShKX6y3xQ0qu69HUNBf7i0QJMQK+k/jj6IMRSPYaqZwbepe8hrGXr7OtQEsYU8KSkuVt5Di3TSKnjR4MnfO8kEmyrTQmR4CzmEtyYoJRrCZL3ixgDq3cxNIZTYoPcDhnApSgCEHyOBBzvUQ3u/f7inQ/ffz4mPOdQPJrBMVTR83RDCKZ/dKbJLAtf1rgHOd3zK7E/kfCRPFcnhy17p919MImch8djZjJX+zVE7SJB19Wn2ri/EPY8J6v4Xd0WPqHB7pfpOzUu8EwjojWgqlts9zy3WinY5Qm7iy1bk/zOiwQupIYxzvbZgq9ToAkK1V9GKZWBMOPqbk3lDdEVqS14VHrfLmsohnCtxk+99hyXnuCMmRxqIMDcJLVlZWZM WnRC0wx0 wG+FY 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 13:28:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624577 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 E0C81CD11C2 for ; Wed, 10 Apr 2024 13:37:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 38C5E6B00A5; Wed, 10 Apr 2024 09:37:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 316E56B00A6; Wed, 10 Apr 2024 09:37:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02F666B00A7; Wed, 10 Apr 2024 09:37:07 -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 D7F0D6B00A5 for ; Wed, 10 Apr 2024 09:37:07 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id AA672A1172 for ; Wed, 10 Apr 2024 13:37:07 +0000 (UTC) X-FDA: 81993723294.04.3183F1D Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf14.hostedemail.com (Postfix) with ESMTP id 3D6EE10000F for ; Wed, 10 Apr 2024 13:37:04 +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.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=1712756226; 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=G5d0o7Br0yQcfbmzLbpM+jzlRlqPZLCQ2wYViA3YFqCuDPtr+e4ZzI6jBP4gEus8s2yrtp +Ps3X9hbMKwxHhuclvKqMphr6+o/Q+HnVlPicg4tdkHGVUn1CjvpnlXALH6aj5qHGG2qbx 4jXO4ny2CqQWbMHs9KcBbGVAcIHQKM4= 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.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756226; a=rsa-sha256; cv=none; b=NfMwhTwWb18u6byEfnO+IdoLsAyd4GU+MkxVLeRGyjKP2VumXOVobmYqqPKRIKHrbzgjT9 lV3Xmhfh1/dSku5QAbrbySwKTo4BqvrR0y0oOeH+tv2JV1jHFT98P3a3zQNUkXGz7yFoWM +PEknPgyuf3arVCwAfShMGtw45DndZU= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lS20YFz4f3mHS for ; Wed, 10 Apr 2024 21:36:52 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id E714D1A016E for ; Wed, 10 Apr 2024 21:37:00 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S25; Wed, 10 Apr 2024 21:37:00 +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, 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 21:28:05 +0800 Message-Id: <20240410132818.2812377-22-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S25 X-Coremail-Antispam: 1UD129KBjvJXoW3Wry3GrW7GF18AF4xJw4ruFg_yoW7uFWfpa s7ArWUWrZ5Xw4j9a1xXw10qr43Xa48WrW7Gr9IgryrZFWftrn8WF1DtFyjvF90qFW0kr17 XFW0kryDA3W7WFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW5JVW7JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUA rcfUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 3D6EE10000F X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: xwckuhjz6noxoesm781z14phipbat1qk X-HE-Tag: 1712756224-777995 X-HE-Meta: U2FsdGVkX1+kMBog1VArmdGmpGC0IBaWmwU2SMZq4UdSj+VvJxBzYD1pGSibWEyMM/bUHWXqSVnIkz27pwSdfFnTtfdzpIBnswN5Eh/0krh951RrdrflDZs0d1xEeOtycxo7+pF+9ZmiNer9NEJaA9aN08SaRr9yUOF/KEHjzX1+ArgRx3i6EzUpRuqC6yjAFxetUD2AaRlLjkhhOlgyCvdNXIySmZDGTBz/1HT0TIUJgqrrgD7x2GWSY+jFpez7KaAh0L+2Xr/PxKY70kT2pwDqnkFpAFmAps5UNTw4eteehcKpgXWOm3TUiLXtyZ6pVG8fqUMaKHu42ykl5xHegJRPdBWZ1NyIa2RkZafDz/kmgKqyWw37rJPhVZPe8jwdaqc+jEFAPrmNdFl3ItIBYjNnq0OK7SAcFxydWtT+hayV4+Yof95GbuNd2ftrHrhTUG953n8ZJ85E9XoaLmrNOZcF2utiPLVymxcZky27u9r3EEEfM/nZzj+gbM/NziZvPufYj0R/Cbm8tmSHUGbcUgKe7ihGy5GzlzjjfDhKREyYvzj0xWySAqXYUkE/KpqDUFH3XXCqtuR6NM4vckM8uxFSPviB5Wpshew3GI/JXpQx08WdCMqkHrXO6kuI8NYsBzMiMz/iQQK7nUUzMA4Er+1QInD0qetlhIhb+VvIQTCyEg++I9IwGz+yM8iqCPedE9xrlj6RHUYd518kkJquOIk3E0H0VEiG5I8eT9G5RGHo6XSCLmUUtek7soqyb47loSKlhyKwVcqCZPoQ2BZPEOBIeNRB/Ih96TfBkuuZBUYurOnPDvMSnKqV5Rw4842wEMmojBd/rJ26+59ndVjkVAJfh1BmCniS1ZAmqRTAKXPrOZWqZySEY+OpUv3pZn21A4n3/pZmDAL9uNe/zIMaZgOk75AR0znQ8J00Ezz/zu8cqTi+JXWMWopgq4g35Uugs2i6D92fjGwZNMqDzcf 6phkIpE9 CwlvfixoRUAvcG6+YmlsjJvPWH8h6MwqomsYV9POLHhQtjLZw5kjSx7oiiqowsPNOMLU/KPydH6BpPlzJ9fs2GOU8c7NQQwSlLVtV70PGJ1U/T39kZ0OKCL7WuBl4XLfDPIEkOCg+jEIL4ekT5jmwqzrfUh/BOMoJiuyJvz/5qHaDt6Ov5j9zoiBfa+pK6Dd9HCWwhGVDOfhMy6Rudi21DhnW6BPyZYKxgw592TbNerwBT80= 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 13:28:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624594 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 5F97BCD11C2 for ; Wed, 10 Apr 2024 13:56:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E6C726B00BB; Wed, 10 Apr 2024 09:56:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E1DA96B00BC; Wed, 10 Apr 2024 09:56:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE3446B00BD; Wed, 10 Apr 2024 09:56:25 -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 B09BF6B00BB for ; Wed, 10 Apr 2024 09:56:25 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 760D0160694 for ; Wed, 10 Apr 2024 13:56:25 +0000 (UTC) X-FDA: 81993771930.13.B32D4B6 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf29.hostedemail.com (Postfix) with ESMTP id 022CF120028 for ; Wed, 10 Apr 2024 13:56:21 +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=1712757383; 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=kVAk2dgYSxzULNFo0gK5IV9T1YIMmcWWsAJ0rMEEiASMeiTDl1caZI8JeViaQ3CTyJnAz9 jxD4IS5RrBD0E+Ty+vFfJxuHU2E2CxogAAd24geNNWu4Lw8ahmkETUmnJJAMfEGIYP3Dk0 SUd65ke8UOBXmWhGDIpDLWwOa8DyJhw= 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=1712757383; a=rsa-sha256; cv=none; b=n3/3SlbXwO3nrh0Om32FixJxmq3LH1ThHVwh8ElHy3agiASlu0YMWzuOby6cagGbxkc36s hFMx18+ZQm+M6/bJTx+XY7M95nCChPVOCRFioTwq7rMNTfMwqq0Mdy+F1Q++JgL8PPipUA 2I+rGl9h2pzEgZreJ/8BkB5mMj0yexE= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lY1JhQz4f3jJ2 for ; Wed, 10 Apr 2024 21:36:57 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 955B21A016E for ; Wed, 10 Apr 2024 21:37:01 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S26; Wed, 10 Apr 2024 21:37:01 +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, 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 21:28:06 +0800 Message-Id: <20240410132818.2812377-23-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S26 X-Coremail-Antispam: 1UD129KBjvJXoWxCryDCFWrXrWrZr17Kr17KFg_yoW5CF17pF Z8Kas3Gr18Zr9F9a1fXayDZF4Yya4fGw4UKFW3G3WavFyrGrW7KFWvk3WjkFy5t3y8Ar17 XF4jkry7WF17CrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW5JVW7JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIc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1iaOtXsmQjnupdTz6z1+RD3xFk7GMdj5bQoqisIvtdtuo929ooCnCmftqpD5L7FfR60UD0WcBST+jKioI51DpJ8xHY9e93qA/cTFTnd4hlHnhhYTeecyEIrkM8BVOwpN/6FGBafBChSlBXUWG0SC/7NlJGwm1nzpVJGiSsYf ZyywNY35 hPwcnTG3Bdxb3sSSEHIbWgJcKOqdctzOzmFj+B9xJtkIrLbe60MKGkFpThghVLG30zJTg2yANuXImYiszfrzyhV6IhvhiUv65XUwhgjiAOMItDD+83ZGoKHi0o8l9/f+mh3i94x7HyKUnXKKCzfAEWlZnKAtJliommeeYQdBkFq+a2BifLV5R+f1QGD8O14R/pl/xbkwYo/9sNCw= 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 13:28:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624578 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 5FDF0CD128A for ; Wed, 10 Apr 2024 13:37:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7FA946B00A6; Wed, 10 Apr 2024 09:37:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 75A976B00A7; Wed, 10 Apr 2024 09:37:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62D6B6B00A8; Wed, 10 Apr 2024 09:37:08 -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 3F4CF6B00A7 for ; Wed, 10 Apr 2024 09:37:08 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 10DE480321 for ; Wed, 10 Apr 2024 13:37:08 +0000 (UTC) X-FDA: 81993723336.15.9B07BCD Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf11.hostedemail.com (Postfix) with ESMTP id A49C940005 for ; Wed, 10 Apr 2024 13:37:05 +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=1712756226; 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=3FBzXTIseLeBJ8OXONtFrncnXbBDmu6QsoUT2cJX4uV3Hmz85kgSvBpkXuOBgCO7GKn3Gb AkU7mTUB9HmCnWf19rvjguENz8JmbwPSDYf0T8rFmNZNRxfJPY4Na85kGM8RQeytd4Ojeq DiOd8UR+KLkc6KTkccyLyvWwnW8dBm8= 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=1712756226; a=rsa-sha256; cv=none; b=gnVqiBaeFYKxDQNZadrHmu5yZJ3XLaDgw0zYIz6bH3HMG8Z04jmnvCLAEKbgpTaq3Hic1B ApatwU59zhNXYuiJWo/UEy5u3DKpPs1Znm9XGgLx/9XErPS/OXlPQ77BlcfVAHYRJYNohS nTorSmuJQSKnPVIAyiIz4Pd9D1HXxNo= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lY5Whzz4f3jkd for ; Wed, 10 Apr 2024 21:36:57 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 31BC61A016E for ; Wed, 10 Apr 2024 21:37:02 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S27; Wed, 10 Apr 2024 21:37:01 +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, 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 21:28:07 +0800 Message-Id: <20240410132818.2812377-24-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S27 X-Coremail-Antispam: 1UD129KBjvJXoW7urW3XF4fAFy7KF1UXrW7XFb_yoW8uFy3pF 98KFy5GF47XrnI9F4SgFZrJr1Yk3Wxtr4UZrWfWasxGFyYkrW2gayjgFyYyF1Yq3y7Ary8 WF1jkr18GF4UArDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW5JVW7JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVWxJr0_GcJvcSsGvfC2KfnxnUUI43ZEXa7VU17G YJUUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: A49C940005 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: e6sg95krax3kysehoc8n6a8rp9tz16kc X-HE-Tag: 1712756225-847073 X-HE-Meta: U2FsdGVkX19zfYxs0v6OeJg0lZmP+S+iLAmdWpVvzyPtLHWo0EgjMrcYsw7WSAsP5RMKIG6aM+nyfZliVKgq67jjRligqOtpMVXZgLqWXlqivgyHhaXUq7LN2aYnk2djzrI1zn5XmSbtHODOfFkoc0WPLzoJMZ3ksyOdcqOiCgOM8I2+yAgmSaaMBhd1y42KN1QVaG+Jn1h1MVjQVMWxTM0mkRS7mxjIrk3KRxHQVk44Cwreh1hKXQCb9r1zjtpp2rmHqxfmIJslFpezzMAM4nAseBAL4H3JoHi9ovUW6zMa7EAwCKxnJrhX7UgaoKIYbV/cc6GrLqe0SZdxe181dw0+hBlp3uAfeBkhmJe+We8Qth3IB/bU5TEWV7BL6NVs91ZTBONBuBk8SWhoTFCBK2SfNsY4+EA4gQtNtO2zeNrk6RYPj/kV76YYaezvx7xfwQq8h32QPqyrn4vMVFB6qyXfJ7cufosG4HOGSWEsM0G7ytg0JYqRIe4WtRvdwG6kTMGacLfM5g3rjAkcOhPlu88Wsg+BLz/1OiTeLgsdKdC9jL/dL/aNvWYShgSAdAotOS0qFsdSnbqGbNlp1fBvPkblUNwfNuc64NscTz+6XB1XOL+rjKqiCYR/SnNfOVnOZScKZJehh3cbcokwTtZPzXdDd+wmxCx5sMcLUeWOykzKg5T1pcJAX2Y0kaR39dbM9FzA94Gd7ip4sTKkJGaNXEoehx4FUh44zdCzLnu5EQ9CzzC+JmC9e0GYp5v/mO4DkNy7TuZEoYC4qUO57yyK6AuDCt/za6FAq5emQVQhG5/u76p06/EaOd4GkU6fdj3LpXy2brmHCA0t5QunZ/FW4bUp0oJG9kXjmF7T6kmu69ms/6Xho3FGmN4D9dJK4AlNyOZTslcszHCWJyOsNPu8ZIZzXqXgiOo5XK2CR/5FSnYfc4v6XwkN15a55t+C11pLUA6g2kfwDbGtwhkHKGZ XfudnYgt cFk42kYGWv42Myd3a9kuafqVzTmj1kN8Ijgb8gVyBb/Ob8FGImS203FIBGh478DQeDx06hhKUdioTwD+L/mE/8uFFDvlG5cj7xPXOrfzFMF3ddy6Cnsx8oyRZgjBGjnsTOJzQ4xHbmLnYD4vJnCH6hJ3hOjnaUBirQnlqUMlZfZ1qEz54C9a9+efKh4wwWhtlSBK7F++K2rA061eZ5Wwuy3dOiADrn49BFyESWI5rOQF198mxhOTL6/7JCUIg+BUZ/xtj 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 13:28: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: 13624579 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 BB0C6CD1299 for ; Wed, 10 Apr 2024 13:37:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 031516B00A7; Wed, 10 Apr 2024 09:37:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F25536B00A8; Wed, 10 Apr 2024 09:37:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC20F6B00A9; Wed, 10 Apr 2024 09:37:08 -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 BF65E6B00A7 for ; Wed, 10 Apr 2024 09:37:08 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8BDEF160653 for ; Wed, 10 Apr 2024 13:37:08 +0000 (UTC) X-FDA: 81993723336.13.20BDDDA Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf08.hostedemail.com (Postfix) with ESMTP id 4AF7A160003 for ; Wed, 10 Apr 2024 13:37:05 +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=1712756227; 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=tTTM7ghQQc6oB+9UHNBrp2yMH+J/qxF6B+3cOIcHygIxdLcNMs1XqOZgvc6LxttEmJ83b/ Ay0ppomwn1MZs6pIevOR7PcYCXBqsw1w8bstsetLTjeBtTi86Z2IigSjszQd0EGO0RMf0a EL98EtFolAU3CQcpjnkdPmzxS4KmBUc= 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=1712756227; a=rsa-sha256; cv=none; b=1JOqsMDYDSujgPsFc3VARnfSjbVcSXtRf/BnohPkTFsQbRmVWXuWCSy1/qlTi1tNmswxZF WIPE22iz9gcewbaHo5gUCJhMz9/t45+5MzWQby+G4AHae6vhSwQ8eLfT05WNJ4OEFzaO45 dQszt1ZtVj5qq+H74+eo/UTg77kfEqs= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF3lW6mgNz4f3khm for ; Wed, 10 Apr 2024 21:36:55 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id C72101A0572 for ; Wed, 10 Apr 2024 21:37:02 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S28; Wed, 10 Apr 2024 21:37:02 +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, 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 21:28:08 +0800 Message-Id: <20240410132818.2812377-25-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S28 X-Coremail-Antispam: 1UD129KBjvJXoWxtw43trWDZFy5ur4xZF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o6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 4AF7A160003 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: in3rqgwisosab4d8f4i8pd9xmmgqnjq3 X-HE-Tag: 1712756225-566450 X-HE-Meta: U2FsdGVkX18sOY72P8cktqrs6L6DMB55EmipkNYBiS2/j2sVK0YAtIH14MV8W44jBj89pNSUuQyVBNle8GppScwTPZY9I4HqwgPDZsp1pHgXT8YeNI3JJHLSNu7WYmNyYxzspA49wfuGw778P1i09LburYIccnpX8FbZObZSjGzs/k7/HMvmc0x9lxU1ntXHykMn6KAdo5emfCQdOncPIqa7snpN+xjdhrhyW74gtS4+AmUbd38xztFLckwgVroRiBNzZPPh5rER9dUY3x0l8EQ4piRG7KRmk4oEi/uWHPAz4yJ3aWYhJ8g0zSY6SO7PKvkJQe18FNLp2hqpN9i4gLVoNDGUjyHn52amAUtRCf3w5v1mYZip/yHHs3vf/jilITe/FAWJ7lP9Y7gKfpcz7EO1uyRTuVNDsyn+w1y9huhzyUPwQWnmZFcpMAbgtb29/axEijhrJtZTYS6Fj414kHRuPB5fpD9T84tNbRAeN9whB1BoivrToP8kMhFyYQIo6wLuBQQ+APjJs2pLYSbPWGE/QWkEeEnlig2onOqYx37akwoJrOt4HNYC0CEGLgvkQDsubHQCvBvdBqhXyw/loc4eNk3jL53AnMDeRgBSmXg4zmAxzeTZEf+kZyk+NijaJ8koCNlcGpDdcaDa+cIoL1Up4Sew0j0ihSkJ2+pCh8GV3v5MW3kzpnHDYzc/f28TKcXJzy+DkCqAn6rueR8/0lllmPxtbCsCK1hKefDA15/Jadc7ahaUQt1PLhfuosjGUJ3AHgt07BYMRVnNYH5VssgiP0bcZDefUo8ZJk2V0IraRSPs77rO8lZ2p96ZgZkfpVf9gHlbMPENkI8+iVMY32nhWP6+Zt/yv6c3kG51hnGlYWuRE4MSKcMYu4L0JqCBcHyBRt517hloiJBeBHBNdCUy6OHtsZHZekqc+a4f0Tinq7T+o7DlMnLuQCg1WAtNiOqFGuQADmq+lMCPdEj OBxlaSdV swqw+h+3QzceyXgk= 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 13:28: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: 13624581 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 CF888CD128A for ; Wed, 10 Apr 2024 13:38:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C0C06B00A9; Wed, 10 Apr 2024 09:37:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 64AD56B00AA; Wed, 10 Apr 2024 09:37:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C29E6B00AB; Wed, 10 Apr 2024 09:37:11 -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 2316C6B00A9 for ; Wed, 10 Apr 2024 09:37:11 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9CB9F16072D for ; Wed, 10 Apr 2024 13:37:09 +0000 (UTC) X-FDA: 81993723378.20.EE62724 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf19.hostedemail.com (Postfix) with ESMTP id 15E271A000D for ; Wed, 10 Apr 2024 13:37:06 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; spf=pass (imf19.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=1712756227; 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=bCT5ztVb6oOe6JscdyR3JtB8gTch3BkQvZJD3a7BDRxKL2prQSR2ZuHMFKunWcLO7YRtEI /S05+kLfMO1mWU/w9Nz5rgwrCczI+kpr+e+zpFyxudlC+NMjWbYQR5jv/Kjr7/MY6hygei 71KWh8CTNsYBn894Op0V2ONCeiflQrI= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; spf=pass (imf19.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=1712756227; a=rsa-sha256; cv=none; b=o4+p7bpsWj1qqWM4ozuvmhSYPoD0KNOEf5ckxPkCfZEMViKcGONPGFL3055+Myxx5pVEvL GKWIVYmVBl7FNPZzSVwrW+PGHY3q6dBXK7AEGVX/ZaTA7M/Br9XeT8HTwQYI6pSHMt7a4y FXRqyEu26BvmY3xP7QEDXF4hn/pcC7o= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lV5Qgrz4f3mJL for ; Wed, 10 Apr 2024 21:36:54 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 690261A0175 for ; Wed, 10 Apr 2024 21:37:03 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S29; Wed, 10 Apr 2024 21:37:03 +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, 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 21:28:09 +0800 Message-Id: <20240410132818.2812377-26-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S29 X-Coremail-Antispam: 1UD129KBjvAXoW3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i81549lKPiVo6WAoxQHVF+gFm6IbTk+YentSVibjisxS25GsCsUy fat6ZInu yC2du/sU7oxmor1xEusScFAkjkiJWzJdcxIpaNRWaRN42y5fs51VpIebGAb8XEsqua6PlEROKgJO8uGpbtJCQD+3H0vuKitEqMtfeeH3L0f3bj4h9Ra+/b7I43AhMn3ytnRx6ByTEwq2MATH2AzHIfRJX35IFqUhX/zd4GiDpPAjD7I/e8WeXBMhjX27c01pB9gPrnb74EYRvWmaQhrPZsjtwlBrqBH6/Ue8ajLbilWXcPvk3K2P7s4wzY7Uaum/CAqCc 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 13:28: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: 13624580 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 215DFCD11C2 for ; Wed, 10 Apr 2024 13:37:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 734866B00A8; Wed, 10 Apr 2024 09:37:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6BEE26B00A9; Wed, 10 Apr 2024 09:37:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4EA486B00AA; Wed, 10 Apr 2024 09:37:10 -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 2DA4B6B00A8 for ; Wed, 10 Apr 2024 09:37:10 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0021912073D for ; Wed, 10 Apr 2024 13:37:09 +0000 (UTC) X-FDA: 81993723420.18.DBD6F43 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf15.hostedemail.com (Postfix) with ESMTP id 7EE3EA0012 for ; Wed, 10 Apr 2024 13:37:07 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf15.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=1712756228; 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=JlmlY9jwEoT/icV34RgjYNUsq47xRR2UbWUY7mYCvc4FqPN84rj9JtZhfmTnK4zkHJPi/l 83Velw0p8eUFZSQ0Gjlw0vKswRiEJ9Gwb5eP+MHujEPmItnUvtf4vKfIL2ZK18gA2bayJk 0vBByPKOufvevOzn6IpFl+koDhAJnw8= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf15.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=1712756228; a=rsa-sha256; cv=none; b=4BwzDNzWo3QIk4naemR6oIvA1ec5uEUqH7hxtJr8adOAI135Ukn3sO2QgjnFh52k6yv3zb AtnDu1a1YtspDFaCBJ2y2U+2clTYt/1Zz/EfyjHT+DB9/baZ2qvpL4s69hnqwWh34+z9rQ Ex5foQjy7i1fjNI62pP067lYOAelKkw= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lW2m6Cz4f3mHW for ; Wed, 10 Apr 2024 21:36:55 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 0D9171A0175 for ; Wed, 10 Apr 2024 21:37:04 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S30; Wed, 10 Apr 2024 21:37:03 +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, 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 21:28:10 +0800 Message-Id: <20240410132818.2812377-27-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S30 X-Coremail-Antispam: 1UD129KBjvJXoW7urW3tr48Kr4rGryUWrWxWFg_yoW8Ar48pF 9akrWrGr4xXwnI9FsagFn8ZFyYy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huqPdbK mNDGO3aY edOGQfGkp95ZT4ZohJqnmEEsCg9AEqUPYPzboSVzMO9RFjFIHOTAz3PJ20Mqyk5IkNp2F8Tn2jcyD7NO78ygXieybVyULhdF7rxmNdsen0rHo6cck1p0oG3ki2+wtASJPGQRt/5J1NT2PwO1WJE+6zGvvNCVhibQAlK5+obWsX/bqY4VJiHhffVEoDEL3a6huj2MDz8KJBJkKBL8= 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 13:28: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: 13624583 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 3A7F9CD128A for ; Wed, 10 Apr 2024 13:38:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5D6B06B00AB; Wed, 10 Apr 2024 09:37:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 586B96B00AC; Wed, 10 Apr 2024 09:37:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 44CFB6B00AD; Wed, 10 Apr 2024 09:37:15 -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 2ABE16B00AB for ; Wed, 10 Apr 2024 09:37:15 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E52E91606F3 for ; Wed, 10 Apr 2024 13:37:14 +0000 (UTC) X-FDA: 81993723588.22.18B9EA6 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf22.hostedemail.com (Postfix) with ESMTP id 1D61DC000D for ; Wed, 10 Apr 2024 13:37:07 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=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; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712756228; 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=Fxg8ONuzaPUVLrw6SN3ME67OVWr5E+ybVklc2DECdRTGhezEN0GpPYyZ75YOJajT+b+vIR L2VQP4Ij26Qgn51lHiMenBh8/v7EjOrLzjZkXQWpzKNgWzBmROpNDrKT3bucI4GJh/isQ1 X9wCfTArAIj3byK5T/YToOYDc6F54G8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756228; a=rsa-sha256; cv=none; b=LNDpSkyNlxdbCweu0my20ChsHHWjeodEnDLTdaROOWq5EBX6OdOfJ6tiwZ0E8NuE5lmvqd hh0nF6Ja3YfF78OhrU7G8iPfw+beb60XN01YiKcqtfZAs2TtXNwRmdekjpa4ND7TTHKpeg KgZB46qlZWJ/wyo20hmRoV22C4Z6aqI= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=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; dmarc=none Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lW7477z4f3n6d for ; Wed, 10 Apr 2024 21:36:55 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id A1B6B1A0572 for ; Wed, 10 Apr 2024 21:37:04 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S31; Wed, 10 Apr 2024 21:37:04 +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, 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 21:28:11 +0800 Message-Id: <20240410132818.2812377-28-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S31 X-Coremail-Antispam: 1UD129KBjvJXoW7urW7CrW8XF1rKFW7Gr1rJFb_yoW8JFWDpr n5K34UCr47Wr9F9F4IgF9rXr1Iy3W5Gw48WryfGrn8Z3yfW34xKFWrK3WFvF4jg3y7Jayj qF45try8Kw17AaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPF14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j6r xdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2 IY04v7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAF wI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc4 0Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AK xVW8Jr0_Cr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JV WxJwCI42IY6I8E87Iv6xkF7I0E14v26F4UJVW0obIYCTnIWIevJa73UjIFyTuYvjfUF18B UUUUU X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 1D61DC000D X-Rspam-User: X-Stat-Signature: fuwcjcq9ygygxttjqr9ww3rhmcczx5mx X-Rspamd-Server: rspam03 X-HE-Tag: 1712756227-17643 X-HE-Meta: U2FsdGVkX19WnwvDFKlyU3/5WiR3DfLhVvnzmBeVHo6T1LUEjJx8IWFSQbnm41PlqB8bz0F3Ek00Yhx8o5t9aQSvneumkn9NwrGJqbFD7UOvIMHe0MQ8HzZ7+ojndbOr+NYN/TZc2EKHSwr/pf9uKBvw/EY7hgFtmnevZJj+1h7KF0+F6n9MIsNZRfJvP12LTiH1+Pf9PdLurY8I7YfQkuZPr5rZKd2RAEPctg0/8JIKeAjYqCC9XnOwJb8j5HstefI3h090K3MT25rg164Bz+zagKckd7NGNNJrG4jbnnYV6OjpsQYkf1SF8LD4wOP6kEMa/eSyXk0VI5Nzw6/eVNFtlNaGPRZSVsCMZIUIkpu4ssEr4nUgivlbs8a18MZRzmk2/HDiXQwn+i0FRGBEqrLRv1p53xOrmQ1yhQThBKlvzb+YQGgEi5IjWEvwCCid6STU8fuirpWdAWYSAkSeI1UfjyGE17RprzlePkars/j2ns4JSzbxfEzBEgxE6gyHPK9UJ/8oNKAvQwQJSSWCCgJ8Q1UDW4efOxoWONejaXRE4iqLW+ivJcYIichvD1QkXsf31cf+X4grzv6PdzKJI+5Xu6c6WQVaAWrf/wO16DLgkXtE9RwZe1Jyxegb7F62RScIuDgGYWro1gd4KS5JS4SL6i4+pHyeMDbIpK+Y4vjW0X7GF0qPSj056uuZoakmNFmpGBGZnBTXcYE9FAon6bp99K6BA4ifMkodW4Hq/Sqc+qkPs7Lc6+mjhkD0E37ymSY7H46nEN0aQTjT3zszDvxy2+GAUS1YEcDoGl1uSukdzZktW8FAyE0dB+4e8tN0+NVt7QsErUYFA29tWH9f2bd5huG4Vn9Hy2f06H4OHmb1r5uo6bUA8IF6IAo+tF1sBIp7NROMWyFd3b6pNvrIoN+onsNHLX2PzxgC5IBnnOafG4eSmKYsH8D8Li/6dsgqxhn6yWGfjes8kHwo7x5 YY5knu44 /Xg78yd/8bfMFCxT0L+nmYpiRoWVoRBa0abMRjzsbrnUvwKM4FzZuGvSnsHCXOoCL/YkTI42BklwlAQ+0/mm5BmOfiFlFsSWURo5k2VE92e0U0urfQPnZCjNF1cF/Z1CFf9g2xjPPft0uwPQjSeQk9po2lTg8NCTg789PacaeTCZlgvru1DjVqO6hhpoCkq1nLSX7N92Br7n2pXMbFr5txXgPdd8+f7gMy/Q7IHWpAcIq4TAAklgD7T103dAanijsB3ErGbDGwx7DuDqdq5925Y7tcezPlx3sHqP080OB1CE/inI= 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 13:28: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: 13624582 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 C91F4CD1299 for ; Wed, 10 Apr 2024 13:38:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4EB6C6B00AA; Wed, 10 Apr 2024 09:37:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 49B676B00AB; Wed, 10 Apr 2024 09:37:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2EDEF6B00AC; Wed, 10 Apr 2024 09:37:13 -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 0F6496B00AA for ; Wed, 10 Apr 2024 09:37:13 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id DAB5EA0678 for ; Wed, 10 Apr 2024 13:37:12 +0000 (UTC) X-FDA: 81993723504.26.7F3172D Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf27.hostedemail.com (Postfix) with ESMTP id BDC3240008 for ; Wed, 10 Apr 2024 13:37:10 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=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; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712756231; 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=DAtM4EzH9kCcF/0taJDuG4uewGCQsDi6soGB74IPwvojSw3D/3hZrBn6g31PKoNbIHb4m7 E10m9xcfUx/pWSf5x3yp77oA/pG+PS5x4cuOzenOb6WUgnhbxVcBOqD/W49G0LfXol7EP5 6lxyWQM4j5Njl2nxsIhAAJEBmqLosNQ= 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.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756231; a=rsa-sha256; cv=none; b=AV8u7l9kTw5r7TzE/cmLzW3h+cDuEKtCmu5UEqvmJHmaPdXgvyQknB+lK9E8U7dO6dTZ5i bizOM4/XpoWME963+B5eJNLwotAKPWmRG/TMiJxNUT/JYqnuwuLnmDRrneP5ZZ40mtEOJU 36129lzt/SYbFZtxfBid4AIS6n9wuRs= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF3lZ33f8z4f3kjJ for ; Wed, 10 Apr 2024 21:36:58 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 427C41A0568 for ; Wed, 10 Apr 2024 21:37:05 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S32; Wed, 10 Apr 2024 21:37:05 +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, 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 21:28:12 +0800 Message-Id: <20240410132818.2812377-29-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S32 X-Coremail-Antispam: 1UD129KBjvdXoW7JrW5Aw4UXw1DtFy5XF47Jwb_yoWkZrc_Xa 4rJr1kWrWftr92g3s7Cry3ArWIyw409r1fuFy0y3s5ZFy5Kws2k3s5Ar4xZrZ5WFy2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5iqfhPAYWPcDyBHCPyqvGkmDfm0IBR6c/LorVQZyJrC8DrzP/hNCAygLSA6SZMT2WZ2PP1uB30TCCF4dVJEEtRoqexq1H7cKC9C9HSFodIce3kvyppX/K7DIHOPirdyoOa7mUiQm3bDOYReHEZDJUACPhx6m3V0b5n5U6RaAw9nmFQuUjfIsTkXQ1U6k+XPfcbIKHW36Q7gghOQnnvvOC4AAuZbBoMhySH8kmqZAYZaLKDPG5k+Z14HoidX 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 13:28: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: 13624584 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 CD0EFCD1299 for ; Wed, 10 Apr 2024 13:38:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 563056B00AC; Wed, 10 Apr 2024 09:37:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4C4F26B00AD; Wed, 10 Apr 2024 09:37:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A0346B00AE; Wed, 10 Apr 2024 09:37:17 -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 0CC0A6B00AC for ; Wed, 10 Apr 2024 09:37:17 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C75834061D for ; Wed, 10 Apr 2024 13:37:16 +0000 (UTC) X-FDA: 81993723672.18.28808F1 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf27.hostedemail.com (Postfix) with ESMTP id 5D49C4001F for ; Wed, 10 Apr 2024 13:37:08 +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.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=1712756230; 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=x1bGk7uGysdPogx5++GHG0PN+Abf9AE9EoOrSx/PNqUs9ec81v0v3oDxAPid062bV2nkcO GdGQDivyp2chCMrv7wo6OV2q4GAtNdjQ49MnLA3Rm8wxkhs/qf3yy7IKBErYPb7L8Cy84o Y+Sqlu9QfLaazEcTaKDPub2PhYSY8Kw= 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.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756230; a=rsa-sha256; cv=none; b=igZrisN91ONVV1YN6vpClLeaP4lIIU2ohsWPKlV7SjGT0q45Zk1cRNH6e+gXAvhpbppiK8 V+8m2daFc3jCE5S+sl6DtpZ/Qnvq0raRLQT3rfCyslTh/zu01tY5aNWiODR6050U67LRg/ 1kJpOIwxjZP0qdOjYul5zx93Mzk3t8c= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lY1btJz4f3n6h for ; Wed, 10 Apr 2024 21:36:57 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id D9CFB1A0568 for ; Wed, 10 Apr 2024 21:37:05 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S33; Wed, 10 Apr 2024 21:37:05 +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, 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 21:28:13 +0800 Message-Id: <20240410132818.2812377-30-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S33 X-Coremail-Antispam: 1UD129KBjvJXoW7uw45KryfZr4UWr15ZF1xuFg_yoW8Kry5pr 9Ikr15Kr4DXas29Fn3ta4UZr1rKa10g3y7urWfW3WxJFWDA34IgFyjkF1UAFW5trZ7JrWa qF40kr17W347G3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j6r xdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2 IY04v7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAF wI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7A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htva4t40X4TFrgUZHGRkho3LswmVsgLkUE9yKUp82zwJgjQFlDkHOLOcrR7ushrgcpavW5MhZ+ouO6klgsVH4elyo9UNEU6CZvhreNDw/9qmhJpalv/YgU+N0NWpk4Qcs+EtVw/iS/vtGE1/1KFa1M0OdyuayoAnUWJ5j5hWZI96M4qvg//Wnqq4jzuD2058v4JOSGF4fzdc5i0DRtKG5y6VjNWhCfhcHck+skVYooHHgwqLCn08ztd6CajcXKFp3TGi9WQp60OAQKM+w3CHhlSU3HrH62SUmKdUnC4XjKMC/soJWMJI RkOSoUNE uav2PeP7I7YvX4GiJWZwxyHh1WiuiF8naDAKeDjCt9RFbnlxd8rvy4HdArMeanyv3B7l1CTsYc9A6Ag/RUQa0jJKgDYNO9sApsR0pfMXWLn6Jg70kft8mk9qNs2fEVOh8C4Empm4T77pM9hQ3rkbxH74GufhobZISCeWBMmfrD8qFaBdKbh2w8FgV2doi8UyzyJB2Z/OYQ2f8B5aRs1N/lf1Jyk6K1ataJWtzZxhWWR3dwr+yiCJUpmg0ElvfYmtXQ5ob/mMkyGVZrquuuUfO4RBFc9LLYHOpOgyafbAVICHLdk6K6uX2EOlRpopuLbTcZwR6DPn4YFDBgnYib2n0J3g+sg== 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 13:28:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624585 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 0752BCD128A for ; Wed, 10 Apr 2024 13:38:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A0C06B00AD; Wed, 10 Apr 2024 09:37:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2515A6B00AE; Wed, 10 Apr 2024 09:37:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07BB46B00AF; Wed, 10 Apr 2024 09:37:17 -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 DBF106B00AD for ; Wed, 10 Apr 2024 09:37:17 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id ACD68140654 for ; Wed, 10 Apr 2024 13:37:17 +0000 (UTC) X-FDA: 81993723714.10.CDD0016 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf05.hostedemail.com (Postfix) with ESMTP id 377C2100005 for ; Wed, 10 Apr 2024 13:37:09 +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=1712756231; 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=MxpibkIMa2EMfSPO8tazoGeDCPVUM5J+zrKHshFe1kVr2SqzFsKQxFeRqO5V8e3B5YKy0z 0iptd6sx/scRCIlzw9zCax1eiSmj7Nw23Ia0EeJixPhFoHKnlRdqZQI6bOUJKVtrFy3v4V B630+S5nIfNRZvSmSeWEJZnV+sa906o= 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=1712756231; a=rsa-sha256; cv=none; b=nRNH1GYyezCqZPBZpW9aKEQ5x+grqqNUWibk134Q6Rh8KI0TbjXVhKAPdbT9odPOf0IGik mH+44oQ2ZQREO3qKsXMFpmSmzmjnjAV8HZoLCXB/zkppIAxLxZ33FwT9hMrJNYkkc+QVK7 eFdqQdndRvE7ULwUyPDhv1D8G3MAHgg= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lf0fnfz4f3jZd for ; Wed, 10 Apr 2024 21:37:02 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 7F4291A0568 for ; Wed, 10 Apr 2024 21:37:06 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S34; Wed, 10 Apr 2024 21:37:06 +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, 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 21:28:14 +0800 Message-Id: <20240410132818.2812377-31-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME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4A2jsIE14v26r4j6F 4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Cr1j6rxdYxBIdaVFxhVjvjDU0xZFpf9x0JUArcfU UUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 377C2100005 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: mrwo86d6desr6ndnz1rsnjdpzokfo66z X-HE-Tag: 1712756229-88437 X-HE-Meta: U2FsdGVkX19jt8uoVR0MZf8/UDXxzgFMizK2BCC1dSVqZJd1rFeIdkqNCcSsxrMs7bTdiBM2PhzYD6m7akpu2UQrO1YGMCropuEo4XgCLiznRw3IBKuSP3+7oW8d0K/eXQSrQ1exQuSasEt0ieB//i2eCS5BWAvvrzPZ45tnHkxJQnC4c0z82+LmhmR2x7y9rg5DRH1aYcHi1dbx5mKKVoY/+cEsfAUV5QQuYlEW7wfs5TqZwSYAm/SWLwzXjATiXuXQDalorUl7WiIHMyX1MSAUvM840VxuSyDau45jRTxX6zYxHAI/ovpHxCfufUUzkryirEKqjLD70uwgP1hGsaj5hlEKVN5CKyAeXaOhlcLDCiAIK246dU7GfdCH0yZW9R7XzgEvGPI6E9+oCVNizaAN6Wdlf8vwxRZUvPtwcfY4Hls/jK8JRB8kmvgtYkVPn54P5mvdZIyMz3EKzuxgxsF0onwQthNYbq2Rbg58t0uz+rVhAzkfFIRTx7p/8KskLhIWk4TI2mDuiqkkYGoSO7oUHH4TBq8HS6KAxx+f+wUN9w++PjTTNkMjF+6JZ7EgaLgDa5ggi99Nci8EWQ/udYl90tU9mSMNYUywawrcNkiHIXsUIDcMA6AqDCQs4KY0dsusOpNWueGNuH3U/qXGHnc86tYBuqL55VnduLCSm90r6eVeDe7+izcSywHYkTwLOh87v0A+IklcCVOi9E7U8uV2i2qN3WxHGtl0TWXCbyTyABZeEKzzW5w9PumqZVpGOJOvrYyBda+w381J8yOmmpShu+PR4cF4Rlf+JSr69V6zfqcNTgxBs1fzxwGN4q11MzaNCHQYhGFCUcSTNdKqdKu1HkoDnpeMxLyGs7FFqtVmO4bXT8IGFYQ1ZtZNHRslghDM0581qdyUoX+o3eBC0GDtQDwNbejfBvSZxMAajhBeRhPkMHnndnz+OTehKUsMXEzfEqihHa9k5D3NONg 9FDRo3IA 3Rfz52nUkeQnbK9mKBPtJRXhy9JKv0x4INLFP7r5gUnaCvHofhQXAUJOJFp57mscj04+Z9OZO3lCE7cV5IQkmDelV53WrE5n6YVIFFWoXu8Bk0ibW4DLKnmyyRRUGLFcyA+1BF/ac6XbWXp+UlK7qQti3lTsQsyumH7a0IIQ3CpTgCTHqMPdNe3L+OdyQ0VZ/PtmnwfKDY7QUMXgcrtsP8XoUB890R4suArI5n4iBBmnSpwq5+P0yVAmvSH1QPxqLLj7J 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;