未验证 提交 cedc20d7 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!1330 [sync] PR-1325: jbd2: fix several checkpoint

Merge Pull Request from: @openeuler-sync-bot 
 

Origin pull request: 
https://gitee.com/openeuler/kernel/pulls/1325 
 
PR sync from: Zhihao Cheng <chengzhihao1@huawei.com>
https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/QARA5X5OQUKRFUIORG2YVB6YE3V5CGQB/ 
Zhang Yi (4):
  jbd2: remove journal_clean_one_cp_list()
  jbd2: fix a race when checking checkpoint buffer busy
  jbd2: remove __journal_try_to_free_buffer()
  jbd2: fix checkpoint cleanup performance regression

Zhihao Cheng (1):
  jbd2: Fix wrongly judgement for buffer head removing while doing
    checkpoint


-- 
2.31.1
 
 
Link:https://gitee.com/openeuler/kernel/pulls/1330 

Reviewed-by: zhangyi (F) <yi.zhang@huawei.com> 
Signed-off-by: Jialin Zhang <zhangjialin11@huawei.com> 
...@@ -204,20 +204,6 @@ int jbd2_log_do_checkpoint(journal_t *journal) ...@@ -204,20 +204,6 @@ int jbd2_log_do_checkpoint(journal_t *journal)
jh = transaction->t_checkpoint_list; jh = transaction->t_checkpoint_list;
bh = jh2bh(jh); bh = jh2bh(jh);
/*
* The buffer may be writing back, or flushing out in the
* last couple of cycles, or re-adding into a new transaction,
* need to check it again until it's unlocked.
*/
if (buffer_locked(bh)) {
get_bh(bh);
spin_unlock(&journal->j_list_lock);
wait_on_buffer(bh);
/* the journal_head may have gone by now */
BUFFER_TRACE(bh, "brelse");
__brelse(bh);
goto retry;
}
if (jh->b_transaction != NULL) { if (jh->b_transaction != NULL) {
transaction_t *t = jh->b_transaction; transaction_t *t = jh->b_transaction;
tid_t tid = t->t_tid; tid_t tid = t->t_tid;
...@@ -252,7 +238,22 @@ int jbd2_log_do_checkpoint(journal_t *journal) ...@@ -252,7 +238,22 @@ int jbd2_log_do_checkpoint(journal_t *journal)
spin_lock(&journal->j_list_lock); spin_lock(&journal->j_list_lock);
goto restart; goto restart;
} }
if (!buffer_dirty(bh)) { if (!trylock_buffer(bh)) {
/*
* The buffer is locked, it may be writing back, or
* flushing out in the last couple of cycles, or
* re-adding into a new transaction, need to check
* it again until it's unlocked.
*/
get_bh(bh);
spin_unlock(&journal->j_list_lock);
wait_on_buffer(bh);
/* the journal_head may have gone by now */
BUFFER_TRACE(bh, "brelse");
__brelse(bh);
goto retry;
} else if (!buffer_dirty(bh)) {
unlock_buffer(bh);
BUFFER_TRACE(bh, "remove from checkpoint"); BUFFER_TRACE(bh, "remove from checkpoint");
/* /*
* If the transaction was released or the checkpoint * If the transaction was released or the checkpoint
...@@ -262,6 +263,7 @@ int jbd2_log_do_checkpoint(journal_t *journal) ...@@ -262,6 +263,7 @@ int jbd2_log_do_checkpoint(journal_t *journal)
!transaction->t_checkpoint_list) !transaction->t_checkpoint_list)
goto out; goto out;
} else { } else {
unlock_buffer(bh);
/* /*
* We are about to write the buffer, it could be * We are about to write the buffer, it could be
* raced by some other transaction shrink or buffer * raced by some other transaction shrink or buffer
...@@ -347,50 +349,12 @@ int jbd2_cleanup_journal_tail(journal_t *journal) ...@@ -347,50 +349,12 @@ int jbd2_cleanup_journal_tail(journal_t *journal)
/* Checkpoint list management */ /* Checkpoint list management */
/* enum shrink_type {SHRINK_DESTROY, SHRINK_BUSY_STOP, SHRINK_BUSY_SKIP};
* journal_clean_one_cp_list
*
* Find all the written-back checkpoint buffers in the given list and
* release them. If 'destroy' is set, clean all buffers unconditionally.
*
* Called with j_list_lock held.
* Returns 1 if we freed the transaction, 0 otherwise.
*/
static int journal_clean_one_cp_list(struct journal_head *jh, bool destroy)
{
struct journal_head *last_jh;
struct journal_head *next_jh = jh;
if (!jh)
return 0;
last_jh = jh->b_cpprev;
do {
jh = next_jh;
next_jh = jh->b_cpnext;
if (!destroy && __cp_buffer_busy(jh))
return 0;
if (__jbd2_journal_remove_checkpoint(jh))
return 1;
/*
* This function only frees up some memory
* if possible so we dont have an obligation
* to finish processing. Bail out if preemption
* requested:
*/
if (need_resched())
return 0;
} while (jh != last_jh);
return 0;
}
/* /*
* journal_shrink_one_cp_list * journal_shrink_one_cp_list
* *
* Find 'nr_to_scan' written-back checkpoint buffers in the given list * Find all the written-back checkpoint buffers in the given list
* and try to release them. If the whole transaction is released, set * and try to release them. If the whole transaction is released, set
* the 'released' parameter. Return the number of released checkpointed * the 'released' parameter. Return the number of released checkpointed
* buffers. * buffers.
...@@ -398,7 +362,7 @@ static int journal_clean_one_cp_list(struct journal_head *jh, bool destroy) ...@@ -398,7 +362,7 @@ static int journal_clean_one_cp_list(struct journal_head *jh, bool destroy)
* Called with j_list_lock held. * Called with j_list_lock held.
*/ */
static unsigned long journal_shrink_one_cp_list(struct journal_head *jh, static unsigned long journal_shrink_one_cp_list(struct journal_head *jh,
unsigned long *nr_to_scan, enum shrink_type type,
bool *released) bool *released)
{ {
struct journal_head *last_jh; struct journal_head *last_jh;
...@@ -406,7 +370,8 @@ static unsigned long journal_shrink_one_cp_list(struct journal_head *jh, ...@@ -406,7 +370,8 @@ static unsigned long journal_shrink_one_cp_list(struct journal_head *jh,
unsigned long nr_freed = 0; unsigned long nr_freed = 0;
int ret; int ret;
if (!jh || *nr_to_scan == 0) *released = false;
if (!jh)
return 0; return 0;
last_jh = jh->b_cpprev; last_jh = jh->b_cpprev;
...@@ -414,12 +379,18 @@ static unsigned long journal_shrink_one_cp_list(struct journal_head *jh, ...@@ -414,12 +379,18 @@ static unsigned long journal_shrink_one_cp_list(struct journal_head *jh,
jh = next_jh; jh = next_jh;
next_jh = jh->b_cpnext; next_jh = jh->b_cpnext;
(*nr_to_scan)--; if (type == SHRINK_DESTROY) {
if (__cp_buffer_busy(jh)) ret = __jbd2_journal_remove_checkpoint(jh);
continue; } else {
ret = jbd2_journal_try_remove_checkpoint(jh);
if (ret < 0) {
if (type == SHRINK_BUSY_SKIP)
continue;
break;
}
}
nr_freed++; nr_freed++;
ret = __jbd2_journal_remove_checkpoint(jh);
if (ret) { if (ret) {
*released = true; *released = true;
break; break;
...@@ -427,7 +398,7 @@ static unsigned long journal_shrink_one_cp_list(struct journal_head *jh, ...@@ -427,7 +398,7 @@ static unsigned long journal_shrink_one_cp_list(struct journal_head *jh,
if (need_resched()) if (need_resched())
break; break;
} while (jh != last_jh && *nr_to_scan); } while (jh != last_jh);
return nr_freed; return nr_freed;
} }
...@@ -445,11 +416,11 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal, ...@@ -445,11 +416,11 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal,
unsigned long *nr_to_scan) unsigned long *nr_to_scan)
{ {
transaction_t *transaction, *last_transaction, *next_transaction; transaction_t *transaction, *last_transaction, *next_transaction;
bool released; bool __maybe_unused released;
tid_t first_tid = 0, last_tid = 0, next_tid = 0; tid_t first_tid = 0, last_tid = 0, next_tid = 0;
tid_t tid = 0; tid_t tid = 0;
unsigned long nr_freed = 0; unsigned long nr_freed = 0;
unsigned long nr_scanned = *nr_to_scan; unsigned long freed;
again: again:
spin_lock(&journal->j_list_lock); spin_lock(&journal->j_list_lock);
...@@ -478,10 +449,11 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal, ...@@ -478,10 +449,11 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal,
transaction = next_transaction; transaction = next_transaction;
next_transaction = transaction->t_cpnext; next_transaction = transaction->t_cpnext;
tid = transaction->t_tid; tid = transaction->t_tid;
released = false;
nr_freed += journal_shrink_one_cp_list(transaction->t_checkpoint_list, freed = journal_shrink_one_cp_list(transaction->t_checkpoint_list,
nr_to_scan, &released); SHRINK_BUSY_SKIP, &released);
nr_freed += freed;
(*nr_to_scan) -= min(*nr_to_scan, freed);
if (*nr_to_scan == 0) if (*nr_to_scan == 0)
break; break;
if (need_resched() || spin_needbreak(&journal->j_list_lock)) if (need_resched() || spin_needbreak(&journal->j_list_lock))
...@@ -502,9 +474,8 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal, ...@@ -502,9 +474,8 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal,
if (*nr_to_scan && next_tid) if (*nr_to_scan && next_tid)
goto again; goto again;
out: out:
nr_scanned -= *nr_to_scan;
trace_jbd2_shrink_checkpoint_list(journal, first_tid, tid, last_tid, trace_jbd2_shrink_checkpoint_list(journal, first_tid, tid, last_tid,
nr_freed, nr_scanned, next_tid); nr_freed, next_tid);
return nr_freed; return nr_freed;
} }
...@@ -520,19 +491,21 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal, ...@@ -520,19 +491,21 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal,
void __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy) void __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy)
{ {
transaction_t *transaction, *last_transaction, *next_transaction; transaction_t *transaction, *last_transaction, *next_transaction;
int ret; enum shrink_type type;
bool released;
transaction = journal->j_checkpoint_transactions; transaction = journal->j_checkpoint_transactions;
if (!transaction) if (!transaction)
return; return;
type = destroy ? SHRINK_DESTROY : SHRINK_BUSY_STOP;
last_transaction = transaction->t_cpprev; last_transaction = transaction->t_cpprev;
next_transaction = transaction; next_transaction = transaction;
do { do {
transaction = next_transaction; transaction = next_transaction;
next_transaction = transaction->t_cpnext; next_transaction = transaction->t_cpnext;
ret = journal_clean_one_cp_list(transaction->t_checkpoint_list, journal_shrink_one_cp_list(transaction->t_checkpoint_list,
destroy); type, &released);
/* /*
* This function only frees up some memory if possible so we * This function only frees up some memory if possible so we
* dont have an obligation to finish processing. Bail out if * dont have an obligation to finish processing. Bail out if
...@@ -545,7 +518,7 @@ void __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy) ...@@ -545,7 +518,7 @@ void __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy)
* avoids pointless scanning of transactions which still * avoids pointless scanning of transactions which still
* weren't checkpointed. * weren't checkpointed.
*/ */
if (!ret) if (!released)
return; return;
} while (transaction != last_transaction); } while (transaction != last_transaction);
} }
...@@ -655,6 +628,34 @@ int __jbd2_journal_remove_checkpoint(struct journal_head *jh) ...@@ -655,6 +628,34 @@ int __jbd2_journal_remove_checkpoint(struct journal_head *jh)
return 1; return 1;
} }
/*
* Check the checkpoint buffer and try to remove it from the checkpoint
* list if it's clean. Returns -EBUSY if it is not clean, returns 1 if
* it frees the transaction, 0 otherwise.
*
* This function is called with j_list_lock held.
*/
int jbd2_journal_try_remove_checkpoint(struct journal_head *jh)
{
struct buffer_head *bh = jh2bh(jh);
if (!trylock_buffer(bh))
return -EBUSY;
if (buffer_dirty(bh)) {
unlock_buffer(bh);
return -EBUSY;
}
unlock_buffer(bh);
/*
* Buffer is clean and the IO has finished (we held the buffer
* lock) so the checkpoint is done. We can safely remove the
* buffer from this transaction.
*/
JBUFFER_TRACE(jh, "remove from checkpoint list");
return __jbd2_journal_remove_checkpoint(jh);
}
/* /*
* journal_insert_checkpoint: put a committed buffer onto a checkpoint * journal_insert_checkpoint: put a committed buffer onto a checkpoint
* list so that we know when it is safe to clean the transaction out of * list so that we know when it is safe to clean the transaction out of
......
...@@ -1758,8 +1758,7 @@ int jbd2_journal_forget(handle_t *handle, struct buffer_head *bh) ...@@ -1758,8 +1758,7 @@ int jbd2_journal_forget(handle_t *handle, struct buffer_head *bh)
* Otherwise, if the buffer has been written to disk, * Otherwise, if the buffer has been written to disk,
* it is safe to remove the checkpoint and drop it. * it is safe to remove the checkpoint and drop it.
*/ */
if (!buffer_dirty(bh)) { if (jbd2_journal_try_remove_checkpoint(jh) >= 0) {
__jbd2_journal_remove_checkpoint(jh);
spin_unlock(&journal->j_list_lock); spin_unlock(&journal->j_list_lock);
goto drop; goto drop;
} }
...@@ -2074,35 +2073,6 @@ void jbd2_journal_unfile_buffer(journal_t *journal, struct journal_head *jh) ...@@ -2074,35 +2073,6 @@ void jbd2_journal_unfile_buffer(journal_t *journal, struct journal_head *jh)
__brelse(bh); __brelse(bh);
} }
/*
* Called from jbd2_journal_try_to_free_buffers().
*
* Called under jh->b_state_lock
*/
static void
__journal_try_to_free_buffer(journal_t *journal, struct buffer_head *bh)
{
struct journal_head *jh;
jh = bh2jh(bh);
if (buffer_locked(bh) || buffer_dirty(bh))
goto out;
if (jh->b_next_transaction != NULL || jh->b_transaction != NULL)
goto out;
spin_lock(&journal->j_list_lock);
if (jh->b_cp_transaction != NULL) {
/* written-back checkpointed metadata buffer */
JBUFFER_TRACE(jh, "remove from checkpoint list");
__jbd2_journal_remove_checkpoint(jh);
}
spin_unlock(&journal->j_list_lock);
out:
return;
}
/** /**
* jbd2_journal_try_to_free_buffers() - try to free page buffers. * jbd2_journal_try_to_free_buffers() - try to free page buffers.
* @journal: journal for operation * @journal: journal for operation
...@@ -2160,7 +2130,13 @@ int jbd2_journal_try_to_free_buffers(journal_t *journal, struct page *page) ...@@ -2160,7 +2130,13 @@ int jbd2_journal_try_to_free_buffers(journal_t *journal, struct page *page)
continue; continue;
spin_lock(&jh->b_state_lock); spin_lock(&jh->b_state_lock);
__journal_try_to_free_buffer(journal, bh); if (!jh->b_transaction && !jh->b_next_transaction) {
spin_lock(&journal->j_list_lock);
/* Remove written-back checkpointed metadata buffer */
if (jh->b_cp_transaction != NULL)
jbd2_journal_try_remove_checkpoint(jh);
spin_unlock(&journal->j_list_lock);
}
spin_unlock(&jh->b_state_lock); spin_unlock(&jh->b_state_lock);
jbd2_journal_put_journal_head(jh); jbd2_journal_put_journal_head(jh);
if (buffer_jbd(bh)) if (buffer_jbd(bh))
......
...@@ -1439,6 +1439,7 @@ extern void jbd2_journal_commit_transaction(journal_t *); ...@@ -1439,6 +1439,7 @@ extern void jbd2_journal_commit_transaction(journal_t *);
void __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy); void __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy);
unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal, unsigned long *nr_to_scan); unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal, unsigned long *nr_to_scan);
int __jbd2_journal_remove_checkpoint(struct journal_head *); int __jbd2_journal_remove_checkpoint(struct journal_head *);
int jbd2_journal_try_remove_checkpoint(struct journal_head *jh);
void jbd2_journal_destroy_checkpoint(journal_t *journal); void jbd2_journal_destroy_checkpoint(journal_t *journal);
void __jbd2_journal_insert_checkpoint(struct journal_head *, transaction_t *); void __jbd2_journal_insert_checkpoint(struct journal_head *, transaction_t *);
......
...@@ -462,11 +462,9 @@ TRACE_EVENT(jbd2_shrink_scan_exit, ...@@ -462,11 +462,9 @@ TRACE_EVENT(jbd2_shrink_scan_exit,
TRACE_EVENT(jbd2_shrink_checkpoint_list, TRACE_EVENT(jbd2_shrink_checkpoint_list,
TP_PROTO(journal_t *journal, tid_t first_tid, tid_t tid, tid_t last_tid, TP_PROTO(journal_t *journal, tid_t first_tid, tid_t tid, tid_t last_tid,
unsigned long nr_freed, unsigned long nr_scanned, unsigned long nr_freed, tid_t next_tid),
tid_t next_tid),
TP_ARGS(journal, first_tid, tid, last_tid, nr_freed, TP_ARGS(journal, first_tid, tid, last_tid, nr_freed, next_tid),
nr_scanned, next_tid),
TP_STRUCT__entry( TP_STRUCT__entry(
__field(dev_t, dev) __field(dev_t, dev)
...@@ -474,7 +472,6 @@ TRACE_EVENT(jbd2_shrink_checkpoint_list, ...@@ -474,7 +472,6 @@ TRACE_EVENT(jbd2_shrink_checkpoint_list,
__field(tid_t, tid) __field(tid_t, tid)
__field(tid_t, last_tid) __field(tid_t, last_tid)
__field(unsigned long, nr_freed) __field(unsigned long, nr_freed)
__field(unsigned long, nr_scanned)
__field(tid_t, next_tid) __field(tid_t, next_tid)
), ),
...@@ -484,15 +481,14 @@ TRACE_EVENT(jbd2_shrink_checkpoint_list, ...@@ -484,15 +481,14 @@ TRACE_EVENT(jbd2_shrink_checkpoint_list,
__entry->tid = tid; __entry->tid = tid;
__entry->last_tid = last_tid; __entry->last_tid = last_tid;
__entry->nr_freed = nr_freed; __entry->nr_freed = nr_freed;
__entry->nr_scanned = nr_scanned;
__entry->next_tid = next_tid; __entry->next_tid = next_tid;
), ),
TP_printk("dev %d,%d shrink transaction %u-%u(%u) freed %lu " TP_printk("dev %d,%d shrink transaction %u-%u(%u) freed %lu "
"scanned %lu next transaction %u", "next transaction %u",
MAJOR(__entry->dev), MINOR(__entry->dev), MAJOR(__entry->dev), MINOR(__entry->dev),
__entry->first_tid, __entry->tid, __entry->last_tid, __entry->first_tid, __entry->tid, __entry->last_tid,
__entry->nr_freed, __entry->nr_scanned, __entry->next_tid) __entry->nr_freed, __entry->next_tid)
); );
#endif /* _TRACE_JBD2_H */ #endif /* _TRACE_JBD2_H */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册