Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp919459lqo; Fri, 17 May 2024 05:53:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV4G1ZMGkj4lXteD9CFO/gSRjwyYLrlqY9gR2cu/Qo8yY1PgzkW8Pj8xD2Rc/ysjvXw07rQvyc+O3iSt6v+ACPj/n8SfMCv/Q8Au6v/Fg== X-Google-Smtp-Source: AGHT+IHE7t2NRtw9Nqs7xVMAabSGsURv3npIncbDrSaXWbg8P/1S26QDzcgwyL3+x21xfT3FskdC X-Received: by 2002:a50:f605:0:b0:572:315a:b2d3 with SMTP id 4fb4d7f45d1cf-5734d5ceb4emr14354392a12.15.1715950405237; Fri, 17 May 2024 05:53:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715950405; cv=pass; d=google.com; s=arc-20160816; b=s5VK1sUO9HXiBuaQFa2u7xkHHAHvZ/nmDhkZqG1JYZgWJzUX4lzPMiP9spMICzHsGT +MuCOYCaKo9eUjiYCartp3mFbi32SKKu3nJC01Ka7ohF+u+BLRCeIpUWWYD4ledE+BIt /X9h0kSGm0pOs1HrcU/aOCoh65z6eSWkRO8l+9PaKi36a/g8hWOPFPrlKtHULYlZadWX 66Z7bhG8SagG5Y6Rd52ewtRMaPswzWESqGUbQQbbljZxnk6kUF5EdYponqmbCcMc87np N3n+AzTSlXQKqqAp/rhXzzB4LR+hlXjgmr3SZzVp9MZ/1N2Z2Mk0mRPzK6LIfmobZ4ct dTBA== 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=oAqicXb7eUxuxb20qHXwUZ2D/F9GceD6Ti8/NZhSe+M=; fh=/gW0yUFnRcFNkSCPxz8UjBHCGPgiCEguRpLIibqIEzc=; b=lQJFsOBS2KQIiTORds4llYgPT9/xfd1kQpfGtET8u4opy+/MwbkqWvHIk+A21iy7O9 Q2WUKgIj4WQpQj5OdGzbSQ2jqVxPELCregKTNpCFHadu+txdggU8mjAVuXNYNkfqVrxA 9VYlpOm88EhL0rhVEB3gfT+EaOM7VRfQgYWxKsoDisOrmnXysrZgWI79E5w+1ZVu9YX5 s33j4CP+anO0n7PDCgpLFZYO+5jxDZLhRU9eABCDDjXwIiQom72+paYiaTCt7wZfMAxp bo2Mk2klODzlVGIq1bg49kiTUwG0tjvVeCetDfNVzuUFQI03b8vPF7c+e9h7On32mRcL BSdg==; 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-2560-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2560-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 4fb4d7f45d1cf-5733beac900si9880307a12.137.2024.05.17.05.53.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 05:53:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-2560-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-2560-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2560-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 CEBA11F20FB1 for ; Fri, 17 May 2024 12:53:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 768AC6A8DC; Fri, 17 May 2024 12:51:09 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (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 51C374EB46; Fri, 17 May 2024 12:51:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715950269; cv=none; b=TZExgcy0gwg5KPanwQvjFqxYlc7Dh/0jZoNjNlELecJnPA7E3OED/VGGtb+rh0+qxVWmpBTvQA5aB4nt9t50vUD1QuWgyMlg/va59mZ9TV34KNwDiHyUC6ulLd0b13Ye9qy+D9cgLxDNfyLvKCz59qTnd7B45d9w2+JlLbdJ5JI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715950269; c=relaxed/simple; bh=s6VT33z8IPvxCrGeg+82nohpiMNggXFCX6ktGWVjs9U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=M+zSufFwy5n0Fln5+tV3IqvHZBdUOqE1pglaFnT5w6+fgzoaOETen1VBwVgfp7jtBJpJSCFl3bRICv+A+jCL5nR1zvH8bqD1qEJzcyoz135XTRsf7ccsJXHYXyZAgcVP/Nd73xnkUN6BY7kkebLIdfiQt+Xs9xzvXWh4+RElFPc= 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.56 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 dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VgmzG1CzCz4f3jrf; Fri, 17 May 2024 20:50:50 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id E378A1A0181; Fri, 17 May 2024 20:50:58 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgBXKBGdUkdmdAmqMw--.14380S13; Fri, 17 May 2024 20:50:58 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: [PATCH v5 09/10] ext4: make ext4_insert_delayed_block() insert multi-blocks Date: Fri, 17 May 2024 20:40:04 +0800 Message-Id: <20240517124005.347221-10-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240517124005.347221-1-yi.zhang@huaweicloud.com> References: <20240517124005.347221-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:cCh0CgBXKBGdUkdmdAmqMw--.14380S13 X-Coremail-Antispam: 1UD129KBjvJXoWxAw1DuF47Zw13JF13CF1Utrb_yoWrJFy7pr Z8CF1fJrWYgr92gFsaqr1DXr1Sga1ktrWDJasIgw1fZrW3JFyfKF1DtF13ZF1SkrZ7JF4Y qFWYya4Uua15Ka7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUA rcfUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ From: Zhang Yi Rename ext4_insert_delayed_block() to ext4_insert_delayed_blocks(), pass length parameter to make it insert multiple delalloc blocks at a time. For non-bigalloc case, just reserve len blocks and insert delalloc extent. For bigalloc case, we can ensure that the clusters in the middle of a extent must be unallocated, we only need to check whether the start and end clusters are delayed/allocated. We should subtract the space for the start and/or end block(s) if they are allocated. 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 eefedb7264c7..4febee4c833f 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1679,24 +1679,29 @@ static int ext4_clu_alloc_state(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; + bool lclu_allocated = false; + bool end_allocated = false; + ext4_lblk_t resv_clu; + 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 @@ -1707,23 +1712,39 @@ 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 */ + resv_clu = EXT4_B2C(sbi, end) - EXT4_B2C(sbi, lblk) + 1; + ret = ext4_clu_alloc_state(inode, lblk); if (ret < 0) return ret; - if (ret == 2) - allocated = true; - if (ret == 0) { - ret = ext4_da_reserve_space(inode, 1); + if (ret > 0) { + resv_clu--; + lclu_allocated = (ret == 2); + } + + if (EXT4_B2C(sbi, lblk) != EXT4_B2C(sbi, end)) { + ret = ext4_clu_alloc_state(inode, end); + if (ret < 0) + return ret; + if (ret > 0) { + resv_clu--; + end_allocated = (ret == 2); + } + } + + 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; } @@ -1828,7 +1849,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