[PATCH] Speed fork with lots of files up.

Andi Kleen (ak@muc.de)
Wed, 19 Aug 1998 07:23:20 +0200


Hallo Linus,

This patch speeds the fork latency for a process that has nearly NR_OPEN
files open up by about 10ms on my machine. File pointers are only
touched once, not twice because memset is only run on the not-yet initialized
rest of the fd table.

It also removes the files_cache constructor, because it is useless with
a fd table separate from files_struct.

-Andi

Index: linux/kernel/fork.c
===================================================================
RCS file: /vger/u4/cvs/linux/kernel/fork.c,v
retrieving revision 1.78
diff -u -r1.78 fork.c
--- fork.c 1998/08/03 23:58:28 1.78
+++ fork.c 1998/08/19 04:07:30
@@ -360,8 +360,9 @@
return 0;
}

-/* return value is only accurate by +-sizeof(long)*8 fds */
-/* XXX make this architecture specific */
+/*
+ * Copy a fd_set and compute the maximum fd it contains.
+ */
static inline int __copy_fdset(unsigned long *d, unsigned long *src)
{
int i;
@@ -415,7 +416,6 @@
new_fds = (struct file **) kmalloc(size, GFP_KERNEL);
if (!new_fds)
goto out_release;
- memset((void *) new_fds, 0, size);

newf->count = 1;
newf->max_fds = NR_OPEN;
@@ -425,13 +425,15 @@

old_fds = oldf->fd;
for (; i != 0; i--) {
- struct file * f = *old_fds;
- old_fds++;
+ struct file *f = *old_fds++;
*new_fds = f;
if (f)
f->f_count++;
new_fds++;
}
+ /* This is long word aligned thus could use a optimized version */
+ memset(new_fds, 0, (char *)newf->fd + size - (char *)new_fds);
+
tsk->files = newf;
error = 0;
out:
@@ -629,20 +631,13 @@
goto bad_fork;
}

-static void files_ctor(void *fp, kmem_cache_t *cachep, unsigned long flags)
-{
- struct files_struct *f = fp;
-
- memset(f, 0, sizeof(*f));
-}
-
__initfunc(void filescache_init(void))
{
files_cachep = kmem_cache_create("files_cache",
sizeof(struct files_struct),
0,
SLAB_HWCACHE_ALIGN,
- files_ctor, NULL);
+ NULL, NULL);
if (!files_cachep)
panic("Cannot create files cache");
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html