Skip to content

Commit 16ca941

Browse files
bmarzinsswhiteho
authored andcommitted
GFS2: replace gfs2_ail structure with gfs2_trans
In order to allow transactions and log flushes to happen at the same time, gfs2 needs to move the transaction accounting and active items list code into the gfs2_trans structure. As a first step toward this, this patch removes the gfs2_ail structure, and handles the active items list in the gfs_trans structure. This keeps gfs2 from allocating an ail structure on log flushes, and gives us a struture that can later be used to store the transaction accounting outside of the gfs2 superblock structure. With this patch, at the end of a transaction, gfs2 will add the gfs2_trans structure to the superblock if there is not one already. This structure now has the active items fields that were previously in gfs2_ail. This is not necessary in the case where the transaction was simply used to add revokes, since these are never written outside of the journal, and thus, don't need an active items list. Also, in order to make sure that the transaction structure is not removed while it's still in use by gfs2_trans_end, unlocking the sd_log_flush_lock has to happen slightly later in ending the transaction. Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
1 parent 2009521 commit 16ca941

7 files changed

Lines changed: 94 additions & 72 deletions

File tree

‎fs/gfs2/aops.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ int gfs2_releasepage(struct page *page, gfp_t gfp_mask)
10551055
if (atomic_read(&bh->b_count))
10561056
goto cannot_release;
10571057
bd = bh->b_private;
1058-
if (bd && bd->bd_ail)
1058+
if (bd && bd->bd_tr)
10591059
goto cannot_release;
10601060
if (buffer_pinned(bh) || buffer_dirty(bh))
10611061
goto not_possible;

