aboutsummaryrefslogtreecommitdiffstats
path: root/mm/filemap.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/filemap.c')
-rw-r--r--mm/filemap.c66
1 files changed, 29 insertions, 37 deletions
diff --git a/mm/filemap.c b/mm/filemap.c
index d6e67be1802e..6f1be573a5e6 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -519,7 +519,7 @@ EXPORT_SYMBOL(filemap_write_and_wait);
519 * 519 *
520 * Write out and wait upon file offsets lstart->lend, inclusive. 520 * Write out and wait upon file offsets lstart->lend, inclusive.
521 * 521 *
522 * Note that `lend' is inclusive (describes the last byte to be written) so 522 * Note that @lend is inclusive (describes the last byte to be written) so
523 * that this function can be used to write to the very end-of-file (end = -1). 523 * that this function can be used to write to the very end-of-file (end = -1).
524 */ 524 */
525int filemap_write_and_wait_range(struct address_space *mapping, 525int filemap_write_and_wait_range(struct address_space *mapping,
@@ -1277,12 +1277,14 @@ EXPORT_SYMBOL(find_lock_entry);
1277 * 1277 *
1278 * PCG flags modify how the page is returned. 1278 * PCG flags modify how the page is returned.
1279 * 1279 *
1280 * FGP_ACCESSED: the page will be marked accessed 1280 * @fgp_flags can be:
1281 * FGP_LOCK: Page is return locked 1281 *
1282 * FGP_CREAT: If page is not present then a new page is allocated using 1282 * - FGP_ACCESSED: the page will be marked accessed
1283 * @gfp_mask and added to the page cache and the VM's LRU 1283 * - FGP_LOCK: Page is return locked
1284 * list. The page is returned locked and with an increased 1284 * - FGP_CREAT: If page is not present then a new page is allocated using
1285 * refcount. Otherwise, %NULL is returned. 1285 * @gfp_mask and added to the page cache and the VM's LRU
1286 * list. The page is returned locked and with an increased
1287 * refcount. Otherwise, NULL is returned.
1286 * 1288 *
1287 * If FGP_LOCK or FGP_CREAT are specified then the function may sleep even 1289 * If FGP_LOCK or FGP_CREAT are specified then the function may sleep even
1288 * if the GFP flags specified for FGP_CREAT are atomic. 1290 * if the GFP flags specified for FGP_CREAT are atomic.
@@ -2202,12 +2204,12 @@ int filemap_fault(struct vm_fault *vmf)
2202 struct file_ra_state *ra = &file->f_ra; 2204 struct file_ra_state *ra = &file->f_ra;
2203 struct inode *inode = mapping->host; 2205 struct inode *inode = mapping->host;
2204 pgoff_t offset = vmf->pgoff; 2206 pgoff_t offset = vmf->pgoff;
2207 pgoff_t max_off;
2205 struct page *page; 2208 struct page *page;
2206 loff_t size;
2207 int ret = 0; 2209 int ret = 0;
2208 2210
2209 size = round_up(i_size_read(inode), PAGE_SIZE); 2211 max_off = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE);
2210 if (offset >= size >> PAGE_SHIFT) 2212 if (unlikely(offset >= max_off))
2211 return VM_FAULT_SIGBUS; 2213 return VM_FAULT_SIGBUS;
2212 2214
2213 /* 2215 /*
@@ -2256,8 +2258,8 @@ retry_find:
2256 * Found the page and have a reference on it. 2258 * Found the page and have a reference on it.
2257 * We must recheck i_size under page lock. 2259 * We must recheck i_size under page lock.
2258 */ 2260 */
2259 size = round_up(i_size_read(inode), PAGE_SIZE); 2261 max_off = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE);
2260 if (unlikely(offset >= size >> PAGE_SHIFT)) { 2262 if (unlikely(offset >= max_off)) {
2261 unlock_page(page); 2263 unlock_page(page);
2262 put_page(page); 2264 put_page(page);
2263 return VM_FAULT_SIGBUS; 2265 return VM_FAULT_SIGBUS;
@@ -2323,7 +2325,7 @@ void filemap_map_pages(struct vm_fault *vmf,
2323 struct file *file = vmf->vma->vm_file; 2325 struct file *file = vmf->vma->vm_file;
2324 struct address_space *mapping = file->f_mapping; 2326 struct address_space *mapping = file->f_mapping;
2325 pgoff_t last_pgoff = start_pgoff; 2327 pgoff_t last_pgoff = start_pgoff;
2326 loff_t size; 2328 unsigned long max_idx;
2327 struct page *head, *page; 2329 struct page *head, *page;
2328 2330
2329 rcu_read_lock(); 2331 rcu_read_lock();
@@ -2369,8 +2371,8 @@ repeat:
2369 if (page->mapping != mapping || !PageUptodate(page)) 2371 if (page->mapping != mapping || !PageUptodate(page))
2370 goto unlock; 2372 goto unlock;
2371 2373
2372 size = round_up(i_size_read(mapping->host), PAGE_SIZE); 2374 max_idx = DIV_ROUND_UP(i_size_read(mapping->host), PAGE_SIZE);
2373 if (page->index >= size >> PAGE_SHIFT) 2375 if (page->index >= max_idx)
2374 goto unlock; 2376 goto unlock;
2375 2377
2376 if (file->f_ra.mmap_miss > 0) 2378 if (file->f_ra.mmap_miss > 0)
@@ -2718,18 +2720,16 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from)
2718 * about to write. We do this *before* the write so that we can return 2720 * about to write. We do this *before* the write so that we can return
2719 * without clobbering -EIOCBQUEUED from ->direct_IO(). 2721 * without clobbering -EIOCBQUEUED from ->direct_IO().
2720 */ 2722 */
2721 if (mapping->nrpages) { 2723 written = invalidate_inode_pages2_range(mapping,
2722 written = invalidate_inode_pages2_range(mapping,
2723 pos >> PAGE_SHIFT, end); 2724 pos >> PAGE_SHIFT, end);
2724 /* 2725 /*
2725 * If a page can not be invalidated, return 0 to fall back 2726 * If a page can not be invalidated, return 0 to fall back
2726 * to buffered write. 2727 * to buffered write.
2727 */ 2728 */
2728 if (written) { 2729 if (written) {
2729 if (written == -EBUSY) 2730 if (written == -EBUSY)
2730 return 0; 2731 return 0;
2731 goto out; 2732 goto out;
2732 }
2733 } 2733 }
2734 2734
2735 written = mapping->a_ops->direct_IO(iocb, from); 2735 written = mapping->a_ops->direct_IO(iocb, from);
@@ -2742,10 +2742,8 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from)
2742 * so we don't support it 100%. If this invalidation 2742 * so we don't support it 100%. If this invalidation
2743 * fails, tough, the write still worked... 2743 * fails, tough, the write still worked...
2744 */ 2744 */
2745 if (mapping->nrpages) { 2745 invalidate_inode_pages2_range(mapping,
2746 invalidate_inode_pages2_range(mapping, 2746 pos >> PAGE_SHIFT, end);
2747 pos >> PAGE_SHIFT, end);
2748 }
2749 2747
2750 if (written > 0) { 2748 if (written > 0) {
2751 pos += written; 2749 pos += written;
@@ -2793,12 +2791,6 @@ ssize_t generic_perform_write(struct file *file,
2793 ssize_t written = 0; 2791 ssize_t written = 0;
2794 unsigned int flags = 0; 2792 unsigned int flags = 0;
2795 2793
2796 /*
2797 * Copies from kernel address space cannot fail (NFSD is a big user).
2798 */
2799 if (!iter_is_iovec(i))
2800 flags |= AOP_FLAG_UNINTERRUPTIBLE;
2801
2802 do { 2794 do {
2803 struct page *page; 2795 struct page *page;
2804 unsigned long offset; /* Offset into pagecache page */ 2796 unsigned long offset; /* Offset into pagecache page */
@@ -3000,7 +2992,7 @@ EXPORT_SYMBOL(generic_file_write_iter);
3000 * @gfp_mask: memory allocation flags (and I/O mode) 2992 * @gfp_mask: memory allocation flags (and I/O mode)
3001 * 2993 *
3002 * The address_space is to try to release any data against the page 2994 * The address_space is to try to release any data against the page
3003 * (presumably at page->private). If the release was successful, return `1'. 2995 * (presumably at page->private). If the release was successful, return '1'.
3004 * Otherwise return zero. 2996 * Otherwise return zero.
3005 * 2997 *
3006 * This may also be called if PG_fscache is set on a page, indicating that the 2998 * This may also be called if PG_fscache is set on a page, indicating that the