Skip to content

Commit 022ef4f

Browse files
committed
GFS2: Move log buffer accounting to transaction
Now we have a master transaction into which other transactions are merged, the accounting can be done using this master transaction. We no longer require the superblock fields which were being used for this function. In addition, this allows for a clean up in calc_reserved() making it rather easier understand. Also, by reducing the number of variables used to track the buffers being added and removed from the journal, a number of error checks are now no longer required. Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
1 parent d69a3c6 commit 022ef4f

5 files changed

Lines changed: 33 additions & 65 deletions

File tree

‎fs/gfs2/incore.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -748,15 +748,10 @@ struct gfs2_sbd {
748748

749749
struct gfs2_trans *sd_log_tr;
750750
unsigned int sd_log_blks_reserved;
751-
unsigned int sd_log_commited_buf;
752-
unsigned int sd_log_commited_databuf;
753751
int sd_log_commited_revoke;
754752

755753
atomic_t sd_log_pinned;
756-
unsigned int sd_log_num_buf;
757754
unsigned int sd_log_num_revoke;
758-
unsigned int sd_log_num_rg;
759-
unsigned int sd_log_num_databuf;
760755

761756
struct list_head sd_log_le_revoke;
762757
struct list_head sd_log_le_ordered;

‎fs/gfs2/log.c‎

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -414,24 +414,22 @@ static inline unsigned int log_distance(struct gfs2_sbd *sdp, unsigned int newer
414414
static unsigned int calc_reserved(struct gfs2_sbd *sdp)
415415
{
416416
unsigned int reserved = 0;
417-
unsigned int mbuf_limit, metabufhdrs_needed;
418-
unsigned int dbuf_limit, databufhdrs_needed;
419-
unsigned int revokes = 0;
417+
unsigned int mbuf;
418+
unsigned int dbuf;
419+
struct gfs2_trans *tr = sdp->sd_log_tr;
420420

421-
mbuf_limit = buf_limit(sdp);
422-
metabufhdrs_needed = (sdp->sd_log_commited_buf +
423-
(mbuf_limit - 1)) / mbuf_limit;
424-
dbuf_limit = databuf_limit(sdp);
425-
databufhdrs_needed = (sdp->sd_log_commited_databuf +
426-
(dbuf_limit - 1)) / dbuf_limit;
421+
if (tr) {
422+
mbuf = tr->tr_num_buf_new - tr->tr_num_buf_rm;
423+
dbuf = tr->tr_num_databuf_new - tr->tr_num_databuf_rm;
424+
reserved = mbuf + dbuf;
425+
/* Account for header blocks */
426+
reserved += DIV_ROUND_UP(mbuf, buf_limit(sdp));
427+
reserved += DIV_ROUND_UP(dbuf, databuf_limit(sdp));
428+
}
427429

428430
if (sdp->sd_log_commited_revoke > 0)
429-
revokes = gfs2_struct2blk(sdp, sdp->sd_log_commited_revoke,
431+
reserved += gfs2_struct2blk(sdp, sdp->sd_log_commited_revoke,
430432
sizeof(u64));
431-
432-
reserved = sdp->sd_log_commited_buf + metabufhdrs_needed +
433-
sdp->sd_log_commited_databuf + databufhdrs_needed +
434-
revokes;
435433
/* One for the overall header */
436434
if (reserved)
437435
reserved++;
@@ -693,16 +691,6 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
693691
INIT_LIST_HEAD(&tr->tr_ail2_list);
694692
}
695693

696-
if (sdp->sd_log_num_buf != sdp->sd_log_commited_buf) {
697-
printk(KERN_INFO "GFS2: log buf %u %u\n", sdp->sd_log_num_buf,
698-
sdp->sd_log_commited_buf);
699-
gfs2_assert_withdraw(sdp, 0);
700-
}
701-
if (sdp->sd_log_num_databuf != sdp->sd_log_commited_databuf) {
702-
printk(KERN_INFO "GFS2: log databuf %u %u\n",
703-
sdp->sd_log_num_databuf, sdp->sd_log_commited_databuf);
704-
gfs2_assert_withdraw(sdp, 0);
705-
}
706694
gfs2_assert_withdraw(sdp,
707695
sdp->sd_log_num_revoke == sdp->sd_log_commited_revoke);
708696

@@ -727,8 +715,6 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
727715
gfs2_log_lock(sdp);
728716
sdp->sd_log_head = sdp->sd_log_flush_head;
729717
sdp->sd_log_blks_reserved = 0;
730-
sdp->sd_log_commited_buf = 0;
731-
sdp->sd_log_commited_databuf = 0;
732718
sdp->sd_log_commited_revoke = 0;
733719

734720
spin_lock(&sdp->sd_ail_lock);
@@ -769,31 +755,29 @@ static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
769755
{
770756
unsigned int reserved;
771757
unsigned int unused;
758+
unsigned int maxres;
772759

773760
gfs2_log_lock(sdp);
774761

775-
sdp->sd_log_commited_buf += tr->tr_num_buf_new - tr->tr_num_buf_rm;
776-
sdp->sd_log_commited_databuf += tr->tr_num_databuf_new -
777-
tr->tr_num_databuf_rm;
778-
gfs2_assert_withdraw(sdp, (((int)sdp->sd_log_commited_buf) >= 0) ||
779-
(((int)sdp->sd_log_commited_databuf) >= 0));
762+
if (sdp->sd_log_tr) {
763+
gfs2_merge_trans(sdp->sd_log_tr, tr);
764+
} else if (tr->tr_num_buf_new || tr->tr_num_databuf_new) {
765+
gfs2_assert_withdraw(sdp, tr->tr_t_gh.gh_gl);
766+
sdp->sd_log_tr = tr;
767+
tr->tr_attached = 1;
768+
}
769+
780770
sdp->sd_log_commited_revoke += tr->tr_num_revoke - tr->tr_num_revoke_rm;
781771
reserved = calc_reserved(sdp);
782-
gfs2_assert_withdraw(sdp, sdp->sd_log_blks_reserved + tr->tr_reserved >= reserved);
783-
unused = sdp->sd_log_blks_reserved - reserved + tr->tr_reserved;
772+
maxres = sdp->sd_log_blks_reserved + tr->tr_reserved;
773+
gfs2_assert_withdraw(sdp, maxres >= reserved);
774+
unused = maxres - reserved;
784775
atomic_add(unused, &sdp->sd_log_blks_free);
785776
trace_gfs2_log_blocks(sdp, unused);
786777
gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <=
787778
sdp->sd_jdesc->jd_blocks);
788779
sdp->sd_log_blks_reserved = reserved;
789780

790-
if (sdp->sd_log_tr) {
791-
gfs2_merge_trans(sdp->sd_log_tr, tr);
792-
} else if (tr->tr_num_buf_new || tr->tr_num_databuf_new) {
793-
gfs2_assert_withdraw(sdp, tr->tr_t_gh.gh_gl);
794-
sdp->sd_log_tr = tr;
795-
tr->tr_attached = 1;
796-
}
797781
gfs2_log_unlock(sdp);
798782
}
799783

@@ -833,10 +817,7 @@ void gfs2_log_shutdown(struct gfs2_sbd *sdp)
833817
down_write(&sdp->sd_log_flush_lock);
834818

835819
gfs2_assert_withdraw(sdp, !sdp->sd_log_blks_reserved);
836-
gfs2_assert_withdraw(sdp, !sdp->sd_log_num_buf);
837820
gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke);
838-
gfs2_assert_withdraw(sdp, !sdp->sd_log_num_rg);
839-
gfs2_assert_withdraw(sdp, !sdp->sd_log_num_databuf);
840821
gfs2_assert_withdraw(sdp, list_empty(&sdp->sd_ail1_list));
841822

842823
sdp->sd_log_flush_head = sdp->sd_log_head;

‎fs/gfs2/lops.c‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,11 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
494494
static void buf_lo_before_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
495495
{
496496
unsigned int limit = buf_limit(sdp); /* 503 for 4k blocks */
497+
unsigned int nbuf;
497498
if (tr == NULL)
498499
return;
499-
gfs2_before_commit(sdp, limit, sdp->sd_log_num_buf, &tr->tr_buf, 0);
500+
nbuf = tr->tr_num_buf_new - tr->tr_num_buf_rm;
501+
gfs2_before_commit(sdp, limit, nbuf, &tr->tr_buf, 0);
500502
}
501503

502504
static void buf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
@@ -511,11 +513,8 @@ static void buf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
511513
while (!list_empty(head)) {
512514
bd = list_entry(head->next, struct gfs2_bufdata, bd_list);
513515
list_del_init(&bd->bd_list);
514-
sdp->sd_log_num_buf--;
515-
516516
gfs2_unpin(sdp, bd->bd_bh, tr);
517517
}
518-
gfs2_assert_warn(sdp, !sdp->sd_log_num_buf);
519518
}
520519

521520
static void buf_lo_before_scan(struct gfs2_jdesc *jd,
@@ -761,10 +760,12 @@ static void revoke_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass)
761760

762761
static void databuf_lo_before_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
763762
{
764-
unsigned int limit = buf_limit(sdp) / 2;
763+
unsigned int limit = databuf_limit(sdp);
764+
unsigned int nbuf;
765765
if (tr == NULL)
766766
return;
767-
gfs2_before_commit(sdp, limit, sdp->sd_log_num_databuf, &tr->tr_databuf, 1);
767+
nbuf = tr->tr_num_databuf_new - tr->tr_num_databuf_rm;
768+
gfs2_before_commit(sdp, limit, nbuf, &tr->tr_databuf, 1);
768769
}
769770

770771
static int databuf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start,
@@ -849,10 +850,8 @@ static void databuf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
849850
while (!list_empty(head)) {
850851
bd = list_entry(head->next, struct gfs2_bufdata, bd_list);
851852
list_del_init(&bd->bd_list);
852-
sdp->sd_log_num_databuf--;
853853
gfs2_unpin(sdp, bd->bd_bh, tr);
854854
}
855-
gfs2_assert_warn(sdp, !sdp->sd_log_num_databuf);
856855
}
857856

858857

‎fs/gfs2/meta_io.c‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,10 @@ void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr, int
267267
trace_gfs2_pin(bd, 0);
268268
atomic_dec(&sdp->sd_log_pinned);
269269
list_del_init(&bd->bd_list);
270-
if (meta) {
271-
gfs2_assert_warn(sdp, sdp->sd_log_num_buf);
272-
sdp->sd_log_num_buf--;
270+
if (meta)
273271
tr->tr_num_buf_rm++;
274-
} else {
275-
gfs2_assert_warn(sdp, sdp->sd_log_num_databuf);
276-
sdp->sd_log_num_databuf--;
272+
else
277273
tr->tr_num_databuf_rm++;
278-
}
279274
tr->tr_touched = 1;
280275
was_pinned = 1;
281276
brelse(bh);

‎fs/gfs2/trans.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ void gfs2_trans_add_data(struct gfs2_glock *gl, struct buffer_head *bh)
213213
set_bit(GLF_DIRTY, &bd->bd_gl->gl_flags);
214214
gfs2_pin(sdp, bd->bd_bh);
215215
tr->tr_num_databuf_new++;
216-
sdp->sd_log_num_databuf++;
217216
list_add_tail(&bd->bd_list, &tr->tr_databuf);
218217
}
219218
gfs2_log_unlock(sdp);
@@ -241,7 +240,6 @@ static void meta_lo_add(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd)
241240
gfs2_pin(sdp, bd->bd_bh);
242241
mh->__pad0 = cpu_to_be64(0);
243242
mh->mh_jid = cpu_to_be32(sdp->sd_jdesc->jd_jid);
244-
sdp->sd_log_num_buf++;
245243
list_add(&bd->bd_list, &tr->tr_buf);
246244
tr->tr_num_buf_new++;
247245
}

0 commit comments

Comments
 (0)