]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
[GFS2] Clean up/speed up readdir
authorSteven Whitehouse <swhiteho@redhat.com>
Wed, 17 Jan 2007 15:09:20 +0000 (15:09 +0000)
committerSteven Whitehouse <swhiteho@redhat.com>
Mon, 5 Feb 2007 18:37:04 +0000 (13:37 -0500)
This removes the extra filldir callback which gfs2 was using to
enclose an attempt at readahead for inodes during readdir. The
code was too complicated and also hurts performance badly in the
case that the getdents64/readdir call isn't being followed by
stat() and it wasn't even getting it right all the time when it
was.

As a result, on my test box an "ls" of a directory containing 250000
files fell from about 7mins (freshly mounted, so nothing cached) to
between about 15 to 25 seconds. When the directory content was cached,
the time taken fell from about 3mins to about 4 or 5 seconds.

Interestingly in the cached case, running "ls -l" once reduced the time
taken for subsequent runs of "ls" to about 6 secs even without this
patch. Now it turns out that there was a special case of glocks being
used for prefetching the metadata, but because of the timeouts for these
locks (set to 10 secs) the metadata was being timed out before it was
being used and this the prefetch code was constantly trying to prefetch
the same data over and over.

Calling "ls -l" meant that the inodes were brought into memory and once
the inodes are cached, the glocks are not disposed of until the inodes
are pushed out of the cache, thus extending the lifetime of the glocks,
and thus bringing down the time for subsequent runs of "ls"
considerably.

Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
fs/gfs2/dir.c
fs/gfs2/dir.h
fs/gfs2/glock.c
fs/gfs2/glock.h
fs/gfs2/incore.h
fs/gfs2/ops_export.c
fs/gfs2/ops_file.c
fs/gfs2/super.c
fs/gfs2/sys.c

index 0fdcb7713cd9378c1fe723b61b6eda9e7a1711ee..0eceb051084f9214d9189fe50bd0d239ec128e26 100644 (file)
@@ -1198,12 +1198,11 @@ static int compare_dents(const void *a, const void *b)
  */
 
 static int do_filldir_main(struct gfs2_inode *dip, u64 *offset,
-                          void *opaque, gfs2_filldir_t filldir,
+                          void *opaque, filldir_t filldir,
                           const struct gfs2_dirent **darr, u32 entries,
                           int *copied)
 {
        const struct gfs2_dirent *dent, *dent_next;
-       struct gfs2_inum_host inum;
        u64 off, off_next;
        unsigned int x, y;
        int run = 0;
@@ -1240,11 +1239,9 @@ static int do_filldir_main(struct gfs2_inode *dip, u64 *offset,
                        *offset = off;
                }
 
-               gfs2_inum_in(&inum, (char *)&dent->de_inum);
-
                error = filldir(opaque, (const char *)(dent + 1),
                                be16_to_cpu(dent->de_name_len),
-                               off, &inum,
+                               off, be64_to_cpu(dent->de_inum.no_addr),
                                be16_to_cpu(dent->de_type));
                if (error)
                        return 1;
@@ -1262,8 +1259,8 @@ static int do_filldir_main(struct gfs2_inode *dip, u64 *offset,
 }
 
 static int gfs2_dir_read_leaf(struct inode *inode, u64 *offset, void *opaque,
-                             gfs2_filldir_t filldir, int *copied,
-                             unsigned *depth, u64 leaf_no)
+                             filldir_t filldir, int *copied, unsigned *depth,
+                             u64 leaf_no)
 {
        struct gfs2_inode *ip = GFS2_I(inode);
        struct buffer_head *bh;
@@ -1343,7 +1340,7 @@ out:
  */
 
 static int dir_e_read(struct inode *inode, u64 *offset, void *opaque,
-                     gfs2_filldir_t filldir)
+                     filldir_t filldir)
 {
        struct gfs2_inode *dip = GFS2_I(inode);
        struct gfs2_sbd *sdp = GFS2_SB(inode);
@@ -1402,7 +1399,7 @@ out:
 }
 
 int gfs2_dir_read(struct inode *inode, u64 *offset, void *opaque,
-                 gfs2_filldir_t filldir)
+                 filldir_t filldir)
 {
        struct gfs2_inode *dip = GFS2_I(inode);
        struct dirent_gather g;
index b21b33668a5bc4ee2ea29c7658c2f8f343232900..48fe89046bbad39af0277bb3a38d0e1f7f5de813 100644 (file)
@@ -16,30 +16,13 @@ struct inode;
 struct gfs2_inode;
 struct gfs2_inum;
 
-/**
- * gfs2_filldir_t - Report a directory entry to the caller of gfs2_dir_read()
- * @opaque: opaque data used by the function
- * @name: the name of the directory entry
- * @length: the length of the name
- * @offset: the entry's offset in the directory
- * @inum: the inode number the entry points to
- * @type: the type of inode the entry points to
- *
- * Returns: 0 on success, 1 if buffer full
- */
-
-typedef int (*gfs2_filldir_t) (void *opaque,
-                             const char *name, unsigned int length,
-                             u64 offset,
-                             struct gfs2_inum_host *inum, unsigned int type);
-
 int gfs2_dir_search(struct inode *dir, const struct qstr *filename,
                    struct gfs2_inum_host *inum, unsigned int *type);
 int gfs2_dir_add(struct inode *inode, const struct qstr *filename,
                 const struct gfs2_inum_host *inum, unsigned int type);
 int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *filename);
