Skip to content

Commit

Permalink
GFS2: Add Orlov allocator
Browse files Browse the repository at this point in the history
Just like ext3, this works on the root directory and any directory
with the +T flag set. Also, just like ext3, any subdirectory created
in one of the just mentioned cases will be allocated to a random
resource group (GFS2 equivalent of a block group).

If you are creating a set of directories, each of which will contain a
job running on a different node, then by setting +T on the parent
directory before creating the subdirectories, each will land up in a
different resource group, and thus resource group contention between
nodes will be kept to a minimum.

Signed-off-by: Steven Whitehouse <[email protected]>
  • Loading branch information
swhiteho committed Nov 7, 2012
1 parent c9aecf7 commit 9dbe961
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 15 deletions.
2 changes: 1 addition & 1 deletion fs/gfs2/aops.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
goto out_unlock;

requested = data_blocks + ind_blocks;
error = gfs2_inplace_reserve(ip, requested);
error = gfs2_inplace_reserve(ip, requested, 0);
if (error)
goto out_qunlock;
}
Expand Down
2 changes: 1 addition & 1 deletion fs/gfs2/bmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ static int do_grow(struct inode *inode, u64 size)
if (error)
return error;

error = gfs2_inplace_reserve(ip, 1);
error = gfs2_inplace_reserve(ip, 1, 0);
if (error)
goto do_grow_qunlock;
unstuff = 1;
Expand Down
4 changes: 2 additions & 2 deletions fs/gfs2/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
if (ret)
goto out_unlock;
gfs2_write_calc_reserv(ip, PAGE_CACHE_SIZE, &data_blocks, &ind_blocks);
ret = gfs2_inplace_reserve(ip, data_blocks + ind_blocks);
ret = gfs2_inplace_reserve(ip, data_blocks + ind_blocks, 0);
if (ret)
goto out_quota_unlock;

