Skip to contentSkip to conversation

Speed up journal head lookup

RFC PATCH New Abhi Das 1 participant 6 messages Aug 13, 2018 GFS2 file system

lore
Share & tools
lore

Abhi Das

author
#0 lore raw

v2 cover Speed up journal head lookup

This is a revised version of the patch set I'd posted earlier to speed up jhead lookup during recovery.

I've made some changes as per Steve's suggestions based on the previous version:
https://www.redhat.com/archives/cluster-devel/2018-May/msg00088.html

As before, this patchset is based on the latest RHEL7 codebase as it is easier for me to test. Upstream version shouldn't be very dissimilar and I'll post the upstream port if it looks good.

I'll do a bit more testing and report some performance numbers shortly.

Cheers!
--Abhi

Abhi Das (5):
gfs2: allow map_journal_extents() to take a journal descriptor as
argument
gfs2: add timing info for various stages of journal recovery
gfs2: changes to gfs2_log_XXX_bio
gfs2: read journal in large chunks to locate the head
gfs2: add tracepoint debugging for gfs2_end_log_read

 fs/gfs2/incore.h     |   9 +++-
 fs/gfs2/log.c        |   4 +-
 fs/gfs2/log.h        |   1 +
 fs/gfs2/lops.c       | 142 +++++++++++++++++++++++++++++++++++++++++++--------
 fs/gfs2/lops.h       |  15 +++++-
 fs/gfs2/ops_fstype.c |  12 +++--
 fs/gfs2/recovery.c   | 138 ++++++++++---------------------------------------
 fs/gfs2/recovery.h   |   1 +
 fs/gfs2/trace_gfs2.h |  25 +++++++++
 9 files changed, 208 insertions(+), 139 deletions(-)
Signature · 1 line
2.4.11
author
#1 lore raw

RFC PATCH v2 1/5 gfs2: allow map_journal_extents() to take a journal descriptor as argument

This function now maps the extents for the journal whose descriptor is passed in as argument.

---
 fs/gfs2/log.h        | 1 +
 fs/gfs2/ops_fstype.c | 5 ++---
 2 files changed, 3 insertions(+), 3 deletions(-)
fs/gfs2/log.h +1 -0
index 92dcbe7..19c93df 100644
@@ -75,4 +75,5 @@ extern int gfs2_logd(void *data);
 extern void gfs2_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd);
 extern void gfs2_write_revokes(struct gfs2_sbd *sdp);
 
+extern int map_journal_extents(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd);
 #endif /* __LOG_DOT_H__ */
fs/gfs2/ops_fstype.c +2 -3
index 228f38e..cf3e366 100644
@@ -524,9 +524,8 @@ out:
  *       but since it's only done at mount time, I'm not worried about the
  *       time it takes.
  */
-static int map_journal_extents(struct gfs2_sbd *sdp)
+int map_journal_extents(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd)
 {
-	struct gfs2_jdesc *jd = sdp->sd_jdesc;
 	unsigned int lb;
 	u64 db, prev_db; /* logical block, disk block, prev disk block */
 	struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
@@ -772,7 +771,7 @@ static int init_journal(struct gfs2_sbd *sdp, int undo)
 		atomic_set(&sdp->sd_log_thresh2, 4*sdp->sd_jdesc->jd_blocks/5);
 
 		/* Map the extents for this journal's blocks */
-		map_journal_extents(sdp);
+		map_journal_extents(sdp, sdp->sd_jdesc);
 	}
 	trace_gfs2_log_blocks(sdp, atomic_read(&sdp->sd_log_blks_free));
 
Signature · 1 line
2.4.11
author
#2 lore raw

RFC PATCH v2 2/5 gfs2: add timing info for various stages of journal recovery

In reply to Abhi Das

Tells you how many milliseconds each stage of journal recovery takes.

---
 fs/gfs2/ops_fstype.c |  5 +++++
 fs/gfs2/recovery.c   | 20 ++++++++++++++------
 2 files changed, 19 insertions(+), 6 deletions(-)
fs/gfs2/ops_fstype.c +5 -0
index cf3e366..fd460c1 100644
@@ -532,7 +532,9 @@ int map_journal_extents(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd)
 	struct gfs2_journal_extent *jext = NULL;
 	struct buffer_head bh;
 	int rc = 0;
+	ktime_t start, end;
 
+	start = ktime_get();
 	prev_db = 0;
 
 	for (lb = 0; lb < i_size_read(jd->jd_inode) >> sdp->sd_sb.sb_bsize_shift; lb++) {
@@ -564,6 +566,9 @@ int map_journal_extents(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd)
 		}
 		prev_db = db;
 	}
