A new way of attaching information to inodes
Subsystems (4)
Jan Kara
reviewercover A new way of attaching information to inodes
Hi,
currently our VFS inode structure is quite big. It contains quite some
members that are useful only in some cases (e.g. device pointers and list head used only when the inode represents a block/character device, quota pointers used only when the filesystem actually supports quota, etc.). And it would be helpful to add some more so that we can handle ACL's in generic code, or we can do some kind of block reservation for mmaped writes, and there are other cases.
So I though it may be worth a try to come up with a way to attach info to
inode structure so that generic code can look it up (or find it's not there), it's space effective and on the other hand the access does not cost us too much.
What I've come up with is that each inode could have a pointer to a (usually
static) table of offsets of structures associated with the inode. Filesystem would then carry the structures it is interested in in it's private inode.
As an example, I've converted quota pointers from inode to use this feature
and ext2 filesystem so that we have some rough idea how the resulting code looks like. IMO from the filesystem's POV it's quite fine, the generic code gets a bit less obvious but it's bearable as well. Regarding the speed, we impose additinal lookup in the table and an addition of the offset from the table so it should be IMHO acceptable cost for things that are not really fast path.
What do you think? Your opinions and suggestions are welcome...
Honza
Jan Kara
reviewerPATCH 1/2 Implement trivial struct feature macros
Sometimes it is useful to have a generic main structure (like struct inode) and then with some of these structures you want to associate additional information (like quota information, block device information etc.). Traditionally, we solved this by having a pointer to associated data in the generic structure. This gets inefficient when there are lots of various kinds of data that can be associated with the generic structure (we need one pointer per type of associated information). This is an attempt to address the issue.
The idea is simple. There is some chunk of allocated memory that contains the generic structure and all the associated information. The generic structure has a pointer to the (usually static) table of offsets (from the beginning of the generic structure) of associated structures for each possible associated structure type.
--- include/linux/fs.h | 5 +++++ include/linux/struct_feature.h | 12 ++++++++++++ 2 files changed, 17 insertions(+), 0 deletions(-) create mode 100644 include/linux/struct_feature.h
include/linux/fs.h +5 -0
@@ -710,6 +710,10 @@ static inline int mapping_writably_mapped(struct address_space *mapping)#define i_size_ordered_init (inode) do { } while (0)#endif +enum { +INODE_FEATURES +}; +struct inode {struct hlist_node i_hash;struct list_head i_list;
@@ -775,6 +779,7 @@ struct inode {void *i_security;#endif void *i_private;/* fs or device private pointer */ +int *feature_table; };/*
include/linux/struct_feature.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef _LINUX_STRUCT_FEATURE_H +#define _LINUX_STRUCT_FEATURE_H + + +#define FEATURE_OFFSET (str, generic, feature) (offsetof(str, feature) - offsetof(str, generic)) + +#define GET_FEATURE (generic, feature) \ + ((generic)->feature_table && (generic)->feature_table[feature] ? \ + ((void *)(((char *)(generic)) + (generic)->feature_table[feature])) : \ + NULL) + +#endif
Signature · 1 line
1.6.0.2
Re: [PATCH 1/2] Implement trivial struct feature macros
Quoted 51 lines · Jan Kara
Sometimes it is useful to have a generic main structure (like struct inode) and then with some of these structures you want to associate additional information (like quota information, block device information etc.). Traditionally, we solved this by having a pointer to associated data in the generic structure. This gets inefficient when there are lots of various kinds of data that can be associated with the generic structure (we need one pointer per type of associated information). This is an attempt to address the issue.
The idea is simple. There is some chunk of allocated memory that contains the generic structure and all the associated information. The generic structure has a pointer to the (usually static) table of offsets (from the beginning of the generic structure) of associated structures for each possible associated structure type.
Signed-off-by Jan Kara <[email protected]>--- include/linux/fs.h | 5 +++++ include/linux/struct_feature.h | 12 ++++++++++++ 2 files changed, 17 insertions(+), 0 deletions(-) create mode 100644 include/linux/struct_feature.hinclude/linux/fs.h +5
-0@@ -710,6 +710,10 @@ static inline int mapping_writably_mapped(struct address_space *mapping)#define i_size_ordered_init (inode) do { } while (0)#endif +enum { +INODE_FEATURES +}; +struct inode {struct hlist_node i_hash;struct list_head i_list;@@ -775,6 +779,7 @@ struct inode {void *i_security;#endif void *i_private;/* fs or device private pointer */ +int *feature_table; };/* include/linux/struct_feature.h new file +0
-0
include/linux/struct_feature.h line 10
Quoted 10 lines
include/linux/struct_feature.h new file +10
-0@@ -0,0 +1,12 @@ +#ifndef _LINUX_STRUCT_FEATURE_H +#define _LINUX_STRUCT_FEATURE_H + + +#define FEATURE_OFFSET (str, generic, feature) (offsetof(str, feature) - offsetof(str, generic)) + +#define GET_FEATURE (generic, feature) \ + ((generic)->feature_table && (generic)->feature_table[feature] ? \ + ((void *)(((char *)(generic)) + (generic)->feature_table[feature])) : \ + NULL)
These should be inlines.
Also I don't think we should make it super-generic. If we'll eventually need it it should be specific to struct inode, something like:
static void *get_inode_extension(struct inode *inode, emum inode_extension ext)
{
if (!inode->i_extensions[ext])
return NULL;
return (char *)inode + inode->i_extensions[ext];
}Jan Kara
reviewerPATCH 2/2 Use feature code to eliminate quota pointers from inodes for filesystems that don't need it.
In reply to Jan Kara--- fs/ext2/ext2.h | 1 + fs/ext2/super.c | 5 ++ fs/inode.c | 7 ++- fs/nilfs2/mdt.c | 3 - fs/quota/dquot.c | 134 ++++++++++++++++++++++++++++++---------------------- include/linux/fs.h | 10 +++- 6 files changed, 97 insertions(+), 63 deletions(-)
fs/ext2/ext2.h +1 -0
@@ -62,6 +62,7 @@ struct ext2_inode_info {struct mutex truncate_mutex;struct inode vfs_inode;struct list_head i_orphan;/* unlinked but open inodes */ +struct inode_quota i_quota; };/*
fs/ext2/super.c +5 -0
@@ -32,6 +32,7 @@#include <linux/mount.h> #include <linux/log2.h> #include <linux/quotaops.h> +#include <linux/struct_feature.h> #include <asm/uaccess.h> #include "ext2.h" #include "xattr.h"
@@ -139,6 +140,9 @@ static void ext2_put_super (struct super_block * sb) }static struct kmem_cache * ext2_inode_cachep; +static int ext2_i_features[INODE_FEATURES ] = { + [INODE_QUOTA] = FEATURE_OFFSET(struct ext2_inode_info, vfs_inode, i_quota), +};static struct inode *ext2_alloc_inode (struct super_block *sb) {
@@ -152,6 +156,7 @@ static struct inode *ext2_alloc_inode(struct super_block *sb)#endif ei->i_block_alloc_info =NULL ; ei->vfs_inode.i_version =1 ; + ei->vfs_inode.feature_table = ext2_i_features;return &ei->vfs_inode; }
fs/inode.c +6 -1
@@ -24,6 +24,7 @@#include <linux/inotify.h> #include <linux/mount.h> #include <linux/async.h> +#include <linux/struct_feature.h> /* * This is needed for the following functions:
@@ -141,7 +142,11 @@ struct inode *inode_init_always(struct super_block *sb, struct inode *inode) inode->i_bytes =0 ; inode->i_generation =0 ;#ifdef CONFIG_QUOTA -memset (&inode->i_dquot,0 ,sizeof (inode->i_dquot)); + { +struct inode_quota *iq =GET_FEATURE (inode,INODE_QUOTA ); +if (iq) +memset (iq,0 ,sizeof (*iq)); + }#endif inode->i_pipe =NULL ; inode->i_bdev =NULL ;
fs/nilfs2/mdt.c +0 -3
@@ -478,9 +478,6 @@ nilfs_mdt_new_common(struct the_nilfs *nilfs, struct super_block *sb, inode->i_blocks =0 ; inode->i_bytes =0 ; inode->i_generation =0 ; -#ifdef CONFIG_QUOTA -memset (&inode->i_dquot,0 ,sizeof (inode->i_dquot)); -#endif inode->i_pipe =NULL ; inode->i_bdev =NULL ; inode->i_cdev =NULL ;
fs/quota/dquot.c +78 -56
363 lines not on this page · raw message
include/linux/fs.h +7 -3
@@ -711,9 +711,16 @@ static inline int mapping_writably_mapped(struct address_space *mapping)#endif enum { +INODE_QUOTA ,INODE_FEATURES }; +#ifdef CONFIG_QUOTA +struct inode_quota { +struct dquot *dquot[MAXQUOTAS ]; +}; +#endif +struct inode {struct hlist_node i_hash;struct list_head i_list;
@@ -746,9 +753,6 @@ struct inode {struct file_lock *i_flock;struct address_space *i_mapping;struct address_space i_data; -#ifdef CONFIG_QUOTA -struct dquot *i_dquot[MAXQUOTAS ]; -#endif struct list_head i_devices;union {struct pipe_inode_info *i_pipe;
Signature · 1 line
1.6.0.2
Re: [PATCH 2/2] Use feature code to eliminate quota pointers from inodes for filesystems that don't need it.
Quoted 9 lines · Jan Kara
Signed-off-by Jan Kara <[email protected]>--- fs/ext2/ext2.h | 1 + fs/ext2/super.c | 5 ++ fs/inode.c | 7 ++- fs/nilfs2/mdt.c | 3 - fs/quota/dquot.c | 134 ++++++++++++++++++++++++++++++---------------------- include/linux/fs.h | 10 +++- 6 files changed, 97 insertions(+), 63 deletions(-)
<snip>
Quoted 5 lines
fs/nilfs2/mdt.c +0
-0
fs/nilfs2/mdt.c nilfs_mdt_new_common(struct the_nilfs *nilfs, struct super_block *sb, · line 483
Quoted 9 lines
fs/nilfs2/mdt.c +0
-3@@ -478,9 +478,6 @@ nilfs_mdt_new_common(struct the_nilfs *nilfs, struct super_block *sb, inode->i_blocks =0 ; inode->i_bytes =0 ; inode->i_generation =0 ; -#ifdef CONFIG_QUOTA -memset (&inode->i_dquot,0 ,sizeof (inode->i_dquot)); -#endif inode->i_pipe =NULL ; inode->i_bdev =NULL ; inode->i_cdev =NULL ;
<snip>
Thanks,
Ryusuke Konishi
Quoted 8 lines · Jan Kara
currently our VFS inode structure is quite big. It contains quite some
members that are useful only in some cases (e.g. device pointers and list head used only when the inode represents a block/character device, quota pointers used only when the filesystem actually supports quota, etc.). And it would be helpful to add some more so that we can handle ACL's in generic code, or we can do some kind of block reservation for mmaped writes, and there are other cases.
One of the things on my "round tuit" list was separating out those inode fields which are only needed when the inode is in use, and separating them out into a separate data structure, so that the 90+% of the inodes which are just being cached, and are not active, don't burn space in struct inode. In particular, we can probably move out i_mutex, i_alloc_sem, i_size_seqcount, i_flock, and perhaps others.
The same applies for the filesystem-specific portion of the in-core inode; and for some filesystems there might be even more opportunity for savings there.
Just a thought,
- Ted
Quoted 6 lines · Theodore Tso
One of the things on my "round tuit" list was separating out those inode fields which are only needed when the inode is in use, and separating them out into a separate data structure, so that the 90+% of the inodes which are just being cached, and are not active, don't burn space in struct inode. In particular, we can probably move out
i_mutex,i_alloc_sem,i_size_seqcount,i_flock, and perhaps others.
I think that's generally a good idea, but I don't think we should use this mechanism for it. Just split the inode into two structures, as struct cached_inode and a struct active_inode and make the struct inode an anonymous union of the two.
Quoted 3 lines
The same applies for the filesystem-specific portion of the in-core inode; and for some filesystems there might be even more opportunity for savings there.
I'd rather move them out into the filesystem. E.g. i_alloc_sem is specific to those few filesystem that support O_DIRECT but don't actually do good enough internal locking - we'd be much better off just having the i_alloc_sem equivalent inside those filesystems and get rid of the calls to it in the VFS which only hurt the others.
Similarly I'd really love to get rid of the quota calls in the VFS but instead move calls to these helpers into the filesystems - it's not a function of the VFS switch and that way we can easily keep the quota inode in the FS without a feature table.