Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp185615lqj; Wed, 10 Apr 2024 07:43:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUS3I3XirhA4d/GmRQ42qyAhqLhALx+v1yWdUem0EBwWw6Iahvbpil1SSJZde30+IJbgNBUhuE468t2xqB2SWEGssI2JUZUCVMKXBe1gA== X-Google-Smtp-Source: AGHT+IHBja18w47Mem0Le31yWMgXJYVVO+/WOHqesx+3d0s/NlM8saQ54vXTDVnJ3oux0D5WQIbD X-Received: by 2002:a05:6358:8490:b0:183:7d27:c08d with SMTP id e16-20020a056358849000b001837d27c08dmr3247226rwk.32.1712760188036; Wed, 10 Apr 2024 07:43:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712760188; cv=pass; d=google.com; s=arc-20160816; b=KVxcsW+/dYwHrEePtPWKNgxOtMTS6JYfiY3r45aW6/KrRskR+u2Ms8Sd/meobHSuSY BYjVObfj9BLffhLJ8DVHBDM/VsI/EAPibjIyj8/ZUGgkqDqJYJiN6356kyX4PP9h9XC4 v4QJvEohw/3kGkvy6UGKcKiFS7HDmAQq7/TbCFEj9pg10T52y2BQjnvgQ9t6UYu4CeKN 8f5q4D6YaSfSeA/hlnpVNGF9t+ERVix9RzbPmtmAzjk6feB35lw/Rxqus06Dg7oq+rTr axl+9QFfXecqI1A8FDGAmJ7JYjYww6PM6JpPJTyAL2uz3ZHg99PZ6Yozso5CFk7ICew2 2ftQ== 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=su8wBnthmKdxQo7o27r28TvXUm1bnpFTwPTSX4XdHa0=; fh=VCdyVZCUh9R8dltaA9/RWs/hxQzWhc63WX0fta2PQtE=; b=qyfdSIHnZHUfXGrr/YO28tlE6tPmujBr2NUBG+tKBkWis4LqXnPcMuBr8zviZLOtY5 etVzx1k/2/FgUrRJP4qqk01IRCNtDsB6krs02SvcYI/kXjX6XqvcvV97OTKpKwNDppw1 ShCyZ4jRHv9NJptUoNCCior3Oa20ZBMUOuUWwBjCdlVbrSV4joDlt4pV4qyw1KjyEt9g /z3M5X18H5uj/SXmq+w1f/HHRFA+3kSYnmV8vcbU6bjEE69gqPVaAY87BiEleKu9xhmM 0x0iSFuEFt9HvbLhskAiz7jD4WpaS/ZnKpDebaULHSv+BsUyEN55y+34TNI/q2LiKu1W J9og==; 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-1980-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1980-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d129-20020a633687000000b005dc89648272si11007677pga.24.2024.04.10.07.43.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 07:43:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1980-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-1980-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1980-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 598C6288A1A for ; Wed, 10 Apr 2024 14:43:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 979C1179211; Wed, 10 Apr 2024 14:38:37 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout11.his.huawei.com (unknown [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 8A554172BBB; Wed, 10 Apr 2024 14:38:34 +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=1712759917; cv=none; b=lkjYsapkSP8wREV6TXu+1/caQLY4cf3Tatyp/Xz9VsCGLeqc139UukTpGW2H0cCRc6gOjhdHuqXZjZdwkiZ0FGF5v13Jln3gsHvSz8GNd7p2g5TR6moBmJCxN1lKDy16/BC4wooPryaf/W9O6GGOc4cpD2qF+kGhc86sqIeK0yA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712759917; c=relaxed/simple; bh=NB4fXWHn4Tcd06n0yHnGM1XaWGMrwV7OP0+NM28cf2Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ke5HOPymakrZW56xSIDdLzM4FAUXxJao+WwyhzUsrO7IWYtDAlNQVvIHUY4S5fLJSQ3OL00Ep2btWjmyAYb6tH4FFCGkmyg6fxY2Ne90kOrCnL/5IJv9ID9u3Cg1dYVBNfXlSJx9WF+MMjN3tbeI4z9tGlC9j7YxzSYU8jc4nj4= 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 4VF56Q2PtRz4f3m7Z; Wed, 10 Apr 2024 22:38:22 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id F33A31A016E; Wed, 10 Apr 2024 22:38:30 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S12; Wed, 10 Apr 2024 22:38:30 +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 08/34] ext4: make ext4_insert_delayed_block() insert multi-blocks Date: Wed, 10 Apr 2024 22:29:22 +0800 Message-Id: <20240410142948.2817554-9-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-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgAX6RFSpBZmcwR8Jg--.63000S12 X-Coremail-Antispam: 1UD129KBjvJXoWxAw1DuF47Aw48XFW3ZF47Jwb_yoWrJFWkpr Z8CF1fJrWagr92gF4Sqr1DXr1aga1ktrWDJFZIgw1rZ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UUI43ZEXa7sRibyCP UUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ From: Zhang Yi Rename ext4_insert_delayed_block() to ext4_insert_delayed_blocks(), pass length parameter to make it insert multi delalloc blocks once a time. For non-bigalloc case, just reserve len blocks and insert delalloc extent. For bigalloc case, we can ensure the middle clusters are not allocated, but need to check whether the start and end clusters are delayed/allocated, if not, we should reserve more space for the start and/or end block(s). Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 51 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 46c34baa848a..08e2692b7286 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1678,24 +1678,28 @@ static int ext4_da_check_clu_allocated(struct inode *inode, ext4_lblk_t lblk, } /* - * ext4_insert_delayed_block - adds a delayed block to the extents status - * tree, incrementing the reserved cluster/block - * count or making a pending reservation - * where needed + * ext4_insert_delayed_blocks - adds a multiple delayed blocks to the extents + * status tree, incrementing the reserved + * cluster/block count or making pending + * reservations where needed * * @inode - file containing the newly added block - * @lblk - logical block to be added + * @lblk - start logical block to be added + * @len - length of blocks to be added * * Returns 0 on success, negative error code on failure. */ -static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk) +static int ext4_insert_delayed_blocks(struct inode *inode, ext4_lblk_t lblk, + ext4_lblk_t len) { struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); - int ret; - bool allocated = false; + int resv_clu, ret; + bool lclu_allocated = false; + bool end_allocated = false; + ext4_lblk_t end = lblk + len - 1; /* - * If the cluster containing lblk is shared with a delayed, + * If the cluster containing lblk or end is shared with a delayed, * written, or unwritten extent in a bigalloc file system, it's * already been accounted for and does not need to be reserved. * A pending reservation must be made for the cluster if it's @@ -1706,21 +1710,38 @@ static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk) * extents status tree doesn't get a match. */ if (sbi->s_cluster_ratio == 1) { - ret = ext4_da_reserve_space(inode, 1); + ret = ext4_da_reserve_space(inode, len); if (ret != 0) /* ENOSPC */ return ret; } else { /* bigalloc */ - ret = ext4_da_check_clu_allocated(inode, lblk, &allocated); + resv_clu = EXT4_B2C(sbi, end) - EXT4_B2C(sbi, lblk) - 1; + if (resv_clu < 0) + resv_clu = 0; + + ret = ext4_da_check_clu_allocated(inode, lblk, &lclu_allocated); if (ret < 0) return ret; - if (ret > 0) { - ret = ext4_da_reserve_space(inode, 1); + if (ret > 0) + resv_clu++; + + if (EXT4_B2C(sbi, lblk) != EXT4_B2C(sbi, end)) { + ret = ext4_da_check_clu_allocated(inode, end, + &end_allocated); + if (ret < 0) + return ret; + if (ret > 0) + resv_clu++; + } + + if (resv_clu) { + ret = ext4_da_reserve_space(inode, resv_clu); if (ret != 0) /* ENOSPC */ return ret; } } - ext4_es_insert_delayed_extent(inode, lblk, 1, allocated, false); + ext4_es_insert_delayed_extent(inode, lblk, len, lclu_allocated, + end_allocated); return 0; } @@ -1823,7 +1844,7 @@ static int ext4_da_map_blocks(struct inode *inode, struct ext4_map_blocks *map, } } - retval = ext4_insert_delayed_block(inode, map->m_lblk); + retval = ext4_insert_delayed_blocks(inode, map->m_lblk, map->m_len); up_write(&EXT4_I(inode)->i_data_sem); if (retval) return retval; -- 2.39.2