-int gfs2_dir_read(struct inode *inode, u64 * offset, void *opaque,
-                 gfs2_filldir_t filldir);
+int gfs2_dir_read(struct inode *inode, u64 *offset, void *opaque,
+                 filldir_t filldir);
 int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename,
                   struct gfs2_inum_host *new_inum, unsigned int new_type);
 
index 438146904b5839727ac2c378c5df87f574cfedaa..fb1960b7fdde5be2c3dfe94b3cc21c7d8d1825ba 100644 (file)
@@ -971,8 +971,6 @@ static void drop_bh(struct gfs2_glock *gl, unsigned int ret)
        const struct gfs2_glock_operations *glops = gl->gl_ops;
        struct gfs2_holder *gh = gl->gl_req_gh;
 
-       clear_bit(GLF_PREFETCH, &gl->gl_flags);
-
        gfs2_assert_warn(sdp, test_bit(GLF_LOCK, &gl->gl_flags));
        gfs2_assert_warn(sdp, queue_empty(gl, &gl->gl_holders));
        gfs2_assert_warn(sdp, !ret);
@@ -1227,8 +1225,6 @@ restart:
                }
        }
 
-       clear_bit(GLF_PREFETCH, &gl->gl_flags);
-
        return error;
 }
 
@@ -1320,36 +1316,6 @@ void gfs2_glock_dq(struct gfs2_holder *gh)
        spin_unlock(&gl->gl_spin);
 }
 
-/**
- * gfs2_glock_prefetch - Try to prefetch a glock
- * @gl: the glock
- * @state: the state to prefetch in
- * @flags: flags passed to go_xmote_th()
- *
- */
-
-static void gfs2_glock_prefetch(struct gfs2_glock *gl, unsigned int state,
-                               int flags)
-{
-       const struct gfs2_glock_operations *glops = gl->gl_ops;
-
-       spin_lock(&gl->gl_spin);
-
-       if (test_bit(GLF_LOCK, &gl->gl_flags) || !list_empty(&gl->gl_holders) ||
-           !list_empty(&gl->gl_waiters1) || !list_empty(&gl->gl_waiters2) ||
-           !list_empty(&gl->gl_waiters3) ||
-           relaxed_state_ok(gl->gl_state, state, flags)) {
-               spin_unlock(&gl->gl_spin);
-               return;
-       }
-
-       set_bit(GLF_PREFETCH, &gl->gl_flags);
-       set_bit(GLF_LOCK, &gl->gl_flags);
-       spin_unlock(&gl->gl_spin);
-
-       glops->go_xmote_th(gl, state, flags);
-}
-
 static void greedy_work(struct work_struct *work)
 {
        struct greedy *gr = container_of(work, struct greedy, gr_work.work);
@@ -1617,34 +1583,6 @@ void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs)
                gfs2_glock_dq_uninit(&ghs[x]);
 }
 
