From patchwork Fri Oct 11 21:44:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sidhartha Kumar X-Patchwork-Id: 13833199 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 1E376D1A424 for ; Fri, 11 Oct 2024 21:45:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A9E86B009B; Fri, 11 Oct 2024 17:45:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 15A8B6B009F; Fri, 11 Oct 2024 17:45:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F15A36B00A1; Fri, 11 Oct 2024 17:45:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CFBFF6B009B for ; Fri, 11 Oct 2024 17:45:06 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 88E1214192F for ; Fri, 11 Oct 2024 21:45:01 +0000 (UTC) X-FDA: 82662652128.09.DB822A8 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf20.hostedemail.com (Postfix) with ESMTP id 0D5081C0010 for ; Fri, 11 Oct 2024 21:45:00 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=ZBIImaXI; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf20.hostedemail.com: domain of sidhartha.kumar@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=sidhartha.kumar@oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728682991; a=rsa-sha256; cv=none; b=XVDQE1e424DjlkXcCZC7GQiQLiKE+EP1hmyK3Q8zwEZOuOUW/Av1bMqvfYUGo4I9NEz84y f+Z6QuG7XLM+9nK6rudx7FrcQqCY62Ckz13zjqf4MCb+SuJTO/11qcr/wpnoVcFZI6BPZH ykcZi3hvbjEPlOsW4rh8I4rlhJ+ksfw= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=ZBIImaXI; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf20.hostedemail.com: domain of sidhartha.kumar@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=sidhartha.kumar@oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728682991; 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:dkim-signature; bh=xnWRry+gLN3GpXpXevD+PZSS7Fx/gqHioKulUKJNRrw=; b=sqquYdR9f70Hl/z7Pd4935K2x9rX+KqyxhxtRqzXhpD4CWmCmoch/KfN880tvaYKWxWm8K 722MPQOvwiDwza4Kvyfy+VrvI5XGMwSAktkbxXOFeaqT69Cbj9+CY88GMCbCc4NVRB6Ptv CSRZai9MZhjmbea3fvrkRmH4SaRJUYk= Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49BJU84k030021; Fri, 11 Oct 2024 21:44:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2023-11-20; bh=xnWRr y+gLN3GpXpXevD+PZSS7Fx/gqHioKulUKJNRrw=; b=ZBIImaXI5Urs9jUykLwXK alYd1N2RAe9o3VbIrDU7Ui8riuXkLOXA3bCACmBnw6fltcAkRPncean0hJ29yzOC +8zF1YmAZRrBRrQSFfJ0lUFjiwzPxni789Abx9QmUxjdR/thSMUXlUH71O1rqbi/ ZKMoiZw7sxx+qyt3eOUXJM9UtsAhBPdwH8JlRN2Bd0aSRrnVGMeG8/lnaqJxd9fS aICtPbhczKa1YMoYi1nUNezOy626Qgc0sI22LrvDIOwFgsNwxcti4dZJ/TTm15UE 7nBFU9WpT5tgYn2D292RLsf6F/NoFXaYItyIxxOqVMAmp4Pbg4nk0X7a8EY/GIbr w== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42308dwvm6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Oct 2024 21:44:56 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49BKUFfp028019; Fri, 11 Oct 2024 21:44:55 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 422uwj3961-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Oct 2024 21:44:55 +0000 Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 49BLisSo026877; Fri, 11 Oct 2024 21:44:55 GMT Received: from sidkumar-mac.us.oracle.com (dhcp-10-65-170-196.vpn.oracle.com [10.65.170.196]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 422uwj395e-2; Fri, 11 Oct 2024 21:44:55 +0000 From: Sidhartha Kumar To: linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, liam.howlett@oracle.com, willy@infradead.org, richard.weiyang@gmail.com, Sidhartha Kumar Subject: [PATCH 2/2] maple_tree: refactor mas_wr_store_type() Date: Fri, 11 Oct 2024 17:44:51 -0400 Message-ID: <20241011214451.7286-2-sidhartha.kumar@oracle.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241011214451.7286-1-sidhartha.kumar@oracle.com> References: <20241011214451.7286-1-sidhartha.kumar@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-11_19,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 mlxscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410110153 X-Proofpoint-ORIG-GUID: 7-fLVjE2wzeVOGEEfcoVFkKReyQH3081 X-Proofpoint-GUID: 7-fLVjE2wzeVOGEEfcoVFkKReyQH3081 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 0D5081C0010 X-Stat-Signature: t58rxicdbpryy1gkfadm4bd6fkzfcpki X-Rspam-User: X-HE-Tag: 1728683100-742847 X-HE-Meta: U2FsdGVkX18JFxzKldSg7Mt/aSEOVYvuidskb4Hr5zLAUTn4Q+3X6Pmcsd6qxx9U+l8dP1OfDzdEQw67iPDMLnRrVP+4d/qzG2RX39FiyNMl1xJzfpX1Dd5vI9jupxlICAQ1fPR777Wyp6F36UeUjyMAJrd1gg1MFeXAlpmwCCa7/LOwMrZDjPp8Mu3fn7U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kzAS5Od15vWvDR6jE8f0FnhC0x82cuq0SfhbaJqnXWCW8PsNyKctSgxvbR/xm7jvUCCPOn5FSrsjAVfrt9bWKFtOOzvBs+nsE1aXo1zgtijsM7qF5Wb7rzU6 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: In mas_wr_store_type(), we check if new_end < mt_slots[wr_mas->type]. If this check fails, we know that ,after this, new_end is >= mt_min_slots. Checking this again when we detect a wr_node_store later in the function is reduntant. Because this check is part of an OR statement, the statement will always evaluate to true, therefore we can just get rid of it. We also refactor mas_wr_store_type() to return the store type rather than set it directly as it greatly cleans up the function. Suggested-by: Liam Howlett Suggested-by: Wei Yang Signed-off-by: Sidhartha Reviewed-by: Wei Yang Reviewed-by: Liam Howlett --- Hi Andrew, could you please drop "maple_tree: remove conditionals to detect wr_node_store" in mm-unstable before applying this patch lib/maple_tree.c | 72 +++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 47 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index b3b1d4b8126b..a5e982e482dd 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4191,24 +4191,22 @@ static inline int mas_prealloc_calc(struct ma_state *mas, void *entry) } /* - * mas_wr_store_type() - Set the store type for a given + * mas_wr_store_type() - Determine the store type for a given * store operation. * @wr_mas: The maple write state + * + * Return: the type of store needed for the operation */ -static inline void mas_wr_store_type(struct ma_wr_state *wr_mas) +static inline enum store_type mas_wr_store_type(struct ma_wr_state *wr_mas) { struct ma_state *mas = wr_mas->mas; unsigned char new_end; - if (unlikely(mas_is_none(mas) || mas_is_ptr(mas))) { - mas->store_type = wr_store_root; - return; - } + if (unlikely(mas_is_none(mas) || mas_is_ptr(mas))) + return wr_store_root; - if (unlikely(!mas_wr_walk(wr_mas))) { - mas->store_type = wr_spanning_store; - return; - } + if (unlikely(!mas_wr_walk(wr_mas))) + return wr_spanning_store; /* At this point, we are at the leaf node that needs to be altered. */ mas_wr_end_piv(wr_mas); @@ -4216,50 +4214,30 @@ static inline void mas_wr_store_type(struct ma_wr_state *wr_mas) mas_wr_extend_null(wr_mas); new_end = mas_wr_new_end(wr_mas); - if ((wr_mas->r_min == mas->index) && (wr_mas->r_max == mas->last)) { - mas->store_type = wr_exact_fit; - return; - } + if ((wr_mas->r_min == mas->index) && (wr_mas->r_max == mas->last)) + return wr_exact_fit; - if (unlikely(!mas->index && mas->last == ULONG_MAX)) { - mas->store_type = wr_new_root; - return; - } + if (unlikely(!mas->index && mas->last == ULONG_MAX)) + return wr_new_root; /* Potential spanning rebalance collapsing a node */ if (new_end < mt_min_slots[wr_mas->type]) { - if (!mte_is_root(mas->node) && !(mas->mas_flags & MA_STATE_BULK)) { - mas->store_type = wr_rebalance; - return; - } - mas->store_type = wr_node_store; - return; + if (!mte_is_root(mas->node) && !(mas->mas_flags & MA_STATE_BULK)) + return wr_rebalance; + return wr_node_store; } - if (new_end >= mt_slots[wr_mas->type]) { - mas->store_type = wr_split_store; - return; - } + if (new_end >= mt_slots[wr_mas->type]) + return wr_split_store; - if (!mt_in_rcu(mas->tree) && (mas->offset == mas->end)) { - mas->store_type = wr_append; - return; - } + if (!mt_in_rcu(mas->tree) && (mas->offset == mas->end)) + return wr_append; if ((new_end == mas->end) && (!mt_in_rcu(mas->tree) || - (wr_mas->offset_end - mas->offset == 1))) { - mas->store_type = wr_slot_store; - return; - } - - if (mte_is_root(mas->node) || (new_end >= mt_min_slots[wr_mas->type]) || - (mas->mas_flags & MA_STATE_BULK)) { - mas->store_type = wr_node_store; - return; - } + (wr_mas->offset_end - mas->offset == 1))) + return wr_slot_store; - mas->store_type = wr_invalid; - MAS_WARN_ON(mas, 1); + return wr_node_store; } /** @@ -4274,7 +4252,7 @@ static inline void mas_wr_preallocate(struct ma_wr_state *wr_mas, void *entry) int request; mas_wr_prealloc_setup(wr_mas); - mas_wr_store_type(wr_mas); + mas->store_type = mas_wr_store_type(wr_mas); request = mas_prealloc_calc(mas, entry); if (!request) return; @@ -5446,7 +5424,7 @@ void *mas_store(struct ma_state *mas, void *entry) * overwrite multiple entries within a self-balancing B-Tree. */ mas_wr_prealloc_setup(&wr_mas); - mas_wr_store_type(&wr_mas); + mas->store_type = mas_wr_store_type(&wr_mas); if (mas->mas_flags & MA_STATE_PREALLOC) { mas_wr_store_entry(&wr_mas); MAS_WR_BUG_ON(&wr_mas, mas_is_err(mas)); @@ -5549,7 +5527,7 @@ int mas_preallocate(struct ma_state *mas, void *entry, gfp_t gfp) int request; mas_wr_prealloc_setup(&wr_mas); - mas_wr_store_type(&wr_mas); + mas->store_type = mas_wr_store_type(&wr_mas); request = mas_prealloc_calc(mas, entry); if (!request) return ret;