From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 183C9C433ED for ; Fri, 14 May 2021 11:14:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 67186613D6 for ; Fri, 14 May 2021 11:14:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 67186613D6 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D5AB86B0036; Fri, 14 May 2021 07:14:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D0A5E6B006E; Fri, 14 May 2021 07:14:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BAAC36B0070; Fri, 14 May 2021 07:14:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0132.hostedemail.com [216.40.44.132]) by kanga.kvack.org (Postfix) with ESMTP id 8C4436B0036 for ; Fri, 14 May 2021 07:14:57 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 29EDDBF10 for ; Fri, 14 May 2021 11:14:57 +0000 (UTC) X-FDA: 78139579434.07.A9DA62D Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP id 3C2F3C0007FA for ; Fri, 14 May 2021 11:14:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=tYLc3GsyfFBaMQ+RDwOHUMKnirmCetzH9ttjQf1YUdo=; b=YR412PtVNoEzxYeawP4MP1QM5A Q/+1RKjNTTOW8llHIEif9QCXY9IgFDK1frnn7UwkBCUTt86KkqT7jixb5PMqIzTQdylwQ5diNkhGt nEb65FhT0RXGQGfWqINuIZBYGLChTU8k3PuKVowzqIaA5iM5dMXAD+EMaddxf25VukWFcsssQWdRk e8x18e8O/NgYs5vuv90qtOjcCur8ejsIMBb7zw1fHC/DRT5rwVUYiXxFsDm9B4eH4+fLBBpI0vr29 DDoQ+z78md+NubYpJzzRQsHf0XGHqsZaSdgp6kfGOklsTDWXw7c20CHEgkVMCMQaXnEo3Y67XBbeC WnX29fUQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lhVlQ-00AJHJ-LC; Fri, 14 May 2021 11:13:58 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 0251F30022A; Fri, 14 May 2021 13:13:51 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id D5D6020298BDE; Fri, 14 May 2021 13:13:51 +0200 (CEST) Date: Fri, 14 May 2021 13:13:51 +0200 From: Peter Zijlstra To: Liam Howlett Cc: "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Andrew Morton , Song Liu , Davidlohr Bueso , "Paul E . McKenney" , Matthew Wilcox , Laurent Dufour , David Rientjes , Axel Rasmussen , Suren Baghdasaryan , Vlastimil Babka , Rik van Riel , Michel Lespinasse Subject: Re: [PATCH 26/94] Maple Tree: Add new data structure Message-ID: References: <20210428153542.2814175-1-Liam.Howlett@Oracle.com> <20210428153542.2814175-27-Liam.Howlett@Oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210428153542.2814175-27-Liam.Howlett@Oracle.com> Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=YR412PtV; spf=none (imf14.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 3C2F3C0007FA X-Stat-Signature: ffadyixezy8ezpsr6e3ng7nwqu69q4nr X-HE-Tag: 1620990896-482578 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: On Wed, Apr 28, 2021 at 03:36:02PM +0000, Liam Howlett wrote: > +/* > + * Special values for ma_state.node. > + * MAS_START means we have not searched the tree. > + * MAS_ROOT means we have searched the tree and the entry we found lives in > + * the root of the tree (ie it has index 0, length 1 and is the only entry in > + * the tree). > + * MAS_NONE means we have searched the tree and there is no node in the > + * tree for this entry. For example, we searched for index 1 in an empty > + * tree. Or we have a tree which points to a full leaf node and we > + * searched for an entry which is larger than can be contained in that > + * leaf node. > + * MA_ERROR represents an errno. After dropping the lock and attempting > + * to resolve the error, the walk would have to be restarted from the > + * top of the tree as the tree may have been modified. > + */ > +#define MAS_START ((struct maple_enode *)1UL) > +#define MAS_ROOT ((struct maple_enode *)5UL) > +#define MAS_NONE ((struct maple_enode *)9UL) > +#define MA_ERROR(err) \ > + ((struct maple_enode *)(((unsigned long)err << 2) | 2UL)) > + > +static inline enum maple_type mte_node_type(const struct maple_enode *entry) > +{ > + return ((unsigned long)entry >> 3) & 15; > +} > +static inline struct maple_node *mte_to_node(const struct maple_enode *entry) > +{ > + return (struct maple_node *)((unsigned long)entry & ~127); > +} > +static inline struct maple_topiary *mte_to_mat(const struct maple_enode *entry) > +{ > + return (struct maple_topiary *)((unsigned long)entry & ~127); > +} Can we please write masks as hex, also do they want a pretty name? This has more magic mask values, proper names might be good: > +static inline void mte_set_parent(struct maple_enode *enode, > + const struct maple_enode *parent, > + unsigned char slot) > +{ > + unsigned long bitmask = 0x78; > + unsigned long val = (unsigned long) parent; > + unsigned long type = 0; > + > + switch (mte_node_type(parent)) { > + case maple_range_64: > + case maple_arange_64: > + type = 6; > + break; > + default: > + break; > + } > + > + val &= ~bitmask; // Remove any old slot number. > + val |= (slot << MAPLE_PARENT_SHIFT); // Set the slot. > + val |= type; > + mte_to_node(enode)->parent = ma_parent_ptr(val); > +} > +static inline unsigned int mte_parent_slot(const struct maple_enode *enode) > +{ > + unsigned long bitmask = 0x7C; > + unsigned long val = (unsigned long) mte_to_node(enode)->parent; > + > + if (val & 1) > + return 0; // Root. > + > + return (val & bitmask) >> MAPLE_PARENT_SHIFT; 7c is 1111100, but then you're shifting out the one bit that makes the difference from the above magic 0x78. What gives? > +}