Lines Matching +full:non +full:- +full:contiguous
1 // SPDX-License-Identifier: GPL-2.0
30 #include <linux/backing-dev.h>
37 * The mpage code never puts partial pages into a BIO (except for end-of-file).
38 * If a page does not map to a contiguous run of blocks then it simply falls
49 int err = blk_status_to_errno(bio->bi_status); in mpage_read_end_io()
60 int err = blk_status_to_errno(bio->bi_status); in mpage_write_end_io()
64 mapping_set_error(fi.folio->mapping, err); in mpage_write_end_io()
73 bio->bi_end_io = mpage_read_end_io; in mpage_bio_submit_read()
81 bio->bi_end_io = mpage_write_end_io; in mpage_bio_submit_write()
100 struct inode *inode = folio->mapping->host; in map_buffer_to_folio()
110 if (inode->i_blkbits == PAGE_SHIFT && in map_buffer_to_folio()
121 page_bh->b_state = bh->b_state; in map_buffer_to_folio()
122 page_bh->b_bdev = bh->b_bdev; in map_buffer_to_folio()
123 page_bh->b_blocknr = bh->b_blocknr; in map_buffer_to_folio()
126 page_bh = page_bh->b_this_page; in map_buffer_to_folio()
145 * blocks are not contiguous on the disk.
153 struct folio *folio = args->folio; in do_mpage_readpage()
154 struct inode *inode = folio->mapping->host; in do_mpage_readpage()
155 const unsigned blkbits = inode->i_blkbits; in do_mpage_readpage()
158 struct buffer_head *map_bh = &args->map_bh; in do_mpage_readpage()
171 gfp_t gfp = mapping_gfp_constraint(folio->mapping, GFP_KERNEL); in do_mpage_readpage()
176 if (args->is_readahead) { in do_mpage_readpage()
184 block_in_file = (sector_t)folio->index << (PAGE_SHIFT - blkbits); in do_mpage_readpage()
185 last_block = block_in_file + args->nr_pages * blocks_per_page; in do_mpage_readpage()
186 last_block_in_file = (i_size_read(inode) + blocksize - 1) >> blkbits; in do_mpage_readpage()
194 nblocks = map_bh->b_size >> blkbits; in do_mpage_readpage()
196 block_in_file > args->first_logical_block && in do_mpage_readpage()
197 block_in_file < (args->first_logical_block + nblocks)) { in do_mpage_readpage()
198 unsigned map_offset = block_in_file - args->first_logical_block; in do_mpage_readpage()
199 unsigned last = nblocks - map_offset; in do_mpage_readpage()
201 first_block = map_bh->b_blocknr + map_offset; in do_mpage_readpage()
212 bdev = map_bh->b_bdev; in do_mpage_readpage()
218 map_bh->b_folio = folio; in do_mpage_readpage()
220 map_bh->b_state = 0; in do_mpage_readpage()
221 map_bh->b_size = 0; in do_mpage_readpage()
224 map_bh->b_size = (last_block-block_in_file) << blkbits; in do_mpage_readpage()
225 if (args->get_block(inode, block_in_file, map_bh, 0)) in do_mpage_readpage()
227 args->first_logical_block = block_in_file; in do_mpage_readpage()
251 goto confused; /* hole -> non-hole */ in do_mpage_readpage()
253 /* Contiguous blocks? */ in do_mpage_readpage()
255 first_block = map_bh->b_blocknr; in do_mpage_readpage()
256 else if (first_block + page_block != map_bh->b_blocknr) in do_mpage_readpage()
258 nblocks = map_bh->b_size >> blkbits; in do_mpage_readpage()
268 bdev = map_bh->b_bdev; in do_mpage_readpage()
285 if (args->bio && (args->last_block_in_bio != first_block - 1)) in do_mpage_readpage()
286 args->bio = mpage_bio_submit_read(args->bio); in do_mpage_readpage()
289 if (args->bio == NULL) { in do_mpage_readpage()
290 args->bio = bio_alloc(bdev, bio_max_segs(args->nr_pages), opf, in do_mpage_readpage()
292 if (args->bio == NULL) in do_mpage_readpage()
294 args->bio->bi_iter.bi_sector = first_block << (blkbits - 9); in do_mpage_readpage()
298 if (!bio_add_folio(args->bio, folio, length, 0)) { in do_mpage_readpage()
299 args->bio = mpage_bio_submit_read(args->bio); in do_mpage_readpage()
303 relative_block = block_in_file - args->first_logical_block; in do_mpage_readpage()
304 nblocks = map_bh->b_size >> blkbits; in do_mpage_readpage()
307 args->bio = mpage_bio_submit_read(args->bio); in do_mpage_readpage()
309 args->last_block_in_bio = first_block + blocks_per_page - 1; in do_mpage_readpage()
311 return args->bio; in do_mpage_readpage()
314 if (args->bio) in do_mpage_readpage()
315 args->bio = mpage_bio_submit_read(args->bio); in do_mpage_readpage()
317 block_read_full_folio(folio, args->get_block); in do_mpage_readpage()
324 * mpage_readahead - start reads against pages
333 * - encountering a page which has buffers
334 * - encountering a page which has a non-hole after a hole
335 * - encountering a page with non-contiguous blocks
337 * then this code just gives up and calls the buffer_head-based read function.
338 * It does handle a page which has holes at the end - that is a common case:
339 * the end-of-file on blocksize < PAGE_SIZE setups.
371 prefetchw(&folio->flags); in mpage_readahead()
403 * mapping. We only support pages which are fully mapped-and-dirty, with a
404 * special case for pages which are unmapped at the end: end-of-file.
408 * If all blocks are found to be contiguous then the page can go into the
412 * written, so it can intelligently allocate a suitably-sized BIO. For now,
413 * just allocate full-size (16-page) BIOs.
439 bh = bh->b_this_page; in clean_buffers()
455 struct bio *bio = mpd->bio; in __mpage_writepage()
456 struct address_space *mapping = folio->mapping; in __mpage_writepage()
457 struct inode *inode = mapping->host; in __mpage_writepage()
458 const unsigned blkbits = inode->i_blkbits; in __mpage_writepage()
485 * block_dirty_folio -> mmapped data in __mpage_writepage()
495 goto confused; /* hole -> non-hole */ in __mpage_writepage()
500 if (bh->b_blocknr != first_block + page_block) in __mpage_writepage()
503 first_block = bh->b_blocknr; in __mpage_writepage()
508 boundary_block = bh->b_blocknr; in __mpage_writepage()
509 boundary_bdev = bh->b_bdev; in __mpage_writepage()
511 bdev = bh->b_bdev; in __mpage_writepage()
512 } while ((bh = bh->b_this_page) != head); in __mpage_writepage()
530 block_in_file = (sector_t)folio->index << (PAGE_SHIFT - blkbits); in __mpage_writepage()
535 if (block_in_file >= (i_size + (1 << blkbits) - 1) >> blkbits) in __mpage_writepage()
537 last_block = (i_size - 1) >> blkbits; in __mpage_writepage()
543 if (mpd->get_block(inode, block_in_file, &map_bh, 1)) in __mpage_writepage()
584 length = i_size - folio_pos(folio); in __mpage_writepage()
591 if (bio && mpd->last_block_in_bio != first_block - 1) in __mpage_writepage()
599 bio->bi_iter.bi_sector = first_block << (blkbits - 9); in __mpage_writepage()
601 bio->bi_write_hint = inode->i_write_hint; in __mpage_writepage()
609 wbc_account_cgroup_owner(wbc, &folio->page, folio_size(folio)); in __mpage_writepage()
628 mpd->last_block_in_bio = first_block + blocks_per_page - 1; in __mpage_writepage()
639 ret = block_write_full_folio(folio, wbc, mpd->get_block); in __mpage_writepage()
642 mpd->bio = bio; in __mpage_writepage()
647 …* mpage_writepages - walk the list of dirty pages of the given address space & writepage() all of …
649 * @wbc: subtract the number of written pages from *@wbc->nr_to_write