Skip to content

Commit e579ed4

Browse files
AstralBobswhiteho
authored andcommitted
GFS2: Introduce rbm field bii
This is a respin of the original patch. As Steve pointed out, the introduction of field bii makes it easy to eliminate bi itself. This revised patch does just that, replacing bi with bii. This patch adds a new field to the rbm structure, called bii, which is an index into the array of bitmaps for an rgrp. This replaces *bi which was a pointer to the bitmap. This is being done for further optimizations. Signed-off-by: Bob Peterson <rpeterso@redhat.com> Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
1 parent b870890 commit e579ed4

File tree

2 files changed

+65
-54
lines changed

2 files changed

+65
-54
lines changed

fs/gfs2/incore.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,25 @@ struct gfs2_rgrpd {
102102

103103
struct gfs2_rbm {
104104
struct gfs2_rgrpd *rgd;
105-
struct gfs2_bitmap *bi; /* Bitmap must belong to the rgd */
106105
u32 offset; /* The offset is bitmap relative */
106+
int bii; /* Bitmap index */
107107
};
108108

109+
static inline struct gfs2_bitmap *rbm_bi(const struct gfs2_rbm *rbm)
110+
{
111+
return rbm->rgd->rd_bits + rbm->bii;
112+
}
113+
109114
static inline u64 gfs2_rbm_to_block(const struct gfs2_rbm *rbm)
110115
{
111-
return rbm->rgd->rd_data0 + (rbm->bi->bi_start * GFS2_NBBY) + rbm->offset;
116+
return rbm->rgd->rd_data0 + (rbm_bi(rbm)->bi_start * GFS2_NBBY) +
117+
rbm->offset;
112118
}
113119

114120
static inline bool gfs2_rbm_eq(const struct gfs2_rbm *rbm1,
115121
const struct gfs2_rbm *rbm2)
116122
{
117-
return (rbm1->rgd == rbm2->rgd) && (rbm1->bi == rbm2->bi) &&
123+
return (rbm1->rgd == rbm2->rgd) && (rbm1->bii == rbm2->bii) &&
118124
(rbm1->offset == rbm2->offset);
119125
}
120126

fs/gfs2/rgrp.c

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ static inline void gfs2_setbit(const struct gfs2_rbm *rbm, bool do_clone,
8181
unsigned char new_state)
8282
{
8383
unsigned char *byte1, *byte2, *end, cur_state;
84-
unsigned int buflen = rbm->bi->bi_len;
84+
struct gfs2_bitmap *bi = rbm_bi(rbm);
85+
unsigned int buflen = bi->bi_len;
8586
const unsigned int bit = (rbm->offset % GFS2_NBBY) * GFS2_BIT_SIZE;
8687

87-
byte1 = rbm->bi->bi_bh->b_data + rbm->bi->bi_offset + (rbm->offset / GFS2_NBBY);
88-
end = rbm->bi->bi_bh->b_data + rbm->bi->bi_offset + buflen;
88+
byte1 = bi->bi_bh->b_data + bi->bi_offset + (rbm->offset / GFS2_NBBY);
89+
end = bi->bi_bh->b_data + bi->bi_offset + buflen;
8990

9091
BUG_ON(byte1 >= end);
9192

@@ -95,18 +96,17 @@ static inline void gfs2_setbit(const struct gfs2_rbm *rbm, bool do_clone,
9596
printk(KERN_WARNING "GFS2: buf_blk = 0x%x old_state=%d, "
9697
"new_state=%d\n", rbm->offset, cur_state, new_state);
9798
printk(KERN_WARNING "GFS2: rgrp=0x%llx bi_start=0x%x\n",
98-
(unsigned long long)rbm->rgd->rd_addr,
99-
rbm->bi->bi_start);
99+
(unsigned long long)rbm->rgd->rd_addr, bi->bi_start);
100100
printk(KERN_WARNING "GFS2: bi_offset=0x%x bi_len=0x%x\n",
101-
rbm->bi->bi_offset, rbm->bi->bi_len);
101+
bi->bi_offset, bi->bi_len);
102102
dump_stack();
103103
gfs2_consist_rgrpd(rbm->rgd);
104104
return;
105105
}
106106
*byte1 ^= (cur_state ^ new_state) << bit;
107107

