Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp143143lqj; Wed, 10 Apr 2024 06:38:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV7rH8ckFq9vKqMtTiDpyT0mrEupSH7mhf3oFk3QN3YfAaZOUlfElmmE8Y+IGTjzLmSlOmU7IiasI4R7QlDD7dJ8gH2xYpDQ3S/Tuoy6g== X-Google-Smtp-Source: AGHT+IE7Cn2C8ou+dytbfHk3v6meuczszIgzMx2o8DhS5iblC3GAJayE23ePAljd/0XgglxaAChb X-Received: by 2002:a05:622a:c:b0:430:a087:ab1e with SMTP id x12-20020a05622a000c00b00430a087ab1emr2988865qtw.3.1712756335031; Wed, 10 Apr 2024 06:38:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712756335; cv=pass; d=google.com; s=arc-20160816; b=n6HBtrT+C1grMa9j7v4EEjEyGOnjf9vsDymeD20qBLLnSZghno+fm0HZvtGJTmXL8s CHltPvOf8THIH1vEbw/FbvlGfn4OMQaUmfx9ZHXsGPyfPpjY+LCvZB3rGKEVLZ/iY/P0 33kidwUx015SKLVXCwOSog7QB29cbHHmaAEy5ZAlaRn5NWZTw7nLsqHte5Iffuh8jn1o s8dKUbndWLOpiAXxrbyOkJzkJoqWSta6TdJO70KrUSGawp+6miltkHYAJLjoD2E0rVBE KpUyUOwFI7GZi9cOZO2obAiZg6o+0Cjnt3NEDERAAD/XXOMGzicmBCyuw7T02S+Q8Zln Z9Zw== 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=UtblERf2SjZldtLbjWMgxYmXdH99mF3nTKBUxIYqrQE=; fh=UhGiR19HeAIu8tzXykjZgtAKLLMPZj8YX6gPScUOsdE=; b=b+xce9co9tt/Q8CDvd/h/jNN5HKcAqoD2Eoh1hh7TCSiEakEvoZF9PtW+wYaqZQHgv k5yFHa+FKZpZGejzsAILF124EceQz5TjSBwrmeS6bJbZ2MGAWG07KNfAyrxmAP7eYqjI npCYQ8p7Th7crMbPmOfaWRipCRAihAyknv8l7+tef8/E2zS3d12g1HIX6fqlbgc2TRRP SJfSSd2oKx7gxlZU7O6U1GJm0znA3QBsplqxenLPOhyf3pFWiSdf/UaRF1KkOrq6P5Xs BAfJA+rpQYkd11rpzj16gBJcZUn0qa8ZFwd+JwlwNUQ1Zm4MeRICexwBLDScONLocgBF Ik3A==; 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-1944-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1944-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 u17-20020a05622a011100b004315cf58118si12860204qtw.277.2024.04.10.06.38.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 06:38:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1944-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-1944-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1944-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 C362F1C26432 for ; Wed, 10 Apr 2024 13:37:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EDA3915FCE5; Wed, 10 Apr 2024 13:36:59 +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 DC2BF15F3E2; Wed, 10 Apr 2024 13:36:57 +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=1712756219; cv=none; b=LY2J7DHpDQvJK+AOg66h2SbvsET+JaL4KxTkk5U05PuKfYZZ9UQDqCanzRX0MfNN5VHkD02Pd6xHS4k9A+Q1A2VOIm5HLdWKkdSXmRtnrbEINUwxTBc6Y10+eMtBEb+ZZTprVlfFISqozDvwuWUb2vsuD0bgE0Z2jqJlgAdmzsA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712756219; c=relaxed/simple; bh=jZ9QuHKWjFnW4Mhr01Zx0Dlq6tt8dMlb+kosdcApHUE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XveLXoKLN1cjMQFZyMKbDuFdISyJTAdgiT+fNjPDetKtiBV4hfedYrQt3DBNGeuhsU/1+GQ4cyPLrz1mxF9L4eYHXtHx8yhqQ+ARjTj7Mik/zu4nQYaGBBxw8FiOkEqkjyHJhsXjvTVZXJoCfjtpHyuGu6Ft07qYFzCGVxDYRuo= 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.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lQ2jFZz4f3jkC; Wed, 10 Apr 2024 21:36:50 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id C4CE51A0DE2; Wed, 10 Apr 2024 21:36:54 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S15; Wed, 10 Apr 2024 21:36: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 v4 11/34] ext4: optimize the EXT4_GET_BLOCKS_DELALLOC_RESERVE flag set Date: Wed, 10 Apr 2024 21:27:55 +0800 Message-Id: <20240410132818.2812377-12-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> 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+RHolRZmeCl4Jg--.8806S15 X-Coremail-Antispam: 1UD129KBjvJXoWxZrWUuryxGrWDCFy3CFyrtFb_yoW5XryDpr WfCF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3voofrz/ From: Zhang Yi Magic EXT4_GET_BLOCKS_DELALLOC_RESERVE means caller is from the delayed allocation writeout path, and the blocks and quotas has already been checked when the data was copied into the page cache, there is no need to check them again when we do the real allocation. But now we only set this magic when allocating delayed allocated clusters, it makes things complicated because we have to deal with the case of allocating non-delayed allocated clusters, e.g. from fallocate, because in this case, free space has already been claimed by ext4_mb_new_blocks(), we shouldn't claim it again. Move setting EXT4_GET_BLOCKS_DELALLOC_RESERVE to where we actually do block allocation could simplify the handling process a lot, it means that we always set this magic once the allocation range covers delalloc blocks, don't distinguish the allocation path. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 10a256cfcaa1..fd5a27db62c0 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -489,6 +489,14 @@ static int ext4_map_create_blocks(handle_t *handle, struct inode *inode, unsigned int status; int err, retval = 0; + /* + * 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. + */ + if (map->m_flags & EXT4_MAP_DELAYED) + flags |= EXT4_GET_BLOCKS_DELALLOC_RESERVE; + /* * Here we clear m_flags because after allocating an new extent, * it will be set again. @@ -2216,11 +2224,6 @@ static int mpage_map_one_extent(handle_t *handle, struct mpage_da_data *mpd) * writeback and there is nothing we can do about it 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 if - * the blocks in question are delalloc blocks. This indicates - * that the blocks and quotas has already been checked when - * the data was copied into the page cache. */ get_blocks_flags = EXT4_GET_BLOCKS_CREATE | EXT4_GET_BLOCKS_METADATA_NOFAIL | @@ -2228,8 +2231,6 @@ static int mpage_map_one_extent(handle_t *handle, struct mpage_da_data *mpd) dioread_nolock = ext4_should_dioread_nolock(inode); if (dioread_nolock) get_blocks_flags |= EXT4_GET_BLOCKS_IO_CREATE_EXT; - if (map->m_flags & BIT(BH_Delay)) - get_blocks_flags |= EXT4_GET_BLOCKS_DELALLOC_RESERVE; err = ext4_map_blocks(handle, inode, map, get_blocks_flags); if (err < 0) -- 2.39.2