Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp92241rdf; Mon, 20 Nov 2023 17:40:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IEKq/gZA3Xz5lLgzTMJzVq9yJlkfoCzmjwkp4pIhB/jFELhH73yoc/nNssqE1ySRdDvMnEt X-Received: by 2002:a05:6808:1496:b0:3a7:1b28:4bc9 with SMTP id e22-20020a056808149600b003a71b284bc9mr10581901oiw.54.1700530856834; Mon, 20 Nov 2023 17:40:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700530856; cv=none; d=google.com; s=arc-20160816; b=xl+aDoceEpg1Mhp4dnA9l6dZJi40yrszAmogQQ50U0xcxqaBuYhkRADpRaAL+3ooTd n19NizMYnZP/BTBx4kj0whIeVNw2f0eXg49H7Id34mu6sZjZs7nfHy0/eMzZTKDEYvsm 8WiqpBbfSV9ANsuO3fEMEiB9rWGFN2Cl+GwToHmIetWgC9vTs7edO3Ih2ZX9YI4IQQyX qmf+hD2ItSaF0J1xfixAJYRyoy2v77f7GTzVzjOjI8d70dYmArOMsbouauP35OXXF/tG w1Sa+TqbT+5xRCxP1kUZdUudIj3pYcP+jgqB6ahlEd+ii+88eEzqVNDKTaNYQyxiG5pH fEGw== ARC-Message-Signature: i=1; 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=vUufWmmR8b+so9WB454M/oiT6IS/Dh6y/jek+FjKyTM=; fh=ylVtUZsu3PtLHiaG6y99VSwNbo3RGBZUz36usYvDI6k=; b=RdHwI2WqnqCQ04UpI9jtTwTbcNsMpLZ+VUZI7B+8Oqew7Dd8qz6VAwojlciTEI8XyB tJW9h6mU/L9Ru0oekHptMJ7n3AsdQAqt+9T9MGcdFly8YwTKm2jWIKcIltxB7o3b5y1n S5q9M2g7yyXoT53QMN1MvJT8kxZ8tSS57s3m0j2oqE/YDLB9OavOp93ojjblyz33tAN6 pvLA+wWpjBu5AhyfeOvA9HkJLGh/hz3tx/8kbugpdyYru1EXpQuLKIn7BTcEfay//Ehr 58Co0ftrVVhiQnxlVpke4Jkl4nFPxXdIB9wz5i5QxFvhQc1l9UIEJxj7ch3w3eIO04Yr asaw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-52-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-52-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bx10-20020a056a02050a00b005acf4298a78si10501244pgb.149.2023.11.20.17.40.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:40:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-52-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-52-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-52-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 42C97282307 for ; Tue, 21 Nov 2023 01:40:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E9B511188; Tue, 21 Nov 2023 01:40:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=none X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 503B8CC for ; Mon, 20 Nov 2023 17:40:42 -0800 (PST) Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4SZ6X50CC9z4f3k6J for ; Tue, 21 Nov 2023 09:40:37 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id AC90F1A0637 for ; Tue, 21 Nov 2023 09:40:39 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgA3iA6MClxlGMf4BQ--.64879S8; Tue, 21 Nov 2023 09:40:39 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: 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: [RFC PATCH 4/6] ext4: add a hole extent entry in cache after punch Date: Tue, 21 Nov 2023 17:34:27 +0800 Message-Id: <20231121093429.1827390-5-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231121093429.1827390-1-yi.zhang@huaweicloud.com> References: <20231121093429.1827390-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:cCh0CgA3iA6MClxlGMf4BQ--.64879S8 X-Coremail-Antispam: 1UD129KBjvJXoW7CF4fWF47JF1xAr1rGr1UGFg_yoW8tr17pa sxAFy8Gr45W34q93yIgF4UZr12ya47G3yUXrWfKw10gry8Xr10yF1UtF13ZFy5tFW8Ja1Y vF4UKryUXa13ArJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2jI8I6cxK62vIxIIY0VWUZVW8XwA2048vs2IY02 0E87I2jVAFwI0_JF0E3s1l82xGYIkIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0 rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6x IIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xv wVC2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFc xC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_ Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2 IErcIFxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r 4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0pRHa0PU UUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ From: Zhang Yi In order to cache hole extents in the extent status tree and keep the hole continuity as much as possible, add a hole entry to the cache after punching a hole. It can reduce the 'hole' in some continuous hole extent entries. Signed-off-by: Zhang Yi --- fs/ext4/ext4.h | 3 +++ fs/ext4/extents.c | 5 ++--- fs/ext4/inode.c | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 9418359b1d9d..c2ca28c6ec38 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3681,6 +3681,9 @@ extern int ext4_convert_unwritten_io_end_vec(handle_t *handle, ext4_io_end_t *io_end); extern int ext4_map_blocks(handle_t *handle, struct inode *inode, struct ext4_map_blocks *map, int flags); +extern void ext4_ext_put_gap_in_cache(struct inode *inode, + ext4_lblk_t hole_start, + ext4_lblk_t hole_len); extern int ext4_ext_calc_credits_for_single_extent(struct inode *inode, int num, struct ext4_ext_path *path); diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 202c76996b62..52bad225e3c8 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -2275,9 +2275,8 @@ static ext4_lblk_t ext4_ext_determine_hole(struct inode *inode, * calculate boundaries of the gap that the requested block fits into * and cache this gap */ -static void -ext4_ext_put_gap_in_cache(struct inode *inode, ext4_lblk_t hole_start, - ext4_lblk_t hole_len) +void ext4_ext_put_gap_in_cache(struct inode *inode, ext4_lblk_t hole_start, + ext4_lblk_t hole_len) { struct extent_status es; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 94e7b8500878..3908ce7f6fb8 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4034,6 +4034,8 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length) ret = ext4_ind_remove_space(handle, inode, first_block, stop_block); + ext4_ext_put_gap_in_cache(inode, first_block, + stop_block - first_block); up_write(&EXT4_I(inode)->i_data_sem); } ext4_fc_track_range(handle, inode, first_block, stop_block); -- 2.39.2