Received: by 10.223.176.5 with SMTP id f5csp1065702wra; Fri, 9 Feb 2018 11:50:53 -0800 (PST) X-Google-Smtp-Source: AH8x227yPjn1BzCzFJcJpePE86HIeiYQ+hPXd6lHuM4tVliZCL+aKKqA0YtRZdC3OUI9Hq7jORsR X-Received: by 2002:a17:902:a03:: with SMTP id 3-v6mr3563504plo.282.1518205852960; Fri, 09 Feb 2018 11:50:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518205852; cv=none; d=google.com; s=arc-20160816; b=oydM8N2NbfkbfftbO6jM6uw99C69GfaEOzbs6EX/YUfXZbrvWn3/2p9XdT+WOrFDpb VnTNB/ngqkZtAGFGYcJzqF9ya1QlF2T+qLGqn5ibHlOGVxv01FE//z90uARA2xuXa+sU a3rpWcD9T7AA39WQ1vJPrlGKvFWrKY8v9D0sOeDqcJl8JIeBbuMW6P0ijBkhmwI+2AnD 5CD1e4pb8wcuYj+OEBs746zdy8oGXfTep2gowVZ5idrF6uhI1f9j6vB/quMakl9u179Y vSToskKHihx+1D/nTPXVr9Y5QgyOYB7jTmfbG+LVs9NxOwbk4AlHxPn/Vq1PZ8JLBalf nifQ== 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:arc-authentication-results; bh=OzTfKLuCNEOLL0/CxmWOcWfK3/k/+cC/sLkxFQHWn5Y=; b=vZKTQY3Dz9sxzHmwgg4WH0ceLYzpErbsq4M0Us/C79bEoLSIrRQq/eCeltcUXbpMm4 j6M0zSP56gFz4tOhvIw7UjEr/vS7MU22HRDMt70Sjcw4GdZZixn9n9QdaV7hdRjyrzyC Oryx51Ff/Ol8wL9gM/P5P5I4pZBslvcHvjkv5PayvFeIgSr1ICZzF7LJb4bryE84Sv27 udGja755SD3MDj4ZmAFx4aVh5OOYq/PvYG+MA7mFD0siD45rL5tCgHA8bl8ERR5R6q6H 08BiwEb1pt+KUYl46YxFzSB3h0L2x9MslF0Gai2MFJMCfUjYmrRXUalghcmRiDvYxBF0 mWBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=X3Zc4fcC; 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 g2si1743365pgu.737.2018.02.09.11.50.25; Fri, 09 Feb 2018 11:50:52 -0800 (PST) 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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=X3Zc4fcC; 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 S1752519AbeBITqw (ORCPT + 99 others); Fri, 9 Feb 2018 14:46:52 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:60361 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750933AbeBITqv (ORCPT ); Fri, 9 Feb 2018 14:46:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=OzTfKLuCNEOLL0/CxmWOcWfK3/k/+cC/sLkxFQHWn5Y=; b=X3Zc4fcC7UKEOoQG/PfCHRsMt ngRRODrRPMuaLYRgo6OWig1fIr1FeLwloLZCcKIz1h7BuWEystT1FlyAL5l2bmOYCDqC1R4jOT2Ij SuYYkogCnu4OH7HXmtPTchBjTO0hZKe23z2EAEZkUnIkyMhY7QUjk1y5fT4Rw9x6ujhYWBCer4POp 7b+RwvL9cFv+OkiCWZedbJ/8IVcXxkZYuJ+HCFupkh9lzKDnuwvaNnuGBOSSP82qzjYE5jEJc9FvG 4qJZTuXnIoXT7DYkKDQqY+pQiInF6w7zkY8ME/Bk0yU4zHJHEEjlKHuaHBdv3apMglMC4jEgry26F +/kXgRwYQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.89 #1 (Red Hat Linux)) id 1ekEdG-0003PG-BJ; Fri, 09 Feb 2018 19:46:50 +0000 Date: Fri, 9 Feb 2018 11:46:50 -0800 From: Matthew Wilcox To: Chris Wilson Cc: linux-kernel@vger.kernel.org, Tejun Heo , Eric Biggers , Daniel Vetter , Chris Mi Subject: Re: [RFC] Rebasing the IDR Message-ID: <20180209194650.GH16666@bombadil.infradead.org> References: <20171130173630.GA15948@bombadil.infradead.org> <151298969175.4445.1226930193594726551@mail.alporthouse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <151298969175.4445.1226930193594726551@mail.alporthouse.com> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 11, 2017 at 10:54:51AM +0000, Chris Wilson wrote: > Quoting Matthew Wilcox (2017-11-30 17:36:30) > > About 40 of the approximately 180 users of the IDR in the kernel are > > "1-based" instead of "0-based". That is, they never want to have ID 0 > > allocated; they want to see IDs allocated between 1 and N. Usually, that's > > expressed like this: > > > > /* Get the user-visible handle using idr. */ > > ret = idr_alloc(&file_priv->object_idr, obj, 1, 0, GFP_KERNEL); > > > > The current implementation of this grieves me. You see, we mark each > > node of the radix tree according to whether it has any free entries > > or not, and entry 0 is always free! If we've already allocated 10,000 > > entries from this IDR, and see this call, we'll walk all the way down > > the left side of the tree looking for entry 1, get to the bottom, > > see that entries 1-63 are allocated, then walk up to the next level, > > see that 64-4095 are allocated, walk up to the next level, see that > > 8192-12287 has a free entry, and then start walking down again. > > Hmm, missing the baseline to apply this patch. But I did the quick hack > of allocating index 0 of the idr and that did eradicate the > idr_get_free_cmn() from being at the top of the profiles for the > many-object stress tests. This improvement will be much appreciated. Hi Chris, The new IDR implementation is now in Linus' tree. For any IDR that you want to be 1s based, initialise it using idr_init_base() instead of idr_init() and it will magically be more efficient. I did a quick example on the first IDR which matched $ git grep 'idr_alloc.*, 1,' drivers/gpu diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c index bd6e9a40f421..c35ea6695fee 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c @@ -844,7 +844,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) } mutex_init(&fpriv->bo_list_lock); - idr_init(&fpriv->bo_list_handles); + idr_init_base(&fpriv->bo_list_handles, 1); amdgpu_ctx_mgr_init(&fpriv->ctx_mgr); Let me know if you run into any problems using it; there are test-cases in the test-suite, but I may have missed something.