Received: by 2002:a05:7412:9c07:b0:fa:6e18:a558 with SMTP id lr7csp42770rdb; Fri, 26 Jan 2024 18:03:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IG77ZdI0IOjA2mzzicBHIRQI7AAZW/AxYPCEUb6vsV1Z4CUE+cPSddlvQxDTa6E1gX/VODv X-Received: by 2002:aa7:84d3:0:b0:6dd:8707:7f99 with SMTP id x19-20020aa784d3000000b006dd87077f99mr586684pfn.62.1706321032124; Fri, 26 Jan 2024 18:03:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706321032; cv=pass; d=google.com; s=arc-20160816; b=ZUhno9ZFEI4rmQ2VFIl9q4oCNS4lVA/u07vwrjpi5tFRi5+26+w6O7FceiwmHS0s1V iNtFQGTyEHylfMF30tI7d3vddiTvgKnOIQNpy/Ww2ZkZjC6Oqzwj6RPLxXEH3PHp3fTs pezL1p1dELjgBDr+SkM+Wd5GbyrTxb3LVsa9s52/sRioHXsoN9rI+VtGHYGON1VidxfW Y7xA2Ah+v3+vVKwZhBCkNqvn/8fRE372OMr4tUwoUbEKdbVobUx2w8POHKY9JxxyBJdG fjv5bXWvmkQFtZ9E9iZLXzfYuJFKgccF5RTaxVeAfFxu0oFL+pb1CModUhWErU4XccRn vDSA== 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=kATHz1/ug5teIHGhsTsvlMF8lutPolqn5X3kiv7q1y0=; fh=UhGiR19HeAIu8tzXykjZgtAKLLMPZj8YX6gPScUOsdE=; b=V3xA61TZCPcxTkdEjD92aXfaiistpG5zI8Uv+CRVQAainB8kdIlhaYKi086LoqJvEH lDZFA2qG9avF0xoB0pzavWFhce9j55dw5yqdihNuMR57ln8e7BCZH1fCZEQaAe7g3NsI SWHJs7RH0fKaUJfK8R886mcCL9u25z6moBE5p+sBkAiftq9h3wOrbVAhhMGqdx/nJOzX CL/ZbM0LCWMKSiVJR5XyYh7fuetZP9DHPmq4RmPQzSofHLQUIk9AWsfTbidUkZE+ULa5 UBZTktl86xTPRJDsl2K9VDyjE4BtwenrlTTgcgRUz/rMPUs3katn6KvRrLNCKlWE0I5T hugw== 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-952-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-ext4+bounces-952-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 c190-20020a6335c7000000b005cf0abea01dsi2006605pga.114.2024.01.26.18.03.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 18:03:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-952-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-952-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-ext4+bounces-952-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 BF8D9281B39 for ; Sat, 27 Jan 2024 02:03:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EF943125B1; Sat, 27 Jan 2024 02:02:46 +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 DF155B667; Sat, 27 Jan 2024 02:02:44 +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=1706320966; cv=none; b=k5TZDfJh+IPinqRNrw8brd31xlgYHfFpHXptna/MLrOfeJTvPy9VhjdOJpMG2hrHTnWErRGcbtsB6OA3lorAyMXQysBtNj/3feElsMhaEsRZVBvRTAMJkndDXWdfKEVdwjKZzV1B/nbgFsD9btnjfw2rbJQHKVqR7uuXiu/ZslI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706320966; c=relaxed/simple; bh=nPDYbHs+OSPKxzaNckg7q40LQCTLFcfnwX0CWyP10T8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AZ6vW2lSnA6COgcxVbU9lUOweq6smYPmg1VrpZTNGHKAmnCHVgayE3W68nT6Y8eSw+7U7e/XLyFGOA47caZWPopSlzPnK8Q3Ct3nhRuBvA60s2IS8U/sv4kPB/sSV1uQX2x8Aq0gmTaYqWvfVnrCZmcqUfaU6pgb2J6hW0SCdCU= 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.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrW4q2Mz4f3lfV; Sat, 27 Jan 2024 10:02:35 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 0A40C1A016E; Sat, 27 Jan 2024 10:02:42 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S8; Sat, 27 Jan 2024 10:02:41 +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 v3 04/26] ext4: add a hole extent entry in cache after punch Date: Sat, 27 Jan 2024 09:58:03 +0800 Message-Id: <20240127015825.1608160-5-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-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:cCh0CgAX5g40ZLRlGJtmCA--.7377S8 X-Coremail-Antispam: 1UD129KBjvJXoW7Ar1kWr15Gr1DXFyrGw4Durg_yoW8Xr4Dp3 98Ca4Sgr1kW34kuan7XFWUXr1293WUGw4UXrW29w1xWFyUA3WI9Fn09F43Z3W8KrW7Xw4F qF48KryY9w1Uu3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPF14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJV W8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUoxhL UUUUU X-CM-SenderInfo: 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 Reviewed-by: Jan Kara --- 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