1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright 2012 Google, Inc.
8 #include "alloc_foreground.h"
11 #include "btree_update.h"
19 #include "extent_update.h"
25 #include "nocow_locking.h"
26 #include "rebalance.h"
27 #include "subvolume.h"
32 #include <linux/blkdev.h>
33 #include <linux/prefetch.h>
34 #include <linux/random.h>
35 #include <linux/sched/mm.h>
37 #ifndef CONFIG_BCACHEFS_NO_LATENCY_ACCT
39 static inline void bch2_congested_acct(struct bch_dev *ca, u64 io_latency,
43 ca->io_latency[rw].quantiles.entries[QUANTILE_IDX(1)].m;
44 /* ideally we'd be taking into account the device's variance here: */
45 u64 latency_threshold = latency_capable << (rw == READ ? 2 : 3);
46 s64 latency_over = io_latency - latency_threshold;
48 if (latency_threshold && latency_over > 0) {
50 * bump up congested by approximately latency_over * 4 /
51 * latency_threshold - we don't need much accuracy here so don't
52 * bother with the divide:
54 if (atomic_read(&ca->congested) < CONGESTED_MAX)
55 atomic_add(latency_over >>
56 max_t(int, ilog2(latency_threshold) - 2, 0),
59 ca->congested_last = now;
60 } else if (atomic_read(&ca->congested) > 0) {
61 atomic_dec(&ca->congested);
65 void bch2_latency_acct(struct bch_dev *ca, u64 submit_time, int rw)
67 atomic64_t *latency = &ca->cur_latency[rw];
68 u64 now = local_clock();
69 u64 io_latency = time_after64(now, submit_time)
72 u64 old, new, v = atomic64_read(latency);
78 * If the io latency was reasonably close to the current
79 * latency, skip doing the update and atomic operation - most of
82 if (abs((int) (old - io_latency)) < (old >> 1) &&
86 new = ewma_add(old, io_latency, 5);
87 } while ((v = atomic64_cmpxchg(latency, old, new)) != old);
89 bch2_congested_acct(ca, io_latency, now, rw);
91 __bch2_time_stats_update(&ca->io_latency[rw].stats, submit_time, now);
96 /* Allocate, free from mempool: */
98 void bch2_bio_free_pages_pool(struct bch_fs *c, struct bio *bio)
100 struct bvec_iter_all iter;
103 bio_for_each_segment_all(bv, bio, iter)
104 if (bv->bv_page != ZERO_PAGE(0))
105 mempool_free(bv->bv_page, &c->bio_bounce_pages);
109 static struct page *__bio_alloc_page_pool(struct bch_fs *c, bool *using_mempool)
113 if (likely(!*using_mempool)) {
114 page = alloc_page(GFP_NOFS);
115 if (unlikely(!page)) {
116 mutex_lock(&c->bio_bounce_pages_lock);
117 *using_mempool = true;
123 page = mempool_alloc(&c->bio_bounce_pages, GFP_NOFS);
129 void bch2_bio_alloc_pages_pool(struct bch_fs *c, struct bio *bio,
132 bool using_mempool = false;
135 struct page *page = __bio_alloc_page_pool(c, &using_mempool);
136 unsigned len = min_t(size_t, PAGE_SIZE, size);
138 BUG_ON(!bio_add_page(bio, page, len, 0));
143 mutex_unlock(&c->bio_bounce_pages_lock);
146 /* Extent update path: */
148 int bch2_sum_sector_overwrites(struct btree_trans *trans,
149 struct btree_iter *extent_iter,
151 bool *usage_increasing,
152 s64 *i_sectors_delta,
153 s64 *disk_sectors_delta)
155 struct bch_fs *c = trans->c;
156 struct btree_iter iter;
158 unsigned new_replicas = bch2_bkey_replicas(c, bkey_i_to_s_c(new));
159 bool new_compressed = bch2_bkey_sectors_compressed(bkey_i_to_s_c(new));
162 *usage_increasing = false;
163 *i_sectors_delta = 0;
164 *disk_sectors_delta = 0;
166 bch2_trans_copy_iter(&iter, extent_iter);
168 for_each_btree_key_upto_continue_norestart(iter,
169 new->k.p, BTREE_ITER_slots, old, ret) {
170 s64 sectors = min(new->k.p.offset, old.k->p.offset) -
171 max(bkey_start_offset(&new->k),
172 bkey_start_offset(old.k));
174 *i_sectors_delta += sectors *
175 (bkey_extent_is_allocation(&new->k) -
176 bkey_extent_is_allocation(old.k));
178 *disk_sectors_delta += sectors * bch2_bkey_nr_ptrs_allocated(bkey_i_to_s_c(new));
179 *disk_sectors_delta -= new->k.p.snapshot == old.k->p.snapshot
180 ? sectors * bch2_bkey_nr_ptrs_fully_allocated(old)
183 if (!*usage_increasing &&
184 (new->k.p.snapshot != old.k->p.snapshot ||
185 new_replicas > bch2_bkey_replicas(c, old) ||
186 (!new_compressed && bch2_bkey_sectors_compressed(old))))
187 *usage_increasing = true;
189 if (bkey_ge(old.k->p, new->k.p))
193 bch2_trans_iter_exit(trans, &iter);
197 static inline int bch2_extent_update_i_size_sectors(struct btree_trans *trans,
198 struct btree_iter *extent_iter,
203 * Crazy performance optimization:
204 * Every extent update needs to also update the inode: the inode trigger
205 * will set bi->journal_seq to the journal sequence number of this
206 * transaction - for fsync.
208 * But if that's the only reason we're updating the inode (we're not
209 * updating bi_size or bi_sectors), then we don't need the inode update
210 * to be journalled - if we crash, the bi_journal_seq update will be
211 * lost, but that's fine.
213 unsigned inode_update_flags = BTREE_UPDATE_nojournal;
215 struct btree_iter iter;
216 struct bkey_s_c k = bch2_bkey_get_iter(trans, &iter, BTREE_ID_inodes,
218 extent_iter->pos.inode,
219 extent_iter->snapshot),
221 int ret = bkey_err(k);
226 * varint_decode_fast(), in the inode .invalid method, reads up to 7
227 * bytes past the end of the buffer:
229 struct bkey_i *k_mut = bch2_trans_kmalloc_nomemzero(trans, bkey_bytes(k.k) + 8);
230 ret = PTR_ERR_OR_ZERO(k_mut);
234 bkey_reassemble(k_mut, k);
236 if (unlikely(k_mut->k.type != KEY_TYPE_inode_v3)) {
237 k_mut = bch2_inode_to_v3(trans, k_mut);
238 ret = PTR_ERR_OR_ZERO(k_mut);
243 struct bkey_i_inode_v3 *inode = bkey_i_to_inode_v3(k_mut);
245 if (!(le64_to_cpu(inode->v.bi_flags) & BCH_INODE_i_size_dirty) &&
246 new_i_size > le64_to_cpu(inode->v.bi_size)) {
247 inode->v.bi_size = cpu_to_le64(new_i_size);
248 inode_update_flags = 0;
251 if (i_sectors_delta) {
252 le64_add_cpu(&inode->v.bi_sectors, i_sectors_delta);
253 inode_update_flags = 0;
256 if (inode->k.p.snapshot != iter.snapshot) {
257 inode->k.p.snapshot = iter.snapshot;
258 inode_update_flags = 0;
261 ret = bch2_trans_update(trans, &iter, &inode->k_i,
262 BTREE_UPDATE_internal_snapshot_node|
265 bch2_trans_iter_exit(trans, &iter);
269 int bch2_extent_update(struct btree_trans *trans,
271 struct btree_iter *iter,
273 struct disk_reservation *disk_res,
275 s64 *i_sectors_delta_total,
278 struct bpos next_pos;
279 bool usage_increasing;
280 s64 i_sectors_delta = 0, disk_sectors_delta = 0;
284 * This traverses us the iterator without changing iter->path->pos to
285 * search_key() (which is pos + 1 for extents): we want there to be a
286 * path already traversed at iter->pos because
287 * bch2_trans_extent_update() will use it to attempt extent merging
289 ret = __bch2_btree_iter_traverse(iter);
293 ret = bch2_extent_trim_atomic(trans, iter, k);
299 ret = bch2_sum_sector_overwrites(trans, iter, k,
302 &disk_sectors_delta);
307 disk_sectors_delta > (s64) disk_res->sectors) {
308 ret = bch2_disk_reservation_add(trans->c, disk_res,
309 disk_sectors_delta - disk_res->sectors,
310 !check_enospc || !usage_increasing
311 ? BCH_DISK_RESERVATION_NOFAIL : 0);
318 * We always have to do an inode update - even when i_size/i_sectors
319 * aren't changing - for fsync to work properly; fsync relies on
320 * inode->bi_journal_seq which is updated by the trigger code:
322 ret = bch2_extent_update_i_size_sectors(trans, iter,
323 min(k->k.p.offset << 9, new_i_size),
325 bch2_trans_update(trans, iter, k, 0) ?:
326 bch2_trans_commit(trans, disk_res, NULL,
327 BCH_TRANS_COMMIT_no_check_rw|
328 BCH_TRANS_COMMIT_no_enospc);
332 if (i_sectors_delta_total)
333 *i_sectors_delta_total += i_sectors_delta;
334 bch2_btree_iter_set_pos(iter, next_pos);
338 static int bch2_write_index_default(struct bch_write_op *op)
340 struct bch_fs *c = op->c;
342 struct keylist *keys = &op->insert_keys;
343 struct bkey_i *k = bch2_keylist_front(keys);
344 struct btree_trans *trans = bch2_trans_get(c);
345 struct btree_iter iter;
347 .subvol = op->subvol,
348 .inum = k->k.p.inode,
352 BUG_ON(!inum.subvol);
354 bch2_bkey_buf_init(&sk);
357 bch2_trans_begin(trans);
359 k = bch2_keylist_front(keys);
360 bch2_bkey_buf_copy(&sk, c, k);
362 ret = bch2_subvolume_get_snapshot(trans, inum.subvol,
363 &sk.k->k.p.snapshot);
364 if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
369 bch2_trans_iter_init(trans, &iter, BTREE_ID_extents,
370 bkey_start_pos(&sk.k->k),
371 BTREE_ITER_slots|BTREE_ITER_intent);
373 ret = bch2_bkey_set_needs_rebalance(c, sk.k, &op->opts) ?:
374 bch2_extent_update(trans, inum, &iter, sk.k,
376 op->new_i_size, &op->i_sectors_delta,
377 op->flags & BCH_WRITE_CHECK_ENOSPC);
378 bch2_trans_iter_exit(trans, &iter);
380 if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
385 if (bkey_ge(iter.pos, k->k.p))
386 bch2_keylist_pop_front(&op->insert_keys);
388 bch2_cut_front(iter.pos, k);
389 } while (!bch2_keylist_empty(keys));
391 bch2_trans_put(trans);
392 bch2_bkey_buf_exit(&sk, c);
399 void bch2_submit_wbio_replicas(struct bch_write_bio *wbio, struct bch_fs *c,
400 enum bch_data_type type,
401 const struct bkey_i *k,
404 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(bkey_i_to_s_c(k));
405 struct bch_write_bio *n;
407 BUG_ON(c->opts.nochanges);
409 bkey_for_each_ptr(ptrs, ptr) {
410 struct bch_dev *ca = nocow
411 ? bch2_dev_have_ref(c, ptr->dev)
412 : bch2_dev_get_ioref(c, ptr->dev, type == BCH_DATA_btree ? READ : WRITE);
414 if (to_entry(ptr + 1) < ptrs.end) {
415 n = to_wbio(bio_alloc_clone(NULL, &wbio->bio, GFP_NOFS, &c->replica_set));
417 n->bio.bi_end_io = wbio->bio.bi_end_io;
418 n->bio.bi_private = wbio->bio.bi_private;
423 n->bio.bi_opf = wbio->bio.bi_opf;
424 bio_inc_remaining(&wbio->bio);
432 n->have_ioref = ca != NULL;
434 n->submit_time = local_clock();
435 n->inode_offset = bkey_start_offset(&k->k);
437 n->nocow_bucket = PTR_BUCKET_NR(ca, ptr);
438 n->bio.bi_iter.bi_sector = ptr->offset;
440 if (likely(n->have_ioref)) {
441 this_cpu_add(ca->io_done->sectors[WRITE][type],
442 bio_sectors(&n->bio));
444 bio_set_dev(&n->bio, ca->disk_sb.bdev);
446 if (type != BCH_DATA_btree && unlikely(c->opts.no_data_io)) {
453 n->bio.bi_status = BLK_STS_REMOVED;
459 static void __bch2_write(struct bch_write_op *);
461 static void bch2_write_done(struct closure *cl)
463 struct bch_write_op *op = container_of(cl, struct bch_write_op, cl);
464 struct bch_fs *c = op->c;
466 EBUG_ON(op->open_buckets.nr);
468 bch2_time_stats_update(&c->times[BCH_TIME_data_write], op->start_time);
469 bch2_disk_reservation_put(c, &op->res);
471 if (!(op->flags & BCH_WRITE_MOVE))
472 bch2_write_ref_put(c, BCH_WRITE_REF_write);
473 bch2_keylist_free(&op->insert_keys, op->inline_keys);
476 closure_debug_destroy(cl);
481 static noinline int bch2_write_drop_io_error_ptrs(struct bch_write_op *op)
483 struct keylist *keys = &op->insert_keys;
484 struct bkey_i *src, *dst = keys->keys, *n;
486 for (src = keys->keys; src != keys->top; src = n) {
489 if (bkey_extent_is_direct_data(&src->k)) {
490 bch2_bkey_drop_ptrs(bkey_i_to_s(src), ptr,
491 test_bit(ptr->dev, op->failed.d));
493 if (!bch2_bkey_nr_ptrs(bkey_i_to_s_c(src)))
498 memmove_u64s_down(dst, src, src->k.u64s);
499 dst = bkey_next(dst);
507 * __bch2_write_index - after a write, update index to point to new data
508 * @op: bch_write_op to process
510 static void __bch2_write_index(struct bch_write_op *op)
512 struct bch_fs *c = op->c;
513 struct keylist *keys = &op->insert_keys;
517 if (unlikely(op->flags & BCH_WRITE_IO_ERROR)) {
518 ret = bch2_write_drop_io_error_ptrs(op);
523 if (!bch2_keylist_empty(keys)) {
524 u64 sectors_start = keylist_sectors(keys);
526 ret = !(op->flags & BCH_WRITE_MOVE)
527 ? bch2_write_index_default(op)
528 : bch2_data_update_index_update(op);
530 BUG_ON(bch2_err_matches(ret, BCH_ERR_transaction_restart));
531 BUG_ON(keylist_sectors(keys) && !ret);
533 op->written += sectors_start - keylist_sectors(keys);
535 if (ret && !bch2_err_matches(ret, EROFS)) {
536 struct bkey_i *insert = bch2_keylist_front(&op->insert_keys);
538 bch_err_inum_offset_ratelimited(c,
539 insert->k.p.inode, insert->k.p.offset << 9,
540 "%s write error while doing btree update: %s",
541 op->flags & BCH_WRITE_MOVE ? "move" : "user",
549 /* If some a bucket wasn't written, we can't erasure code it: */
550 for_each_set_bit(dev, op->failed.d, BCH_SB_MEMBERS_MAX)
551 bch2_open_bucket_write_error(c, &op->open_buckets, dev);
553 bch2_open_buckets_put(c, &op->open_buckets);
556 keys->top = keys->keys;
558 op->flags |= BCH_WRITE_DONE;
562 static inline void __wp_update_state(struct write_point *wp, enum write_point_state state)
564 if (state != wp->state) {
565 u64 now = ktime_get_ns();
567 if (wp->last_state_change &&
568 time_after64(now, wp->last_state_change))
569 wp->time[wp->state] += now - wp->last_state_change;
571 wp->last_state_change = now;
575 static inline void wp_update_state(struct write_point *wp, bool running)
577 enum write_point_state state;
579 state = running ? WRITE_POINT_running :
580 !list_empty(&wp->writes) ? WRITE_POINT_waiting_io
581 : WRITE_POINT_stopped;
583 __wp_update_state(wp, state);
586 static CLOSURE_CALLBACK(bch2_write_index)
588 closure_type(op, struct bch_write_op, cl);
589 struct write_point *wp = op->wp;
590 struct workqueue_struct *wq = index_update_wq(op);
593 if ((op->flags & BCH_WRITE_DONE) &&
594 (op->flags & BCH_WRITE_MOVE))
595 bch2_bio_free_pages_pool(op->c, &op->wbio.bio);
597 spin_lock_irqsave(&wp->writes_lock, flags);
598 if (wp->state == WRITE_POINT_waiting_io)
599 __wp_update_state(wp, WRITE_POINT_waiting_work);
600 list_add_tail(&op->wp_list, &wp->writes);
601 spin_unlock_irqrestore (&wp->writes_lock, flags);
603 queue_work(wq, &wp->index_update_work);
606 static inline void bch2_write_queue(struct bch_write_op *op, struct write_point *wp)
610 if (wp->state == WRITE_POINT_stopped) {
611 spin_lock_irq(&wp->writes_lock);
612 __wp_update_state(wp, WRITE_POINT_waiting_io);
613 spin_unlock_irq(&wp->writes_lock);
617 void bch2_write_point_do_index_updates(struct work_struct *work)
619 struct write_point *wp =
620 container_of(work, struct write_point, index_update_work);
621 struct bch_write_op *op;
624 spin_lock_irq(&wp->writes_lock);
625 op = list_first_entry_or_null(&wp->writes, struct bch_write_op, wp_list);
627 list_del(&op->wp_list);
628 wp_update_state(wp, op != NULL);
629 spin_unlock_irq(&wp->writes_lock);
634 op->flags |= BCH_WRITE_IN_WORKER;
636 __bch2_write_index(op);
638 if (!(op->flags & BCH_WRITE_DONE))
641 bch2_write_done(&op->cl);
645 static void bch2_write_endio(struct bio *bio)
647 struct closure *cl = bio->bi_private;
648 struct bch_write_op *op = container_of(cl, struct bch_write_op, cl);
649 struct bch_write_bio *wbio = to_wbio(bio);
650 struct bch_write_bio *parent = wbio->split ? wbio->parent : NULL;
651 struct bch_fs *c = wbio->c;
652 struct bch_dev *ca = wbio->have_ioref
653 ? bch2_dev_have_ref(c, wbio->dev)
656 if (bch2_dev_inum_io_err_on(bio->bi_status, ca, BCH_MEMBER_ERROR_write,
658 wbio->inode_offset << 9,
659 "data write error: %s",
660 bch2_blk_status_to_str(bio->bi_status))) {
661 set_bit(wbio->dev, op->failed.d);
662 op->flags |= BCH_WRITE_IO_ERROR;
666 bch2_bucket_nocow_unlock(&c->nocow_locks,
667 POS(ca->dev_idx, wbio->nocow_bucket),
668 BUCKET_NOCOW_LOCK_UPDATE);
669 set_bit(wbio->dev, op->devs_need_flush->d);
672 if (wbio->have_ioref) {
673 bch2_latency_acct(ca, wbio->submit_time, WRITE);
674 percpu_ref_put(&ca->io_ref);
678 bch2_bio_free_pages_pool(c, bio);
684 bio_endio(&parent->bio);
689 static void init_append_extent(struct bch_write_op *op,
690 struct write_point *wp,
691 struct bversion version,
692 struct bch_extent_crc_unpacked crc)
694 struct bkey_i_extent *e;
696 op->pos.offset += crc.uncompressed_size;
698 e = bkey_extent_init(op->insert_keys.top);
700 e->k.size = crc.uncompressed_size;
701 e->k.version = version;
704 crc.compression_type ||
706 bch2_extent_crc_append(&e->k_i, crc);
708 bch2_alloc_sectors_append_ptrs_inlined(op->c, wp, &e->k_i, crc.compressed_size,
709 op->flags & BCH_WRITE_CACHED);
711 bch2_keylist_push(&op->insert_keys);
714 static struct bio *bch2_write_bio_alloc(struct bch_fs *c,
715 struct write_point *wp,
717 bool *page_alloc_failed,
720 struct bch_write_bio *wbio;
722 unsigned output_available =
723 min(wp->sectors_free << 9, src->bi_iter.bi_size);
724 unsigned pages = DIV_ROUND_UP(output_available +
726 ? ((unsigned long) buf & (PAGE_SIZE - 1))
729 pages = min(pages, BIO_MAX_VECS);
731 bio = bio_alloc_bioset(NULL, pages, 0,
732 GFP_NOFS, &c->bio_write);
733 wbio = wbio_init(bio);
734 wbio->put_bio = true;
735 /* copy WRITE_SYNC flag */
736 wbio->bio.bi_opf = src->bi_opf;
739 bch2_bio_map(bio, buf, output_available);
746 * We can't use mempool for more than c->sb.encoded_extent_max
747 * worth of pages, but we'd like to allocate more if we can:
749 bch2_bio_alloc_pages_pool(c, bio,
750 min_t(unsigned, output_available,
751 c->opts.encoded_extent_max));
753 if (bio->bi_iter.bi_size < output_available)
755 bch2_bio_alloc_pages(bio,
757 bio->bi_iter.bi_size,
763 static int bch2_write_rechecksum(struct bch_fs *c,
764 struct bch_write_op *op,
765 unsigned new_csum_type)
767 struct bio *bio = &op->wbio.bio;
768 struct bch_extent_crc_unpacked new_crc;
771 /* bch2_rechecksum_bio() can't encrypt or decrypt data: */
773 if (bch2_csum_type_is_encryption(op->crc.csum_type) !=
774 bch2_csum_type_is_encryption(new_csum_type))
775 new_csum_type = op->crc.csum_type;
777 ret = bch2_rechecksum_bio(c, bio, op->version, op->crc,
779 op->crc.offset, op->crc.live_size,
784 bio_advance(bio, op->crc.offset << 9);
785 bio->bi_iter.bi_size = op->crc.live_size << 9;
790 static int bch2_write_decrypt(struct bch_write_op *op)
792 struct bch_fs *c = op->c;
793 struct nonce nonce = extent_nonce(op->version, op->crc);
794 struct bch_csum csum;
797 if (!bch2_csum_type_is_encryption(op->crc.csum_type))
801 * If we need to decrypt data in the write path, we'll no longer be able
802 * to verify the existing checksum (poly1305 mac, in this case) after
803 * it's decrypted - this is the last point we'll be able to reverify the
806 csum = bch2_checksum_bio(c, op->crc.csum_type, nonce, &op->wbio.bio);
807 if (bch2_crc_cmp(op->crc.csum, csum) && !c->opts.no_data_io)
810 ret = bch2_encrypt_bio(c, op->crc.csum_type, nonce, &op->wbio.bio);
811 op->crc.csum_type = 0;
812 op->crc.csum = (struct bch_csum) { 0, 0 };
816 static enum prep_encoded_ret {
819 PREP_ENCODED_CHECKSUM_ERR,
820 PREP_ENCODED_DO_WRITE,
821 } bch2_write_prep_encoded_data(struct bch_write_op *op, struct write_point *wp)
823 struct bch_fs *c = op->c;
824 struct bio *bio = &op->wbio.bio;
826 if (!(op->flags & BCH_WRITE_DATA_ENCODED))
827 return PREP_ENCODED_OK;
829 BUG_ON(bio_sectors(bio) != op->crc.compressed_size);
831 /* Can we just write the entire extent as is? */
832 if (op->crc.uncompressed_size == op->crc.live_size &&
833 op->crc.uncompressed_size <= c->opts.encoded_extent_max >> 9 &&
834 op->crc.compressed_size <= wp->sectors_free &&
835 (op->crc.compression_type == bch2_compression_opt_to_type(op->compression_opt) ||
836 op->incompressible)) {
837 if (!crc_is_compressed(op->crc) &&
838 op->csum_type != op->crc.csum_type &&
839 bch2_write_rechecksum(c, op, op->csum_type) &&
841 return PREP_ENCODED_CHECKSUM_ERR;
843 return PREP_ENCODED_DO_WRITE;
847 * If the data is compressed and we couldn't write the entire extent as
848 * is, we have to decompress it:
850 if (crc_is_compressed(op->crc)) {
851 struct bch_csum csum;
853 if (bch2_write_decrypt(op))
854 return PREP_ENCODED_CHECKSUM_ERR;
856 /* Last point we can still verify checksum: */
857 csum = bch2_checksum_bio(c, op->crc.csum_type,
858 extent_nonce(op->version, op->crc),
860 if (bch2_crc_cmp(op->crc.csum, csum) && !c->opts.no_data_io)
861 return PREP_ENCODED_CHECKSUM_ERR;
863 if (bch2_bio_uncompress_inplace(c, bio, &op->crc))
864 return PREP_ENCODED_ERR;
868 * No longer have compressed data after this point - data might be
873 * If the data is checksummed and we're only writing a subset,
874 * rechecksum and adjust bio to point to currently live data:
876 if ((op->crc.live_size != op->crc.uncompressed_size ||
877 op->crc.csum_type != op->csum_type) &&
878 bch2_write_rechecksum(c, op, op->csum_type) &&
880 return PREP_ENCODED_CHECKSUM_ERR;
883 * If we want to compress the data, it has to be decrypted:
885 if ((op->compression_opt ||
886 bch2_csum_type_is_encryption(op->crc.csum_type) !=
887 bch2_csum_type_is_encryption(op->csum_type)) &&
888 bch2_write_decrypt(op))
889 return PREP_ENCODED_CHECKSUM_ERR;
891 return PREP_ENCODED_OK;
894 static int bch2_write_extent(struct bch_write_op *op, struct write_point *wp,
897 struct bch_fs *c = op->c;
898 struct bio *src = &op->wbio.bio, *dst = src;
899 struct bvec_iter saved_iter;
901 unsigned total_output = 0, total_input = 0;
903 bool page_alloc_failed = false;
906 BUG_ON(!bio_sectors(src));
908 ec_buf = bch2_writepoint_ec_buf(c, wp);
910 switch (bch2_write_prep_encoded_data(op, wp)) {
911 case PREP_ENCODED_OK:
913 case PREP_ENCODED_ERR:
916 case PREP_ENCODED_CHECKSUM_ERR:
918 case PREP_ENCODED_DO_WRITE:
919 /* XXX look for bug here */
921 dst = bch2_write_bio_alloc(c, wp, src,
924 bio_copy_data(dst, src);
927 init_append_extent(op, wp, op->version, op->crc);
932 op->compression_opt ||
934 !(op->flags & BCH_WRITE_PAGES_STABLE)) ||
935 (bch2_csum_type_is_encryption(op->csum_type) &&
936 !(op->flags & BCH_WRITE_PAGES_OWNED))) {
937 dst = bch2_write_bio_alloc(c, wp, src,
943 saved_iter = dst->bi_iter;
946 struct bch_extent_crc_unpacked crc = { 0 };
947 struct bversion version = op->version;
948 size_t dst_len = 0, src_len = 0;
950 if (page_alloc_failed &&
951 dst->bi_iter.bi_size < (wp->sectors_free << 9) &&
952 dst->bi_iter.bi_size < c->opts.encoded_extent_max)
955 BUG_ON(op->compression_opt &&
956 (op->flags & BCH_WRITE_DATA_ENCODED) &&
957 bch2_csum_type_is_encryption(op->crc.csum_type));
958 BUG_ON(op->compression_opt && !bounce);
960 crc.compression_type = op->incompressible
961 ? BCH_COMPRESSION_TYPE_incompressible
962 : op->compression_opt
963 ? bch2_bio_compress(c, dst, &dst_len, src, &src_len,
966 if (!crc_is_compressed(crc)) {
967 dst_len = min(dst->bi_iter.bi_size, src->bi_iter.bi_size);
968 dst_len = min_t(unsigned, dst_len, wp->sectors_free << 9);
971 dst_len = min_t(unsigned, dst_len,
972 c->opts.encoded_extent_max);
975 swap(dst->bi_iter.bi_size, dst_len);
976 bio_copy_data(dst, src);
977 swap(dst->bi_iter.bi_size, dst_len);
983 BUG_ON(!src_len || !dst_len);
985 if (bch2_csum_type_is_encryption(op->csum_type)) {
986 if (bversion_zero(version)) {
987 version.lo = atomic64_inc_return(&c->key_version);
989 crc.nonce = op->nonce;
990 op->nonce += src_len >> 9;
994 if ((op->flags & BCH_WRITE_DATA_ENCODED) &&
995 !crc_is_compressed(crc) &&
996 bch2_csum_type_is_encryption(op->crc.csum_type) ==
997 bch2_csum_type_is_encryption(op->csum_type)) {
998 u8 compression_type = crc.compression_type;
999 u16 nonce = crc.nonce;
1001 * Note: when we're using rechecksum(), we need to be
1002 * checksumming @src because it has all the data our
1003 * existing checksum covers - if we bounced (because we
1004 * were trying to compress), @dst will only have the
1005 * part of the data the new checksum will cover.
1007 * But normally we want to be checksumming post bounce,
1008 * because part of the reason for bouncing is so the
1009 * data can't be modified (by userspace) while it's in
1012 if (bch2_rechecksum_bio(c, src, version, op->crc,
1015 bio_sectors(src) - (src_len >> 9),
1019 * rchecksum_bio sets compression_type on crc from op->crc,
1020 * this isn't always correct as sometimes we're changing
1021 * an extent from uncompressed to incompressible.
1023 crc.compression_type = compression_type;
1026 if ((op->flags & BCH_WRITE_DATA_ENCODED) &&
1027 bch2_rechecksum_bio(c, src, version, op->crc,
1030 bio_sectors(src) - (src_len >> 9),
1034 crc.compressed_size = dst_len >> 9;
1035 crc.uncompressed_size = src_len >> 9;
1036 crc.live_size = src_len >> 9;
1038 swap(dst->bi_iter.bi_size, dst_len);
1039 ret = bch2_encrypt_bio(c, op->csum_type,
1040 extent_nonce(version, crc), dst);
1044 crc.csum = bch2_checksum_bio(c, op->csum_type,
1045 extent_nonce(version, crc), dst);
1046 crc.csum_type = op->csum_type;
1047 swap(dst->bi_iter.bi_size, dst_len);
1050 init_append_extent(op, wp, version, crc);
1053 bio_advance(dst, dst_len);
1054 bio_advance(src, src_len);
1055 total_output += dst_len;
1056 total_input += src_len;
1057 } while (dst->bi_iter.bi_size &&
1058 src->bi_iter.bi_size &&
1060 !bch2_keylist_realloc(&op->insert_keys,
1062 ARRAY_SIZE(op->inline_keys),
1063 BKEY_EXTENT_U64s_MAX));
1065 more = src->bi_iter.bi_size != 0;
1067 dst->bi_iter = saved_iter;
1069 if (dst == src && more) {
1070 BUG_ON(total_output != total_input);
1072 dst = bio_split(src, total_input >> 9,
1073 GFP_NOFS, &c->bio_write);
1074 wbio_init(dst)->put_bio = true;
1075 /* copy WRITE_SYNC flag */
1076 dst->bi_opf = src->bi_opf;
1079 dst->bi_iter.bi_size = total_output;
1084 bch_err(c, "%s writ error: error verifying existing checksum while rewriting existing data (memory corruption?)",
1085 op->flags & BCH_WRITE_MOVE ? "move" : "user");
1088 if (to_wbio(dst)->bounce)
1089 bch2_bio_free_pages_pool(c, dst);
1090 if (to_wbio(dst)->put_bio)
1096 static bool bch2_extent_is_writeable(struct bch_write_op *op,
1099 struct bch_fs *c = op->c;
1100 struct bkey_s_c_extent e;
1101 struct extent_ptr_decoded p;
1102 const union bch_extent_entry *entry;
1103 unsigned replicas = 0;
1105 if (k.k->type != KEY_TYPE_extent)
1108 e = bkey_s_c_to_extent(k);
1111 extent_for_each_ptr_decode(e, p, entry) {
1112 if (crc_is_encoded(p.crc) || p.has_ec) {
1117 replicas += bch2_extent_ptr_durability(c, &p);
1121 return replicas >= op->opts.data_replicas;
1124 static int bch2_nocow_write_convert_one_unwritten(struct btree_trans *trans,
1125 struct btree_iter *iter,
1126 struct bkey_i *orig,
1130 if (!bch2_extents_match(bkey_i_to_s_c(orig), k)) {
1135 struct bkey_i *new = bch2_bkey_make_mut_noupdate(trans, k);
1136 int ret = PTR_ERR_OR_ZERO(new);
1140 bch2_cut_front(bkey_start_pos(&orig->k), new);
1141 bch2_cut_back(orig->k.p, new);
1143 struct bkey_ptrs ptrs = bch2_bkey_ptrs(bkey_i_to_s(new));
1144 bkey_for_each_ptr(ptrs, ptr)
1148 * Note that we're not calling bch2_subvol_get_snapshot() in this path -
1149 * that was done when we kicked off the write, and here it's important
1150 * that we update the extent that we wrote to - even if a snapshot has
1151 * since been created. The write is still outstanding, so we're ok
1152 * w.r.t. snapshot atomicity:
1154 return bch2_extent_update_i_size_sectors(trans, iter,
1155 min(new->k.p.offset << 9, new_i_size), 0) ?:
1156 bch2_trans_update(trans, iter, new,
1157 BTREE_UPDATE_internal_snapshot_node);
1160 static void bch2_nocow_write_convert_unwritten(struct bch_write_op *op)
1162 struct bch_fs *c = op->c;
1163 struct btree_trans *trans = bch2_trans_get(c);
1165 for_each_keylist_key(&op->insert_keys, orig) {
1166 int ret = for_each_btree_key_upto_commit(trans, iter, BTREE_ID_extents,
1167 bkey_start_pos(&orig->k), orig->k.p,
1168 BTREE_ITER_intent, k,
1169 NULL, NULL, BCH_TRANS_COMMIT_no_enospc, ({
1170 bch2_nocow_write_convert_one_unwritten(trans, &iter, orig, k, op->new_i_size);
1173 if (ret && !bch2_err_matches(ret, EROFS)) {
1174 struct bkey_i *insert = bch2_keylist_front(&op->insert_keys);
1176 bch_err_inum_offset_ratelimited(c,
1177 insert->k.p.inode, insert->k.p.offset << 9,
1178 "%s write error while doing btree update: %s",
1179 op->flags & BCH_WRITE_MOVE ? "move" : "user",
1189 bch2_trans_put(trans);
1192 static void __bch2_nocow_write_done(struct bch_write_op *op)
1194 if (unlikely(op->flags & BCH_WRITE_IO_ERROR)) {
1196 } else if (unlikely(op->flags & BCH_WRITE_CONVERT_UNWRITTEN))
1197 bch2_nocow_write_convert_unwritten(op);
1200 static CLOSURE_CALLBACK(bch2_nocow_write_done)
1202 closure_type(op, struct bch_write_op, cl);
1204 __bch2_nocow_write_done(op);
1205 bch2_write_done(cl);
1208 struct bucket_to_lock {
1211 struct nocow_lock_bucket *l;
1214 static void bch2_nocow_write(struct bch_write_op *op)
1216 struct bch_fs *c = op->c;
1217 struct btree_trans *trans;
1218 struct btree_iter iter;
1220 DARRAY_PREALLOCATED(struct bucket_to_lock, 3) buckets;
1222 struct bucket_to_lock *stale_at;
1225 if (op->flags & BCH_WRITE_MOVE)
1228 darray_init(&buckets);
1229 trans = bch2_trans_get(c);
1231 bch2_trans_begin(trans);
1233 ret = bch2_subvolume_get_snapshot(trans, op->subvol, &snapshot);
1237 bch2_trans_iter_init(trans, &iter, BTREE_ID_extents,
1238 SPOS(op->pos.inode, op->pos.offset, snapshot),
1241 struct bio *bio = &op->wbio.bio;
1245 ret = bch2_trans_relock(trans);
1249 k = bch2_btree_iter_peek_slot(&iter);
1254 /* fall back to normal cow write path? */
1255 if (unlikely(k.k->p.snapshot != snapshot ||
1256 !bch2_extent_is_writeable(op, k)))
1259 if (bch2_keylist_realloc(&op->insert_keys,
1261 ARRAY_SIZE(op->inline_keys),
1265 /* Get iorefs before dropping btree locks: */
1266 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
1267 bkey_for_each_ptr(ptrs, ptr) {
1268 struct bch_dev *ca = bch2_dev_get_ioref(c, ptr->dev, WRITE);
1272 struct bpos b = PTR_BUCKET_POS(ca, ptr);
1273 struct nocow_lock_bucket *l =
1274 bucket_nocow_lock(&c->nocow_locks, bucket_to_u64(b));
1277 /* XXX allocating memory with btree locks held - rare */
1278 darray_push_gfp(&buckets, ((struct bucket_to_lock) {
1279 .b = b, .gen = ptr->gen, .l = l,
1280 }), GFP_KERNEL|__GFP_NOFAIL);
1283 op->flags |= BCH_WRITE_CONVERT_UNWRITTEN;
1286 /* Unlock before taking nocow locks, doing IO: */
1287 bkey_reassemble(op->insert_keys.top, k);
1288 bch2_trans_unlock(trans);
1290 bch2_cut_front(op->pos, op->insert_keys.top);
1291 if (op->flags & BCH_WRITE_CONVERT_UNWRITTEN)
1292 bch2_cut_back(POS(op->pos.inode, op->pos.offset + bio_sectors(bio)), op->insert_keys.top);
1294 darray_for_each(buckets, i) {
1295 struct bch_dev *ca = bch2_dev_have_ref(c, i->b.inode);
1297 __bch2_bucket_nocow_lock(&c->nocow_locks, i->l,
1298 bucket_to_u64(i->b),
1299 BUCKET_NOCOW_LOCK_UPDATE);
1302 bool stale = gen_after(*bucket_gen(ca, i->b.offset), i->gen);
1305 if (unlikely(stale)) {
1307 goto err_bucket_stale;
1311 bio = &op->wbio.bio;
1312 if (k.k->p.offset < op->pos.offset + bio_sectors(bio)) {
1313 bio = bio_split(bio, k.k->p.offset - op->pos.offset,
1314 GFP_KERNEL, &c->bio_write);
1315 wbio_init(bio)->put_bio = true;
1316 bio->bi_opf = op->wbio.bio.bi_opf;
1318 op->flags |= BCH_WRITE_DONE;
1321 op->pos.offset += bio_sectors(bio);
1322 op->written += bio_sectors(bio);
1324 bio->bi_end_io = bch2_write_endio;
1325 bio->bi_private = &op->cl;
1326 bio->bi_opf |= REQ_OP_WRITE;
1327 closure_get(&op->cl);
1328 bch2_submit_wbio_replicas(to_wbio(bio), c, BCH_DATA_user,
1329 op->insert_keys.top, true);
1331 bch2_keylist_push(&op->insert_keys);
1332 if (op->flags & BCH_WRITE_DONE)
1334 bch2_btree_iter_advance(&iter);
1337 bch2_trans_iter_exit(trans, &iter);
1339 if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
1343 bch_err_inum_offset_ratelimited(c,
1344 op->pos.inode, op->pos.offset << 9,
1345 "%s: btree lookup error %s", __func__, bch2_err_str(ret));
1347 op->flags |= BCH_WRITE_DONE;
1350 bch2_trans_put(trans);
1351 darray_exit(&buckets);
1353 /* fallback to cow write path? */
1354 if (!(op->flags & BCH_WRITE_DONE)) {
1355 closure_sync(&op->cl);
1356 __bch2_nocow_write_done(op);
1357 op->insert_keys.top = op->insert_keys.keys;
1358 } else if (op->flags & BCH_WRITE_SYNC) {
1359 closure_sync(&op->cl);
1360 bch2_nocow_write_done(&op->cl.work);
1364 * needs to run out of process context because ei_quota_lock is
1367 continue_at(&op->cl, bch2_nocow_write_done, index_update_wq(op));
1371 darray_for_each(buckets, i)
1372 percpu_ref_put(&bch2_dev_have_ref(c, i->b.inode)->io_ref);
1374 /* Fall back to COW path: */
1377 darray_for_each(buckets, i) {
1378 bch2_bucket_nocow_unlock(&c->nocow_locks, i->b, BUCKET_NOCOW_LOCK_UPDATE);
1383 /* We can retry this: */
1384 ret = -BCH_ERR_transaction_restart;
1388 static void __bch2_write(struct bch_write_op *op)
1390 struct bch_fs *c = op->c;
1391 struct write_point *wp = NULL;
1392 struct bio *bio = NULL;
1393 unsigned nofs_flags;
1396 nofs_flags = memalloc_nofs_save();
1398 if (unlikely(op->opts.nocow && c->opts.nocow_enabled)) {
1399 bch2_nocow_write(op);
1400 if (op->flags & BCH_WRITE_DONE)
1401 goto out_nofs_restore;
1404 memset(&op->failed, 0, sizeof(op->failed));
1407 struct bkey_i *key_to_write;
1408 unsigned key_to_write_offset = op->insert_keys.top_p -
1409 op->insert_keys.keys_p;
1411 /* +1 for possible cache device: */
1412 if (op->open_buckets.nr + op->nr_replicas + 1 >
1413 ARRAY_SIZE(op->open_buckets.v))
1416 if (bch2_keylist_realloc(&op->insert_keys,
1418 ARRAY_SIZE(op->inline_keys),
1419 BKEY_EXTENT_U64s_MAX))
1423 * The copygc thread is now global, which means it's no longer
1424 * freeing up space on specific disks, which means that
1425 * allocations for specific disks may hang arbitrarily long:
1427 ret = bch2_trans_do(c, NULL, NULL, 0,
1428 bch2_alloc_sectors_start_trans(trans,
1430 op->opts.erasure_code && !(op->flags & BCH_WRITE_CACHED),
1434 op->nr_replicas_required,
1437 (op->flags & (BCH_WRITE_ALLOC_NOWAIT|
1438 BCH_WRITE_ONLY_SPECIFIED_DEVS))
1439 ? NULL : &op->cl, &wp));
1440 if (unlikely(ret)) {
1441 if (bch2_err_matches(ret, BCH_ERR_operation_blocked))
1449 bch2_open_bucket_get(c, wp, &op->open_buckets);
1450 ret = bch2_write_extent(op, wp, &bio);
1452 bch2_alloc_sectors_done_inlined(c, wp);
1455 op->flags |= BCH_WRITE_DONE;
1458 if (!(op->flags & BCH_WRITE_ALLOC_NOWAIT))
1459 bch_err_inum_offset_ratelimited(c,
1461 op->pos.offset << 9,
1462 "%s(): %s error: %s", __func__,
1463 op->flags & BCH_WRITE_MOVE ? "move" : "user",
1470 bio->bi_end_io = bch2_write_endio;
1471 bio->bi_private = &op->cl;
1472 bio->bi_opf |= REQ_OP_WRITE;
1474 closure_get(bio->bi_private);
1476 key_to_write = (void *) (op->insert_keys.keys_p +
1477 key_to_write_offset);
1479 bch2_submit_wbio_replicas(to_wbio(bio), c, BCH_DATA_user,
1480 key_to_write, false);
1486 * If we're running asynchronously, wne may still want to block
1487 * synchronously here if we weren't able to submit all of the IO at
1488 * once, as that signals backpressure to the caller.
1490 if ((op->flags & BCH_WRITE_SYNC) ||
1491 (!(op->flags & BCH_WRITE_DONE) &&
1492 !(op->flags & BCH_WRITE_IN_WORKER))) {
1493 if (closure_sync_timeout(&op->cl, HZ * 10)) {
1494 bch2_print_allocator_stuck(c);
1495 closure_sync(&op->cl);
1498 __bch2_write_index(op);
1500 if (!(op->flags & BCH_WRITE_DONE))
1502 bch2_write_done(&op->cl);
1504 bch2_write_queue(op, wp);
1505 continue_at(&op->cl, bch2_write_index, NULL);
1508 memalloc_nofs_restore(nofs_flags);
1511 static void bch2_write_data_inline(struct bch_write_op *op, unsigned data_len)
1513 struct bio *bio = &op->wbio.bio;
1514 struct bvec_iter iter;
1515 struct bkey_i_inline_data *id;
1519 memset(&op->failed, 0, sizeof(op->failed));
1521 op->flags |= BCH_WRITE_WROTE_DATA_INLINE;
1522 op->flags |= BCH_WRITE_DONE;
1524 bch2_check_set_feature(op->c, BCH_FEATURE_inline_data);
1526 ret = bch2_keylist_realloc(&op->insert_keys, op->inline_keys,
1527 ARRAY_SIZE(op->inline_keys),
1528 BKEY_U64s + DIV_ROUND_UP(data_len, 8));
1534 sectors = bio_sectors(bio);
1535 op->pos.offset += sectors;
1537 id = bkey_inline_data_init(op->insert_keys.top);
1539 id->k.version = op->version;
1540 id->k.size = sectors;
1542 iter = bio->bi_iter;
1543 iter.bi_size = data_len;
1544 memcpy_from_bio(id->v.data, bio, iter);
1546 while (data_len & 7)
1547 id->v.data[data_len++] = '\0';
1548 set_bkey_val_bytes(&id->k, data_len);
1549 bch2_keylist_push(&op->insert_keys);
1551 __bch2_write_index(op);
1553 bch2_write_done(&op->cl);
1557 * bch2_write() - handle a write to a cache device or flash only volume
1558 * @cl: &bch_write_op->cl
1560 * This is the starting point for any data to end up in a cache device; it could
1561 * be from a normal write, or a writeback write, or a write to a flash only
1562 * volume - it's also used by the moving garbage collector to compact data in
1563 * mostly empty buckets.
1565 * It first writes the data to the cache, creating a list of keys to be inserted
1566 * (if the data won't fit in a single open bucket, there will be multiple keys);
1567 * after the data is written it calls bch_journal, and after the keys have been
1568 * added to the next journal write they're inserted into the btree.
1570 * If op->discard is true, instead of inserting the data it invalidates the
1571 * region of the cache represented by op->bio and op->inode.
1573 CLOSURE_CALLBACK(bch2_write)
1575 closure_type(op, struct bch_write_op, cl);
1576 struct bio *bio = &op->wbio.bio;
1577 struct bch_fs *c = op->c;
1580 EBUG_ON(op->cl.parent);
1581 BUG_ON(!op->nr_replicas);
1582 BUG_ON(!op->write_point.v);
1583 BUG_ON(bkey_eq(op->pos, POS_MAX));
1585 op->nr_replicas_required = min_t(unsigned, op->nr_replicas_required, op->nr_replicas);
1586 op->start_time = local_clock();
1587 bch2_keylist_init(&op->insert_keys, op->inline_keys);
1588 wbio_init(bio)->put_bio = false;
1590 if (bio->bi_iter.bi_size & (c->opts.block_size - 1)) {
1591 bch_err_inum_offset_ratelimited(c,
1593 op->pos.offset << 9,
1594 "%s write error: misaligned write",
1595 op->flags & BCH_WRITE_MOVE ? "move" : "user");
1600 if (c->opts.nochanges) {
1601 op->error = -BCH_ERR_erofs_no_writes;
1605 if (!(op->flags & BCH_WRITE_MOVE) &&
1606 !bch2_write_ref_tryget(c, BCH_WRITE_REF_write)) {
1607 op->error = -BCH_ERR_erofs_no_writes;
1611 this_cpu_add(c->counters[BCH_COUNTER_io_write], bio_sectors(bio));
1612 bch2_increment_clock(c, bio_sectors(bio), WRITE);
1614 data_len = min_t(u64, bio->bi_iter.bi_size,
1615 op->new_i_size - (op->pos.offset << 9));
1617 if (c->opts.inline_data &&
1618 data_len <= min(block_bytes(c) / 2, 1024U)) {
1619 bch2_write_data_inline(op, data_len);
1626 bch2_disk_reservation_put(c, &op->res);
1628 closure_debug_destroy(&op->cl);
1633 static const char * const bch2_write_flags[] = {
1640 void bch2_write_op_to_text(struct printbuf *out, struct bch_write_op *op)
1642 prt_str(out, "pos: ");
1643 bch2_bpos_to_text(out, op->pos);
1645 printbuf_indent_add(out, 2);
1647 prt_str(out, "started: ");
1648 bch2_pr_time_units(out, local_clock() - op->start_time);
1651 prt_str(out, "flags: ");
1652 prt_bitflags(out, bch2_write_flags, op->flags);
1655 prt_printf(out, "ref: %u\n", closure_nr_remaining(&op->cl));
1657 printbuf_indent_sub(out, 2);
1660 void bch2_fs_io_write_exit(struct bch_fs *c)
1662 mempool_exit(&c->bio_bounce_pages);
1663 bioset_exit(&c->replica_set);
1664 bioset_exit(&c->bio_write);
1667 int bch2_fs_io_write_init(struct bch_fs *c)
1669 if (bioset_init(&c->bio_write, 1, offsetof(struct bch_write_bio, bio), BIOSET_NEED_BVECS) ||
1670 bioset_init(&c->replica_set, 4, offsetof(struct bch_write_bio, bio), 0))
1671 return -BCH_ERR_ENOMEM_bio_write_init;
1673 if (mempool_init_page_pool(&c->bio_bounce_pages,
1675 c->opts.btree_node_size,
1676 c->opts.encoded_extent_max) /
1678 return -BCH_ERR_ENOMEM_bio_bounce_pages_init;