+	end = ktime_get();
+	fs_info(sdp, "jid=%u: Journal extent mapped in %lldms\n", jd->jd_jid,
+		ktime_ms_delta(end, start));
 	return rc;
 }
 
fs/gfs2/recovery.c +14 -6
index 56dea44..4b042db 100644
@@ -14,6 +14,7 @@
 #include <linux/buffer_head.h>
 #include <linux/gfs2_ondisk.h>
 #include <linux/crc32.h>
+#include <linux/ktime.h>
 
 #include "gfs2.h"
 #include "incore.h"
@@ -455,12 +456,13 @@ void gfs2_recover_func(struct work_struct *work)
 	struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
 	struct gfs2_log_header_host head;
 	struct gfs2_holder j_gh, ji_gh, t_gh;
-	unsigned long t;
+	ktime_t t_start, t_jlck, t_jhd, t_tlck, t_rep;
 	int ro = 0;
 	unsigned int pass;
 	int error;
 	int jlocked = 0;
 
+	t_start = ktime_get();
 	if (sdp->sd_args.ar_spectator ||
 	    (jd->jd_jid != sdp->sd_lockstruct.ls_jid)) {
 		fs_info(sdp, "jid=%u: Trying to acquire journal lock...\n",
@@ -492,6 +494,7 @@ void gfs2_recover_func(struct work_struct *work)
 		fs_info(sdp, "jid=%u, already locked for use\n", jd->jd_jid);
 	}
 
+	t_jlck = ktime_get();
 	fs_info(sdp, "jid=%u: Looking at journal...\n", jd->jd_jid);
 
 	error = gfs2_jdesc_check(jd);
@@ -501,13 +504,12 @@ void gfs2_recover_func(struct work_struct *work)
 	error = gfs2_find_jhead(jd, &head);
 	if (error)
 		goto fail_gunlock_ji;
+	t_jhd = ktime_get();
 
 	if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) {
 		fs_info(sdp, "jid=%u: Acquiring the transaction lock...\n",
 			jd->jd_jid);
 
-		t = jiffies;
-
 		/* Acquire a shared hold on the transaction lock */
 
 		error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED,
@@ -541,6 +543,7 @@ void gfs2_recover_func(struct work_struct *work)
 			goto fail_gunlock_tr;
 		}
 
+		t_tlck = ktime_get();
 		fs_info(sdp, "jid=%u: Replaying journal...\n", jd->jd_jid);
 
 		for (pass = 0; pass < 2; pass++) {
@@ -557,9 +560,14 @@ void gfs2_recover_func(struct work_struct *work)
 			goto fail_gunlock_tr;
 
 		gfs2_glock_dq_uninit(&t_gh);
-		t = DIV_ROUND_UP(jiffies - t, HZ);
-		fs_info(sdp, "jid=%u: Journal replayed in %lus\n",
-			jd->jd_jid, t);
+		t_rep = ktime_get();
+		fs_info(sdp, "jid=%u: Journal replayed in %lldms [jlck:%lldms, "
+			"jhead:%lldms, tlck:%lldms, replay:%lldms]\n",
+			jd->jd_jid, ktime_ms_delta(t_rep, t_start),
+			ktime_ms_delta(t_jlck, t_start),
+			ktime_ms_delta(t_jhd, t_jlck),
+			ktime_ms_delta(t_tlck, t_jhd),
+			ktime_ms_delta(t_rep, t_tlck));
 	}
 
 	gfs2_recovery_done(sdp, jd->jd_jid, LM_RD_SUCCESS);
Signature · 1 line
2.4.11
author
#3 lore raw

RFC PATCH v2 3/5 gfs2: changes to gfs2_log_XXX_bio

In reply to Abhi Das

Change gfs2_log_flush_bio to accept a pointer to the struct bio to be flushed. Change gfs2_log_alloc_bio and gfs2_log_get_bio to take a struct gfs2_jdesc instead of gfs2_sbd.

---
 fs/gfs2/log.c  |  4 ++--
 fs/gfs2/lops.c | 32 ++++++++++++++++++--------------
 fs/gfs2/lops.h |  2 +-
 3 files changed, 21 insertions(+), 17 deletions(-)
fs/gfs2/log.c +2 -2
index 15a3a8c..87b7d87 100644
@@ -655,7 +655,7 @@ static void log_write_header(struct gfs2_sbd *sdp, u32 flags)
 
 	sdp->sd_log_idle = (tail == sdp->sd_log_flush_head);
 	gfs2_log_write_page(sdp, page);
