From patchwork Wed Apr 10 14:29:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624694 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A103CD1299 for ; Wed, 10 Apr 2024 14:38:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84F146B007B; Wed, 10 Apr 2024 10:38:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F2496B0087; Wed, 10 Apr 2024 10:38:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 61E6F6B0088; Wed, 10 Apr 2024 10:38:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 236896B007B for ; Wed, 10 Apr 2024 10:38:36 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7C1761A05D0 for ; Wed, 10 Apr 2024 14:38:35 +0000 (UTC) X-FDA: 81993878190.21.2D995DA Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf30.hostedemail.com (Postfix) with ESMTP id 30B5380015 for ; Wed, 10 Apr 2024 14:38:31 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf30.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759913; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RuHY6VVKOxj9Xdepnr+9bRSoYO0Xxk07pmy/1ZAaEXY=; b=RszYKIctlrrjgwL3k28/HG+8gfxBItKrEz6LSfMcw3b1hrtl6fDL2UzYSadFtVGl37xgs9 UQdXLm9s1eXHX/RCuukz50aA6DH/ja+TDdANosUUHI4r0LgaJWpWKUsYg3aC6PtYw0pAR+ 5eFXa5rmHVVDdJW+9KnIN+StgNTXYBs= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf30.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759913; a=rsa-sha256; cv=none; b=X6bhFnkNW7lrsvEUpVcqLSS0pqzh/4AWRpPWgCwF8SN5LTf3phnbndfedvL3h2DH+wgVEu 35KHXeVT3NgX2wBeeoZKkBK2fzL0cZAq6gWNXhx9XpskYR1nAaVPH7rs/OWtcpVBI1qMeS OLnS7RqAD/Og/miEE2CtslvlgT/TGw4= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56M0GC2z4f3lg7 for ; Wed, 10 Apr 2024 22:38:19 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id AB9711A0568 for ; Wed, 10 Apr 2024 22:38:27 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S7; Wed, 10 Apr 2024 22:38:27 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [PATCH v4 03/34] ext4: trim delalloc extent Date: Wed, 10 Apr 2024 22:29:17 +0800 Message-Id: <20240410142948.2817554-4-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S7 X-Coremail-Antispam: 1UD129KBjvJXoW7uF1xWF1Dtr17tF15Aw4Utwb_yoW8CFyUp3 93CFn5Gr4fWw18WayxJF15XF1rK3WUKrW7GrWfKw1rZas8Gw1fKaykAF17tFyUtrZ3Xrs5 XFWDtw18Cw4ftrDanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUH214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JrWl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAa w2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrV C2j2WlYx0E2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE 7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxc IEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2AFwI0_GFv_Wryl42xK82IYc2Ij64vIr41l4I8I 3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2IqxVAqx4xG67AKxVWUJV WUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MIIYrxkI7VAK I48JMIIF0xvE2Ix0cI8IcVAFwI0_Ar0_tr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJV WxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4UJVWxJr1l IxAIcVC2z280aVCY1x0267AKxVWxJr0_GcJvcSsGvfC2KfnxnUUI43ZEXa7sRizVb3UUUU U== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Stat-Signature: ky945ittjk95ik7ew6a6na6f7nsqpbn8 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 30B5380015 X-HE-Tag: 1712759911-902849 X-HE-Meta: U2FsdGVkX18KC5dG5ZQPF8fH72Ei2AkwpYnGjM8ZZAv8RSJVh9fL1wIv7DS6Mv7r8lbq3odQ9xWemJ6+vPyTtcyu08NspR3wp+vakEqaJCKytVd+uVIk25R+8wFPXTGwup2INxUNCxNirB0oOU/xdl0JxoiACCS4LvBqAT/NFhbZqntgoxv4nCktSzPquDWjtSncyGRVLcijEC+Ok/bChd9gDGoFI/7i9cl01O8G27w91nLQuKt5yLZ5TIh4dpbVTX+xwG5ufCh/1NeUCm0n1d+o8gAtU6TdFdnfJPrWvZMH34JrasRRc4m1zgA9OIO9MH8dFf33bFQEYjOaBE82LEoBi/MOm+Gg9kvQIIJ8AqYnfD6EqSFlsPsvfubYonhJq5huV8TUDnUbMWiobmmoRLwVNVZyNs9rN96XGkBw8PNYly9ID2QvXbsYmDohsORQaJctsK3AooDm/CTd62QZuKu27pS4b3YQdmkuArGnU/P9pD6wkVtvLlsmZjncIOwyRtksT9Mmk5Bp33Qyw+WKReMbPuwnsbtmQwJQPtCpXLqObOcCIA2KnNsRIbewnZ43TgQpr0LSBb0yIZ+kVlArGsms/1ISMGG1GiPv7AwRgFMjXeG2zn7Lxw+n9johcM4cYRucir+ohF2rYgQWo6m6kUvuz1tMY8E+znDUNatKN00MkFys+fKs1iN3JJ+TWx8/ANePG0o8gQQpAILRZqEynu9YGGQ4Byz3AaSb7SlN/NcBRc5IkLn1z5cqrKcSCRt3dobDWqVlqscQJe5RqToYQNmYK+UTFOLaWZqCLuChKgI1KjtFPPVaOJuew4379isonzJxdpksDdWiwww+PsdeeoLRFb8LKqAL/7dOr36N9T7OHtUwoX3+PmusZniCxcuIcWGkdgBI1SG18Nypwz3fm704syO2DrJvufH7kk73rcSjVwZbtPbacQQs99ZFm7OlmFM5PyVuR3f/e8+HNW2 5FKayFgR 7a+kaj3xfdkOhDZZOt3avf7nc2Mvj4XUZA5XPGxNHVSfyp/Y5Q2RoO4bIfsxz1XgafDOdeMwaF2bDGWuqBKzHLty1Pa5SoZ/6EeqwS3zGBwwXG7Tr8NCGH2YPoGL6VbmR5YwnQchX8S89nT5j3JtqqFGx1YT8ZJUN/P9yvLehvMR0c3D96+jechgfbLRUd6emMKHAaD/+6b1Ro91pUhUxpy+wMwtsuh7v73QJpDly5nEYgzY0EJQ3VCsH2klCnW8HgRE8 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi The cached delalloc or hole extent should be trimed to the map->map_len if we map delalloc blocks in ext4_da_map_blocks(). But it doesn't trigger any issue now because the map->m_len is always set to one and we always insert one delayed block once a time. Fix this by trim the extent once we get one from the cached extent tree, prearing for mapping a extent with multiple delalloc blocks. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 118b0497a954..e4043ddb07a5 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1734,6 +1734,11 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, /* Lookup extent status tree firstly */ if (ext4_es_lookup_extent(inode, iblock, NULL, &es)) { + retval = es.es_len - (iblock - es.es_lblk); + if (retval > map->m_len) + retval = map->m_len; + map->m_len = retval; + if (ext4_es_is_hole(&es)) goto add_delayed; @@ -1750,10 +1755,6 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, } map->m_pblk = ext4_es_pblock(&es) + iblock - es.es_lblk; - retval = es.es_len - (iblock - es.es_lblk); - if (retval > map->m_len) - retval = map->m_len; - map->m_len = retval; if (ext4_es_is_written(&es)) map->m_flags |= EXT4_MAP_MAPPED; else if (ext4_es_is_unwritten(&es)) @@ -1788,6 +1789,11 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, * whitout holding i_rwsem and folio lock. */ if (ext4_es_lookup_extent(inode, iblock, NULL, &es)) { + retval = es.es_len - (iblock - es.es_lblk); + if (retval > map->m_len) + retval = map->m_len; + map->m_len = retval; + if (!ext4_es_is_hole(&es)) { up_write(&EXT4_I(inode)->i_data_sem); goto found;