-/**
- * gfs2_glock_prefetch_num - prefetch a glock based on lock number
- * @sdp: the filesystem
- * @number: the lock number
- * @glops: the glock operations for the type of glock
- * @state: the state to acquire the glock in
- * @flags: modifier flags for the aquisition
- *
- * Returns: errno
- */
-
-void gfs2_glock_prefetch_num(struct gfs2_sbd *sdp, u64 number,
-                            const struct gfs2_glock_operations *glops,
-                            unsigned int state, int flags)
-{
-       struct gfs2_glock *gl;
-       int error;
-
-       if (atomic_read(&sdp->sd_reclaim_count) <
-           gfs2_tune_get(sdp, gt_reclaim_limit)) {
-               error = gfs2_glock_get(sdp, number, glops, CREATE, &gl);
-               if (!error) {
-                       gfs2_glock_prefetch(gl, state, flags);
-                       gfs2_glock_put(gl);
-               }
-       }
-}
-
 /**
  * gfs2_lvb_hold - attach a LVB from a glock
  * @gl: The glock in question
@@ -1781,15 +1719,11 @@ void gfs2_glock_cb(void *cb_data, unsigned int type, void *data)
 
 static int demote_ok(struct gfs2_glock *gl)
 {
-       struct gfs2_sbd *sdp = gl->gl_sbd;
        const struct gfs2_glock_operations *glops = gl->gl_ops;
        int demote = 1;
 
        if (test_bit(GLF_STICKY, &gl->gl_flags))
                demote = 0;
-       else if (test_bit(GLF_PREFETCH, &gl->gl_flags))
-               demote = time_after_eq(jiffies, gl->gl_stamp +
-                                   gfs2_tune_get(sdp, gt_prefetch_secs) * HZ);
        else if (glops->go_demote_ok)
                demote = glops->go_demote_ok(gl);
 
index fb39108fc05c2e378f6d349775ab808a986e3594..bde02a7061ecd35c3905f2abd4f78539e3c81899 100644 (file)
@@ -103,10 +103,6 @@ int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs);
 void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs);
 void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs);
 
-void gfs2_glock_prefetch_num(struct gfs2_sbd *sdp, u64 number,
-                            const struct gfs2_glock_operations *glops,
-                            unsigned int state, int flags);
-
 /**
  * gfs2_glock_nq_init - intialize a holder and enqueue it on a glock
  * @gl: the glock
index 734421edae85a21ac02bf00e6735228208965919..807587050384befe8b19ddeb2e4b028ec31aaa00 100644 (file)
@@ -147,7 +147,6 @@ struct gfs2_holder {
 enum {
        GLF_LOCK                = 1,
        GLF_STICKY              = 2,
-       GLF_PREFETCH            = 3,
        GLF_DIRTY               = 5,
        GLF_SKIP_WAITERS2       = 6,
        GLF_GREEDY              = 7,
@@ -425,7 +424,6 @@ struct gfs2_tune {
        unsigned int gt_complain_secs;
        unsigned int gt_reclaim_limit; /* Max num of glocks in reclaim list */
        unsigned int gt_entries_per_readdir;
-       unsigned int gt_prefetch_secs; /* Usage window for prefetched glocks */
        unsigned int gt_greedy_default;
        unsigned int gt_greedy_quantum;
        unsigned int gt_greedy_max;
index 6ea979c74b6b9334824fd58e73fc8dc14b5c2401..fbf55063928fbc40cd32e6073c663c8581aeb000 100644 (file)
@@ -113,13 +113,12 @@ struct get_name_filldir {
        char *name;
 };
 
