Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp555038ybk; Fri, 15 May 2020 07:41:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvzOhWSH5FDLQDyapby0bYIH/g3SRHYtFRN1KulceL+MgXmUnrbqSQthH0LCGgPeB6moCE X-Received: by 2002:a50:a412:: with SMTP id u18mr3240694edb.192.1589553702319; Fri, 15 May 2020 07:41:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589553702; cv=none; d=google.com; s=arc-20160816; b=F5lwCQLDBao0hIpMAuoQtkgm7G5kjjDqeZnMNpRN+N9yNVGWe+nNNfzjpbRmaK7BId d+ieVjXddPmqyeC3uc1DY6Bn2S8p3IPWKS7h3FBN1yLLs7HvkopIE1jgGalHhvDPG2wu 1r2qe6MpRktzObW7YwaND0rlgVk1Isb9cQkrD3qaUrK16BpwWmxw7uVJRm1Jon7F95xO bj8s+TObLR2a1kvD8TpQCYmPd5XcXsODo7Bh+Z35zVHk6N9jRNO8OgxtUxr9WGrNeaBr Ffg2aCZzdsJGUclGXRCdDeykFlACGLiN8lmdrqBiXhy56O+ilWxXWefYIL6ZC/0gCPA8 sqnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=G4hpPbKuo/eM3pj3/8Bij0gexeSDdOJHguLYolZpnKs=; b=oDAYnA6g6eTM6AfKkpiSRBRx0kaOKr2EjzD/94yK6EnSaXhNVJAtQPm+s8QRZ1prN8 TVyxrbi4GxYYAd3aNm9KMRhdDFduJgF1HsjoOWFvH/y4hDgQ8uizgciQqrHii9GRXhhH r7QeoSUUZcFM6+K0mfEW70IWLDOG0G2IKNbWhGwgYop2Djy+Fk8xu+qp9eBSO67Ct2kB vzmLhxKSduGYVV8A2BPSvo4F9L3l6XBOdrwpLd3WJeVibM5VpNigMKJDcQX/S7Wx3j25 THFXZsO7wnThRJYv+yEhwA9W5JpNlHUtXxiunXMLgFVMRYj12tnt0D9AEamOZL4IVCZs XxQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EINNHW9t; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m9si1336609ejr.100.2020.05.15.07.41.18; Fri, 15 May 2020 07:41:42 -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=pass header.i=@gmail.com header.s=20161025 header.b=EINNHW9t; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728396AbgEOOjj (ORCPT + 99 others); Fri, 15 May 2020 10:39:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726719AbgEOOjh (ORCPT ); Fri, 15 May 2020 10:39:37 -0400 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BE8EC061A0C for ; Fri, 15 May 2020 07:39:37 -0700 (PDT) Received: by mail-io1-xd41.google.com with SMTP id x5so2976631ioh.6 for ; Fri, 15 May 2020 07:39:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=G4hpPbKuo/eM3pj3/8Bij0gexeSDdOJHguLYolZpnKs=; b=EINNHW9tIkICYl47a8AU63VrYU5C2scpuARJTsP/TsQ5cQzHBrJb64es1TdQNfzB0Z kx7VDchChuQupqL21ecTM6d/vWEDCBR9/Mj/T6gCVP0egVvjgWc7NmEIgxAoa3uMxKpz /K88McJ4rzVlfbFGm6J2bLOCcOht/xcZvDaX00RYyCcawkdq3Actzuwtq2TK8fl4s2Lg avUNEFz4X/u6f28O1W0p/sBimqX3ruf1yDupSHCBp+B2z/g1atEgcEquvjabpI5aDhUr ADEyA1YhRpY5L0XbORk0kp3IMCV2isKMD5faV9CGzmeFxs+bulJlaVVu/F6kP1dZnPac 8d0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=G4hpPbKuo/eM3pj3/8Bij0gexeSDdOJHguLYolZpnKs=; b=WueS372cuLqqi1HfJkZW4Df43YqDUHW5Lw+xsscbEcsSJBA9r5Az3qzFPHDY0HshnS XYgxLNC5FGqlgCDEdY6FkdBEDNn6mNwbCuKWx1wysTKqi652wxxjjO9GLP0u2zSKHBi3 YxHypDSzXrEHM5WENHi0SiCCV1W5CW/YiqJ65Y6ZetbKnfNE/6p/ELhhEd6xkcZAarXg KZvZmDb8MmFR/jq8z5vzFZV2HHd6t9Wc2GWR4NA79YZFS/Ulfg0PAY9Hl8gJ4VEUbYbi a1pIR5bbcT80ucatJAcyEfGp2/tiFxgO5Muo0Uhji5DWP5ksKEffQh+WQAb/ZevA+T0o Homw== X-Gm-Message-State: AOAM533f+zSz6CfxNFreLBd6J/a0ImX79fahLq/fLRJ/+HO7g6iDj2qg RWCeHNQSvgsm0rY+rfd7fCb/9cZugshGzfXkkrc= X-Received: by 2002:a05:6638:158:: with SMTP id y24mr3441021jao.43.1589553576465; Fri, 15 May 2020 07:39:36 -0700 (PDT) MIME-Version: 1.0 References: <20200515124710.16439-1-laijs@linux.alibaba.com> <20200515130030.GV2957@hirez.programming.kicks-ass.net> In-Reply-To: <20200515130030.GV2957@hirez.programming.kicks-ass.net> From: Lai Jiangshan Date: Fri, 15 May 2020 22:39:25 +0800 Message-ID: Subject: Re: [PATCH 1/2] rbtree_latch: quit searching when reaching to maximum depth To: Peter Zijlstra Cc: Lai Jiangshan , LKML , "Paul E . McKenney" , Oleg Nesterov , Michel Lespinasse , Andrea Arcangeli , David Woodhouse , Rik van Riel , Mathieu Desnoyers Content-Type: text/plain; charset="UTF-8" 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 9:04 PM Peter Zijlstra wrote: > > 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? I can only test it on x86 by now, which implies smp_wmb() between writes. I haven't observed any thing wrong. I'm just imaging it on some other ARCHs. I accidentally found this part of code when I searched for whether there is any attempt again to use rbtree with RCU, and whether there are the cases besides speculative page fault. > > > 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. Sure, I will add some comments about why "2*BITS_PER_LONG" in code. But how it could be larger key space? there are not more than (1<