Skip to content

Commit 9dbe961

Browse files
committed
GFS2: Add Orlov allocator
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 <swhiteho@redhat.com>
1 parent c9aecf7 commit 9dbe961

8 files changed

Lines changed: 38 additions & 15 deletions

File tree

‎fs/gfs2/aops.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
643643
goto out_unlock;
644644

645645
requested = data_blocks + ind_blocks;
646-
error = gfs2_inplace_reserve(ip, requested);
646+
error = gfs2_inplace_reserve(ip, requested, 0);
647647
if (error)
648648
goto out_qunlock;
649649
}

‎fs/gfs2/bmap.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ static int do_grow(struct inode *inode, u64 size)
11781178
if (error)
11791179
return error;
11801180

1181-
error = gfs2_inplace_reserve(ip, 1);
1181+
error = gfs2_inplace_reserve(ip, 1, 0);
11821182
if (error)
11831183
goto do_grow_qunlock;
11841184
unstuff = 1;

‎fs/gfs2/file.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
432432
if (ret)
433433
goto out_unlock;
434434
gfs2_write_calc_reserv(ip, PAGE_CACHE_SIZE, &data_blocks, &ind_blocks);
435-
ret = gfs2_inplace_reserve(ip, data_blocks + ind_blocks);
435+
ret = gfs2_inplace_reserve(ip, data_blocks + ind_blocks, 0);
436436
if (ret)
437437
goto out_quota_unlock;
438438

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

