summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSlava Pestov <sp@daterainc.com>2015-02-05 15:54:26 -0800
committerKent Overstreet <kmo@daterainc.com>2015-02-12 23:43:55 -0800
commit6ba32f2e088b425f42b68c22ebe57f15c8996a48 (patch)
tree801b099bf4292d98fd3d203d0ac5deb64afb38fc
parent3b7ddfc37585a67cb4f6fc430d63248a2d933f9a (diff)
bcache: enforce minimum journal entry size
This lowers write latency by reducing the likelyhood that we fill up a journal entry really quickly while the previous journal write is still in progress. Previously, this would often happen when we are near the end of a journal bucket. Now, we just skip to the next journal bucket if we can't get a 32KiB journal entry. Change-Id: I08a0b40c75bb6b3486fd77f91a3caca7d9fffcf6
-rw-r--r--drivers/md/bcache/journal.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/drivers/md/bcache/journal.c b/drivers/md/bcache/journal.c
index cc8156c44850..8dce022a2b57 100644
--- a/drivers/md/bcache/journal.c
+++ b/drivers/md/bcache/journal.c
@@ -701,11 +701,14 @@ static inline unsigned journal_free_buckets(struct cache *ca)
return (ja->last_idx - ja->cur_idx + nr - 1) % nr;
}
+#define JSET_SECTORS (PAGE_SECTORS << JSET_BITS)
+
+/* Number of u64s we can write to the current journal bucket */
static size_t journal_write_u64s_remaining(struct cache_set *c)
{
- ssize_t u64s = min_t(size_t,
- c->journal.sectors_free << 9,
- PAGE_SIZE << JSET_BITS) / sizeof(u64);
+ ssize_t u64s = (min_t(size_t,
+ c->journal.sectors_free,
+ JSET_SECTORS) << 9) / sizeof(u64);
/* Subtract off some for the btree roots */
u64s -= BTREE_ID_NR * (JSET_KEYS_U64s + BKEY_EXTENT_MAX_U64s);
@@ -1075,6 +1078,17 @@ static void journal_write_locked(struct closure *cl)
BUG_ON(sectors > ca->journal.sectors_free);
ca->journal.sectors_free -= sectors;
+ /*
+ * If we don't have enough space for a full-sized journal
+ * entry, go to the next bucket. We do this check after
+ * the write, so that if our bucket size is really small
+ * we don't get stuck forever.
+ */
+ if (ca->journal.sectors_free < JSET_SECTORS) {
+ c->journal.sectors_free = 0;
+ ca->journal.sectors_free = 0;
+ }
+
bio = &ca->journal.bio;
atomic_long_add(sectors, &ca->meta_sectors_written);