Commit e8306e3b authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Wrap write path in memalloc_nofs_save()

This fixes a lockdep splat where we're allocating memory with vmalloc in
the compression bounce path, which doesn't always obey GFP_NOFS.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent f621e152
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "super-io.h" #include "super-io.h"
#include <linux/lz4.h> #include <linux/lz4.h>
#include <linux/sched/mm.h>
#include <linux/zlib.h> #include <linux/zlib.h>
#include <linux/zstd.h> #include <linux/zstd.h>
...@@ -64,7 +63,7 @@ static struct bbuf __bio_map_or_bounce(struct bch_fs *c, struct bio *bio, ...@@ -64,7 +63,7 @@ static struct bbuf __bio_map_or_bounce(struct bch_fs *c, struct bio *bio,
struct bbuf ret; struct bbuf ret;
struct bio_vec bv; struct bio_vec bv;
struct bvec_iter iter; struct bvec_iter iter;
unsigned nr_pages = 0, flags; unsigned nr_pages = 0;
struct page *stack_pages[16]; struct page *stack_pages[16];
struct page **pages = NULL; struct page **pages = NULL;
void *data; void *data;
...@@ -104,10 +103,7 @@ static struct bbuf __bio_map_or_bounce(struct bch_fs *c, struct bio *bio, ...@@ -104,10 +103,7 @@ static struct bbuf __bio_map_or_bounce(struct bch_fs *c, struct bio *bio,
__bio_for_each_segment(bv, bio, iter, start) __bio_for_each_segment(bv, bio, iter, start)
pages[nr_pages++] = bv.bv_page; pages[nr_pages++] = bv.bv_page;
flags = memalloc_nofs_save();
data = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL); data = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL);
memalloc_nofs_restore(flags);
if (pages != stack_pages) if (pages != stack_pages)
kfree(pages); kfree(pages);
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include <linux/random.h> #include <linux/random.h>
#include <linux/sched/mm.h>
#ifndef CONFIG_BCACHEFS_NO_LATENCY_ACCT #ifndef CONFIG_BCACHEFS_NO_LATENCY_ACCT
...@@ -1052,7 +1053,10 @@ static void __bch2_write(struct closure *cl) ...@@ -1052,7 +1053,10 @@ static void __bch2_write(struct closure *cl)
struct write_point *wp; struct write_point *wp;
struct bio *bio; struct bio *bio;
bool skip_put = true; bool skip_put = true;
unsigned nofs_flags;
int ret; int ret;
nofs_flags = memalloc_nofs_save();
again: again:
memset(&op->failed, 0, sizeof(op->failed)); memset(&op->failed, 0, sizeof(op->failed));
...@@ -1134,13 +1138,15 @@ static void __bch2_write(struct closure *cl) ...@@ -1134,13 +1138,15 @@ static void __bch2_write(struct closure *cl)
if (!skip_put) if (!skip_put)
continue_at(cl, bch2_write_index, index_update_wq(op)); continue_at(cl, bch2_write_index, index_update_wq(op));
out:
memalloc_nofs_restore(nofs_flags);
return; return;
err: err:
op->error = ret; op->error = ret;
op->flags |= BCH_WRITE_DONE; op->flags |= BCH_WRITE_DONE;
continue_at(cl, bch2_write_index, index_update_wq(op)); continue_at(cl, bch2_write_index, index_update_wq(op));
return; goto out;
flush_io: flush_io:
/* /*
* If the write can't all be submitted at once, we generally want to * If the write can't all be submitted at once, we generally want to
...@@ -1151,7 +1157,7 @@ static void __bch2_write(struct closure *cl) ...@@ -1151,7 +1157,7 @@ static void __bch2_write(struct closure *cl)
*/ */
if (current->flags & PF_WQ_WORKER) { if (current->flags & PF_WQ_WORKER) {
continue_at(cl, bch2_write_index, index_update_wq(op)); continue_at(cl, bch2_write_index, index_update_wq(op));
return; goto out;
} }
closure_sync(cl); closure_sync(cl);
...@@ -1162,7 +1168,7 @@ static void __bch2_write(struct closure *cl) ...@@ -1162,7 +1168,7 @@ static void __bch2_write(struct closure *cl)
if (op->error) { if (op->error) {
op->flags |= BCH_WRITE_DONE; op->flags |= BCH_WRITE_DONE;
continue_at_nobarrier(cl, bch2_write_done, NULL); continue_at_nobarrier(cl, bch2_write_done, NULL);
return; goto out;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment