Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp486731ybk; Fri, 15 May 2020 06:03:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCP8xiPEntsF/3nGM3O6Ipd5w2jVpWthMsaJoRNcivOyFRsGp7zE85f743UWR9j+Dxvaac X-Received: by 2002:a50:bb25:: with SMTP id y34mr2615992ede.237.1589547783886; Fri, 15 May 2020 06:03:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589547783; cv=none; d=google.com; s=arc-20160816; b=b9P70cTh8/yYExVeswzpylCZRZA4VyN7abmfHdiQCYhwNx7EGkYi/zbh925O/LX7Kw 2Bb6kM7YgLS7ZbndErA48ysxx0I0W09PqKwI4KRJWz6OOaHdzUuCUFXBtGWB+5kuxUhl A2zPVWHeYCL5/3yE3nr398pAfAHzyZeX37dfTqcsK7n1skvKkVqmp5Yy780J2K1YCOuW gGSqf4aCCGYy9ewxeU+aWpCIVMUeZV+Ek9mljtI74xi+tRqT0pKBdkfu7d4jx/U47lCF 8pCHhug5eTm5wM8hKKUOJU+k3Gv0zrBd9IlMJfrCc7n3UmJjLtT/5Wukk7rZw/nYxZGP DVSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=h2owgyYDbTAlYqnctNoL/S3qPxaT1kcJhxurcXxw10o=; b=pqxaSJPb6T/VaFXhuuCM8hdlYMne0ltrH32MM7f4Zn7HtNlEUDKh32OczU/8zVxwpR I3U3cUNZjFVDu/g0lajZxCzBvB3r5IhVffh+heog7ccoho7EUoqi/l2hsq2nRxUEeqC2 x90EBxUt2rawR0QBh98tlRsF7yMXBOYyvwF6KASsVOXeDgYuhrFqA8f1bT3uqvne4ze8 7Et9dTxgDpSug1BkqIzgG6l+/TH4adCtBcfp6MBokvF+YCgO3H5AyHkTuGB9P+N4sXYj XmkycRuEWcbbsQQPPJgQdh1NM1GvvnqpYJw8nGwOdwwjrmJbQjZMS1PEIeqxvMNcqsBi Fi9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=GV1f5TcN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x23si1059097edq.363.2020.05.15.06.02.33; Fri, 15 May 2020 06:03:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=GV1f5TcN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726177AbgEONBC (ORCPT + 99 others); Fri, 15 May 2020 09:01:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726122AbgEONBB (ORCPT ); Fri, 15 May 2020 09:01:01 -0400 Received: from merlin.infradead.org (unknown [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69555C061A0C for ; Fri, 15 May 2020 06:01:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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=h2owgyYDbTAlYqnctNoL/S3qPxaT1kcJhxurcXxw10o=; b=GV1f5TcNia61n2ZO7zfukMn4ut uDX9S1Nlpr8L2Br5bOxQLG/83xdIZENw80kP5o44MoEZRWlB09/m6NbgRJLTy/tsTHLQZ+8yXaygS FsNq0ZeVs4Z9cPm/zROCvZ/+5/cA4ih1ohVyZTnSLGonD0L8k+L6EkDuu+T89NpqA2MB6P3w4fHP9 Mqj3DtKmEhHmUMkKv6CmNbGSVSPKqlrwteLtDwLsxloKX5Dv3LQ24DSKYU8h8nmGqj0AsBjB7xd0C STLHfPvxmi+YXIsxtBieaqxPS53FbnkrWCrrDvbgxkf7hL5XQRRtj+1ml4UiqLgOydhCEIxLEg2Oy 4UQap32w==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jZZx2-0000DP-MY; Fri, 15 May 2020 13:00:32 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id AD5713007CD; Fri, 15 May 2020 15:00:30 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 1768A2024968B; Fri, 15 May 2020 15:00:30 +0200 (CEST) Date: Fri, 15 May 2020 15:00:30 +0200 From: Peter Zijlstra To: Lai Jiangshan Cc: linux-kernel@vger.kernel.org, "Paul E . McKenney" , Oleg Nesterov , Michel Lespinasse , Andrea Arcangeli , David Woodhouse , Rik van Riel , Mathieu Desnoyers Subject: Re: [PATCH 1/2] rbtree_latch: quit searching when reaching to maximum depth Message-ID: <20200515130030.GV2957@hirez.programming.kicks-ass.net> References: <20200515124710.16439-1-laijs@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200515124710.16439-1-laijs@linux.alibaba.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 15, 2020 at 12:47:06PM +0000, Lai Jiangshan wrote: > lib/rbtree.c has ensured that there is not possible to > inadvertently cause (temporary) loops in the tree structure > as seen in program order of the modifier. But loop is still > possible to be seen in searcher due to CPU's reordering. > > for example: > modifier searcher > > left rotate at parent > parent->rb_right is node > search to parent > parent->rb_right is node > +->see node->rb_left changed > WRITE_ONCE(parent->rb_right, tmp);-+ | node->rb_left is parennt > no smp_wmb(), some arch can | | > reorder these two writes | | loop long between > WRITE_ONCE(node->rb_left, parent);-+-+ parent and node > | > +--->finally see > parent->rb_right > > The long loop won't stop until the modifer's CPU flushes > its writes. Too avoid it, we should limit the searching depth. Cute, have you actually observed this? Did you have performance issues? > There are no more than (1< And the max_depth of a tree is no more than 2*lg(node_count+1), > which is no mare than 2*BITS_PER_LONG. > > So the serarch should stop when diving down up to > 2*BITS_PER_LONG depth. Arguably you can have a larger key space, but I think due to memory constraints this limit still isn't wrong. But I do feel you need a comment with that.