From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933585AbcBQB0j (ORCPT ); Tue, 16 Feb 2016 20:26:39 -0500 Received: from jackal.aluminati.org ([72.9.247.210]:58264 "EHLO jackal.aluminati.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933123AbcBQB0i (ORCPT ); Tue, 16 Feb 2016 20:26:38 -0500 X-Quarantine-ID: X-Spam-Flag: NO X-Spam-Score: -0.2 Subject: Re: Idea for reducing sysfs memory usage To: Greg Kroah-Hartman References: <56C3B4E9.7030207@cantab.net> <20160216235502.GA14565@kroah.com> <56C3C0D2.9090407@cantab.net> <20160217004730.GA7558@kroah.com> Cc: linux-kernel@vger.kernel.org, David Ahern From: Edward Cree Message-ID: <56C3CC43.8060706@cantab.net> Date: Wed, 17 Feb 2016 01:26:27 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.4.0 MIME-Version: 1.0 In-Reply-To: <20160217004730.GA7558@kroah.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17/02/16 00:47, Greg Kroah-Hartman wrote: > How many sysfs entries are you creating for that 20kb? And how did you > measure it? If you don't access the files, the backing store is not > allocated, saving you a lot of memory. Thinking about this some more, could we not do the same thing with the struct kernfs_nodes, i.e. only allocate them when someone first accesses the file? Or simpler, defer allocation of all the files in the dir until someone first touches the directory? Of course it would add a little latency to that first access, but (barring differences in cache warmth) it would subtract the same amount of time from the initial dir creation, and in the case where no-one ever looks at the directory, it would save the memory. I did find a patch series from 2009 doing something vaguely similar[1], but a) it looks like it wasn't applied and b) it appears to involve a function pointer in struct sysfs_elem_dir to say how to populate the directory. All we need here is to get our kobj (which we have in priv member of struct kernfs_node) and call populate_dir(). (And remove whatever flag or mark we used to say "not populated yet". And some locking will be needed.) Again, no hard numbers on how much memory this would save, nor evidence that the "no-one ever touches the dir" case happens in practice... [1] http://thread.gmane.org/gmane.linux.kernel/904418 -- -ed