diff options
author | Dave Chinner <dchinner@redhat.com> | 2010-05-21 00:37:18 -0400 |
---|---|---|
committer | Alex Elder <aelder@sgi.com> | 2010-05-24 11:38:03 -0400 |
commit | 71e330b593905e40d6c5afa824d38ee02d70ce5f (patch) | |
tree | 4c9fa6c4766280752fc40f3057fd6cf64396c16c /fs/xfs/xfs_log_priv.h | |
parent | a9a745daadab26f13884ff26a50fa38247c11ce9 (diff) |
xfs: Introduce delayed logging core code
The delayed logging code only changes in-memory structures and as
such can be enabled and disabled with a mount option. Add the mount
option and emit a warning that this is an experimental feature that
should not be used in production yet.
We also need infrastructure to track committed items that have not
yet been written to the log. This is what the Committed Item List
(CIL) is for.
The log item also needs to be extended to track the current log
vector, the associated memory buffer and it's location in the Commit
Item List. Extend the log item and log vector structures to enable
this tracking.
To maintain the current log format for transactions with delayed
logging, we need to introduce a checkpoint transaction and a context
for tracking each checkpoint from initiation to transaction
completion. This includes adding a log ticket for tracking space
log required/used by the context checkpoint.
To track all the changes we need an io vector array per log item,
rather than a single array for the entire transaction. Using the new
log vector structure for this requires two passes - the first to
allocate the log vector structures and chain them together, and the
second to fill them out. This log vector chain can then be passed
to the CIL for formatting, pinning and insertion into the CIL.
Formatting of the log vector chain is relatively simple - it's just
a loop over the iovecs on each log vector, but it is made slightly
more complex because we re-write the iovec after the copy to point
back at the memory buffer we just copied into.
This code also needs to pin log items. If the log item is not
already tracked in this checkpoint context, then it needs to be
pinned. Otherwise it is already pinned and we don't need to pin it
again.
The only other complexity is calculating the amount of new log space
the formatting has consumed. This needs to be accounted to the
transaction in progress, and the accounting is made more complex
becase we need also to steal space from it for log metadata in the
checkpoint transaction. Calculate all this at insert time and update
all the tickets, counters, etc correctly.
Once we've formatted all the log items in the transaction, attach
the busy extents to the checkpoint context so the busy extents live
until checkpoint completion and can be processed at that point in
time. Transactions can then be freed at this point in time.
Now we need to issue checkpoints - we are tracking the amount of log space
used by the items in the CIL, so we can trigger background checkpoints when the
space usage gets to a certain threshold. Otherwise, checkpoints need ot be
triggered when a log synchronisation point is reached - a log force event.
Because the log write code already handles chained log vectors, writing the
transaction is trivial, too. Construct a transaction header, add it
to the head of the chain and write it into the log, then issue a
commit record write. Then we can release the checkpoint log ticket
and attach the context to the log buffer so it can be called during
Io completion to complete the checkpoint.
We also need to allow for synchronising multiple in-flight
checkpoints. This is needed for two things - the first is to ensure
that checkpoint commit records appear in the log in the correct
sequence order (so they are replayed in the correct order). The
second is so that xfs_log_force_lsn() operates correctly and only
flushes and/or waits for the specific sequence it was provided with.
To do this we need a wait variable and a list tracking the
checkpoint commits in progress. We can walk this list and wait for
the checkpoints to change state or complete easily, an this provides
the necessary synchronisation for correct operation in both cases.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Alex Elder <aelder@sgi.com>
Diffstat (limited to 'fs/xfs/xfs_log_priv.h')
-rw-r--r-- | fs/xfs/xfs_log_priv.h | 71 |
1 files changed, 69 insertions, 2 deletions
diff --git a/fs/xfs/xfs_log_priv.h b/fs/xfs/xfs_log_priv.h index ac97bddcadba..48d920891b94 100644 --- a/fs/xfs/xfs_log_priv.h +++ b/fs/xfs/xfs_log_priv.h | |||
@@ -377,6 +377,54 @@ typedef struct xlog_in_core { | |||
377 | } xlog_in_core_t; | 377 | } xlog_in_core_t; |
378 | 378 | ||
379 | /* | 379 | /* |
380 | * The CIL context is used to aggregate per-transaction details as well be | ||
381 | * passed to the iclog for checkpoint post-commit processing. After being | ||
382 | * passed to the iclog, another context needs to be allocated for tracking the | ||
383 | * next set of transactions to be aggregated into a checkpoint. | ||
384 | */ | ||
385 | struct xfs_cil; | ||
386 | |||
387 | struct xfs_cil_ctx { | ||
388 | struct xfs_cil *cil; | ||
389 | xfs_lsn_t sequence; /* chkpt sequence # */ | ||
390 | xfs_lsn_t start_lsn; /* first LSN of chkpt commit */ | ||
391 | xfs_lsn_t commit_lsn; /* chkpt commit record lsn */ | ||
392 | struct xlog_ticket *ticket; /* chkpt ticket */ | ||
393 | int nvecs; /* number of regions */ | ||
394 | int space_used; /* aggregate size of regions */ | ||
395 | struct list_head busy_extents; /* busy extents in chkpt */ | ||
396 | struct xfs_log_vec *lv_chain; /* logvecs being pushed */ | ||
397 | xfs_log_callback_t log_cb; /* completion callback hook. */ | ||
398 | struct list_head committing; /* ctx committing list */ | ||
399 | }; | ||
400 | |||
401 | /* | ||
402 | * Committed Item List structure | ||
403 | * | ||
404 | * This structure is used to track log items that have been committed but not | ||
405 | * yet written into the log. It is used only when the delayed logging mount | ||
406 | * option is enabled. | ||
407 | * | ||
408 | * This structure tracks the list of committing checkpoint contexts so | ||
409 | * we can avoid the problem of having to hold out new transactions during a | ||
410 | * flush until we have a the commit record LSN of the checkpoint. We can | ||
411 | * traverse the list of committing contexts in xlog_cil_push_lsn() to find a | ||
412 | * sequence match and extract the commit LSN directly from there. If the | ||
413 | * checkpoint is still in the process of committing, we can block waiting for | ||
414 | * the commit LSN to be determined as well. This should make synchronous | ||
415 | * operations almost as efficient as the old logging methods. | ||
416 | */ | ||
417 | struct xfs_cil { | ||
418 | struct log *xc_log; | ||
419 | struct list_head xc_cil; | ||
420 | spinlock_t xc_cil_lock; | ||
421 | struct xfs_cil_ctx *xc_ctx; | ||
422 | struct rw_semaphore xc_ctx_lock; | ||
423 | struct list_head xc_committing; | ||
424 | sv_t xc_commit_wait; | ||
425 | }; | ||
426 | |||
427 | /* | ||
380 | * The reservation head lsn is not made up of a cycle number and block number. | 428 | * The reservation head lsn is not made up of a cycle number and block number. |
381 | * Instead, it uses a cycle number and byte number. Logs don't expect to | 429 | * Instead, it uses a cycle number and byte number. Logs don't expect to |
382 | * overflow 31 bits worth of byte offset, so using a byte number will mean | 430 | * overflow 31 bits worth of byte offset, so using a byte number will mean |
@@ -386,6 +434,7 @@ typedef struct log { | |||
386 | /* The following fields don't need locking */ | 434 | /* The following fields don't need locking */ |
387 | struct xfs_mount *l_mp; /* mount point */ | 435 | struct xfs_mount *l_mp; /* mount point */ |
388 | struct xfs_ail *l_ailp; /* AIL log is working with */ | 436 | struct xfs_ail *l_ailp; /* AIL log is working with */ |
437 | struct xfs_cil *l_cilp; /* CIL log is working with */ | ||
389 | struct xfs_buf *l_xbuf; /* extra buffer for log | 438 | struct xfs_buf *l_xbuf; /* extra buffer for log |
390 | * wrapping */ | 439 | * wrapping */ |
391 | struct xfs_buftarg *l_targ; /* buftarg of log */ | 440 | struct xfs_buftarg *l_targ; /* buftarg of log */ |
@@ -436,14 +485,17 @@ typedef struct log { | |||
436 | 485 | ||
437 | #define XLOG_FORCED_SHUTDOWN(log) ((log)->l_flags & XLOG_IO_ERROR) | 486 | #define XLOG_FORCED_SHUTDOWN(log) ((log)->l_flags & XLOG_IO_ERROR) |
438 | 487 | ||
439 | |||
440 | /* common routines */ | 488 | /* common routines */ |
441 | extern xfs_lsn_t xlog_assign_tail_lsn(struct xfs_mount *mp); | 489 | extern xfs_lsn_t xlog_assign_tail_lsn(struct xfs_mount *mp); |
442 | extern int xlog_recover(xlog_t *log); | 490 | extern int xlog_recover(xlog_t *log); |
443 | extern int xlog_recover_finish(xlog_t *log); | 491 | extern int xlog_recover_finish(xlog_t *log); |
444 | extern void xlog_pack_data(xlog_t *log, xlog_in_core_t *iclog, int); | 492 | extern void xlog_pack_data(xlog_t *log, xlog_in_core_t *iclog, int); |
445 | 493 | ||
446 | extern kmem_zone_t *xfs_log_ticket_zone; | 494 | extern kmem_zone_t *xfs_log_ticket_zone; |
495 | struct xlog_ticket *xlog_ticket_alloc(struct log *log, int unit_bytes, | ||
496 | int count, char client, uint xflags, | ||
497 | int alloc_flags); | ||
498 | |||
447 | 499 | ||
448 | static inline void | 500 | static inline void |
449 | xlog_write_adv_cnt(void **ptr, int *len, int *off, size_t bytes) | 501 | xlog_write_adv_cnt(void **ptr, int *len, int *off, size_t bytes) |
@@ -453,6 +505,21 @@ xlog_write_adv_cnt(void **ptr, int *len, int *off, size_t bytes) | |||
453 | *off += bytes; | 505 | *off += bytes; |
454 | } | 506 | } |
455 | 507 | ||
508 | void xlog_print_tic_res(struct xfs_mount *mp, struct xlog_ticket *ticket); | ||
509 | int xlog_write(struct log *log, struct xfs_log_vec *log_vector, | ||
510 | struct xlog_ticket *tic, xfs_lsn_t *start_lsn, | ||
511 | xlog_in_core_t **commit_iclog, uint flags); | ||
512 | |||
513 | /* | ||
514 | * Committed Item List interfaces | ||
515 | */ | ||
516 | int xlog_cil_init(struct log *log); | ||
517 | void xlog_cil_init_post_recovery(struct log *log); | ||
518 | void xlog_cil_destroy(struct log *log); | ||
519 | |||
520 | int xlog_cil_push(struct log *log, int push_now); | ||
521 | xfs_lsn_t xlog_cil_push_lsn(struct log *log, xfs_lsn_t push_sequence); | ||
522 | |||
456 | /* | 523 | /* |
457 | * Unmount record type is used as a pseudo transaction type for the ticket. | 524 | * Unmount record type is used as a pseudo transaction type for the ticket. |
458 | * It's value must be outside the range of XFS_TRANS_* values. | 525 | * It's value must be outside the range of XFS_TRANS_* values. |