828-
error = gfs2_inplace_reserve(ip, data_blocks + ind_blocks);
828+
error = gfs2_inplace_reserve(ip, data_blocks + ind_blocks, 0);
829829
if (error) {
830830
if (error == -ENOSPC && bytes > sdp->sd_sb.sb_bsize) {
831831
bytes >>= 1;

‎fs/gfs2/inode.c‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -385,13 +385,13 @@ static void munge_mode_uid_gid(const struct gfs2_inode *dip,
385385
inode->i_gid = current_fsgid();
386386
}
387387

388-
static int alloc_dinode(struct gfs2_inode *ip)
388+
static int alloc_dinode(struct gfs2_inode *ip, u32 flags)
389389
{
390390
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
391391
int error;
392392
int dblocks = 1;
393393

394-
error = gfs2_inplace_reserve(ip, RES_DINODE);
394+
error = gfs2_inplace_reserve(ip, RES_DINODE, flags);
395395
if (error)
396396
goto out;
397397

@@ -560,7 +560,7 @@ static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
560560
if (error)
561561
goto fail_quota_locks;
562562

563-
error = gfs2_inplace_reserve(dip, sdp->sd_max_dirres);
563+
error = gfs2_inplace_reserve(dip, sdp->sd_max_dirres, 0);
564564
if (error)
565565
goto fail_quota_locks;
566566

@@ -650,6 +650,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
650650
struct gfs2_glock *io_gl;
651651
int error;
652652
struct buffer_head *bh = NULL;
653+
u32 aflags = 0;
653654

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

688-
error = alloc_dinode(ip);
689+
if ((GFS2_I(sdp->sd_root_dir->d_inode) == dip) ||
690+
(dip->i_diskflags & GFS2_DIF_TOPDIR))
691+
aflags |= GFS2_AF_ORLOV;
692+
693+
error = alloc_dinode(ip, aflags);
689694
if (error)
690695
goto fail_free_inode;
691696

@@ -897,7 +902,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
897902
if (error)
898903
goto out_gunlock;
899904

900-
error = gfs2_inplace_reserve(dip, sdp->sd_max_dirres);
905+
error = gfs2_inplace_reserve(dip, sdp->sd_max_dirres, 0);
901906
if (error)
902907
goto out_gunlock_q;
903908

@@ -1378,7 +1383,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
13781383
if (error)
13791384
goto out_gunlock;
13801385

1381-
error = gfs2_inplace_reserve(ndip, sdp->sd_max_dirres);
1386+
error = gfs2_inplace_reserve(ndip, sdp->sd_max_dirres, 0);
13821387
if (error)
13831388
goto out_gunlock_q;
13841389

‎fs/gfs2/quota.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
816816
blocks = num_qd * data_blocks + RES_DINODE + num_qd + 3;
817817

818818
reserved = 1 + (nalloc * (data_blocks + ind_blocks));
819-
error = gfs2_inplace_reserve(ip, reserved);
819+
error = gfs2_inplace_reserve(ip, reserved, 0);
820820
if (error)
821821
goto out_alloc;
822822

@@ -1605,7 +1605,7 @@ static int gfs2_set_dqblk(struct super_block *sb, struct kqid qid,
16051605
gfs2_write_calc_reserv(ip, sizeof(struct gfs2_quota),
16061606
&data_blocks, &ind_blocks);
16071607
blocks = 1 + data_blocks + ind_blocks;
1608-
error = gfs2_inplace_reserve(ip, blocks);
1608+
error = gfs2_inplace_reserve(ip, blocks, 0);
16091609
if (error)
16101610
goto out_i;
16111611
blocks += gfs2_rg_blocks(ip, blocks);

‎fs/gfs2/rgrp.c‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/prefetch.h>
1717
#include <linux/blkdev.h>
1818
#include <linux/rbtree.h>
19+
#include <linux/random.h>
1920

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

1767+
static u32 gfs2_orlov_skip(const struct gfs2_inode *ip)
1768+
{
1769+
const struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1770+
u32 skip;
1771+
1772+
get_random_bytes(&skip, sizeof(skip));
1773+
return skip % sdp->sd_rgrps;
1774+
}
1775+
17661776
static bool gfs2_select_rgrp(struct gfs2_rgrpd **pos, const struct gfs2_rgrpd *begin)
17671777
{
17681778
struct gfs2_rgrpd *rgd = *pos;
@@ -1784,14 +1794,15 @@ static bool gfs2_select_rgrp(struct gfs2_rgrpd **pos, const struct gfs2_rgrpd *b
17841794
* Returns: errno
17851795
*/
17861796

1787-
int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested)
1797+
int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested, u32 aflags)
17881798
{
17891799
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
17901800
struct gfs2_rgrpd *begin = NULL;
17911801
struct gfs2_blkreserv *rs = ip->i_res;
17921802
int error = 0, rg_locked, flags = 0;
17931803
u64 last_unlinked = NO_BLOCK;
17941804
int loops = 0;
1805+
u32 skip = 0;
17951806

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

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

18141827
if (!gfs2_glock_is_locked_by_me(rs->rs_rbm.rgd->rd_gl)) {
18151828
rg_locked = 0;
1829+
if (skip && skip--)
1830+
goto next_rgrp;
18161831
if (!gfs2_rs_active(rs) && (loops < 2) &&
18171832
gfs2_rgrp_used_recently(rs, 1000) &&
18181833
gfs2_rgrp_congested(rs->rs_rbm.rgd, loops))
@@ -1871,6 +1886,8 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested)
18711886
/* Find the next rgrp, and continue looking */
18721887
if (gfs2_select_rgrp(&rs->rs_rbm.rgd, begin))
18731888
continue;
1889+
if (skip)
1890+
continue;
18741891

18751892
/* If we've scanned all the rgrps, but found no free blocks
18761893
* then this checks for some less likely conditions before

‎fs/gfs2/rgrp.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ extern void gfs2_rgrp_go_unlock(struct gfs2_holder *gh);
3939

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

42-
extern int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested);
42+
#define GFS2_AF_ORLOV 1
43+
extern int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested, u32 flags);
4344
extern void gfs2_inplace_release(struct gfs2_inode *ip);
4445

4546
extern int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *n,

‎fs/gfs2/xattr.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er,
734734
if (error)
735735
return error;
736736

737-
error = gfs2_inplace_reserve(ip, blks);
737+
error = gfs2_inplace_reserve(ip, blks, 0);
738738
if (error)
739739
goto out_gunlock_q;
740740

0 commit comments

Comments
 (0)