-	gfs2_log_flush_bio(sdp, rw);
+	gfs2_log_flush_bio(&sdp->sd_log_bio, rw);
 	log_flush_wait(sdp);
 
 	if (sdp->sd_log_tail != tail)
@@ -699,7 +699,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
 
 	gfs2_ordered_write(sdp);
 	lops_before_commit(sdp, tr);
-	gfs2_log_flush_bio(sdp, WRITE);
+	gfs2_log_flush_bio(&sdp->sd_log_bio, WRITE);
 
 	if (sdp->sd_log_head != sdp->sd_log_flush_head) {
 		log_flush_wait(sdp);
fs/gfs2/lops.c +18 -14
index 4da6055..0284648 100644
@@ -230,25 +230,27 @@ static void gfs2_end_log_write(struct bio *bio, int error)
 
 /**
  * gfs2_log_flush_bio - Submit any pending log bio
- * @sdp: The superblock
+ * @biop: Pointer to the bio we want to flush
  * @rw: The rw flags
  *
  * Submit any pending part-built or full bio to the block device. If
  * there is no pending bio, then this is a no-op.
  */
 
-void gfs2_log_flush_bio(struct gfs2_sbd *sdp, int rw)
+void gfs2_log_flush_bio(struct bio **biop, int rw)
 {
-	if (sdp->sd_log_bio) {
+	struct bio *bio = *biop;
+	if (bio) {
+		struct gfs2_sbd *sdp = bio->bi_private;
 		atomic_inc(&sdp->sd_log_in_flight);
-		submit_bio(rw, sdp->sd_log_bio);
-		sdp->sd_log_bio = NULL;
+		submit_bio(rw, bio);
+		*biop = NULL;
 	}
 }
 
 /**
  * gfs2_log_alloc_bio - Allocate a new bio for log writing
- * @sdp: The superblock
+ * @jd: The journal descriptor
  * @blkno: The next device block number we want to write to
  *
  * This should never be called when there is a cached bio in the
@@ -259,8 +261,9 @@ void gfs2_log_flush_bio(struct gfs2_sbd *sdp, int rw)
  * Returns: Newly allocated bio
  */
 
-static struct bio *gfs2_log_alloc_bio(struct gfs2_sbd *sdp, u64 blkno)
+static struct bio *gfs2_log_alloc_bio(struct gfs2_jdesc *jd, u64 blkno)
 {
+	struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
 	struct super_block *sb = sdp->sd_vfs;
 	unsigned nrvecs = bio_get_nr_vecs(sb->s_bdev);
 	struct bio *bio;
@@ -286,7 +289,7 @@ static struct bio *gfs2_log_alloc_bio(struct gfs2_sbd *sdp, u64 blkno)
 
 /**
  * gfs2_log_get_bio - Get cached log bio, or allocate a new one
- * @sdp: The superblock
+ * @jd: The journal descriptor
  * @blkno: The device block number we want to write to
  *
  * If there is a cached bio, then if the next block number is sequential
@@ -297,8 +300,9 @@ static struct bio *gfs2_log_alloc_bio(struct gfs2_sbd *sdp, u64 blkno)
  * Returns: The bio to use for log writes
  */
 
-static struct bio *gfs2_log_get_bio(struct gfs2_sbd *sdp, u64 blkno)
+static struct bio *gfs2_log_get_bio(struct gfs2_jdesc *jd, u64 blkno)
 {
+	struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
 	struct bio *bio = sdp->sd_log_bio;
 	u64 nblk;
 
@@ -307,10 +311,10 @@ static struct bio *gfs2_log_get_bio(struct gfs2_sbd *sdp, u64 blkno)
 		nblk >>= sdp->sd_fsb2bb_shift;
 		if (blkno == nblk)
 			return bio;
-		gfs2_log_flush_bio(sdp, WRITE);
+		gfs2_log_flush_bio(&sdp->sd_log_bio, WRITE);
 	}
 
-	return gfs2_log_alloc_bio(sdp, blkno);
+	return gfs2_log_alloc_bio(sdp->sd_jdesc, blkno);
 }
 
 
@@ -333,11 +337,11 @@ static void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page,
 	struct bio *bio;
 	int ret;
 
-	bio = gfs2_log_get_bio(sdp, blkno);
+	bio = gfs2_log_get_bio(sdp->sd_jdesc, blkno);
 	ret = bio_add_page(bio, page, size, offset);
 	if (ret == 0) {
-		gfs2_log_flush_bio(sdp, WRITE);
-		bio = gfs2_log_alloc_bio(sdp, blkno);
+		gfs2_log_flush_bio(&sdp->sd_log_bio, WRITE);
+		bio = gfs2_log_alloc_bio(sdp->sd_jdesc, blkno);
 		ret = bio_add_page(bio, page, size, offset);
 		WARN_ON(ret == 0);
 	}
fs/gfs2/lops.h +1 -1
index 06793e3..3044347 100644
@@ -28,7 +28,7 @@ extern const struct gfs2_log_operations gfs2_databuf_lops;
 
 extern const struct gfs2_log_operations *gfs2_log_ops[];
 extern void gfs2_log_write_page(struct gfs2_sbd *sdp, struct page *page);
-extern void gfs2_log_flush_bio(struct gfs2_sbd *sdp, int rw);
+extern void gfs2_log_flush_bio(struct bio **biop, int rw);
 extern void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh);
 
 static inline unsigned int buf_limit(struct gfs2_sbd *sdp)
Signature · 1 line
2.4.11
author
#4 lore raw

RFC PATCH v2 4/5 gfs2: read journal in large chunks to locate the head

In reply to Abhi Das

Use bio(s) to read in the journal sequentially in large chunks and locate the head of the journal.
This is faster in most cases when compared to the existing bisect method which operates one block at a time.

---
 fs/gfs2/incore.h     |   8 +++-
 fs/gfs2/lops.c       | 121 +++++++++++++++++++++++++++++++++++++++++++++------
 fs/gfs2/lops.h       |  13 ++++++
 fs/gfs2/ops_fstype.c |   1 +
 fs/gfs2/recovery.c   | 118 +++++--------------------------------------------
 fs/gfs2/recovery.h   |   1 +
 6 files changed, 142 insertions(+), 120 deletions(-)
fs/gfs2/incore.h +7 -1
index f303616..31188c0 100644
@@ -494,18 +494,24 @@ struct gfs2_journal_extent {
 	u64 blocks;
 };
 
+enum {
+	JDF_RECOVERY = 1,
+	JDF_JHEAD    = 2,
+};
+
 struct gfs2_jdesc {
 	struct list_head jd_list;
 	struct list_head extent_list;
 	struct work_struct jd_work;
 	struct inode *jd_inode;
 	unsigned long jd_flags;
-#define JDF_RECOVERY 1
 	unsigned int jd_jid;
 	unsigned int jd_blocks;
 	int jd_recover_error;
 	/* Replay stuff */
 
+	struct gfs2_log_header_host jd_jhead;
+	struct bio *jd_rd_bio; /* bio used for reading this journal */
 	unsigned int jd_found_blocks;
 	unsigned int jd_found_revokes;
 	unsigned int jd_replayed_blocks;
fs/gfs2/lops.c +108 -13

183 lines not on this page · raw message

fs/gfs2/lops.h +13 -0
index 3044347..4d7841f 100644
@@ -11,6 +11,7 @@
 #define __LOPS_DOT_H__
 
 #include <linux/list.h>
+#include <linux/crc32.h>
 #include "incore.h"
 
 #define BUF_OFFSET \
@@ -30,6 +31,7 @@ extern const struct gfs2_log_operations *gfs2_log_ops[];
 extern void gfs2_log_write_page(struct gfs2_sbd *sdp, struct page *page);
 extern void gfs2_log_flush_bio(struct bio **biop, int rw);
 extern void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh);
+extern void gfs2_log_read(struct gfs2_jdesc *jd);
 
 static inline unsigned int buf_limit(struct gfs2_sbd *sdp)
 {
@@ -101,5 +103,16 @@ static inline void lops_after_scan(struct gfs2_jdesc *jd, int error,
 			gfs2_log_ops[x]->lo_after_scan(jd, error, pass);
 }
 
+static inline u32 compute_hash(const void *ptr)
+{
+	const u32 nothing = 0;
+	u32 hash;
+
+	hash = crc32_le((u32)~0, ptr, sizeof(struct gfs2_log_header) - sizeof(u32));
+	hash = crc32_le(hash, (unsigned char const *)&nothing, sizeof(nothing));
+	hash ^= (u32)~0;
+
+	return hash;
+}
 #endif /* __LOPS_DOT_H__ */
 
fs/gfs2/ops_fstype.c +1 -0
index fd460c1..4a17eaf 100644
@@ -642,6 +642,7 @@ static int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh)
 			kfree(jd);
 			break;
 		}
