Commit 3699e3a4 authored by Steven Whitehouse's avatar Steven Whitehouse

[GFS2] Clean up/speed up readdir

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: default avatarSteven Whitehouse <swhiteho@redhat.com>
parent a8d638e3
...@@ -1198,12 +1198,11 @@ static int compare_dents(const void *a, const void *b) ...@@ -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, 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, const struct gfs2_dirent **darr, u32 entries,
int *copied) int *copied)
{ {
const struct gfs2_dirent *dent, *dent_next; const struct gfs2_dirent *dent, *dent_next;
struct gfs2_inum_host inum;
u64 off, off_next; u64 off, off_next;
unsigned int x, y; unsigned int x, y;
int run = 0; int run = 0;
...@@ -1240,11 +1239,9 @@ static int do_filldir_main(struct gfs2_inode *dip, u64 *offset, ...@@ -1240,11 +1239,9 @@ static int do_filldir_main(struct gfs2_inode *dip, u64 *offset,
*offset = off; *offset = off;
} }
gfs2_inum_in(&inum, (char *)&dent->de_inum);
error = filldir(opaque, (const char *)(dent + 1), error = filldir(opaque, (const char *)(dent + 1),
be16_to_cpu(dent->de_name_len), be16_to_cpu(dent->de_name_len),
off, &inum, off, be64_to_cpu(dent->de_inum.no_addr),
be16_to_cpu(dent->de_type)); be16_to_cpu(dent->de_type));
if (error) if (error)
return 1; return 1;
...@@ -1262,8 +1259,8 @@ static int do_filldir_main(struct gfs2_inode *dip, u64 *offset, ...@@ -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, static int gfs2_dir_read_leaf(struct inode *inode, u64 *offset, void *opaque,
gfs2_filldir_t filldir, int *copied, filldir_t filldir, int *copied, unsigned *depth,
unsigned *depth, u64 leaf_no) u64 leaf_no)
{ {
struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_inode *ip = GFS2_I(inode);
struct buffer_head *bh; struct buffer_head *bh;
...@@ -1343,7 +1340,7 @@ static int gfs2_dir_read_leaf(struct inode *inode, u64 *offset, void *opaque, ...@@ -1343,7 +1340,7 @@ static int gfs2_dir_read_leaf(struct inode *inode, u64 *offset, void *opaque,
*/ */
static int dir_e_read(struct inode *inode, u64 *offset, void *opaque, 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_inode *dip = GFS2_I(inode);
struct gfs2_sbd *sdp = GFS2_SB(inode); struct gfs2_sbd *sdp = GFS2_SB(inode);
...@@ -1402,7 +1399,7 @@ static int dir_e_read(struct inode *inode, u64 *offset, void *opaque, ...@@ -1402,7 +1399,7 @@ static int dir_e_read(struct inode *inode, u64 *offset, void *opaque,
} }
int gfs2_dir_read(struct inode *inode, u64 *offset, void *opaque, 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 gfs2_inode *dip = GFS2_I(inode);
struct dirent_gather g; struct dirent_gather g;
......
...@@ -16,30 +16,13 @@ struct inode; ...@@ -16,30 +16,13 @@ struct inode;
struct gfs2_inode; struct gfs2_inode;
struct gfs2_inum; 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, int gfs2_dir_search(struct inode *dir, const struct qstr *filename,
struct gfs2_inum_host *inum, unsigned int *type); struct gfs2_inum_host *inum, unsigned int *type);
int gfs2_dir_add(struct inode *inode, const struct qstr *filename, int gfs2_dir_add(struct inode *inode, const struct qstr *filename,
const struct gfs2_inum_host *inum, unsigned int type); const struct gfs2_inum_host *inum, unsigned int type);
int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *filename); int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *filename);
int gfs2_dir_read(struct inode *inode, u64 * offset, void *opaque, int gfs2_dir_read(struct inode *inode, u64 *offset, void *opaque,
gfs2_filldir_t filldir); filldir_t filldir);
int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename, int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename,
struct gfs2_inum_host *new_inum, unsigned int new_type); struct gfs2_inum_host *new_inum, unsigned int new_type);
......
...@@ -971,8 +971,6 @@ static void drop_bh(struct gfs2_glock *gl, unsigned int ret) ...@@ -971,8 +971,6 @@ static void drop_bh(struct gfs2_glock *gl, unsigned int ret)
const struct gfs2_glock_operations *glops = gl->gl_ops; const struct gfs2_glock_operations *glops = gl->gl_ops;
struct gfs2_holder *gh = gl->gl_req_gh; 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, test_bit(GLF_LOCK, &gl->gl_flags));
gfs2_assert_warn(sdp, queue_empty(gl, &gl->gl_holders)); gfs2_assert_warn(sdp, queue_empty(gl, &gl->gl_holders));
gfs2_assert_warn(sdp, !ret); gfs2_assert_warn(sdp, !ret);
...@@ -1227,8 +1225,6 @@ int gfs2_glock_nq(struct gfs2_holder *gh) ...@@ -1227,8 +1225,6 @@ int gfs2_glock_nq(struct gfs2_holder *gh)
} }
} }
clear_bit(GLF_PREFETCH, &gl->gl_flags);
return error; return error;
} }
...@@ -1320,36 +1316,6 @@ void gfs2_glock_dq(struct gfs2_holder *gh) ...@@ -1320,36 +1316,6 @@ void gfs2_glock_dq(struct gfs2_holder *gh)
spin_unlock(&gl->gl_spin); 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) static void greedy_work(struct work_struct *work)
{ {
struct greedy *gr = container_of(work, struct greedy, gr_work.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) ...@@ -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_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 * gfs2_lvb_hold - attach a LVB from a glock
* @gl: The glock in question * @gl: The glock in question
...@@ -1781,15 +1719,11 @@ void gfs2_glock_cb(void *cb_data, unsigned int type, void *data) ...@@ -1781,15 +1719,11 @@ void gfs2_glock_cb(void *cb_data, unsigned int type, void *data)
static int demote_ok(struct gfs2_glock *gl) static int demote_ok(struct gfs2_glock *gl)
{ {
struct gfs2_sbd *sdp = gl->gl_sbd;
const struct gfs2_glock_operations *glops = gl->gl_ops; const struct gfs2_glock_operations *glops = gl->gl_ops;
int demote = 1; int demote = 1;
if (test_bit(GLF_STICKY, &gl->gl_flags)) if (test_bit(GLF_STICKY, &gl->gl_flags))
demote = 0; 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) else if (glops->go_demote_ok)
demote = glops->go_demote_ok(gl); demote = glops->go_demote_ok(gl);
......
...@@ -103,10 +103,6 @@ int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs); ...@@ -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_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_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 * gfs2_glock_nq_init - intialize a holder and enqueue it on a glock
* @gl: the glock * @gl: the glock
......
...@@ -147,7 +147,6 @@ struct gfs2_holder { ...@@ -147,7 +147,6 @@ struct gfs2_holder {
enum { enum {
GLF_LOCK = 1, GLF_LOCK = 1,
GLF_STICKY = 2, GLF_STICKY = 2,
GLF_PREFETCH = 3,
GLF_DIRTY = 5, GLF_DIRTY = 5,
GLF_SKIP_WAITERS2 = 6, GLF_SKIP_WAITERS2 = 6,
GLF_GREEDY = 7, GLF_GREEDY = 7,
...@@ -425,7 +424,6 @@ struct gfs2_tune { ...@@ -425,7 +424,6 @@ struct gfs2_tune {
unsigned int gt_complain_secs; unsigned int gt_complain_secs;
unsigned int gt_reclaim_limit; /* Max num of glocks in reclaim list */ unsigned int gt_reclaim_limit; /* Max num of glocks in reclaim list */
unsigned int gt_entries_per_readdir; 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_default;
unsigned int gt_greedy_quantum; unsigned int gt_greedy_quantum;
unsigned int gt_greedy_max; unsigned int gt_greedy_max;
......
...@@ -113,13 +113,12 @@ struct get_name_filldir { ...@@ -113,13 +113,12 @@ struct get_name_filldir {
char *name; char *name;
}; };
static int get_name_filldir(void *opaque, const char *name, unsigned int length, static int get_name_filldir(void *opaque, const char *name, int length,
u64 offset, struct gfs2_inum_host *inum, loff_t offset, u64 inum, unsigned int type)
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; return 0;
memcpy(gnfd->name, name, length); memcpy(gnfd->name, name, length);
......
...@@ -43,15 +43,6 @@ ...@@ -43,15 +43,6 @@
#include "util.h" #include "util.h"
#include "eaops.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 * Most fields left uninitialised to catch anybody who tries to
* use them. f_flags set to prevent file_accessed() from touching * 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) ...@@ -127,41 +118,6 @@ static loff_t gfs2_llseek(struct file *file, loff_t offset, int origin)
return error; 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 * gfs2_readdir - Read directory entries from a directory
* @file: The directory to read from * @file: The directory to read from
...@@ -175,16 +131,10 @@ static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir) ...@@ -175,16 +131,10 @@ static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir)
{ {
struct inode *dir = file->f_mapping->host; struct inode *dir = file->f_mapping->host;
struct gfs2_inode *dip = GFS2_I(dir); struct gfs2_inode *dip = GFS2_I(dir);
struct filldir_reg fdr;
struct gfs2_holder d_gh; struct gfs2_holder d_gh;
u64 offset = file->f_pos; u64 offset = file->f_pos;
int error; 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); gfs2_holder_init(dip->i_gl, LM_ST_SHARED, GL_ATIME, &d_gh);
error = gfs2_glock_nq_atime(&d_gh); error = gfs2_glock_nq_atime(&d_gh);
if (error) { if (error) {
...@@ -192,7 +142,7 @@ static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir) ...@@ -192,7 +142,7 @@ static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir)
return error; 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); gfs2_glock_dq_uninit(&d_gh);
......
...@@ -78,7 +78,6 @@ void gfs2_tune_init(struct gfs2_tune *gt) ...@@ -78,7 +78,6 @@ void gfs2_tune_init(struct gfs2_tune *gt)
gt->gt_complain_secs = 10; gt->gt_complain_secs = 10;
gt->gt_reclaim_limit = 5000; gt->gt_reclaim_limit = 5000;
gt->gt_entries_per_readdir = 32; gt->gt_entries_per_readdir = 32;
gt->gt_prefetch_secs = 10;
gt->gt_greedy_default = HZ / 10; gt->gt_greedy_default = HZ / 10;
gt->gt_greedy_quantum = HZ / 40; gt->gt_greedy_quantum = HZ / 40;
gt->gt_greedy_max = HZ / 4; gt->gt_greedy_max = HZ / 4;
......
...@@ -436,7 +436,6 @@ TUNE_ATTR(atime_quantum, 0); ...@@ -436,7 +436,6 @@ TUNE_ATTR(atime_quantum, 0);
TUNE_ATTR(max_readahead, 0); TUNE_ATTR(max_readahead, 0);
TUNE_ATTR(complain_secs, 0); TUNE_ATTR(complain_secs, 0);
TUNE_ATTR(reclaim_limit, 0); TUNE_ATTR(reclaim_limit, 0);
TUNE_ATTR(prefetch_secs, 0);
TUNE_ATTR(statfs_slow, 0); TUNE_ATTR(statfs_slow, 0);
TUNE_ATTR(new_files_jdata, 0); TUNE_ATTR(new_files_jdata, 0);
TUNE_ATTR(new_files_directio, 0); TUNE_ATTR(new_files_directio, 0);
...@@ -465,7 +464,6 @@ static struct attribute *tune_attrs[] = { ...@@ -465,7 +464,6 @@ static struct attribute *tune_attrs[] = {
&tune_attr_max_readahead.attr, &tune_attr_max_readahead.attr,
&tune_attr_complain_secs.attr, &tune_attr_complain_secs.attr,
&tune_attr_reclaim_limit.attr, &tune_attr_reclaim_limit.attr,
&tune_attr_prefetch_secs.attr,
&tune_attr_statfs_slow.attr, &tune_attr_statfs_slow.attr,
&tune_attr_quota_simul_sync.attr, &tune_attr_quota_simul_sync.attr,
&tune_attr_quota_cache_secs.attr, &tune_attr_quota_cache_secs.attr,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment