Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6512305rdb; Tue, 2 Jan 2024 04:43:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IEPu6JbXTgIuhFeWQonuLjIy8OWC+eowHdGdanL9LNGFzQPsOhC1Rh+rYT+l/0XlkYGyAJP X-Received: by 2002:a05:6358:340b:b0:174:ddea:296d with SMTP id h11-20020a056358340b00b00174ddea296dmr15660896rwd.59.1704199384301; Tue, 02 Jan 2024 04:43:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704199384; cv=none; d=google.com; s=arc-20160816; b=N2X654Orxeett1yUZjh/XrqwbeQ8qu/7okQF6ZyOW1pmtKP4FRjSZC+veYXx3flLqE 1piNkBC223S2xRmZWKbSESDXsL7Ww+e7Nf5UeAAow17bOdPOxDDPlcHxz4yNRQdf1yp7 xg4lDxQu88RheYxt9yXZrR6rQTqrQ6e1/agLURfgu7ahldv/vyS2FvUsozUaUoVwRxDl UF7e8Txz0GvJ/8F2BgHAZ0dNaEocOwCHaTkIkJ+R9Sydv+XXtASxCE94kToVrLTb2M5M QS89jpRBIwwm9OK55zUWGmh8+NxnE3lKonKJIaQQ0NX5K8WoZLPFCrqzSGuqCTbx0Tcm dIdQ== 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=BIlKBpX/fh6KTLPsFEW+BnZmAWGaAK0RBIHKE1F3Fkk=; fh=yWWoL3IRufgA/+2kSpO6uyfw9eN3ZOO7zvul0qbDPkA=; b=yUoM9bzeUQgV1un2Z6lV2WutqD0HiknVyKhCW4Y0rIKuOk/ZmYpWW5DtWqmm3nJ9JH jEmExo3TrKXnzY2fXH5ksvkobup12H0tQSor/HkKAJRGIXqIV4VJyoYJtuqj4eYYufL6 2QL/LikaPuWCnZySgyEjHVB8pUBpWuVLfwJVkElEbo2BajmMNV/5yL3tE6lyDEBskMwG IBZCSdSstTyad8LUS4LIgOQ4foRhEO168Ac9LkLnFdZrlmoniWxCUiH6nPuiCGv/9NvC KpDyY/b/SfsnTs52OsowUcnOpmBNpJeR1cKjVdIf+rrRjxJ0iN3fOPEWfLnT7PaIUZQh X0aA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-598-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-ext4+bounces-598-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 y191-20020a638ac8000000b005cdf9bd6af5si17750185pgd.894.2024.01.02.04.43.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 04:43:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-598-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; spf=pass (google.com: domain of linux-ext4+bounces-598-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-ext4+bounces-598-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 C3ADD28334B for ; Tue, 2 Jan 2024 12:43:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DBA8211189; Tue, 2 Jan 2024 12:42:12 +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 E03FEF9C3; Tue, 2 Jan 2024 12:42:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4T4CCx64k8z4f3l8F; Tue, 2 Jan 2024 20:42:05 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 8E7AD1A017F; Tue, 2 Jan 2024 20:42:07 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgBnwUGUBJRl+EvDFQ--.31823S8; Tue, 02 Jan 2024 20:42:07 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@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, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v2 04/25] ext4: add a hole extent entry in cache after punch Date: Tue, 2 Jan 2024 20:38:57 +0800 Message-Id: <20240102123918.799062-5-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240102123918.799062-1-yi.zhang@huaweicloud.com> References: <20240102123918.799062-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:gCh0CgBnwUGUBJRl+EvDFQ--.31823S8 X-Coremail-Antispam: 1UD129KBjvJXoW7Ar1kWr18u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derInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ From: Zhang Yi In order to cache hole extents in the extent status tree and keep the hole length as long as possible, re-add a hole entry to the cache just after punching a hole. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 142c67f5c7fc..1b5e6409f958 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4000,12 +4000,12 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length) /* If there are blocks to remove, do it */ if (stop_block > first_block) { + ext4_lblk_t hole_len = stop_block - first_block; down_write(&EXT4_I(inode)->i_data_sem); ext4_discard_preallocations(inode, 0); - ext4_es_remove_extent(inode, first_block, - stop_block - first_block); + ext4_es_remove_extent(inode, first_block, hole_len); if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) ret = ext4_ext_remove_space(inode, first_block, @@ -4014,6 +4014,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_es_insert_extent(inode, first_block, hole_len, ~0, + EXTENT_STATUS_HOLE); up_write(&EXT4_I(inode)->i_data_sem); } ext4_fc_track_range(handle, inode, first_block, stop_block); -- 2.39.2