Expand Down Expand Up @@ -825,7 +825,7 @@ static long gfs2_fallocate(struct file *file, int mode, loff_t offset,
retry:
gfs2_write_calc_reserv(ip, bytes, &data_blocks, &ind_blocks);

error = gfs2_inplace_reserve(ip, data_blocks + ind_blocks);
error = gfs2_inplace_reserve(ip, data_blocks + ind_blocks, 0);
if (error) {
if (error == -ENOSPC && bytes > sdp->sd_sb.sb_bsize) {
bytes >>= 1;
Expand Down
17 changes: 11 additions & 6 deletions fs/gfs2/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,13 @@ static void munge_mode_uid_gid(const struct gfs2_inode *dip,
inode->i_gid = current_fsgid();
}

static int alloc_dinode(struct gfs2_inode *ip)
static int alloc_dinode(struct gfs2_inode *ip, u32 flags)
{
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
int error;
int dblocks = 1;

error = gfs2_inplace_reserve(ip, RES_DINODE);
error = gfs2_inplace_reserve(ip, RES_DINODE, flags);
if (error)
goto out;

Expand Down Expand Up @@ -560,7 +560,7 @@ static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
if (error)
goto fail_quota_locks;

error = gfs2_inplace_reserve(dip, sdp->sd_max_dirres);
error = gfs2_inplace_reserve(dip, sdp->sd_max_dirres, 0);
if (error)
goto fail_quota_locks;

Expand Down Expand Up @@ -650,6 +650,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
struct gfs2_glock *io_gl;
int error;
struct buffer_head *bh = NULL;
u32 aflags = 0;

if (!name->len || name->len > GFS2_FNAMESIZE)
return -ENAMETOOLONG;
Expand Down Expand Up @@ -685,7 +686,11 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
munge_mode_uid_gid(dip, inode);
ip->i_goal = dip->i_goal;

error = alloc_dinode(ip);
if ((GFS2_I(sdp->sd_root_dir->d_inode) == dip) ||
(dip->i_diskflags & GFS2_DIF_TOPDIR))
aflags |= GFS2_AF_ORLOV;

error = alloc_dinode(ip, aflags);
if (error)
goto fail_free_inode;

Expand Down Expand Up @@ -897,7 +902,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
if (error)
goto out_gunlock;

error = gfs2_inplace_reserve(dip, sdp->sd_max_dirres);
error = gfs2_inplace_reserve(dip, sdp->sd_max_dirres, 0);
if (error)
goto out_gunlock_q;

Expand Down Expand Up @@ -1378,7 +1383,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
if (error)
goto out_gunlock;

error = gfs2_inplace_reserve(ndip, sdp->sd_max_dirres);
error = gfs2_inplace_reserve(ndip, sdp->sd_max_dirres, 0);
if (error)
goto out_gunlock_q;

Expand Down
4 changes: 2 additions & 2 deletions fs/gfs2/quota.c
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
blocks = num_qd * data_blocks + RES_DINODE + num_qd + 3;

reserved = 1 + (nalloc * (data_blocks + ind_blocks));
error = gfs2_inplace_reserve(ip, reserved);
error = gfs2_inplace_reserve(ip, reserved, 0);
if (error)
goto out_alloc;

Expand Down Expand Up @@ -1605,7 +1605,7 @@ static int gfs2_set_dqblk(struct super_block *sb, struct kqid qid,
gfs2_write_calc_reserv(ip, sizeof(struct gfs2_quota),
&data_blocks, &ind_blocks);
blocks = 1 + data_blocks + ind_blocks;
error = gfs2_inplace_reserve(ip, blocks);
error = gfs2_inplace_reserve(ip, blocks, 0);
if (error)
goto out_i;
blocks += gfs2_rg_blocks(ip, blocks);
Expand Down
19 changes: 18 additions & 1 deletion fs/gfs2/rgrp.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <linux/prefetch.h>
#include <linux/blkdev.h>
#include <linux/rbtree.h>
#include <linux/random.h>

#include "gfs2.h"
#include "incore.h"
Expand Down Expand Up @@ -1763,6 +1764,15 @@ static bool gfs2_rgrp_used_recently(const struct gfs2_blkreserv *rs,
return tdiff > (msecs * 1000 * 1000);
}

static u32 gfs2_orlov_skip(const struct gfs2_inode *ip)
{
const struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
u32 skip;

get_random_bytes(&skip, sizeof(skip));
return skip % sdp->sd_rgrps;
}

static bool gfs2_select_rgrp(struct gfs2_rgrpd **pos, const struct gfs2_rgrpd *begin)
{
struct gfs2_rgrpd *rgd = *pos;
Expand All @@ -1784,14 +1794,15 @@ static bool gfs2_select_rgrp(struct gfs2_rgrpd **pos, const struct gfs2_rgrpd *b
* Returns: errno
*/

int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested)
int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested, u32 aflags)
{
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct gfs2_rgrpd *begin = NULL;
struct gfs2_blkreserv *rs = ip->i_res;
int error = 0, rg_locked, flags = 0;
u64 last_unlinked = NO_BLOCK;
int loops = 0;
u32 skip = 0;

if (sdp->sd_args.ar_rgrplvb)
flags |= GL_SKIP;
Expand All @@ -1805,6 +1816,8 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested)
} else {
rs->rs_rbm.rgd = begin = gfs2_blk2rgrpd(sdp, ip->i_goal, 1);
}
if (S_ISDIR(ip->i_inode.i_mode) && (aflags & GFS2_AF_ORLOV))
skip = gfs2_orlov_skip(ip);
if (rs->rs_rbm.rgd == NULL)
return -EBADSLT;

Expand All @@ -1813,6 +1826,8 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested)

if (!gfs2_glock_is_locked_by_me(rs->rs_rbm.rgd->rd_gl)) {
rg_locked = 0;
if (skip && skip--)
goto next_rgrp;
if (!gfs2_rs_active(rs) && (loops < 2) &&
gfs2_rgrp_used_recently(rs, 1000) &&
gfs2_rgrp_congested(rs->rs_rbm.rgd, loops))
Expand Down Expand Up @@ -1871,6 +1886,8 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested)
/* Find the next rgrp, and continue looking */
if (gfs2_select_rgrp(&rs->rs_rbm.rgd, begin))
continue;
if (skip)
continue;

/* If we've scanned all the rgrps, but found no free blocks
* then this checks for some less likely conditions before
Expand Down
3 changes: 2 additions & 1 deletion fs/gfs2/rgrp.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ extern void gfs2_rgrp_go_unlock(struct gfs2_holder *gh);

extern struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip);

extern int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested);
#define GFS2_AF_ORLOV 1
extern int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested, u32 flags);
extern void gfs2_inplace_release(struct gfs2_inode *ip);

extern int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *n,
Expand Down
2 changes: 1 addition & 1 deletion fs/gfs2/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er,
if (error)
return error;

error = gfs2_inplace_reserve(ip, blks);
error = gfs2_inplace_reserve(ip, blks, 0);
if (error)
goto out_gunlock_q;

Expand Down

0 comments on commit 9dbe961

Please sign in to comment.