bcachefs: allocate sb_read_scratch with __get_free_page
authorKent Overstreet <kent.overstreet@gmail.com>
Sat, 6 Apr 2019 18:32:06 +0000 (14:32 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:20 +0000 (17:08 -0400)
kmalloc allocations aren't guranteed alignment for io

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/super-io.c
fs/bcachefs/super.c

index 7aaa8b785d5716dc489b8369cb7dd25c6b44e0cc..0fe8ea22c6a1b442b268ffc0728ab419c3f15a1b 100644 (file)
@@ -652,7 +652,7 @@ static void read_back_super(struct bch_fs *c, struct bch_dev *ca)
 
        bio_reset(bio, ca->disk_sb.bdev, REQ_OP_READ|REQ_SYNC|REQ_META);
        bio->bi_iter.bi_sector  = le64_to_cpu(sb->layout.sb_offset[0]);
-       bio->bi_iter.bi_size    = 4096;
+       bio->bi_iter.bi_size    = PAGE_SIZE;
        bio->bi_end_io          = write_super_endio;
        bio->bi_private         = ca;
        bch2_bio_map(bio, ca->sb_read_scratch);
index 85a9400a47fc302d590db7d437bfb25c031f5e5c..18576538613c01c7a4bd8ce242347fa8cd3c8b6b 100644 (file)
@@ -919,7 +919,7 @@ static void bch2_dev_free(struct bch_dev *ca)
        free_percpu(ca->io_done);
        bioset_exit(&ca->replica_set);
        bch2_dev_buckets_free(ca);
-       kfree(ca->sb_read_scratch);
+       free_page((unsigned long) ca->sb_read_scratch);
 
        bch2_time_stats_exit(&ca->io_latency[WRITE]);
        bch2_time_stats_exit(&ca->io_latency[READ]);
@@ -1030,7 +1030,7 @@ static struct bch_dev *__bch2_dev_alloc(struct bch_fs *c,
                            0, GFP_KERNEL) ||
            percpu_ref_init(&ca->io_ref, bch2_dev_io_ref_complete,
                            PERCPU_REF_INIT_DEAD, GFP_KERNEL) ||
-           !(ca->sb_read_scratch = kmalloc(4096, GFP_KERNEL)) ||
+           !(ca->sb_read_scratch = (void *) __get_free_page(GFP_KERNEL)) ||
            bch2_dev_buckets_alloc(c, ca) ||
            bioset_init(&ca->replica_set, 4,
                        offsetof(struct bch_write_bio, bio), 0) ||