Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp177434ybh; Mon, 9 Mar 2020 19:02:58 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtrHZXwgrTjpXRX5rgFNcKxP3LiZAbYbW87RgqN6VnbheduCvnYEIypFcSthdo9XvP4T0YA X-Received: by 2002:aca:e146:: with SMTP id y67mr268175oig.93.1583805778159; Mon, 09 Mar 2020 19:02:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583805778; cv=none; d=google.com; s=arc-20160816; b=NF39wif2qedHHktVc7HME4OfnqZTZRWsboMpE3q/KWZ6xZcoZK9WhUqNlZKQAK0kT9 mM3PsEAKpTK/e037RpoUlmycjcllwpawpoU734OeiripOsfb+500HuX6l/j6BK9HwGHi osrUuXyVscreYuBHWUzqOBjfDUwlFhyG7LrilcvJoIMIEKi7yVU21v0rehEXsJfycwze Pe6sCJC5GUUcJMNyaM+QIqybxRUGK0ycbLhDZt6gyHBvRpqst2ebvvmRKm/cuqlmVtCt qxWAkZBHjXjjA42qsdgZ2QTRA118B2a7XVa/WY6SIkavZGGUQHhqPgCE/Sd+m1FT1bBL nS9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=J7pCBtBDSjcVtEqS1SMqVaavriUKG9Gcw86QjHCE7is=; b=di/n488TrqaU9Rg2QMDk43g0u/BvywzuS/CCWkYdn+ldd/PXcbQejbdMiAAh2gkTgu rR9AnJPvnMcMPRC6P3jEjoGmfH1fVzgq4OGJJicWdnM8DgsvoqksVJtHQn/QfXFM5F5C UPb72QjAS+Il66kBVbFt8NZBqyI7bijrTCScBP+28zRxQ3rtf5i/NgnU8qINlY6pTtiz 6hoM3OJnrXCbkdzMOZSEKJPMSFoTD+zPuL1y3T1e+ut74L0X9hCGX9U7SpQ7uMlIBxSj tkMg2Zm3lyfEaDp/U15v+614U7J0diAgtfe13IX5qIYi8NDwITDPRU3ScVIMbd2H21QN 2a5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="od8Ik/Ke"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id j26si270001otk.227.2020.03.09.19.02.45; Mon, 09 Mar 2020 19:02:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="od8Ik/Ke"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726462AbgCJCCL (ORCPT + 99 others); Mon, 9 Mar 2020 22:02:11 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:41573 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726134AbgCJCCL (ORCPT ); Mon, 9 Mar 2020 22:02:11 -0400 Received: by mail-pf1-f194.google.com with SMTP id z65so5706332pfz.8 for ; Mon, 09 Mar 2020 19:02:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=J7pCBtBDSjcVtEqS1SMqVaavriUKG9Gcw86QjHCE7is=; b=od8Ik/Ke9KrtA9c/iHuIQuTCQ4UUl9WD9SzJlxBa0aaRNAas2uFuzo6bHEfdOUpWGm WeUdb/iJ7YvGs4FVnzeE3n/MncwQcj9DyktXeEC+gNykkoQkBGT6NDSyM59/wmD91jHP J7MugXKmAov+76/+0Kd3UjFBamWcWzVmFMy21HGRegnvWAJEziGuFvSt/YETxzmQCEcG Nf8fkbMpKGksMaRpqWgBWAzPt6gY+4XqZKkWEgluS0U9VLe3zlffZVr1AxjfY39HYelJ UHbdZVbmytWTt3fXxV3Ls781j0S6f2qR4VRLqYKFV6h0jz965t+gu7MmGKAE+USEBHOJ 2s3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=J7pCBtBDSjcVtEqS1SMqVaavriUKG9Gcw86QjHCE7is=; b=cyuqi5+LBcXMD0zoNtvhzolZA4w2vc0j+KyF9aLDRIKbHgWiPjBnmCiRzuTq/8xvI0 2PJziIVGTK5csJlZxo0z53UOL3RRTZ1nmbB6iKWcxykC4X2jxtlhINbXgCldXP7B4Rgz PZvu20MzO0HyYqOszT5SDyt0XlvYejYRJ3Gd0LeRldbZBwjYxNsNT+NxshAkDe3UGxy8 eWlIOsY4fmrDpZIBM9YBOxrpiZ+WToSPfbPBpmINYm5y8GTCy5ilazSElHj5yMucZaG6 grOIGkhQO0eYsQfGtqOhKpryDbgJEdBG2XRmiYH6o6JRkeKwFaZSdH/Bn5sDI1Fu1p5F qzog== X-Gm-Message-State: ANhLgQ3jU8M5wD0iLkAi2hgWKiZgWwqb9MeHjrDd7p0w6xiDQ34dtCWc SQlTPDgMgqYvbqLti3mYlHM= X-Received: by 2002:a63:a069:: with SMTP id u41mr3283610pgn.3.1583805730150; Mon, 09 Mar 2020 19:02:10 -0700 (PDT) Received: from localhost ([43.224.245.179]) by smtp.gmail.com with ESMTPSA id d6sm740081pjv.38.2020.03.09.19.02.08 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 09 Mar 2020 19:02:09 -0700 (PDT) Date: Tue, 10 Mar 2020 10:02:07 +0800 From: chenqiwu To: Peter Zijlstra Cc: akpm@linux-foundation.org, walken@google.com, rfontana@redhat.com, dbueso@suse.de, tglx@linutronix.de, linux-kernel@vger.kernel.org, chenqiwu Subject: Re: [PATCH] rbtree: introduce three helpers about sort-order iteration Message-ID: <20200310020206.GA8961@cqw-OptiPlex-7050> References: <1583769734-1311-1-git-send-email-qiwuchen55@gmail.com> <20200309165511.GK12561@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200309165511.GK12561@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 09, 2020 at 05:55:11PM +0100, Peter Zijlstra wrote: > On Tue, Mar 10, 2020 at 12:02:14AM +0800, qiwuchen55@gmail.com wrote: > > +/** > > + * rbtree_for_each_entry_safe - iterate in sort-order over of given type > > + * allowing the backing memory of @pos to be invalidated. > > + * @pos: the 'type *' to use as a loop cursor. > > + * @n: another 'type *' to use as temporary storage. > > + * @root: 'rb_root *' of the rbtree. > > + * @field: the name of the rb_node field within 'type'. > > + * > > + * rbtree_order_for_each_entry_safe() provides a similar guarantee as > > + * list_for_each_entry_safe() and allows the sort-order iteration to > > + * continue independent of changes to @pos by the body of the loop. > > + * > > + * Note, however, that it cannot handle other modifications that re-order the > > + * rbtree it is iterating over. This includes calling rb_erase() on @pos, as > > + * rb_erase() may rebalance the tree, causing us to miss some nodes. > > + */ > > +#define rbtree_for_each_entry_safe(pos, n, root, field) \ > > + for (pos = rb_entry_safe(rb_first(root), typeof(*pos), field); \ > > + pos && ({ n = rb_entry_safe(rb_next(&pos->field), \ > > + typeof(*pos), field); 1; }); \ > > + pos = n) > > Since this cannot deal with rb_erase(), what exactly is the purpose of > this thing? It's just a copy of rbtree_postorder_for_each_entry_safe() for the usage scenario of sort-order iteration. It can be used for walking the tree and free all entries of the given type.