From patchwork Wed Apr 10 14:29:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624704 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4D32CD11C2 for ; Wed, 10 Apr 2024 14:39:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 843586B009B; Wed, 10 Apr 2024 10:38:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F3B86B009C; Wed, 10 Apr 2024 10:38:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 695576B009D; Wed, 10 Apr 2024 10:38:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 47ADA6B009B for ; Wed, 10 Apr 2024 10:38:40 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 15FBA1207C3 for ; Wed, 10 Apr 2024 14:38:40 +0000 (UTC) X-FDA: 81993878400.18.FEF269C Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf04.hostedemail.com (Postfix) with ESMTP id AA38E40006 for ; Wed, 10 Apr 2024 14:38:37 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759918; a=rsa-sha256; cv=none; b=JkA1EE9uZ1lKZspJN9Xhj4rTbBDHmdV1N9oB+QMVIriSiK1ntj2TJdh3rDVH6PydLJgW9Y xB1COkfS24ZZnJppWSJu7APAluiwJ2+VOjyjZxSRp2dvBNJ8flno2sMFl9+/4iYlZ7Qfl4 3MYNlv5oU8eEDDgaJ6Hy1wbTzzJp4Vs= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759918; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XmGlqO05uCWAx2h9YEVVAjwERSqwY7O+ms/+oS1z0DE=; b=5P63+hmKHr+2U/LsUwHvfBJ3qWdxvrE3wxZ+lQhwm39hjeqelZ98Q+bIhYT4jNYC7kt9O3 sFCTOPJfAQKJKy+YBsZgWWhewoGmL1p0+bOmJtw+MffE0PcQaUMn3V82cb+YPjTnWrYjrg +2iGUjPo/7NTYc+FXlCtld95U0wBfoo= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56Y5BL6z4f3jkk for ; Wed, 10 Apr 2024 22:38:29 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 267CC1A016E for ; Wed, 10 Apr 2024 22:38:34 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S17; Wed, 10 Apr 2024 22:38:33 +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, david@fromorbit.com, 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: [RFC PATCH v4 13/34] ext4: let __revise_pending() return newly inserted pendings Date: Wed, 10 Apr 2024 22:29:27 +0800 Message-Id: <20240410142948.2817554-14-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S17 X-Coremail-Antispam: 1UD129KBjvJXoWxKFyfXw47WrWkWF15AryrJFb_yoW7GF1xp3 yY9as8CryrXw1jg3yFyF4UZr1Yg3W8JFWDXrZakrySkFyrJFyYkF10yF1avF1rCrWxJw13 XFWjk34Uu3WUKaDanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUHS14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAaw2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I 8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCF s4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFI xGxcIEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2AFwI0_GFv_Wryl42xK82IYc2Ij64vIr41l 4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2IqxVAqx4xG67AKxV WUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MIIYrxkI 7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_tr0E3s1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r 4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4UJVWx Jr1lIxAIcVC2z280aVCY1x0267AKxVWxJr0_GcJvcSsGvfC2KfnxnUUI43ZEXa7sRibyCP UUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: AA38E40006 X-Stat-Signature: cts4hf4atgcf7ytca39a1pkmufntmggx X-HE-Tag: 1712759917-760553 X-HE-Meta: U2FsdGVkX1/Jd1AwAuAE4HtsNIB4OplgYlr73LlSFYqA5UhSgKU6Uh55GvuCeiJiKVZ3Z+NvCY1wIJBSfbEU9uwdxR0agV+zrGy1hNkfGku31yjsdvdH5bg/rdcO6sxlzQB1Qyer1kr9SgdmEQOFThvexzu9D1aYXIwkd1QV4T2OtXLxa8EBAmWP3I0MY6lLARrEZOarSTaFFqAilT8l3TA5EJr+OfNa2lcfS5DH3wlxttcE8MZvnD613o8G2abH272KC+G5YYeSda2SSPyusJHNo2de9SeOleG5NWnZNASU77FwJsu5SXwNOkj/2yk73GbmyHJMeAYPZQGNxEKOoH+bvEYm0KyagEdRmWsVV0etXs/pqNNVz8jNrzduHIJqGRdPRcFS58JVjvEZETzoFuBJOBg8KSZU1qeakoQQ/ME8uEjN+bi5nBZnSbEgnHhXNiJbIoBrIJiSNsw3ZGSL/wLhO6m2dwOUZBvsEG9S0AhYqghpr28+YxE/Va/PbFFY0+eXFunIo/TffEugAjGgwlSj3HiMgiNYHWXZ7ZVl258GXSnznD3bVGSlj4vyNLkoVfu6nre4n/pAWRi0O75cohFpLTHd5GY7lNQRxYNzBFCs1V+vUSheO9Otl4/14xiv22y1JcO3tV+FtUKwArvbnKwDXv4nbzLrbzEkZ70Y+qhl2TgP94//yO8mxWb0tsCczCwL9dgC9xOKqBw5EJ8wrsA/y7KuC+zIbA1L64R4jK/FNn0ns55T+vKVsGZH46kZZHWH/ib/Q80j14Pt1mPQoepZUaQ+PbOkZ8Q9SPTua5gWTvOlaX91QN7uRq+00LXPsMQhShAkdaQ6unt8rNTBOiacmVb399HBuQUwJZKAf2EXkbcbwEQsA3FjWyDckxqUAzPp7/bCujluOEusjot4WINhPKOaCvHoyyrmmF7w/xO5EhAfsvsMOgoCVq5h1yK93IdWbTaj1GWPLjfd3i5 k1w24TM1 Ew18ALXs5RPEVolvKu76jx/tfLscFzPkj4wUNFgmdk2ePruE4pU5aeV5jknJbA2Jjx+uQI0I8m6OjHLPZjzYuxxkmGkqV4hSsI0sdGj4jFMqI/c0UZsx5K4h3eEi45mtjDGzQPZIxvdQ02ZiTASQVuAIRYsUOGu3Ht42UvCJK1D27VXzC+JFQ9EsW5u+5QIn4LxGkR47Vskxy5bEgbq7nbmi1txThZ8+qVG79sLNMELy1YsBnXIoTmhspeWSzkxku7731M7gJkUIkrR3wIVREygv1VdcvZ3GUhj1cJIGSqZNbInY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Let __insert_pending() return 1 after successfully inserting a new pending cluster, and also let __revise_pending() to return the number of of newly inserted pendings. Signed-off-by: Zhang Yi --- fs/ext4/extents_status.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 952a38eaea0f..382a96c1bc5c 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -885,7 +885,7 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, es1 = __es_alloc_extent(true); if ((err1 || err2) && !es2) es2 = __es_alloc_extent(true); - if ((err1 || err2 || err3) && revise_pending && !pr) + if ((err1 || err2 || err3 < 0) && revise_pending && !pr) pr = __alloc_pending(true); write_lock(&EXT4_I(inode)->i_es_lock); @@ -913,7 +913,7 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, if (revise_pending) { err3 = __revise_pending(inode, lblk, len, &pr); - if (err3 != 0) + if (err3 < 0) goto error; if (pr) { __free_pending(pr); @@ -922,7 +922,7 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, } error: write_unlock(&EXT4_I(inode)->i_es_lock); - if (err1 || err2 || err3) + if (err1 || err2 || err3 < 0) goto retry; ext4_es_print_tree(inode); @@ -1931,7 +1931,7 @@ static struct pending_reservation *__get_pending(struct inode *inode, * @lblk - logical block in the cluster to be added * @prealloc - preallocated pending entry * - * Returns 0 on successful insertion and -ENOMEM on failure. If the + * Returns 1 on successful insertion and -ENOMEM on failure. If the * pending reservation is already in the set, returns successfully. */ static int __insert_pending(struct inode *inode, ext4_lblk_t lblk, @@ -1975,6 +1975,7 @@ static int __insert_pending(struct inode *inode, ext4_lblk_t lblk, rb_link_node(&pr->rb_node, parent, p); rb_insert_color(&pr->rb_node, &tree->root); + ret = 1; out: return ret; @@ -2089,7 +2090,7 @@ void ext4_es_insert_delayed_extent(struct inode *inode, ext4_lblk_t lblk, es1 = __es_alloc_extent(true); if ((err1 || err2) && !es2) es2 = __es_alloc_extent(true); - if (err1 || err2 || err3) { + if (err1 || err2 || err3 < 0) { if (lclu_allocated && !pr1) pr1 = __alloc_pending(true); if (end_allocated && !pr2) @@ -2119,7 +2120,7 @@ void ext4_es_insert_delayed_extent(struct inode *inode, ext4_lblk_t lblk, if (lclu_allocated) { err3 = __insert_pending(inode, lblk, &pr1); - if (err3 != 0) + if (err3 < 0) goto error; if (pr1) { __free_pending(pr1); @@ -2128,7 +2129,7 @@ void ext4_es_insert_delayed_extent(struct inode *inode, ext4_lblk_t lblk, } if (end_allocated) { err3 = __insert_pending(inode, end, &pr2); - if (err3 != 0) + if (err3 < 0) goto error; if (pr2) { __free_pending(pr2); @@ -2137,7 +2138,7 @@ void ext4_es_insert_delayed_extent(struct inode *inode, ext4_lblk_t lblk, } error: write_unlock(&EXT4_I(inode)->i_es_lock); - if (err1 || err2 || err3) + if (err1 || err2 || err3 < 0) goto retry; ext4_es_print_tree(inode); @@ -2247,7 +2248,9 @@ unsigned int ext4_es_delayed_clu(struct inode *inode, ext4_lblk_t lblk, * * Used after a newly allocated extent is added to the extents status tree. * Requires that the extents in the range have either written or unwritten - * status. Must be called while holding i_es_lock. + * status. Must be called while holding i_es_lock. Returns number of new + * inserts pending cluster on insert pendings, returns 0 on remove pendings, + * return -ENOMEM on failure. */ static int __revise_pending(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t len, @@ -2257,6 +2260,7 @@ static int __revise_pending(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t end = lblk + len - 1; ext4_lblk_t first, last; bool f_del = false, l_del = false; + int pendings = 0; int ret = 0; if (len == 0) @@ -2284,6 +2288,7 @@ static int __revise_pending(struct inode *inode, ext4_lblk_t lblk, ret = __insert_pending(inode, first, prealloc); if (ret < 0) goto out; + pendings += ret; } else { last = EXT4_LBLK_CMASK(sbi, end) + sbi->s_cluster_ratio - 1; @@ -2295,6 +2300,7 @@ static int __revise_pending(struct inode *inode, ext4_lblk_t lblk, ret = __insert_pending(inode, last, prealloc); if (ret < 0) goto out; + pendings += ret; } else __remove_pending(inode, last); } @@ -2307,6 +2313,7 @@ static int __revise_pending(struct inode *inode, ext4_lblk_t lblk, ret = __insert_pending(inode, first, prealloc); if (ret < 0) goto out; + pendings += ret; } else __remove_pending(inode, first); @@ -2318,9 +2325,10 @@ static int __revise_pending(struct inode *inode, ext4_lblk_t lblk, ret = __insert_pending(inode, last, prealloc); if (ret < 0) goto out; + pendings += ret; } else __remove_pending(inode, last); } out: - return ret; + return (ret < 0) ? ret : pendings; }