fs: Remove i_devices from struct inode
Jan Kara
reviewerv3 cover fs: Remove i_devices from struct inode
Hello,
this patch set removes use of i_devices from block and character device
code and thus we can remove the list head from struct inode thus saving two pointers in it. As Christoph has reviewed the series, can you please merge it Al? Thanks!
Since v2 I've added reviewed-by tags from Christoph and changed one variable name in cdev_forget().
Since v1 I have split the patches and properly handled character devices (I broke them last time as Christoph pointed out).
Honza
Jan Kara
reviewerPATCH v3 1/4 blockdev: Don't use i_devices inode field
Block devices use i_devices inode field to track all inodes that reference a particular block device (through i_bdev field) so that this reference can be removed when block device inode is being evicted from memory. However we get a reference to the block device (in fact an inode holding the block device structure) when setting up i_bdev in bd_acquire() and we drop the reference only in bd_forget() when clearing i_bdev. Thus inode holding block device structure can be evicted only after all inodes referencing it are evicted and the whole excercise with i_devices is pointless. Remove the i_devices handling.
--- fs/block_dev.c | 17 +++-------------- include/linux/fs.h | 1 - 2 files changed, 3 insertions(+), 15 deletions(-)
fs/block_dev.c +3 -14
@@ -458,7 +458,6 @@ static void init_once(void *foo)memset (bdev,0 ,sizeof (*bdev));mutex_init (&bdev->bd_mutex); -INIT_LIST_HEAD (&bdev->bd_inodes);INIT_LIST_HEAD (&bdev->bd_list);#ifdef CONFIG_SYSFS INIT_LIST_HEAD (&bdev->bd_holder_disks);
@@ -468,24 +467,14 @@ static void init_once(void *foo)mutex_init (&bdev->bd_fsfreeze_mutex); } -static inline void __bd_forget (struct inode *inode) -{ -list_del_init (&inode->i_devices); - inode->i_bdev =NULL ; - inode->i_mapping = &inode->i_data; -} -static void bdev_evict_inode (struct inode *inode) {struct block_device *bdev = &BDEV_I (inode)->bdev; -struct list_head *p; +truncate_inode_pages_final (&inode->i_data);invalidate_inode_buffers (inode);/* is it needed here? */ clear_inode (inode);spin_lock (&bdev_lock); -while ( (p = bdev->bd_inodes.next) != &bdev->bd_inodes ) { -__bd_forget (list_entry(p ,struct inode ,i_devices )); - }list_del_init (&bdev->bd_list);spin_unlock (&bdev_lock); }
@@ -645,7 +634,6 @@ static struct block_device *bd_acquire(struct inode *inode)ihold (bdev->bd_inode); inode->i_bdev = bdev; inode->i_mapping = bdev->bd_inode->i_mapping; -list_add (&inode->i_devices, &bdev->bd_inodes); }spin_unlock (&bdev_lock); }
@@ -666,7 +654,8 @@ void bd_forget(struct inode *inode)spin_lock (&bdev_lock);if (!sb_is_blkdev_sb (inode->i_sb)) bdev = inode->i_bdev; -__bd_forget (inode); + inode->i_bdev =NULL ; + inode->i_mapping = &inode->i_data;spin_unlock (&bdev_lock);if (bdev)
include/linux/fs.h +0 -1
@@ -413,7 +413,6 @@ struct block_device {struct inode * bd_inode;/* will die */ struct super_block * bd_super;struct mutex bd_mutex;/* open/close mutex */ -struct list_head bd_inodes;void * bd_claiming;void * bd_holder;int bd_holders;
Signature · 1 line
1.8.1.4
Jan Kara
reviewerPATCH v3 2/4 chardev: Increment cdev reference count when i_cdev references it
In reply to Jan KaraCurrently i_cdev reference to a character device isn't accounted in the reference count of the character device. This then requires us to track all references through a list of all inodes referencing a character device which is somewhat clumsy and requires list_head in each inode in the system.
So make i_cdev a reference like any other.
--- fs/char_dev.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
fs/char_dev.c +9 -3
@@ -388,12 +388,13 @@ static int chrdev_open(struct inode *inode, struct file *filp)we dropped the lock. */ p = inode->i_cdev;if (!p) { +/* Use reference from kobj_lookup for i_cdev ref */ inode->i_cdev = p = new;list_add (&inode->i_devices, &p->list); new =NULL ; - }else if (!cdev_get (p)) - ret = -ENXIO ; - }else if (!cdev_get (p)) + } + } +if (!cdev_get (p)) ret = -ENXIO ;spin_unlock (&cdev_lock);cdev_put (new);
@@ -421,10 +422,15 @@ static int chrdev_open(struct inode *inode, struct file *filp)void cd_forget (struct inode *inode) { +struct cdev *to_put; +spin_lock (&cdev_lock);list_del_init (&inode->i_devices); + to_put = inode->i_cdev; inode->i_cdev =NULL ;spin_unlock (&cdev_lock); +if (to_put) +cdev_put (to_put); }static void cdev_purge (struct cdev *cdev)
Signature · 1 line
1.8.1.4
Jan Kara
reviewerPATCH v3 3/4 chardev: Don't use i_devices inode field
In reply to Jan KaraNow that character device can be freed only after all inodes referencing it through i_cdev are gone, we can remove all the tracking of inodes pointing to a character device.
--- fs/char_dev.c | 22 +--------------------- include/linux/cdev.h | 1 - 2 files changed, 1 insertion(+), 22 deletions(-)
fs/char_dev.c +1 -21
@@ -390,7 +390,6 @@ static int chrdev_open(struct inode *inode, struct file *filp)if (!p) {/* Use reference from kobj_lookup for i_cdev ref */ inode->i_cdev = p = new; -list_add (&inode->i_devices, &p->list); new =NULL ; } }
@@ -425,7 +424,6 @@ void cd_forget(struct inode *inode)struct cdev *to_put;spin_lock (&cdev_lock); -list_del_init (&inode->i_devices); to_put = inode->i_cdev; inode->i_cdev =NULL ;spin_unlock (&cdev_lock);
@@ -433,18 +431,6 @@ void cd_forget(struct inode *inode)cdev_put (to_put); } -static void cdev_purge (struct cdev *cdev) -{ -spin_lock (&cdev_lock); -while (!list_empty (&cdev->list)) { -struct inode *inode; - inode = container_of(cdev->list.next, struct inode, i_devices); -list_del_init (&inode->i_devices); - inode->i_cdev =NULL ; - } -spin_unlock (&cdev_lock); -} -/* * Dummy default file-operations: the only thing this does * is contain the open that then fills in the correct operations
@@ -515,10 +501,8 @@ void cdev_del(struct cdev *p)static void cdev_default_release (struct kobject *kobj) { - struct cdev *p = container_of(kobj, struct cdev, kobj);struct kobject *parent = kobj->parent; -cdev_purge (p);kobject_put (parent); }
@@ -527,7 +511,6 @@ static void cdev_dynamic_release(struct kobject *kobj) struct cdev *p = container_of(kobj, struct cdev, kobj);struct kobject *parent = kobj->parent; -cdev_purge (p);kfree (p);kobject_put (parent); }
@@ -548,10 +531,8 @@ static struct kobj_type ktype_cdev_dynamic = {struct cdev *cdev_alloc (void ) {struct cdev *p =kzalloc (sizeof (struct cdev ),GFP_KERNEL ); -if (p) { -INIT_LIST_HEAD (&p->list); +if (p)kobject_init (&p->kobj, &ktype_cdev_dynamic); - }return p; }
@@ -566,7 +547,6 @@ struct cdev *cdev_alloc(void)void cdev_init (struct cdev *cdev,const struct file_operations *fops) {memset (cdev,0 ,sizeof *cdev); -INIT_LIST_HEAD (&cdev->list);kobject_init (&cdev->kobj, &ktype_cdev_default); cdev->ops = fops; }
include/linux/cdev.h +0 -1
@@ -13,7 +13,6 @@ struct cdev {struct kobject kobj;struct module *owner;const struct file_operations *ops; -struct list_head list;dev_t dev;unsigned int count; };
Signature · 1 line
1.8.1.4
Jan Kara
reviewerPATCH v3 4/4 fs: Remove i_devices list head
In reply to Jan KaraNoone uses i_devices anymore. Remove it (thus saving two pointers in every inode).
--- fs/inode.c | 1 - include/linux/fs.h | 1 - 2 files changed, 2 deletions(-)
fs/inode.c +0 -1
@@ -366,7 +366,6 @@ void inode_init_once(struct inode *inode) {memset (inode,0 ,sizeof (*inode));INIT_HLIST_NODE (&inode->i_hash); -INIT_LIST_HEAD (&inode->i_devices);INIT_LIST_HEAD (&inode->i_wb_list);INIT_LIST_HEAD (&inode->i_lru);address_space_init_once (&inode->i_data);
include/linux/fs.h +0 -1
@@ -595,7 +595,6 @@ struct inode {#ifdef CONFIG_QUOTA struct dquot *i_dquot[MAXQUOTAS ];#endif -struct list_head i_devices;union {struct pipe_inode_info *i_pipe;struct block_device *i_bdev;
Signature · 1 line
1.8.1.4
Al Viro
maintainerQuoted 7 lines · Jan Kara
Hello,
this patch set removes use of
i_devicesfrom block and character device
code and thus we can remove the list head from struct inode thus saving two pointers in it. As Christoph has reviewed the series, can you please merge it Al? Thanks!
Quoted 5 lines
Since v2 I've added reviewed-by tags from Christoph and changed one variable name in
cdev_forget().Since v1 I have split the patches and properly handled character devices (I broke them last time as Christoph pointed out).
My problem with that is in buggered module refcounts (which was the reason for doing those non-counting references back then). Suppose you open /dev/some_char_device and close it; having the module pinned down until the inode of that sucker gets evicted by dcache/icache memory pressure would be wrong - it _isn't_ in use, and there's no way short of forcing the full eviction of VFS caches to get it possible to unload...
Quoted 14 lines · Al Viro
Quoted 7 lines · Jan Kara
Hello,
this patch set removes use of
i_devicesfrom block and character device
code and thus we can remove the list head from struct inode thus saving two pointers in it. As Christoph has reviewed the series, can you please merge it Al? Thanks!Quoted 5 lines
Since v2 I've added reviewed-by tags from Christoph and changed one variable name in
cdev_forget().Since v1 I have split the patches and properly handled character devices (I broke them last time as Christoph pointed out).
Quoted 7 lines
My problem with that is in buggered module refcounts (which was the reason for doing those non-counting references back then). Suppose you open
/dev/some_char_deviceand close it; having the module pinned down until the inode of that sucker gets evicted by dcache/icache memory pressure would be wrong - it _isn't_ in use, and there's no way short of forcing the full eviction of VFS caches to get it possible to unload...
At the risk of asking what may be a rather dumb question...
Why do device node inodes need to be cached at all? In other words, when you try open a device node, can't the kernel materialize the inode from just information that's in the dentry without touching the filesystem at all? If that's true, couldn't all device inodes be dropped from icache as soon as they're unreferenced?
(Yes, there's mtime, but I never understood why tracking mtime on device nodes made any sense in the first place.)
--Andy
Quoted 25 lines · Andy Lutomirski
Quoted 14 lines · Al Viro
Quoted 7 lines · Jan Kara
Hello,
this patch set removes use of
i_devicesfrom block and character device
code and thus we can remove the list head from struct inode thus saving two pointers in it. As Christoph has reviewed the series, can you please merge it Al? Thanks!Quoted 5 lines
Since v2 I've added reviewed-by tags from Christoph and changed one variable name in
cdev_forget().Since v1 I have split the patches and properly handled character devices (I broke them last time as Christoph pointed out).
Quoted 7 lines
My problem with that is in buggered module refcounts (which was the reason for doing those non-counting references back then). Suppose you open
/dev/some_char_deviceand close it; having the module pinned down until the inode of that sucker gets evicted by dcache/icache memory pressure would be wrong - it _isn't_ in use, and there's no way short of forcing the full eviction of VFS caches to get it possible to unload...At the risk of asking what may be a rather dumb question...
Quoted 8 lines
Why do device node inodes need to be cached at all? In other words, when you try open a device node, can't the kernel materialize the inode from just information that's in the dentry without touching the filesystem at all? If that's true, couldn't all device inodes be dropped from icache as soon as they're unreferenced?
(Yes, there's mtime, but I never understood why tracking mtime on device nodes made any sense in the first place.)
On further reflection, this is indeed a dumb question. i_rdev is in the inode, so of course the inode is useful.
Let me try again, though: what if a chardev inode replaced i_cdev with NULL and dropped its kobj reference in iput_final? This would add a bit over overhead to things that repeatedly open and close the same device node, but I doubt this matters much.
--Andy
Al Viro
maintainerQuoted 4 lines · Andy Lutomirski
Let me try again, though: what if a chardev inode replaced
i_cdevwith NULL and dropped its kobj reference iniput_final? This would add a bit over overhead to things that repeatedly open and close the same device node, but I doubt this matters much.
How is it different from what Jan proposed? The whole problem is that iput_final() is too late. We could clean the reference on close, all right, and have it looked up again on every open, but I'm not at all sure that situation with opening/closing cdev is never a hot path, especially with udev playing silly buggers, etc.
Quoted 7 lines · Al Viro
Quoted 4 lines · Andy Lutomirski
Let me try again, though: what if a chardev inode replaced
i_cdevwith NULL and dropped its kobj reference iniput_final? This would add a bit over overhead to things that repeatedly open and close the same device node, but I doubt this matters much.
Quoted 5 lines
How is it different from what Jan proposed? The whole problem is that
iput_final()is too late. We could clean the reference on close, all right, and have it looked up again on every open, but I'm not at all sure that situation with opening/closing cdev is never a hot path, especially with udev playing silly buggers, etc.
I thought the issue was inodes on the LRU list holding references open.
Anyway, the only expensive part of recreating the reference seems to be kobj_lookup, and that doesn't look so bad. If there's a case where the performance impact would matter at all, maybe that's an argument for fixing it.
And is udev really opening the same device node more than once? I can see once for blkid and such, but I don't see where a second open call would come from.
--Andy
Jan Kara
reviewerQuoted 25 lines · Andy Lutomirski
Quoted 14 lines · Al Viro
Quoted 7 lines · Jan Kara
Hello,
this patch set removes use of
i_devicesfrom block and character device
code and thus we can remove the list head from struct inode thus saving two pointers in it. As Christoph has reviewed the series, can you please merge it Al? Thanks!Quoted 5 lines
Since v2 I've added reviewed-by tags from Christoph and changed one variable name in
cdev_forget().Since v1 I have split the patches and properly handled character devices (I broke them last time as Christoph pointed out).
Quoted 7 lines
My problem with that is in buggered module refcounts (which was the reason for doing those non-counting references back then). Suppose you open
/dev/some_char_deviceand close it; having the module pinned down until the inode of that sucker gets evicted by dcache/icache memory pressure would be wrong - it _isn't_ in use, and there's no way short of forcing the full eviction of VFS caches to get it possible to unload...At the risk of asking what may be a rather dumb question...
Quoted 8 lines
Why do device node inodes need to be cached at all? In other words, when you try open a device node, can't the kernel materialize the inode from just information that's in the dentry without touching the filesystem at all? If that's true, couldn't all device inodes be dropped from icache as soon as they're unreferenced?
(Yes, there's mtime, but I never understood why tracking mtime on device nodes made any sense in the first place.)
I can see a few reasons:
1) positive dentry without inode - no-no for dcache.
2) how would you get the information which device the dentry references?
3) what would you gain to outweight the complications and special code paths?
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 32 lines · Jan Kara
Quoted 31 lines · Andy Lutomirski
Quoted 14 lines · Al Viro
Quoted 7 lines · Jan Kara
Hello,
this patch set removes use of
i_devicesfrom block and character device
code and thus we can remove the list head from struct inode thus saving two pointers in it. As Christoph has reviewed the series, can you please merge it Al? Thanks!Quoted 5 lines
Since v2 I've added reviewed-by tags from Christoph and changed one variable name in
cdev_forget().Since v1 I have split the patches and properly handled character devices (I broke them last time as Christoph pointed out).
Quoted 7 lines
My problem with that is in buggered module refcounts (which was the reason for doing those non-counting references back then). Suppose you open
/dev/some_char_deviceand close it; having the module pinned down until the inode of that sucker gets evicted by dcache/icache memory pressure would be wrong - it _isn't_ in use, and there's no way short of forcing the full eviction of VFS caches to get it possible to unload...At the risk of asking what may be a rather dumb question...
Why do device node inodes need to be cached at all? In other words, when you try open a device node, can't the kernel materialize the inode from just information that's in the dentry without touching the filesystem at all? If that's true, couldn't all device inodes be dropped from icache as soon as they're unreferenced?
Quoted 8 lines
Quoted 2 lines
(Yes, there's mtime, but I never understood why tracking mtime on device nodes made any sense in the first place.)
I can see a few reasons:
1) positive dentry without inode - no-no for dcache.
2) how would you get the information which device the dentry references?
3) what would you gain to outweight the complications and special code paths?
Yeah, this idea clearly doesn't work. But I wonder whether the revised variant (which may be just moving cd_forget and bd_forget from evict to iput_final) would work.
--Andy
Quoted 4 lines
Honza
--
Jan Kara <[email protected]>
SUSE Labs, CR
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
Al Viro
maintainerQuoted 3 lines · Andy Lutomirski
Yeah, this idea clearly doesn't work. But I wonder whether the revised variant (which may be just moving
cd_forgetandbd_forgetfrom evict toiput_final) would work.
How the hell is it better? Neither of those will happen as long as dentry is retained. And with /dev on tmpfs (which is bloody common) _that_ won't happen until device node is unlinked...
Quoted 9 lines · Al Viro
Quoted 3 lines · Andy Lutomirski
Yeah, this idea clearly doesn't work. But I wonder whether the revised variant (which may be just moving
cd_forgetandbd_forgetfrom evict toiput_final) would work.How the hell is it better? Neither of those will happen as long as dentry is retained. And with /dev on tmpfs (which is bloody common) _that_ won't happen until device node is unlinked...
It's by my misunderstanding of how inode refcounting works. The idea would be to drop the cdev reference when there are no non-VFS-internal references to the inode left.