Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp118211ybl; Tue, 13 Aug 2019 17:08:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZOJ2NIoKIchNaOmlfHZCs5F8OUglfn7gp7rqSq2U1+W1PRw+J9ZdTiJ3nu/Nv3VMRQjQO X-Received: by 2002:a17:90a:cc11:: with SMTP id b17mr2886257pju.136.1565741306774; Tue, 13 Aug 2019 17:08:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565741306; cv=none; d=google.com; s=arc-20160816; b=qMoARfDA3FvZvqS/k1AhaTfRNQL0x/iJzPwHOHAiriZc3lDsRIXqa/Zm7jEJm3taus UrXuCMwjN8S7eQfCxTq9uRBAO1uT60tIVrsFuRcESBuZ5towu4/jkbKHzG5Bd9wSu12U qwzTjTTB7sly63FC5bqrkpkuk8mNbA0qXKr5SQg3/7qmbALZJagx0Uwb1YhDIOnmf6C8 HBdsew13Aic4o9/q9cV3D5c/WftNkivo/fWx7OP1avebKeX64fkr92pnuEygMG6Gxtiw Tu4pYxStFEFDhqMpKXJglL74uI4he09Xdv49hWCycOykLI1quOHDroPRCy3+iUIDHqEY s6qg== 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; bh=oEF6ZFY85c+wx7PqxQ1vyqpDhB/+HX6xxjxhqa/8hmk=; b=allV01pF1TSwTli+y8JhUjXGEPAbikvTrCg4NjA+B4fvMqjQfbwthyl2zlwRQ93XxK waVcjOlY82WS118LcZbXo7sC5eFuF6wyMkkAedVhSEezSGRL9O4CuSmd4+t/6NwgNfoz EDIXc7BGlgou+TJbpyCZk3a69zFePCs2JoNh+wTKpeNYU0XbQ3rK4BY68Ofg6yPCAXXY zLANw1FLaMEZl89DdNufXphyfCCxCpKt9maSigriW1nEIbrvvUHlOzq/dt6PKhaF+l6V N8uur3u8ycFw7pJ+YcQ4hE2MScPls1cn1AQJybvVGkKXmFYJRpwGCGLrXzDupbmTsQLR Q7PA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z185si65006948pfz.248.2019.08.13.17.07.56; Tue, 13 Aug 2019 17:08:26 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726688AbfHNAG0 (ORCPT + 99 others); Tue, 13 Aug 2019 20:06:26 -0400 Received: from mx2.suse.de ([195.135.220.15]:59556 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726102AbfHNAGZ (ORCPT ); Tue, 13 Aug 2019 20:06:25 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B7E88ACC6; Wed, 14 Aug 2019 00:06:23 +0000 (UTC) Date: Tue, 13 Aug 2019 17:06:16 -0700 From: Davidlohr Bueso To: Michel Lespinasse Cc: Peter Zijlstra , David Howells , Andrew Morton , LKML Subject: Re: [PATCH v2 2/3] augmented rbtree: add new RB_DECLARE_CALLBACKS_MAX macro Message-ID: <20190814000616.sd4mxwsewhqqz6ra@linux-r8p5> References: <20190702075819.34787-1-walken@google.com> <20190702075819.34787-3-walken@google.com> <20190702160913.ptg4p2jyb6ih43hb@linux-r8p5> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180323 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 02 Jul 2019, Michel Lespinasse wrote: >Ehhh, I have my own list of gripes about interval tree (I'm >responsible for some of these too): Sorry just getting back to this. > >- The majority of interval tree users (though either the >interval_tree.h or the interval_tree_generic.h API) do not store any >overlapping intervals, and as such they really don't have any reason >to use an augmented rbtree in the first place. This seems to be true >for at least drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c, >drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c, drivers/gpu/drm/drm_mm.c, >drivers/gpu/drm/radeon/radeon_mn.c, >drivers/infiniband/hw/usnic/usnic_uiom_interval_tree.c, and probably >(not 100% sure) also drivers/infiniband/hw/hfi1/mmu_rb.c and >drivers/vhost/vhost.c. I think the reason they do that is because they >like to have the auto-generated insert / remove / iter functions >rather than writing their own as they would have to do through the >base rbtree API. Not necessarily a huge problem but it is annoying >when working on inteval tree to consider that the data structure is >not optimal for most of its users. I think the patch I sent earlier will add to your unhappiness. > >- The intervals are represented as [start, last], where most >everything else in the kernel uses [start, end[ (with last == end - >1). The reason it was done that way was for stabbing queries - I >thought these would be nicer to represent as a [stab, stab] interval >rather than [stab, stab+1[. But, things didn't turn out that way >because of huge pages, and we end up with stabbing queries in the >[stab, stab + page_size - 1] format, at which point we could just as >easily go for [stab, stab + page_size[ representation. Having looked >into it, my understanding is that *all* current users of the interval >tree API would be better served if the intervals were represented as >[start, end[ like everywhere else in the kernel. > >- interval_tree_generic.h refers to interval_tree.h as being the >generic one. I think this is quite confusing. To me >interval_tree_generic is the generic implementation (it works with any >scalar ITTYPE), and interval_tree.h is the specialized version (it >works with unsigned long keys only). Fun fact, interval_tree.[c,h] was >initially only meant as sample / test code - I thought everyone would >use the generic version. Not a big deal, it's probably better for >everyone to use the specialized version when applicable (unless they >don't really need overlapping intervals in the first place, but that's >a separate gripe). > >- I don't like that interval tree API forces rb_leftmost caching on >its users. I'm not sure what was the use case that motivated it, but I >don' think it's a relevant optimization for most users - I can only >see a benefit if people are frequently calling the iter_first function >with a search interval that is to the left of the leftmost entry, and >that doesn't seem to be relevant to the general case (in the general >case, maintaining leftmost has a O(1) cost and its benefit is only >expected to show up in 1/N cases, ....) Right, so this was done originally for optimizing range locking which needed to do the iter_first a lot. fwiw pat_rbtree tree could also use it before insertion. While I did not examine the other users of interval_tree, I considered it overall worthwhile having; it comes at pretty much no cost and the extra footprint has not been a problem so far for users. > >Going back to your specific pat_rbtree.c comment, I think using >interval trees could still work. The issue with end is the typical one >([start, last] vs [start, end[) which can be worked around by >adjusting the end by 1 (still hate having to do that though). The >issue with insertion order may possibly not matter, as >memtype_rb_check_conflict verifies that any overlapping ranges will >have the same configured memory type. So maybe the order doesn't >matter in the end ??? Not 100% sure about that one. I've sent out a patch. Thanks, Davidlohr