Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp184743lqj; Wed, 10 Apr 2024 07:41:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVCFwOKsEMnefXsrNvWlf+iehRX79DglGrk8DSLrLZbLfWP85Hzwh1cne3bQADn5P68fZeKTezaPuO2Imv7yfpt3CnYN8rAQBRGjQrmfA== X-Google-Smtp-Source: AGHT+IF+anEkTFsPXPk/XkLjQRQmHSJrFLSebuVXnXlcoGRbr9HcE7AUA1O6y8zFMopz+aquwhB9 X-Received: by 2002:a05:6a00:841:b0:6ea:c42a:d705 with SMTP id q1-20020a056a00084100b006eac42ad705mr3496177pfk.10.1712760104353; Wed, 10 Apr 2024 07:41:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712760104; cv=pass; d=google.com; s=arc-20160816; b=ZmK/qxYNBu2HWuwk0HeRkf3uSC6tOOo4FHW/euXa2f8tuCk/DINazNVHrJVW8EBaAH i9g7uTEGj7rxjeNKXGwwXq9rYBnN/DlXOodAnABo2xJG8MY0sPGU7zfQ5776Vw/rxQlS UvunAQu3/WadBgsaJUtPnC3At+VZjNqjl3IbRkh3CPZcLHqeL1fr1Vt0b4CLAM4CmFXe bXUfvy9qv0fZfjy/k4O+my+mO5eu01rf5+CFdpseywCcmwzVag3fL9D1QOmVVsbaDTS6 XbUXkWIqtNZJ1omQoNNWDoB10dF18HsfsRhL6O8nvYR7juBhfne4d19P5tebQzS6TGoc 3dsw== 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=RuHY6VVKOxj9Xdepnr+9bRSoYO0Xxk07pmy/1ZAaEXY=; fh=VCdyVZCUh9R8dltaA9/RWs/hxQzWhc63WX0fta2PQtE=; b=YnxgDy8pTau0xf9wf8+9/Smvsk9FRyO2+DVBaxHnIbY5StNhZFT+0Zzpj1mlshsNHw J0WdT8mRH4c/aYxiK+WA4sB4lwx446kVYbruIZfeTFhWwhQ52meNIgX9iLr6kgQhxLtT MDlExlwoUddwowdhWN+NS9mfLKfeLHQaLd2WULZxAFpiHgvksGo7wcub/q0jFOdN7miF HCXk65b5V2eHDy1QHLfCihvmrl0YX8d3TboNf7hn6xlw2S6i+WkaMU/AdIPotAyRdPJl 98sXTPEgIG8AByP8+iJzTQ1/4c2s24Yb5FoVjzySuJGygsK/N6Sm9441QaVryEJiZfsC QxGQ==; 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-kernel+bounces-138772-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138772-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id o4-20020a63fb04000000b005d778417e50si10898418pgh.587.2024.04.10.07.41.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 07:41:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-138772-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-138772-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138772-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 4A516285C6B for ; Wed, 10 Apr 2024 14:41:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EEEF2176FB4; Wed, 10 Apr 2024 14:38:34 +0000 (UTC) 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 ABA4B16F0FE; Wed, 10 Apr 2024 14:38:30 +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=1712759914; cv=none; b=sic6GY/Wofx3SDUdartvkGW3A21Lni2tBrZpGuaNNqb+JFExbh54uRMq+EB3UpJsusa+B9tQLV52n01snbOiFqlXjqaz8Lnh4tnLvPVfoxOBrc8sUQLVtl9OKfbr79PwFhpnKrq5f5wxL4gNjhYwFJqam8kZ8gR+L8HP+AcNitA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712759914; c=relaxed/simple; bh=4aKBF6J1JifebI88IbB+j6VQBFGLK9Ep7hy6nrxj5rE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QKrEqN6H3TElRwO76ZDA0dA/FZ16Hg2jPJ630/wIJjcfF7Wb5hTBCFSJZi8GI3RvKIvvy33hGRCAzYCahiBEaZAHDhFvK/VBma6iH4dNs72Vx00mjrA90qm+NBvDjTBulRikSIjIejKo6ZzfJHbZAqetKp+egFroG8kQ/ncPEss= 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 4VF56M0kcNz4f3lgM; 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 B9A5B1A0572; 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgAX6RFSpBZmcwR8Jg--.63000S7 X-Coremail-Antispam: 1UD129KBjvJXoW7uF1xWF1Dtr17tF15Aw4Utwb_yoW8CFyUp3 93CFn5Gr4fWw18WayxJF15XF1rK3WUKrW7GrWfKw1rZas8Gw1fKaykAF17tFyUtrZ3Xrs5 XFWDtw18Cw4ftrDanT9S1TB71UUUUUJq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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; -- 2.39.2