| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Ram backed block device driver. |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 153 | 154 | pos++; |
|---|
| 154 | 155 | |
|---|
| 155 | 156 | /* |
|---|
| 157 | + * It takes 3.4 seconds to remove 80GiB ramdisk. |
|---|
| 158 | + * So, we need cond_resched to avoid stalling the CPU. |
|---|
| 159 | + */ |
|---|
| 160 | + cond_resched(); |
|---|
| 161 | + |
|---|
| 162 | + /* |
|---|
| 156 | 163 | * This assumes radix_tree_gang_lookup always returns as |
|---|
| 157 | 164 | * many pages as possible. If the radix-tree code changes, |
|---|
| 158 | 165 | * so will this have to. |
|---|
| .. | .. |
|---|
| 275 | 282 | return err; |
|---|
| 276 | 283 | } |
|---|
| 277 | 284 | |
|---|
| 278 | | -static blk_qc_t brd_make_request(struct request_queue *q, struct bio *bio) |
|---|
| 285 | +static blk_qc_t brd_submit_bio(struct bio *bio) |
|---|
| 279 | 286 | { |
|---|
| 280 | 287 | struct brd_device *brd = bio->bi_disk->private_data; |
|---|
| 281 | 288 | struct bio_vec bvec; |
|---|
| .. | .. |
|---|
| 289 | 296 | bio_for_each_segment(bvec, bio, iter) { |
|---|
| 290 | 297 | unsigned int len = bvec.bv_len; |
|---|
| 291 | 298 | int err; |
|---|
| 299 | + |
|---|
| 300 | + /* Don't support un-aligned buffer */ |
|---|
| 301 | + WARN_ON_ONCE((bvec.bv_offset & (SECTOR_SIZE - 1)) || |
|---|
| 302 | + (len & (SECTOR_SIZE - 1))); |
|---|
| 292 | 303 | |
|---|
| 293 | 304 | err = brd_do_bvec(brd, bvec.bv_page, len, bvec.bv_offset, |
|---|
| 294 | 305 | bio_op(bio), sector); |
|---|
| .. | .. |
|---|
| 319 | 330 | |
|---|
| 320 | 331 | static const struct block_device_operations brd_fops = { |
|---|
| 321 | 332 | .owner = THIS_MODULE, |
|---|
| 333 | + .submit_bio = brd_submit_bio, |
|---|
| 322 | 334 | .rw_page = brd_rw_page, |
|---|
| 323 | 335 | }; |
|---|
| 324 | 336 | |
|---|
| .. | .. |
|---|
| 370 | 382 | spin_lock_init(&brd->brd_lock); |
|---|
| 371 | 383 | INIT_RADIX_TREE(&brd->brd_pages, GFP_ATOMIC); |
|---|
| 372 | 384 | |
|---|
| 373 | | - brd->brd_queue = blk_alloc_queue(GFP_KERNEL); |
|---|
| 385 | + brd->brd_queue = blk_alloc_queue(NUMA_NO_NODE); |
|---|
| 374 | 386 | if (!brd->brd_queue) |
|---|
| 375 | 387 | goto out_free_dev; |
|---|
| 376 | | - |
|---|
| 377 | | - blk_queue_make_request(brd->brd_queue, brd_make_request); |
|---|
| 378 | | - blk_queue_max_hw_sectors(brd->brd_queue, 1024); |
|---|
| 379 | 388 | |
|---|
| 380 | 389 | /* This is so fdisk will align partitions on 4k, because of |
|---|
| 381 | 390 | * direct_access API needing 4k alignment, returning a PFN |
|---|
| .. | .. |
|---|
| 394 | 403 | disk->flags = GENHD_FL_EXT_DEVT; |
|---|
| 395 | 404 | sprintf(disk->disk_name, "ram%d", i); |
|---|
| 396 | 405 | set_capacity(disk, rd_size * 2); |
|---|
| 397 | | - brd->brd_queue->backing_dev_info->capabilities |= BDI_CAP_SYNCHRONOUS_IO; |
|---|
| 398 | 406 | |
|---|
| 399 | 407 | /* Tell the block layer that this is not a rotational device */ |
|---|
| 400 | 408 | blk_queue_flag_set(QUEUE_FLAG_NONROT, brd->brd_queue); |
|---|