-static int get_name_filldir(void *opaque, const char *name, unsigned int length,
-                           u64 offset, struct gfs2_inum_host *inum,
-                           unsigned int type)
+static int get_name_filldir(void *opaque, const char *name, int length,
+                           loff_t offset, u64 inum, unsigned int type)
 {
-       struct get_name_filldir *gnfd = (struct get_name_filldir *)opaque;
+       struct get_name_filldir *gnfd = opaque;
 
-       if (!gfs2_inum_equal(inum, &gnfd->inum))
+       if (inum != gnfd->inum.no_addr)
                return 0;
 
        memcpy(gnfd->name, name, length);
index faa07e4b97d025709cc246a22d51fd367e2c6d89..c996aa739a0515f5c11229591a83805a4abb6f99 100644 (file)
 #include "util.h"
 #include "eaops.h"
 
-/* For regular, non-NFS */
-struct filldir_reg {
-       struct gfs2_sbd *fdr_sbd;
-       int fdr_prefetch;
-
-       filldir_t fdr_filldir;
-       void *fdr_opaque;
-};
-
 /*
  * Most fields left uninitialised to catch anybody who tries to
  * use them. f_flags set to prevent file_accessed() from touching
@@ -127,41 +118,6 @@ static loff_t gfs2_llseek(struct file *file, loff_t offset, int origin)
        return error;
 }
 
-/**
- * filldir_func - Report a directory entry to the caller of gfs2_dir_read()
- * @opaque: opaque data used by the function
- * @name: the name of the directory entry
- * @length: the length of the name
- * @offset: the entry's offset in the directory
- * @inum: the inode number the entry points to
- * @type: the type of inode the entry points to
- *
- * Returns: 0 on success, 1 if buffer full
- */
-
-static int filldir_func(void *opaque, const char *name, unsigned int length,
-                       u64 offset, struct gfs2_inum_host *inum,
-                       unsigned int type)
-{
-       struct filldir_reg *fdr = (struct filldir_reg *)opaque;
-       struct gfs2_sbd *sdp = fdr->fdr_sbd;
-       int error;
-
-       error = fdr->fdr_filldir(fdr->fdr_opaque, name, length, offset,
-                                inum->no_addr, type);
-       if (error)
-               return 1;
-
-       if (fdr->fdr_prefetch && !(length == 1 && *name == '.')) {
-               gfs2_glock_prefetch_num(sdp, inum->no_addr, &gfs2_inode_glops,
-                                      LM_ST_SHARED, LM_FLAG_TRY | LM_FLAG_ANY);
-               gfs2_glock_prefetch_num(sdp, inum->no_addr, &gfs2_iopen_glops,
-                                      LM_ST_SHARED, LM_FLAG_TRY);
-       }
-
-       return 0;
-}
-
 /**
  * gfs2_readdir - Read directory entries from a directory
  * @file: The directory to read from
@@ -175,16 +131,10 @@ static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir)
 {
        struct inode *dir = file->f_mapping->host;
        struct gfs2_inode *dip = GFS2_I(dir);
-       struct filldir_reg fdr;
        struct gfs2_holder d_gh;
        u64 offset = file->f_pos;
        int error;
 
-       fdr.fdr_sbd = GFS2_SB(dir);
-       fdr.fdr_prefetch = 1;
-       fdr.fdr_filldir = filldir;
-       fdr.fdr_opaque = dirent;
-
        gfs2_holder_init(dip->i_gl, LM_ST_SHARED, GL_ATIME, &d_gh);
        error = gfs2_glock_nq_atime(&d_gh);
        if (error) {
@@ -192,7 +142,7 @@ static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir)
                return error;
        }
 
-       error = gfs2_dir_read(dir, &offset, &fdr, filldir_func);
+       error = gfs2_dir_read(dir, &offset, dirent, filldir);
 
        gfs2_glock_dq_uninit(&d_gh);
 
index 43a24f2e5905f9a26be19bcc032b4761a777baef..100852a61b5dd584f2355901238868ea50a7ea26 100644 (file)
@@ -78,7 +78,6 @@ void gfs2_tune_init(struct gfs2_tune *gt)
        gt->gt_complain_secs = 10;
        gt->gt_reclaim_limit = 5000;
        gt->gt_entries_per_readdir = 32;
-       gt->gt_prefetch_secs = 10;
        gt->gt_greedy_default = HZ / 10;
        gt->gt_greedy_quantum = HZ / 40;
        gt->gt_greedy_max = HZ / 4;
index 983eaf1e06becb3e0c6516bb04ffa397bc121ab9..cd28f08b244cb88e9581eb19ed8b0a87a9a3cc12 100644 (file)
@@ -436,7 +436,6 @@ TUNE_ATTR(atime_quantum, 0);
 TUNE_ATTR(max_readahead, 0);
 TUNE_ATTR(complain_secs, 0);
 TUNE_ATTR(reclaim_limit, 0);
-TUNE_ATTR(prefetch_secs, 0);
 TUNE_ATTR(statfs_slow, 0);
 TUNE_ATTR(new_files_jdata, 0);
 TUNE_ATTR(new_files_directio, 0);
@@ -465,7 +464,6 @@ static struct attribute *tune_attrs[] = {
        &tune_attr_max_readahead.attr,
        &tune_attr_complain_secs.attr,
        &tune_attr_reclaim_limit.attr,
-       &tune_attr_prefetch_secs.attr,
        &tune_attr_statfs_slow.attr,
        &tune_attr_quota_simul_sync.attr,
        &tune_attr_quota_cache_secs.attr,