From patchwork Wed Apr 10 13:27:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624540 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02C09CD129A for ; Wed, 10 Apr 2024 13:37:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7D2C56B0095; Wed, 10 Apr 2024 09:36:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 780946B0096; Wed, 10 Apr 2024 09:36:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 648EB6B0098; Wed, 10 Apr 2024 09:36:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 3C5466B0096 for ; Wed, 10 Apr 2024 09:36:59 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E7EBB140654 for ; Wed, 10 Apr 2024 13:36:58 +0000 (UTC) X-FDA: 81993722916.28.3DB3FB3 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by imf27.hostedemail.com (Postfix) with ESMTP id 6F14B40008 for ; Wed, 10 Apr 2024 13:36:56 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756217; a=rsa-sha256; cv=none; b=4tNiNc4YQiBY0Lh+67P67iielmG7ENoYCilEshmqv+y1kYMjr7YIgDWSa6uMVQkH+gCHps FYEAXqktMPh+z3fes0DoEo6uuxDIYVykB4vrJtknYae8WpjsbHST0RGP1AV69AHNdUtaNL WDed7TREcsxASsrWTBr2BDQSKuYkU4Q= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712756217; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wObD8zXh9fI3SG/H+pZZoJlfw14IqjpYDMmvtigX7IA=; b=esgEfyHo84+rLpEGi4dxG8EAOaxEHbTtwHK9si/kuunTNRuP9M1LfG+cVu+wyXS0xdV/uM KLhogOVryGZVDNVT8NmilVfop7AVvbwBhJZ624xMoEukfg2ZeKaai+joG79ebzDgvGInT1 UytO/PuFTXP5a732baoRXwGuSukehEA= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF3lJ5xG4z4f3jHf for ; Wed, 10 Apr 2024 21:36:44 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id A8FE81A0D6B for ; Wed, 10 Apr 2024 21:36:51 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S10; Wed, 10 Apr 2024 21:36:51 +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, 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 21:27:50 +0800 Message-Id: <20240410132818.2812377-7-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S10 X-Coremail-Antispam: 1UD129KBjvJXoWxXF1fZr4DXF48uFWrAr4kCrg_yoWrXF1xpF s8AF43WryIv34kWFWxZr4DZF1S9a4SqFWUta93WFyxXry5J3WSgF1UKF1YvF1rKrWkCw4q qa45u348u3WjgFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUA rcfUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6F14B40008 X-Stat-Signature: cgcuw6tz33thdqm1equetjy48u13w6gs X-HE-Tag: 1712756216-48298 X-HE-Meta: U2FsdGVkX1/wvsdf/4bD6zN0ejxBTo/mDy+IgsZ/hk5RzwU4hzg46RePd2aSYZsGcey0DO4k+4lpS9jb1PxAiCZjxpv604e0i+hxCW4zuAt3+xuDVUw1c68TDNcx3x1owPOHFJUfOVw8GbiVFOeNlcXhNJs1eKexequp2qoHesm/K3rzVZkw4ERMbAxrwqqCJr5Aq9U7l6SCcEA1TcA9IkjTjzQ0Cf25d9Fj7HOF/b0gglBBjgYeHl+C8+w3duZXj9MWHUhBL/REJr7HI+r5vefFUcKx4Y7DplTWXYEQOwP8KwWina+xvyuFia1x5O+F/JOKWOyiegh4zxs5cfJiLQxEQQ3xnv1tA+/4/WFdZSEheHzt+cNtrYo/ESmGNlBhvtnSlAAbixB9YG6Wfr0cX8Ric8wNyfODcyGUXzpbaBHYPhwHWCayHi+R5lYrLGpkkzUfNKRd2q77wVwbnlh9yIF9/pVNau+O3k/jpQa32Lu9bpiyaMcx/DenoKE+eQ3HYUuqH8wi4xgVpZ8X+rMROshv+WViuLKIn5UJvcdKWo8TGTObuax/Tf7IfWZnokCAV6kWNqXMIk0O2k94R4b4OQNNzfZZTf+2jnbIwLCZgkw+Gqg8xNQJORP9LGSy7WFoobohaGBE5GqKeH2u2VKM5XkqEH/tGiHee+Rgvu106TIQthWqdfzQq1yhYiHFXYQagpL/0Nhl9EG0Pnh0walBwENw58n8a0GRrqFmkyZ2Z+q9CZ7ywHDKhwqt//5fXtoY+/3uKMivql8wPlnCerweXHXYJU+0VDa362+Q4j5GFXJFJ5SuC4cQHC37it4do84lDG7Pmmp+3SIst5VCQp+E4bXQpsUdWkLW5vUanZRY+qnphmDwa3k84txc0PCXw2Y+MdZf+Xbnwjf82n5uu2jI2xE4X8dWMvLOSAkR1diBwhX7HkPwsz+NGamAUYfbf0L4LnJD42tkyCIaxv+gczu EB9WcLfv i024Vf19XRU76l//MiD7vzD/BU0oE2VVz8tl+/kjsq+3PiKG1ZY0f3zeK+gst7XK9K1kiTKP2iRmOLoxYFReE8MQdYLHY3GvVSETWEDZoxj8WAcivl8Ux4pKlMvnOP9LK8vC1BaO0niaPIACRiwl3BkR9/nBdbqTuK1Ql614ZPEznY4ksW0Kjo08FsK2CtzZ1sJ5VT3IJ/6w1HSGaf2ufkTBFkbTYPJnuljGKMh5HmxyI3AucLj0Zu36+DUIjT9V+OgCq X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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,