2018-06-06 02:42:14 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2005-11-02 03:58:39 +00:00
|
|
|
* Copyright (c) 2000,2005 Silicon Graphics, Inc.
|
|
|
|
* All Rights Reserved.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
#ifndef __XFS_LOG_RECOVER_H__
|
|
|
|
#define __XFS_LOG_RECOVER_H__
|
|
|
|
|
2020-05-01 23:00:45 +00:00
|
|
|
/*
|
|
|
|
* Each log item type (XFS_LI_*) gets its own xlog_recover_item_ops to
|
|
|
|
* define how recovery should work for that type of log item.
|
|
|
|
*/
|
|
|
|
struct xlog_recover_item;
|
2023-12-14 05:16:32 +00:00
|
|
|
struct xfs_defer_op_type;
|
2020-05-01 23:00:45 +00:00
|
|
|
|
|
|
|
/* Sorting hat for log items as they're read in. */
|
|
|
|
enum xlog_recover_reorder {
|
|
|
|
XLOG_REORDER_BUFFER_LIST,
|
|
|
|
XLOG_REORDER_ITEM_LIST,
|
|
|
|
XLOG_REORDER_INODE_BUFFER_LIST,
|
|
|
|
XLOG_REORDER_CANCEL_LIST,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct xlog_recover_item_ops {
|
|
|
|
uint16_t item_type; /* XFS_LI_* type code. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Help sort recovered log items into the order required to replay them
|
|
|
|
* correctly. Log item types that always use XLOG_REORDER_ITEM_LIST do
|
|
|
|
* not have to supply a function here. See the comment preceding
|
|
|
|
* xlog_recover_reorder_trans for more details about what the return
|
|
|
|
* values mean.
|
|
|
|
*/
|
|
|
|
enum xlog_recover_reorder (*reorder)(struct xlog_recover_item *item);
|
2020-05-01 23:00:46 +00:00
|
|
|
|
|
|
|
/* Start readahead for pass2, if provided. */
|
|
|
|
void (*ra_pass2)(struct xlog *log, struct xlog_recover_item *item);
|
2020-05-01 23:00:46 +00:00
|
|
|
|
|
|
|
/* Do whatever work we need to do for pass1, if provided. */
|
|
|
|
int (*commit_pass1)(struct xlog *log, struct xlog_recover_item *item);
|
2020-05-01 23:00:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This function should do whatever work is needed for pass2 of log
|
|
|
|
* recovery, if provided.
|
|
|
|
*
|
|
|
|
* If the recovered item is an intent item, this function should parse
|
|
|
|
* the recovered item to construct an in-core log intent item and
|
|
|
|
* insert it into the AIL. The in-core log intent item should have 1
|
|
|
|
* refcount so that the item is freed either (a) when we commit the
|
|
|
|
* recovered log item for the intent-done item; (b) replay the work and
|
|
|
|
* log a new intent-done item; or (c) recovery fails and we have to
|
|
|
|
* abort.
|
|
|
|
*
|
|
|
|
* If the recovered item is an intent-done item, this function should
|
|
|
|
* parse the recovered item to find the id of the corresponding intent
|
|
|
|
* log item. Next, it should find the in-core log intent item in the
|
|
|
|
* AIL and release it.
|
|
|
|
*/
|
|
|
|
int (*commit_pass2)(struct xlog *log, struct list_head *buffer_list,
|
|
|
|
struct xlog_recover_item *item, xfs_lsn_t lsn);
|
2020-05-01 23:00:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern const struct xlog_recover_item_ops xlog_icreate_item_ops;
|
|
|
|
extern const struct xlog_recover_item_ops xlog_buf_item_ops;
|
|
|
|
extern const struct xlog_recover_item_ops xlog_inode_item_ops;
|
|
|
|
extern const struct xlog_recover_item_ops xlog_dquot_item_ops;
|
|
|
|
extern const struct xlog_recover_item_ops xlog_quotaoff_item_ops;
|
|
|
|
extern const struct xlog_recover_item_ops xlog_bui_item_ops;
|
|
|
|
extern const struct xlog_recover_item_ops xlog_bud_item_ops;
|
|
|
|
extern const struct xlog_recover_item_ops xlog_efi_item_ops;
|
|
|
|
extern const struct xlog_recover_item_ops xlog_efd_item_ops;
|
|
|
|
extern const struct xlog_recover_item_ops xlog_rui_item_ops;
|
|
|
|
extern const struct xlog_recover_item_ops xlog_rud_item_ops;
|
|
|
|
extern const struct xlog_recover_item_ops xlog_cui_item_ops;
|
|
|
|
extern const struct xlog_recover_item_ops xlog_cud_item_ops;
|
2022-05-04 02:41:02 +00:00
|
|
|
extern const struct xlog_recover_item_ops xlog_attri_item_ops;
|
|
|
|
extern const struct xlog_recover_item_ops xlog_attrd_item_ops;
|
2020-05-01 23:00:45 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Macros, structures, prototypes for internal log manager use.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define XLOG_RHASH_BITS 4
|
|
|
|
#define XLOG_RHASH_SIZE 16
|
|
|
|
#define XLOG_RHASH_SHIFT 2
|
|
|
|
#define XLOG_RHASH(tid) \
|
2017-06-16 18:00:05 +00:00
|
|
|
((((uint32_t)tid)>>XLOG_RHASH_SHIFT) & (XLOG_RHASH_SIZE-1))
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-05-07 01:05:19 +00:00
|
|
|
#define XLOG_MAX_REGIONS_IN_ITEM (XFS_MAX_BLOCKSIZE / XFS_BLF_CHUNK / 2 + 1)
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* item headers are in ri_buf[0]. Additional buffers follow.
|
|
|
|
*/
|
2020-04-30 17:45:41 +00:00
|
|
|
struct xlog_recover_item {
|
2010-01-11 11:49:57 +00:00
|
|
|
struct list_head ri_list;
|
|
|
|
int ri_cnt; /* count of regions found */
|
|
|
|
int ri_total; /* total regions */
|
2020-05-01 23:00:45 +00:00
|
|
|
struct xfs_log_iovec *ri_buf; /* ptr to regions buffer */
|
|
|
|
const struct xlog_recover_item_ops *ri_ops;
|
2020-04-30 17:45:41 +00:00
|
|
|
};
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2019-11-13 01:04:28 +00:00
|
|
|
struct xlog_recover {
|
2010-01-11 11:49:57 +00:00
|
|
|
struct hlist_node r_list;
|
|
|
|
xlog_tid_t r_log_tid; /* log's transaction id */
|
|
|
|
xfs_trans_header_t r_theader; /* trans header for partial */
|
|
|
|
int r_state; /* not needed */
|
|
|
|
xfs_lsn_t r_lsn; /* xact lsn */
|
|
|
|
struct list_head r_itemq; /* q for items */
|
2019-11-13 01:04:28 +00:00
|
|
|
};
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-11-08 00:55:48 +00:00
|
|
|
#define ITEM_TYPE(i) (*(unsigned short *)(i)->ri_buf[0].i_addr)
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-01-04 04:55:10 +00:00
|
|
|
#define XLOG_RECOVER_CRCPASS 0
|
2005-04-16 22:20:36 +00:00
|
|
|
#define XLOG_RECOVER_PASS1 1
|
|
|
|
#define XLOG_RECOVER_PASS2 2
|
|
|
|
|
2020-05-01 23:00:46 +00:00
|
|
|
void xlog_buf_readahead(struct xlog *log, xfs_daddr_t blkno, uint len,
|
|
|
|
const struct xfs_buf_ops *ops);
|
2020-05-01 23:00:47 +00:00
|
|
|
bool xlog_is_buffer_cancelled(struct xlog *log, xfs_daddr_t blkno, uint len);
|
2020-05-01 23:00:46 +00:00
|
|
|
|
2021-08-08 15:27:13 +00:00
|
|
|
int xlog_recover_iget(struct xfs_mount *mp, xfs_ino_t ino,
|
|
|
|
struct xfs_inode **ipp);
|
2020-05-01 23:00:54 +00:00
|
|
|
void xlog_recover_release_intent(struct xlog *log, unsigned short intent_type,
|
|
|
|
uint64_t intent_id);
|
2022-05-27 00:27:19 +00:00
|
|
|
int xlog_alloc_buf_cancel_table(struct xlog *log);
|
2022-05-27 00:26:17 +00:00
|
|
|
void xlog_free_buf_cancel_table(struct xlog *log);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void xlog_check_buf_cancel_table(struct xlog *log);
|
|
|
|
#else
|
|
|
|
#define xlog_check_buf_cancel_table(log) do { } while (0)
|
|
|
|
#endif
|
2020-05-01 23:00:54 +00:00
|
|
|
|
xfs: reserve less log space when recovering log intent items
Wengang Wang reports that a customer's system was running a number of
truncate operations on a filesystem with a very small log. Contention
on the reserve heads lead to other threads stalling on smaller updates
(e.g. mtime updates) long enough to result in the node being rebooted
on account of the lack of responsivenes. The node failed to recover
because log recovery of an EFI became stuck waiting for a grant of
reserve space. From Wengang's report:
"For the file deletion, log bytes are reserved basing on
xfs_mount->tr_itruncate which is:
tr_logres = 175488,
tr_logcount = 2,
tr_logflags = XFS_TRANS_PERM_LOG_RES,
"You see it's a permanent log reservation with two log operations (two
transactions in rolling mode). After calculation (xlog_calc_unit_res()
adds space for various log headers), the final log space needed per
transaction changes from 175488 to 180208 bytes. So the total log
space needed is 360416 bytes (180208 * 2). [That quantity] of log space
(360416 bytes) needs to be reserved for both run time inode removing
(xfs_inactive_truncate()) and EFI recover (xfs_efi_item_recover())."
In other words, runtime pre-reserves 360K of space in anticipation of
running a chain of two transactions in which each transaction gets a
180K reservation.
Now that we've allocated the transaction, we delete the bmap mapping,
log an EFI to free the space, and roll the transaction as part of
finishing the deferops chain. Rolling creates a new xfs_trans which
shares its ticket with the old transaction. Next, xfs_trans_roll calls
__xfs_trans_commit with regrant == true, which calls xlog_cil_commit
with the same regrant parameter.
xlog_cil_commit calls xfs_log_ticket_regrant, which decrements t_cnt and
subtracts t_curr_res from the reservation and write heads.
If the filesystem is fresh and the first transaction only used (say)
20K, then t_curr_res will be 160K, and we give that much reservation
back to the reservation head. Or if the file is really fragmented and
the first transaction actually uses 170K, then t_curr_res will be 10K,
and that's what we give back to the reservation.
Having done that, we're now headed into the second transaction with an
EFI and 180K of reservation. Other threads apparently consumed all the
reservation for smaller transactions, such as timestamp updates.
Now let's say the first transaction gets written to disk and we crash
without ever completing the second transaction. Now we remount the fs,
log recovery finds the unfinished EFI, and calls xfs_efi_recover to
finish the EFI. However, xfs_efi_recover starts a new tr_itruncate
tranasction, which asks for 360K log reservation. This is a lot more
than the 180K that we had reserved at the time of the crash. If the
first EFI to be recovered is also pinning the tail of the log, we will
be unable to free any space in the log, and recovery livelocks.
Wengang confirmed this:
"Now we have the second transaction which has 180208 log bytes reserved
too. The second transaction is supposed to process intents including
extent freeing. With my hacking patch, I blocked the extent freeing 5
hours. So in that 5 hours, 180208 (NOT 360416) log bytes are reserved.
"With my test case, other transactions (update timestamps) then happen.
As my hacking patch pins the journal tail, those timestamp-updating
transactions finally use up (almost) all the left available log space
(in memory in on disk). And finally the on disk (and in memory)
available log space goes down near to 180208 bytes. Those 180208 bytes
are reserved by [the] second (extent-free) transaction [in the chain]."
Wengang and I noticed that EFI recovery starts a transaction, completes
one step of the chain, and commits the transaction without completing
any other steps of the chain. Those subsequent steps are completed by
xlog_finish_defer_ops, which allocates yet another transaction to
finish the rest of the chain. That transaction gets the same tr_logres
as the head transaction, but with tr_logcount = 1 to force regranting
with every roll to avoid livelocks.
In other words, we already figured this out in commit 929b92f64048d
("xfs: xfs_defer_capture should absorb remaining transaction
reservation"), but should have applied that logic to each intent item's
recovery function. For Wengang's case, the xfs_trans_alloc call in the
EFI recovery function should only be asking for a single transaction's
worth of log reservation -- 180K, not 360K.
Quoting Wengang again:
"With log recovery, during EFI recovery, we use tr_itruncate again to
reserve two transactions that needs 360416 log bytes. Reserving 360416
bytes fails [stalls] because we now only have about 180208 available.
"Actually during the EFI recover, we only need one transaction to free
the extents just like the 2nd transaction at RUNTIME. So it only needs
to reserve 180208 rather than 360416 bytes. We have (a bit) more than
180208 available log bytes on disk, so [if we decrease the reservation
to 180K] the reservation goes and the recovery [finishes]. That is to
say: we can fix the log recover part to fix the issue. We can introduce
a new xfs_trans_res xfs_mount->tr_ext_free
{
tr_logres = 175488,
tr_logcount = 0,
tr_logflags = 0,
}
"and use tr_ext_free instead of tr_itruncate in EFI recover."
However, I don't think it quite makes sense to create an entirely new
transaction reservation type to handle single-stepping during log
recovery. Instead, we should copy the transaction reservation
information in the xfs_mount, change tr_logcount to 1, and pass that
into xfs_trans_alloc. We know this won't risk changing the min log size
computation since we always ask for a fraction of the reservation for
all known transaction types.
This looks like it's been lurking in the codebase since commit
3d3c8b5222b92, which changed the xfs_trans_reserve call in
xlog_recover_process_efi to use the tr_logcount in tr_itruncate.
That changed the EFI recovery transaction from making a
non-XFS_TRANS_PERM_LOG_RES request for one transaction's worth of log
space to a XFS_TRANS_PERM_LOG_RES request for two transactions worth.
Fixes: 3d3c8b5222b92 ("xfs: refactor xfs_trans_reserve() interface")
Complements: 929b92f64048d ("xfs: xfs_defer_capture should absorb remaining transaction reservation")
Suggested-by: Wengang Wang <wen.gang.wang@oracle.com>
Cc: Srikanth C S <srikanth.c.s@oracle.com>
[djwong: apply the same transformation to all log intent recovery]
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2023-09-11 15:39:05 +00:00
|
|
|
/*
|
|
|
|
* Transform a regular reservation into one suitable for recovery of a log
|
|
|
|
* intent item.
|
|
|
|
*
|
|
|
|
* Intent recovery only runs a single step of the transaction chain and defers
|
|
|
|
* the rest to a separate transaction. Therefore, we reduce logcount to 1 here
|
|
|
|
* to avoid livelocks if the log grant space is nearly exhausted due to the
|
|
|
|
* recovered intent pinning the tail. Keep the same logflags to avoid tripping
|
|
|
|
* asserts elsewhere. Struct copies abound below.
|
|
|
|
*/
|
|
|
|
static inline struct xfs_trans_res
|
|
|
|
xlog_recover_resv(const struct xfs_trans_res *r)
|
|
|
|
{
|
|
|
|
struct xfs_trans_res ret = {
|
|
|
|
.tr_logres = r->tr_logres,
|
|
|
|
.tr_logcount = 1,
|
|
|
|
.tr_logflags = r->tr_logflags,
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-11-22 21:39:25 +00:00
|
|
|
struct xfs_defer_pending;
|
|
|
|
|
2023-11-22 18:23:23 +00:00
|
|
|
void xlog_recover_intent_item(struct xlog *log, struct xfs_log_item *lip,
|
2023-12-14 05:16:32 +00:00
|
|
|
xfs_lsn_t lsn, const struct xfs_defer_op_type *ops);
|
2023-11-22 19:25:45 +00:00
|
|
|
int xlog_recover_finish_intent(struct xfs_trans *tp,
|
2023-11-22 18:47:10 +00:00
|
|
|
struct xfs_defer_pending *dfp);
|
2023-11-22 18:23:23 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif /* __XFS_LOG_RECOVER_H__ */
|