108-
if (do_clone && rbm->bi->bi_clone) {
109-
byte2 = rbm->bi->bi_clone + rbm->bi->bi_offset + (rbm->offset / GFS2_NBBY);
108+
if (do_clone && bi->bi_clone) {
109+
byte2 = bi->bi_clone + bi->bi_offset + (rbm->offset / GFS2_NBBY);
110110
cur_state = (*byte2 >> bit) & GFS2_BIT_MASK;
111111
*byte2 ^= (cur_state ^ new_state) << bit;
112112
}
@@ -121,7 +121,8 @@ static inline void gfs2_setbit(const struct gfs2_rbm *rbm, bool do_clone,
121121

122122
static inline u8 gfs2_testbit(const struct gfs2_rbm *rbm)
123123
{
124-
const u8 *buffer = rbm->bi->bi_bh->b_data + rbm->bi->bi_offset;
124+
struct gfs2_bitmap *bi = rbm_bi(rbm);
125+
const u8 *buffer = bi->bi_bh->b_data + bi->bi_offset;
125126
const u8 *byte;
126127
unsigned int bit;
127128

@@ -252,25 +253,23 @@ static u32 gfs2_bitfit(const u8 *buf, const unsigned int len,
252253
static int gfs2_rbm_from_block(struct gfs2_rbm *rbm, u64 block)
253254
{
254255
u64 rblock = block - rbm->rgd->rd_data0;
255-
u32 x;
256256

257257
if (WARN_ON_ONCE(rblock > UINT_MAX))
258258
return -EINVAL;
259259
if (block >= rbm->rgd->rd_data0 + rbm->rgd->rd_data)
260260
return -E2BIG;
261261

262-
rbm->bi = rbm->rgd->rd_bits;
262+
rbm->bii = 0;
263263
rbm->offset = (u32)(rblock);
264264
/* Check if the block is within the first block */
265-
if (rbm->offset < rbm->bi->bi_blocks)
265+
if (rbm->offset < rbm_bi(rbm)->bi_blocks)
266266
return 0;
267267

268268
/* Adjust for the size diff between gfs2_meta_header and gfs2_rgrp */
269269
rbm->offset += (sizeof(struct gfs2_rgrp) -
270270
sizeof(struct gfs2_meta_header)) * GFS2_NBBY;
271-
x = rbm->offset / rbm->rgd->rd_sbd->sd_blocks_per_bitmap;
272-
rbm->offset -= x * rbm->rgd->rd_sbd->sd_blocks_per_bitmap;
273-
rbm->bi += x;
271+
rbm->bii = rbm->offset / rbm->rgd->rd_sbd->sd_blocks_per_bitmap;
272+
rbm->offset -= rbm->bii * rbm->rgd->rd_sbd->sd_blocks_per_bitmap;
274273
return 0;
275274
}
276275

@@ -328,6 +327,7 @@ static u32 gfs2_free_extlen(const struct gfs2_rbm *rrbm, u32 len)
328327
u32 chunk_size;
329328
u8 *ptr, *start, *end;
330329
u64 block;
330+
struct gfs2_bitmap *bi;
331331

332332
if (n_unaligned &&
333333
gfs2_unaligned_extlen(&rbm, 4 - n_unaligned, &len))
@@ -336,11 +336,12 @@ static u32 gfs2_free_extlen(const struct gfs2_rbm *rrbm, u32 len)
336336
n_unaligned = len & 3;
337337
/* Start is now byte aligned */
338338
while (len > 3) {
339-
start = rbm.bi->bi_bh->b_data;
340-
if (rbm.bi->bi_clone)
341-
start = rbm.bi->bi_clone;
342-
end = start + rbm.bi->bi_bh->b_size;
343-
start += rbm.bi->bi_offset;
339+
bi = rbm_bi(&rbm);
340+
start = bi->bi_bh->b_data;
341+
if (bi->bi_clone)
342+
start = bi->bi_clone;
343+
end = start + bi->bi_bh->b_size;
344+
start += bi->bi_offset;
344345
BUG_ON(rbm.offset & 3);
345346
start += (rbm.offset / GFS2_NBBY);
346347
bytes = min_t(u32, len / GFS2_NBBY, (end - start));
@@ -605,11 +606,13 @@ static void __rs_deltree(struct gfs2_blkreserv *rs)
605606
RB_CLEAR_NODE(&rs->rs_node);
606607

607608
if (rs->rs_free) {
609+
struct gfs2_bitmap *bi = rbm_bi(&rs->rs_rbm);
610+
608611
/* return reserved blocks to the rgrp */
609612
BUG_ON(rs->rs_rbm.rgd->rd_reserved < rs->rs_free);
610613
rs->rs_rbm.rgd->rd_reserved -= rs->rs_free;
611614
rs->rs_free = 0;
612-
clear_bit(GBF_FULL, &rs->rs_rbm.bi->bi_flags);
615+
clear_bit(GBF_FULL, &bi->bi_flags);
613616
smp_mb__after_clear_bit();
614617
}
615618
}
@@ -1558,14 +1561,14 @@ static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 minext,
15581561
const struct gfs2_inode *ip, bool nowrap)
15591562
{
15601563
struct buffer_head *bh;
1561-
struct gfs2_bitmap *initial_bi;
1564+
int initial_bii;
15621565
u32 initial_offset;
15631566
u32 offset;
15641567
u8 *buffer;
1565-
int index;
15661568
int n = 0;
15671569
int iters = rbm->rgd->rd_length;
15681570
int ret;
1571+
struct gfs2_bitmap *bi;
15691572

15701573
/* If we are not starting at the beginning of a bitmap, then we
15711574
* need to add one to the bitmap count to ensure that we search
@@ -1575,52 +1578,53 @@ static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 minext,
15751578
iters++;
15761579

15771580
while(1) {
1578-
if (test_bit(GBF_FULL, &rbm->bi->bi_flags) &&
1581+
bi = rbm_bi(rbm);
1582+
if (test_bit(GBF_FULL, &bi->bi_flags) &&
15791583
(state == GFS2_BLKST_FREE))
15801584
goto next_bitmap;
15811585

1582-
bh = rbm->bi->bi_bh;
1583-
buffer = bh->b_data + rbm->bi->bi_offset;
1586+
bh = bi->bi_bh;
1587+
buffer = bh->b_data + bi->bi_offset;
15841588
WARN_ON(!buffer_uptodate(bh));
1585-
if (state != GFS2_BLKST_UNLINKED && rbm->bi->bi_clone)
1586-
buffer = rbm->bi->bi_clone + rbm->bi->bi_offset;
1589+
if (state != GFS2_BLKST_UNLINKED && bi->bi_clone)
1590+
buffer = bi->bi_clone + bi->bi_offset;
15871591
initial_offset = rbm->offset;
1588-
offset = gfs2_bitfit(buffer, rbm->bi->bi_len, rbm->offset, state);
1592+
offset = gfs2_bitfit(buffer, bi->bi_len, rbm->offset, state);
15891593
if (offset == BFITNOENT)
15901594
goto bitmap_full;
15911595
rbm->offset = offset;
15921596
if (ip == NULL)
15931597
return 0;
15941598

1595-
initial_bi = rbm->bi;
1599+
initial_bii = rbm->bii;
15961600
ret = gfs2_reservation_check_and_update(rbm, ip, minext);
15971601
if (ret == 0)
15981602
return 0;
15991603
if (ret > 0) {
1600-
n += (rbm->bi - initial_bi);
1604+
n += (rbm->bii - initial_bii);
16011605
goto next_iter;
16021606
}
16031607
if (ret == -E2BIG) {
1604-
index = 0;
1608+
rbm->bii = 0;
16051609
rbm->offset = 0;
1606-
n += (rbm->bi - initial_bi);
1610+
n += (rbm->bii - initial_bii);
16071611
goto res_covered_end_of_rgrp;
16081612
}
16091613
return ret;
16101614

16111615
bitmap_full: /* Mark bitmap as full and fall through */
1612-
if ((state == GFS2_BLKST_FREE) && initial_offset == 0)
1613-
set_bit(GBF_FULL, &rbm->bi->bi_flags);
1616+
if ((state == GFS2_BLKST_FREE) && initial_offset == 0) {
1617+
struct gfs2_bitmap *bi = rbm_bi(rbm);
1618+
set_bit(GBF_FULL, &bi->bi_flags);
1619+
}
16141620

16151621
next_bitmap: /* Find next bitmap in the rgrp */
16161622
rbm->offset = 0;
1617-
index = rbm->bi - rbm->rgd->rd_bits;
1618-
index++;
1619-
if (index == rbm->rgd->rd_length)
1620-
index = 0;
1623+
rbm->bii++;
1624+
if (rbm->bii == rbm->rgd->rd_length)
1625+
rbm->bii = 0;
16211626
res_covered_end_of_rgrp:
1622-
rbm->bi = &rbm->rgd->rd_bits[index];
1623-
if ((index == 0) && nowrap)
1627+
if ((rbm->bii == 0) && nowrap)
16241628
break;
16251629
n++;
16261630
next_iter:
@@ -1649,7 +1653,7 @@ static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip
16491653
struct gfs2_inode *ip;
16501654
int error;
16511655
int found = 0;
1652-
struct gfs2_rbm rbm = { .rgd = rgd, .bi = rgd->rd_bits, .offset = 0 };
1656+
struct gfs2_rbm rbm = { .rgd = rgd, .bii = 0, .offset = 0 };
16531657

16541658
while (1) {
16551659
down_write(&sdp->sd_log_flush_lock);
@@ -1976,14 +1980,14 @@ static void gfs2_alloc_extent(const struct gfs2_rbm *rbm, bool dinode,
19761980

19771981
*n = 1;
19781982
block = gfs2_rbm_to_block(rbm);
1979-
gfs2_trans_add_meta(rbm->rgd->rd_gl, rbm->bi->bi_bh);
1983+
gfs2_trans_add_meta(rbm->rgd->rd_gl, rbm_bi(rbm)->bi_bh);
19801984
gfs2_setbit(rbm, true, dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED);
19811985
block++;
19821986
while (*n < elen) {
19831987
ret = gfs2_rbm_from_block(&pos, block);
19841988
if (ret || gfs2_testbit(&pos) != GFS2_BLKST_FREE)
19851989
break;
1986-
gfs2_trans_add_meta(pos.rgd->rd_gl, pos.bi->bi_bh);
1990+
gfs2_trans_add_meta(pos.rgd->rd_gl, rbm_bi(&pos)->bi_bh);
19871991
gfs2_setbit(&pos, true, GFS2_BLKST_USED);
19881992
(*n)++;
19891993
block++;
@@ -2004,6 +2008,7 @@ static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, u64 bstart,
20042008
u32 blen, unsigned char new_state)
20052009
{
20062010
struct gfs2_rbm rbm;
2011+
struct gfs2_bitmap *bi;
20072012

20082013
rbm.rgd = gfs2_blk2rgrpd(sdp, bstart, 1);
20092014
if (!rbm.rgd) {
@@ -2014,15 +2019,15 @@ static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, u64 bstart,
20142019

20152020
while (blen--) {
20162021
gfs2_rbm_from_block(&rbm, bstart);
2022+
bi = rbm_bi(&rbm);
20172023
bstart++;
2018-
if (!rbm.bi->bi_clone) {
2019-
rbm.bi->bi_clone = kmalloc(rbm.bi->bi_bh->b_size,
2020-
GFP_NOFS | __GFP_NOFAIL);
2021-
memcpy(rbm.bi->bi_clone + rbm.bi->bi_offset,
2022-
rbm.bi->bi_bh->b_data + rbm.bi->bi_offset,
2023-
rbm.bi->bi_len);
2024+
if (!bi->bi_clone) {
2025+
bi->bi_clone = kmalloc(bi->bi_bh->b_size,
2026+
GFP_NOFS | __GFP_NOFAIL);
2027+
memcpy(bi->bi_clone + bi->bi_offset,
2028+
bi->bi_bh->b_data + bi->bi_offset, bi->bi_len);
20242029
}
2025-
gfs2_trans_add_meta(rbm.rgd->rd_gl, rbm.bi->bi_bh);
2030+
gfs2_trans_add_meta(rbm.rgd->rd_gl, bi->bi_bh);
20262031
gfs2_setbit(&rbm, false, new_state);
20272032
}
20282033

0 commit comments

Comments
 (0)