+		jd->jd_rd_bio = NULL;
 
 		spin_lock(&sdp->sd_jindex_spin);
 		jd->jd_jid = sdp->sd_journals++;
fs/gfs2/recovery.c +12 -106

143 lines not on this page · raw message

fs/gfs2/recovery.h +1 -0
index 11fdfab..cd691ff 100644
@@ -29,6 +29,7 @@ extern void gfs2_revoke_clean(struct gfs2_jdesc *jd);
 
 extern int gfs2_find_jhead(struct gfs2_jdesc *jd,
 		    struct gfs2_log_header_host *head);
+extern int gfs2_log_header_in(struct gfs2_log_header_host *lh, const void *buf);
 extern int gfs2_recover_journal(struct gfs2_jdesc *gfs2_jd, bool wait);
 extern void gfs2_recover_func(struct work_struct *work);
 
Signature · 1 line
2.4.11
author
#5 lore raw

RFC PATCH v2 5/5 gfs2: add tracepoint debugging for gfs2_end_log_read

In reply to Abhi Das

Use a tracepoint and a counter in gfs2_jdesc to count the number of outstanding reads (in pages) as we read through a journal to aid debugging.

---
 fs/gfs2/incore.h     |  1 +
 fs/gfs2/lops.c       |  3 +++
 fs/gfs2/ops_fstype.c |  1 +
 fs/gfs2/trace_gfs2.h | 25 +++++++++++++++++++++++++
 4 files changed, 30 insertions(+)
