Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp185293lqj; Wed, 10 Apr 2024 07:42:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV8wNxf7iL6SHJSxM8PJj/oAQyaf2tZzksZYwEGaOHH5kgZip0sBGYimp6M3C1aIbzIDTCyfDkUiamemfr1PHirgKEzbpLskbAS9RuHPQ== X-Google-Smtp-Source: AGHT+IGVO3NcEGidaLDq2N9qwP0HMu/Y8KkRattnbGCuOsUiGihYtn16gtOhgUxZVcB5/KKC74qR X-Received: by 2002:a05:6358:2c89:b0:183:a0ac:b638 with SMTP id l9-20020a0563582c8900b00183a0acb638mr3243236rwm.11.1712760156008; Wed, 10 Apr 2024 07:42:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712760155; cv=pass; d=google.com; s=arc-20160816; b=aAEVLFiNgx2cgVXC4DUAA9T87odtyL0cjUhuw2g5lDbVkC/u20+JOpfNArmjdz0Xsy OTcEQA3UPYZz+UA1RDhS5CD057xrjbT2HqMcIzKiYjZVKIZu57mQUAibmhbI2szkBGak Sh+2rjzZjBRzALd0pfFxEXOk5Buo2KHtJE82I+FR6aW7TsqRHaZWqElkHAVovoTJQoOo zFdqgep2cEjKXEySRZEhhzQg70CH4iLTFrsHJcKBmHmuyrqdES4qjXPfhnyAaaT7O20Q VCHSI2T/KWPu6BMBjZM0nLE3uR30ZMU6bxpY+OpHG9EZKhZqgTEtRRp+ysrGUdNCaudk wDgw== 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=wObD8zXh9fI3SG/H+pZZoJlfw14IqjpYDMmvtigX7IA=; fh=VCdyVZCUh9R8dltaA9/RWs/hxQzWhc63WX0fta2PQtE=; b=h2gy7yLspJf0y/JNWISsUv3kTqC05NoyRL11yvk1KcweJvokZeGzJtM+Kj8iPuf2Tq v7QvVr5SbaX1HsZb2vfA/L1n9eeBKdy4l3+xn9MnrXe02rsWMYqdD4RCh7ZjLb8VxoOy 9O4RlYSdEZUZDIiDAlUdTikYTfut2jtNhPQF8Uvy8S0KRel8HAMxMh3Eok2b4FD8Xmau wCda8K3Zdsin5r0a/ePVBDqr9gyly1UVpSMPuvCK//isTEvHa7e1VCLVO6rNC1j5OGZ6 ESgQPAXdB5iFYv+UbHPAwEZGFFMzvOPd8LG0Pazrc4wPskpWtKT3PBsuMPKy2Wkbhvhv qLlA==; 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-1978-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1978-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id r2-20020a632b02000000b005dc15e82c4fsi10937164pgr.170.2024.04.10.07.42.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 07:42:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1978-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-1978-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1978-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 A8DA7282AAB for ; Wed, 10 Apr 2024 14:42:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C74FF178CED; Wed, 10 Apr 2024 14:38:36 +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 D7882171E42; Wed, 10 Apr 2024 14:38:33 +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=1712759916; cv=none; b=h5KmKejbVzsw8mcrazVuX/I9DB1k0EjMIdbSDkadY2gmbLoyLsY7h4i2PReYw4ZHc5AorTtizdCi/yivgU6M6SQ+RNKfEGbrQBKKR5ZGmHegrWbUwn1kSbVysPLcQGNSsxAt+QIZqqkpG4baylcZAGW2OtbjTIC6JtTbZWzQaIo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712759916; c=relaxed/simple; bh=NOyElOQaf27dJq/f3VnEzoSkQgo67chGcw7cpfTgSv8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ar364Lf+0XV1athUKL31kyS4LwLaiKA1ILndse5xvOvhsGUkN7+QohkVl5lzXrtt/iHjKlyuIiWsjmwIbZZl9HRNbN+BJguBm/VCA9b1FfWTkR5QPHnlyrXy5jD8GWiqpwwmMX5WUsAIPwsrxm6DoEo6f239yLBfzzF5ngvKFcE= 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.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56P0L9wz4f3m74; Wed, 10 Apr 2024 22:38:21 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id AB9EF1A0572; Wed, 10 Apr 2024 22:38:29 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S10; Wed, 10 Apr 2024 22:38:29 +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 06/34] ext4: make ext4_da_reserve_space() reserve multi-clusters Date: Wed, 10 Apr 2024 22:29:20 +0800 Message-Id: <20240410142948.2817554-7-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--.63000S10 X-Coremail-Antispam: 1UD129KBjvJXoWxXF1fZr4DXF48uFWrAr4kCrg_yoWrXF1xpF s8AF43WryIv34kWFWxZr4DZF1S9a4SqFWUta93WFyxXry5J3WSgF1UKF1YvF1rKrWkCw4q qa45u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: d1lo6xhdqjqx5xdzvxpfor3voofrz/ From: Zhang Yi Add 'nr_resv' parameter to ext4_da_reserve_space(), which indicates the number of clusters wants to reserve, make it reserve multi-clusters once a time. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 18 +++++++++--------- include/trace/events/ext4.h | 10 ++++++---- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index d37233e2ed0b..1180a9eb4362 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1479,9 +1479,9 @@ static int ext4_journalled_write_end(struct file *file, } /* - * Reserve space for a single cluster + * Reserve space for 'nr_resv' clusters */ -static int ext4_da_reserve_space(struct inode *inode) +static int ext4_da_reserve_space(struct inode *inode, int nr_resv) { struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); struct ext4_inode_info *ei = EXT4_I(inode); @@ -1492,18 +1492,18 @@ static int ext4_da_reserve_space(struct inode *inode) * us from metadata over-estimation, though we may go over by * a small amount in the end. Here we just reserve for data. */ - ret = dquot_reserve_block(inode, EXT4_C2B(sbi, 1)); + ret = dquot_reserve_block(inode, EXT4_C2B(sbi, nr_resv)); if (ret) return ret; spin_lock(&ei->i_block_reservation_lock); - if (ext4_claim_free_clusters(sbi, 1, 0)) { + if (ext4_claim_free_clusters(sbi, nr_resv, 0)) { spin_unlock(&ei->i_block_reservation_lock); - dquot_release_reservation_block(inode, EXT4_C2B(sbi, 1)); + dquot_release_reservation_block(inode, EXT4_C2B(sbi, nr_resv)); return -ENOSPC; } - ei->i_reserved_data_blocks++; - trace_ext4_da_reserve_space(inode); + ei->i_reserved_data_blocks += nr_resv; + trace_ext4_da_reserve_space(inode, nr_resv); spin_unlock(&ei->i_block_reservation_lock); return 0; /* success */ @@ -1678,7 +1678,7 @@ 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); + ret = ext4_da_reserve_space(inode, 1); if (ret != 0) /* ENOSPC */ return ret; } else { /* bigalloc */ @@ -1690,7 +1690,7 @@ static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk) if (ret < 0) return ret; if (ret == 0) { - ret = ext4_da_reserve_space(inode); + ret = ext4_da_reserve_space(inode, 1); if (ret != 0) /* ENOSPC */ return ret; } else { diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h index 6b41ac61310f..cc5e9b7b2b44 100644 --- a/include/trace/events/ext4.h +++ b/include/trace/events/ext4.h @@ -1246,14 +1246,15 @@ TRACE_EVENT(ext4_da_update_reserve_space, ); TRACE_EVENT(ext4_da_reserve_space, - TP_PROTO(struct inode *inode), + TP_PROTO(struct inode *inode, int nr_resv), - TP_ARGS(inode), + TP_ARGS(inode, nr_resv), TP_STRUCT__entry( __field( dev_t, dev ) __field( ino_t, ino ) __field( __u64, i_blocks ) + __field( int, reserve_blocks ) __field( int, reserved_data_blocks ) __field( __u16, mode ) ), @@ -1262,16 +1263,17 @@ TRACE_EVENT(ext4_da_reserve_space, __entry->dev = inode->i_sb->s_dev; __entry->ino = inode->i_ino; __entry->i_blocks = inode->i_blocks; + __entry->reserve_blocks = nr_resv; __entry->reserved_data_blocks = EXT4_I(inode)->i_reserved_data_blocks; __entry->mode = inode->i_mode; ), - TP_printk("dev %d,%d ino %lu mode 0%o i_blocks %llu " + TP_printk("dev %d,%d ino %lu mode 0%o i_blocks %llu reserve_blocks %d" "reserved_data_blocks %d", MAJOR(__entry->dev), MINOR(__entry->dev), (unsigned long) __entry->ino, __entry->mode, __entry->i_blocks, - __entry->reserved_data_blocks) + __entry->reserve_blocks, __entry->reserved_data_blocks) ); TRACE_EVENT(ext4_da_release_space, -- 2.39.2