aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_log_priv.h
diff options
context:
space:
mode:
authorDave Chinner <dchinner@redhat.com>2010-12-20 20:29:14 -0500
committerDave Chinner <david@fromorbit.com>2010-12-20 20:29:14 -0500
commitd0eb2f38b250b7d6c993adf81b0e4ded0565497e (patch)
tree660923947f3f7d412bd65c58ba9d2e4c8835320b /fs/xfs/xfs_log_priv.h
parent3f16b9850743b702380f098ab5e0308cd6af1792 (diff)
xfs: convert grant head manipulations to lockless algorithm
The only thing that the grant lock remains to protect is the grant head manipulations when adding or removing space from the log. These calculations are already based on atomic variables, so we can already update them safely without locks. However, the grant head manpulations require atomic multi-step calculations to be executed, which the algorithms currently don't allow. To make these multi-step calculations atomic, convert the algorithms to compare-and-exchange loops on the atomic variables. That is, we sample the old value, perform the calculation and use atomic64_cmpxchg() to attempt to update the head with the new value. If the head has not changed since we sampled it, it will succeed and we are done. Otherwise, we rerun the calculation again from a new sample of the head. This allows us to remove the grant lock from around all the grant head space manipulations, and that effectively removes the grant lock from the log completely. Hence we can remove the grant lock completely from the log at this point. Signed-off-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'fs/xfs/xfs_log_priv.h')
-rw-r--r--fs/xfs/xfs_log_priv.h23
1 files changed, 15 insertions, 8 deletions
diff --git a/fs/xfs/xfs_log_priv.h b/fs/xfs/xfs_log_priv.h
index befb2fc5b027..d5f8be8f4bf6 100644
--- a/fs/xfs/xfs_log_priv.h
+++ b/fs/xfs/xfs_log_priv.h
@@ -510,9 +510,6 @@ typedef struct log {
510 int l_curr_block; /* current logical log block */ 510 int l_curr_block; /* current logical log block */
511 int l_prev_block; /* previous logical log block */ 511 int l_prev_block; /* previous logical log block */
512 512
513 /* The following block of fields are changed while holding grant_lock */
514 spinlock_t l_grant_lock ____cacheline_aligned_in_smp;
515
516 /* 513 /*
517 * l_last_sync_lsn and l_tail_lsn are atomics so they can be set and 514 * l_last_sync_lsn and l_tail_lsn are atomics so they can be set and
518 * read without needing to hold specific locks. To avoid operations 515 * read without needing to hold specific locks. To avoid operations
@@ -599,23 +596,33 @@ xlog_assign_atomic_lsn(atomic64_t *lsn, uint cycle, uint block)
599} 596}
600 597
601/* 598/*
602 * When we crack the grrant head, we sample it first so that the value will not 599 * When we crack the grant head, we sample it first so that the value will not
603 * change while we are cracking it into the component values. This means we 600 * change while we are cracking it into the component values. This means we
604 * will always get consistent component values to work from. 601 * will always get consistent component values to work from.
605 */ 602 */
606static inline void 603static inline void
607xlog_crack_grant_head(atomic64_t *head, int *cycle, int *space) 604xlog_crack_grant_head_val(int64_t val, int *cycle, int *space)
608{ 605{
609 int64_t val = atomic64_read(head);
610
611 *cycle = val >> 32; 606 *cycle = val >> 32;
612 *space = val & 0xffffffff; 607 *space = val & 0xffffffff;
613} 608}
614 609
615static inline void 610static inline void
611xlog_crack_grant_head(atomic64_t *head, int *cycle, int *space)
612{
613 xlog_crack_grant_head_val(atomic64_read(head), cycle, space);
614}
615
616static inline int64_t
617xlog_assign_grant_head_val(int cycle, int space)
618{
619 return ((int64_t)cycle << 32) | space;
620}
621
622static inline void
616xlog_assign_grant_head(atomic64_t *head, int cycle, int space) 623xlog_assign_grant_head(atomic64_t *head, int cycle, int space)
617{ 624{
618 atomic64_set(head, ((int64_t)cycle << 32) | space); 625 atomic64_set(head, xlog_assign_grant_head_val(cycle, space));
619} 626}
620 627
621/* 628/*