Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

filemap: introduce filemap_invalidate_pages

kiocb_invalidate_pages() is useful for the write path, however not
everything is backed by kiocb and we want to reuse the function for bio
based discard implementation. Extract and and reuse a new helper called
filemap_invalidate_pages(), which takes a argument indicating whether it
should be non-blocking and might return -EAGAIN.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/f81374b52c92d0dce0f01a279d1eed42b54056aa.1726072086.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Pavel Begunkov and committed by
Jens Axboe
a12c883a a6ccb48e

+14 -5
+2
include/linux/pagemap.h
··· 32 32 pgoff_t start, pgoff_t end); 33 33 int kiocb_invalidate_pages(struct kiocb *iocb, size_t count); 34 34 void kiocb_invalidate_post_direct_write(struct kiocb *iocb, size_t count); 35 + int filemap_invalidate_pages(struct address_space *mapping, 36 + loff_t pos, loff_t end, bool nowait); 35 37 36 38 int write_inode_now(struct inode *, int sync); 37 39 int filemap_fdatawrite(struct address_space *);
+12 -5
mm/filemap.c
··· 2712 2712 } 2713 2713 EXPORT_SYMBOL_GPL(kiocb_write_and_wait); 2714 2714 2715 - int kiocb_invalidate_pages(struct kiocb *iocb, size_t count) 2715 + int filemap_invalidate_pages(struct address_space *mapping, 2716 + loff_t pos, loff_t end, bool nowait) 2716 2717 { 2717 - struct address_space *mapping = iocb->ki_filp->f_mapping; 2718 - loff_t pos = iocb->ki_pos; 2719 - loff_t end = pos + count - 1; 2720 2718 int ret; 2721 2719 2722 - if (iocb->ki_flags & IOCB_NOWAIT) { 2720 + if (nowait) { 2723 2721 /* we could block if there are any pages in the range */ 2724 2722 if (filemap_range_has_page(mapping, pos, end)) 2725 2723 return -EAGAIN; ··· 2735 2737 */ 2736 2738 return invalidate_inode_pages2_range(mapping, pos >> PAGE_SHIFT, 2737 2739 end >> PAGE_SHIFT); 2740 + } 2741 + 2742 + int kiocb_invalidate_pages(struct kiocb *iocb, size_t count) 2743 + { 2744 + struct address_space *mapping = iocb->ki_filp->f_mapping; 2745 + 2746 + return filemap_invalidate_pages(mapping, iocb->ki_pos, 2747 + iocb->ki_pos + count - 1, 2748 + iocb->ki_flags & IOCB_NOWAIT); 2738 2749 } 2739 2750 EXPORT_SYMBOL_GPL(kiocb_invalidate_pages); 2740 2751