From: Brian Foster <bfoster@redhat.com>
To: linux-xfs@vger.kernel.org
Subject: [RFC v6 PATCH 04/10] xfs: relog log reservation stealing and accounting
Date: Mon, 6 Apr 2020 08:36:26 -0400 [thread overview]
Message-ID: <20200406123632.20873-5-bfoster@redhat.com> (raw)
In-Reply-To: <20200406123632.20873-1-bfoster@redhat.com>
The transaction that eventually commits relog enabled log items
requires log reservation like any other transaction. It is not safe
to acquire reservation on-demand because relogged items aren't
processed until they are likely at the tail of the log and require
movement in order to free up space in the log. As such, a relog
transaction that blocks on log reservation is a likely deadlock
vector.
To address this problem, implement a model where relog reservation
is contributed by the transaction that enables relogging on a
particular item. Update the relog helper to transfer reservation
from the transaction to the relog pool. The relog pool holds
outstanding reservation such that it can be used to commit the item
in an otherwise empty transaction. The upcoming relog mechanism is
responsible to replenish the relog reservation as items are
relogged. When relog is cancelled on a log item, transfer the
outstanding relog reservation to the current transaction (if
provided) for eventual release or otherwise release it directly to
the grant heads.
Note that this approach has several caveats:
- Log reservation calculations for transactions that relog items
must be increased accordingly.
- Each current transaction reservation includes extra space for
various overheads, such as for the CIL ticket, etc. Since items
can be relogged in arbitrary combinations, this reservation
overhead must be included for each relogged item.
- Relog reservation must be based on the worst case log requirement
for the lifetime of an item. This is not a concern for fixed size
log items, such as most intents. More granular log items like
buffers can have additional ranges dirtied after relogging has
been enabled for the item and the relog subsystem must have
enough reservation to accommodate.
Signed-off-by: Brian Foster <bfoster@redhat.com>
---
fs/xfs/xfs_log.c | 3 +++
fs/xfs/xfs_trans.c | 20 ++++++++++++++++++++
fs/xfs/xfs_trans.h | 17 +++++++++++++++++
fs/xfs/xfs_trans_ail.c | 2 ++
fs/xfs/xfs_trans_priv.h | 14 ++++++++++++++
5 files changed, 56 insertions(+)
diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c
index b55abde6c142..940e5bb9786c 100644
--- a/fs/xfs/xfs_log.c
+++ b/fs/xfs/xfs_log.c
@@ -983,6 +983,9 @@ xfs_log_item_init(
item->li_type = type;
item->li_ops = ops;
item->li_lv = NULL;
+#ifdef DEBUG
+ atomic64_set(&item->li_relog_res, 0);
+#endif
INIT_LIST_HEAD(&item->li_ail);
INIT_LIST_HEAD(&item->li_cil);
diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c
index 1b25980315bd..6fc81c3b8500 100644
--- a/fs/xfs/xfs_trans.c
+++ b/fs/xfs/xfs_trans.c
@@ -20,6 +20,7 @@
#include "xfs_trace.h"
#include "xfs_error.h"
#include "xfs_defer.h"
+#include "xfs_log_priv.h"
kmem_zone_t *xfs_trans_zone;
@@ -776,9 +777,19 @@ xfs_trans_relog_item(
struct xfs_trans *tp,
struct xfs_log_item *lip)
{
+ int nbytes;
+
+ ASSERT(tp->t_flags & XFS_TRANS_RELOG);
+
if (test_and_set_bit(XFS_LI_RELOG, &lip->li_flags))
return;
trace_xfs_relog_item(lip);
+
+ nbytes = xfs_relog_calc_res(lip);
+
+ tp->t_ticket->t_curr_res -= nbytes;
+ xfs_relog_res_account(lip, nbytes);
+ tp->t_flags |= XFS_TRANS_DIRTY;
}
void
@@ -786,9 +797,18 @@ xfs_trans_relog_item_cancel(
struct xfs_trans *tp,
struct xfs_log_item *lip)
{
+ int res;
+
if (!test_and_clear_bit(XFS_LI_RELOG, &lip->li_flags))
return;
trace_xfs_relog_item_cancel(lip);
+
+ res = xfs_relog_calc_res(lip);
+ if (tp)
+ tp->t_ticket->t_curr_res += res;
+ else
+ xfs_log_ungrant_bytes(lip->li_mountp, res);
+ xfs_relog_res_account(lip, -res);
}
/* Detach and unlock all of the items in a transaction */
diff --git a/fs/xfs/xfs_trans.h b/fs/xfs/xfs_trans.h
index 9ea0f415e5ca..b4bb2a6c5251 100644
--- a/fs/xfs/xfs_trans.h
+++ b/fs/xfs/xfs_trans.h
@@ -48,6 +48,9 @@ struct xfs_log_item {
struct xfs_log_vec *li_lv; /* active log vector */
struct xfs_log_vec *li_lv_shadow; /* standby vector */
xfs_lsn_t li_seq; /* CIL commit seq */
+#ifdef DEBUG
+ atomic64_t li_relog_res; /* automatic relog log res */
+#endif
};
/*
@@ -212,6 +215,20 @@ xfs_trans_read_buf(
flags, bpp, ops);
}
+static inline int
+xfs_relog_calc_res(
+ struct xfs_log_item *lip)
+{
+ int niovecs = 0;
+ int nbytes = 0;
+
+ lip->li_ops->iop_size(lip, &niovecs, &nbytes);
+ ASSERT(niovecs == 1);
+ nbytes = xfs_log_calc_unit_res(lip->li_mountp, nbytes);
+
+ return nbytes;
+}
+
struct xfs_buf *xfs_trans_getsb(xfs_trans_t *, struct xfs_mount *);
void xfs_trans_brelse(xfs_trans_t *, struct xfs_buf *);
diff --git a/fs/xfs/xfs_trans_ail.c b/fs/xfs/xfs_trans_ail.c
index 564253550b75..0b4b1c3cc4de 100644
--- a/fs/xfs/xfs_trans_ail.c
+++ b/fs/xfs/xfs_trans_ail.c
@@ -861,6 +861,7 @@ xfs_trans_ail_init(
spin_lock_init(&ailp->ail_lock);
INIT_LIST_HEAD(&ailp->ail_buf_list);
init_waitqueue_head(&ailp->ail_empty);
+ atomic64_set(&ailp->ail_relog_res, 0);
ailp->ail_task = kthread_run(xfsaild, ailp, "xfsaild/%s",
ailp->ail_mount->m_super->s_id);
@@ -881,6 +882,7 @@ xfs_trans_ail_destroy(
{
struct xfs_ail *ailp = mp->m_ail;
+ ASSERT(atomic64_read(&ailp->ail_relog_res) == 0);
kthread_stop(ailp->ail_task);
kmem_free(ailp);
}
diff --git a/fs/xfs/xfs_trans_priv.h b/fs/xfs/xfs_trans_priv.h
index c890794314a6..926bafdf6cd7 100644
--- a/fs/xfs/xfs_trans_priv.h
+++ b/fs/xfs/xfs_trans_priv.h
@@ -63,6 +63,7 @@ struct xfs_ail {
int ail_log_flush;
struct list_head ail_buf_list;
wait_queue_head_t ail_empty;
+ atomic64_t ail_relog_res;
};
/*
@@ -182,4 +183,17 @@ xfs_set_li_failed(
}
}
+static inline int64_t
+xfs_relog_res_account(
+ struct xfs_log_item *lip,
+ int64_t bytes)
+{
+#ifdef DEBUG
+ int64_t res;
+
+ res = atomic64_add_return(bytes, &lip->li_relog_res);
+ ASSERT(res == bytes || (bytes < 0 && res == 0));
+#endif
+ return atomic64_add_return(bytes, &lip->li_ailp->ail_relog_res);
+}
#endif /* __XFS_TRANS_PRIV_H__ */
--
2.21.1
next prev parent reply other threads:[~2020-04-06 12:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-06 12:36 [RFC v6 PATCH 00/10] xfs: automatic relogging experiment Brian Foster
2020-04-06 12:36 ` [RFC v6 PATCH 01/10] xfs: automatic relogging item management Brian Foster
2020-04-06 12:36 ` [RFC v6 PATCH 02/10] xfs: create helper for ticket-less log res ungrant Brian Foster
2020-04-06 23:52 ` Allison Collins
2020-04-06 12:36 ` [RFC v6 PATCH 03/10] xfs: extra runtime reservation overhead for relog transactions Brian Foster
2020-04-07 23:04 ` Allison Collins
2020-04-08 11:43 ` Brian Foster
2020-04-06 12:36 ` Brian Foster [this message]
2020-04-06 12:36 ` [RFC v6 PATCH 05/10] xfs: automatic log item relog mechanism Brian Foster
2020-04-06 12:36 ` [RFC v6 PATCH 06/10] xfs: automatically relog the quotaoff start intent Brian Foster
2020-04-06 12:36 ` [RFC v6 PATCH 07/10] xfs: prevent fs freeze with outstanding relog items Brian Foster
2020-04-09 0:05 ` Allison Collins
2020-04-06 12:36 ` [RFC v6 PATCH 08/10] xfs: buffer relogging support prototype Brian Foster
2020-04-06 12:36 ` [RFC v6 PATCH 09/10] xfs: create an error tag for random relog reservation Brian Foster
2020-04-06 12:36 ` [RFC v6 PATCH 10/10] xfs: relog random buffers based on errortag Brian Foster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200406123632.20873-5-bfoster@redhat.com \
--to=bfoster@redhat.com \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox