@@ -538,6 +538,14 @@ static int cache_lookup_fn(struct btree_op *op, struct btree *b, struct bkey *k)
if (!KEY_SIZE(k))
return MAP_CONTINUE;
+ n = bio_next_split(bio, min_t(uint64_t, INT_MAX,
+ KEY_OFFSET(k) - bio->bi_iter.bi_sector),
+ !current->bio_list || bio_list_empty(current->bio_list)
+ ? GFP_NOIO : GFP_NOWAIT,
+ &s->d->bio_split);
+ if (!n)
+ return -EAGAIN;
+
/* XXX: figure out best pointer - for multiple cache devices */
ptr = 0;
@@ -546,10 +554,6 @@ static int cache_lookup_fn(struct btree_op *op, struct btree *b, struct bkey *k)
if (KEY_DIRTY(k))
s->read_dirty_data = true;
- n = bio_next_split(bio, min_t(uint64_t, INT_MAX,
- KEY_OFFSET(k) - bio->bi_iter.bi_sector),
- GFP_NOIO, &s->d->bio_split);
-
bio_key = &container_of(n, struct bbio, bio)->key;
bch_bkey_copy_single_ptr(bio_key, k, ptr);