Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp186647lqj; Wed, 10 Apr 2024 07:45:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV5y9WEnPtbcrlzRmI4QDQkeMaUsawtJPnvhJq2QyBZbq4bPvp8RHLsvK+nb7mKyRg2EdwOa2fjLR+UyPgqHu4Jwk+Ntqhzpjx/vhpKRA== X-Google-Smtp-Source: AGHT+IFpS6Gurzm5aK3ScytY4LOl3TGy5FWw1PU0Z+SaZyr3BrxKT3JTnNTb0rQjvZg3kv/06xPN X-Received: by 2002:a50:99da:0:b0:56b:cecb:a4c8 with SMTP id n26-20020a5099da000000b0056bcecba4c8mr2434667edb.39.1712760301289; Wed, 10 Apr 2024 07:45:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712760301; cv=pass; d=google.com; s=arc-20160816; b=zxwbsNoiuMLfVnIsysCbccPjD/GnYf2flYl4sE6P7gdXN/cPiqZisNemwWEmd58x5U MS7epbkXp8QqmIvgPrvr+4Ikrnggvoddz/cqwOmt+sRu2f7bwOgXHQ0wBKR3l7jzp/pQ Nvnu/P75H7ET2Do1I3ojl2+jIGo3U7n8UREx/gOHSksBYCfBeoG2IRN3KD3ZN5Mfw5iS GWTkQtC9/sUj2aV+orP90lNUVjxuhst1wzDhW4T3a5PwbiWvNjO40rjDMYhZ4u1CmuSy syHQNUiVL2UlCJZwDhEvxHGiaDxELlcEP7mif35v/4UQ4P08cqLvyF63XAS+HY2V2Qs9 rCOw== 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=VCdyVZCUh9R8dltaA9/RWs/hxQzWhc63WX0fta2PQtE=; b=Db56cIY9cRVLgY3LOIn0qXS3Vbc856YDM5xxZPjhiML2E7VSWX1oDmzBwtZ92oftVV 3w0xjpPpEP596d6iq1OoQp6bAW88vIAdClfcuUPKUaKR9t2eLUNYkxu3o1YPu0KISeLn CzXXSDfFhyTnMtUNyPh4rwcBzFJIcyBvY/wnSqV2F5WGErM/nYc1uTG72HsSvX+gWyZt 0uUEunqz1N0mgFr8UtvBATd43bzYI1yqa/K5nivtauevKquk9wVHjFczHieP0zrZmWo8 8UCXckGQCe2pKnvd4Fp0+zVfZk1NZampwp3cOaXK4Wviti9l1q6IljrPRFyjYsjp8CYQ +JEQ==; 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-138781-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138781-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id i15-20020a05640242cf00b0056e69cc80c3si2550597edc.243.2024.04.10.07.45.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 07:45:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-138781-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-138781-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138781-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 am.mirrors.kernel.org (Postfix) with ESMTPS id DF5EA1F24B3A for ; Wed, 10 Apr 2024 14:45:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6B64D17B4EC; Wed, 10 Apr 2024 14:38:41 +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 656A01791FF; Wed, 10 Apr 2024 14:38: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=1712759919; cv=none; b=DySQmViuDZym5bIEEyPEA0fZIGX6/ZDQKSdC97Yk4CtUv2VsSJPUAdgkuQoIMrueBZyNNoicP6FgpJsTcscMpPNdyrly4MdOcBfW0L9i0Z/nNKAkQctPiknJ4uOqXp/pYC2q3WdIjXDi98qst7ufNPs1rB6wMja3Q2cW4EVDeec= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712759919; c=relaxed/simple; bh=jZ9QuHKWjFnW4Mhr01Zx0Dlq6tt8dMlb+kosdcApHUE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=m3dvKwkyQKZLuCvvCZk+MeYdw65xWqAYAGg69VWGnFG1nfPdzaNVVIAKsLu/H6+2qza5zupT7oVN4TwPF6Nsf+jPN9VDDD7j62nzwtlcQZglrh6oF5FYecDJ6krqcvAvT0E9CT3CHGhPHz0ROsVPdcMCvHBA7tyvpFUG0iHWvr4= 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.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56X3c7Dz4f3k69; Wed, 10 Apr 2024 22:38:28 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id E1DB51A0179; Wed, 10 Apr 2024 22:38:32 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S15; Wed, 10 Apr 2024 22:38:32 +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: [RFC PATCH v4 11/34] ext4: optimize the EXT4_GET_BLOCKS_DELALLOC_RESERVE flag set Date: Wed, 10 Apr 2024 22:29:25 +0800 Message-Id: <20240410142948.2817554-12-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--.63000S15 X-Coremail-Antispam: 1UD129KBjvJXoWxZrWUuryxGrWDCFy3CFyrtFb_yoW5XryDpr WfCFyrGan2ga45Za93Ww18Wr1akan7GF4UArWS93yUZ3yakryfKF98tFyrZFy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UUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ 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