‎fs/gfs2/incore.h‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ struct gfs2_holder;
3131
struct gfs2_glock;
3232
struct gfs2_quota_data;
3333
struct gfs2_trans;
34-
struct gfs2_ail;
3534
struct gfs2_jdesc;
3635
struct gfs2_sbd;
3736
struct lm_lockops;
@@ -53,7 +52,7 @@ struct gfs2_log_header_host {
5352

5453
struct gfs2_log_operations {
5554
void (*lo_before_commit) (struct gfs2_sbd *sdp);
56-
void (*lo_after_commit) (struct gfs2_sbd *sdp, struct gfs2_ail *ai);
55+
void (*lo_after_commit) (struct gfs2_sbd *sdp, struct gfs2_trans *tr);
5756
void (*lo_before_scan) (struct gfs2_jdesc *jd,
5857
struct gfs2_log_header_host *head, int pass);
5958
int (*lo_scan_elements) (struct gfs2_jdesc *jd, unsigned int start,
@@ -139,7 +138,7 @@ struct gfs2_bufdata {
139138
struct list_head bd_list;
140139
const struct gfs2_log_operations *bd_ops;
141140

142-
struct gfs2_ail *bd_ail;
141+
struct gfs2_trans *bd_tr;
143142
struct list_head bd_ail_st_list;
144143
struct list_head bd_ail_gl_list;
145144
};
@@ -433,21 +432,20 @@ struct gfs2_trans {
433432
struct gfs2_holder tr_t_gh;
434433

435434
int tr_touched;
435+
int tr_attached;
436436

437437
unsigned int tr_num_buf_new;
438438
unsigned int tr_num_databuf_new;
439439
unsigned int tr_num_buf_rm;
440440
unsigned int tr_num_databuf_rm;
441441
unsigned int tr_num_revoke;
442442
unsigned int tr_num_revoke_rm;
443-
};
444443

445-
struct gfs2_ail {
446-
struct list_head ai_list;
444+
struct list_head tr_list;
447445

448-
unsigned int ai_first;
449-
struct list_head ai_ail1_list;
450-
struct list_head ai_ail2_list;
446+
unsigned int tr_first;
447+
struct list_head tr_ail1_list;
448+
struct list_head tr_ail2_list;
451449
};
452450

453451
struct gfs2_journal_extent {
@@ -710,6 +708,7 @@ struct gfs2_sbd {
710708

711709
spinlock_t sd_log_lock;
712710

711+
struct gfs2_trans *sd_log_tr;
713712
unsigned int sd_log_blks_reserved;
714713
unsigned int sd_log_commited_buf;
715714
unsigned int sd_log_commited_databuf;

‎fs/gfs2/log.c‎

Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct,
7373

7474
void gfs2_remove_from_ail(struct gfs2_bufdata *bd)
7575
{
76-
bd->bd_ail = NULL;
76+
bd->bd_tr = NULL;
7777
list_del_init(&bd->bd_ail_st_list);
7878
list_del_init(&bd->bd_ail_gl_list);
7979
atomic_dec(&bd->bd_gl->gl_ail_count);
@@ -90,7 +90,7 @@ void gfs2_remove_from_ail(struct gfs2_bufdata *bd)
9090

9191
static int gfs2_ail1_start_one(struct gfs2_sbd *sdp,
9292
struct writeback_control *wbc,
93-
struct gfs2_ail *ai)
93+
struct gfs2_trans *tr)
9494
__releases(&sdp->sd_ail_lock)
9595
__acquires(&sdp->sd_ail_lock)
9696
{
@@ -99,15 +99,15 @@ __acquires(&sdp->sd_ail_lock)
9999
struct gfs2_bufdata *bd, *s;
100100
struct buffer_head *bh;
101101

102-
list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list, bd_ail_st_list) {
102+
list_for_each_entry_safe_reverse(bd, s, &tr->tr_ail1_list, bd_ail_st_list) {
103103
bh = bd->bd_bh;
104104

105-
gfs2_assert(sdp, bd->bd_ail == ai);
105+
gfs2_assert(sdp, bd->bd_tr == tr);
106106

107107
if (!buffer_busy(bh)) {
108108
if (!buffer_uptodate(bh))
109109
gfs2_io_error_bh(sdp, bh);
110-
list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list);
110+
list_move(&bd->bd_ail_st_list, &tr->tr_ail2_list);
111111
continue;
112112
}
113113

@@ -116,7 +116,7 @@ __acquires(&sdp->sd_ail_lock)
116116
if (gl == bd->bd_gl)
117117
continue;
118118
gl = bd->bd_gl;
119-
list_move(&bd->bd_ail_st_list, &ai->ai_ail1_list);
119+
list_move(&bd->bd_ail_st_list, &tr->tr_ail1_list);
120120
mapping = bh->b_page->mapping;
121121
if (!mapping)
122122
continue;
@@ -144,15 +144,15 @@ __acquires(&sdp->sd_ail_lock)
144144
void gfs2_ail1_flush(struct gfs2_sbd *sdp, struct writeback_control *wbc)
145145
{
146146
struct list_head *head = &sdp->sd_ail1_list;
147-
struct gfs2_ail *ai;
147+
struct gfs2_trans *tr;
148148

149149
trace_gfs2_ail_flush(sdp, wbc, 1);
150150
spin_lock(&sdp->sd_ail_lock);
151151
restart:
152-
list_for_each_entry_reverse(ai, head, ai_list) {
152+
list_for_each_entry_reverse(tr, head, tr_list) {
153153
if (wbc->nr_to_write <= 0)
154154
break;
155-
if (gfs2_ail1_start_one(sdp, wbc, ai))
155+
if (gfs2_ail1_start_one(sdp, wbc, tr))
156156
goto restart;
157157
}
158158
spin_unlock(&sdp->sd_ail_lock);
@@ -183,20 +183,20 @@ static void gfs2_ail1_start(struct gfs2_sbd *sdp)
183183
*
184184
*/
185185

186-
static void gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
186+
static void gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
187187
{
188188
struct gfs2_bufdata *bd, *s;
189189
struct buffer_head *bh;
190190

191-
list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list,
191+
list_for_each_entry_safe_reverse(bd, s, &tr->tr_ail1_list,
192192
bd_ail_st_list) {
193193
bh = bd->bd_bh;
194-
gfs2_assert(sdp, bd->bd_ail == ai);
194+
gfs2_assert(sdp, bd->bd_tr == tr);
195195
if (buffer_busy(bh))
196196
continue;
197197
if (!buffer_uptodate(bh))
198198
gfs2_io_error_bh(sdp, bh);
199-
list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list);
199+
list_move(&bd->bd_ail_st_list, &tr->tr_ail2_list);
200200
}
201201

202202
}
@@ -210,14 +210,14 @@ static void gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
210210

211211
static int gfs2_ail1_empty(struct gfs2_sbd *sdp)
212212
{
213-
struct gfs2_ail *ai, *s;
213+
struct gfs2_trans *tr, *s;
214214
int ret;
215215

216216
spin_lock(&sdp->sd_ail_lock);
217-
list_for_each_entry_safe_reverse(ai, s, &sdp->sd_ail1_list, ai_list) {
218-
gfs2_ail1_empty_one(sdp, ai);
219-
if (list_empty(&ai->ai_ail1_list))
220-
list_move(&ai->ai_list, &sdp->sd_ail2_list);
217+
list_for_each_entry_safe_reverse(tr, s, &sdp->sd_ail1_list, tr_list) {
218+
gfs2_ail1_empty_one(sdp, tr);
219+
if (list_empty(&tr->tr_ail1_list))
220+
list_move(&tr->tr_list, &sdp->sd_ail2_list);
221221
else
222222
break;
223223
}
@@ -229,13 +229,13 @@ static int gfs2_ail1_empty(struct gfs2_sbd *sdp)
229229

230230
static void gfs2_ail1_wait(struct gfs2_sbd *sdp)
231231
{
232-
struct gfs2_ail *ai;
232+
struct gfs2_trans *tr;
233233
struct gfs2_bufdata *bd;
234234
struct buffer_head *bh;
235235

236236
spin_lock(&sdp->sd_ail_lock);
237-
list_for_each_entry_reverse(ai, &sdp->sd_ail1_list, ai_list) {
238-
list_for_each_entry(bd, &ai->ai_ail1_list, bd_ail_st_list) {
237+
list_for_each_entry_reverse(tr, &sdp->sd_ail1_list, tr_list) {
238+
list_for_each_entry(bd, &tr->tr_ail1_list, bd_ail_st_list) {
239239
bh = bd->bd_bh;
240240
if (!buffer_locked(bh))
241241
continue;
@@ -256,40 +256,40 @@ static void gfs2_ail1_wait(struct gfs2_sbd *sdp)
256256
*
257257
*/
258258

259-
static void gfs2_ail2_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
259+
static void gfs2_ail2_empty_one(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
260260
{
261-
struct list_head *head = &ai->ai_ail2_list;
261+
struct list_head *head = &tr->tr_ail2_list;
262262
struct gfs2_bufdata *bd;
263263

264264
while (!list_empty(head)) {
265265
bd = list_entry(head->prev, struct gfs2_bufdata,
266266
bd_ail_st_list);
267-
gfs2_assert(sdp, bd->bd_ail == ai);
267+
gfs2_assert(sdp, bd->bd_tr == tr);
268268
gfs2_remove_from_ail(bd);
269269
}
270270
}
271271

272272
static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail)
273273
{
274-
struct gfs2_ail *ai, *safe;
274+
struct gfs2_trans *tr, *safe;
275275
unsigned int old_tail = sdp->sd_log_tail;
276276
int wrap = (new_tail < old_tail);
277277
int a, b, rm;
278278

279279
spin_lock(&sdp->sd_ail_lock);
280280

281-
list_for_each_entry_safe(ai, safe, &sdp->sd_ail2_list, ai_list) {
282-
a = (old_tail <= ai->ai_first);
283-
b = (ai->ai_first < new_tail);
281+
list_for_each_entry_safe(tr, safe, &sdp->sd_ail2_list, tr_list) {
282+
a = (old_tail <= tr->tr_first);
283+
b = (tr->tr_first < new_tail);
284284
rm = (wrap) ? (a || b) : (a && b);
285285
if (!rm)
286286
continue;
287287

288-
gfs2_ail2_empty_one(sdp, ai);
289-
list_del(&ai->ai_list);
290-
gfs2_assert_warn(sdp, list_empty(&ai->ai_ail1_list));
291-
gfs2_assert_warn(sdp, list_empty(&ai->ai_ail2_list));
292-
kfree(ai);
288+
gfs2_ail2_empty_one(sdp, tr);
289+
list_del(&tr->tr_list);
290+
gfs2_assert_warn(sdp, list_empty(&tr->tr_ail1_list));
291+
gfs2_assert_warn(sdp, list_empty(&tr->tr_ail2_list));
292+
kfree(tr);
293293
}
294294

295295
spin_unlock(&sdp->sd_ail_lock);
@@ -435,16 +435,17 @@ static unsigned int calc_reserved(struct gfs2_sbd *sdp)
435435

436436
static unsigned int current_tail(struct gfs2_sbd *sdp)
437437
{
438-
struct gfs2_ail *ai;
438+
struct gfs2_trans *tr;
439439
unsigned int tail;
440440

441441
spin_lock(&sdp->sd_ail_lock);
442442

443443
if (list_empty(&sdp->sd_ail1_list)) {
444444
tail = sdp->sd_log_head;
445445
} else {
446-
ai = list_entry(sdp->sd_ail1_list.prev, struct gfs2_ail, ai_list);
447-
tail = ai->ai_first;
446+
tr = list_entry(sdp->sd_ail1_list.prev, struct gfs2_trans,
447+
tr_list);
448+
tail = tr->tr_first;
448449
}
449450

450451
spin_unlock(&sdp->sd_ail_lock);
@@ -600,7 +601,7 @@ static void log_write_header(struct gfs2_sbd *sdp, u32 flags)
600601

601602
void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
602603
{
603-
struct gfs2_ail *ai;
604+
struct gfs2_trans *tr;
604605

605606
down_write(&sdp->sd_log_flush_lock);
606607

@@ -611,9 +612,12 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
611612
}
612613
trace_gfs2_log_flush(sdp, 1);
613614

614-
ai = kzalloc(sizeof(struct gfs2_ail), GFP_NOFS | __GFP_NOFAIL);
615-
INIT_LIST_HEAD(&ai->ai_ail1_list);
616-
INIT_LIST_HEAD(&ai->ai_ail2_list);
615+
tr = sdp->sd_log_tr;
616+
if (tr) {
617+
sdp->sd_log_tr = NULL;
618+
INIT_LIST_HEAD(&tr->tr_ail1_list);
619+
INIT_LIST_HEAD(&tr->tr_ail2_list);
620+
}
617621

618622
if (sdp->sd_log_num_buf != sdp->sd_log_commited_buf) {
619623
printk(KERN_INFO "GFS2: log buf %u %u\n", sdp->sd_log_num_buf,
@@ -630,7 +634,8 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
630634

631635
sdp->sd_log_flush_head = sdp->sd_log_head;
632636
sdp->sd_log_flush_wrapped = 0;
633-
ai->ai_first = sdp->sd_log_flush_head;
637+
if (tr)
638+
tr->tr_first = sdp->sd_log_flush_head;
634639

635640
gfs2_ordered_write(sdp);
636641
lops_before_commit(sdp);
@@ -643,7 +648,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
643648
trace_gfs2_log_blocks(sdp, -1);
644649
log_write_header(sdp, 0);
645650
}
646-
lops_after_commit(sdp, ai);
651+
lops_after_commit(sdp, tr);
647652

648653
gfs2_log_lock(sdp);
649654
sdp->sd_log_head = sdp->sd_log_flush_head;
@@ -653,16 +658,16 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
653658
sdp->sd_log_commited_revoke = 0;
654659

655660
spin_lock(&sdp->sd_ail_lock);
656-
if (!list_empty(&ai->ai_ail1_list)) {
657-
list_add(&ai->ai_list, &sdp->sd_ail1_list);
658-
ai = NULL;
661+
if (tr && !list_empty(&tr->tr_ail1_list)) {
662+
list_add(&tr->tr_list, &sdp->sd_ail1_list);
663+
tr = NULL;
659664
}
660665
spin_unlock(&sdp->sd_ail_lock);
661666
gfs2_log_unlock(sdp);
662667
trace_gfs2_log_flush(sdp, 0);
663668
up_write(&sdp->sd_log_flush_lock);
664669

665-
kfree(ai);
670+
kfree(tr);
666671
}
667672

668673
static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
@@ -687,6 +692,12 @@ static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
687692
sdp->sd_jdesc->jd_blocks);
688693
sdp->sd_log_blks_reserved = reserved;
689694

695+
if (sdp->sd_log_tr == NULL &&
696+
(tr->tr_num_buf_new || tr->tr_num_databuf_new)) {
697+
gfs2_assert_withdraw(sdp, tr->tr_t_gh.gh_gl);
698+
sdp->sd_log_tr = tr;
699+
tr->tr_attached = 1;
700+
}
690701
gfs2_log_unlock(sdp);
691702
}
692703

@@ -708,7 +719,6 @@ static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
708719
void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
709720
{
710721
log_refund(sdp, tr);
711-
up_read(&sdp->sd_log_flush_lock);
712722

713723
if (atomic_read(&sdp->sd_log_pinned) > atomic_read(&sdp->sd_log_thresh1) ||
714724
((sdp->sd_jdesc->jd_blocks - atomic_read(&sdp->sd_log_blks_free)) >

0 commit comments

Comments
 (0)