Lines Matching +full:wait +full:- +full:pin

1 // SPDX-License-Identifier: GPL-2.0
32 union journal_res_state s = READ_ONCE(j->reservations); in bch2_journal_buf_to_text()
34 struct journal_buf *buf = j->buf + i; in bch2_journal_buf_to_text()
49 prt_human_readable_u64(out, vstruct_bytes(buf->data)); in bch2_journal_buf_to_text()
54 prt_printf(out, "%li jiffies", buf->expires - jiffies); in bch2_journal_buf_to_text()
62 if (!out->nr_tabstops) in bch2_journal_bufs_to_text()
73 return seq > j->seq_ondisk; in journal_seq_unwritten()
83 return atomic64_read(&j->seq) - j->seq_ondisk; in nr_unwritten_journal_entries()
88 return __journal_entry_is_open(j->reservations); in journal_entry_is_open()
99 buf = j->buf + (seq & JOURNAL_BUF_MASK); in journal_seq_to_buf()
100 EBUG_ON(le64_to_cpu(buf->data->seq) != seq); in journal_seq_to_buf()
109 for (i = 0; i < ARRAY_SIZE(p->list); i++) in journal_pin_list_init()
110 INIT_LIST_HEAD(&p->list[i]); in journal_pin_list_init()
111 INIT_LIST_HEAD(&p->flushed); in journal_pin_list_init()
112 atomic_set(&p->count, count); in journal_pin_list_init()
113 p->devs.nr = 0; in journal_pin_list_init()
140 spin_lock(&j->lock); in journal_error_check_stuck()
142 if (j->can_discard) { in journal_error_check_stuck()
143 spin_unlock(&j->lock); in journal_error_check_stuck()
150 * The journal shutdown path will set ->err_seq, but do it here first to in journal_error_check_stuck()
154 if (j->err_seq) { in journal_error_check_stuck()
155 spin_unlock(&j->lock); in journal_error_check_stuck()
158 j->err_seq = journal_cur_seq(j); in journal_error_check_stuck()
159 spin_unlock(&j->lock); in journal_error_check_stuck()
161 bch_err(c, "Journal stuck! Hava a pre-reservation but journal full (error %s)", in journal_error_check_stuck()
179 * dropped. Drop the pin list reference acquired at journal entry open and write
186 lockdep_assert_held(&j->lock); in bch2_journal_buf_put_final()
191 closure_call(&j->io, bch2_journal_write, c->io_complete_wq, NULL); in bch2_journal_buf_put_final()
198 * and can be opened again - this also initializes the next journal_buf:
205 u64 v = atomic64_read(&j->reservations.counter); in __journal_entry_close()
211 lockdep_assert_held(&j->lock); in __journal_entry_close()
220 } while ((v = atomic64_cmpxchg(&j->reservations.counter, in __journal_entry_close()
227 buf->data->u64s = cpu_to_le32(old.cur_entry_offset); in __journal_entry_close()
234 prt_human_readable_u64(&pbuf, vstruct_bytes(buf->data)); in __journal_entry_close()
241 sectors = vstruct_blocks_plus(buf->data, c->block_bits, in __journal_entry_close()
242 buf->u64s_reserved) << c->block_bits; in __journal_entry_close()
243 BUG_ON(sectors > buf->sectors); in __journal_entry_close()
244 buf->sectors = sectors; in __journal_entry_close()
249 * A threads may replace an old pin with a new pin on their current in __journal_entry_close()
250 * journal reservation - the expectation being that the journal will in __journal_entry_close()
251 * contain either what the old pin protected or what the new pin in __journal_entry_close()
254 * After the old pin is dropped journal_last_seq() won't include the old in __journal_entry_close()
255 * pin, so we can only write the updated last_seq on the entry that in __journal_entry_close()
256 * contains whatever the new pin protects. in __journal_entry_close()
265 buf->last_seq = journal_last_seq(j); in __journal_entry_close()
266 buf->data->last_seq = cpu_to_le64(buf->last_seq); in __journal_entry_close()
267 BUG_ON(buf->last_seq > le64_to_cpu(buf->data->seq)); in __journal_entry_close()
269 cancel_delayed_work(&j->write_work); in __journal_entry_close()
273 __bch2_journal_buf_put(j, old.idx, le64_to_cpu(buf->data->seq)); in __journal_entry_close()
278 spin_lock(&j->lock); in bch2_journal_halt()
280 if (!j->err_seq) in bch2_journal_halt()
281 j->err_seq = journal_cur_seq(j); in bch2_journal_halt()
283 spin_unlock(&j->lock); in bch2_journal_halt()
297 if (!buf->flush_time) { in journal_entry_want_write()
298 buf->flush_time = local_clock() ?: 1; in journal_entry_want_write()
299 buf->expires = jiffies; in journal_entry_want_write()
310 spin_lock(&j->lock); in bch2_journal_entry_close()
312 spin_unlock(&j->lock); in bch2_journal_entry_close()
318 * should _only_ called from journal_res_get() - when we actually want a
319 * journal reservation - journal entry is open means journal is dirty:
324 struct journal_buf *buf = j->buf + in journal_entry_open()
330 lockdep_assert_held(&j->lock); in journal_entry_open()
332 BUG_ON(BCH_SB_CLEAN(c->disk_sb.sb)); in journal_entry_open()
334 if (j->blocked) in journal_entry_open()
337 if (j->cur_entry_error) in journal_entry_open()
338 return j->cur_entry_error; in journal_entry_open()
341 return JOURNAL_ERR_insufficient_devices; /* -EROFS */ in journal_entry_open()
343 if (!fifo_free(&j->pin)) in journal_entry_open()
346 if (nr_unwritten_journal_entries(j) == ARRAY_SIZE(j->buf)) in journal_entry_open()
349 BUG_ON(!j->cur_entry_sectors); in journal_entry_open()
351 buf->expires = in journal_entry_open()
352 (journal_cur_seq(j) == j->flushed_seq_ondisk in journal_entry_open()
354 : j->last_flush_write) + in journal_entry_open()
355 msecs_to_jiffies(c->opts.journal_flush_delay); in journal_entry_open()
357 buf->u64s_reserved = j->entry_u64s_reserved; in journal_entry_open()
358 buf->disk_sectors = j->cur_entry_sectors; in journal_entry_open()
359 buf->sectors = min(buf->disk_sectors, buf->buf_size >> 9); in journal_entry_open()
361 u64s = (int) (buf->sectors << 9) / sizeof(u64) - in journal_entry_open()
363 u64s = clamp_t(int, u64s, 0, JOURNAL_ENTRY_CLOSED_VAL - 1); in journal_entry_open()
365 if (u64s <= (ssize_t) j->early_journal_entries.nr) in journal_entry_open()
368 if (fifo_empty(&j->pin) && j->reclaim_thread) in journal_entry_open()
369 wake_up_process(j->reclaim_thread); in journal_entry_open()
372 * The fifo_push() needs to happen at the same time as j->seq is in journal_entry_open()
375 atomic64_inc(&j->seq); in journal_entry_open()
376 journal_pin_list_init(fifo_push_ref(&j->pin), 1); in journal_entry_open()
378 BUG_ON(j->pin.back - 1 != atomic64_read(&j->seq)); in journal_entry_open()
380 BUG_ON(j->buf + (journal_cur_seq(j) & JOURNAL_BUF_MASK) != buf); in journal_entry_open()
382 bkey_extent_init(&buf->key); in journal_entry_open()
383 buf->noflush = false; in journal_entry_open()
384 buf->must_flush = false; in journal_entry_open()
385 buf->separate_flush = false; in journal_entry_open()
386 buf->flush_time = 0; in journal_entry_open()
387 buf->need_flush_to_write_buffer = true; in journal_entry_open()
389 memset(buf->data, 0, sizeof(*buf->data)); in journal_entry_open()
390 buf->data->seq = cpu_to_le64(journal_cur_seq(j)); in journal_entry_open()
391 buf->data->u64s = 0; in journal_entry_open()
393 if (j->early_journal_entries.nr) { in journal_entry_open()
394 memcpy(buf->data->_data, j->early_journal_entries.data, in journal_entry_open()
395 j->early_journal_entries.nr * sizeof(u64)); in journal_entry_open()
396 le32_add_cpu(&buf->data->u64s, j->early_journal_entries.nr); in journal_entry_open()
402 j->cur_entry_u64s = u64s; in journal_entry_open()
404 v = atomic64_read(&j->reservations.counter); in journal_entry_open()
417 new.cur_entry_offset = le32_to_cpu(buf->data->u64s); in journal_entry_open()
418 } while ((v = atomic64_cmpxchg(&j->reservations.counter, in journal_entry_open()
421 mod_delayed_work(c->io_complete_wq, in journal_entry_open()
422 &j->write_work, in journal_entry_open()
423 msecs_to_jiffies(c->opts.journal_flush_delay)); in journal_entry_open()
426 if (j->early_journal_entries.nr) in journal_entry_open()
427 darray_exit(&j->early_journal_entries); in journal_entry_open()
433 bool ret = atomic64_read(&j->seq) == j->seq_ondisk; in journal_quiesced()
442 wait_event(j->wait, journal_quiesced(j)); in journal_quiesce()
451 spin_lock(&j->lock); in journal_write_work()
452 if (!__journal_entry_is_open(j->reservations)) in journal_write_work()
455 delta = journal_cur_buf(j)->expires - jiffies; in journal_write_work()
458 mod_delayed_work(c->io_complete_wq, &j->write_work, delta); in journal_write_work()
462 spin_unlock(&j->lock); in journal_write_work()
477 return -BCH_ERR_erofs_journal_err; in __journal_res_get()
479 spin_lock(&j->lock); in __journal_res_get()
483 spin_unlock(&j->lock); in __journal_res_get()
484 return -BCH_ERR_erofs_journal_err; in __journal_res_get()
493 spin_unlock(&j->lock); in __journal_res_get()
497 if ((flags & BCH_WATERMARK_MASK) < j->watermark) { in __journal_res_get()
513 buf->buf_size >> 9 < buf->disk_sectors && in __journal_res_get()
514 buf->buf_size < JOURNAL_ENTRY_SIZE_MAX) in __journal_res_get()
515 j->buf_size_want = max(j->buf_size_want, buf->buf_size << 1); in __journal_res_get()
521 track_event_change(&c->times[BCH_TIME_blocked_journal_max_in_flight], in __journal_res_get()
522 &j->max_in_flight_start, true); in __journal_res_get()
534 can_discard = j->can_discard; in __journal_res_get()
535 spin_unlock(&j->lock); in __journal_res_get()
540 ret = -BCH_ERR_journal_res_get_blocked; in __journal_res_get()
543 * Journal is full - can't rely on reclaim from work item due to in __journal_res_get()
554 if (mutex_trylock(&j->reclaim_lock)) { in __journal_res_get()
556 mutex_unlock(&j->reclaim_lock); in __journal_res_get()
561 ? -BCH_ERR_erofs_journal_err in __journal_res_get()
562 : -BCH_ERR_journal_res_get_blocked; in __journal_res_get()
580 closure_wait_event(&j->async_wait, in bch2_journal_res_get_slowpath()
581 (ret = __journal_res_get(j, res, flags)) != -BCH_ERR_journal_res_get_blocked || in bch2_journal_res_get_slowpath()
593 int d = new_u64s - res->u64s; in bch2_journal_entry_res_resize()
595 spin_lock(&j->lock); in bch2_journal_entry_res_resize()
597 j->entry_u64s_reserved += d; in bch2_journal_entry_res_resize()
601 j->cur_entry_u64s = max_t(int, 0, j->cur_entry_u64s - d); in bch2_journal_entry_res_resize()
603 state = READ_ONCE(j->reservations); in bch2_journal_entry_res_resize()
606 state.cur_entry_offset > j->cur_entry_u64s) { in bch2_journal_entry_res_resize()
607 j->cur_entry_u64s += d; in bch2_journal_entry_res_resize()
613 journal_cur_buf(j)->u64s_reserved += d; in bch2_journal_entry_res_resize()
616 spin_unlock(&j->lock); in bch2_journal_entry_res_resize()
617 res->u64s += d; in bch2_journal_entry_res_resize()
623 * bch2_journal_flush_seq_async - wait for a journal entry to be written
626 * @parent: closure object to wait with
628 * -EIO if @seq will never be flushed
639 if (seq <= j->flushed_seq_ondisk) in bch2_journal_flush_seq_async()
642 spin_lock(&j->lock); in bch2_journal_flush_seq_async()
650 if (j->err_seq && seq >= j->err_seq) { in bch2_journal_flush_seq_async()
651 ret = -EIO; in bch2_journal_flush_seq_async()
655 if (seq <= j->flushed_seq_ondisk) { in bch2_journal_flush_seq_async()
660 /* if seq was written, but not flushed - flush a newer one instead */ in bch2_journal_flush_seq_async()
670 spin_unlock(&j->lock); in bch2_journal_flush_seq_async()
677 buf = j->buf + (seq & JOURNAL_BUF_MASK); in bch2_journal_flush_seq_async()
678 buf->must_flush = true; in bch2_journal_flush_seq_async()
680 if (!buf->flush_time) { in bch2_journal_flush_seq_async()
681 buf->flush_time = local_clock() ?: 1; in bch2_journal_flush_seq_async()
682 buf->expires = jiffies; in bch2_journal_flush_seq_async()
685 if (parent && !closure_wait(&buf->wait, parent)) in bch2_journal_flush_seq_async()
690 spin_lock(&j->lock); in bch2_journal_flush_seq_async()
699 if (buf->noflush) { in bch2_journal_flush_seq_async()
704 buf->must_flush = true; in bch2_journal_flush_seq_async()
706 if (parent && !closure_wait(&buf->wait, parent)) in bch2_journal_flush_seq_async()
712 spin_unlock(&j->lock); in bch2_journal_flush_seq_async()
724 if (seq <= j->flushed_seq_ondisk) in bch2_journal_flush_seq()
727 ret = wait_event_interruptible(j->wait, (ret2 = bch2_journal_flush_seq_async(j, seq, NULL))); in bch2_journal_flush_seq()
730 bch2_time_stats_update(j->flush_seq_time, start_time); in bch2_journal_flush_seq()
736 * bch2_journal_flush_async - if there is an open journal entry, or a journal
737 * still being written, write it and wait for the write to complete
741 bch2_journal_flush_seq_async(j, atomic64_read(&j->seq), parent); in bch2_journal_flush_async()
746 return bch2_journal_flush_seq(j, atomic64_read(&j->seq)); in bch2_journal_flush()
750 * bch2_journal_noflush_seq - tell the journal not to issue any flushes before
759 if (!(c->sb.features & (1ULL << BCH_FEATURE_journal_no_flush))) in bch2_journal_noflush_seq()
762 if (seq <= c->journal.flushed_seq_ondisk) in bch2_journal_noflush_seq()
765 spin_lock(&j->lock); in bch2_journal_noflush_seq()
766 if (seq <= c->journal.flushed_seq_ondisk) in bch2_journal_noflush_seq()
775 if (unwritten_seq == journal_last_unwritten_seq(j) && !buf->noflush) in bch2_journal_noflush_seq()
778 buf->noflush = true; in bch2_journal_noflush_seq()
783 spin_unlock(&j->lock); in bch2_journal_noflush_seq()
799 buf = j->buf + (res.seq & JOURNAL_BUF_MASK); in bch2_journal_meta()
800 buf->must_flush = true; in bch2_journal_meta()
802 if (!buf->flush_time) { in bch2_journal_meta()
803 buf->flush_time = local_clock() ?: 1; in bch2_journal_meta()
804 buf->expires = jiffies; in bch2_journal_meta()
816 spin_lock(&j->lock); in bch2_journal_unblock()
817 j->blocked--; in bch2_journal_unblock()
818 spin_unlock(&j->lock); in bch2_journal_unblock()
825 spin_lock(&j->lock); in bch2_journal_block()
826 j->blocked++; in bch2_journal_block()
827 spin_unlock(&j->lock); in bch2_journal_block()
836 mutex_lock(&j->buf_lock); in __bch2_next_write_buffer_flush_journal_buf()
837 spin_lock(&j->lock); in __bch2_next_write_buffer_flush_journal_buf()
844 struct journal_buf *buf = j->buf + idx; in __bch2_next_write_buffer_flush_journal_buf()
846 if (buf->need_flush_to_write_buffer) { in __bch2_next_write_buffer_flush_journal_buf()
851 s.v = atomic64_read_acquire(&j->reservations.counter); in __bch2_next_write_buffer_flush_journal_buf()
854 ? ERR_PTR(-EAGAIN) in __bch2_next_write_buffer_flush_journal_buf()
860 spin_unlock(&j->lock); in __bch2_next_write_buffer_flush_journal_buf()
862 mutex_unlock(&j->buf_lock); in __bch2_next_write_buffer_flush_journal_buf()
870 …wait_event(j->wait, (ret = __bch2_next_write_buffer_flush_journal_buf(j, max_seq)) != ERR_PTR(-EAG… in bch2_next_write_buffer_flush_journal_buf()
879 struct bch_fs *c = ca->fs; in __bch2_set_nr_journal_buckets()
880 struct journal_device *ja = &ca->journal; in __bch2_set_nr_journal_buckets()
884 unsigned i, pos, nr_got = 0, nr_want = nr - ja->nr; in __bch2_set_nr_journal_buckets()
887 BUG_ON(nr <= ja->nr); in __bch2_set_nr_journal_buckets()
894 ret = -BCH_ERR_ENOMEM_set_nr_journal_buckets; in __bch2_set_nr_journal_buckets()
902 ret = -BCH_ERR_ENOSPC_bucket_alloc; in __bch2_set_nr_journal_buckets()
913 ob[nr_got]->bucket, BCH_DATA_journal, in __bch2_set_nr_journal_buckets()
914 ca->mi.bucket_size)); in __bch2_set_nr_journal_buckets()
921 bu[nr_got] = ob[nr_got]->bucket; in __bch2_set_nr_journal_buckets()
932 bch2_journal_flush_all_pins(&c->journal); in __bch2_set_nr_journal_buckets()
933 bch2_journal_block(&c->journal); in __bch2_set_nr_journal_buckets()
934 mutex_lock(&c->sb_lock); in __bch2_set_nr_journal_buckets()
937 memcpy(new_buckets, ja->buckets, ja->nr * sizeof(u64)); in __bch2_set_nr_journal_buckets()
938 memcpy(new_bucket_seq, ja->bucket_seq, ja->nr * sizeof(u64)); in __bch2_set_nr_journal_buckets()
940 BUG_ON(ja->discard_idx > ja->nr); in __bch2_set_nr_journal_buckets()
942 pos = ja->discard_idx ?: ja->nr; in __bch2_set_nr_journal_buckets()
946 sizeof(new_buckets[0]) * (ja->nr - pos)); in __bch2_set_nr_journal_buckets()
949 sizeof(new_bucket_seq[0]) * (ja->nr - pos)); in __bch2_set_nr_journal_buckets()
956 nr = ja->nr + nr_got; in __bch2_set_nr_journal_buckets()
967 spin_lock(&c->journal.lock); in __bch2_set_nr_journal_buckets()
969 swap(new_buckets, ja->buckets); in __bch2_set_nr_journal_buckets()
970 swap(new_bucket_seq, ja->bucket_seq); in __bch2_set_nr_journal_buckets()
971 ja->nr = nr; in __bch2_set_nr_journal_buckets()
973 if (pos <= ja->discard_idx) in __bch2_set_nr_journal_buckets()
974 ja->discard_idx = (ja->discard_idx + nr_got) % ja->nr; in __bch2_set_nr_journal_buckets()
975 if (pos <= ja->dirty_idx_ondisk) in __bch2_set_nr_journal_buckets()
976 ja->dirty_idx_ondisk = (ja->dirty_idx_ondisk + nr_got) % ja->nr; in __bch2_set_nr_journal_buckets()
977 if (pos <= ja->dirty_idx) in __bch2_set_nr_journal_buckets()
978 ja->dirty_idx = (ja->dirty_idx + nr_got) % ja->nr; in __bch2_set_nr_journal_buckets()
979 if (pos <= ja->cur_idx) in __bch2_set_nr_journal_buckets()
980 ja->cur_idx = (ja->cur_idx + nr_got) % ja->nr; in __bch2_set_nr_journal_buckets()
983 spin_unlock(&c->journal.lock); in __bch2_set_nr_journal_buckets()
986 bch2_journal_unblock(&c->journal); in __bch2_set_nr_journal_buckets()
987 mutex_unlock(&c->sb_lock); in __bch2_set_nr_journal_buckets()
1008 * Allocate more journal space at runtime - not currently making use if it, but
1014 struct journal_device *ja = &ca->journal; in bch2_set_nr_journal_buckets()
1020 down_write(&c->state_lock); in bch2_set_nr_journal_buckets()
1023 if (nr < ja->nr) in bch2_set_nr_journal_buckets()
1026 while (ja->nr < nr) { in bch2_set_nr_journal_buckets()
1032 * when space used goes up without a reservation - but we do need the in bch2_set_nr_journal_buckets()
1036 * filesystem-wide allocation will succeed, this is a device in bch2_set_nr_journal_buckets()
1037 * specific allocation - we can hang here: in bch2_set_nr_journal_buckets()
1041 bucket_to_sector(ca, nr - ja->nr), 1, 0); in bch2_set_nr_journal_buckets()
1051 if (ret && ret != -BCH_ERR_bucket_alloc_blocked) in bch2_set_nr_journal_buckets()
1057 up_write(&c->state_lock); in bch2_set_nr_journal_buckets()
1067 ret = -BCH_ERR_ENOMEM_set_nr_journal_buckets; in bch2_dev_journal_alloc()
1072 nr = ca->mi.nbuckets >> 7; in bch2_dev_journal_alloc()
1081 (1 << 24) / ca->mi.bucket_size)); in bch2_dev_journal_alloc()
1092 if (ca->journal.nr) in bch2_fs_journal_alloc()
1097 percpu_ref_put(&ca->io_ref); in bch2_fs_journal_alloc()
1112 spin_lock(&j->lock); in bch2_journal_writing_to_device()
1118 if (bch2_bkey_has_device_c(bkey_i_to_s_c(&buf->key), dev_idx)) in bch2_journal_writing_to_device()
1121 spin_unlock(&j->lock); in bch2_journal_writing_to_device()
1128 wait_event(j->wait, !bch2_journal_writing_to_device(j, ca->dev_idx)); in bch2_dev_journal_stop()
1136 wait_event(j->wait, bch2_journal_entry_close(j)); in bch2_fs_journal_stop()
1147 test_bit(JOURNAL_REPLAY_DONE, &j->flags) && in bch2_fs_journal_stop()
1148 j->last_empty_seq != journal_cur_seq(j)); in bch2_fs_journal_stop()
1150 cancel_delayed_work_sync(&j->write_work); in bch2_fs_journal_stop()
1163 genradix_for_each_reverse(&c->journal_entries, iter, _i) { in bch2_fs_journal_start()
1166 if (!i || i->ignore) in bch2_fs_journal_start()
1169 last_seq = le64_to_cpu(i->j.last_seq); in bch2_fs_journal_start()
1173 nr = cur_seq - last_seq; in bch2_fs_journal_start()
1175 if (nr + 1 > j->pin.size) { in bch2_fs_journal_start()
1176 free_fifo(&j->pin); in bch2_fs_journal_start()
1177 init_fifo(&j->pin, roundup_pow_of_two(nr + 1), GFP_KERNEL); in bch2_fs_journal_start()
1178 if (!j->pin.data) { in bch2_fs_journal_start()
1180 return -BCH_ERR_ENOMEM_journal_pin_fifo; in bch2_fs_journal_start()
1184 j->replay_journal_seq = last_seq; in bch2_fs_journal_start()
1185 j->replay_journal_seq_end = cur_seq; in bch2_fs_journal_start()
1186 j->last_seq_ondisk = last_seq; in bch2_fs_journal_start()
1187 j->flushed_seq_ondisk = cur_seq - 1; in bch2_fs_journal_start()
1188 j->seq_ondisk = cur_seq - 1; in bch2_fs_journal_start()
1189 j->pin.front = last_seq; in bch2_fs_journal_start()
1190 j->pin.back = cur_seq; in bch2_fs_journal_start()
1191 atomic64_set(&j->seq, cur_seq - 1); in bch2_fs_journal_start()
1193 fifo_for_each_entry_ptr(p, &j->pin, seq) in bch2_fs_journal_start()
1196 genradix_for_each(&c->journal_entries, iter, _i) { in bch2_fs_journal_start()
1199 if (!i || i->ignore) in bch2_fs_journal_start()
1202 seq = le64_to_cpu(i->j.seq); in bch2_fs_journal_start()
1208 if (journal_entry_empty(&i->j)) in bch2_fs_journal_start()
1209 j->last_empty_seq = le64_to_cpu(i->j.seq); in bch2_fs_journal_start()
1213 p->devs.nr = 0; in bch2_fs_journal_start()
1214 for (ptr = 0; ptr < i->nr_ptrs; ptr++) in bch2_fs_journal_start()
1215 bch2_dev_list_add_dev(&p->devs, i->ptrs[ptr].dev); in bch2_fs_journal_start()
1221 j->last_empty_seq = cur_seq; in bch2_fs_journal_start()
1223 spin_lock(&j->lock); in bch2_fs_journal_start()
1225 set_bit(JOURNAL_STARTED, &j->flags); in bch2_fs_journal_start()
1226 j->last_flush_write = jiffies; in bch2_fs_journal_start()
1228 j->reservations.idx = j->reservations.unwritten_idx = journal_cur_seq(j); in bch2_fs_journal_start()
1229 j->reservations.unwritten_idx++; in bch2_fs_journal_start()
1231 c->last_bucket_seq_cleanup = journal_cur_seq(j); in bch2_fs_journal_start()
1234 spin_unlock(&j->lock); in bch2_fs_journal_start()
1243 kfree(ca->journal.bio); in bch2_dev_journal_exit()
1244 kfree(ca->journal.buckets); in bch2_dev_journal_exit()
1245 kfree(ca->journal.bucket_seq); in bch2_dev_journal_exit()
1247 ca->journal.bio = NULL; in bch2_dev_journal_exit()
1248 ca->journal.buckets = NULL; in bch2_dev_journal_exit()
1249 ca->journal.bucket_seq = NULL; in bch2_dev_journal_exit()
1254 struct journal_device *ja = &ca->journal; in bch2_dev_journal_init()
1261 ja->nr = 0; in bch2_dev_journal_init()
1267 ja->nr += le64_to_cpu(journal_buckets_v2->d[i].nr); in bch2_dev_journal_init()
1269 ja->nr = bch2_nr_journal_buckets(journal_buckets); in bch2_dev_journal_init()
1272 ja->bucket_seq = kcalloc(ja->nr, sizeof(u64), GFP_KERNEL); in bch2_dev_journal_init()
1273 if (!ja->bucket_seq) in bch2_dev_journal_init()
1274 return -BCH_ERR_ENOMEM_dev_journal_init; in bch2_dev_journal_init()
1278 ca->journal.bio = bio_kmalloc(nr_bvecs, GFP_KERNEL); in bch2_dev_journal_init()
1279 if (!ca->journal.bio) in bch2_dev_journal_init()
1280 return -BCH_ERR_ENOMEM_dev_journal_init; in bch2_dev_journal_init()
1282 bio_init(ca->journal.bio, NULL, ca->journal.bio->bi_inline_vecs, nr_bvecs, 0); in bch2_dev_journal_init()
1284 ja->buckets = kcalloc(ja->nr, sizeof(u64), GFP_KERNEL); in bch2_dev_journal_init()
1285 if (!ja->buckets) in bch2_dev_journal_init()
1286 return -BCH_ERR_ENOMEM_dev_journal_init; in bch2_dev_journal_init()
1293 for (j = 0; j < le64_to_cpu(journal_buckets_v2->d[i].nr); j++) in bch2_dev_journal_init()
1294 ja->buckets[dst++] = in bch2_dev_journal_init()
1295 le64_to_cpu(journal_buckets_v2->d[i].start) + j; in bch2_dev_journal_init()
1297 for (i = 0; i < ja->nr; i++) in bch2_dev_journal_init()
1298 ja->buckets[i] = le64_to_cpu(journal_buckets->buckets[i]); in bch2_dev_journal_init()
1308 darray_exit(&j->early_journal_entries); in bch2_fs_journal_exit()
1310 for (i = 0; i < ARRAY_SIZE(j->buf); i++) in bch2_fs_journal_exit()
1311 kvpfree(j->buf[i].data, j->buf[i].buf_size); in bch2_fs_journal_exit()
1312 free_fifo(&j->pin); in bch2_fs_journal_exit()
1320 mutex_init(&j->buf_lock); in bch2_fs_journal_init()
1321 spin_lock_init(&j->lock); in bch2_fs_journal_init()
1322 spin_lock_init(&j->err_lock); in bch2_fs_journal_init()
1323 init_waitqueue_head(&j->wait); in bch2_fs_journal_init()
1324 INIT_DELAYED_WORK(&j->write_work, journal_write_work); in bch2_fs_journal_init()
1325 init_waitqueue_head(&j->reclaim_wait); in bch2_fs_journal_init()
1326 init_waitqueue_head(&j->pin_flush_wait); in bch2_fs_journal_init()
1327 mutex_init(&j->reclaim_lock); in bch2_fs_journal_init()
1328 mutex_init(&j->discard_lock); in bch2_fs_journal_init()
1330 lockdep_init_map(&j->res_map, "journal res", &res_key, 0); in bch2_fs_journal_init()
1332 atomic64_set(&j->reservations.counter, in bch2_fs_journal_init()
1336 if (!(init_fifo(&j->pin, JOURNAL_PIN, GFP_KERNEL))) in bch2_fs_journal_init()
1337 return -BCH_ERR_ENOMEM_journal_pin_fifo; in bch2_fs_journal_init()
1339 for (i = 0; i < ARRAY_SIZE(j->buf); i++) { in bch2_fs_journal_init()
1340 j->buf[i].buf_size = JOURNAL_ENTRY_SIZE_MIN; in bch2_fs_journal_init()
1341 j->buf[i].data = kvpmalloc(j->buf[i].buf_size, GFP_KERNEL); in bch2_fs_journal_init()
1342 if (!j->buf[i].data) in bch2_fs_journal_init()
1343 return -BCH_ERR_ENOMEM_journal_buf; in bch2_fs_journal_init()
1346 j->pin.front = j->pin.back = 1; in bch2_fs_journal_init()
1357 u64 nr_writes = j->nr_flush_writes + j->nr_noflush_writes; in __bch2_journal_debug_to_text()
1359 if (!out->nr_tabstops) in __bch2_journal_debug_to_text()
1361 out->atomic++; in __bch2_journal_debug_to_text()
1364 s = READ_ONCE(j->reservations); in __bch2_journal_debug_to_text()
1366 prt_printf(out, "dirty journal entries:\t%llu/%llu\n", fifo_used(&j->pin), j->pin.size); in __bch2_journal_debug_to_text()
1368 prt_printf(out, "seq_ondisk:\t\t%llu\n", j->seq_ondisk); in __bch2_journal_debug_to_text()
1370 prt_printf(out, "last_seq_ondisk:\t%llu\n", j->last_seq_ondisk); in __bch2_journal_debug_to_text()
1371 prt_printf(out, "flushed_seq_ondisk:\t%llu\n", j->flushed_seq_ondisk); in __bch2_journal_debug_to_text()
1372 prt_printf(out, "watermark:\t\t%s\n", bch2_watermarks[j->watermark]); in __bch2_journal_debug_to_text()
1373 prt_printf(out, "each entry reserved:\t%u\n", j->entry_u64s_reserved); in __bch2_journal_debug_to_text()
1374 prt_printf(out, "nr flush writes:\t%llu\n", j->nr_flush_writes); in __bch2_journal_debug_to_text()
1375 prt_printf(out, "nr noflush writes:\t%llu\n", j->nr_noflush_writes); in __bch2_journal_debug_to_text()
1377 prt_human_readable_u64(out, nr_writes ? div64_u64(j->entry_bytes_written, nr_writes) : 0); in __bch2_journal_debug_to_text()
1379 prt_printf(out, "nr direct reclaim:\t%llu\n", j->nr_direct_reclaim); in __bch2_journal_debug_to_text()
1380 prt_printf(out, "nr background reclaim:\t%llu\n", j->nr_background_reclaim); in __bch2_journal_debug_to_text()
1381 prt_printf(out, "reclaim kicked:\t\t%u\n", j->reclaim_kicked); in __bch2_journal_debug_to_text()
1382 prt_printf(out, "reclaim runs in:\t%u ms\n", time_after(j->next_reclaim, now) in __bch2_journal_debug_to_text()
1383 ? jiffies_to_msecs(j->next_reclaim - jiffies) : 0); in __bch2_journal_debug_to_text()
1384 prt_printf(out, "current entry sectors:\t%u\n", j->cur_entry_sectors); in __bch2_journal_debug_to_text()
1385 prt_printf(out, "current entry error:\t%s\n", bch2_journal_errors[j->cur_entry_error]); in __bch2_journal_debug_to_text()
1396 prt_printf(out, "%u/%u", s.cur_entry_offset, j->cur_entry_u64s); in __bch2_journal_debug_to_text()
1407 test_bit(JOURNAL_REPLAY_DONE, &j->flags)); in __bch2_journal_debug_to_text()
1411 j->space[journal_space_discarded].next_entry, in __bch2_journal_debug_to_text()
1412 j->space[journal_space_discarded].total); in __bch2_journal_debug_to_text()
1414 j->space[journal_space_clean_ondisk].next_entry, in __bch2_journal_debug_to_text()
1415 j->space[journal_space_clean_ondisk].total); in __bch2_journal_debug_to_text()
1417 j->space[journal_space_clean].next_entry, in __bch2_journal_debug_to_text()
1418 j->space[journal_space_clean].total); in __bch2_journal_debug_to_text()
1420 j->space[journal_space_total].next_entry, in __bch2_journal_debug_to_text()
1421 j->space[journal_space_total].total); in __bch2_journal_debug_to_text()
1423 for_each_member_device_rcu(c, ca, &c->rw_devs[BCH_DATA_journal]) { in __bch2_journal_debug_to_text()
1424 struct journal_device *ja = &ca->journal; in __bch2_journal_debug_to_text()
1426 if (!test_bit(ca->dev_idx, c->rw_devs[BCH_DATA_journal].d)) in __bch2_journal_debug_to_text()
1429 if (!ja->nr) in __bch2_journal_debug_to_text()
1432 prt_printf(out, "dev %u:\n", ca->dev_idx); in __bch2_journal_debug_to_text()
1433 prt_printf(out, "\tnr\t\t%u\n", ja->nr); in __bch2_journal_debug_to_text()
1434 prt_printf(out, "\tbucket size\t%u\n", ca->mi.bucket_size); in __bch2_journal_debug_to_text()
1435 …e\t%u:%u\n", bch2_journal_dev_buckets_available(j, ja, journal_space_discarded), ja->sectors_free); in __bch2_journal_debug_to_text()
1436 prt_printf(out, "\tdiscard_idx\t%u\n", ja->discard_idx); in __bch2_journal_debug_to_text()
1437 …prt_printf(out, "\tdirty_ondisk\t%u (seq %llu)\n", ja->dirty_idx_ondisk, ja->bucket_seq[ja->dirty_… in __bch2_journal_debug_to_text()
1438 prt_printf(out, "\tdirty_idx\t%u (seq %llu)\n", ja->dirty_idx, ja->bucket_seq[ja->dirty_idx]); in __bch2_journal_debug_to_text()
1439 prt_printf(out, "\tcur_idx\t\t%u (seq %llu)\n", ja->cur_idx, ja->bucket_seq[ja->cur_idx]); in __bch2_journal_debug_to_text()
1444 --out->atomic; in __bch2_journal_debug_to_text()
1449 spin_lock(&j->lock); in bch2_journal_debug_to_text()
1451 spin_unlock(&j->lock); in bch2_journal_debug_to_text()
1457 struct journal_entry_pin *pin; in bch2_journal_seq_pins_to_text() local
1460 spin_lock(&j->lock); in bch2_journal_seq_pins_to_text()
1461 *seq = max(*seq, j->pin.front); in bch2_journal_seq_pins_to_text()
1463 if (*seq >= j->pin.back) { in bch2_journal_seq_pins_to_text()
1464 spin_unlock(&j->lock); in bch2_journal_seq_pins_to_text()
1468 out->atomic++; in bch2_journal_seq_pins_to_text()
1472 prt_printf(out, "%llu: count %u", *seq, atomic_read(&pin_list->count)); in bch2_journal_seq_pins_to_text()
1476 for (i = 0; i < ARRAY_SIZE(pin_list->list); i++) in bch2_journal_seq_pins_to_text()
1477 list_for_each_entry(pin, &pin_list->list[i], list) { in bch2_journal_seq_pins_to_text()
1478 prt_printf(out, "\t%px %ps", pin, pin->flush); in bch2_journal_seq_pins_to_text()
1482 if (!list_empty(&pin_list->flushed)) { in bch2_journal_seq_pins_to_text()
1487 list_for_each_entry(pin, &pin_list->flushed, list) { in bch2_journal_seq_pins_to_text()
1488 prt_printf(out, "\t%px %ps", pin, pin->flush); in bch2_journal_seq_pins_to_text()
1494 --out->atomic; in bch2_journal_seq_pins_to_text()
1495 spin_unlock(&j->lock); in bch2_journal_seq_pins_to_text()