Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp4673015rwb; Tue, 8 Aug 2023 11:54:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF8PTaACDIBQFonu4+A/DTKZd0u6AtwqxZpAEaXt951HzXFFeUPTPfLKWFgnFl71+jYdHxH X-Received: by 2002:a17:903:2382:b0:1bc:5924:2da2 with SMTP id v2-20020a170903238200b001bc59242da2mr467318plh.56.1691520868099; Tue, 08 Aug 2023 11:54:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691520868; cv=none; d=google.com; s=arc-20160816; b=A7Fd4yMVvLRdIa1aruNT1gboyD5nyRdPxEEJiHvngUPkKkVmpXkDdOJDr2qKGut5/4 aphPLwgblcTQ3nayenY+wcxrXfvrtOSKo0ZZpx6tD7KgvQ0WIK3mb27hh2f76bdWp10h K5O+AvGYAKsjEoGuKrnUXfmA7DEoIbVfJHPv9nM/REi796aGDPlY4teA0OpFHGT/ssJP coXvu8yoBnFNu9HzBR1j2c2h+ZvouMwxe65nuff8uNJbFOu5g9cPR2Ff2HCX6cXFkTXF 6KiyTb11JIi+6VD1oD9mR0PrpShYHhmdepL/bs4EcXcE7Utsh4OFAzsLZ092eK9PncLD 9I+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=g8FIh3x2zNUP0yYP7PB1u90fbVokcWFuUWdhtukLqsk=; fh=2YoCZkvP955s1pH4h6JVKq608i+nkJ2P4+BtlQus3UA=; b=QTUXz96XYp7iLystG24WS9OrysL48mkCngz/wcxfR58ex2tQEnmrIdr8PhzmX5xzA2 ec4zS+xrejCfjwcuIUmZqiXhPz8StGqe1kQDURHtvMWGzWspLjkQzmi0vZHx6i3a7C13 ZWgEnnTQSWNsvNO9ozrBpZZhiE9hqS0lYV6fNaXFiTmIkZbDw5jgOpg6k+EA7GF3gDkT Jn9lkPr5SN/s2xMCOYxoubGvBNuNEykD6hrAiy+Ep5u2sFOQg6K6xEr5wsxkGX1OU9o7 T8pAe6H75Vr3LTQD2g1uL4yo2liPb9FovIdFyTgUVijuSrq7OouNk65c/hX8k3RjYazw f8mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b="RH6PXCq/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u16-20020a170902e81000b001b025aba9f2si7740700plg.22.2023.08.08.11.54.14; Tue, 08 Aug 2023 11:54:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b="RH6PXCq/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233527AbjHHQt0 (ORCPT + 99 others); Tue, 8 Aug 2023 12:49:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230512AbjHHQsp (ORCPT ); Tue, 8 Aug 2023 12:48:45 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25D5316AFC; Tue, 8 Aug 2023 08:57:14 -0700 (PDT) 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=g8FIh3x2zNUP0yYP7PB1u90fbVokcWFuUWdhtukLqsk=; b=RH6PXCq/xfGf7RhCXgKdGsbR4X e3Fja+sKYDNhIrFIXlx80hY5riayoG7Sluxx5F9phC+DfSgnYp1ZWYAdSTnGe2VtXky6T38nhySLN sueBnp9LTVvPh4+sD2kJSvC61885sATFW5M7vgFxFElL2+B/Z0pU6e0BgH4xNCOCgCWmvQsyLjdA+ gOlv8XnyEtNo3tA5/u3x6GjRCKKJi9eGpDwHs4HgyDFPEsoRrG5YSbZwDLtwrkziFcge98gbUGZ6W UJMenmKClJd1IwB9QsXyIfQWM3cVV+RVhJku/nZtgKTesO98Vt5OYfvhhS05C9Jiho1mWtHnFudP4 TnFOQyMA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qTITg-004exJ-0B; Tue, 08 Aug 2023 08:54:08 +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 (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id CDCC230003A; Tue, 8 Aug 2023 10:54:06 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 9ACF820299019; Tue, 8 Aug 2023 10:54:06 +0200 (CEST) Date: Tue, 8 Aug 2023 10:54:06 +0200 From: Peter Zijlstra To: Thomas Gleixner Cc: axboe@kernel.dk, linux-kernel@vger.kernel.org, mingo@redhat.com, dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com, Andrew Morton , urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, Arnd Bergmann , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, malteskarupke@web.de Subject: Re: [PATCH v2 11/14] futex: Implement FUTEX2_NUMA Message-ID: <20230808085406.GU212435@hirez.programming.kicks-ass.net> References: <20230807121843.710612856@infradead.org> <20230807123323.504975124@infradead.org> <87fs4utv6f.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87fs4utv6f.ffs@tglx> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 07, 2023 at 11:11:04PM +0200, Thomas Gleixner wrote: > On Mon, Aug 07 2023 at 14:18, Peter Zijlstra wrote: > > /** > > * futex_hash - Return the hash bucket in the global hash > > * @key: Pointer to the futex key for which the hash is calculated > > @@ -114,10 +137,29 @@ late_initcall(fail_futex_debugfs); > > */ > > struct futex_hash_bucket *futex_hash(union futex_key *key) > > { > > - u32 hash = jhash2((u32 *)key, offsetof(typeof(*key), both.offset) / 4, > > + u32 hash = jhash2((u32 *)key, > > + offsetof(typeof(*key), both.offset) / sizeof(u32), > > key->both.offset); > > + int node = key->both.node; > > + > > + if (node == -1) { > > NUMA_NO_NODE please all over the place. Ah, so our (futex2) ABI states this needs to be -1, but in theory someone could come along and change the kernel internal NUMA_NO_NODE to something else. That is, I explicitly chose not to use it. I can of course, because as of now these values do match. > > + /* > > + * In case of !FLAGS_NUMA, use some unused hash bits to pick a > > + * node -- this ensures regular futexes are interleaved across > > + * the nodes and avoids having to allocate multiple > > + * hash-tables. > > + * > > + * NOTE: this isn't perfectly uniform, but it is fast and > > + * handles sparse node masks. > > + */ > > + node = (hash >> futex_hashshift) % nr_node_ids; > > + if (!node_possible(node)) { > > + node = find_next_bit_wrap(node_possible_map.bits, > > + nr_node_ids, node); > > + } > > Smart. Thanks :-) > > > > +static inline unsigned int futex_size(unsigned int flags) > > +{ > > + return 1 << (flags & FLAGS_SIZE_MASK); > > +} > > + > > static inline bool futex_flags_valid(unsigned int flags) > > If you reorder these two functions in the patch which introduces them, > this diff gets readable :) Durr, I knew I was forgetting something, will do.