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 06D3FC433ED for ; Fri, 14 May 2021 11:27:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9148B613AA for ; Fri, 14 May 2021 11:27:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9148B613AA 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 119996B0036; Fri, 14 May 2021 07:27:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0CAA26B006E; Fri, 14 May 2021 07:27:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E5ED96B0070; Fri, 14 May 2021 07:27:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0024.hostedemail.com [216.40.44.24]) by kanga.kvack.org (Postfix) with ESMTP id B32596B0036 for ; Fri, 14 May 2021 07:27:25 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4D452824999B for ; Fri, 14 May 2021 11:27:25 +0000 (UTC) X-FDA: 78139610850.13.80ED5A6 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf30.hostedemail.com (Postfix) with ESMTP id 7D30BE000112 for ; Fri, 14 May 2021 11:27:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=mCCyvpSutI8noyt1HNcq373sVHNhz9AT4dX+rpfCZkQ=; b=leLuXHsAYlKLMBPzk/T2noDdB0 iQwvag3bNqeyX1jJhtpNdbdKIRS+SSmLTZYR8DehrZTrn0HM88g+PhX5UWIZGO6tMw6ZmQCRf32ii ooSaBFFzI/XBm/eMmW7ursLe211u6/w0WxbsTQkU07MjTRIBz0WaV+7F/4xkUjJXpoOyMFtptTXAy rXpjsF3YTPorbxjUjUcTLazh6ZIhg7yVn0FrQQsCtOOV4Z9sB8Nogy3a+LFyRji/ZZ7z6qGR31KRo UbGPvRW1sxqPsLfgZAymXplaE4v1xp9GqyQZFVjAlekFPmYpkZS4GAIrhYZjo9BS3dDlNgbpHzzoG hcXr+C2w==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lhVyM-007tq5-Fb; Fri, 14 May 2021 11:27:14 +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 CE55530001C; Fri, 14 May 2021 13:27:13 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id AF4EE20298BDE; Fri, 14 May 2021 13:27:13 +0200 (CEST) Date: Fri, 14 May 2021 13:27:13 +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: X-Rspamd-Queue-Id: 7D30BE000112 Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=leLuXHsA; spf=none (imf30.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org; dmarc=none X-Rspamd-Server: rspam04 X-Stat-Signature: jw5zq5zedbcjnihbrfprqc49d75bgp9p X-HE-Tag: 1620991643-978986 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 Fri, May 14, 2021 at 01:13:51PM +0200, Peter Zijlstra wrote: > On Wed, Apr 28, 2021 at 03:36:02PM +0000, Liam Howlett wrote: > > +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? IMO the more obvious way is something like: (val >> MAPLE_PARENT_SHIFT) & ((1 << MAPLE_SLOT_BITS)-1); And then we also see that 3+4 gives 7, which is that magical 127 above, are them the same? Related names would be good in that case.