From: Davide Libenzi <davidel@xmailserver.org>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [patch] epoll use a single inode ...
Date: Mon, 5 Mar 2007 13:25:50 -0800 (PST) [thread overview]
Message-ID: <Pine.LNX.4.64.0703051311380.4907@alien.or.mcafeemobile.com> (raw)
Epoll does not keep any private data attached to its inode, so there'd be
no need to allocate one inode per fd. For epoll, the inode is just a
placeholder for the file operations and could be shared by all instances.
I'd like to use the same optimization even for the upcoming file-based
objects, so if you see problems let me know.
One that Al was pointing out was that an fstat(2) over an epoll fd would
show the same st_ino. IMO that should be fine since an fstat(2) over an
epoll fd is not something you want to do in any case and expecting
meaningfull results.
Signed-off-by: Davide Libenzi <davidel@xmailserver.org>
- Davide
eventpoll.c | 36 ++++++++++++++++++++++++++++++++----
1 file changed, 32 insertions(+), 4 deletions(-)
Index: linux-2.6.20.ep2/fs/eventpoll.c
===================================================================
--- linux-2.6.20.ep2.orig/fs/eventpoll.c 2007-03-04 14:40:01.000000000 -0800
+++ linux-2.6.20.ep2/fs/eventpoll.c 2007-03-05 13:03:52.000000000 -0800
@@ -258,6 +258,7 @@
int maxevents, long timeout);
static int eventpollfs_delete_dentry(struct dentry *dentry);
static struct inode *ep_eventpoll_inode(void);
+static struct inode *ep_create_inode(void);
static int eventpollfs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name,
void *data, struct vfsmount *mnt);
@@ -279,6 +280,9 @@
/* Virtual fs used to allocate inodes for eventpoll files */
static struct vfsmount *eventpoll_mnt __read_mostly;
+/* Placeholder inode for eventpoll fds */
+static struct inode *eventpoll_inode;
+
/* File callbacks that implement the eventpoll file behaviour */
static const struct file_operations eventpoll_fops = {
.release = ep_eventpoll_close,
@@ -763,15 +767,18 @@
* using the inode number.
*/
error = -ENOMEM;
- sprintf(name, "[%lu]", inode->i_ino);
+ sprintf(name, "[%p]", ep);
this.name = name;
this.len = strlen(name);
- this.hash = inode->i_ino;
+ this.hash = 0;
dentry = d_alloc(eventpoll_mnt->mnt_sb->s_root, &this);
if (!dentry)
goto eexit_4;
dentry->d_op = &eventpollfs_dentry_operations;
- d_add(dentry, inode);
+ /* Do not publish this dentry inside the global dentry hash table */
+ dentry->d_flags &= ~DCACHE_UNHASHED;
+ d_instantiate(dentry, inode);
+
file->f_path.mnt = mntget(eventpoll_mnt);
file->f_path.dentry = dentry;
file->f_mapping = inode->i_mapping;
@@ -1555,6 +1562,11 @@
static int eventpollfs_delete_dentry(struct dentry *dentry)
{
+ /*
+ * We faked vfs to believe the dentry was hashed when we created it.
+ * Now we restore the flag so that dput() will work correctly.
+ */
+ dentry->d_flags |= DCACHE_UNHASHED;
return 1;
}
@@ -1562,6 +1574,17 @@
static struct inode *ep_eventpoll_inode(void)
{
+
+ return igrab(eventpoll_inode);
+}
+
+/*
+ * A single inode exist for all eventpoll files. On the contrary of pipes,
+ * eventpoll inodes has no per-instance data associated, so we can avoid
+ * the allocation of multiple of them.
+ */
+static struct inode *ep_create_inode(void)
+{
int error = -ENOMEM;
struct inode *inode = new_inode(eventpoll_mnt->mnt_sb);
@@ -1626,10 +1649,14 @@
/* Mount the above commented virtual file system */
eventpoll_mnt = kern_mount(&eventpoll_fs_type);
- error = PTR_ERR(eventpoll_mnt);
if (IS_ERR(eventpoll_mnt))
goto epanic;
+ /* Create the single instance of inode for all eventpoll fds */
+ eventpoll_inode = ep_create_inode();
+ if (IS_ERR(eventpoll_inode))
+ goto epanic;
+
DNPRINTK(3, (KERN_INFO "[%p] eventpoll: successfully initialized.\n",
current));
return 0;
@@ -1642,6 +1669,7 @@
static void __exit eventpoll_exit(void)
{
/* Undo all operations done inside eventpoll_init() */
+ iput(eventpoll_inode);
unregister_filesystem(&eventpoll_fs_type);
mntput(eventpoll_mnt);
kmem_cache_destroy(pwq_cache);
next reply other threads:[~2007-03-05 21:25 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-05 21:25 Davide Libenzi [this message]
2007-03-05 21:52 ` Eric Dumazet
[not found] <45ED046A.5010508@argo.co.il>
2007-03-06 7:27 ` Davide Libenzi
[not found] <45ED1A3C.6030707@argo.co.il>
2007-03-07 0:37 ` Davide Libenzi
2007-03-07 0:51 ` Linus Torvalds
2007-03-07 1:01 ` Davide Libenzi
2007-03-07 1:27 ` Linus Torvalds
2007-03-07 1:47 ` Davide Libenzi
2007-03-07 6:52 ` Eric Dumazet
2007-03-07 7:15 ` Davide Libenzi
2007-03-07 7:16 ` Eric Dumazet
2007-03-07 8:56 ` Christoph Hellwig
2007-03-07 17:21 ` Linus Torvalds
2007-03-07 17:02 ` Linus Torvalds
2007-03-07 17:31 ` Eric Dumazet
2007-03-07 17:36 ` Eric Dumazet
2007-03-07 17:45 ` Linus Torvalds
2007-03-07 18:06 ` Eric Dumazet
2007-03-07 18:30 ` Linus Torvalds
2007-03-07 18:52 ` Eric Dumazet
2007-03-07 19:07 ` Linus Torvalds
2007-03-07 22:14 ` Anton Blanchard
2007-03-07 22:57 ` Linus Torvalds
2007-03-08 1:25 ` Michael K. Edwards
2007-03-08 2:48 ` Kyle Moffett
2007-03-08 7:24 ` Eric Dumazet
2007-03-08 16:57 ` Valdis.Kletnieks
2007-03-09 1:34 ` Kyle Moffett
2007-03-09 2:52 ` Anton Blanchard
2007-03-09 2:51 ` Anton Blanchard
2007-03-08 3:20 ` Linus Torvalds
2007-03-08 8:37 ` Michael K. Edwards
2007-03-09 2:46 ` Anton Blanchard
2007-03-08 8:56 ` Christoph Hellwig
2007-03-08 9:42 ` Eric Dumazet
2007-03-08 10:21 ` Christoph Hellwig
2007-03-08 11:11 ` Eric Dumazet
2007-03-08 11:18 ` Christoph Hellwig
2007-03-08 15:52 ` Linus Torvalds
2007-03-08 20:00 ` Bob Copeland
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.64.0703051311380.4907@alien.or.mcafeemobile.com \
--to=davidel@xmailserver.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®