From patchwork Thu Aug 24 09:26:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 1825264 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=gandalf.ozlabs.org; envelope-from=srs0=4ho7=ej=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RWdBX43Qhz26jP for ; Thu, 24 Aug 2023 19:31:32 +1000 (AEST) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4RWdBT3sQSz4wZn for ; Thu, 24 Aug 2023 19:31:29 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4RWdBT3p0rz4wxK; Thu, 24 Aug 2023 19:31:29 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=ozlabs.org) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4RWdBT2Xh8z4wZn for ; Thu, 24 Aug 2023 19:31:29 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240347AbjHXJbA (ORCPT ); Thu, 24 Aug 2023 05:31:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240784AbjHXJas (ORCPT ); Thu, 24 Aug 2023 05:30:48 -0400 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0364519A0 for ; Thu, 24 Aug 2023 02:30:45 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.169]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4RWd9W68pXz4f3lK3 for ; Thu, 24 Aug 2023 17:30:39 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgAHl6kzI+dkL1rbBQ--.46575S11; Thu, 24 Aug 2023 17:30:43 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: [RFC PATCH 07/16] ext4: count inode's total delalloc data blocks into ext4_es_tree Date: Thu, 24 Aug 2023 17:26:10 +0800 Message-Id: <20230824092619.1327976-8-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230824092619.1327976-1-yi.zhang@huaweicloud.com> References: <20230824092619.1327976-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgAHl6kzI+dkL1rbBQ--.46575S11 X-Coremail-Antispam: 1UD129KBjvJXoWxXrWDWrW7JrWkGr1rKw47twb_yoW5Gw13pa s3A3WUGr4fXw1kWayxXr4UZr1fta48Gay7GrWftr1IkFyUAryftF10yFWjvFyYqrW8Jw45 XF48tw1UGa13KaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9C14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j6r xdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxAIw28IcxkI7VAKI48JMx C20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAF wI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20x vE14v26r1I6r4UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF04k26cxK x2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI 0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUQSdkUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,MAY_BE_FORGED, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Zhang Yi Add a parameter in struct ext4_es_tree to count per-inode's total delalloc data blocks number, it will be used to calculate reserved meta blocks when creating a new delalloc extent entry, or mapping a delalloc entry to a real one or releasing a delalloc entry. Signed-off-by: Zhang Yi --- fs/ext4/extents_status.c | 19 +++++++++++++++++++ fs/ext4/extents_status.h | 1 + 2 files changed, 20 insertions(+) diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 34164c2827f2..b098c3316189 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -178,6 +178,7 @@ void ext4_es_init_tree(struct ext4_es_tree *tree) { tree->root = RB_ROOT; tree->cache_es = NULL; + tree->da_es_len = 0; } #ifdef ES_DEBUG__ @@ -787,6 +788,20 @@ static inline void ext4_es_insert_extent_check(struct inode *inode, } #endif +/* + * Update total delay allocated extent length. + */ +static inline void ext4_es_update_da_block(struct inode *inode, long es_len) +{ + struct ext4_es_tree *tree = &EXT4_I(inode)->i_es_tree; + + if (!es_len) + return; + + tree->da_es_len += es_len; + es_debug("update da blocks %ld, to %u\n", es_len, tree->da_es_len); +} + static int __es_insert_extent(struct inode *inode, struct extent_status *newes, struct extent_status *prealloc) { @@ -915,6 +930,7 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, __es_free_extent(es1); es1 = NULL; } + ext4_es_update_da_block(inode, -rinfo.ndelonly_blk); err2 = __es_insert_extent(inode, &newes, es2); if (err2 == -ENOMEM && !ext4_es_must_keep(&newes)) @@ -1571,6 +1587,7 @@ void ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk, __es_free_extent(es); es = NULL; } + ext4_es_update_da_block(inode, -rinfo.ndelonly_blk); write_unlock(&EXT4_I(inode)->i_es_lock); if (err) goto retry; @@ -2161,6 +2178,8 @@ void ext4_es_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk, pr = NULL; } } + + ext4_es_update_da_block(inode, newes.es_len); error: write_unlock(&EXT4_I(inode)->i_es_lock); if (err1 || err2 || err3 < 0) diff --git a/fs/ext4/extents_status.h b/fs/ext4/extents_status.h index 7344667eb2cd..ee873b305210 100644 --- a/fs/ext4/extents_status.h +++ b/fs/ext4/extents_status.h @@ -66,6 +66,7 @@ struct extent_status { struct ext4_es_tree { struct rb_root root; struct extent_status *cache_es; /* recently accessed extent */ + ext4_lblk_t da_es_len; /* total delalloc len */ }; struct ext4_es_stats {