fs/gfs2/incore.h +1 -0
index 31188c0..bb4446d 100644
@@ -512,6 +512,7 @@ struct gfs2_jdesc {
 
 	struct gfs2_log_header_host jd_jhead;
 	struct bio *jd_rd_bio; /* bio used for reading this journal */
+	atomic_t jd_rd_pg_ct;
 	unsigned int jd_found_blocks;
 	unsigned int jd_found_revokes;
 	unsigned int jd_replayed_blocks;
fs/gfs2/lops.c +3 -0
index 518b786..a261398 100644
@@ -250,6 +250,7 @@ static void gfs2_end_log_read(struct bio *bio, int error)
 		ptr = page_address(page);
 		error = gfs2_log_header_in(&lh, ptr);
 		last = page_private(page);
+		atomic_dec(&jd->jd_rd_pg_ct);
 
 		if (!test_bit(JDF_JHEAD, &jd->jd_flags)) {
 			mempool_free(page, gfs2_page_pool);
@@ -273,6 +274,7 @@ static void gfs2_end_log_read(struct bio *bio, int error)
 	}
 
 	bio_put(bio);
+	trace_gfs2_end_log_read(jd);
 }
 
 /**
@@ -454,6 +456,7 @@ void gfs2_log_read_extent(struct gfs2_jdesc *jd, u64 dblock,
 			ret = bio_add_page(bio, page, sb->s_blocksize, 0);
 			WARN_ON(ret == 0);
 		}
+		atomic_inc(&jd->jd_rd_pg_ct);
 		bio->bi_private = jd;
 	}
 }
fs/gfs2/ops_fstype.c +1 -0
index 4a17eaf..ac9855a 100644
@@ -643,6 +643,7 @@ static int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh)
 			break;
 		}
 		jd->jd_rd_bio = NULL;
+		atomic_set(&jd->jd_rd_pg_ct, 0);
 
 		spin_lock(&sdp->sd_jindex_spin);
 		jd->jd_jid = sdp->sd_journals++;
fs/gfs2/trace_gfs2.h +25 -0
index d1de2ed..9f0cc8d 100644
@@ -613,6 +613,31 @@ TRACE_EVENT(gfs2_rs,
 		  rs_func_name(__entry->func), (unsigned long)__entry->free)
 );
 
+TRACE_EVENT(gfs2_end_log_read,
+
+	TP_PROTO(const struct gfs2_jdesc *jd),
+
+
+	TP_ARGS(jd),
+
+	TP_STRUCT__entry(
+		__field(        dev_t,        dev               )
+		__field(	unsigned int, jid		)
+		__field(	unsigned int, pages 	        )
+	),
+
+	TP_fast_assign(
+		__entry->dev            = jd->jd_inode->i_sb->s_dev;
+		__entry->jid		= jd->jd_jid;
+		__entry->pages		= atomic_read(&jd->jd_rd_pg_ct);
+	),
+
+	TP_printk("%u,%u end_log_read jid:%u outstanding pages:%u",
+		  MAJOR(__entry->dev), MINOR(__entry->dev),
+		  (unsigned int)__entry->jid,
+		  (unsigned int)__entry->pages)
+);
+
 #endif /* _TRACE_GFS2_H */
 
 /* This part must be outside protection */
Signature · 1 line
2.4.11