Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1333321lqa; Mon, 29 Apr 2024 05:56:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVOZItYqHWVnWEzoHrlsxVCL+9cvWPiFm5EvOL0Ijq88Gj2j/LVZhpzu0qwl/0JUT5AJtkmP3j7ToJcvxEOs7C9w5mOorRUzDcy12GzMA== X-Google-Smtp-Source: AGHT+IE09sUeXc7wpGt28yhMXHCHsFy+ezoI7nSuy1spmHp6kjGU8y/nI8ZKc+BpvbBfg1OrwSXo X-Received: by 2002:ac2:58e5:0:b0:519:4f54:1ad4 with SMTP id v5-20020ac258e5000000b005194f541ad4mr5808602lfo.27.1714395385049; Mon, 29 Apr 2024 05:56:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714395385; cv=pass; d=google.com; s=arc-20160816; b=r+KADQvs86IzqK8Bl1PUF2CzRQKem3gqwImdPD7Fqoz7pfI54INJWIX9gbF8hKo7Qs 1BWNX7WjtV5HDVqHgRFWyPa9AUY9WWmnFATzKEEFsN0voQy/+vkDUOSyK4aIjqGYq+cn 3vetb37Gd7NxbGNk0nkoxPAQdc7JeW6KKlPTuil9tk+RbnBnrPxd6GsZAOFmM/Gjhphm LNyKNWbjOu0hf+tHBwyq8bYhHCZAPobWyzuR0ZVblS6t7lxJF/tLNOKQibZgNT4rrYSS 7xjcX60I1Tie0/kwIY2hB5uV3U69cXSuIzHwlx6m0jWR8PggM1w9f23mKSG5KO4+c2yt sCzQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:user-agent:date :message-id:from:references:cc:to:subject; bh=2bMbQpr/TIBru+JD8zpJ2TC4+RSO1ZOg3FGsdSDmEOM=; fh=1Q5tS/thi59I9xbGZKEqGxYYQ5q707YuZZQ8vq+R+eo=; b=tp2bdJ0e/fBatpmbSKF4cDfa66YkXN+rTjaODjH6xS8MqInIjB2UU6/CvqzKcTZFop HAvG4Mg0aowdHtuFDGQEZnuotBuJEUYq+Ee/CjbMqROWTMRs9PhpwubhR9nYOIqNbrEC 3NIMVPXDsHEW6LDvsPrKjdJbXq1zAVjzXs9TywsHNgztdr7PBLfjA/BYhcC2FJr54jdu jO4N4Gsx6eNU4Wk9gXg5m3QS3bLLBvnR7L/H8GYh9jCcUGo2KzW6PWebdpaISycL6fzN M+jN1IeZd749O55w6HaVV6uf3dNcSZ9lIRKuJcx94XDRkZoZ+gFn67yzDBS/quvYjZvE 9a9w==; 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-2234-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2234-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id fy25-20020a170906b7d900b00a58c571120csi4059317ejb.943.2024.04.29.05.56.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 05:56:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-2234-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-2234-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2234-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 9943D1F21711 for ; Mon, 29 Apr 2024 12:56:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DFC23548F3; Mon, 29 Apr 2024 12:54:26 +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 D5EDE548E6; Mon, 29 Apr 2024 12:54:23 +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=1714395266; cv=none; b=JgRvSEnDSGS9R1g6BJ5trR2zMiIITvh4Ue5UywQvWd0POz8yJgT0H7po9T9ModGwfJNpUDZs7hNzmJczHQsUB8vm8SoV0qn8tHuEMr/sZnqHUQN4O09z9BPGKRnV2TDVskn2jFWH7XDoVuelxR+/r84QXaTPJ9snQ3g091GB68I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714395266; c=relaxed/simple; bh=guw/nyeZnNGsEQjhYGD+vv6oq+tSkv94n7vFLKO6Xlw=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=L/Z8uBgVMSUj0IJ3GAX+1T9YFgwdPJQq+63Oi+lfhv8MYPBdSy6abvwGmmZn4bY6cvlzmw8v5QUECvjsp0b1R3Agg2I4xTtfEmWvWg7PO/XhbrJDcqrlu/HgsmnBor+tCNy5XHjst5IA9/UaQ9voZsDfPgTBr/AeqiYJPppYvp8= 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 4VSjvQ1QLCz4f3m77; Mon, 29 Apr 2024 20:54:10 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 9C96B1A0179; Mon, 29 Apr 2024 20:54:19 +0800 (CST) Received: from [10.174.179.80] (unknown [10.174.179.80]) by APP2 (Coremail) with SMTP id Syh0CgBXfA95mC9m9qstLg--.45045S3; Mon, 29 Apr 2024 20:54:19 +0800 (CST) Subject: Re: [PATCH v2 8/9] ext4: make ext4_insert_delayed_block() insert multi-blocks To: Jan Kara Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, yi.zhang@huawei.com, chengzhihao1@huawei.com, yukuai3@huawei.com References: <20240410034203.2188357-1-yi.zhang@huaweicloud.com> <20240410034203.2188357-9-yi.zhang@huaweicloud.com> <20240429100659.pudgimunspsmrthy@quack3> From: Zhang Yi Message-ID: Date: Mon, 29 Apr 2024 20:54:17 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20240429100659.pudgimunspsmrthy@quack3> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CM-TRANSID:Syh0CgBXfA95mC9m9qstLg--.45045S3 X-Coremail-Antispam: 1UD129KBjvJXoWxGryUCF48JrW3tFW5tFyxXwb_yoW7JrWUpr Z8GF1fJ3yaqryIgF4SqF1DXrnIga1ktrWUJFZIg3WrZF93GF93KF1DKr15ua4xCrWkGa1Y vF45A347uan0ka7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkjb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I 0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40E x7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lc7I2V7IY0VAS07AlzVAYIcxG8wCF04k20xvY0x0E wIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E74 80Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0 I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04 k26cxKx2IYs7xG6rWUJVWrZr1UMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIE c7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07UWE__UUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ On 2024/4/29 18:06, Jan Kara wrote: > On Wed 10-04-24 11:42:02, Zhang Yi wrote: >> 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 > > Thanks for the patch. Some comments below. > >> --- >> 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; > ^^^ this variable is in prinple the length of the extent. Thus > it should be ext4_lblk_t type. > >> + 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; > > Here resv_clu going negative is strange I'm not sure the math is 100% > correct in all the cases. I think it would be more logical as: > > resv_clu = EXT4_B2C(sbi, end) - EXT4_B2C(sbi, lblk) + 1; >> and then update resv_clu below as: > >> + >> + 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++; > > Here we would do: > 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++; > > And similarly here: > if (ret == 0) > resv_clu--; Oh, yes, it is definitely more logical than mine. Thanks for taking time to review this series, other changelog and comments suggestions in this series are looks fine to me, I will use them. Besides, Ritesh improved my changelog in patch 2, I will keep your reviewed tag if you don't have different opinions. Thanks, Yi. > >> + } >> + >> + 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 >>