Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp477062lqz; Sat, 30 Mar 2024 05:10:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWQGLoJ4nidRPabT7hP8X55viXUkT8GeUrrZBPv7jXlSYElmHDkBTsQSEHQXEFMZ7Kkgn6PwuJ7x99RFkJYskxviYH3hpnbCzXIFR6J4g== X-Google-Smtp-Source: AGHT+IGV5MMAvrJ8RcVZO1giSrZpNozZL6XQSkGFiDox5a6cfaGQD6T9n1TuXG3GXUBCPpYj5mJq X-Received: by 2002:a05:6214:5144:b0:690:747d:f8d4 with SMTP id kh4-20020a056214514400b00690747df8d4mr4939158qvb.19.1711800653272; Sat, 30 Mar 2024 05:10:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711800653; cv=pass; d=google.com; s=arc-20160816; b=QPZZm6tlRr7zGzK1OD7GCGtXqq/CSwqjmZYeJ2S7z+SNygriM2WWb1io76xf0o/Yv0 kpKwNXHLRvPbdF7wefesVnz7+WWAqWC/LScxgdGLoUNxRk2bMwyaspV6OZbQL7c8ZjOc tCBzDF/9MOub8lWgy4ZhwcqDwL5X/MZl5GcvqtIsyUiyD++elRI1/q6b85TyOxUerXuD c4KwdrW+vvfdF108OtYWW0RNG+e8pwBFy6wJVTHkYV3BmWVclRmXRNlyaHgCFUFS9KiU hoYLZeUVrKyz3WdlS1bYt9uTm1cMaY42lpAs+xn4EF8LMipFsO4BvDMmkvRdDTb7WUce N2tg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=YhxVXtrSHEw2s/oCsMy116pk+Um7fUgp8JY/6rq0H3Y=; fh=dC1DNofMpo0fGa+HNNOiDPPA5M30OdZqJ1HdUJkde1U=; b=qbRwMr99JfBXP/eEMUmHQLdlR89WnFMJHcXbDffHlhGf1gKaz1vHOE/AU8gKgUmI5J Z++0HIlcp5447LbPr6NE00UCP4aVMZSg6wkt64udxdrl4Y2QhTMyZjRXP0onIWzG5C1l JKF4yHzVNLHO2rsouz6iNQBwMPqg9/1fn4lXHpMMrvSkC4/lgQU43t/7Xm/pnKjHdHFp FfUKTRZSfOPYfha67b6uxHsYCceSrAIRR0EoDla5Hh29ImJOVe9zKZ0VXIyRhZb/1GeF XmoAJapmkf6DMA+By7TLmdUFhgzmSTf+irQ3SynH/AttwdhhjjrYamidO8IDFj1VTIQW VHxw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-1793-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1793-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id s8-20020a0ce308000000b0068ffe75615csi5890877qvl.269.2024.03.30.05.10.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 05:10:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1793-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-1793-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1793-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 04D601C211AA for ; Sat, 30 Mar 2024 12:10:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5633E38F84; Sat, 30 Mar 2024 12:10:40 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DFF55376F1; Sat, 30 Mar 2024 12:10:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711800640; cv=none; b=r5FAfmRMbNEgg+tykiVHArYEAiDevfbrkHSX9cw5XCIUsLuZH32IC8HMISIY6loT4AuCVAS5NFs9KvUoFdxRs+oFmzcj20eEXSWKR8W2U9B3AT55QMjQFbpgcwmrNcG3DheJrzFj2uhjSpPYS/iZy7OGOl9oajEOpEroslI4ISk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711800640; c=relaxed/simple; bh=11+SGCiUJDvBIX8i0MUftVdWpPzxfUmBF5mjBNtiZNQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=j8vp6BLd9pWA/hEJLoCvv8UPlB+ASqbdDE0iYzGZt15YrHRyhBevycMNQlNaqTnUc4f/f21d3tQKud8ARV7jQgPhYMdYwb8OS5nVlGpss9iAwd7M3doH6jqQ8V47I6plelrRsC4Xy9bJ4eS9t77ISuqahE6saWVpe9weiAQ92zY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4V6GLl54gwz4f3m78; Sat, 30 Mar 2024 20:10:23 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id EC9AE1A0232; Sat, 30 Mar 2024 20:10:31 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REsAQhmkPEjIg--.10652S5; Sat, 30 Mar 2024 20:10:31 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: [PATCH 1/7] ext4: trim delalloc extent Date: Sat, 30 Mar 2024 20:02:30 +0800 Message-Id: <20240330120236.3789589-2-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240330120236.3789589-1-yi.zhang@huaweicloud.com> References: <20240330120236.3789589-1-yi.zhang@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgAn+REsAQhmkPEjIg--.10652S5 X-Coremail-Antispam: 1UD129KBjvJXoW7uF1xWF1Dtr17tF18Kw1kGrg_yoW8Xr4xp3 93CFn5Gr4fWw18uayxtF13XF1rK3W5KrW7WrWfKw1ruas8Gw1fKa1kA3W7ta48trZ3Jr4F qFWUtw18Aa1SyrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9m14x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r1I6r4UM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0EwIxGrwCFx2 IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v2 6r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67 AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IY s7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr 0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUqAp5UUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ 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 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 537803250ca9..b98f92622442 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1705,6 +1705,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; @@ -1720,10 +1725,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)) -- 2.39.2