Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758843AbcLPVpw (ORCPT ); Fri, 16 Dec 2016 16:45:52 -0500 Received: from mail-sn1nam01on0106.outbound.protection.outlook.com ([104.47.32.106]:11314 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758597AbcLPVpl (ORCPT ); Fri, 16 Dec 2016 16:45:41 -0500 X-Greylist: delayed 2191 seconds by postgrey-1.27 at vger.kernel.org; Fri, 16 Dec 2016 16:45:41 EST From: Matthew Wilcox To: Rasmus Villemoes 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 Thread-Topic: [RFC 00/10] implement alternative and much simpler id allocator Thread-Index: AQHSUme+SjIWPmjllE++nkCQM7WotKEKtg/Q Date: Fri, 16 Dec 2016 19:14:11 +0000 Message-ID: References: <1481160187-9652-1-git-send-email-linux@rasmusvillemoes.dk> <20161209140140.5e0a68e2e1cf9861335bdf3b@linux-foundation.org> In-Reply-To: <20161209140140.5e0a68e2e1cf9861335bdf3b@linux-foundation.org> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=mawilcox@microsoft.com; x-originating-ip: [104.247.244.59] x-ms-office365-filtering-correlation-id: 4eea703a-b5d7-4fee-6c6a-08d425e7b81e x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:BY2PR21MB0035; x-microsoft-exchange-diagnostics: 1;BY2PR21MB0035;7:x5eArkfJzBNkirH+VOq0+I230JC8oAzyfjMC0UaV0IoLEEaN46RkkDYoPOCBtykaXone4/CiRbc8xm/n1p0qtukx800EUWERWfsll52Eb0Egf5OrP8sMEJzlX/Zcuv0+WqnrcOuhM8DeeGkLsiG3beOFz+3BA8K/1wWBlg4UWoiLtEM9FiSuiqL5O4NS9TsK+63qc9WuLWXeb9JmvJLHBE5VEWChuX0ZAb9K5MO4pHwTxo7cH12jhG2cmjB9VNNPW8aSEb4+OI2t9nzbJpB1myQIToVgPnoGvV8/iATZvZ/k66PxFKAGxjZeekh1rv6hYtrKKOyOD0y7VJX28V+XJdsbp9tzxLjXDx+nA95kb/y63zSb0DdfY+nLXD65xPoUx0q1JvaocJM9QnUMfQZF3VaUAKgBKY7XVTnKFm6uLnQ93Q7X82/eCWLnxhrzaba7ypjPDtPEJC+HeCM1xzj4iuMYnQrTKCB93uC9B7zLF/4= x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026)(61426038)(61427038)(6041248)(20161123564025)(20161123560025)(20161123558021)(20161123562025)(20161123555025)(6072148);SRVR:BY2PR21MB0035;BCL:0;PCL:0;RULEID:;SRVR:BY2PR21MB0035; x-forefront-prvs: 01583E185C x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(7916002)(39450400003)(39840400002)(39410400002)(39850400002)(39860400002)(189002)(24454002)(199003)(77096006)(39060400001)(38730400001)(76576001)(92566002)(6506006)(74316002)(33656002)(7736002)(305945005)(105586002)(99286002)(2900100001)(106356001)(229853002)(106116001)(189998001)(6116002)(122556002)(3280700002)(86612001)(4001150100001)(3660700001)(97736004)(86362001)(3846002)(81166006)(54356999)(8676002)(50986999)(8936002)(25786008)(102836003)(110136003)(10090500001)(101416001)(6436002)(81156014)(2906002)(76176999)(7696004)(4326007)(5005710100001)(6916009)(8990500004)(10290500002)(68736007)(9686002)(2950100002)(66066001)(5660300001);DIR:OUT;SFP:1102;SCL:1;SRVR:BY2PR21MB0035;H:BY2PR21MB0036.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Dec 2016 19:14:11.9664 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR21MB0035 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id uBGLjtjB005796 Content-Length: 2739 Lines: 27 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. 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. Above 1024 IDs, I allocate a layer (576 bytes), and a second leaf (832 bytes total), while you just double to 256 bytes. I think tIDA's memory consumption then stays ahead of new IDA. But performance of 'allocate new ID' should be better for newIDA than tIDA as newIDA can skip over all the cachelines of full bitmaps. Yesterday, I found a new problem with the IDA allocator that you hadn't mentioned -- about half of the users of the IDA data structure never call destroy_ida(). Which means that they're leaking the preloaded bitmap. I have a patch which moves the preloaded IDA bitmap from being stored in the IDA to being stored in a percpu variable. You can find it here: http://git.infradead.org/users/willy/linux-dax.git/shortlog/refs/heads/idr-2016-12-16 I'd welcome more testing and code review.