From patchwork Wed Apr 10 13:27:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624534 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31C07CD11C2 for ; Wed, 10 Apr 2024 13:36:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E1A06B008A; Wed, 10 Apr 2024 09:36:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7598A6B0092; Wed, 10 Apr 2024 09:36:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 621886B0093; Wed, 10 Apr 2024 09:36:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 41D796B008C for ; Wed, 10 Apr 2024 09:36:57 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id EAA731C09ED for ; Wed, 10 Apr 2024 13:36:56 +0000 (UTC) X-FDA: 81993722832.10.AAC7E6A Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf26.hostedemail.com (Postfix) with ESMTP id 9CF8E14001B for ; Wed, 10 Apr 2024 13:36:53 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf26.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712756215; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RuHY6VVKOxj9Xdepnr+9bRSoYO0Xxk07pmy/1ZAaEXY=; b=aQpz+83kqZr5Y9dotrz/JW5gN6YE1HDHQXhrd8uaICj7SsK2q6XGiupETpbY7J2ZAHwEB5 OgJ41rmLinAKjC92rUMepD0sUnIxdK6+EePR297EpTwcx5K1/kvwB1zRITf8GNwvBvsTpA rappG2oArJbMQM2kZrjoHYwbfjSJmWU= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf26.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756215; a=rsa-sha256; cv=none; b=ygmT8H8XTQoMcDRoey5Rdxvn7w99B0GX8Aboj6aLnO9GiH7wxqoxeq/0ukuZZjek7vSMRU Fo1BCN73f35aiU4GAbsUEBzznUGhijZshbgDE0r4a8wbyWbovC+xc723ZQxxlNKzWCkBtp 2b+oSlmRJvb1gqaW8Tx4YtDttv7kEVY= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lF18ynz4f3mHF for ; Wed, 10 Apr 2024 21:36:41 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id CC1091A0D6D for ; Wed, 10 Apr 2024 21:36:49 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S7; Wed, 10 Apr 2024 21:36:49 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [PATCH v4 03/34] ext4: trim delalloc extent Date: Wed, 10 Apr 2024 21:27:47 +0800 Message-Id: <20240410132818.2812377-4-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S7 X-Coremail-Antispam: 1UD129KBjvJXoW7uF1xWF1Dtr17tF15Aw4Utwb_yoW8CFyUp3 93CFn5Gr4fWw18WayxJF15XF1rK3WUKrW7GrWfKw1rZas8Gw1fKaykAF17tFyUtrZ3Xrs5 XFWDtw18Cw4ftrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP014x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JrWl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJw CI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VU1VOJ5UU UUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 9CF8E14001B X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: a4m4wsmieyhrqmc83mabkcghn3c4pui3 X-HE-Tag: 1712756213-484378 X-HE-Meta: U2FsdGVkX1+oKwAFoi88djIGmMEYpsle3CFadapKlbjyzGcoIh05hAOiFxAn/bubsLGIGrE91d0gS54LZ9XZDkeQ8I81ZwL/yErQc3qsITgkvUZsWzT1n0q+aLq3wrW0ORYRqoCytLKIAtYFN1eUQLyC67tObNC6qQxF41zpb/F5/UwyHNeCME7u5EhpbPzzg+Z9ReoGwGyAgUUE30kJMCv+tVitByZ0IVkUrpzU/NX2RZ119Wf9dF6tLlXeUsLncZRB1xGej3Mba/hbpooJPd0y3RVeS1FDCMtkInpRfpkJ0yfAkgKr3UVBRbZ4tzNIn0+9FW/I3wT5jRKB0EmL5Qx4gMMXIkBW+u+N8Eh95fv48lmRC0QOKiJ1KAsbIAqDYwUldoUCyv/SoAO5XwnWX+F4B9uEIheAnVYWrS6wemOSGM0mbHjrkepINhYjSUrIq1M4x/nkVyjNQqTeFvVApCm3qYFn16cD7w/hizF2OIHM6UeJZXzlh7d4ca3AZBKYhyrpYH6PAqL0wnc7Vluhjc7IOGG7431/R683SgsMh+lHyyylUJClRzphaeOYBnGZSYbXLXevdsBmRQxMhGKfoDGl/8dtIwALCcmlWBgrwfEut9o4KJaynPW3unpFjMdoi5Lbdhwjy2syW/vnfaSzSYRg6SSNLT3LcArRV3B4wUHBquet2HA9gDRN5MtmyncbzvDO7OX54BFBLCHCnUN/ciF7qLFtabfoLmDOY+uwLgZKEuTPsHtgCtcTkESPmA1FuC1BHkbdADheELFwcJvIq+C9Nv+z/19pTd40Bnam6IBGsYu6gbKpPBeXeX+l9JxnRzz4zqmLPbeOVfe7sFBOzn9eYznbISAbMJK9h3SZYhEA7MLRSXywRTevazBjykDEwMOA4laZlp+jT7v7J8hravpBRHM3xTTKmu/irBsC2VJpvPjCCPJ+l207MPKZ15XPMwQ3yh73fLGCrAK91/M gu2Q/+La dc2KrK2224tOUmpAZm+5QvWo+doz9Fh9adaujNrjfnGAfrW4VYXBadEZTwQfWHPk0WUMxFj9pdEBj6jVa7aUqLnW8QjJaHjhqPYqxH5VL6FZjtgg20dPf3RXUtJZDXwPVEI6ja9uLdnui82BI/hB0D5Q1uS6prBrU1lm5920e19OoVsUHzXdB78G/ggS9Vjb+ybbdSrEjiKTJJac2mGL0BItG2wkI8EHHWwQafqyiwTRSe00iptOFPkL0OuQcrV3gJVhq X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi The cached delalloc or hole extent should be trimed to the map->map_len if we map delalloc blocks in ext4_da_map_blocks(). But it doesn't trigger any issue now because the map->m_len is always set to one and we always insert one delayed block once a time. Fix this by trim the extent once we get one from the cached extent tree, prearing for mapping a extent with multiple delalloc blocks. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 118b0497a954..e4043ddb07a5 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1734,6 +1734,11 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, /* Lookup extent status tree firstly */ if (ext4_es_lookup_extent(inode, iblock, NULL, &es)) { + retval = es.es_len - (iblock - es.es_lblk); + if (retval > map->m_len) + retval = map->m_len; + map->m_len = retval; + if (ext4_es_is_hole(&es)) goto add_delayed; @@ -1750,10 +1755,6 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, } map->m_pblk = ext4_es_pblock(&es) + iblock - es.es_lblk; - retval = es.es_len - (iblock - es.es_lblk); - if (retval > map->m_len) - retval = map->m_len; - map->m_len = retval; if (ext4_es_is_written(&es)) map->m_flags |= EXT4_MAP_MAPPED; else if (ext4_es_is_unwritten(&es)) @@ -1788,6 +1789,11 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, * whitout holding i_rwsem and folio lock. */ if (ext4_es_lookup_extent(inode, iblock, NULL, &es)) { + retval = es.es_len - (iblock - es.es_lblk); + if (retval > map->m_len) + retval = map->m_len; + map->m_len = retval; + if (!ext4_es_is_hole(&es)) { up_write(&EXT4_I(inode)->i_data_sem); goto found;