Patch-Name: fast-unlink.patch
Kernel-Version: linux-2.2.10
Target-file: linux/fs/namei.c
Abstract: The do_unlink() function locks parent directory and calls
        vfs_unlink() without checking the existence of the target.
        This patch fixes the problem.

I was comparing the news server performances running kernels 2.0.36
and 2.2.10, before upgrading the main service machine to the newer kernel.
The following table shows a part of INND timer report of the servers.
The hardware specs are almost same except the number of news readers.
They serve approximately 20 and 500 readers per day, respectively.

                      host-1     host-2
    -------------     ------     ------
    Linux kernel      2.2.10     2.0.36
    avg.readers           20        500
    -------------     ------     ------

    INND code         avg. msec/call
    -------------     ------     ------
    artwrite          14.956     53.826
      open            12.779     40.805
      write            1.975      4.505
      close            0.038      8.305
    artexpire         20.981     14.628

The above result shows that 2.2.10 is faster except artexpire.
Naturally, I had to study the reason why the unlink() performance
is so bad on 2.2.10.

Reading sys_unlink(), do_unlink(), and lookup_dentry(), I realized
that do_unlink() does something unnecessary processes.  It looks up
the target but does not check the existence of the target which is
stored within the returned dentry.  It simply locks the parent
directory and calls vfs_unlink().

There are many application programs which do not check the existence
of a file and relies on the kernel to delete.  For example, during the
boot, my Slackware-4.0 Linux tries to delete following files without
checking the status:

    /etc/initrunlvl
    /var/log/initrunlvl
    /dev/log
    /etc/ld.so.cache~
    /dev/log
    /var/run/named.pid
    /dev/printer
    cron.update

And they are repeatededly requested. :-(

And, finally, here is the patch.  It changes only one file,
linux/fs/namei.c.  The diff is against kernel-2.2.10.
--
Sang-yong Suh

Patch-Name: fast-unlink.patch
Kernel-Version: linux-2.2.10
Target-files: linux/fs/namei.c
Abstract: The do_unlink() function locks parent directory and calls
        vfs_unlink() without checking the existence of the target.
        This patch fixes the problem.
Author: Sang-yong Suh <[EMAIL PROTECTED]>
Date: Aug. 12, 1998

*** namei.c.orig        Sun May  9 12:46:08 1999
--- namei.c     Thu Aug 12 12:13:59 1999
***************
*** 1040,1051 ****
        if (IS_ERR(dentry))
                goto exit;
  
-       dir = lock_parent(dentry);
        error = -ENOENT;
!       if (check_parent(dir, dentry))
!               error = vfs_unlink(dir->d_inode, dentry);
! 
          unlock_dir(dir);
        dput(dentry);
  exit:
        return error;
--- 1040,1052 ----
        if (IS_ERR(dentry))
                goto exit;
  
        error = -ENOENT;
!       if (dentry->d_inode) {
!               dir = lock_parent(dentry);
!               if (check_parent(dir, dentry))
!                       error = vfs_unlink(dir->d_inode, dentry);
          unlock_dir(dir);
+       }
        dput(dentry);
  exit:
        return error;

Reply via email to