Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp310501rdh; Thu, 23 Nov 2023 04:52:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IHRYl7IcvLoEqSwPKl/qtV7VISzrD6XvD9X7nIL7S6omPPTOKNCvuJzqgSYmWCNG4svrsbN X-Received: by 2002:a05:620a:1aaa:b0:777:3bd:9774 with SMTP id bl42-20020a05620a1aaa00b0077703bd9774mr6823811qkb.27.1700743939540; Thu, 23 Nov 2023 04:52:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700743939; cv=none; d=google.com; s=arc-20160816; b=c3E0uzL4/wIm5mPXDJ3hi7hrOixuBU5qGXi8J3Mhxi0DP6O1cMh4pFddlREsrukJ3k /cBxTDZbn4CFGB4Wfe0RsJ+mcgU/qgSalG9EJ/EA5xrtpk45p6oPCqLhgCKb5ZMe+2bW pvlwhHtuFyvYMoQC6QN80P+/rJYSrMzzx7j5cU8uo4+5s55tvAAj75VnsD+IHjfy/vPc w2hXq0UEYmWMVrvrADckq3Ut6qgDAV70CV0UIdr6WEHdXoHJkfKOec54PTvdb/6o1kyt QgEwVuCwkUY2N1mqFHUiXjqW9ujF2IuAsuYfPNZ23zZig1bM9R+fSLd5n4V4p2HyaW5d RFJQ== 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=IrWGbicuvIxBGx2RkVt80jbKVUOYzo37tC26KuGxEtY=; fh=oXgJbFeK1mY0T4jBbK/Fs3Mi9F4SdMRqpoziDljuAF4=; b=VzEJzQFtabR92hZme9HytbK24vbmej8PghzOAESYOsbPUO2qpe1OUu/BgIdXDTHvWU +VF3SzENyNNk0VfnDcAYYfJySfD+G36W2lOYDZ38dK1RHhm6MhqTbqECKaNMPeXuBua0 gySEt4P2lx2/7TU+h/eQCR6vplh9bMCRvwkuB3gl0bUTb3i5Ex4pFkwtRu3JEEy/GdGi fs7pbIMKKYRQZfbyy1bjZw5qVSBID2LKy1eZAnxog5FLgAw6CBXWMOjMYyn7rq4oJLdK e37x/lBT7oTNM4VT7vTzH5NbWD7yJFv6MzqLYydz3rhgKHCSh0WGJWMEQIXP25BPZGen n59Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-106-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-106-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g1-20020a05620a40c100b0076ef653ac9fsi1126577qko.127.2023.11.23.04.52.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 04:52:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-106-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-106-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-106-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 2AC861C21052 for ; Thu, 23 Nov 2023 12:52:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 292B824B3D; Thu, 23 Nov 2023 12:52:09 +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 554D8D40; Thu, 23 Nov 2023 04:52:03 -0800 (PST) Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4SbdKn2rYdz4f3kKH; Thu, 23 Nov 2023 20:51:57 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 244F31A03BD; Thu, 23 Nov 2023 20:52:00 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgDn6xHdSl9lSfnfBg--.20473S5; Thu, 23 Nov 2023 20:51:59 +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, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: [RFC PATCH 01/18] ext4: introduce ext4_es_skip_hole_extent() to skip hole extents Date: Thu, 23 Nov 2023 20:51:03 +0800 Message-Id: <20231123125121.4064694-2-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231123125121.4064694-1-yi.zhang@huaweicloud.com> References: <20231123125121.4064694-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:cCh0CgDn6xHdSl9lSfnfBg--.20473S5 X-Coremail-Antispam: 1UD129KBjvJXoWxXF15ZFykZFyUurWfCF13XFb_yoWrJrWfpF 9xZ345K3yrWwsF9ayfGw17Xr1Yqa48CrW7Jr9xKr1rK3WIqr9akF1UtFy2vF9YqrW8tr1Y qFW0k34DGa12ga7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBE14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMI IF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JU4T5dUUUUU = X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ From: Zhang Yi Introduce a new helper ext4_es_skip_hole_extent() to skip all hole extents in a search range, return the valid lblk of next not hole extent entry. It's useful to estimate and limit the length of a potential hole returned when querying mapping status in ext4_map_blocks(). Signed-off-by: Zhang Yi --- fs/ext4/extents_status.c | 32 ++++++++++++++++++++++++++++++++ fs/ext4/extents_status.h | 2 ++ include/trace/events/ext4.h | 28 ++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 6f7de14c0fa8..1b1b1a8848a8 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -944,6 +944,38 @@ void ext4_es_cache_extent(struct inode *inode, ext4_lblk_t lblk, write_unlock(&EXT4_I(inode)->i_es_lock); } +/* + * ext4_es_skip_hole_extent() skip hole extents and loops up the next + * delayed/unwritten/mapped extent in extent status tree from lblk to + * end. + */ +ext4_lblk_t ext4_es_skip_hole_extent(struct inode *inode, ext4_lblk_t lblk, + ext4_lblk_t len) +{ + struct extent_status *es = NULL; + ext4_lblk_t next_lblk; + struct rb_node *node; + + read_lock(&EXT4_I(inode)->i_es_lock); + es = __es_tree_search(&EXT4_I(inode)->i_es_tree.root, lblk); + + while (es && es->es_lblk < lblk + len) { + if (!ext4_es_is_hole(es)) + break; + node = rb_next(&es->rb_node); + es = rb_entry(node, struct extent_status, rb_node); + } + if (!es || es->es_lblk >= lblk + len) + next_lblk = lblk + len; + else + next_lblk = es->es_lblk; + + trace_ext4_es_skip_hole_extent(inode, lblk, len, next_lblk); + read_unlock(&EXT4_I(inode)->i_es_lock); + + return next_lblk; +} + /* * ext4_es_lookup_extent() looks up an extent in extent status tree. * diff --git a/fs/ext4/extents_status.h b/fs/ext4/extents_status.h index d9847a4a25db..4f69322dd626 100644 --- a/fs/ext4/extents_status.h +++ b/fs/ext4/extents_status.h @@ -139,6 +139,8 @@ extern void ext4_es_find_extent_range(struct inode *inode, int (*match_fn)(struct extent_status *es), ext4_lblk_t lblk, ext4_lblk_t end, struct extent_status *es); +ext4_lblk_t ext4_es_skip_hole_extent(struct inode *inode, ext4_lblk_t lblk, + ext4_lblk_t len); extern int ext4_es_lookup_extent(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t *next_lblk, struct extent_status *es); diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h index 65029dfb92fb..84421cecec0b 100644 --- a/include/trace/events/ext4.h +++ b/include/trace/events/ext4.h @@ -2291,6 +2291,34 @@ TRACE_EVENT(ext4_es_find_extent_range_exit, __entry->pblk, show_extent_status(__entry->status)) ); +TRACE_EVENT(ext4_es_skip_hole_extent, + TP_PROTO(struct inode *inode, ext4_lblk_t lblk, + ext4_lblk_t len, ext4_lblk_t next_lblk), + + TP_ARGS(inode, lblk, len, next_lblk), + + TP_STRUCT__entry( + __field( dev_t, dev ) + __field( ino_t, ino ) + __field( ext4_lblk_t, lblk ) + __field( ext4_lblk_t, len ) + __field( ext4_lblk_t, next ) + ), + + TP_fast_assign( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->lblk = lblk; + __entry->len = len; + __entry->next = next_lblk; + ), + + TP_printk("dev %d,%d ino %lu [%u/%u) next_lblk %u", + MAJOR(__entry->dev), MINOR(__entry->dev), + (unsigned long) __entry->ino, __entry->lblk, + __entry->len, __entry->next) +); + TRACE_EVENT(ext4_es_lookup_extent_enter, TP_PROTO(struct inode *inode, ext4_lblk_t lblk), -- 2.39.2