Re: [Patch] Delete sysfs_dirent.s_count, saving ~100kB on my system

From: Maneesh Soni
Date: Mon Nov 22 2004 - 18:00:44 EST


On Tue, Nov 23, 2004 at 03:17:33AM +0800, Adam J. Richter wrote:
> The following patch against linux-2.6.10-rc2-bk6 removes
> the s_count field from sysfs_dirent. This reduces sizeof(sysfs_dirent)
> from 36 to 32 bytes on 32-bit machines, resulting in big space
> savings because it reduces the size that kmalloc actually uses for
> the allocation from 64 to 32 bytes, and there is one of these for
> every node in sysfs, of which there are 3405 on the modest desktop
> machine that I'm using to compose this email. That's a savings of
> 108,960 bytes of unswappable kernel memory in this case.
>
> Reference counting appears to me to be unnecessary on this
> data structure. sysfs_dirent exists when a node name is registered in
> sysfs, and it does not exist when the node name is not registered.
> It does not matter if a program is still holding a reference to the
> struct inode when sysfs_dirent is deleted, since sysfs_dirent is only
> relevant to directory lookup operations. It also should not matter if the
> system is freeing the struct inode and the struct dentry to save
> space. As long as the file is registered in sysfs, the sysfs_dirent
> is not freed.
>
> Removing sysfs_dirent.s_count results in the removal of other
> supporting code, including sysfs_dentry_ops, for a net deletion of
> 39 lines of code.
>
> I have only tested this patch by mounting /sys, and running
> some "find" commands on it, plugging and unplugging a USB device,
> and verifying that the number of entries in sysfs increased and
> decreased accordingly. I am running it on the system on which I
> am composing this email.
>

The idea for having ref count for sysfs_dirent was to keep the sysfs_dirents
around as long as there are live dentries corresponding to sysfs objects.
There can be open files (live dentries) but files getting removed. IMO,
without having ref count for sysfs_dirent, we could end up loosing the
sysfs_dirent and end up in inconsistent sysfs_dirent tree with respect to
dentry tree. If we could maintain the consistency without refcounts then
it is good to reduce the size of sysfs_dirent structure.

Could you also test the patch like this, on an SMP box. Basically
opening/closing sysfs files and simultaneously inserting & removing dummy
module. This is just to make sure that we don't have any races
particularly in dir and file operations. I will also test the patch tonight.

# while true; do find /sys/class/net/ | xargs cat; done
# while true; do insmod dummy.ko; rmmod dummy; done
# while true; do ls -lR /sys > /dev/null; done


Thanks
Maneesh

--
Maneesh Soni
Linux Technology Center,
IBM Austin
email: maneesh@xxxxxxxxxx
Phone: 1-512-838-1896 Fax:
T/L : 6781896
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/