*/
        xlog_cil_insert_format_items(log, tp, &len);
 
-       spin_lock(&cil->xc_cil_lock);
-
-       /* attach the transaction to the CIL if it has any busy extents */
-       if (!list_empty(&tp->t_busy))
-               list_splice_init(&tp->t_busy, &ctx->busy_extents);
-
        /*
         * We need to take the CIL checkpoint unit reservation on the first
         * commit into the CIL. Test the XLOG_CIL_EMPTY bit first so we don't
-        * unnecessarily do an atomic op in the fast path here.
+        * unnecessarily do an atomic op in the fast path here. We don't need to
+        * hold the xc_cil_lock here to clear the XLOG_CIL_EMPTY bit as we are
+        * under the xc_ctx_lock here and that needs to be held exclusively to
+        * reset the XLOG_CIL_EMPTY bit.
         */
        if (test_bit(XLOG_CIL_EMPTY, &cil->xc_flags) &&
-           test_and_clear_bit(XLOG_CIL_EMPTY, &cil->xc_flags)) {
+           test_and_clear_bit(XLOG_CIL_EMPTY, &cil->xc_flags))
                ctx_res = ctx->ticket->t_unit_res;
-               ctx->ticket->t_curr_res = ctx_res;
-               tp->t_ticket->t_curr_res -= ctx_res;
-       }
+
+       spin_lock(&cil->xc_cil_lock);
 
        /* do we need space for more log record headers? */
        iclog_space = log->l_iclog_size - log->l_iclog_hsize;
                /* need to take into account split region headers, too */
                split_res *= log->l_iclog_hsize + sizeof(struct xlog_op_header);
                ctx->ticket->t_unit_res += split_res;
-               ctx->ticket->t_curr_res += split_res;
-               tp->t_ticket->t_curr_res -= split_res;
-               ASSERT(tp->t_ticket->t_curr_res >= len);
        }
-       tp->t_ticket->t_curr_res -= len;
-       tp->t_ticket->t_curr_res += released_space;
+       tp->t_ticket->t_curr_res -= split_res + ctx_res + len;
+       ctx->ticket->t_curr_res += split_res + ctx_res;
        ctx->space_used += len;
+
+       tp->t_ticket->t_curr_res += released_space;
        ctx->space_used -= released_space;
 
        /*
                        list_move_tail(&lip->li_cil, &cil->xc_cil);
        }
 
+       /* attach the transaction to the CIL if it has any busy extents */
+       if (!list_empty(&tp->t_busy))
+               list_splice_init(&tp->t_busy, &ctx->busy_extents);
        spin_unlock(&cil->xc_cil_lock);
 
        if (tp->t_ticket->t_curr_res < 0)