Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757310AbcLPUcW (ORCPT ); Fri, 16 Dec 2016 15:32:22 -0500 Received: from mail-wm0-f49.google.com ([74.125.82.49]:38679 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753210AbcLPUcO (ORCPT ); Fri, 16 Dec 2016 15:32:14 -0500 From: Rasmus Villemoes To: Matthew Wilcox Cc: Tejun Heo , "linux-kernel\@vger.kernel.org" , Lai Jiangshan , "Jens Axboe" , Greg Kroah-Hartman , "linux-block\@vger.kernel.org" , "dri-devel\@lists.freedesktop.org" , "Andrew Morton" Subject: Re: [RFC 00/10] implement alternative and much simpler id allocator Organization: D03 References: <1481160187-9652-1-git-send-email-linux@rasmusvillemoes.dk> <20161209140140.5e0a68e2e1cf9861335bdf3b@linux-foundation.org> X-Hashcash: 1:20:161216:gregkh@linuxfoundation.org::s4LAPK+xtYlz0aeD:0000000000000000000000000000000000033dS X-Hashcash: 1:20:161216:tj@kernel.org::OJBFFe+F1gRNqhDP:00004MCz X-Hashcash: 1:20:161216:linux-kernel@vger.kernel.org::nGeTUDBM4qIShnEu:00000000000000000000000000000000068bB X-Hashcash: 1:20:161216:akpm@linux-foundation.org::/4EJcRtaf23y4dkb:0000000000000000000000000000000000006YXa X-Hashcash: 1:20:161216:jiangshanlai@gmail.com::5/Rfy/bSLqakvtHG:0000000000000000000000000000000000000006K3Z X-Hashcash: 1:20:161216:dri-devel@lists.freedesktop.org::P6GXqKXSGWQps1Zw:0000000000000000000000000000008LQk X-Hashcash: 1:20:161216:linux-block@vger.kernel.org::pnLbdex4budMRY5y:00000000000000000000000000000000006M1n X-Hashcash: 1:20:161216:axboe@kernel.dk::O4XwAu3uPT//G8cL:00BYJM X-Hashcash: 1:20:161216:mawilcox@microsoft.com::diw1we/1lhwrFLCq:000000000000000000000000000000000000000GGuX Date: Fri, 16 Dec 2016 21:32:11 +0100 In-Reply-To: (Matthew Wilcox's message of "Fri, 16 Dec 2016 19:14:11 +0000") Message-ID: <87inqj8vjo.fsf@rasmusvillemoes.dk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2906 Lines: 58 On Fri, Dec 16 2016, Matthew Wilcox wrote: > From: Andrew Morton [mailto:akpm@linux-foundation.org] >> On Thu, 8 Dec 2016 02:22:55 +0100 Rasmus Villemoes >> wrote: >> > TL;DR: these patches save 250 KB of memory, with more low-hanging >> > fruit ready to pick. >> > >> > While browsing through the lib/idr.c code, I noticed that the code at >> > the end of ida_get_new_above() probably doesn't work as intended: Most >> > users of ida use it via ida_simple_get(), and that starts by >> > unconditionally calling ida_pre_get(), ensuring that ida->idr has >> > 8==MAX_IDR_FREE idr_layers in its free list id_free. In the common >> > case, none (or at most one) of these get used during >> > ida_get_new_above(), and we only free one, leaving at least 6 (usually >> > 7) idr_layers in the free list. >> >> I expect we'll be merging patches 1-32 of that series into 4.10-rc1 and >> the above patch (#33) into 4.11-rc1. > > Hi Rasmus, > > Thanks for your work on this; you've really put some effort into > proving your work has value. My motivation was purely aesthetic, but > you've got some genuine savings here (admittedly it's about a quarter > of a cent's worth of memory with DRAM selling for $10/GB). > Nevertheless, that adds up over a billion devices, and there are still > people trying to fit Linux into 4MB embedded devices. > Yeah, my main motivation was embedded devices which don't have the luxury of measuring their RAM in GB. E.g., it's crazy that the watchdog_ida effectively use more memory than the .text of the watchdog subsystem, and similarly for the kthread workers, etc., etc.. I didn't mean for my patches to go in as is, more to provoke some discussion. I wasn't aware of your reimplementation, but it seems that may make the problem go away. > I think my reimplementation of the IDA on top of the radix tree is > close enough to your tIDA in memory consumption that it doesn't > warrant a new data structure. > > On a 64-bit machine, your tIDA root is 24 bytes; my new IDA root is 16 > bytes. If you allocate only one entry, you'll allocate 8 bytes. > Thanks to the slab allocator, that gets rounded up to 32 bytes. I > allocate the full 128 byte leaf, but I store the pointer to it in the > root (unlike the IDR, the radix tree doesn't need to allocate a layer > for a single entry). So tIDA wins on memory consumption between 1 and > 511 IDs, and newIDA is slightly ahead between 512 and 1023 IDs. This sounds good. I think there may still be a lot of users that never allocate more than a handful of IDAs, making a 128 byte allocation still somewhat excessive. One thing I considered was (exactly as it's done for file descriptor tables) to embed a single word in the struct ida and use that initially; I haven't looked closely at newIDA, so I don't know how easy that would be or if its worth the complexity. Rasmus