From patchwork Sat Jan 27 01:58: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: 13533896 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 B444FC47DA9 for ; Sat, 27 Jan 2024 02:02:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD7056B008A; Fri, 26 Jan 2024 21:02:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D5556B008C; Fri, 26 Jan 2024 21:02:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 52AFC6B0087; Fri, 26 Jan 2024 21:02:50 -0500 (EST) 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 01A296B0087 for ; Fri, 26 Jan 2024 21:02:49 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9C562A1CEE for ; Sat, 27 Jan 2024 02:02:49 +0000 (UTC) X-FDA: 81723442458.30.ED7C2C6 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf22.hostedemail.com (Postfix) with ESMTP id B3474C0019 for ; Sat, 27 Jan 2024 02:02:45 +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=1706320967; 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=OeRvB9hMis2SFRCTB3XI733Q86WrQ5pD2A6MCYZWG6Q=; b=dM3A7CGOhxw+m0ArwqhzCMwUko22qAqu4PlgDc9ucbwmkso+6yCqjMdlEums2WUDZwGpxS V3VYn0gS/e0m9n/yAYiSNIm7dwT2lsWgzIfT518ZZvjIp+2R1zZI3gmdkcvdljePwT7rJh N8sBSOdct7hvhna0O6mt8MNAbY28rFc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320968; a=rsa-sha256; cv=none; b=GsCX+a/UG5Bj3h6aTz7sc7clp89xF+Rx4mJ9QAZlz3/4wbDUWh5UnnZlomvQ4XL0yGWv3S 21ueOasf5H1xctQ1vc0f3yJmMus24mzWUNer79WHtvykuY/ufb+WqRURk2ktGjD0Yziq0n Q3er7LDMIFiU9/9tX8u9BvRDVvWMuXs= 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 4TMHrT4R3Qz4f3lg8 for ; Sat, 27 Jan 2024 10:02:33 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 000241A0232 for ; Sat, 27 Jan 2024 10:02:39 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S5; Sat, 27 Jan 2024 10:02:39 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, 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 v3 01/26] ext4: refactor ext4_da_map_blocks() Date: Sat, 27 Jan 2024 09:58:00 +0800 Message-Id: <20240127015825.1608160-2-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S5 X-Coremail-Antispam: 1UD129KBjvJXoWxJr17JF15uw4DuryfZr4rAFb_yoW8uFy7pr 9IkF93Wr1UXwnYgF4Iqr1UXF1fKa4YqrWDGrZ3Ww18Ary8AwnagFn8tF1fKa4rtrZ7ZF1Y qF4rKry5uw15GrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBE14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMI IF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUszV8UUUUU = X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Stat-Signature: 5167ci66dwowdx3u6me5kmbbb6d6pixz X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: B3474C0019 X-Rspam-User: X-HE-Tag: 1706320965-693367 X-HE-Meta: U2FsdGVkX1/pnRLDU+8/AyqTbmYsy5/v65CVlmVxEaeVppetOdcEABm+2vi/e+LV3kVMi6aHw5SiFF4S7Gi8IZI3mdoxyjEZJ6tzYIjjjZxWqCKOsTFX0eZxME/fBSLMu0ClU+uDh2+DtfBQYOp6NqloCK1o6bjv4tVRJgJugiODHsoeCn8p6rqeMS9/3wSHS8yII156Z1543C6aCAlGRfNJoHc/tHygdmiy/H7urmRQpokb5vUXZzPJL79+zeHLVBkWbfEI6LQ6aehuiwurml8QzdEn5H5iTSmFPv2cWi5xv3hjh/+0V5soyOJo9Q4TLCThBu4avzgnH95rVgbH/h/wWh0NZ60oHgMALM5spaJ5MlqNfk34cquqe1LEN7BTIj/KZtzPmT1heKcFwyqLyjlaYQEU1q87cHi//R3vilOo3/lcS9uU6chGy7XvNU7DMXHMpGWCL1IHKe8d1Zn+yxdvhxiPbElMJA8PkcYKVjM4QinbFgiHB+H+15zChniu+9fIi04LrB12gIpIwEvrbIPx+9V9dJ8NzK6nxafazrB//VSjpQZQDQxX8cg+bETHStjPF+ju/WJUPAzjkAOUKkBh/VCAuwcgXR5SuU/hn/D4qbhYztmQOC3Gg+nyaUnYPi5lBDevzY9Dx+7pXj4GxAqgYesBjyrP4hSPgrW+Uh8B7OwHKj5I3w5Ri+M7lJQeDd51+Hun+3GYWHMczm+JAQaz/NGnBNsd5EQOeVYfgjW6Fp6VFe3XJvXoe5/H4jdjtSM0zqb0L3rVw5pB5flhQXM4AnItLcCC4uf+EhWwJTbRbheJDwg57iclzOHJ/fh75G7j4KaA+0CgsoZw2hRB2TeSuzxAxjUborZ7TgcAuCMJFm7jMxAm+VhFQ0Oi+KPfYU0JUQg4qvIeFPgAcKNJGaZaBLARwXWzdCtKtYiJFmoHR7CTkFWqRHFLDi+gC5BCb2+HEWuqeLqQ6xNIpIU vBFB8qri KaKQVPi2dptbNOdVhenBg9YjTQ3Qj9THXD3IKIfp48jUgwPZGJnXV51niWlldbUknzPpZ/Xw3iM5FF1ZgqwhcJGQRcut2Q/ZJiI+GlFbsRDHc+wqgvqNqN1iO9rTd8AttVJxDZ+SrhPULATsrZriQTSlRtKlKRHpFutuBPrSgpv9jpYbfItWa0TLkrc9XEnf+rD645OnmAeVM696ChlJZyY60LcG78VFPmIMCBLWomaMgHcF2fyVeQwFiAViatvT7u3PCihVnLI6tAgj5NbqmFdkWYg1nYB7zfjgt3BIrPupNqzhTGKqe/88YKLtGF1hMDFfLN+YzWKaHVdQKfPscjPEv1Q== 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 Refactor and cleanup ext4_da_map_blocks(), reduce some unnecessary parameters and branches, no logic changes. Signed-off-by: Zhang Yi Reviewed-by: Jan Kara --- fs/ext4/inode.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 61277f7f8722..5b0d3075be12 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1704,7 +1704,6 @@ 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)) { if (ext4_es_is_hole(&es)) { - retval = 0; down_read(&EXT4_I(inode)->i_data_sem); goto add_delayed; } @@ -1749,26 +1748,9 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, retval = ext4_ext_map_blocks(NULL, inode, map, 0); else retval = ext4_ind_map_blocks(NULL, inode, map, 0); - -add_delayed: - if (retval == 0) { - int ret; - - /* - * XXX: __block_prepare_write() unmaps passed block, - * is it OK? - */ - - ret = ext4_insert_delayed_block(inode, map->m_lblk); - if (ret != 0) { - retval = ret; - goto out_unlock; - } - - map_bh(bh, inode->i_sb, invalid_block); - set_buffer_new(bh); - set_buffer_delay(bh); - } else if (retval > 0) { + if (retval < 0) + goto out_unlock; + if (retval > 0) { unsigned int status; if (unlikely(retval != map->m_len)) { @@ -1783,11 +1765,24 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; ext4_es_insert_extent(inode, map->m_lblk, map->m_len, map->m_pblk, status); + goto out_unlock; } +add_delayed: + /* + * XXX: __block_prepare_write() unmaps passed block, + * is it OK? + */ + retval = ext4_insert_delayed_block(inode, map->m_lblk); + if (retval) + goto out_unlock; + + map_bh(bh, inode->i_sb, invalid_block); + set_buffer_new(bh); + set_buffer_delay(bh); + out_unlock: up_read((&EXT4_I(inode)->i_data_sem)); - return retval; } From patchwork Sat Jan 27 01:58: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: 13533895 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 8CE35C47422 for ; Sat, 27 Jan 2024 02:02:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 82C2C6B0087; Fri, 26 Jan 2024 21:02:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 68B316B0092; Fri, 26 Jan 2024 21:02:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B9046B008A; Fri, 26 Jan 2024 21:02:50 -0500 (EST) 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 041686B0092 for ; Fri, 26 Jan 2024 21:02:50 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 96D0F80821 for ; Sat, 27 Jan 2024 02:02:49 +0000 (UTC) X-FDA: 81723442458.28.2A4F4E4 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf07.hostedemail.com (Postfix) with ESMTP id 479D44000E for ; Sat, 27 Jan 2024 02:02:44 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf07.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=1706320967; 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=LDz98XSxYiJRQC1cVb6S82GBYBYojLb8QpdBTLPL8OI=; b=TUV+F+4hvwmkTiHmTKc0a1+NhYrJzDOJmXV7iPAoVINkN1WHLmjqiU/+JWWR95+/I0cNml c0hRrR30tt5dVBqsHqg8LfyeCq/uDjNYFCnWNA4DFgvHLVjBuebANmZGdbsZEc/IYPzdFr C9bVFbzF/W0PMzSZecghXTVwkvG2zjg= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf07.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=1706320967; a=rsa-sha256; cv=none; b=Ig4jU0EjDTGV7+Bt4C3J2OZzdz+51+NQkN52z7PfeatdHT8UpV77kGAigrkLzoE33yJHEV cAvDS2uHwjhSXmiRDzmOUPNK81j+DjHQWDbDpEwzeVvPO/zcKx4v0NJDm5Gh52YSLfH6Py QVSS12UlWEj2HHHti9BSPQ2qpT2sKr0= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TMHrX4dRhz4f3lwH for ; Sat, 27 Jan 2024 10:02:36 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id A1C621A0272 for ; Sat, 27 Jan 2024 10:02:40 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S6; Sat, 27 Jan 2024 10:02:40 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, 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 v3 02/26] ext4: convert to exclusive lock while inserting delalloc extents Date: Sat, 27 Jan 2024 09:58:01 +0800 Message-Id: <20240127015825.1608160-3-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S6 X-Coremail-Antispam: 1UD129KBjvJXoWxJw4DZFy8uF4kXr1fZry3XFb_yoW5Zr4kpr ZIkFyfCr1UW3ykuayIqr17XF1xG3WUJFW7GFZxGF4UZFyUAFnaqF1jyF1aqFyftrZ7AF4Y qFW0qry5uayUCrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPj14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8Jw CI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUoSdgDUUU U X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 479D44000E X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 1fcxerc4xt681dizjob1gfa4xq95rfcj X-HE-Tag: 1706320964-712304 X-HE-Meta: U2FsdGVkX19hUdQS1XUjga/CvAnn3dLVu6ovFNkwTazMA6GbVy3fNXp9OYfSQatmQA8llq+nvrmlDd5QMPGX9kjSVqan8phSQh4O6H0pnz8EOcmLLHO9gGaBD+1jQ2RK8S8xc6YhNzFH8ISv1WYbaGOx3G6fnTuqlRtepDI/ZLnBnhDobw3AOnG94JH2UeWrOa51yf/G4SrkpCOs2rnSnyGuWqo8SXlZEAo8bVwlow2m+9aHbwLML6agixm8OVifLeB4ppb+u38e0jDdAvfY94QtD0BDv1vboGth8M+aahvQw6hiQ1Q4Uc/QbHMxvgoPjjuse+shB/7jOpcIvn/DPdRjWNHMqE4p4Wi9gkeFZvBndFI/adfQwxhw/6tw9Cm3LQFl2zntmKmpP6cLhWdlqIHBSbGM1+B6q45+Gr8zl7o9HKqFCECSFzs5Kmz9OpK4ujlYs8KCH33cn9sIk6IlLQYt9nkzQoC6xj7oVVsL0mvqNcSq95HwA8mCbGOD3T0+kM4oPfgxIrnjqpmvd+9HqPWSxmV+soCstT6vVQDS1KCvpWfz9pmJA/ttq0ogQOQKSVhuZL2M8byPuj/Fw1xf5eT9TYmDDieY5K7RnLEZbB0m5X93WQfRLUjqzDhUWhEvGE0CWl3SlhstVMy/B7saDeV/f8ZutZQ/Ljx7R7LLI9PVAqiJsAYWneq4YlN6gRH4tgoo4nQ+UhzqR6b8td7vX0BsAoslthBf19sp3svEXDev0w6f5ct4Rvf0ClBlOgxyLa5r8Ygdr+ccg/vnL8uto+30tOHOHs877dHW2Tjo4+K6/W1QeuA1qQRd/uJ8mQ30V6EkXVK7A5NkKUJau/XlXJDClHzLh3VUmPYz+K10AgPhXsd9//i90zZVXReTtV76koEhupoJuUcFhsJ+P+QuFO2OzIdQkCy7fW4HEbSzmXsv9Woykq3r3CsyRylZzQrEKLGSgmi7Se7H2LmDyg1 tSUhJtZ5 Sf8dCXtqIX8PcqfpddITKIiaHH1SsWqaprBGlOjbEL0pb8WPq6IH9XVoG2SQjheYy8tkuLwjibZan5jTBq/G3XI/ZwgGWMCDvoKvSfptDVq2HEgEjuPPMbfYb2fuudRaSB6eMx66sRY3BF15FVAyiaCskB/nzc8LjGavHKKlwtub589HY+fU730poJJAfM0jzXkPEE3QPumjTG6stb/U/lzXOuVCX0N0VcHlkBqawIQpTR3F7lnWcISvOQoWvYeHTkwKfrjqUocHQMLVvYV7gxgZD7jaYdgxyaipc9yMAW26vV9rOH2il02gVZA== 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_da_map_blocks() only hold i_data_sem in shared mode and i_rwsem when inserting delalloc extents, it could be raced by another querying path of ext4_map_blocks() without i_rwsem, .e.g buffered read path. Suppose we buffered read a file containing just a hole, and without any cached extents tree, then it is raced by another delayed buffered write to the same area or the near area belongs to the same hole, and the new delalloc extent could be overwritten to a hole extent. pread() pwrite() filemap_read_folio() ext4_mpage_readpages() ext4_map_blocks() down_read(i_data_sem) ext4_ext_determine_hole() //find hole ext4_ext_put_gap_in_cache() ext4_es_find_extent_range() //no delalloc extent ext4_da_map_blocks() down_read(i_data_sem) ext4_insert_delayed_block() //insert delalloc extent ext4_es_insert_extent() //overwrite delalloc extent to hole This race could lead to inconsistent delalloc extents tree and incorrect reserved space counter. Fix this by converting to hold i_data_sem in exclusive mode when adding a new delalloc extent in ext4_da_map_blocks(). Cc: stable@vger.kernel.org Signed-off-by: Zhang Yi Suggested-by: Jan Kara Reviewed-by: Jan Kara --- fs/ext4/inode.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 5b0d3075be12..142c67f5c7fc 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1703,10 +1703,8 @@ 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)) { - if (ext4_es_is_hole(&es)) { - down_read(&EXT4_I(inode)->i_data_sem); + if (ext4_es_is_hole(&es)) goto add_delayed; - } /* * Delayed extent could be allocated by fallocate. @@ -1748,8 +1746,10 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, retval = ext4_ext_map_blocks(NULL, inode, map, 0); else retval = ext4_ind_map_blocks(NULL, inode, map, 0); - if (retval < 0) - goto out_unlock; + if (retval < 0) { + up_read(&EXT4_I(inode)->i_data_sem); + return retval; + } if (retval > 0) { unsigned int status; @@ -1765,24 +1765,21 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; ext4_es_insert_extent(inode, map->m_lblk, map->m_len, map->m_pblk, status); - goto out_unlock; + up_read(&EXT4_I(inode)->i_data_sem); + return retval; } + up_read(&EXT4_I(inode)->i_data_sem); add_delayed: - /* - * XXX: __block_prepare_write() unmaps passed block, - * is it OK? - */ + down_write(&EXT4_I(inode)->i_data_sem); retval = ext4_insert_delayed_block(inode, map->m_lblk); + up_write(&EXT4_I(inode)->i_data_sem); if (retval) - goto out_unlock; + return retval; map_bh(bh, inode->i_sb, invalid_block); set_buffer_new(bh); set_buffer_delay(bh); - -out_unlock: - up_read((&EXT4_I(inode)->i_data_sem)); return retval; } From patchwork Sat Jan 27 01:58: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: 13533894 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 86D04C47DA9 for ; Sat, 27 Jan 2024 02:02:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A84A6B0083; Fri, 26 Jan 2024 21:02:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 41FD56B0095; Fri, 26 Jan 2024 21:02:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F257E6B0083; Fri, 26 Jan 2024 21:02:49 -0500 (EST) 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 D1BC96B0087 for ; Fri, 26 Jan 2024 21:02:49 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A89211A0FFA for ; Sat, 27 Jan 2024 02:02:49 +0000 (UTC) X-FDA: 81723442458.30.8B0055C Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf12.hostedemail.com (Postfix) with ESMTP id 3440140010 for ; Sat, 27 Jan 2024 02:02:45 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf12.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=1706320967; 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=wSf1NcIMWRvjDJDKI/OHBqUKBoVpTLWWYixqR/BPt/g=; b=fWhHfNgngFsRYwv6ocztuYtxIU4OvMiVF1MdX2YXkG5MLrCjbNQadg1ZsaKnfqTmvzHEri kFZrGn0c3GOxWJVqMN2/nIw4zwkQ4EVc30gXZ6E9N+JT9sP9ygnrnMHJyKMuBrDNQg67wR aLiRCFrwy5omhI5M1X3urDO/wfr1IcI= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf12.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=1706320967; a=rsa-sha256; cv=none; b=BmIj1KB7PgpdUJmDmK0oqrhcD0wV255OYOy3hbORMG58lhiQKpQUjulK8j3zEwCZJ1bluV CFHAYZXlTEF4YNo7xPegVaS36mjWO8dEJxFndHLdZXoY0ixTVv9zWgsL4TzsDuQQY+pVkZ LoIC/4Z4VPstPbln1jOInKU8lFwoBa0= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrV6ldjz4f3lg0 for ; Sat, 27 Jan 2024 10:02:34 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 4F1FD1A016E for ; Sat, 27 Jan 2024 10:02:41 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S7; Sat, 27 Jan 2024 10:02:41 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, 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 v3 03/26] ext4: correct the hole length returned by ext4_map_blocks() Date: Sat, 27 Jan 2024 09:58:02 +0800 Message-Id: <20240127015825.1608160-4-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S7 X-Coremail-Antispam: 1UD129KBjvJXoW3Gr1UCF4DJw13Xw47uFyrCrg_yoWxJr13pF Wfury5Gws8W34q93yxAF4UZr1rC3W8CrW7JrZ3tr1SyF15Jr48WF18KF12vFZ3tFWrJF1Y vr4jya4UCa1akaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPj14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JrWl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8Jw CI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUoL0eDUUU U X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Stat-Signature: dintgkrno47x3sbx6gwt3oiy3m1x84uk X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3440140010 X-HE-Tag: 1706320965-590566 X-HE-Meta: U2FsdGVkX1//QWhEumNZ8Xa7h92vo8ZeQkOSOUW6U0UgvuozC3FSmW7S2VUN2BYOkEJsGaNMYuD286UtPvpLfljDWFx3cVtKEn24mlCOLZpT+cnIqcR0kgrH1sjcYZgJ4jihiinv1SbKcppfrFxPSFOi2Tc+3MhsezogaCZovZvccPR1aKFgczA4bGeERo98Wis81vqlSo/eJn4VsKo/Wtf0AgC/DvMG0Ymr/7Mc8+ydyNFkTS9g+FLYv6i4g7mdPTJcO57skL0CqWDoUMrqfv2Al/71IBkkJ/kXx6GDyJ8pyaqfmdH/XKlsM+LsaWT1q3WaVUtKzEacdPiNidStmIyvSmPjNnBfM+UwvHDd1kFZWJRIgcGRAL6DQImSfb8XbHS0GZSQoILQLpvInyCVmbNJgSHHjRamsxcJdDPPCEDxP6Wzz4Uw9H5U7JmFKKaAOfquotoQjDeOgC4yH51INkYz/wwK5zgiCcymwLjND/pGZjNinxPc3+ARlqYIuEoxFxAc0Pf69vh6V3rBtVf+qApOcu2Q0avUkuP8jzlXQcN+NTu/zPOlTVVcC0bqrPtg5fnPikCGskiwG191jXw2G8rqhj3yW+7jacJvMnEsAIe9SoUxS9FEqZ2qIN2ImkYo6CBTKS+jRCEwc+3O+aBjyx5Sid7TF7sbAvoVjCoeh+oWniyswQm0db533HrGPJe0hjgPafCphMAA2f9qLBIGWhNwPHLLv2LwIJg6GRoLpvGyEx2oD0jVJ+sPJtQq/xmxKVltHx8m6RPuksncOzmBj6hysse3vRQoVAx2YWla7cv6lomefJU72plF1NBN8M9LkGkFUMZyLO35ATBp2HeYQtSza5CtOHFQWNlkI1A6KfQ7NB0FgtZAcscGP7e9fsZELBCxLbWUoAPsPH2dm3uFTxiHmTFnWLx745oBbDCDy/rwwH4uckaActVKseu5VuSlLfZ2lV1OFvz57acpi2D JxJYN1dw t+zY90h6sqDukfgmdQ4eoNkqj8XpNqwE8YJHVfPYCjXrQYe5BIix1LDSOzs0ZEoyltcKUTtmSglVRm1PwS2NuCYD24WPx27MRtnD4cGyvvl5I8iG4GcNdxfl33H7l5DXVs1hTcPYy4FHSu+5ED65a6pYsJq6T/0WvQKbXyEAgue2+WWnEfTh0bTb9RhTscSEl12EU853N2gbt1KP9oVPvhYk0dh7BIKv3I8VrCg/yOSxD5vqE9ve3bskxvq60ORz+yjEIq5V49Ta4/0iFd20+wIK9nIIpfgf5fhwKEzNB0G5ItGY= 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 In ext4_map_blocks(), if we can't find a range of mapping in the extents cache, we are calling ext4_ext_map_blocks() to search the real path and ext4_ext_determine_hole() to determine the hole range. But if the querying range was partially or completely overlaped by a delalloc extent, we can't find it in the real extent path, so the returned hole length could be incorrect. Fortunately, ext4_ext_put_gap_in_cache() have already handle delalloc extent, but it searches start from the expanded hole_start, doesn't start from the querying range, so the delalloc extent found could not be the one that overlaped the querying range, plus, it also didn't adjust the hole length. Let's just remove ext4_ext_put_gap_in_cache(), handle delalloc and insert adjusted hole extent in ext4_ext_determine_hole(). Signed-off-by: Zhang Yi Suggested-by: Jan Kara Reviewed-by: Jan Kara Signed-off-by: Luis Henriques (SUSE) --- fs/ext4/extents.c | 111 +++++++++++++++++++++++++++++----------------- 1 file changed, 70 insertions(+), 41 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index d5efe076d3d3..e0b7e48c4c67 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -2229,7 +2229,7 @@ static int ext4_fill_es_cache_info(struct inode *inode, /* - * ext4_ext_determine_hole - determine hole around given block + * ext4_ext_find_hole - find hole around given block according to the given path * @inode: inode we lookup in * @path: path in extent tree to @lblk * @lblk: pointer to logical block around which we want to determine hole @@ -2241,9 +2241,9 @@ static int ext4_fill_es_cache_info(struct inode *inode, * The function returns the length of a hole starting at @lblk. We update @lblk * to the beginning of the hole if we managed to find it. */ -static ext4_lblk_t ext4_ext_determine_hole(struct inode *inode, - struct ext4_ext_path *path, - ext4_lblk_t *lblk) +static ext4_lblk_t ext4_ext_find_hole(struct inode *inode, + struct ext4_ext_path *path, + ext4_lblk_t *lblk) { int depth = ext_depth(inode); struct ext4_extent *ex; @@ -2270,30 +2270,6 @@ static ext4_lblk_t ext4_ext_determine_hole(struct inode *inode, return len; } -/* - * ext4_ext_put_gap_in_cache: - * calculate boundaries of the gap that the requested block fits into - * and cache this gap - */ -static void -ext4_ext_put_gap_in_cache(struct inode *inode, ext4_lblk_t hole_start, - ext4_lblk_t hole_len) -{ - struct extent_status es; - - ext4_es_find_extent_range(inode, &ext4_es_is_delayed, hole_start, - hole_start + hole_len - 1, &es); - if (es.es_len) { - /* There's delayed extent containing lblock? */ - if (es.es_lblk <= hole_start) - return; - hole_len = min(es.es_lblk - hole_start, hole_len); - } - ext_debug(inode, " -> %u:%u\n", hole_start, hole_len); - ext4_es_insert_extent(inode, hole_start, hole_len, ~0, - EXTENT_STATUS_HOLE); -} - /* * ext4_ext_rm_idx: * removes index from the index block. @@ -4062,6 +4038,69 @@ static int get_implied_cluster_alloc(struct super_block *sb, return 0; } +/* + * Determine hole length around the given logical block, first try to + * locate and expand the hole from the given @path, and then adjust it + * if it's partially or completely converted to delayed extents, insert + * it into the extent cache tree if it's indeed a hole, finally return + * the length of the determined extent. + */ +static ext4_lblk_t ext4_ext_determine_insert_hole(struct inode *inode, + struct ext4_ext_path *path, + ext4_lblk_t lblk) +{ + ext4_lblk_t hole_start, len; + struct extent_status es; + + hole_start = lblk; + len = ext4_ext_find_hole(inode, path, &hole_start); +again: + ext4_es_find_extent_range(inode, &ext4_es_is_delayed, hole_start, + hole_start + len - 1, &es); + if (!es.es_len) + goto insert_hole; + + /* + * There's a delalloc extent in the hole, handle it if the delalloc + * extent is in front of, behind and straddle the queried range. + */ + if (lblk >= es.es_lblk + es.es_len) { + /* + * The delalloc extent is in front of the queried range, + * find again from the queried start block. + */ + len -= lblk - hole_start; + hole_start = lblk; + goto again; + } else if (in_range(lblk, es.es_lblk, es.es_len)) { + /* + * The delalloc extent containing lblk, it must have been + * added after ext4_map_blocks() checked the extent status + * tree, adjust the length to the delalloc extent's after + * lblk. + */ + len = es.es_lblk + es.es_len - lblk; + return len; + } else { + /* + * The delalloc extent is partially or completely behind + * the queried range, update hole length until the + * beginning of the delalloc extent. + */ + len = min(es.es_lblk - hole_start, len); + } + +insert_hole: + /* Put just found gap into cache to speed up subsequent requests */ + ext_debug(inode, " -> %u:%u\n", hole_start, len); + ext4_es_insert_extent(inode, hole_start, len, ~0, EXTENT_STATUS_HOLE); + + /* Update hole_len to reflect hole size after lblk */ + if (hole_start != lblk) + len -= lblk - hole_start; + + return len; +} /* * Block allocation/map/preallocation routine for extents based files @@ -4179,22 +4218,12 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, * we couldn't try to create block if create flag is zero */ if ((flags & EXT4_GET_BLOCKS_CREATE) == 0) { - ext4_lblk_t hole_start, hole_len; + ext4_lblk_t len; - hole_start = map->m_lblk; - hole_len = ext4_ext_determine_hole(inode, path, &hole_start); - /* - * put just found gap into cache to speed up - * subsequent requests - */ - ext4_ext_put_gap_in_cache(inode, hole_start, hole_len); + len = ext4_ext_determine_insert_hole(inode, path, map->m_lblk); - /* Update hole_len to reflect hole size after map->m_lblk */ - if (hole_start != map->m_lblk) - hole_len -= map->m_lblk - hole_start; map->m_pblk = 0; - map->m_len = min_t(unsigned int, map->m_len, hole_len); - + map->m_len = min_t(unsigned int, map->m_len, len); goto out; } From patchwork Sat Jan 27 01:58: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: 13533899 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 83837C47422 for ; Sat, 27 Jan 2024 02:03:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9374F6B008C; Fri, 26 Jan 2024 21:02:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 83D316B0098; Fri, 26 Jan 2024 21:02:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41BBA6B0093; Fri, 26 Jan 2024 21:02:51 -0500 (EST) 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 2AB296B0096 for ; Fri, 26 Jan 2024 21:02:51 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0C07D1406D4 for ; Sat, 27 Jan 2024 02:02:51 +0000 (UTC) X-FDA: 81723442542.15.EEBA158 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf19.hostedemail.com (Postfix) with ESMTP id 1103C1A001D for ; Sat, 27 Jan 2024 02:02:47 +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=1706320969; 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=kATHz1/ug5teIHGhsTsvlMF8lutPolqn5X3kiv7q1y0=; b=r0e+471pppjdjclLFEQiN34Z1oQZWcvou2Z+SCwiwbu30/lRVBX2QydKZ8obQNrjFs41ZN 7sjCjOueFDDAZnrdgUg5em7W6hzhCw5/BdL+mdkKDCxrAeKOEZZ54c657PElTUBjDet4Ja JhGqT/L6Ugo8ltbeG4H9ed9e6PM2xpg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320969; a=rsa-sha256; cv=none; b=duxiwsG+9e+NyNZowG1WZLMiR0hYCJ4g8CcEoFiuuk1SpJAbDQ6nJ8QVpOhvAqplbQA/SD nWF8qjp7X72IDAUEovNReCHMfywStpfMYVQfD2j+YcLi4SwugEdq2Q1UdMVV53ryXJaQA3 QWijKWaCfJTBtBEVVb+hqghLIqUYsyA= 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 Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrb3tbrz4f3k5Y for ; Sat, 27 Jan 2024 10:02:39 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id EF3F11A0171 for ; Sat, 27 Jan 2024 10:02:41 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S8; Sat, 27 Jan 2024 10:02:41 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, 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 v3 04/26] ext4: add a hole extent entry in cache after punch Date: Sat, 27 Jan 2024 09:58:03 +0800 Message-Id: <20240127015825.1608160-5-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S8 X-Coremail-Antispam: 1UD129KBjvJXoW7Ar1kWr15Gr1DXFyrGw4Durg_yoW8Xr4Dp3 98Ca4Sgr1kW34kuan7XFWUXr1293WUGw4UXrW29w1xWFyUA3WI9Fn09F43Z3W8KrW7Xw4F qF48KryY9w1Uu3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPF14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJV W8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUoxhL UUUUU X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 1103C1A001D X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: pir1dzgstaw35dpdgpi8ubim4hxrihcp X-HE-Tag: 1706320967-857375 X-HE-Meta: U2FsdGVkX18X1ob7SwXD9G4xRpeGmhHIffPlASXkLDYzOTZexIEdtWjRqtDuNsjeAimHwLQ1TpK1PbffV0rnFtKeTqQgd4RxjNEf+vlbISTvd28ELAsUD+wJe4fg/xmydmeqLpKCdUjK8NNiA+wb9jc0gdn+/ZCTFqT/wyyfv7B1KpTcAKe6VJkLYLAjcd1S/sl49qac1SqUrdgqymnx7y9ugVbIhkfdzq/vlAlW0bbLiIGITBMIEt7bPXxfW8fbNrTqLgaTzqJ3ndq6yu1g8+MGrY6ihuQjEDlhUqvvVaUfHLs9prHLH7G/O4au3cyW1dmd1Gs/3uiIzs2p9N7vvJTbeHg26GIrdEBqEWgsffe6US8YFdYPqLweGE2UFWEQEUG3As5yOKOW9jWqncFZDg0AET6NqJTdyn7xAco8zqtKmFK5B2h1Cu2Q6FvPvKjdMqujQwfFqLx2HzPkNpKAZDAyBzHPtSeuFFKfCqb+VRrBeOBpSmn+jnEeIOQjXU5xoSC/Zcom6zBXnpJrJBWSAFjKNDzKm4yEIScK0a9aA0N3BL+DcKFzWtt6Q55WYfMd57ZYHhpXVE8uRk61f44vyUD8JVLCTa/awdx005A3yumpUgnPz7+ROSf1KreZM2dUdF4SQOQTJZmbFqU7zCU1Cd0PoJaSOhoEKcbgXMB3U6TmsaUjqezXkfEjYCEFOgAlbmwGD7uGzlMf7ccImoJMqK5M/Yn3xnRw/LvWttbBX6+BVw8m9v2pzWwsBljOp/ztLo118BzIXraw4FrNVaTilnrHYLNuCa7QsVsK53Fv2738W+zOM9/FJrkKKvWjtJD5s01A12AVmyNo9wpz0H9EutY4w6FRWRNRf17IqvSpZ9jXG0N9Z7VKhV1Z0a6GPfJw+hIg1lHKD+HJY3KkCVt9nsmjM7J4H+CRqKy+8g8PRs31Tku78YhFT6bzPRv9XZRA7DLtSZrpkpS4TVURLil bp+5BGhI Up1EyHyQxFKaZN2538CKMUuCDYmFTVjC/CMOYso7AYL1hjHRew7Ch2yFVcY3NYngAwJ4XBzmnqHTnpReoehfdWvhOlqNj5Ji1UxZeAuOfFZ8HGLmi1i/Yc17zZlQvizP3IaYl6b18zuCwdOUIw5EkgDC/AtyQmp6aaQNWVa+ehA9JMEqlz+aOlwwdaJSrQIby65YTnbdTXV/RVTZ0eHPlnuCd2idpTcBOS+KZiuWYN4K5RlTHO8UdwXgeH5BoPZYA8xVy 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 In order to cache hole extents in the extent status tree and keep the hole length as long as possible, re-add a hole entry to the cache just after punching a hole. Signed-off-by: Zhang Yi Reviewed-by: Jan Kara --- fs/ext4/inode.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 142c67f5c7fc..1b5e6409f958 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4000,12 +4000,12 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length) /* If there are blocks to remove, do it */ if (stop_block > first_block) { + ext4_lblk_t hole_len = stop_block - first_block; down_write(&EXT4_I(inode)->i_data_sem); ext4_discard_preallocations(inode, 0); - ext4_es_remove_extent(inode, first_block, - stop_block - first_block); + ext4_es_remove_extent(inode, first_block, hole_len); if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) ret = ext4_ext_remove_space(inode, first_block, @@ -4014,6 +4014,8 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length) ret = ext4_ind_remove_space(handle, inode, first_block, stop_block); + ext4_es_insert_extent(inode, first_block, hole_len, ~0, + EXTENT_STATUS_HOLE); up_write(&EXT4_I(inode)->i_data_sem); } ext4_fc_track_range(handle, inode, first_block, stop_block); From patchwork Sat Jan 27 01:58: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: 13533893 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 1DFC8C48285 for ; Sat, 27 Jan 2024 02:02:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DF3E6B0089; Fri, 26 Jan 2024 21:02:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1CF856B008C; Fri, 26 Jan 2024 21:02:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E03316B008A; Fri, 26 Jan 2024 21:02:49 -0500 (EST) 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 C7A5F6B0083 for ; Fri, 26 Jan 2024 21:02:49 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A496DA1D59 for ; Sat, 27 Jan 2024 02:02:49 +0000 (UTC) X-FDA: 81723442458.02.B89A66C Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf22.hostedemail.com (Postfix) with ESMTP id 2BBFCC0015 for ; Sat, 27 Jan 2024 02:02:46 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=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; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706320967; 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=nDGmM1XnD1u3GRfMKazoP/kuf8eh300xJ6+WETgmkfg=; b=UJL0qldgdiGgrCQgKVv7tMrJ9Duva0sQBhxajQLj0wUhgFAN2Xaaf3cdZUbhg5XguKCHuB F8jH0wATXlPEyf6MczTAXkapP3ylQ3c1DgUQCkRJ7yEzpc51bLawmBg3gX78x6kdxDkSKj CAl+1aoVHpnJuosHEvWPjuXL4iKEcw8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320968; a=rsa-sha256; cv=none; b=VsEPYlKvrKxtKiKzDKXOAO3YqRxBOS76cEjhtymGLNnQ/fvS5EuP37vbA+vMJjRRj6omcC dXpQ8uV0sNvp1nPzbpJgw+J8HCOqQSKrQzo61u7abeD2zzbdY9uz24oKe9KA2EGYsDrR47 Mm8rDyQxFscWkV/7SBDlSOJ0LvFtVtY= 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.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TMHrZ4Qzlz4f3lwQ for ; Sat, 27 Jan 2024 10:02:38 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 9CF2C1A017A for ; Sat, 27 Jan 2024 10:02:42 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S9; Sat, 27 Jan 2024 10:02:42 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, 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 v3 05/26] ext4: make ext4_map_blocks() distinguish delalloc only extent Date: Sat, 27 Jan 2024 09:58:04 +0800 Message-Id: <20240127015825.1608160-6-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S9 X-Coremail-Antispam: 1UD129KBjvJXoW7Zw47Xw1xGw1DAFy8tr4Dtwb_yoW8KrW8pa 95GFy8GFs8Ww1q93yxGa1UJr1UKa48C3y7Cr4Yqr4F9F9xJr1ftF1q9F1fZFyYgrWxXFyU XF4Utw1UCa9IkrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr 0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 2BBFCC0015 X-Rspam-User: X-Stat-Signature: gycob8b4bamer8ik3ua6zyffu1qp7a5d X-Rspamd-Server: rspam03 X-HE-Tag: 1706320966-662317 X-HE-Meta: U2FsdGVkX1+jGRXFmdj72NqKuGCZj0Divtk877zW/FHOeo9Asb/2CpDwMxcTaxLKPbuKGJh0iV4mNLHmeiD1LMwGXRiq5vio/3HUvvmQ4eCa7nSoJvcQWKDJsMsyn8QkO+8QNWnKWUKt3hfgPqTvlskG1BTOF/VW1y/V4Trz+sjirFTDnk0sVTBWFHhqx49LyLIx2ZDOsIa8r9SePROwEhSxbGN1kHkmlOudMoPfFT+WZ0/dfuaNVGTiTo45YE3LwDyslN2domE9xVgBl36Dgz5T0uMotJaKQwWbUbSrLg8d1WaVCgFVr8WKumaVT2k3aXZbxh5GBtM0Aln3FwxMwWaWoTjXZBtzKlqhp1TPS4KF3uSP8owRpKTfw0bdbWxN4aBQUb/pxoH/RTR1/QffFTc91JZxpsccWq3IHmj5JaMu0ztnxLR/9ovKL+j9SbFWeI9p2A67uFRdqz0tPLiB8xdbowSpHCCAbHJ9rjcS/lQYLOki2oVe4u9cZzt3NZrTZkQYBrFIIkJDj2pd4CwXrcuCJy+SzFeZRG+rOJBf3qJYGoEbYUHgjJGnx6WwLq1I9nEbR1DXbjsGh0LQZUmPaN2kqJ8t5HhklzEysoYpKWQuzRmFibY6j3pwuEtSIj4P8jGov6h0VprQp9+xEhB3fjRG8AIlW6OwkN9zi/FiUFwXUfzFdSBTzcAwr/kXoV+CDCIDmI4s15dneBVhWqrksuwO6V6a0PkeWAU5QvhmqtcgCFW1zxNfu5Rk2+NK8kBRvX7eD/NKyFlbd1xMgbwxNj7ixOkMpUHRKYnfXiJ79JVQ1ebDi/XinrWTt5PHWQwW+2l2RXfoP1VA6hoY63ruGvFtdDjLe8gT0LpMjBJc80Onl7fjDubPN/916Y6QDAyfHIZbIytZ2UmtLvUz9fMCF+e8GsJxZwVCV6So8YYMTu4vlnkVapiEYX04MIBCneXrVrR0TuuBcJI8t2sUQdZ TCTS730f xQSY7aLueLg58GCoaJ5dA9/QqQug+0xI2g+c5Zg2TI1jndTJDfZJ2HU79rhwAw0nCQ6pUZUNLYcnUMDMasZ1dN08L9NfKMtVY533eduyvM0DPqmUnkGCQZkfEezwcHo+umMKV+XEfXblBoXCmp5j/RAkafeuMhrtmnhaYd73cm7ZKoCLtXHH8azF4lhznUkHQ5c3jmbytv/vsimnhC2f51XZFqGOrafU8sBXb4r71QfEmUV1vLI77diIzadmag74uRnv02Cn7DzJXeMc0VCX319vj9w8uqtrkoY7rfQa1l7qTKCY= 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 new map flag EXT4_MAP_DELAYED to indicate the mapping range is a delayed allocated only (not unwritten) one, and making ext4_map_blocks() can distinguish it, no longer mixing it with holes. Signed-off-by: Zhang Yi Reviewed-by: Jan Kara --- fs/ext4/ext4.h | 4 +++- fs/ext4/extents.c | 7 +++++-- fs/ext4/inode.c | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index a5d784872303..55195909d32f 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -252,8 +252,10 @@ struct ext4_allocation_request { #define EXT4_MAP_MAPPED BIT(BH_Mapped) #define EXT4_MAP_UNWRITTEN BIT(BH_Unwritten) #define EXT4_MAP_BOUNDARY BIT(BH_Boundary) +#define EXT4_MAP_DELAYED BIT(BH_Delay) #define EXT4_MAP_FLAGS (EXT4_MAP_NEW | EXT4_MAP_MAPPED |\ - EXT4_MAP_UNWRITTEN | EXT4_MAP_BOUNDARY) + EXT4_MAP_UNWRITTEN | EXT4_MAP_BOUNDARY |\ + EXT4_MAP_DELAYED) struct ext4_map_blocks { ext4_fsblk_t m_pblk; diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index e0b7e48c4c67..6b64319a7df8 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -4076,8 +4076,11 @@ static ext4_lblk_t ext4_ext_determine_insert_hole(struct inode *inode, /* * The delalloc extent containing lblk, it must have been * added after ext4_map_blocks() checked the extent status - * tree, adjust the length to the delalloc extent's after - * lblk. + * tree so we are not holding i_rwsem and delalloc info is + * only stabilized by i_data_sem we are going to release + * soon. Don't modify the extent status tree and report + * extent as a hole, just adjust the length to the delalloc + * extent's after lblk. */ len = es.es_lblk + es.es_len - lblk; return len; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 1b5e6409f958..c141bf6d8db2 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -515,6 +515,8 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, map->m_len = retval; } else if (ext4_es_is_delayed(&es) || ext4_es_is_hole(&es)) { map->m_pblk = 0; + map->m_flags |= ext4_es_is_delayed(&es) ? + EXT4_MAP_DELAYED : 0; retval = es.es_len - (map->m_lblk - es.es_lblk); if (retval > map->m_len) retval = map->m_len; From patchwork Sat Jan 27 01:58: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: 13533897 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 1F3DEC47422 for ; Sat, 27 Jan 2024 02:03:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 41BED6B0095; Fri, 26 Jan 2024 21:02:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F0406B0092; Fri, 26 Jan 2024 21:02:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 06EB26B0093; Fri, 26 Jan 2024 21:02:50 -0500 (EST) 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 E6FDF6B008C for ; Fri, 26 Jan 2024 21:02:50 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B0290C0718 for ; Sat, 27 Jan 2024 02:02:50 +0000 (UTC) X-FDA: 81723442500.20.AE2E4F8 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf18.hostedemail.com (Postfix) with ESMTP id 2D87A1C0004 for ; Sat, 27 Jan 2024 02:02:47 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf18.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706320969; 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=A68f8fGvG41lu4S+4QA4P6nfcoO3Ylc64rgculcreRk=; b=NNWGZoHfN73BQKeYbPQIs/6ldMkbUN3fPtIYK0z252tnLaIbzcsKAuaD78R/2kKbHFJzv1 3+5L710rCMShg14R2Ay1jXQxU/gsglvqj7EAtnVb8YEK5PHLZRtsyNtpkx5rI+NT1NkqmV rkhygoz5ABwln2iBCv8h0NBLfb+gkd4= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf18.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320969; a=rsa-sha256; cv=none; b=WHalwPjnMj1zQbSc1lHR7VTiD3P+hY7RUAULzzKQGHQ24Ra5/ubc3Ss4YvJtcuq0FTj7g4 3M0cC0DEeIc7+r+qVrpwDYlJUDpuQNXTVNKDmqvwcCbqlqOBLSpk60YS7SgxKlLexmXa6Y eO0UZxq9kduyBJYrddLauF9CnwU+uak= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrX6jLsz4f3lfJ for ; Sat, 27 Jan 2024 10:02:36 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 4DA121A0172 for ; Sat, 27 Jan 2024 10:02:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S10; Sat, 27 Jan 2024 10:02:43 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, 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 v3 06/26] ext4: make ext4_set_iomap() recognize IOMAP_DELALLOC map type Date: Sat, 27 Jan 2024 09:58:05 +0800 Message-Id: <20240127015825.1608160-7-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S10 X-Coremail-Antispam: 1UD129KBjvJXoW7Aw1kKFWkAr4DGw43GrW7Arb_yoW8Kr17pa 9xKFy7GF43Xr1qgr48trW7Zr1Yk3WUK3y7WrWfG3s5Cr10yry8tF48CF1SyF90qrWxZw1I qF4jkr18ua1SyFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr 0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 2D87A1C0004 X-Stat-Signature: ffbtjcztdwyqo1pui7ngdxngezidstfx X-HE-Tag: 1706320967-417548 X-HE-Meta: U2FsdGVkX193jlbf2aAd5lNwQXDtWeyBp7bVfVfSu+lk7hbG+/eINiK5iqCX+WMAW4gXFMTvgdYWTswXv1df8Q2EB0uKFM+UBC3NIDsu+iSZOGcrm4mI8qzqi4e2NAMzXT+CINLbOnQwGxLeVvx0cs5RTCWk3daQteLdWzEDSE2IaINBFiqr3wROsH21X4mfHLvWSb+d56Pp31An5Bz/+Rf7WKhhU+d6yjkuj0g3RT81iwalpewO91crPfI1Fm9V3g3najFPFFwFW/kcBF7n/vUxYDr787O1jlDwW/nX/YyaQk9GTQTJplZNTpiMDv8neAfozHkOfjgFbz16e20ejNjvyY2kJQpS1EMyT5OG1/aEEM5elVSWETtWZHP8mHWWPosdPlHvij54vs4sCArVCB+qM/WYL41U5VlJU8Z8qZPASGtaX5LCVQi4ie4Wk259QkkJDRTGpZPdU52XzW3VVzXVxbJvYI4ShBcZLeO208mNYvlddrPrFqDBv7+2egKN4TyYpXkYmDq0x5jEZmCX6YR+1px0MuoxZs0j8fXsg+lWuiN5+Gzlj1UZd29H0+bopBLihBzOKcqTjQqv3/fmmi0/HwVxCtjQBYOb7ia4AVLHmu3Qy2YbaR4GAS53nqubblVNq4jiCuXPfjZXZRlF3UQrLJyS8gtAYGOCqXXKDCMEZhsQ8mZYvZHynSiFManEpchXl4V2jIZcsDdVnZht1/IJF7KbkaGzttZdpbYUSDxa1NMZoAXa2fV8MMGRcBsG4ci6Y4WPiqrtazvyBibdISq6jLlZ/nxJoBJaHcntPNbUShaZAxMsFe0DfyUnuYvQ2jVtMfSeSpwm5EzC1LAPgdkshMGrkx28ckFfPUFlYevVzYv29uSC2vZo10kG1+Z4gepG92BVac+dykwOf5OaJ8ZvDJpgNnGGg36cqU5+kAWpOO3HVnslxye1gWnF6hNi8KNyKHUIeR0s+bbSAdJ HThpP+Xk fyXKE5bj9iQNFpyzAFOaFd+LEYqF591Dxk36qPgXgNz7UMNhbYgn5qikpJq19szp8tM2ek4wSUCYsSy0O+Z6acGiSzBLszZqYAz7hRqQBZZFz9Nv7m73FosA7a06DXcIO1zvFLofjXo7/dvRdBJATE8Lqx7gsLaNF9gANHbxGDw6q5+8x9i+UErLMO1E9AtTqfgszyAEZE0Cib9xZUTcrV6skeqLFPOmHxJifV/yBcSU1KlARFZe5ZfJRhe9qF0VRbktwKbccEKOZ1+UBTEi+h4S2z+2KgA1qkzNlbk51w/PYd1A= 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 ext4_map_blocks() can recognize a delayed allocated only extent, make ext4_set_iomap() can also recognize it, and remove the useless separate check in ext4_iomap_begin_report(). Signed-off-by: Zhang Yi Reviewed-by: Jan Kara --- fs/ext4/inode.c | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index c141bf6d8db2..0458d7f0c059 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3261,6 +3261,9 @@ static void ext4_set_iomap(struct inode *inode, struct iomap *iomap, iomap->addr = (u64) map->m_pblk << blkbits; if (flags & IOMAP_DAX) iomap->addr += EXT4_SB(inode->i_sb)->s_dax_part_off; + } else if (map->m_flags & EXT4_MAP_DELAYED) { + iomap->type = IOMAP_DELALLOC; + iomap->addr = IOMAP_NULL_ADDR; } else { iomap->type = IOMAP_HOLE; iomap->addr = IOMAP_NULL_ADDR; @@ -3423,35 +3426,11 @@ const struct iomap_ops ext4_iomap_overwrite_ops = { .iomap_end = ext4_iomap_end, }; -static bool ext4_iomap_is_delalloc(struct inode *inode, - struct ext4_map_blocks *map) -{ - struct extent_status es; - ext4_lblk_t offset = 0, end = map->m_lblk + map->m_len - 1; - - ext4_es_find_extent_range(inode, &ext4_es_is_delayed, - map->m_lblk, end, &es); - - if (!es.es_len || es.es_lblk > end) - return false; - - if (es.es_lblk > map->m_lblk) { - map->m_len = es.es_lblk - map->m_lblk; - return false; - } - - offset = map->m_lblk - es.es_lblk; - map->m_len = es.es_len - offset; - - return true; -} - static int ext4_iomap_begin_report(struct inode *inode, loff_t offset, loff_t length, unsigned int flags, struct iomap *iomap, struct iomap *srcmap) { int ret; - bool delalloc = false; struct ext4_map_blocks map; u8 blkbits = inode->i_blkbits; @@ -3492,13 +3471,8 @@ static int ext4_iomap_begin_report(struct inode *inode, loff_t offset, ret = ext4_map_blocks(NULL, inode, &map, 0); if (ret < 0) return ret; - if (ret == 0) - delalloc = ext4_iomap_is_delalloc(inode, &map); - set_iomap: ext4_set_iomap(inode, iomap, &map, offset, length, flags); - if (delalloc && iomap->type == IOMAP_HOLE) - iomap->type = IOMAP_DELALLOC; return 0; } From patchwork Sat Jan 27 01:58: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: 13533898 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 5AB81C47422 for ; Sat, 27 Jan 2024 02:03:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6AF876B0092; Fri, 26 Jan 2024 21:02:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 618956B008C; Fri, 26 Jan 2024 21:02:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3595D6B0098; Fri, 26 Jan 2024 21:02:51 -0500 (EST) 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 085DA6B008C for ; Fri, 26 Jan 2024 21:02:51 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C75131208AA for ; Sat, 27 Jan 2024 02:02:50 +0000 (UTC) X-FDA: 81723442500.18.7780E20 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf29.hostedemail.com (Postfix) with ESMTP id 29ECC120031 for ; Sat, 27 Jan 2024 02:02:47 +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.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=1706320969; 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=Fc2ea8oBDAjhZiCLZolifIy7EWEW0yrJpaeEC6rgGJ8=; b=hMQtG1rClLIqWItU4pvBm9v9zpxle3KIrup/gE1MUhTEwaxoGJUbDW7nZCml7dYPa5gmyZ ITnm+uFBDAW81Hr4hLuw8xx/daaxYrno9wPkjkQsxYTgBIylJjth3/cl7xPeeVj9jJPdbZ y50M1Paguxr+AkF7gEKQcry1jyYN/2Q= 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.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320969; a=rsa-sha256; cv=none; b=PxpmKtqLrljkh78ydpteFOJ5Rnn/lsDjpjARqCz/alDBIpc7YjI2313Bv9+Il3o06O86kx RS1D13nsH/zSA+DVzbWrYAD45epSaiC2fXzEz87JkEdntMpLIBzu7FX5twncyywq0TfNf0 hZaHd+eRZ6HJQSfZKpCqVP2Md211YZw= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TMHrb6mYNz4f3lwZ for ; Sat, 27 Jan 2024 10:02:39 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id EC58B1A027B for ; Sat, 27 Jan 2024 10:02:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S11; Sat, 27 Jan 2024 10:02:43 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, 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 v3 07/26] iomap: don't increase i_size if it's not a write operation Date: Sat, 27 Jan 2024 09:58:06 +0800 Message-Id: <20240127015825.1608160-8-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S11 X-Coremail-Antispam: 1UD129KBjvJXoWxZrWkXr1UuF4fKr18XF4UCFg_yoW5ZFWxpr WDK398Crs7JF47Wrn5JF98Xr1Yk34rGrW2kFWxG3y3ZFn0yr47K3W8KayY9F18J3s7Ar4f JF4vya4rWr1UCr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr 0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 29ECC120031 X-Stat-Signature: 4u7skx8qrph8r4ty39xmnkccq58rs4m6 X-HE-Tag: 1706320967-465049 X-HE-Meta: U2FsdGVkX1/o5zUU12AL0hI1IVAyLrxLZo6TTd3EspOstrMBuCahCShTubdJ+J6ubjWkrx28cMN44u7f/+QqctbWZbPu7cY2WOFAMRgdcAPjrMocmMP0bYR6xVz1wPTHajNnnh/ByqsQDnYhyYfZD5/PvM1BNLMGxl7GfMiv/6+TKzzlE4XTj6E5IlYfUhTzrrquhWxvgxjFikhqmJ+MtC2OvLzfVkntoxcO4ovY9fa5WasABql61Dhn79NrQK8t1AmTQUHDKMgGX//iJEy2R69Suc8983fsFqfpK3TVS09H09JL7ArLlxmiKP3SaI5h07OZ9FojFNTL/eQb3PGfziAh+B2NS9Z1ak36W4bATqtSUc1sIhpQ+Bzx/k11NB/kt2+iRLL8E84DRhU6ZN7pZuMC1a3ZS0tMcGTI6KLMGHPeMfxa/+0tV+x7nJGAp5Dz6rLcDwVKd+nkve3ICVxH58gAgBqUNkI07P4mdZBAk9V8cmm98nRcvY+XHMiD3wTMU4vCvCurUmxlQ0OVmVNK7ihRGwRhs5J0cRRy1dzBK8v+Wo4nh4YbKMDwHeCyKIwLJG0wLE/1UdzyZUO+N7gTje9JHKJyBwZF4lt+oQZzaOFFRzM7n3lh18+U9daaqUn17TNcpRan/dWLzeRflho9NS8OvvveFJ1/5vOMflhVhz7lxhcPNGh9Qijwlen9+89kR5Nz6vIjYtGYiGLviN5YWLCX7AK68DYCTH1/t6BgbY7srjes4enx/Fki/P42UutXGByjNr7eN7/JHUWwMDUoz5sw+b/zhZlH+Ri29xAcaRkRjugRx6+haFh5O1WMKnSpNpBAbt5TGi1nKi5oX7YYhB/v4dMiRgGIjW5NG0zwD0hvcfidWcEMVX3ZunkgPykc1Ck4Qs4N2tzaHieWA7kApwRzEMOutBgyvtDiWmelRirMpr22uf59+o7NWqMSLP0tnxbmoIC6OG26EItUR4C uN16bhXf P+9wGYfHJvoHOBjmr0UPYBdV07+A5nrcZu9meEGtjg+jDNmpLzr7f0dqC68pZ3RMshoXXtaYxCucliXzobCQ/Vcq/aeBUf8dMKWHu5szt/FFMYbjLZnCOSURLoo1QU0PFTldaUt8UnINLV7kMe/BYdLJR/tZ23SxntKLmQUBsAdc7y7GfisjACfPZlM7svVEN4l/Yq4r55/CbN0NnKB0a97RxWA6LNo93fKfbxYNMSqA0zuJrrAcGu+ATS05b+WYAtLRqQVw1pEDjdPiikWBvQk1g3EgnkFkHHK/Hqow3cRJ5OgY= 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 Increase i_size in iomap_zero_range() and iomap_unshare_iter() is not needed, the caller should handle it. Especially, when truncate partial block, we could not increase i_size beyond the new EOF here. It dosn't affect xfs and gfs2 now because they reset the new file size after zero out, it doesn't matter that a brief increase in i_size, but it will affect ext4 because it set file size before truncate. At the same time, iomap_write_failed() is also not needed for above two cases too, so let's introduce a new helper iomap_write_end_simple() to replace the common iomap_write_end() helper which designed for buffer write, and also move out iomap_write_failed() from iomap_write_begin() to iomap_write_iter(). Signed-off-by: Zhang Yi --- fs/iomap/buffered-io.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index e0c9cede82ee..2ae936e5af74 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -834,7 +834,6 @@ static int iomap_write_begin(struct iomap_iter *iter, loff_t pos, out_unlock: __iomap_put_folio(iter, pos, 0, folio); - iomap_write_failed(iter->inode, pos, len); return status; } @@ -881,6 +880,25 @@ static size_t iomap_write_end_inline(const struct iomap_iter *iter, return copied; } +static size_t iomap_write_end_simple(struct iomap_iter *iter, loff_t pos, + size_t len, struct folio *folio) +{ + const struct iomap *srcmap = iomap_iter_srcmap(iter); + size_t ret; + + if (srcmap->type == IOMAP_INLINE) { + ret = iomap_write_end_inline(iter, folio, pos, len); + } else if (srcmap->flags & IOMAP_F_BUFFER_HEAD) { + ret = block_write_end(NULL, iter->inode->i_mapping, pos, len, + len, &folio->page, NULL); + } else { + ret = __iomap_write_end(iter->inode, pos, len, len, folio); + } + + __iomap_put_folio(iter, pos, ret, folio); + return ret; +} + /* Returns the number of bytes copied. May be 0. Cannot be an errno. */ static size_t iomap_write_end(struct iomap_iter *iter, loff_t pos, size_t len, size_t copied, struct folio *folio) @@ -960,8 +978,10 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) } status = iomap_write_begin(iter, pos, bytes, &folio); - if (unlikely(status)) + if (unlikely(status)) { + iomap_write_failed(iter->inode, pos, bytes); break; + } if (iter->iomap.flags & IOMAP_F_STALE) break; @@ -1343,7 +1363,7 @@ static loff_t iomap_unshare_iter(struct iomap_iter *iter) if (bytes > folio_size(folio) - offset) bytes = folio_size(folio) - offset; - bytes = iomap_write_end(iter, pos, bytes, bytes, folio); + bytes = iomap_write_end_simple(iter, pos, bytes, folio); if (WARN_ON_ONCE(bytes == 0)) return -EIO; @@ -1407,7 +1427,7 @@ static loff_t iomap_zero_iter(struct iomap_iter *iter, bool *did_zero) folio_zero_range(folio, offset, bytes); folio_mark_accessed(folio); - bytes = iomap_write_end(iter, pos, bytes, bytes, folio); + bytes = iomap_write_end_simple(iter, pos, bytes, folio); if (WARN_ON_ONCE(bytes == 0)) return -EIO; From patchwork Sat Jan 27 01:58: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: 13533900 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 76B5FC47DA9 for ; Sat, 27 Jan 2024 02:03:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0971A6B0093; Fri, 26 Jan 2024 21:02:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F14B76B0096; Fri, 26 Jan 2024 21:02:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1B6D6B0099; Fri, 26 Jan 2024 21:02:51 -0500 (EST) 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 B36BA6B0096 for ; Fri, 26 Jan 2024 21:02:51 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9167680F2C for ; Sat, 27 Jan 2024 02:02:51 +0000 (UTC) X-FDA: 81723442542.14.8978E24 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf04.hostedemail.com (Postfix) with ESMTP id 22C8B4000B for ; Sat, 27 Jan 2024 02:02:48 +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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706320969; 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=Iw3JaRFBdREWOAR52tTvEFycZqWua1x0l9UMHTUegX0=; b=IG1yIlvCv9aqwLZArDKrza1EkTfZmTz7SrBHPxDch6uzOYuUY/ToTZLB6g2FJrksOB+VM5 ePIHr7Xiwh8Beasse9cdGZnYstNB/AC7K13RxRqbXlUrKGi13yrl86bn5QzX8oQHl+g0Mi XfqlvkT6rUDHL8sBTFwNWNYWkvAH9MY= 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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320969; a=rsa-sha256; cv=none; b=f+oAdeOw8aWJLrNFQ4os2aj5hWyA8q4LTXS9dhAkciqRyCsGiGOaNy/oN17yju7kDE7+9Q gWSdZysQk3QobXbN0PkbgwK3YUvFsdLvA810pqNgan0NJ74vFv+iHO8bm8ZVIR/iDzyVAW Pmr+1/GHuYwG0Jk2I+K+IDcHkiPhFdc= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrZ1qGLz4f3lg5 for ; Sat, 27 Jan 2024 10:02:38 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 9A0771A016E for ; Sat, 27 Jan 2024 10:02:44 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S12; Sat, 27 Jan 2024 10:02:44 +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 v3 08/26] iomap: add pos and dirty_len into trace_iomap_writepage_map Date: Sat, 27 Jan 2024 09:58:07 +0800 Message-Id: <20240127015825.1608160-9-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S12 X-Coremail-Antispam: 1UD129KBjvJXoWxGw4xZF18Cw4Utw48CrWUXFb_yoW5AryfpF 9FyFZ8Cr4kJr429w1fZ34rArs0vF95ur4Utr13u3y5Zw4vyr17GF4vkFWjvF95ArnIyr13 XF4F934kG3WUCw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr 0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Stat-Signature: kdfokbdwyqt33pd6d4634wqpgchhzmza X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 22C8B4000B X-HE-Tag: 1706320968-345868 X-HE-Meta: U2FsdGVkX18IHxUd179qaSYMqwmejpSx5Sc/OcgyxUhCzQY4ngEOAHnH7wIwKev4UwM+w/qn5j7BEfXKlNQZ4RG6GomdqTNBk2IDAUGpguTlcgAnOpz+7yRM7uRBcF04ABNPw627+pXiU0GGjMsloe4MeBc+nzs0FLD3WKDvQK3JdTPXc5IorOcr+zFinI6QqBh+agJbHHOK/emvJyrVjajBD5oPWR0xg5MjzKsjofRt8ACNptTttOuiMLgS1tqZW3WhKBnnl6VkBJiqi7O6jydOcM6F4jbCO+8Tv5cr7eHoKqLViAUNTDpyxk5Ed4GaNceVG3BNeFmSui4ClXSMydOdqB/nSIwqRI0KcdqcsOmZMDGxd/x9yF1L9WzFYIyK8RxHuyGPwDo0naW+lAQCskJ9yIUOuRiem6Jmfpr3Yq4xQWZYS/nWsa+LG29R/urDyCWTEriDEgBfBrnvdHZzguVi26JchoGXdsE8wmwC9EQbYtLOCflL5NuVGz4d3Np9JBUbNDXbuxrxNXvEfy/gXvaEzT0SoiXQxXI0SNpKP6TLSq9hEmCX8cvzTriCvWQtd1TJaeUMAq6z5/ZYiB3QarsOGZ4oRtfcevuQ8HnVW4V6Jqktr5ab7b/JvavIoJWEafDvdAFvPh/UKeDHRBxyAbPsRB1SI4/bYdvioI6g7Paqb4af5IpkTFC77j9a6e1GoKoCmnkvBkrqzAiW+TtdpCiwW3c/U1Rb1/QdCtQlukoHICqKI0sTHJ9T4M1HZhd3y/KMDecfvOBEqxDeZqHitwf0jxwqPuZgoje7DdWm2MLB+XyCTaAjsTkI60iyxA6X90cNaZ259+yjlvdAYlnwW2zgKm6pCMh6qdqhnZJQNc0F0amZSrhvnBiKCa9kEx6q/+EAO/j6K/AsdanxPbWd9DSbRZDrjGQ3br4at6PztpuaEbWUWGBa3sbihRwBbYnUGVL9MgigOL9ZWBegLuW NcTWPL6h a96zyGEsJ2h5fDq3YnYiPY60x9i5R1JscTyHe2dOowsW1YrWi84JA76Wnbg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Since commit "iomap: map multiple blocks at a time", we could map multi-blocks once a time, and the dirty_len indicates the expected map length, map_len won't large than it. The pos and dirty_len means the dirty range that should be mapped to write, add them into trace_iomap_writepage_map() could be more useful for debug. Signed-off-by: Zhang Yi Reviewed-by: Christoph Hellwig --- fs/iomap/buffered-io.c | 2 +- fs/iomap/trace.h | 43 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 2ae936e5af74..9a9f1bfe80b4 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1806,7 +1806,7 @@ static int iomap_writepage_map_blocks(struct iomap_writepage_ctx *wpc, error = wpc->ops->map_blocks(wpc, inode, pos, dirty_len); if (error) break; - trace_iomap_writepage_map(inode, &wpc->iomap); + trace_iomap_writepage_map(inode, pos, dirty_len, &wpc->iomap); map_len = min_t(u64, dirty_len, wpc->iomap.offset + wpc->iomap.length - pos); diff --git a/fs/iomap/trace.h b/fs/iomap/trace.h index c16fd55f5595..3ef694f9489f 100644 --- a/fs/iomap/trace.h +++ b/fs/iomap/trace.h @@ -154,7 +154,48 @@ DEFINE_EVENT(iomap_class, name, \ TP_ARGS(inode, iomap)) DEFINE_IOMAP_EVENT(iomap_iter_dstmap); DEFINE_IOMAP_EVENT(iomap_iter_srcmap); -DEFINE_IOMAP_EVENT(iomap_writepage_map); + +TRACE_EVENT(iomap_writepage_map, + TP_PROTO(struct inode *inode, u64 pos, unsigned int dirty_len, + struct iomap *iomap), + TP_ARGS(inode, pos, dirty_len, iomap), + TP_STRUCT__entry( + __field(dev_t, dev) + __field(u64, ino) + __field(u64, pos) + __field(u64, dirty_len) + __field(u64, addr) + __field(loff_t, offset) + __field(u64, length) + __field(u16, type) + __field(u16, flags) + __field(dev_t, bdev) + ), + TP_fast_assign( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->pos = pos; + __entry->dirty_len = dirty_len; + __entry->addr = iomap->addr; + __entry->offset = iomap->offset; + __entry->length = iomap->length; + __entry->type = iomap->type; + __entry->flags = iomap->flags; + __entry->bdev = iomap->bdev ? iomap->bdev->bd_dev : 0; + ), + TP_printk("dev %d:%d ino 0x%llx bdev %d:%d pos 0x%llx dirty len 0x%llx " + "addr 0x%llx offset 0x%llx length 0x%llx type %s flags %s", + MAJOR(__entry->dev), MINOR(__entry->dev), + __entry->ino, + MAJOR(__entry->bdev), MINOR(__entry->bdev), + __entry->pos, + __entry->dirty_len, + __entry->addr, + __entry->offset, + __entry->length, + __print_symbolic(__entry->type, IOMAP_TYPE_STRINGS), + __print_flags(__entry->flags, "|", IOMAP_F_FLAGS_STRINGS)) +); TRACE_EVENT(iomap_iter, TP_PROTO(struct iomap_iter *iter, const void *ops, From patchwork Sat Jan 27 01:58: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: 13533901 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 94460C48285 for ; Sat, 27 Jan 2024 02:03:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 31A416B0096; Fri, 26 Jan 2024 21:02:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2722D6B009A; Fri, 26 Jan 2024 21:02:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DDFA06B0098; Fri, 26 Jan 2024 21:02:51 -0500 (EST) 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 AEA5B6B0093 for ; Fri, 26 Jan 2024 21:02:51 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8F1F480AF3 for ; Sat, 27 Jan 2024 02:02:51 +0000 (UTC) X-FDA: 81723442542.11.4C9B799 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf05.hostedemail.com (Postfix) with ESMTP id 1812B100024 for ; Sat, 27 Jan 2024 02:02:48 +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=1706320969; 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=tKcrRdUmH14QplBC92PnCc5CF4CQLz76teadQEIKfa0=; b=3NQd99ywi7daEkVu8xHz/uolgCLDn74xHYR8H2p6fDEeG5BCZThZIs64Zf3WwnUXBcXBRE IgS7+PK+5MlChJ5v8U7mK8xKmdv2OuCQ7xcgaVZzpERNmrLqIE+Fq+2LB8OXxu85ALA21g D9/W4jYPTakWAoEsPat2zfwTCcadkps= 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320969; a=rsa-sha256; cv=none; b=T6WI/OwW0S0YzJ7iJPNuFbcs3wq6etjqlqaWKJenJAXAeVj0Ty9i8ZWdYJ0BHrjelE0/HE fUfEMRhqvSKfJyAlvWkYy+0N1BPKSDihNxdEQulN7fHgyz3KFCq2Cvv+Z/Zeq/lT1wEeLr F7QWKmiWmzmbGCEe20U7m/kYq4sZLqk= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrZ6Z3pz4f3lgB for ; Sat, 27 Jan 2024 10:02:38 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 48D931A017A for ; Sat, 27 Jan 2024 10:02:45 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S13; Sat, 27 Jan 2024 10:02:45 +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 v3 09/26] ext4: allow inserting delalloc extents with multi-blocks Date: Sat, 27 Jan 2024 09:58:08 +0800 Message-Id: <20240127015825.1608160-10-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S13 X-Coremail-Antispam: 1UD129KBjvJXoW3Jr4xKr43GrW8tw1xtF18Krg_yoWfKryDpF Z8CF18GrWag34vgFWSqr4UZr1S9a4xtrWUJr9agw1fZFy8JFySqF1UtF1YvFyrtrZ5Jrn0 qFyYy34Uua1jga7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr 0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 1812B100024 X-Rspam-User: X-Stat-Signature: pyzjhf54aryseqtzcenf5xegazmdij5q X-Rspamd-Server: rspam01 X-HE-Tag: 1706320968-117734 X-HE-Meta: U2FsdGVkX1/V+hqddq5WM9s2vuTDHb1/GXJ5i04IsqJiybl9Yp92aM/KkItK/hOxrEBnufcm71iIh/nNZ5rnLafk6UIfwC2nRu0lnnwa4VPelvDbIKyghcDpIRcLEEe/fb+5RloJl8UTendG+pjI3XjeMMk/2vWENc/2FRj7LR7kCgCF+mNLgvL5Xu3u3IMroYqsAqGOq2iwTzYhTPM8jeaxW1IDO6ZxVdFUjzNAIgDRUgvFR6xpXN1eSi9cop74CI1bbW1H/fusfutoY18/+LqBxL/2WK9OztMoGNdkkAkGVUsb6myu4H2f+OdrvCSqSpHurUyIdU1KT9a94/9PvCJzW6/QiBkorsVspeiY9ZHvOg2Pzsm+mIxq+Lt2dmbyXiVXfIq5alwEZG7m2ocQolGVBcsCt0mDCNyUXZp3eeRlYlXLliFFMzgUX3dAEH2Ast7EeaVO+ZRxWePrJ0Bz/FEgY5UrW4h2vUS00RAC1J0CV9bum468pVbgt3WgTOt0m2u/GnjE6RS5+2yAfEhn/9no/uqjHajVsQDtI4HoQaGN6+56cnm+HL5ZPPmMey9OtmgUYd1F2lHDMKF7u3YTwiw0v9pHfnaefdq6vYtAp1H7K1aB6/yzus7w2ZR53EeIOFbhDz+9op/hsbBrCFRaDuw5dhgwAXgZasZ6bvOUQAAUW1axAjOlaqoJ3vMhu0axupZt6KqLgf+x9yMtk/yzBSCRyaJIsIRWjBtL6YVVetS38b7JMDm0cWzXDUAZpOO55Lht/8tTd1yLmsEq954w9T9KWW7xMFT1BOvR+5Z0r0qzqUQo2VP38DdorClWqmO1Qz64f/oG+BZShuhmyM+fAChgI5XtD53CWYNaZ8ScR+Mabrtcrhu++FNYoSSH2jy7Jo0J/BbpgCVa+aFbzaGbryTv0MtHljDfhMQPrZuW2/VHsVP5wc1cO9YLFP8YIPqrMB6fXSkXBKGiZ8KJbhl ByPU3Bzv V0iFy/MC8vSI9AQCq8c29PQB1GSWego/xcZpPv2lplnPn856Rym/h1MUE89NhiYEOFSNMCKRZK+onWGH41csrAm+/lEHRRBhsLD9mXp6HjCzsDqmSFAoVQqQnCvAI+C5lidr39Pu0f/zKSgW93yan77JrwosX0AfIn3PKQBXCxX3wwJbpaPaJgrdyk+8huRyqg/05t5ZanB99/h7tbrR5+FPM5DI4xRw05UwyjX06COVaYv4jegnufuwVU4ZUQQqQhuUD 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 helper ext4_insert_delayed_blocks() to replace ext4_insert_delayed_block() that we could add multi-delayed blocks into the extent status tree once a time. But for now, it doesn't support bigalloc feature yet. Also rename ext4_es_insert_delayed_block() to ext4_es_insert_delayed_extent(), which matches the name style of other ext4_es_{insert|remove}_extent() functions. Signed-off-by: Zhang Yi --- fs/ext4/extents_status.c | 26 ++++++++++++++----------- fs/ext4/extents_status.h | 4 ++-- fs/ext4/inode.c | 39 ++++++++++++++++++++++--------------- include/trace/events/ext4.h | 12 +++++++----- 4 files changed, 47 insertions(+), 34 deletions(-) diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 4a00e2f019d9..324a6b0a6283 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -2052,19 +2052,21 @@ 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 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 + * @lblk - first logical block to be added + * @len - length of blocks to be added * @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, + unsigned int len, bool 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; @@ -2073,13 +2075,15 @@ void ext4_es_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk, 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, allocated); ext4_es_insert_extent_check(inode, &newes); @@ -2092,7 +2096,7 @@ void ext4_es_insert_delayed_block(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, 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. */ diff --git a/fs/ext4/extents_status.h b/fs/ext4/extents_status.h index d9847a4a25db..24493e682ab4 100644 --- a/fs/ext4/extents_status.h +++ b/fs/ext4/extents_status.h @@ -249,8 +249,8 @@ 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, + unsigned int len, bool 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 0458d7f0c059..bc29c2e92750 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1452,7 +1452,7 @@ static int ext4_journalled_write_end(struct file *file, /* * Reserve space for a single cluster */ -static int ext4_da_reserve_space(struct inode *inode) +static int ext4_da_reserve_space(struct inode *inode, unsigned int len) { struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); struct ext4_inode_info *ei = EXT4_I(inode); @@ -1463,18 +1463,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, len)); 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, len, 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, len)); return -ENOSPC; } - ei->i_reserved_data_blocks++; - trace_ext4_da_reserve_space(inode); + ei->i_reserved_data_blocks += len; + trace_ext4_da_reserve_space(inode, len); spin_unlock(&ei->i_block_reservation_lock); return 0; /* success */ @@ -1620,18 +1620,21 @@ static void ext4_print_free_blocks(struct inode *inode) return; } + /* - * 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 multi-delayed blocks to the extents + * status tree, incrementing the reserved + * cluster/block count or making a pending + * reservation 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; @@ -1649,10 +1652,14 @@ 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, len); if (ret != 0) /* ENOSPC */ return ret; } else { /* bigalloc */ + /* TODO: support bigalloc for multi-blocks. */ + if (len != 1) + return -EOPNOTSUPP; + if (!ext4_es_scan_clu(inode, &ext4_es_is_delonly, lblk)) { if (!ext4_es_scan_clu(inode, &ext4_es_is_mapped, lblk)) { @@ -1661,7 +1668,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 { @@ -1673,7 +1680,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, len, allocated); return 0; } @@ -1774,7 +1781,7 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, add_delayed: down_write(&EXT4_I(inode)->i_data_sem); - 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; diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h index 65029dfb92fb..53aa7a7fb3be 100644 --- a/include/trace/events/ext4.h +++ b/include/trace/events/ext4.h @@ -1249,14 +1249,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 reserved_blocks), - TP_ARGS(inode), + TP_ARGS(inode, reserved_blocks), TP_STRUCT__entry( __field( dev_t, dev ) __field( ino_t, ino ) __field( __u64, i_blocks ) + __field( int, reserved_blocks ) __field( int, reserved_data_blocks ) __field( __u16, mode ) ), @@ -1265,16 +1266,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->reserved_blocks = reserved_blocks; __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 reserved_blocks %u " "reserved_data_blocks %d", MAJOR(__entry->dev), MINOR(__entry->dev), (unsigned long) __entry->ino, __entry->mode, __entry->i_blocks, - __entry->reserved_data_blocks) + __entry->reserved_blocks, __entry->reserved_data_blocks) ); TRACE_EVENT(ext4_da_release_space, @@ -2481,7 +2483,7 @@ 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), From patchwork Sat Jan 27 01:58: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: 13533904 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 4AFD6C47422 for ; Sat, 27 Jan 2024 02:03:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3858E6B009A; Fri, 26 Jan 2024 21:02:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2BB6F6B009B; Fri, 26 Jan 2024 21:02:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3D9F6B009C; Fri, 26 Jan 2024 21:02:54 -0500 (EST) 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 D3C5B6B009A for ; Fri, 26 Jan 2024 21:02:54 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8787A1C0FBB for ; Sat, 27 Jan 2024 02:02:54 +0000 (UTC) X-FDA: 81723442668.19.37AFACC Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf23.hostedemail.com (Postfix) with ESMTP id 15D79140003 for ; Sat, 27 Jan 2024 02:02:51 +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.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=1706320972; 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=ibzvTDQvbHWpuZlSBRam506AV7dGjs5LmZoPW0q5Qsg=; b=aqXtJ2FbnpTCXqomphWDR/EEJoi2iUJq/nKw4G45ERM8zzgR37GwLCwYE+Almx2/XmaKsr HNl0vgk+16PBcrVMg4B1TemRTqEiWWCA1KLq9XXkzFZN0f0y0vGK6AnK0eYj/x4iojJhcV wDywgIaVULBg7I8/Eeujv8JpyIkmrGY= 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.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320972; a=rsa-sha256; cv=none; b=Gt/n1UOG3/uNz9P6yShOxofEw3pNtAfFquWmlICkEZfGUlva7C5ZaoRBAbJPZiFB3Bau2W OkLpo3XshH9+DI10t3iaj3ivUyH4HzHyEOBqrxQ14cjsvgqc3uf3mNHwhyHl5eQlEH81cQ 4arip0y9LYqit2hO1vW4Wxn3Pnm0tfs= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TMHrd6mHGz4f3lwr for ; Sat, 27 Jan 2024 10:02:41 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id EA5F51A0272 for ; Sat, 27 Jan 2024 10:02:45 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S14; Sat, 27 Jan 2024 10:02:45 +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 v3 10/26] ext4: correct delalloc extent length Date: Sat, 27 Jan 2024 09:58:09 +0800 Message-Id: <20240127015825.1608160-11-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S14 X-Coremail-Antispam: 1UD129KBjvJXoW7CryfAry5Zw1Uuw1kXr1fJFb_yoW8Gw1Up3 93CF1kGr4fuw1UuayxtF13XF1rK3W5K3y7Jr95tw1rZas5Gw1Iga1kA3W7ta40qFWfJF4r XFW7tw1xAw4SyrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 15D79140003 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: j6d1enmwdt6oz1jxtrrbn4cfy85q91jb X-HE-Tag: 1706320971-21333 X-HE-Meta: U2FsdGVkX1+ObBF1iLpFIJ46mBW+EGSMtgVzQO+jYT5cQsyI/80HLNuSWxUPAvMh1dzNBpH/ktMGq36gShdmFjnkDWIo5OWr7J4VtYQ7KGqK22ZhK4ZfZ+jzIEUp5uqlIIh2aeP24hxw2Kaea/6GfZYjdu9zJtpI2StLBlN2CtTZVjGqEJX1sqXOY2xEqWbZl6Bkht/BSJmMhrcIL0itVLOMDvYzLfPKYYGVJLg26ejQXS6kuutk3shP99YxM4t6oF5sczvL0zTT7gN/e2lOCBFH0RCU3ObnHLCMgYsrM9VAOSApGYPSjMBHM07QBSt+6uOoje9ifMohC9mRAZ/xVHjIdFGfZaZo1AsCqGOATQDo5I2R6ChuxbwjOka392QHG5K6i3gLIug+LZ6Gzmg2ddgRDC3kTF/7+ooy4IBoRcZUWX1m4EH+/jIWToGsIgJ335GJ2gjvGAyo8VNKXVytMeL1x4EWVdbTlCsRXpQRWEbg2j93FwMMw+Du9wdaP0s6tmtIAjoj+aH5YC18crx7H2n/mo+oAy8R3CZAI5LkXvKiURtWVrj2WEfG/F6eSqaEykfoJAag4ABKp/vC3HWhERxGK2fPWiI2u5QWmF3e8ua1zJVRvfbNiYcyrCANPLzF0C9xui6VeLc/M9cuRbKbkKxN+MUIP9+HTfSwsEE5TXTozQgBumTOm7CBRxfcIxM6bmBYvyAdZKfWSpfAHoX6AVGWMEn91guaB7E1hgsQ3TmplR32zPLNQR1p3RPUD0Mo+73E0Jjdfw2I/PH8m9bBAtmOrSMsVqyRABBrkJXexH2Sd8glwW7M65cSj/kscjCRokVUtFHBYL4wlZO4e4JxeLR+cRKZS2kdf+YkXS+ILg/sKHp/vnhN2z8aKdC4Xz0cdPCjUtC5HE04fzpMkMmF8E9Kcr2xlrqHCIKZnKzZjcK1Vvs4zNlfYNDyD7QZDVtOlogKmW9eT0+Lpk4RnwD 8TEvK8ZC DWC1VP16dPnO5LGtV/I00tEKF+NfetDq91Bdh2OdKwuxWaitenIAIuWex++9wet3ZaZV7Jit7MQV7DPTiQJGXP+2Gta7on9PJkDztntFeXiGsC5syFu0StwwwHNhcgZfd42maYX/HgZg4tQc3KBC6/A/aSbfiROgm0mrQ8qPTAKMfkAvloGTp+Shj6o6v3dyEjj60GhhY7n45yLY3OV4xzxnWAjiC4UAYgphNyzs777+uARAO7/SU7jAGVWHXuKis4cQR 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 When adding a delalloc extent in ext4_da_map_blocks(), the extent length can be incorrect if we found a cached hole extent entry and the hole length is smaller than the origin map->m_len. Fortunately, it should not be able to trigger any issue now because the map->m_len is always 1. Fix this by adjust length before inserting delalloc extent. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index bc29c2e92750..44033828db44 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1712,6 +1712,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; @@ -1727,10 +1732,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)) From patchwork Sat Jan 27 01:58: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: 13533902 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 BDBD8C47422 for ; Sat, 27 Jan 2024 02:03:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF65C6B0098; Fri, 26 Jan 2024 21:02:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C2F3B6B0099; Fri, 26 Jan 2024 21:02:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A5FDD6B009A; Fri, 26 Jan 2024 21:02:53 -0500 (EST) 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 8C9286B0098 for ; Fri, 26 Jan 2024 21:02:53 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 60FCC1204DF for ; Sat, 27 Jan 2024 02:02:53 +0000 (UTC) X-FDA: 81723442626.25.53E154F Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf28.hostedemail.com (Postfix) with ESMTP id E2A8DC000B for ; Sat, 27 Jan 2024 02:02:50 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706320971; 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=0yX1oIPNedORYEt87tF6uMdqEjQWvDkcG92o6cjnUek=; b=5N2MpmKdY1K55133TiLctNy9AxVo2sNML8407tHuz2FN7M1huTo/wXdzfXgI20BUnK/rdj PYi5PU8r/laKaYetVVekzYUxq9s7hCE3zdUOBp2GWi4qc2M4AU8gF6hV55DhGqLan9IP5n BPrtYTHKqwlj1XCal44YxM33Af62Q4g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320971; a=rsa-sha256; cv=none; b=CZvyZVCNrnF5iGxMtssrpc9RFJFob1kMn6GaDWYW1S6ZMsZU8cxB458R/A0JOLYfdQbGHM yegC4EGiWgIINRaoUMAhlvCQG/X5/asblRRvL0yXCiCG++KTyY4/lTGRTAE/WqUulWp4J8 rkWt7ecFIDZfARJ8kdVsGbR70GrlhCk= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrh1Lsxz4f3k62 for ; Sat, 27 Jan 2024 10:02:44 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 985391A016E for ; Sat, 27 Jan 2024 10:02:46 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S15; Sat, 27 Jan 2024 10:02:46 +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 v3 11/26] ext4: also mark extent as delalloc if it's been unwritten Date: Sat, 27 Jan 2024 09:58:10 +0800 Message-Id: <20240127015825.1608160-12-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S15 X-Coremail-Antispam: 1UD129KBjvJXoW7AF1xtFW8Ww48JrWxur4fGrg_yoW8GFWUpa 97C34rGr4UX348uayIyF1UZr1rKa4UKrWUtFs8uF1jya4fGF9a9F10yFyI9FyxKrWrJ3yF qF48Kry8Cay8A37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Stat-Signature: pdu3kgssy4ndo6hyjjbgyogxonxmz9ws X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: E2A8DC000B X-Rspam-User: X-HE-Tag: 1706320970-272684 X-HE-Meta: U2FsdGVkX18SnMYYgJIsPtBGg9SzbUAPC6AYHZCipm0DMCpweCm+QOg9XaFJPHxQamw3jws+hhDCq3YSj1jvQPjxNyO0LjNMGpPHOMWj9sjNsDs7wzZ3MD19Oey6Lloq4rcjOXuB4Lbf/u04KV6UcCtlqZW2NqrX4fzLbQcMOfy5/Q5JtmIRnyCCZAG5ys/11u0ACaE+PpX5YT4R/iGvOJdOd17ja5wgG+yiCFDZYMhe97cU8i55reuS7nCLk8rxFVmSnkTvlLSOy7EfdUnZkussrozOKd+TVuhSu7UY27HtvGPgTljeglV1ldBLOBmMHLPWVR+tjomOCVAaXPdNybKgTG/4NQPHeIWm2drpFsyt3XTIIEsZGP2TBOQ2D7iLNtN5dqEj+e3WfWXR3GLnQZhAcqGT4hMM8lGurKkap/D77sQzy30lDLzZ3RaKQyH+jpFz0tfNrRCPcyvbkZG5ojPmh+SxM4fIkK6Sq8StKlYh9g23znHpUX0prGDILmt3fZasAWD/Frpn2/tOIbe9DVNiYx+E9pueuduN/4SSZxZ1Pker56HJb7j4ZQQ0vg0B/fbx0j25UU8QCjEPWRTXJC6G74MIJO8opJX+xui05yTrdN6BkuvAuiMYT6RteTxuCgiBSIa2964JJUJtCH8uYJtmyX46vbGvTvCgwlYfckWK93fBZanROKZEOejlBINsAYipvbmdR1i5AXOlZxK6USOrfBPQtPwswIsKkYq9qzkVLPMYwtYBjd12eZrsDAYzv1P7Ie69yepYggtHnM/oVP6eH0e1oKLTTP01bAUX6ECrlFx9H+s3VkfIaXQYgyVG22MoGZzRWQnJkC4VHeDbo4GFvbRGtL5EqNk/9y/eWD+b20e/wV3hn9Rs9Gz6ufvlLwiOJJZCw4T6mSFWby7umekZyvJ8AAZNudlHEuqZI2hf3VaBTSTDTk8Ufpa9eqgCqOs1r2ICQIGuUSZzQs8 obccCKXA w2CVYcMc+DhqVvZpvfNzii1CvTM5qnij6jZfRcfyg8TaQv75Hwg5lyqbEo2yZyCX/OfmNMnGAB5JL18cJ7Ti57ZvPVAwKa4QTcB9612+OCSs0nS/VqpH8NxiWLtIIOqRAkxhbY0iuRDScUDhJpY6S/nLBZWWl34JjGx3tV6GOpKkNE4sasCJIlTIMp3brl1LyhlgNvg0z9aUsUTdlmtWhntY1hr/eJePrYCkH2w9Bvkkm52tLb8sYzNG4pjkZ7o8whNsthYkiNTA96hoMCVNo/byi1A== 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 Mark extent as delalloc if it's been unwritten, this delalloc flag will last until write back. It would be useful to indicate the map length when writing data back after converting regular file's buffered write path to iomap. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 44033828db44..9ac9bb548a4c 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1742,7 +1742,11 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, #ifdef ES_AGGRESSIVE_TEST ext4_map_blocks_es_recheck(NULL, inode, map, &orig_map, 0); #endif - return retval; + if (ext4_es_is_delayed(&es) || ext4_es_is_written(&es)) + return retval; + + down_read(&EXT4_I(inode)->i_data_sem); + goto insert_extent; } /* @@ -1770,9 +1774,11 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, inode->i_ino, retval, map->m_len); WARN_ON(1); } - +insert_extent: status = map->m_flags & EXT4_MAP_UNWRITTEN ? EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; + if (status == EXTENT_STATUS_UNWRITTEN) + status |= EXTENT_STATUS_DELAYED; ext4_es_insert_extent(inode, map->m_lblk, map->m_len, map->m_pblk, status); up_read(&EXT4_I(inode)->i_data_sem); From patchwork Sat Jan 27 01:58: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: 13533905 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 B3722C47422 for ; Sat, 27 Jan 2024 02:03:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8134C6B009B; Fri, 26 Jan 2024 21:02:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C42A6B009C; Fri, 26 Jan 2024 21:02:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5EB556B009E; Fri, 26 Jan 2024 21:02:55 -0500 (EST) 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 2DF1D6B009C for ; Fri, 26 Jan 2024 21:02:55 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0A1C78086A for ; Sat, 27 Jan 2024 02:02:55 +0000 (UTC) X-FDA: 81723442710.16.283D8D1 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf07.hostedemail.com (Postfix) with ESMTP id 812EE40015 for ; Sat, 27 Jan 2024 02:02:52 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; spf=pass (imf07.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=1706320973; 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=fN+CuPyasvpUZa0cOQv4KhVMd/nrmJogmtJKnzS8QfM=; b=ANzolhDuczR2fukDTWrD2HCvpAf2Vsr3Rump/DpAmgHRpPWDwK0k9iAkRkp1X+yvxgRr6b 3geE0nZDSKZ8xTQYCISXkMnxC/IJZ0Vi7tKFJQD2Zk46uvEPkLXJMwNUcYpgdTZloHqtiu R6On+m92n8vsYNEDIQ4EoUmyfrQXulc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320973; a=rsa-sha256; cv=none; b=izaoV+coct0PbUmp93S3MiAcHyYvCctHtxA2Sn330YWRXY4InMzmZNdDx7CVZTG7es0Xsv fkqrT8RBDyNKrM227/vnNK/bVEP2RL1rGgXlkoGE7X2ibWdDlJCA8uXTVIi1zOAeAHfJbb Cu5tD5G/ZaMEl89Laj9+fXFl3JraHKg= 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.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TMHrg1zRfz4f3lwC for ; Sat, 27 Jan 2024 10:02:43 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 477D41A016E for ; Sat, 27 Jan 2024 10:02:47 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S16; Sat, 27 Jan 2024 10:02:47 +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 v3 12/26] ext4: factor out bh handles to ext4_da_get_block_prep() Date: Sat, 27 Jan 2024 09:58:11 +0800 Message-Id: <20240127015825.1608160-13-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S16 X-Coremail-Antispam: 1UD129KBjvJXoW3XF1rWr48Zw4ruF47JF1DJrb_yoW7Ary8p3 9xAF1rGr13Ww109a1ftr1UXF1fK3WqyrW7Cr93GryFy3s5JrnaqF1UAFySqF98trZ3Zrs8 WF45Kry8uF18GrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 812EE40015 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: f6axg1j7u8t7w1rj9hwgh9m1d1west34 X-HE-Tag: 1706320972-411143 X-HE-Meta: U2FsdGVkX19kIp75wyXT+CuYXyh7NXUs7LDOyAW7H085yj9fxKYlkKJFnI9+nKNHia8FR1hzcX7mp6KB8clkKouXS5oDW0ZcU6TgYcIoQYzV39+W09SThP+VFlhPHS+atCrBJs3z0ZrlpkHBQIcO7vilhfAMWrcNJAR1p6fxyPw8A7M8s3KNfdU7FzlWC++UVrzXU3gJuu/8FzCOAz0mNmWHQnVyQOXdNRlLwoZhc8dRB5MRBbqHEOIOxUSUHBGjmx6pGV2GL0GHkgubbkAWghm5zNTU/I7NUxieyb0d4/yL9VBWc6o4dZ6BXk+DYoN+ul3sln0lnQQGlzFkEC9JGy9EIhEmofelCEiVK17ozqZFTpLLS7s2TLWf+UiTfYABtrfxKZrUPFEMdBqgwzt8QkXwrF8GDoTGnSURI5Dxbm4t0n31qqwnzpBP3bQZyO7QCHWlSnEb0PTY7TAp4s7gfg3w+1IDi5i5cipFcVjMzrZuOWQxgO3cg0t/oo0/G5qURieusgx6ups2iW9RSmbJhbI3dhMiTAlk0TyC0MsqgX10JyKvRy1ep6H4sj28VtzQ4qPx11mltTelWWUt9gM1QvucbSW1epCrhagX/Bf+f/QMG4+WDrE10J+Kgam2cCtHe0pGoVw84vlb1+q8B0D4g2btGJ+W/84miLNjXofarTXYhXpDsdd9hiv45Tu2mxrIxFVCRcgACoc5ncg1HhSHRooc+MW7ig3e2JDz/bzhy4rc1R3ABkSOc0gl5SQgWJMxHiSpK+XCsrSCwd6eAEJW+pldTgi0v5vsqsVEEVVh+udDRenYSQBwmt+GK9Laa1Ew6JkUzZ+aVGpV56W5fzFHXbB3YloMSu8gISykYk8AITOvpqLVCGHsYfut7zSwk5WJpcUvijJRdK6UPDZeH7KXoVcJmAaXJN1UZrXu1/vxH+o/qQIo5WqFOi6ZNykDNDz9qqMZX/lQCbOO2H4a3Uq iYDGwvVs wRHd8017NBwua0wNCGUqojcE15O/32m75I4RGcx44TdqcaXGBfNiGUlvp1gRAdP99y2Gku2h5V2nqlbhIsQ4mL9Vkx8u+h2iVybTmO3qj9SXTdF+rZLwKutw6NOvKqgATycaZUu1sNVg1B5v3q1YR7EGeyN1F5NnCmFegCXCX2J5OHPhohG+QtEHaZW+5UtOL9UNG17SAVth+1A+RxZHjHbw3QPFxqz0YlumWFTAns09kbtwi4n4utSoAxttLDXMEpAp09R7mRiqh3kcCtbFZWAmKyDKuOhdM+pJfpULZiYsOXsw= 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 buffer_head related handles out from ext4_da_map_blocks() to ext4_da_get_block_prep(), and make ext4_da_map_blocks() always return 0 if success, we can distinguish delalloc map through EXT4_MAP_DELAYED flag. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 75 ++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 9ac9bb548a4c..9f9b1fce8da8 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1690,48 +1690,37 @@ static int ext4_insert_delayed_blocks(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, - 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, 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; + if (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, map->m_len, retval); /* * 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; } + if (ext4_es_is_hole(&es)) + goto add_delayed; - 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)) @@ -1743,7 +1732,7 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, ext4_map_blocks_es_recheck(NULL, inode, map, &orig_map, 0); #endif if (ext4_es_is_delayed(&es) || ext4_es_is_written(&es)) - return retval; + return 0; down_read(&EXT4_I(inode)->i_data_sem); goto insert_extent; @@ -1775,6 +1764,7 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, WARN_ON(1); } insert_extent: + retval = 0; status = map->m_flags & EXT4_MAP_UNWRITTEN ? EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; if (status == EXTENT_STATUS_UNWRITTEN) @@ -1788,14 +1778,10 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, add_delayed: down_write(&EXT4_I(inode)->i_data_sem); + 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; } @@ -1815,11 +1801,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; @@ -1828,22 +1818,29 @@ 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); - if (ret <= 0) + ret = ext4_da_map_blocks(inode, &map); + if (ret < 0) return ret; - map_bh(bh, inode->i_sb, map.m_pblk); - ext4_update_bh_state(bh, map.m_flags); - - if (buffer_unwritten(bh)) { - /* A delayed write to unwritten bh should be marked - * new and mapped. Mapped ensures that we don't do - * get_block multiple times when we write to the same - * offset and new ensures that we do proper zero out - * for partial write. - */ + if (map.m_flags & EXT4_MAP_DELAYED) { + map_bh(bh, inode->i_sb, invalid_block); set_buffer_new(bh); - set_buffer_mapped(bh); + set_buffer_delay(bh); + } else { + map_bh(bh, inode->i_sb, map.m_pblk); + ext4_update_bh_state(bh, map.m_flags); + + if (buffer_unwritten(bh)) { + /* + * A delayed write to unwritten bh should be marked + * new and mapped. Mapped ensures that we don't do + * get_block multiple times when we write to the same + * offset and new ensures that we do proper zero out + * for partial write. + */ + set_buffer_new(bh); + set_buffer_mapped(bh); + } } return 0; } From patchwork Sat Jan 27 01:58: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: 13533903 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 E4DF2C47422 for ; Sat, 27 Jan 2024 02:03:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7EE6D6B0099; Fri, 26 Jan 2024 21:02:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 79BDD6B009A; Fri, 26 Jan 2024 21:02:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5EF716B009B; Fri, 26 Jan 2024 21:02:54 -0500 (EST) 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 488F46B0099 for ; Fri, 26 Jan 2024 21:02:54 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 27B74803E3 for ; Sat, 27 Jan 2024 02:02:54 +0000 (UTC) X-FDA: 81723442668.16.DC2C91E Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf27.hostedemail.com (Postfix) with ESMTP id AC50C40005 for ; Sat, 27 Jan 2024 02:02:51 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320972; a=rsa-sha256; cv=none; b=trK2S379F4xbvY9M4S6etgqQPRz3yxsbd8+CZ6BnJDZj92t4tFicnYoU05iscVuN4fTRIj /rx7RYaE9osPK8hRNYhw0PUPEfV0OFwjYVxhPbK4PAvoHm0zB/KODe5IlLV/kETZ2SYQKm szwOmf496mHBWRstdp5YpznVkXh6voU= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706320972; 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=dyRM1jf5CeAp9qbUfvlJ8CU8r3Drv8/gQ2NAo01PoDQ=; b=v2e/IGNsM0U8taxPIGLM3zqeJkY4ntCauVSdKHY3oetreNTaxnkiwQNaKTuH+qXxLQJlEQ m2Hb42AXB9ybFh7cLlWSN+rDfNWYLn8j7Mhe+OVxt+C+bpG3FxCx+Ss1Td25Eid03Qo+RT Tzsvgh+MuQWc0ix/PHdjCbYd6TglfhU= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrj3f3Hz4f3k68 for ; Sat, 27 Jan 2024 10:02:45 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id E765B1A0172 for ; Sat, 27 Jan 2024 10:02:47 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S17; Sat, 27 Jan 2024 10:02:47 +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 v3 13/26] ext4: use reserved metadata blocks when splitting extent in endio Date: Sat, 27 Jan 2024 09:58:12 +0800 Message-Id: <20240127015825.1608160-14-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S17 X-Coremail-Antispam: 1UD129KBjvJXoW7CF4rtw18JFykGr1kKw1xXwb_yoW8CrWUpr 93Ar18Gr409a409aykZ3WUG34rua43WF47GrZ0q3y29FWUCFyFgr47tFyrZFyrtrWxX3Wj vF40v348AwnxAa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: AC50C40005 X-Stat-Signature: 7wz5cdbt8teooq563ri5aityq8m1rmuf X-HE-Tag: 1706320971-233560 X-HE-Meta: U2FsdGVkX1/JfpeCGTTliLyC/BzFaZ+X593huD1ZUBTS3V0LZgcOgK47ukPQeR2g0GJL/4zZcxpelVdlPtEFQp4lD2AEJh3qCP5G3VxyYFl7IbwZsM1QP7bMLfBMofR7DFaxmu7IIRbg3tqbKpDUyt3m3Iwhc/iQrTQ9MoQ7OZNqjhYWh2cpqa4EU9TS336SNXW1Pd9ka+VRt83Brr/HnC8wonTAjZuFgO9JZGNuK2BX4pQBSK3NZwqEd/K7K1hf1NNKcfFpEV9h6sP1aa1xGKPILl/GdLB0s9A9g+/WxuA+tbGuvR7uEbz4ygiuG0Y71OZxK3BbU04Qu0/HAGvRLnKkZWXwswPxuU3m5V+DUei/wWZ7N7MKFrMD1E8hSFrOroKycO+/0mCw6i4JEuOdUvz3K7fC5XzRynTmH7CX6fQMBgJoGlOFQEAaRQC7ymi7RmNcbJqATeKQkIZLycK9lAc8bnM7r0DF6SHtJMIgIPvhvtiw2n3KCISRius8jKhP/tOUS3lMUYqv/HMHTEonABD7zv79XHX9MN4pv7IfenXKnFXf3YTMYcRIf2U8S7GWuq3A+MZ+FdYpACO87Xsn5Bu0X7qHSnbzOac0YZsVNDkr62YEP9Eq1UgVZlzKYoHfFwMPx9xkGOvLDZYbCz3kAmkef/gDm+KAVxKfGzMu7coUVJd0oTJyzINmxXLwKQju4Y/i3rVHd8mjn+O2McrlWw939y2CPTPVZad8f7gF92af2qOXl79+fnmE6+xkKy/6dW23X7Fh1vOP67qpB/p98B9t1BHL19QScy+So6M+PbETJySVXq9/fRjuE8AIOdRkhVfUP3tJ8k78/6WdeCs4TVBsii9ZQJ2MO371Oz72rAzHwbwX2CL19HCBn8iqBIoa9YqOKxdxATXhyoOVEQKJypmnAetDN31gNIo3Nqg9AHKx5VPTZn93rTL2TLxCVUwRNBLPDbncZ3l0Nmy95Jm R4Zj1QPx HCSWxnR8j7ADTMs1lyqWLFEpjot+s9m2/dzErOnKVJn5erCxiXOQGHOdDS1j1/JfMc7Z69igd2WcxzqWd94DVrhG55swEiThqF6zs/vy/5DKh97YT/H550aNz82oUU1KXY7ymtHDG9FYaCd81WLrZvWPxYA9+V/qyyE83PSECE7AGLQjccLU4qqoYraZ6j0TfeBp1POBAEywUtPUwmEJkEU+MJc4V+gJfZ78CoHFHZj54aO711Ty6Qckck/kxLA6hopS+xbsHz/NTt9fsq74/+I8u0QL6Z9vWKNpj 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 ext4 only reserved space for delalloc for data blocks in ext4_da_reserve_space(), not reserve space for meta blocks when allocating data blocks. Besides, if we enable dioread_nolock mount option, it also not reserve meta blocks for the unwritten extents to written extents conversion. In order to prevent data loss due to failed to allocate meta blocks when writing data back, 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 are just best efforts, if it's really running out of sapce, there is no difference between splitting extent when writing data back and when I/Os are completed, both will result in data loss. The best way is to reserve enough space for metadata. Before that, we can at least make sure that things will not get worse if we postpone splitting extent in endio. Plus, after converting regular file's buffered write path from buffer_head to iomap, splitting extents in endio becomes mandatory. Now, in preparation for the future conversion, 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 6b64319a7df8..48d6d125ec37 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 Sat Jan 27 01:58: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: 13533909 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 D82B0C47422 for ; Sat, 27 Jan 2024 02:03:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AADA66B00A0; Fri, 26 Jan 2024 21:02:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 904566B00A3; Fri, 26 Jan 2024 21:02:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5EFF36B00A1; Fri, 26 Jan 2024 21:02:57 -0500 (EST) 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 350C56B00A0 for ; Fri, 26 Jan 2024 21:02:57 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EABEAC04C6 for ; Sat, 27 Jan 2024 02:02:56 +0000 (UTC) X-FDA: 81723442752.24.5F8EAD4 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf22.hostedemail.com (Postfix) with ESMTP id 7C6B6C0017 for ; Sat, 27 Jan 2024 02:02:54 +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=1706320975; 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=J2QS6ExtvS7nsfEMfwbh3PqT+OTW1+ESgoG5Yrg4D5Y=; b=PlPAylXCy+RtjZ9v7aqj8AROLjkcohAyiboYM/BNs4Ri97iAUJz/IUV3rQCA9PPOKg/EDo JZvSVvp8iQzjD1vI/xKmyMYBm1ZhrNg03FcoRHmoLHpZgDn3gFtnWhkr/boOJ2FCW5XMpJ 7ffh7PqBv+Y/5RyIuvF78cbiENapW2o= 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=1706320975; a=rsa-sha256; cv=none; b=jeSjlRIoqAuFZ3Ku1FEcfk/xc79YRLBn6J0oDGEa5G6iGix1M2vVDuwAlyGJDwB2c/5Nbo xFhJLf9TTZz/woeMD4sAPNLwjOjjLw3W96+WRVu719HTSiAqQ+zfL6kvWJHymJFYJbkh2Z Aqt2lAFAyxNZ4YtVTcW1j2vxKLasQtM= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrf1jdMz4f3lft for ; Sat, 27 Jan 2024 10:02:42 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 960B61A0171 for ; Sat, 27 Jan 2024 10:02:48 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S18; Sat, 27 Jan 2024 10:02: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: [RFC PATCH v3 14/26] ext4: factor out ext4_map_{create|query}_blocks() Date: Sat, 27 Jan 2024 09:58:13 +0800 Message-Id: <20240127015825.1608160-15-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S18 X-Coremail-Antispam: 1UD129KBjvJXoW3XF17urW8uF4fCrW7AFW3trb_yoW3uF1Upr W3AF1rGr4UGwn0gaySyr48XF1Yk3WYkrWDC393Wry5Z345CrySyF15AFy3JF9rKrWxZw1Y qFWFk348Ca95GFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 7C6B6C0017 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: rxc3rz17qm9tgia8uxb97bu3tb3o1g5p X-HE-Tag: 1706320974-21466 X-HE-Meta: U2FsdGVkX19Xlt6VdW6W58niyroA1btZKAjznCuUUDxwn3WQmOu+sFooleiQsYrqa529ITy8TA3iQ7Ftp/IeOxYFZEqpYV2OQCO/pkEVmOoyQPQCIbu1Jhkn1j2T1vIb+KWQhQ5LnGmsd1JsDcs3sk5fMQ2zS8rW4rhwtIPRf1aeU44pukiUbHohIi0zyFYScj+iAf4MdyS0NlCIuEqytFpsH9Aut/ltSMNYl5FTANTQnmGrhiDWtTbeTo9roI+QjZFRTtlw9nMjcL1q5FsJGK0e7aOnj3OzFsljXK3rpKR4lDlzcllfQcHSIwaRwAneFZdWe1rFMqI7SWgvhU3TLFNHyyqSPNU6Fr2hKTbl/r4a0LT5h3Zs4IjV2XjdxMk/vjZRppF151ff5JiJXSDG9rtfUYw2/8hfz/rBLZatkoLgDE5CMah8/jPUk5YPVmgv+S0NMINNHesQMt72uRbK+bD9jKCJNMH28hHm1qhGM3MKSAQnojy6Sbix1tdOUS+KkfVI2Vxr4dR+Q3QgOSzPsLZMe8/aICREEGcw9w64moee3dKHbvHwOEpkoH97Ik36AxR6Arat7/ltgW00O7dQXZ7VmBXQb7Cj8W/XtkFjVei1ggxIDlwJ9DgKiYLcFxziqvGx4+lYnBVuPTZcZ3mf/EiwiYVnqotIHG64XnR98gwErROwHMo120a4JQI9uXsuJboA0qQAiXO72alut8Llk0eJprLJkxXMWysbkElhXpAcd5hw4VCOyNtadBGz0qaktVBJK8X6JBxvdU1DFru5mGZYdNlbv+TApz/n0rWdDqklr4I72gcCZtvYjxSO+DQ1MlsTXY2EqZt0l+vRWwfgc+W35TLCri/7wSdI9tcKlBpnA3EFJEyzZ5En7Jk6/X4bkmdk7FRubxnsCU4jz4fF410uPkztAdh8lYzD4CxSUVfeww4nWOWjf5+rQXLN8bo0iO8vaAc+ZE8BP7IFjvh mXsCKoYF HIdgNV74+i5dRbBP8zxhgFKfjJtP3QRYjVU88rxIsoAeVGr3VNL7qe62JkoXpQOc7dRzG9VE8O8lWBqf9x6ZRcwm1odQShnbEaaGBcn8oCjhKPbrTm+dKP4ye4MMfFcQMGxZVebvAVydm+/DgLsySBQgkvU/2sDgdGG2JesgyD1JGlpKoLpxvMBNndX0K1r0JEL+GIOLu03Z8fQGLRdjop1fzVrabSUGRi/EN3S+6R2rbf/SkWCqsec3BpkYmmyoTjbxtbtuai1gov/UG3ibnVI1M9IS8vx250pobm7A3pyzURGk= 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 two new helpers, ext4_map_query_blocks() query blocks mapping, and ext4_map_create_blocks() allocate new blocks and map a new extent, no logic changes. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 219 ++++++++++++++++++++++++++---------------------- 1 file changed, 117 insertions(+), 102 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 9f9b1fce8da8..125d0665fa10 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -453,6 +453,121 @@ 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, int flags) +{ + 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; + 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; +} + +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. @@ -546,32 +661,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; - 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); - } + retval = ext4_map_query_blocks(handle, inode, map, 0); up_read((&EXT4_I(inode)->i_data_sem)); found: @@ -601,12 +691,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 @@ -614,76 +698,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 Sat Jan 27 01:58: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: 13533906 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 5B790C47DA9 for ; Sat, 27 Jan 2024 02:03:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB7AF6B009E; Fri, 26 Jan 2024 21:02:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D409A6B009D; Fri, 26 Jan 2024 21:02:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B6B596B009E; Fri, 26 Jan 2024 21:02:55 -0500 (EST) 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 A01A96B009D for ; Fri, 26 Jan 2024 21:02:55 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 76BE2140F0F for ; Sat, 27 Jan 2024 02:02:55 +0000 (UTC) X-FDA: 81723442710.09.895D506 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf30.hostedemail.com (Postfix) with ESMTP id F02F580020 for ; Sat, 27 Jan 2024 02:02:52 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.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=1706320973; 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=uC1nS63G2vqggRSn2dOOIt2ysYrZz+B3cJj8p8R4VNQ=; b=Z5E4zAFR708a4iyFIjI2FwwPrfR4SwgX8+184XcCc72SxW0yfxczaSDP3WFX1zP2bjM4vX Tjja8DNjKF9rni9DZFjEV0JsFSvXICUK/rKl0IB9sH6RBQW5yGIj7KzPPOn4NQMHHbqGzA qKeuccyHrJGsB56G316bcAARufWJJLg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320973; a=rsa-sha256; cv=none; b=LSM5vxCaGCz7cirYJcp/VrbXh515fBFbS50k45duaSwuPWutPb0RNTKWOLOYvmNJQzv6bE Fyvb5+8KZkyqHmZxLCfvUqc7yh1LYO0JFIHGJyVThvWoMOi6IUYQjG2aX3a6ouxi4ZYhU4 MIc4YndsT/MgKPi60KGH0PFqmGq2rzg= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TMHrj1tbpz4f3lwb for ; Sat, 27 Jan 2024 10:02:45 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 442B71A016E for ; Sat, 27 Jan 2024 10:02:49 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S19; Sat, 27 Jan 2024 10:02: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: [RFC PATCH v3 15/26] ext4: introduce seq counter for extent entry Date: Sat, 27 Jan 2024 09:58:14 +0800 Message-Id: <20240127015825.1608160-16-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S19 X-Coremail-Antispam: 1UD129KBjvJXoW3Jw1kZw4xGFy8Jr4DGF15urg_yoW7Zr43pa 97AryUGrZ3Xw4j9a1xXw10qr45Za48urW7Gr9Ig34rXFWftrn0gF1DtFyjvF90qFW0kr17 XFW0kryDAa17WFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: F02F580020 X-Rspam-User: X-Stat-Signature: rjgtwzgmzq4ogieb68gtecf8j1ebnz1e X-Rspamd-Server: rspam03 X-HE-Tag: 1706320972-689495 X-HE-Meta: U2FsdGVkX1+GSscDitjIsmftVx0yz4e4wMCqb1039BjZP4iC8GGrw/7sruvuq+f99bQfy5la+5OThhOAHlxf7n2t1bH5vyBQmbuSPNEetyINWFEANeIyDf26qwUolXA9Cjb1cl8AWxFIRRZplhH4gahOGoIlgFRdgJXk9Zd7gFC48+GQyYB0RAUnsrzIhjJNgOODkfj6krxNSBYYD0OzFyFkj3/V6e5y12DcWM0GnDVu1gZyseY716NATS3b9jP5puOc5LHAXDFkltTsNze8kLw0ZKKjHJa1H6ug3BXOGK3UZDTuccG9Lfkwm+zUuzWKKOevFdIQngONK49OxVZtiaKVboPsd0rcI5GSmjrkiGtE+PrN9waodoPTEaGMD+TxSsPPprCRZo3wj7o6z5p7HxT//HElgT4Pn2wo3cSAjqCOGU1t5w1Ouswi19HyO7qLVu+mqFSzPC/TSGRT3gXk0qgQlKMR9+SEhZhuCk9TjFXye4M+BtUx5r0VfAuiMZ5BgrSsrB7a+d/Dnh0FNAPeHsVKSw77EOdSSPjlvcqE/7clZ0uyn9uDelbv8+owUeN7ZhI/Z57ypyoHFEoSyuqfqjJhHhNQbMJebIzzjaOwkf9tvCTQzX97CHmgowLdr7wtqQpvH0ShxZWcqyTqGKBodsEXzvqjchgvxnB2g1P635LnI/HenDjgoTLdUJ+mTOjgkwB5AR70V9KoHIWN0ByY1RwmEHMPL/ABuNH5xcbALNJcvYTwnrg6vyceQ1sPGMR1kUyDXDQHFoKkj8/1RTYG2NqqV2vFdnGTYm+vCMrUyCzsi3quipUaaKUlBUU3WYKfV/+9fxMxT+QXumKAKw8/GW/V7FWGvM26BocAWG2nO4ynDjbQULFhrbR/W/w1Ta4NbBz1mbBCIQ5Y24W1uAnPqyJrLzFnlZPydEpGfXXbd8ta06jYs0g2gDoXwZfMim0AocYzfB1tBDi1BqcFT2/ XaCoJDsh 97Fn3J40hGzRH+1ym+EOh5VkBjuN6q99L0wayZoqIsrns51l94ie9U0muwJKdHW3dbmnIab5vokO5CDgFJIljPHIO/yQkk/7xtGbK0k1EeOsmguBfPkb+lgCPX4ISDOzOB+W4v1EscoLVppkkx1Tv9mhuPuFwj3ONtL+5gtsMpJxivNgG/Ivh1/4mTHWKhV462JCq3VUgR3s/bIOx+Za7/HSi2Ps686qqhK54r9ETivJKYwAdPsuerrshrIL7lBJJ1yubhZ4ag7rWQR5vvrRRmoAfR5/xBpOjOgv8 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 extents to indicate the version of one inode's extent status, increase it once extent changes, it will be used for converting regular file's buffered write path 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 | 19 +++++++++++++------ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 55195909d32f..287284a3f128 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 324a6b0a6283..b0a4aa60b311 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -204,6 +204,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, WARN_ON(1); } + ext4_es_inc_seq(inode); newes.es_lblk = lblk; newes.es_len = len; ext4_es_store_pblock_status(&newes, pblk, status); @@ -1503,13 +1511,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); @@ -2080,6 +2090,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 c5fcf377ab1f..d4afaae8ab38 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 53aa7a7fb3be..6ae504c43de7 100644 --- a/include/trace/events/ext4.h +++ b/include/trace/events/ext4.h @@ -2186,6 +2186,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( @@ -2195,13 +2196,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, @@ -2226,6 +2229,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( @@ -2233,12 +2237,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, @@ -2497,6 +2502,7 @@ TRACE_EVENT(ext4_es_insert_delayed_extent, __field( ext4_fsblk_t, pblk ) __field( char, status ) __field( bool, allocated ) + __field( unsigned int, seq ) ), TP_fast_assign( @@ -2507,15 +2513,16 @@ TRACE_EVENT(ext4_es_insert_delayed_extent, __entry->pblk = ext4_es_show_pblock(es); __entry->status = ext4_es_status(es); __entry->allocated = 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", + "allocated %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->allocated) + __entry->allocated, __entry->seq) ); /* fsmap traces */ From patchwork Sat Jan 27 01:58:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13533907 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 C97A0C47422 for ; Sat, 27 Jan 2024 02:03:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 424B06B00A2; Fri, 26 Jan 2024 21:02:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B8C06B009F; Fri, 26 Jan 2024 21:02:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C1F16B00A0; Fri, 26 Jan 2024 21:02:56 -0500 (EST) 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 DCFC36B009C for ; Fri, 26 Jan 2024 21:02:56 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BDE5CC0166 for ; Sat, 27 Jan 2024 02:02:56 +0000 (UTC) X-FDA: 81723442752.23.69D6D6B Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf13.hostedemail.com (Postfix) with ESMTP id 41A832000B for ; Sat, 27 Jan 2024 02:02:53 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; spf=pass (imf13.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=1706320975; 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=jZXDX/r428qGIjAuoeLgCUOV30TlAf4fX7eW5feSwIY=; b=yco3jGlYE+MVlrOrC6XW4K/II+hirosUqiEJOdoSUXcxX+WRoZQgYxZNUsXI4cXBuHJLYz MlqdKNLewihCoQQzzN4Ec26vXTY58A5uCXAkjyEjigb02wR3SJlWkfiZhsxwXxGZlB92YE 8vfQarX8cJwREujQ12xQEYx/EvBgZKw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320975; a=rsa-sha256; cv=none; b=ToZFuscIwPY22Cnatf9I/qkwETjXCTx1rIt9qKlx72SS/WSc/q/Gon2Ez+Yrkdz4UwCUlD ofWtUq4PuSuU4GKBgFx8vpBRccb7qPCpN81nFpNF5AbfkAmt/dC2hY8cESn1l478BtloGx 1RtqH1hAkqFV4LqYU3U0DzgPChGZ+DA= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; spf=pass (imf13.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 4TMHrl3gNqz4f3k5v for ; Sat, 27 Jan 2024 10:02:47 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id E77361A0272 for ; Sat, 27 Jan 2024 10:02:49 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S20; Sat, 27 Jan 2024 10:02: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: [RFC PATCH v3 16/26] ext4: add a new iomap aops for regular file's buffered IO path Date: Sat, 27 Jan 2024 09:58:15 +0800 Message-Id: <20240127015825.1608160-17-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S20 X-Coremail-Antispam: 1UD129KBjvJXoWxur43KF1xCr4ruw1kKF13twb_yoW5Cr1UpF Z8Gas8Gr18Zry7ua1fXFWDZF4Yka4fJw4jgFW3G3Wa9ryrGrW7KFWvka4jyFy7t3y8Ar17 XF4jkry7WFy7CrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Stat-Signature: csfjwij7en9w1gd1jk8r5whkb78ksu6d X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 41A832000B X-Rspam-User: X-HE-Tag: 1706320973-578363 X-HE-Meta: U2FsdGVkX18mF1NoWdnEmHqol+NEn+MjiS2N0YdZq2Yc0b5ERdOQwgUY/T0AoJgCHhcYg4pcbNIya7jNeKyXCnzuOtP0F+BMfW6RLxfDqqaBu2XIKEqG63lp/VfVyKimmZzfd6h+1J33vq2krOjmSmhT/FYmkTUxc2MDCZ0crTnIUXoVh9/lhaeZWdtGtTsmeTwBFpr7WcHWKrZKQf867hSxAok1cvRliTDp9VWBBUsRdnE7n5kJJ2vxSb9Fvc+KigstbeIybgGJrdy2GLBO9Lqxh3tCaNJ+yQw4erbu5MPzmOdqvNHX6PEe83yYLweC8IYJdhWh9AzrjT4Djt7tY5LEhg6kRTAZYuq0nZEErAmU3GpMUHiLF/TnIkFC9dX8XvLuH80VbdOicBPD6v0bKE3phix431NUJSa2JoMuCBjKokXId8OyQXn8C1w36EoZ4oKIUBgeZJ8PAk2aXrh6jIqHdaaxgzqgyxXSUziuQV6DvIMjPIlDQiYj/xwju41ihCu7Okqic01j1G0ou4YSVkwgXE8GDb6f/vmv1IAUYznu0GpFwXTIfuwk4FjNl+aRTvoEx5+dL6BbMjEbG5yUFQ67kPY6mPs3JNed21vC3ISiwjMN+CM0jto73smQDz4svCIaLEHx+unEqYvTzKY4Ig2EPXHTblSB7uPybbCNuZ2Hf9gELAjrNxXfN05LfNbzoO1hoMLJeOyokdhmslqFef890v/y9Za2r8rIVm59EyjvCr9RBau5GnPx9ffKjnUBu/xAaPi3D3JO0lX/Z6ozsWhLvVMuaqi/QssQezKoKOK0pA2HzaYxwpuVKQXpWXDbsDi4GjokH15IeB3KhUYRlNJL/RC1bAkNf/mEda9NNq5XNR0GzctvNNaPYg/ghs/laHlh4PvvEpniMNGvAxeFnhpMAvsY8oWBuKABPjPDhOF1j5hZy90+qkM2KhGIF9UrMCP4V7kiVzjL+ZWbSMt 3aIcPF6j J0D/0A5frGyKadppk8jTqwdsq1Ze60A+cCDda70GiQFb3OqTnrSrG5QEyozNtcCExn+nA3w/iVexED1gwHcipYS3EBkltFeRQJNLKdNWca9VBo+YzeioS7ssURL7RKrse0lyi8al9SXbkiY8jfVCY0iLAlw7gqbPd0DQcoDmEcSM+4VMsGuyrm83Qnctl0O2knj69OfJVR1D3rEl19ME+SZjTfLIVIpKVeRI91g6VfWexYHhkewEaqaKbLvFMk99kxFyO 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 and add an inode state flag EXT4_STATE_BUFFERED_IOMAP to indicate that one inode use the iomap path. Most of their callbacks should be able to use general implementation, the left over read_folio, readahead and writepages should 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 287284a3f128..3461cb3ff524 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 125d0665fa10..eca9bf5dd255 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3507,6 +3507,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 @@ -3596,6 +3612,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_page = generic_error_remove_page, + .swap_activate = ext4_iomap_swap_activate, +}; + static const struct address_space_operations ext4_dax_aops = { .writepages = ext4_dax_writepages, .direct_IO = noop_direct_IO, @@ -3618,6 +3649,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 Sat Jan 27 01:58:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13533908 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 1ED26C47DA9 for ; Sat, 27 Jan 2024 02:03:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7273C6B009D; Fri, 26 Jan 2024 21:02:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 41B1D6B009C; Fri, 26 Jan 2024 21:02:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 159E16B009D; Fri, 26 Jan 2024 21:02:57 -0500 (EST) 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 01BBC6B009F for ; Fri, 26 Jan 2024 21:02:56 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D4C1C1406D4 for ; Sat, 27 Jan 2024 02:02:56 +0000 (UTC) X-FDA: 81723442752.24.1717548 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf14.hostedemail.com (Postfix) with ESMTP id 4EE34100006 for ; Sat, 27 Jan 2024 02:02:53 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf14.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706320975; 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=V0qrNBKHUWdDnSnlHTyNTuDS1TnUypLYX4BpeAl7EPc=; b=EooDYkfjHzBR2i5FYRf7SarGHXD8C4w2N4e0PjQbHQCcEwYGKpkddOfWBPFsfeVZw1ZHHo Y9RLHJu38oLJuU2Ql3tGisc6uiw+yQf66AW+RRKXPvCX+ul2BTTo42Km/mnL02FDy22nrT 1LMwf+JXRJSlCzZu8gB8Ie2w01q59zA= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf14.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320975; a=rsa-sha256; cv=none; b=B9useJ4hKvbz0FyeqVww8iE0u8rLJrONkiQ8Qg3yPkQst8XTsLqPG6uUllQEAUyfUcoSBj 2oDuoJMCkKQpxRw/W3gOTiKvxMhd4ELSTRfzZ2uWPnErF2M/JC7sZ0cIdWHtrnhlFQain8 sllqhHJAHwBfiyAx0Yz89jsNa7aHxv8= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TMHrk4F9jz4f3lx9 for ; Sat, 27 Jan 2024 10:02:46 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 94CAF1A0171 for ; Sat, 27 Jan 2024 10:02:50 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S21; Sat, 27 Jan 2024 10:02: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: [RFC PATCH v3 17/26] ext4: implement buffered read iomap path Date: Sat, 27 Jan 2024 09:58:16 +0800 Message-Id: <20240127015825.1608160-18-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S21 X-Coremail-Antispam: 1UD129KBjvJXoW7urW7uFW8uw17ZF1kWF13CFg_yoW8uFW7pF 98KFy5GF47XrnI9F4SqFZrJr1Yk3WxtF4UurW3WasxGFyYkrW2gayUWFyYyF15X3y7Ary0 qF4jkr18GF1UArDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 4EE34100006 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: m4jghdcq7npdu81fs5a6mwm1iriu5p7c X-HE-Tag: 1706320973-586285 X-HE-Meta: U2FsdGVkX1+xOyELBnETsWMUhRA6Z5R0gwmsrTO6JTYIY4nYiSSofKyKxYUUfKCe9DLgzNemUIFdA+6KlZosQhWwtZC3IeHW+ku4KR4V2oGZDCSXmOquYsbo5JHc4S5B9IfEcDN0Xk+JFG82JkplfZRcBiRHSDPPhmuHgXUjQKOovtvzQ/QzsjIIDhdvowEkdNWf+uBbIDAXB/NfbOTqac4T1z0ORVpEhQKC4nF+sZ9GausMekOuKTjkHOFXgSxWuzs3vtt1vqf5NGGOyea3VeWyeb4rjlo9uzaMve8DkNogSsrL7IRfe+TVbW1/fcirQYkuNXDPe7ghzk3mKOP8iqTdoWxGuDBIyLE91TwBwS3TvpwoqrpEu2STkrIwJSLlCIO6kaRCtCR+d7F+gBwNU2WOAxI6Gfl47mlwBOd00Ir7hLxvIdKFQlghm/ZXVpCz+CHju/7fatLQiYous98VQz4xrTvHUkimw+dV9iR3H5UwtGiD/V6O/+dfXxXmYeInWtslkfYrX+68Em/k2rBeKNpeV3l5c4HEZc79oTPt2CKii2wZtWxm+XjCLk2HJfAF/BITc53FV0Xcm8yvH3Qh8lHWUN3KwqkKRYFIpr0yc6znxTAQunFoiWLvcVXHv5d+CNooH/eBso8zrH+DIyVVyGNUxqCmJzyKPNhpcm8N7o71c7G83zR13kitnsZ2BLG0tHK2MKCJRU6GJV+TidEe34+FYd1cHLtBVbqWsV+uNzHe36YxfDFmhR1DphhEtPQlzvjz/pmaGUwvr6pFAYjbeygIB7ec6BXH2fObpNSVY6hBf3Tpjd8EaoaO6Q2TU2C8B6WkYj/GHvrp7UX/BKsHyzf4QJeTSEEGnSziPKi44HKzbyM37XLkO8a9ZEZ/bt/Obvbsb5mUu132IL/h1KPfhsP7ty86YiOfNYL8/fhdhyDftCiqhxWcBtCkrj4V3FdS19AUKMTvRhal9RaM/60 KjZrtBIC 1HQJ9S4nV2yRS3PmOaAl2Imr8ac47O28s2SpukkMnMjIWUZXZMZPdPoc24RB3E1cMirKea/JuTHp7j9tiBtootlAC0Tvd3gsOIMX8RRniRyszlOJ041NpG6debzlgUoEGvn0vS8c5YXrsCt4u19kL9gtTP8m+bU/ZakRX1qT1bZGfxhOkMipGDgMWkeRKVt4DrIr9FhdU6Hr1JzXqDB6PmEj6HUorPrXplZRtNJAIE/jjnFfmiYrH9rnnr5JEsr0Kk95Y 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() to query map blocks, and use ext4_set_iomap() to convert ext4 map to iomap, after that we can convert buffered read path to iomap simply. 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 eca9bf5dd255..5d542ce13d2a 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3507,14 +3507,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 Sat Jan 27 01:58:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13533910 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 B9B85C47DA9 for ; Sat, 27 Jan 2024 02:03:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E7CC96B009C; Fri, 26 Jan 2024 21:02:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E2A886B00A1; Fri, 26 Jan 2024 21:02:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AAB646B009F; Fri, 26 Jan 2024 21:02:57 -0500 (EST) 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 7FE316B009F for ; Fri, 26 Jan 2024 21:02:57 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 674441C0FBB for ; Sat, 27 Jan 2024 02:02:57 +0000 (UTC) X-FDA: 81723442794.18.F1C3A49 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf23.hostedemail.com (Postfix) with ESMTP id 0B82A14000A for ; Sat, 27 Jan 2024 02:02:54 +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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706320975; 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=c4b+UUrjOV+PbxS3N7EWCREBI1daFn8kJscWvxsFcbw=; b=XP2eNEA/2dv1ZxuVi91MEQuf01RnooLQzXxy02FVmD1FAtru5tFr37m4n6I/f/ACICxZo/ LySCPeyuL62ZkRNffF+VA6OZF++9yRv3MV0xn/nBqZ+albiNIRsrxHAtfygPAkj5B9Q3B9 pLKEHqpho2uxpE23zy8pYeRltWb0X8Q= 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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320975; a=rsa-sha256; cv=none; b=YGCQF1SVhTkHIAzVxdco1GkXM6vYKFIcih6vMvuojdPy0hMmtnugSJx52FopnXtnJOoAt8 k92vTYqsn3kwp8DIpfuwgAXwNXv1MPgIh2GNXi+am33qunEYohPC6x7pqA4BPVV1QLy/j8 3EmS4VxTqsImSb2eeyoqXKxagdyD0Yk= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrm5v65z4f3k5Y for ; Sat, 27 Jan 2024 10:02:48 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 4019E1A016E for ; Sat, 27 Jan 2024 10:02:51 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S22; Sat, 27 Jan 2024 10:02: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: [RFC PATCH v3 18/26] ext4: implement buffered write iomap path Date: Sat, 27 Jan 2024 09:58:17 +0800 Message-Id: <20240127015825.1608160-19-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S22 X-Coremail-Antispam: 1UD129KBjvJXoW3CF4UArWxKF1UKw17Zw1UKFg_yoWDuF4fpF Z0kFy5GF4UWF97uF4fKF4UZr1ak3W7tr4UurW3Wrn8Xr9FvrWIqF18KFyayF15JrWxur4j qF4jkry8Wr47ArDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Stat-Signature: jtfs11nnky14zcygsductfw94a7yj8bf X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 0B82A14000A X-HE-Tag: 1706320974-33999 X-HE-Meta: U2FsdGVkX1/B/bkpsX49WEK6sv8sh2/lgOJ3LAAjPEOLZ7gSjjhEimux4BKonBFd6xvUHrMhDUzn+AsQ35B2ncEzy7xrsSxeG0GxFCjARfztu11yUxjCy0ucBsDhWKVLPOtuVEX7YuEPLR6JB6wlYeGMp9DPRpWAtLU0Y91ChewfG2yfcBYWmH2qtwIdV7lrEtdqo4qjS8kj8cwo7WvKUDFHehnTmqqiPcnLQem2FAeYcIG6TsRPo7K1sio0BL/Wx2Ji+JXeMPcxCH/ZYevzdLoe4Ejux6zVNUEyWMMnNMXV5iNyRUr6f6RKn6swxOkSJc2xoJydfC/g3avu7JFXWVc0smd5QKgd5IcWRMMmNBWcl0IkJIbwTU2gadyboTrlAaxg85fveHTpaddv8wzahI+izGJvj0UzMDRC7f1AU1jRVQfRR/oexJrW+h1U3dwsOVHkHZwHlgg/BQ1h5wJsP/1NFizYhAX677KZdEbUPQmgoSZkrBFyEyzx4FvQlMFiiS3d1ZT25SwknMlfkwRRG6OFBox5maD5hQDKIwvON+/JAHmdv5lDyJVNV6DDKmN3eQCyrL8s0GcDAGgK/eWL1cFxZPOmRvdVoBBDbd+xrH0FCAcg2D1qD36dmG1BqbxWayVIpr9alj5vEyeAOPTQ0bXWYPhiH2rGctvCoeWrI1MKdzQ1YB83sWh0T/ORgp/sRHb1eSvktL6FHPKLGdpK3CojFe4XRHOR4AtHdVcP5kuxxHao9jARNr47SbO7ISNVK3EOz9Ji47pUCir6eaveC5erLcODmbpO/IyoTKkUB+IFzDT1COTnTbSThcuU3Z+15JL1oZQSJxOT8svA/hfq/UjXl10ms2D8XtVPRQ+m5K9IhlpYriz0HB1Pl4pm/OuEgY0akAvt8dJfFcKlJAs0umQlFYRayXgx5DJpGOwP80+puIpVmGtUnc51XJtvsn0Z8aQk3SkMkD1L0pnDYUy PnWqQQVA sOlv/ 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 don't want to support dioread_lock mount option any more, so we drop the branch of ext4_should_dioread_nolock() and always allocate unwritten extents for new blocks, also make ext4_should_dioread_nolock() not controlled by the DIOREAD_NOLOCK mount option and always return true. Besides, the i_disksize updating is also postponed to after writeback. After this, now we map or allocate batch of blocks once a time, so it should be able to bring a lot of performance gains. Signed-off-by: Zhang Yi --- fs/ext4/ext4.h | 3 + fs/ext4/ext4_jbd2.h | 7 ++ fs/ext4/file.c | 19 ++++- fs/ext4/inode.c | 168 ++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 190 insertions(+), 7 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 3461cb3ff524..03cdcf3d86a5 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/ext4_jbd2.h b/fs/ext4/ext4_jbd2.h index 0c77697d5e90..c1194ba8d6f2 100644 --- a/fs/ext4/ext4_jbd2.h +++ b/fs/ext4/ext4_jbd2.h @@ -499,6 +499,13 @@ static inline int ext4_free_data_revoke_credits(struct inode *inode, int blocks) */ static inline int ext4_should_dioread_nolock(struct inode *inode) { + /* + * Always enable dioread_nolock for inode which use buffered + * iomap path. + */ + if (ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP)) + return 1; + if (!test_opt(inode->i_sb, DIOREAD_NOLOCK)) return 0; if (!S_ISREG(inode->i_mode)) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 6aa15dafc677..d15bd6ff1b20 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 5d542ce13d2a..c48aca637896 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -2842,7 +2842,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); @@ -3238,6 +3238,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) @@ -3268,6 +3277,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 @@ -3507,11 +3519,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; @@ -3521,20 +3564,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(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 Sat Jan 27 01:58:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13533911 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 E1AE3C47422 for ; Sat, 27 Jan 2024 02:03:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C52C6B009F; Fri, 26 Jan 2024 21:02:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 79CDB6B00A1; Fri, 26 Jan 2024 21:02:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A0946B00A3; Fri, 26 Jan 2024 21:02:58 -0500 (EST) 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 421DF6B009F for ; Fri, 26 Jan 2024 21:02:58 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1441BA1B71 for ; Sat, 27 Jan 2024 02:02:58 +0000 (UTC) X-FDA: 81723442836.10.1AF5401 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf05.hostedemail.com (Postfix) with ESMTP id 9989F100014 for ; Sat, 27 Jan 2024 02:02: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=1706320976; 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=rsTGrzoWnjZ1nLzTycpGM4rxzaTDNiMxWKaoTYkDihQ=; b=UtsTVng+gOe2G1OQVgdfMw/W/Z0aCE/bVH+gyblKTuD0FoTCmR6VLAMhnwwjvO8+xohx5G r/deKG/0pqyhy3RP5iS7YV66EwsRJAg1WZi4ybYKlbh/FUqjl1s1JBOnb/n+MCyipRgBAb CRCjUv8D/RwcVIedEdPXyp3k3+ep6ys= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320976; a=rsa-sha256; cv=none; b=wgNdCzYbxWJpicUp1sCkV6calTfkiSuckBUjUEp2weujvz/TTvJtGfhAEFLzRZwS4seD31 kSGreGDwXpVT95sBK0ME7ceykmtKicxKDm5PdCFLnn7RRTEy4S1bmCcXO0QUZto58eZ2FB A7Fx9h6r4H3RO9ZvJZv7h3xufuOx9QE= 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.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrj43Mkz4f3lg3 for ; Sat, 27 Jan 2024 10:02:45 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id E5AAF1A0171 for ; Sat, 27 Jan 2024 10:02:51 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S23; Sat, 27 Jan 2024 10:02: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: [RFC PATCH v3 19/26] ext4: implement writeback iomap path Date: Sat, 27 Jan 2024 09:58:18 +0800 Message-Id: <20240127015825.1608160-20-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S23 X-Coremail-Antispam: 1UD129KBjvAXoW3CF45CrWxCrW5XrW8Zr4rAFb_yoW8Wr4kWo WavF43Xr48Jr98tayFkr1xJFyUuan7Ga1rJF15Zr40qa43AF1Y9w4xKw43Wa43Ww4Fkr4x ZryxJF45Gr4kXF4rn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UjIYCTnIWjp_UUUO07AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20EY4v20xva j40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r126s0DM28Irc Ia0xkI8VCY1x0267AKxVW5JVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK021l 84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4UJV WxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE 3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2I x0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8 JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2Y2 ka0xkIwI1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG 67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MI IYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E 14v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r 4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjfU oxhLUUUUU X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Stat-Signature: z76gnmgxy9yacm37d7p3wb6m3jd7q4b5 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 9989F100014 X-Rspam-User: X-HE-Tag: 1706320975-333152 X-HE-Meta: U2FsdGVkX19wbhCN+2UQ/8JSs2/dOjBMaTX6BNDuClIMtUS2fvX46RX630YiT8vQes8sVIJLVWBZrFA8daL5Rs5qrdrzq5eBpFgqLttJ4U3qbCs1ljbcVg/dPwQwYI8h2Te6FgvQ859rPNY77UOsL2JhWQP05hHbPk6H69FFlz75KroBpvnzEcI7Xv3yoUmFOLvfR3Wbb0TKbu9OaFSDhf2LHTDv7GF3edAQORbGPOYVGZcf0lDGMFLPTkwnPCD9b/N7x+9xqP/ygKlrL9CYXKLJpiPp8v60Yp16TsTW/Q7m5TyxTJjZZMvTSNpQ+/T2wPHUvlJLTW+2qSAjBtpO3J9hlutBjZgdJ1OWSTNEn3CH46ZbQKHQeV8RUjf52M0+2vcEYoOqEtqQ1ecXeMiEuv1JhbGYlAPDEpuSgzhN0yN2WO4AO6pjqhOhWRvKWTJj+IPUOMpy5JsTh5BxGosTK/qgGjseDpsQ3bHVi5kCVObDCe5HNMOgshtlOILDXlHr2Ypkx5x8YEj6se3XRHnCSvOyUITByCT+ElnOY2Xz9n8j091QY3mOs5wpXNxpRr5namlsDZGA9emJOBvrcrmtdV84fupyVuKJlPU/qo3AzbomzQid6Ut13ZWYAHU7skaoZwzSgCqIjPVZUMK8Iu18FezMGd8FeP94uxDhUXaj99s16FdOxPa0MkOAoYIFdLasq6GlicLUvG9Bi5VFUatD/BDDFTWy+nQ5MtxMWmmhzmTuW+Vi8hnvpvCRFTBlc8ArXjGghYgWu0p5viLwdH4n3JUKiZkyFliJQWm6XOjjpnYLWAvW1Smkc95CXIRK6e5XRwYltsD/uIt+Dhe7hePt4SRuEa5+us2v2v7/S15BXdJ8U7H9ZLrc6VnHxOqPDvrRIGWcqOa5pf6qNg7H69n8lEMfCPfBQj06H4ywQQ05DaF1b4Ll++WBJr+SPaL8/9HJAJONAEDWWNh7I2hPcWU 5gTQ0lTj XcGrmfO/5hMHQvU3AF0zYXqAF3FRwVEbdA99/Us6i0IrfsMo6W+TyCDEM+7kvj7Ql9qG2rN6TKQ/jd77fZduDynveqEWivrtlPxXYeJ99m1kLPPNBZ8nlKKifVpW5sT7eNmYeLm8294WzYaLRx7BkxfPzpw1ngDK5x7+wbtPRJuFGIsLd12H27zZPXCiwM7r2ClVGhvjsh60JAT4Y4xaf/B1u26lVg0AfD1bEfqzithmT20ozTHpUBF1h1KxM7RMNDg4U 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 writeback iomap path, include map_blocks() and prepare_ioend() callbacks in iomap_writeback_ops and the corresponding end io process. Add ext4_iomap_map_blocks() to query mapping status, start journal handle and allocate new blocks if it's not allocated. Add ext4_iomap_prepare_ioend() to register the end io handler of converting unwritten extents to mapped extents. In order to reduce the number of map times, we map an entire delayed extent once a time, it means that we could map more blocks than we expected, so we have to calculate the length through wbc->range_end carefully. Besides, we won't be able to avoid splitting extents in endio, so we would allow that because we have been using reserved blocks in endio, it doesn't bring more risks of data loss than splitting before submitting IO. Since we always allocate unwritten extents and keep them until data have been written to disk, we don't need to write back the data before the metadata is updated to disk, there is no risk of exposing stale data, so the data=ordered journal mode becomes useless. We don't need to attach data to the jinode, and the journal thread won't have to write any dependent data any more. In the meantime, we don't have to reserve journal credits for the extent status conversion and we also could postpone i_disksize updating into endio. 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 | 190 +++++++++++++++++++++++++++++++++++++++++++- fs/ext4/page-io.c | 107 +++++++++++++++++++++++++ fs/ext4/super.c | 2 + 6 files changed, 322 insertions(+), 10 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 03cdcf3d86a5..eaf29bade606 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 d1a2e6624401..94c8073b49e7 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 48d6d125ec37..46805b8e7bdc 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 c48aca637896..8ee0eca6a1e8 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" @@ -3705,10 +3706,197 @@ 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_delonly(&es))) { + 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. + * + * 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. + */ + map_flags = EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT | + EXT4_GET_BLOCKS_METADATA_NOFAIL | + EXT4_GET_BLOCKS_DELALLOC_RESERVE; + + 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, 0); + } + + 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 dfdd7e5cf038..a499208500e4 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 d4afaae8ab38..811a46f83bb9 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 Sat Jan 27 01:58:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13533912 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 69DC0C48285 for ; Sat, 27 Jan 2024 02:03:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 380476B00A4; Fri, 26 Jan 2024 21:02:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E1626B00A6; Fri, 26 Jan 2024 21:02:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E4FC6B00A4; Fri, 26 Jan 2024 21:02:59 -0500 (EST) 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 F02D76B00A1 for ; Fri, 26 Jan 2024 21:02:58 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D2777160B85 for ; Sat, 27 Jan 2024 02:02:58 +0000 (UTC) X-FDA: 81723442836.04.36EDEBC Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf24.hostedemail.com (Postfix) with ESMTP id 4C141180014 for ; Sat, 27 Jan 2024 02:02:55 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf24.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706320977; 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=F4gKSLaarwbkUP2bBelrp4pI88/teDZ9PgWWS9mW83Y=; b=oPHMmUJCA9bXCvrsoprjNGr63hocQm/FEerGN5hcR5w20k8Pi/iBYpq8PoKlL5UuzJOJZ8 1LbXAJowQVU6fJyNMsN+JEA/WqH1Jxsa7XV1FrPWEYLgwJ3xdOLYdjrn3YfP/CCSxJHchE wMOkuAagfP+wpNKoaOiwT/jNl9CdQUk= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf24.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320977; a=rsa-sha256; cv=none; b=R0SM5Oq2GELOVljiP7FxbUavFAC+SpFHG0E1V4pvSu5LZZL1JFYuJCkPxZTZfNgzyRzERp N5DkmkLwr3id5beYpgwkQJVGVxivBsm3udEqruo41CLhEe1s3Ayvyj1Dnd3e2kKu85zri2 wvVdBDTE19yH+S+kGT5ceCsw//kAJ8c= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrk1c4Dz4f3lg6 for ; Sat, 27 Jan 2024 10:02:46 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 925E41A0232 for ; Sat, 27 Jan 2024 10:02:52 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S24; Sat, 27 Jan 2024 10:02: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: [RFC PATCH v3 20/26] ext4: implement mmap iomap path Date: Sat, 27 Jan 2024 09:58:19 +0800 Message-Id: <20240127015825.1608160-21-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S24 X-Coremail-Antispam: 1UD129KBjvJXoW7ZrykWr13Gr1xKryUJw1kZrb_yoW8Ar4fpF 9akrWrGr4xXwnF9FsagFZ8ZryYya4rWr4UWry3GFn5ZrnrZr4rtF48GF1rZF45J3yxZr40 qr45Cry8u34akrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW5JVW7JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 4C141180014 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: cw8dbgs6967zaqu9414h13yqywhobt1a X-HE-Tag: 1706320975-94253 X-HE-Meta: U2FsdGVkX1+6xauRrJN63CD15xKLxlxE27Bb9xDcb/buhGMwUtjptRNK/PaxEiG4oBSg0c8P/K/8bC4Yt0zi0J78UvC9Kvcbzrfq8R8MtbFB+xaahgd/hD6F0dHTe4cEDDIHEKxQMY9/VgYxt+pKQArH5/4bz69oh68s6X1qRO+jd6he+FRh2QHi+giFbM/bfEwX1Uze7VPvFtxvoujcKpsRPDYL4TypxVua2GD8wM+y39geNqbSM4jbgsrUfwFwyijM8P1J/18+ConqSAAsknZm7rOzcrBu364IyOZkqOQ8Kf1M3u4m8NJG4FV6+WWKkIHC6xCkhil2PQMCEZNze+n6riljyhTlFzHVpJUW9Qy4OIcrECOkVKX2f5eCa/+CzpGdfHaz5pisvfxwVmpyAg+uv+cx3a8NS8ArOAqO74D6rGPJ53idw2MC0dm+rDPlJas+ebKfnXpYKrcwnX/7cMt8YSaLjW0q+NmcpVXPAgNvG5Ke2mDQrc/5qwtwFNYhaZcgSAr6h77TY61psPB6sXoGBb29okjWC1UjFyss5lZ5yJ8Rox2GjoKZ/AeYW9l1THTOrcB7Os0z0bPaXjRUAjc/zn1ZLuovXsu2TOdxfZTGzsHjLfHdFGHX4Gi+HNmyhLjxMt9S841w/4hlPJVEgs91xgnnhgPF6woLncYJinkySVXINUgC8X4j7sOS8jHQROc/zxu2s0Qb4uhqiP30XtMltXGk7zCSqFSsovC6/hy0qxtq7gbKhT0nSKdr/Vxvd/qAE4beRYj2cXXYetL9DoIOCb8iDtCAGIQNSbYW1K/TUlYQkckqZXUYKi5RHxWP8EoCylwtGlf6m0GmHQecOWesE+bLZbGa11+0yDOmdOdHMUo87yfUWgVMHSQ7wbya/Uwe+2eSmEvrBkLxUyO5pGxItqoH+ThRc7V5bl+4Jo5uzqeeP1juYT0BzVTXN/ARAFyw21dpZkKNtuw3KjH yBhHdHYy KlEa/xf3cFfbAGeBtxe+UbaByOMaG98aUZyoJW+53fzytoPWWLaA8jl8XJTVkiGyhf1IzyhkiV2LeqJmh7tI6fIrMJfO25Avo9prJr5KrmyWRSBnviupzBxYxZFdzqvcJDdob2FRtZX336zLmc6JTWYZafJlFw7WK8uak7S70dTTlXX47skc7r0+2K1HxjVyedB2HOT83iRY7cOdeN0/paq9D6IbFcRhRTJib0dZI2R8GCLCLnlQHpWPRO79GONvpQ3G4 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 mmap iomap path, add ext4_iomap_page_mkwrite() to map blocks and dirty folio, almost everying have been done in iomap_page_mkwrite(), so invoke 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 8ee0eca6a1e8..dee661e64a69 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -6466,6 +6466,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; @@ -6489,6 +6509,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 Sat Jan 27 01:58:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13533913 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 C2AA3C47DA9 for ; Sat, 27 Jan 2024 02:03:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 79DDC6B00A1; Fri, 26 Jan 2024 21:02:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 74FA66B00A5; Fri, 26 Jan 2024 21:02:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 37D7F6B00A1; Fri, 26 Jan 2024 21:02:59 -0500 (EST) 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 1A84B6B00A1 for ; Fri, 26 Jan 2024 21:02:59 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id F24D4A2416 for ; Sat, 27 Jan 2024 02:02:58 +0000 (UTC) X-FDA: 81723442836.04.E333F61 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf01.hostedemail.com (Postfix) with ESMTP id 0332F40002 for ; Sat, 27 Jan 2024 02:02:56 +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=1706320977; 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=9Mb/RznkrCjHh4Mh0dc5h2XBBULEP8om7It5ehGzqdY=; b=a8yUGjBebkf84D7yZ+oWppCP1jwmAr/2gS+/NPS/d/LGJDR6NALWIJN3OEAI7heMB5Y0GP k7WGnIo82Cpj0EnJYraQLO2g2Rb6oaAfbSsmxGq/b+BGAnMIZxK/FA8i4u82O3ymoBopBg uRPzQfXv3KhJNuueNhrGdTACCFcCUzw= 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=1706320977; a=rsa-sha256; cv=none; b=7Bdn0LnE0irOtys86XWpmwv/NM0FwaBVgshMVPLHDYYCCTfUTQ1Bd1ebm5oksnwFaI5/i2 Spjf15NFJraqRL5s/Aat0vEwHem8dhVPS/OYkVBOMJR/17ZFjMg1f/Yw2IwAUafkdfHsVO wVy5Vco11p1ErHQ1WGweIruWFurGqds= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrk6Cd3z4f3lgC for ; Sat, 27 Jan 2024 10:02:46 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 3DACD1A017A for ; Sat, 27 Jan 2024 10:02:53 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S25; Sat, 27 Jan 2024 10:02: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 v3 21/26] ext4: implement zero_range iomap path Date: Sat, 27 Jan 2024 09:58:20 +0800 Message-Id: <20240127015825.1608160-22-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S25 X-Coremail-Antispam: 1UD129KBjvJXoWxJr1ruF4Utw45Kr4DXr4rGrg_yoW8Jw4rpr n5KryUGr47Wr9F9F4xtF9rXr1Iy3W3Gr48Wry3Gr98Z343W3yxKFW5K3WFvF1jg3y7J3y0 qF45try0gw17Aa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j6r xdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2 IY04v7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAF wI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc4 0Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AK xVW8Jr0_Cr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JV WxJwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUbCe HDUUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 0332F40002 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: mp95a7x3cntf639hacf65gu9kufbhfjp X-HE-Tag: 1706320976-221586 X-HE-Meta: U2FsdGVkX1+O14qs8H8EeZx6ywd0jdH/L/IdscXouBwDH6W/zb5mVYrkPBtGItnffUuzU6fXtWw6meaKyx1EaZM2H9Y+Vklm9mYkQy8mFaNTRIMQrx2zuxmPF8E1kZlo8GbfLi7Xs/HbjlduGGtPnYcZov2gzZZkIsoslvxgIb1SXL/VfENVFudORPFP1q1LuV74F/Aghre4xPJwMNVtFI2YI8AhKZOT32cED+uJLroNI6CdSzo3sQwwX4M5AX/cTlcRVZpAyZIEh/VQ0glbHIleRvbq8NpV53wWulO62oTSqtcjjcbCCwtqF1eQWKxUXuIBflnrOBAhSqRQtUN+t/CHi0uo4ity6nsM7tU9tqqRRWjGX5+Ev/C3BIkvnWpKlNTp9JE/EEAEc7ETy1AWosaMyCDByVnVqk6J9Z1M+fEn21hF58khYJ4ot4M55C27lY6xNzpppqXyF+Kvjv/jGD/DWH7fBG3sS3LRDH7//2Akh1653iWIq+CmIJVwAkxWLtnMkqhdYB8ur2aZLknA3KUqH4/dct43vwWni+m/lYhRtFZhrm1zMGKU2jyH2VkP6O4YJ4pJIrOhKgcIqgSsoGzCtDSpnO96xF5GNCHdDyC8zYnvw8hivFt2Cn4D1AKzOdVQgs86JEd/gCtIEW4zLpmUFxtiis4erN0Y5O2/zuG+ACQHXoAJX9L3nW2ewzHZDOXf53U8lCTWvhJ3/eIUAZ7dO+Dts/6KuHUCTrVIY3fHFhpKRebRFaPnKFoQuxW4TLL3D/ojw0YFT7mMzUcchbyuIZoDc/oyYYrYXYpGWeyZZNXGwo+uD+CwTNBPM0/rDA0su50uKQC/gY0tS4VDtBp3ayC5TOhRMgF+1rJybfbYe6Nkd2zxCd2nlUD9A4kBq6w1lqcT7tgtyLb8uj1B7K4XCK4KDjRogAG+vqzTz0PWDkUUJNgspTV8YjrwKIrq/M7qLIIoCby5XWLg7YN 2lgCiyum 3Dsf2tZAnDOjWIqMqT5lvpeZ7DbhgA+xeC52hcIYI7LCqVaGEsGmiUANGLA== 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 zero_range iomap path, add ext4_iomap_zero_range() to zero out the already mapped blocks, everything have been done in iomap_zero_range(), so invoke 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 dee661e64a69..f8e9f566ef6a 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4126,6 +4126,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 @@ -4151,6 +4158,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 Sat Jan 27 01:58:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13533914 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 046BEC47DA9 for ; Sat, 27 Jan 2024 02:03:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68B096B00A3; Fri, 26 Jan 2024 21:03:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 63B256B00A5; Fri, 26 Jan 2024 21:03:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B55F6B00A6; Fri, 26 Jan 2024 21:03:00 -0500 (EST) 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 36CA26B00A3 for ; Fri, 26 Jan 2024 21:03:00 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1718F80821 for ; Sat, 27 Jan 2024 02:03:00 +0000 (UTC) X-FDA: 81723442920.25.2FD7555 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf09.hostedemail.com (Postfix) with ESMTP id A1BD314001F for ; Sat, 27 Jan 2024 02:02:57 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf09.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706320978; 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=QboxDcRjbBuLzciXveZIXmgBvzYHPY4OBOFRdlHKrSw=; b=UNFvo4f70X7qZo2qRZee1XDCGE52+370NdWv1jaRJER0IH++IxtQ/BzbnjtJAxkGzveesU BB7lEY5O0/2nfI8dZGyvevotwv+4AOGiX733mxqxgvUR09mLtC8ymuhYkI8hLEOwRaNW6P mEEHVIl/akX1xJAKdSeJdp1RanGyqSM= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf09.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320978; a=rsa-sha256; cv=none; b=dS5fZm19+29UPh03Jqs2a79imTobaPvKRF7kffunpIm5G1zhvIBxL3yFR+T1L3tf1QZxXi DQ2sfYs3BGsZsn5Fbb80X9EIPwRSRLyslpgdtPnQOCXjnQivniwCmn6eO25vII52SwfFJr fW5wvN8ErkIkHR/1+z+MoLVLwV9w3Nk= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrl3q9Kz4f3lgK for ; Sat, 27 Jan 2024 10:02:47 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id DF3C01A0232 for ; Sat, 27 Jan 2024 10:02:53 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S26; Sat, 27 Jan 2024 10:02: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 v3 22/26] ext4: writeback partial blocks before zero range Date: Sat, 27 Jan 2024 09:58:21 +0800 Message-Id: <20240127015825.1608160-23-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S26 X-Coremail-Antispam: 1UD129KBjvdXoW7JrW5Aw4UCw1kWw45Jr1fZwb_yoWktFX_Za 4rJrn5JrWftrn7Was7AFy3ZrZ2yw4vkr1xWFy0vr98ZFy2gws2kwnYyr1xurZ8WF429ry3 Cr4qqF4xWFy7ujkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbq8FF20E14v26rWj6s0DM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAVCq3wA2048vs2 IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28E F7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWxJr0_Gc Wl84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s1l e2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI 8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwAC jcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2Y2ka0x kIwI1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AK xVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MIIYrx kI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Xr0_Ar1lIxAIcVC0I7IYx2IY6xkF7I0E14v2 6r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F 4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjfUoxhL UUUUU X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: A1BD314001F X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: c9sjpjoanknza83etadfnytzkfmgr9mu X-HE-Tag: 1706320977-870479 X-HE-Meta: U2FsdGVkX18ZUoZ1mP+8ZjqZFYX+7lsdexkSzheUo0UR4VixBln6ws5tPmpGPYqDWDSkIyC/A1mtwMR4vHfM6gdFUqDWExeqZ1cTpmUiNpQHN0M+8Fcfs6+K2g4Y6/3m2JiOoC3KYlvTyEy9X2dPXO6fmOMSkRE1KzzdyOtj5B6VarMs4BDIvL74R0EB/YmSMJZH3yvXKZtYjD+B7YZM1hpC1ErsGqp1vTqC50/Cd39q/k5chqZjoAQ186oHz8txxH6OAkdnbie9jpn06/2/YMqDN1XpKB6bi9wu7z3qnuI7KJF+5gJy5wt+WamtAtpMWagrVITiMA7tPpnUu9sTIlcWOYQbmqQ7Nm7X8VXfT7Iviajx8y5MPAqlkEDhlj+mO7voVNIvpUh2nSsxraae/o/fSr3FN5HlivNi7llroSm0RBtga3mtBioYL8u7rCFCBixoR2ErOaTU9++zdReQTqKxD2YI8CP3DVQSM/GuHNkEAY9LL6p2Rl/t1mwGXCG8h2xLkWmF9dJ2LCxLanm6HreFZDW2kEIPCnW95oQOjtKGCCgrZaHZWBV/v2J+WnPT0JEEEfF5bE+nubT+faMd2ocGpaQXWeW11KEO9+/YBuMlQHAI6ntVNNAf3OmJZFMU5tR6iflp5FNyWQ480e2R2ejJpidyJqAhIOo0sGew36jupfTxtf+DR3A+G8r6S6yuhSrH8IOC9NnmNQSI9dBWg8lgut9ZbDN0vCO6U6YMLTVD2kemUTwUv1GaeORTipViSEKAlSCazaKBqKPYBO+0Mzn1IUjLToJjmuUdRuOvzN0fk6WmHrg91osPdh6p0n7m3FgL/bgEAnAzarAveAUlvOzCCdRFGSM5Xq0GsH8AEfoabFDsQSyyrwoyxOzfPzRl+WoJgbsOMmgl9+LIPea8UIbN0nmAPUnEEPstEHHfNi8AZthFCdNyNaWN7A1qfV9S1O21ushxuprNvsGXGme BIIyeysI MYDjKqGoWPOs7jaHqVMDu67Nl7/3yS9C0PudJDSigswpkERO2v4SFMEocg0OwGMlI/LLSvoch7VBx09/N3HSTkbsT3aNXecPGIW9l223fe07cOFHALh89KBIMMQSBF1rUHMRgfn7/rT5uBAe9JtKw0xgJwosIZxPKdQvxtZ4fyx9vvNvFPiKO84tBXv74rkf1a/DaD5XC/iLW2ZEuCSLUki/LTO+oumSDaz6MKXRffrijgtvwCitsHtXI8nB3NToLKVCt 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 if the srcmap is IOMAP_UNWRITTEN, it works fine in xfs because this type means the block is pure unwritten, doesn't contain any delayed data, but in ext4, IOMAP_UNWRITTEN may contain delayed data. For now we cannot simply change the meaning of this flag in ext4, so just writeback partial blocks from the beginning, make sure it becomes IOMAP_MAPPED 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 46805b8e7bdc..cb80c57ccc3d 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -4616,6 +4616,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 Sat Jan 27 01:58:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13533915 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 00A82C47422 for ; Sat, 27 Jan 2024 02:03:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3A5FE6B00A5; Fri, 26 Jan 2024 21:03:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3319E6B00A6; Fri, 26 Jan 2024 21:03:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0BEFA6B00A7; Fri, 26 Jan 2024 21:03:01 -0500 (EST) 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 E61816B00A5 for ; Fri, 26 Jan 2024 21:03:00 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C886AA1B71 for ; Sat, 27 Jan 2024 02:03:00 +0000 (UTC) X-FDA: 81723442920.20.8C80968 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf09.hostedemail.com (Postfix) with ESMTP id 524E914002A for ; Sat, 27 Jan 2024 02:02:57 +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.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320979; a=rsa-sha256; cv=none; b=YsPObHbuxvvnepuaO0yJscLgOJnSB0Y8hUBf8Lexv98ys9qpjCJFRQLXPl9bQiG5uqwxk8 mj4FnJihe5FSuzjiZP/50eswMV2bgVOvufu5BETKMs8mEMwinQkvb+Jwxo4Z6gLztNltp1 Zfmo5xF+QZpstwLp+wXGtcQ4l0ZFfPE= 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.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=1706320979; 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=DIcdqiMoOH5wnufmVPOCwbErzSVlQnTOpemmkCPNNtA=; b=P516mRZW/AN6ddnbewQ5UGMEugDc025BRjpQ4JBuvYk00O0Zkr4MPCSoxsRCmUCDnZsz2K AQ3gK0GK1acU+bZ5qDAheuewPV0TJUGw4eDNgxEzMW+XBtQtVKfQqgc71rlvzRlTBYBpAr Kjunlybe2xhCq1UqqJyowVc+EmXb+lI= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TMHrp43PDz4f3lx3 for ; Sat, 27 Jan 2024 10:02:50 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 8E72B1A0232 for ; Sat, 27 Jan 2024 10:02:54 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S27; Sat, 27 Jan 2024 10:02: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 v3 23/26] ext4: fall back to buffer_head path for defrag Date: Sat, 27 Jan 2024 09:58:22 +0800 Message-Id: <20240127015825.1608160-24-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S27 X-Coremail-Antispam: 1UD129KBjvJXoW7Kr1fCrW7Jw1fXw17JrykAFb_yoW8Krykpr 9Ikr15Kr4UXas29rs3tF1UZr15Ka18W3y7uryfW3WxCF4DA34IgFWjkF18Aay5trZ7JrWa qF48Cr17Wry7G3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j6r xdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2 IY04v7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAF wI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc4 0Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AK xVW8Jr0_Cr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JV WxJwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUbCe HDUUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 524E914002A X-Stat-Signature: 81fzbaubmotu5khqrpx8w7oqia6g39ap X-Rspam-User: X-HE-Tag: 1706320977-322414 X-HE-Meta: U2FsdGVkX18u2NFhGARPO+bQZdYG06+WVSb0PAmEGv/vAZHIa8aILWRsK9D1iV2GFSZRZbus/ANyZTorpIIavgk8MSD+uS4YUqjusNLu35KOpSzUOun7OESznhm1o90QxeHdSkJFvEuCtFgH+z1mygOu3k0KQifUGbEDf/UInM9gPxFp/7CcEHeIfqH9KQZei2d981PzjiOSsRUm415mjEP1SgH3HbqOubGmKxh+iKBz8KU4N0bOB8gmBxsLJCEOmC1/THvVhYyjrTzrEK62ggbECmPD5GJR8s59j+DoOQOqwXvJ0z4SaU4ri+YIqYnrZl5mbGaYv3FWVMEmNjTQSo+J8qhEpSyrJIL/mm8DryF4HUTSPCyduC1YKWF6G7XxtaWZKujeAFbeQFqY4k3svsEpctpDj14XFXcpRT+R3mSnN5Xw6eIVt/KDO9uk+yqaprjO8pBAEKBw1loMk652UJC3gADzyQ9KgqmUu15nQn6yCSK9ImWY5eUKg4hqyuxEpAlfVT50Kt5RYyeN3yEkAd+9kNaCEFnuvMIJw/QpLZqCbzeowDZryHN/z6ub5bLUxEbuEm1SZU/puOfc7oQhOZemD/9FqbL2y4oLC+d9X8wfki2Mhdw1Qh9/2d5dEnHtjHm8ZJorv9fv5200L0QaVjdjLCAxf0enQqrs6HyA1stSOaqz+sXPZme1UQu4YmhTcqcdFD2OM3kcR+VW8KA01pfEHxlIOPHaP7KCI/WwJZ73Q3WhZSPhUiZf3yqCU7mHzC7hAPkEdbNTf52ZbwDJc6llyWtJ/qnxQc/8WqUOKKFtAn913HynVHs5njq+Gb77KJMiMC9N4RWQLy5Ymq35ZXU6b/cCOKlBmWniyVvN0KMpyNAeRxGXjvAspJ4VSGETebsuEQXAczA9+tIGaQCvgnXw/ksx/8fgxB14Yq6fvtCPMlRiGdQg1IImQMUqZUnpFux4BrrqnHeR8mhE2yj FZwzwxc2 tgZ4HcvUaNJAX1FMFXXMYL6n7eC3IbG/6JCscUBmzWubGNldXYiJ+EC1YYFAnChuUeGnfSQQxDzyvZv89Rsv7vUegtdS6Ut2PT7Vznwykb67YAaam/W11mPzwluiz1qY4vS02q3aj8pljkni8ZiHJ3kv++OT3lo+Zu27jwSSSE9+FFUQzp1VbPkd0R9ogxqGEnbWp0lMgEVsLA3Uq6EAKq5AbSckdvgJq3DEw3jPHAVy6H4Yh+6LoZFPgfVe+Jng37jVbZP6uqBqBMGF/NHSRhN/SYeOKnwp8EyYX4xRi30hgml2c4EkvySrO1XIs1bM1hzQMDjDPRqtW8SAKLDoGLZ+kVg== 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, so we have to fall back to buffer_head path for inodes which have been useing iomap. Fall back active inode is dangerous, we must writeback and drop all dirty pages under inode lock and mapping->invalidate_lock, those can protect us from adding new folios into mapping. 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 3aa57376d9c2..7a9ca71d4cac 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 Sat Jan 27 01:58:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13533916 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 75DDAC47422 for ; Sat, 27 Jan 2024 02:03:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D91DE6B00A6; Fri, 26 Jan 2024 21:03:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D19916B00A7; Fri, 26 Jan 2024 21:03:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B93616B00A8; Fri, 26 Jan 2024 21:03:01 -0500 (EST) 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 A697E6B00A6 for ; Fri, 26 Jan 2024 21:03:01 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7FC5D140F63 for ; Sat, 27 Jan 2024 02:03:01 +0000 (UTC) X-FDA: 81723442962.10.9491D69 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf11.hostedemail.com (Postfix) with ESMTP id 0C9CF4000A for ; Sat, 27 Jan 2024 02:02:58 +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=1706320979; 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=5hFbF0KxnHt4vEEsH7/8Qchlvjc2GO7GkzsMdnMu9kI=; b=weVOsyT/tz7nBtctvlQQuUHmcdTB7DQt7lxHwdKdezWYsHT5+nQeBcpbuf1dyXDWJv9W4g sZumscdl0ySLdvzHkgjEoHsXJ94wP3u+gE+CNqOGPHiMvMjeEUSyrpEhRAt9+NFMPynlZi n5t26zCRNVn20+8P6AvzIcOo/yHRt7s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320979; a=rsa-sha256; cv=none; b=5h6VqBGesgrUdaXmUeefBWF4/EwlDZNtkmE70qNladHQt/lL+pERbxhRFVeMgfA01CYyKA W0LuUZfczwN8kTmO6U891kb3V6Wq6KhWo8otNOu2PuVm7IQ5qqjv5QIffJ9NvOap/N07oH 2MBwjJRzxsyKJFjPMjIr23JZnuUbZAA= 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.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrr5k3hz4f3k6G for ; Sat, 27 Jan 2024 10:02:52 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 3C1951A017A for ; Sat, 27 Jan 2024 10:02:55 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S28; Sat, 27 Jan 2024 10:02: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 v3 24/26] ext4: partially enable iomap for regular file's buffered IO path Date: Sat, 27 Jan 2024 09:58:23 +0800 Message-Id: <20240127015825.1608160-25-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S28 X-Coremail-Antispam: 1UD129KBjvJXoWxXFyxGFy5GF1xXFy8XFyrWFg_yoWrXw18pF ZIkr1rJr48u3s7ur4ftF48Zr1ava1xK3yUGrWSgwn5JFyrJ3WSqF1FyF1YyF15JrZ5u3WS qF48CF15uw47urDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j6r xdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2 IY04v7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAF wI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc4 0Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AK xVW8Jr0_Cr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JV WxJwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUbCe HDUUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 0C9CF4000A X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: dqgezsj133w9i7yyecrngii5nwcs4nkq X-HE-Tag: 1706320978-154826 X-HE-Meta: U2FsdGVkX18TYsJ15g62D9EmESBYWQilEm1ug4Al+KphfyoZkVlnV8QEl5ynxbUoeYmDM3/V4SF1EDJYFPMnsetTfnp0l0VBkByyAnnviT5RlxvL2nsKFfr6yIQp3Gci87UAOdslky09OgEAAuPVIErriPSUGnLcL/pD/60YnQtbhZl/Vs9hhfCgg9+6gF7pB6/nZXwzG/KBuBAP0zGO8ooTqHH24bd0/wToHL/vufzqMkjm8SRe4RxBR/e3Rv/gLJTt4aQGq3m1DCqpVxY9Xy3Szi01QoyF2sAXijQAoY2HOr08dO94JBNOXah/0NHYSlfCLZKHq9CCUWM2SqpWsq2rAX0qNJbRIynJ/MWXsUpI5o9wyCd4QM2Lb5ANmlQ1bgPZWVSfxTXKo1KF/B2DDHhkKkI7B6WYNlY/ZzNUA48wwdOoJ3crpiWTrV9QdcNqfqxEW/L+CFgkpF+tSm9EejHrfJuWxxBADBL83ay4oQmxiKf5cNjiJbghiXNjmS6bVpb4G5OnpbN0j6/G/JfxIkTepHEwNBkX8xLbwNAlIzF8PZQ0SeQtQZ+fDIP63B1DLDhA5+v1EyuTnDSKpzHok7WpiLbucYJK0VCVRYJIXoe5iKeFFe81yFYjJqsKHlIcSvqG7ONLWKwfbl3U9U7WlJkvnG9Lg5q9dwzKxIda7cnA1N3mxgG0mjbJYrrDbH6rB31f1mwpjxtFhI4FF60hizUELCDvfNfZcybM6f2wHmYvQlcV3lON+jaMx4cUP3SrFdI3pMChV3+qq1sBx1VQoEqgVIvhr59AviKhxNR31aPr8ATln1cIthE0clYqg6133f8q/mDxUozeJxeyxwcngvq18U2lcl63/8qCL+sR1QAAk/VksleFHQJD3m1S6MJ6Rf9X5/b6Tkr4xdzyAyj+ONNGYEk2DcO+ZGvmg+1WMnF+nUYFazplAAcQ4PcIGHKUetZ7bnFQBWEVEL8CD1k ywX7zDUs TRh5UEBf3MyUPDWfGbg/+qBUNQtTXBZ/+DbqsO/dZxn6OAfs0hfMhtgSC4BpBcKGxuqFUYtpPeVwPCmf8CQ4s8shaGGc/EL4BUPGcxZcJPsYJrghjBBMC9LBPrVXWYiXwxc6nbJoeEK8pzxjP9t8UeH5bbZVp+xoDx9jPxMuiWiXlZOtvItsQNb5oqjBhrysmdmSGF0+vtER2py+X3gB72TwH/bBLjuZR9dSKTU5E10d8xImqcYx+Jw0zVJQs++VzU/JP 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 Partially enable iomap for regular file's buffered IO path on default mount option and default filesystem features. Set inode state flag EXT4_STATE_BUFFERED_IOMAP when creating one inode to indicate that this inode choice the iomap path. Now it still have many limitations, it doesn't support inline data, fs_verity, fs_crypt, defrag, bigalloc, dax and data=journal mode yet, so we have to fallback to buffered_head path if these options/features were enabled. I hope these would be supported gradually in the future. Signed-off-by: Zhang Yi --- fs/ext4/ext4.h | 1 + fs/ext4/ialloc.c | 3 +++ fs/ext4/inode.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index eaf29bade606..16dce8701c5e 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 f8e9f566ef6a..30067775e828 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -774,6 +774,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; @@ -2552,6 +2554,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() @@ -5089,6 +5094,32 @@ 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 (ext4_has_feature_bigalloc(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) @@ -5353,6 +5384,9 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, if (ret) goto bad_inode; + if (ext4_should_use_buffered_iomap(inode)) + ext4_set_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP); + if (S_ISREG(inode->i_mode)) { inode->i_op = &ext4_file_inode_operations; inode->i_fop = &ext4_file_operations; From patchwork Sat Jan 27 01:58:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13533918 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 A4242C47DA9 for ; Sat, 27 Jan 2024 02:03:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 073C06B00A8; Fri, 26 Jan 2024 21:03:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 021976B00A9; Fri, 26 Jan 2024 21:03:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D97476B00AA; Fri, 26 Jan 2024 21:03:03 -0500 (EST) 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 C2C4D6B00A8 for ; Fri, 26 Jan 2024 21:03:03 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9AB7AC031A for ; Sat, 27 Jan 2024 02:03:03 +0000 (UTC) X-FDA: 81723443046.02.5D640FC Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf22.hostedemail.com (Postfix) with ESMTP id 1F746C0015 for ; Sat, 27 Jan 2024 02:02: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=1706320980; 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=W4Z4WZaEfIoZ3vwpGldL2aH+8SMBSn2purh947hOd1g=; b=kSBpl2C/YQSORk799QBmPRcP3BQIkd8r9eQoS9Kp1TtEgj6n2y+l5YCD5+Rtt7LJ2+/vGd oUX11WLarZz7caV3hljfk98jezthh2TEUt7X+0P+zGFpWMUiCjg3jDoHnmVGihJ9cxbc68 9itQZZpiOauZlxCXYmKiCSF/DFoThsU= 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=1706320980; a=rsa-sha256; cv=none; b=FZfoC+nOb7Kz/oNY7wGEGmGg4WRWL/E16fgkmhvfbsD7yQjo3y+TcYAYgADHwp27yVwXPd DeItRBuuFUut5+Qfh8u6MvhPumK52lF80QJFqjjPPvjbKnI78icwfCtkESazJGkVg5IsmB tTgApygmkpumOc35EonWpKVR6Oqq3ck= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrn3tcDz4f3lgG for ; Sat, 27 Jan 2024 10:02:49 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id DF90F1A0232 for ; Sat, 27 Jan 2024 10:02:55 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S29; Sat, 27 Jan 2024 10:02: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 v3 25/26] filemap: support disable large folios on active inode Date: Sat, 27 Jan 2024 09:58:24 +0800 Message-Id: <20240127015825.1608160-26-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S29 X-Coremail-Antispam: 1UD129KBjvJXoW7CFW7KF13Ar18uFW5tw4ktFb_yoW5JF47pF y7Cw4rJrW8XF4YyrykAFsFvr4ag348WayUAFy3Was8A3ZxKF42gFWUCasxXry7Ar4rAa1x Za1UAry7GFyYg3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j6r xdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2 IY04v7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAF wI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc4 0Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AK xVW8Jr0_Cr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JV WxJwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUbCe HDUUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Stat-Signature: d1xq9wqy4bicaej34jwgy98pdqgu33gy X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1F746C0015 X-HE-Tag: 1706320979-574827 X-HE-Meta: U2FsdGVkX1/q7riuDVa1kfsJtv6/8fEP0wz4LJGN8PyfNcMhnfIDA5baey/feDoBIjQeMcwa2kkKDPeGXKl0NZw9bSyYtDGckI1gc9nokrNYmiskxQf6wxHtFdphQv1kTXAkLT63YjxP5f/68CWCUD/WldjPt3SdBUltsUKihRmUG3nv4bv496RYYCyx0THFxDkXAPAsXqHzKKvY+Pbjfxf3gT/3cJszdLoH4PlhLryknVNJ/pLW/jZ1n/4GXHMZvMsB8ChpJEifQ7erWJZxGvsz/rJQUFpkZHwSEVHbvkmZb0oLs+KciLYJKUK/ptnSYqm256Foxfwc11Odg010ZQHHvqJLwitzasvSQrdRHHmDLnGHM/nyOecGyoVdl03U4brlfTiNChv+mq/XJzfLLKh3SR36P6Vm7YEEJp1StyBLQogvSQFDuZOO3uR/8kLm3cF5rdAxT6LsW5Yt8zl4OKaEkVC4Lp5iQ45qrDuSqvlpl+ytyNyqLWDjxin1bGDz3y+7ySindGv22g8xZqW50y4iNAbpWATgb0vXdhUsGVx4ZjdWxXoyc02+1hoL8oUVM6uFDMuz2nceWD7/OFVOXVYZ/TRh7WtlpLc/3gBaIU/vGIIRMLW9L6Xv1y+3YwubioOGWvoz4OuCBBG86xC5bjZ1YtF8JKsVi2oH/RlrYCFnzIXHlCmlfDU3NOTIVjewRjxoGIVB1OCB4s9s+PMcGT4V7EnJPyPq2qFAoP6cv7BjhR3I04GDE8jBGUPPw5w8Ht1BrwOKTK43MpdVW8SA9DzpzwnWBUyfzWqrciUics/PIveJKgJfm5rQmQhL0soAL/JxUTNHzUjoP5aW3EXMJYXMJsgydtt1dc1Qoo1242pMLzxGBN1i7DORGNky6XEDNG2LeMh9N2PkufVi1wZ045nJutkX4eJuv1nX+baE52HByPN8JR7CAhB/znAzMFFdYvRnERT3N/aT5khhCF3 qx9PZGw4 HF5DxRF0qzordg/YT0I0nJ37xHAhLqScTryhJK4G6cQrc5mGMikOT8h/FpKikFzSC0lBiVzecIpWDhLDjcUjerdahdWr8RJIW0nn0j1v7zmEjHqRptJoqxRbwu8eTh5VkA6r//99WyL7yXor/6hth85l5r7rW6ESh7lYkZxVXmpg/zdkeFHz1ACia3bTqP0pCM1TFHiQXsjhsB6qcGvIssctPt8wbX5xLCC+HtWABcVHlX5Dqm0Mq5b/HSlpax0fEapVX X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Since commit 730633f0b7f9 ("mm: Protect operations adding pages to page cache with invalidate_lock"), mapping->invalidate_lock can protect us from adding new folios into page cache. So it's possible to disable active inodes' large folios support, even through it might be dangerous. Filesystems can disable it under mapping->invalidate_lock and drop all page cache before dropping AS_LARGE_FOLIO_SUPPORT, besides, the order of folio must also be determined under the lock. Signed-off-by: Zhang Yi --- include/linux/pagemap.h | 14 ++++++++++++++ mm/readahead.c | 6 ++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 06142ff7f9ce..7f77670960d8 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -343,6 +343,20 @@ static inline void mapping_set_large_folios(struct address_space *mapping) __set_bit(AS_LARGE_FOLIO_SUPPORT, &mapping->flags); } +/** + * mapping_clear_large_folios() - The file disable supports large folios. + * @mapping: The file. + * + * The filesystem have to make sure the file is in atomic context and all + * cached folios have been cleared under mapping->invalidate_lock before + * calling this function. + */ +static inline void mapping_clear_large_folios(struct address_space *mapping) +{ + WARN_ON_ONCE(!rwsem_is_locked(&mapping->invalidate_lock)); + __clear_bit(AS_LARGE_FOLIO_SUPPORT, &mapping->flags); +} + /* * Large folio support currently depends on THP. These dependencies are * being worked on but are not yet fixed. diff --git a/mm/readahead.c b/mm/readahead.c index 6925e6959fd3..c97eceaf7214 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -493,8 +493,11 @@ void page_cache_ra_order(struct readahead_control *ractl, int err = 0; gfp_t gfp = readahead_gfp_mask(mapping); - if (!mapping_large_folio_support(mapping) || ra->size < 4) + filemap_invalidate_lock_shared(mapping); + if (!mapping_large_folio_support(mapping) || ra->size < 4) { + filemap_invalidate_unlock_shared(mapping); goto fallback; + } limit = min(limit, index + ra->size - 1); @@ -506,7 +509,6 @@ void page_cache_ra_order(struct readahead_control *ractl, new_order--; } - filemap_invalidate_lock_shared(mapping); while (index <= limit) { unsigned int order = new_order; From patchwork Sat Jan 27 01:58:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13533917 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 5250CC47422 for ; Sat, 27 Jan 2024 02:03:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3A6E56B00A7; Fri, 26 Jan 2024 21:03:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 330B86B00A8; Fri, 26 Jan 2024 21:03:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 134426B00A9; Fri, 26 Jan 2024 21:03:03 -0500 (EST) 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 EB3746B00A7 for ; Fri, 26 Jan 2024 21:03:02 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BFD28A0938 for ; Sat, 27 Jan 2024 02:03:02 +0000 (UTC) X-FDA: 81723443004.30.ED3058E Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf20.hostedemail.com (Postfix) with ESMTP id 47B4A1C0005 for ; Sat, 27 Jan 2024 02:02:59 +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.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=1706320981; 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=o+POuTt7I/XsNA/8ETXw49t7kNThw0TpGBA2GYXDn/o=; b=TaVTEKL4JCbj3nmhX6qCJqgu1WRlQGJoR9hvieB2wdRD3lcnBUI5SzdFtYnv8Bko6nG1Ox 9SL5qfvtmgJ8uD+NbNR6J9lJIbw8ng3JI93L7uGTJeqi9WK0AzTXtHtnLhMBGJPXAwqfXR 5QTQUHkrb5Ql7qGjTpEpLPI+nnuXr1E= 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.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320981; a=rsa-sha256; cv=none; b=lzTY1HcGTThf3ZdxxElFIMuz3EymwDsNiOU+Z1L2E6Nngev7unThm2b9qed6TxhoLIO9QG kIknsIisWzz078CqPgjdGu36z23pyHswWs1wSpAmgO/flXGlc7AfxcZmAj61ejTMxsVnIL CrA3/xbTxB648BJ7M/8mnA0ljXXl2hg= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrt0zQQz4f3k6J for ; Sat, 27 Jan 2024 10:02:54 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 8B5ED1A01E9 for ; Sat, 27 Jan 2024 10:02:56 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S30; Sat, 27 Jan 2024 10:02: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 v3 26/26] ext4: enable large folio for regular file with iomap buffered IO path Date: Sat, 27 Jan 2024 09:58:25 +0800 Message-Id: <20240127015825.1608160-27-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S30 X-Coremail-Antispam: 1UD129KBjvJXoW7uw4DXFWfXF47Jw4xAr48Xrb_yoW8Zw4xpr nIk3WrGrW8X34q9anagry7Zr1jq3W8K3yUurWS9wn8uFZrJa4IgF4qkF1xAa18trWrA3yS qF4Ikr13Zw13K3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j6r xdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2 IY04v7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAF wI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc4 0Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AK xVW8Jr0_Cr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JV WxJwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUbCe HDUUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 47B4A1C0005 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: s3jp4p6ib7g9hxxb3zibmmx4enhk9oyu X-HE-Tag: 1706320979-85242 X-HE-Meta: U2FsdGVkX18JR9VOGgQQqLH/NNC7pNTWyr1X5II09JZ5nUtpeNKf3y72ZdRLzp/FNwXKNEt3E+H6axCzlqU563dhY7eNWOK10MogHsRfMOTtl5dU1yw4f0lez/grYP+pVtnu9Af314Jye3uMbnQzpTqbfhjv6zJwUomu3g+IzoSuTbHd3UkfAeCLNUGVgWO8brnLaYbWgoz4jVcF/Ndcxnhyjmt8s+RhPkZOGPkoTbxOXwsEJzD7YAKUSSQ7ciJ7p8CgUJAFLF+XFGtGYveXL/ixtfL6wGv6n+0QItC+N/PCCkpNcKW4eVV0Gxf3ASya+6HKmeu1qSSAXaI669COQ6+soC+5V5tpUcvotnTSYGQfHZRpSf0pKV3IlkBtTX5aP8fLKGHAqANHypI+mgSnt2yGU+aRn9BN/PU1ydnG8vqy0rx/ZWAy46s8HUk9+q01eqhTVnbkzZkLYNNI0+UnxPmWWsCiIwibPh9ICB7fq2t0Q8ZWo4iJQyouzWqvLrkQuZnPrQ585TrQDEpBbsts4vp4Nl6WbkrEix5Dj0ACdD2t3CN7+xqNOgPVw1LQUGc4+7ir6MEjAebbFRq9Ozls5NaVByb3FFakLtPgwJClPc58DPFPnBn/Fctrx68n5vFhlBngL+RsKyCn7UA7JSjHbo0yYpiPWo/kgcSqbOsCvCvPTuByLYBmbyISM6PnMzVf44gCbL7o/KdrhDsOuiTQ2uBA8BuCXA1rZ2gndZl1m+aJMt26AZydCng0IPRtybdAO/Imy1C3BKjJC+anGDOlehi0mT6Giyuw9u+S/XKt2pH1gpN2j/AK0fOI0Rkd5yaIu71a3larZZMrtFM9fpyPAFc8KolWdICjWGG9fURsfZXGPG5oeweH3VqK1U8hTKKqqrVxpbruRmSlj1qGf6dBU+Uvkc7cPYk+fyRbt+nvOkzq98+oFumRR62db29Og3joe/zjHtZ67pV7w5B8FHM vuZxL6hr O4UOFxwPnsArM3JsDP06fiO9w3gH4nkQ5vsMlvdlPryjAWuOHYFEnXCBOXYiJg9y7MPnHcvQ0CNHrA8fjnYh/RoZ4eeAxnQ0QNlqUhsl6Zb5ieFiRXEOYp4Mkh9Vyns7Gx0xB79yr+HnQP02esJxPvYwnki/wI4GYQUjgx+fhITgG7/FXFsX2Apy1GpUFhE60ng/O71Rk6olMqwKfflgcSrmcWM9hd0FhflgPng83ULwq0yd83a73hp6rRUSDC06iFPQF 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 we convert buffered IO path to iomap for regular files, we can enable large foilo for them together, that should be able to bring a lot of performance gains for large IO. Signed-off-by: Zhang Yi --- fs/ext4/ialloc.c | 4 +++- fs/ext4/inode.c | 4 +++- fs/ext4/move_extent.c | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index 956b9d69c559..5a22fe5aa46b 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c @@ -1336,8 +1336,10 @@ struct inode *__ext4_new_inode(struct mnt_idmap *idmap, } } - if (ext4_should_use_buffered_iomap(inode)) + if (ext4_should_use_buffered_iomap(inode)) { ext4_set_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP); + mapping_set_large_folios(inode->i_mapping); + } if (ext4_handle_valid(handle)) { ei->i_sync_tid = handle->h_transaction->t_tid; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 30067775e828..a1dbfc2b904c 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5384,8 +5384,10 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, if (ret) goto bad_inode; - if (ext4_should_use_buffered_iomap(inode)) + if (ext4_should_use_buffered_iomap(inode)) { ext4_set_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP); + mapping_set_large_folios(inode->i_mapping); + } if (S_ISREG(inode->i_mode)) { inode->i_op = &ext4_file_inode_operations; diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c index 7a9ca71d4cac..aecd6112d8a2 100644 --- a/fs/ext4/move_extent.c +++ b/fs/ext4/move_extent.c @@ -560,6 +560,7 @@ static int ext4_disable_buffered_iomap_aops(struct inode *inode) truncate_inode_pages(inode->i_mapping, 0); ext4_clear_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP); + mapping_clear_large_folios(inode->i_mapping); ext4_set_aops(inode); filemap_invalidate_unlock(inode->i_mapping);