2015-04-07 22:00:32 -06:00
|
|
|
/*
|
|
|
|
* linux/fs/ext4/readpage.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002, Linus Torvalds.
|
|
|
|
* Copyright (C) 2015, Google, Inc.
|
|
|
|
*
|
|
|
|
* This was originally taken from fs/mpage.c
|
|
|
|
*
|
|
|
|
* The intent is the ext4_mpage_readpages() function here is intended
|
|
|
|
* to replace mpage_readpages() in the general case, not just for
|
|
|
|
* encrypted files. It has some limitations (see below), where it
|
|
|
|
* will fall back to read_block_full_page(), but these limitations
|
|
|
|
* should only be hit when page_size != block_size.
|
|
|
|
*
|
|
|
|
* This will allow us to attach a callback function to support ext4
|
|
|
|
* encryption.
|
|
|
|
*
|
|
|
|
* If anything unusual happens, such as:
|
|
|
|
*
|
|
|
|
* - encountering a page which has buffers
|
|
|
|
* - encountering a page which has a non-hole after a hole
|
|
|
|
* - encountering a page with non-contiguous blocks
|
|
|
|
*
|
|
|
|
* then this code just gives up and calls the buffer_head-based read function.
|
|
|
|
* It does handle a page which has holes at the end - that is a common case:
|
2016-04-01 06:29:48 -06:00
|
|
|
* the end-of-file on blocksize < PAGE_SIZE setups.
|
2015-04-07 22:00:32 -06:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/export.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/kdev_t.h>
|
|
|
|
#include <linux/gfp.h>
|
|
|
|
#include <linux/bio.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/buffer_head.h>
|
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include <linux/highmem.h>
|
|
|
|
#include <linux/prefetch.h>
|
|
|
|
#include <linux/mpage.h>
|
|
|
|
#include <linux/writeback.h>
|
|
|
|
#include <linux/backing-dev.h>
|
|
|
|
#include <linux/pagevec.h>
|
|
|
|
#include <linux/cleancache.h>
|
|
|
|
|
|
|
|
#include "ext4.h"
|
|
|
|
|
2015-04-11 22:56:10 -06:00
|
|
|
static inline bool ext4_bio_encrypted(struct bio *bio)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_EXT4_FS_ENCRYPTION
|
|
|
|
return unlikely(bio->bi_private != NULL);
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-04-07 22:00:32 -06:00
|
|
|
/*
|
|
|
|
* I/O completion handler for multipage BIOs.
|
|
|
|
*
|
|
|
|
* The mpage code never puts partial pages into a BIO (except for end-of-file).
|
|
|
|
* If a page does not map to a contiguous run of blocks then it simply falls
|
|
|
|
* back to block_read_full_page().
|
|
|
|
*
|
|
|
|
* Why is this? If a page's completion depends on a number of different BIOs
|
|
|
|
* which can complete in any order (or at the same time) then determining the
|
|
|
|
* status of that page is hard. See end_buffer_async_read() for the details.
|
|
|
|
* There is no point in duplicating all that complexity.
|
|
|
|
*/
|
2015-07-20 07:29:37 -06:00
|
|
|
static void mpage_end_io(struct bio *bio)
|
2015-04-07 22:00:32 -06:00
|
|
|
{
|
|
|
|
struct bio_vec *bv;
|
|
|
|
int i;
|
|
|
|
|
2015-04-11 22:56:10 -06:00
|
|
|
if (ext4_bio_encrypted(bio)) {
|
2015-07-20 07:29:37 -06:00
|
|
|
if (bio->bi_error) {
|
2016-07-10 12:01:03 -06:00
|
|
|
fscrypt_release_ctx(bio->bi_private);
|
2015-04-11 22:56:10 -06:00
|
|
|
} else {
|
2016-07-10 12:01:03 -06:00
|
|
|
fscrypt_decrypt_bio_pages(bio->bi_private, bio);
|
2015-04-11 22:56:10 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-04-07 22:00:32 -06:00
|
|
|
bio_for_each_segment_all(bv, bio, i) {
|
|
|
|
struct page *page = bv->bv_page;
|
|
|
|
|
2015-07-20 07:29:37 -06:00
|
|
|
if (!bio->bi_error) {
|
2015-04-07 22:00:32 -06:00
|
|
|
SetPageUptodate(page);
|
|
|
|
} else {
|
|
|
|
ClearPageUptodate(page);
|
|
|
|
SetPageError(page);
|
|
|
|
}
|
|
|
|
unlock_page(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
bio_put(bio);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ext4_mpage_readpages(struct address_space *mapping,
|
|
|
|
struct list_head *pages, struct page *page,
|
|
|
|
unsigned nr_pages)
|
|
|
|
{
|
|
|
|
struct bio *bio = NULL;
|
|
|
|
sector_t last_block_in_bio = 0;
|
|
|
|
|
|
|
|
struct inode *inode = mapping->host;
|
|
|
|
const unsigned blkbits = inode->i_blkbits;
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 06:29:47 -06:00
|
|
|
const unsigned blocks_per_page = PAGE_SIZE >> blkbits;
|
2015-04-07 22:00:32 -06:00
|
|
|
const unsigned blocksize = 1 << blkbits;
|
|
|
|
sector_t block_in_file;
|
|
|
|
sector_t last_block;
|
|
|
|
sector_t last_block_in_file;
|
|
|
|
sector_t blocks[MAX_BUF_PER_PAGE];
|
|
|
|
unsigned page_block;
|
|
|
|
struct block_device *bdev = inode->i_sb->s_bdev;
|
|
|
|
int length;
|
|
|
|
unsigned relative_block = 0;
|
|
|
|
struct ext4_map_blocks map;
|
|
|
|
|
|
|
|
map.m_pblk = 0;
|
|
|
|
map.m_lblk = 0;
|
|
|
|
map.m_len = 0;
|
|
|
|
map.m_flags = 0;
|
|
|
|
|
2016-07-05 14:32:32 -06:00
|
|
|
for (; nr_pages; nr_pages--) {
|
2015-04-07 22:00:32 -06:00
|
|
|
int fully_mapped = 1;
|
|
|
|
unsigned first_hole = blocks_per_page;
|
|
|
|
|
|
|
|
prefetchw(&page->flags);
|
|
|
|
if (pages) {
|
|
|
|
page = list_entry(pages->prev, struct page, lru);
|
|
|
|
list_del(&page->lru);
|
mm, fs: obey gfp_mapping for add_to_page_cache()
Commit 6afdb859b710 ("mm: do not ignore mapping_gfp_mask in page cache
allocation paths") has caught some users of hardcoded GFP_KERNEL used in
the page cache allocation paths. This, however, wasn't complete and
there were others which went unnoticed.
Dave Chinner has reported the following deadlock for xfs on loop device:
: With the recent merge of the loop device changes, I'm now seeing
: XFS deadlock on my single CPU, 1GB RAM VM running xfs/073.
:
: The deadlocked is as follows:
:
: kloopd1: loop_queue_read_work
: xfs_file_iter_read
: lock XFS inode XFS_IOLOCK_SHARED (on image file)
: page cache read (GFP_KERNEL)
: radix tree alloc
: memory reclaim
: reclaim XFS inodes
: log force to unpin inodes
: <wait for log IO completion>
:
: xfs-cil/loop1: <does log force IO work>
: xlog_cil_push
: xlog_write
: <loop issuing log writes>
: xlog_state_get_iclog_space()
: <blocks due to all log buffers under write io>
: <waits for IO completion>
:
: kloopd1: loop_queue_write_work
: xfs_file_write_iter
: lock XFS inode XFS_IOLOCK_EXCL (on image file)
: <wait for inode to be unlocked>
:
: i.e. the kloopd, with it's split read and write work queues, has
: introduced a dependency through memory reclaim. i.e. that writes
: need to be able to progress for reads make progress.
:
: The problem, fundamentally, is that mpage_readpages() does a
: GFP_KERNEL allocation, rather than paying attention to the inode's
: mapping gfp mask, which is set to GFP_NOFS.
:
: The didn't used to happen, because the loop device used to issue
: reads through the splice path and that does:
:
: error = add_to_page_cache_lru(page, mapping, index,
: GFP_KERNEL & mapping_gfp_mask(mapping));
This has changed by commit aa4d86163e4 ("block: loop: switch to VFS
ITER_BVEC").
This patch changes mpage_readpage{s} to follow gfp mask set for the
mapping. There are, however, other places which are doing basically the
same.
lustre:ll_dir_filler is doing GFP_KERNEL from the function which
apparently uses GFP_NOFS for other allocations so let's make this
consistent.
cifs:readpages_get_pages is called from cifs_readpages and
__cifs_readpages_from_fscache called from the same path obeys mapping
gfp.
ramfs_nommu_expand_for_mapping is hardcoding GFP_KERNEL as well
regardless it uses mapping_gfp_mask for the page allocation.
ext4_mpage_readpages is the called from the page cache allocation path
same as read_pages and read_cache_pages
As I've noticed in my previous post I cannot say I would be happy about
sprinkling mapping_gfp_mask all over the place and it sounds like we
should drop gfp_mask argument altogether and use it internally in
__add_to_page_cache_locked that would require all the filesystems to use
mapping gfp consistently which I am not sure is the case here. From a
quick glance it seems that some file system use it all the time while
others are selective.
Signed-off-by: Michal Hocko <mhocko@suse.com>
Reported-by: Dave Chinner <david@fromorbit.com>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Ming Lei <ming.lei@canonical.com>
Cc: Andreas Dilger <andreas.dilger@intel.com>
Cc: Oleg Drokin <oleg.drokin@intel.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-10-15 16:28:24 -06:00
|
|
|
if (add_to_page_cache_lru(page, mapping, page->index,
|
2016-07-26 16:24:53 -06:00
|
|
|
readahead_gfp_mask(mapping)))
|
2015-04-07 22:00:32 -06:00
|
|
|
goto next_page;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (page_has_buffers(page))
|
|
|
|
goto confused;
|
|
|
|
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 06:29:47 -06:00
|
|
|
block_in_file = (sector_t)page->index << (PAGE_SHIFT - blkbits);
|
2015-04-07 22:00:32 -06:00
|
|
|
last_block = block_in_file + nr_pages * blocks_per_page;
|
|
|
|
last_block_in_file = (i_size_read(inode) + blocksize - 1) >> blkbits;
|
|
|
|
if (last_block > last_block_in_file)
|
|
|
|
last_block = last_block_in_file;
|
|
|
|
page_block = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map blocks using the previous result first.
|
|
|
|
*/
|
|
|
|
if ((map.m_flags & EXT4_MAP_MAPPED) &&
|
|
|
|
block_in_file > map.m_lblk &&
|
|
|
|
block_in_file < (map.m_lblk + map.m_len)) {
|
|
|
|
unsigned map_offset = block_in_file - map.m_lblk;
|
|
|
|
unsigned last = map.m_len - map_offset;
|
|
|
|
|
|
|
|
for (relative_block = 0; ; relative_block++) {
|
|
|
|
if (relative_block == last) {
|
|
|
|
/* needed? */
|
|
|
|
map.m_flags &= ~EXT4_MAP_MAPPED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (page_block == blocks_per_page)
|
|
|
|
break;
|
|
|
|
blocks[page_block] = map.m_pblk + map_offset +
|
|
|
|
relative_block;
|
|
|
|
page_block++;
|
|
|
|
block_in_file++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Then do more ext4_map_blocks() calls until we are
|
|
|
|
* done with this page.
|
|
|
|
*/
|
|
|
|
while (page_block < blocks_per_page) {
|
|
|
|
if (block_in_file < last_block) {
|
|
|
|
map.m_lblk = block_in_file;
|
|
|
|
map.m_len = last_block - block_in_file;
|
|
|
|
|
|
|
|
if (ext4_map_blocks(NULL, inode, &map, 0) < 0) {
|
|
|
|
set_error_page:
|
|
|
|
SetPageError(page);
|
|
|
|
zero_user_segment(page, 0,
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 06:29:47 -06:00
|
|
|
PAGE_SIZE);
|
2015-04-07 22:00:32 -06:00
|
|
|
unlock_page(page);
|
|
|
|
goto next_page;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((map.m_flags & EXT4_MAP_MAPPED) == 0) {
|
|
|
|
fully_mapped = 0;
|
|
|
|
if (first_hole == blocks_per_page)
|
|
|
|
first_hole = page_block;
|
|
|
|
page_block++;
|
|
|
|
block_in_file++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (first_hole != blocks_per_page)
|
|
|
|
goto confused; /* hole -> non-hole */
|
|
|
|
|
|
|
|
/* Contiguous blocks? */
|
|
|
|
if (page_block && blocks[page_block-1] != map.m_pblk-1)
|
|
|
|
goto confused;
|
|
|
|
for (relative_block = 0; ; relative_block++) {
|
|
|
|
if (relative_block == map.m_len) {
|
|
|
|
/* needed? */
|
|
|
|
map.m_flags &= ~EXT4_MAP_MAPPED;
|
|
|
|
break;
|
|
|
|
} else if (page_block == blocks_per_page)
|
|
|
|
break;
|
|
|
|
blocks[page_block] = map.m_pblk+relative_block;
|
|
|
|
page_block++;
|
|
|
|
block_in_file++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (first_hole != blocks_per_page) {
|
|
|
|
zero_user_segment(page, first_hole << blkbits,
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 06:29:47 -06:00
|
|
|
PAGE_SIZE);
|
2015-04-07 22:00:32 -06:00
|
|
|
if (first_hole == 0) {
|
|
|
|
SetPageUptodate(page);
|
|
|
|
unlock_page(page);
|
|
|
|
goto next_page;
|
|
|
|
}
|
|
|
|
} else if (fully_mapped) {
|
|
|
|
SetPageMappedToDisk(page);
|
|
|
|
}
|
|
|
|
if (fully_mapped && blocks_per_page == 1 &&
|
|
|
|
!PageUptodate(page) && cleancache_get_page(page) == 0) {
|
|
|
|
SetPageUptodate(page);
|
|
|
|
goto confused;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This page will go to BIO. Do we need to send this
|
|
|
|
* BIO off first?
|
|
|
|
*/
|
|
|
|
if (bio && (last_block_in_bio != blocks[0] - 1)) {
|
|
|
|
submit_and_realloc:
|
2016-06-05 13:31:41 -06:00
|
|
|
submit_bio(bio);
|
2015-04-07 22:00:32 -06:00
|
|
|
bio = NULL;
|
|
|
|
}
|
|
|
|
if (bio == NULL) {
|
2016-07-10 12:01:03 -06:00
|
|
|
struct fscrypt_ctx *ctx = NULL;
|
2015-04-11 22:56:10 -06:00
|
|
|
|
|
|
|
if (ext4_encrypted_inode(inode) &&
|
|
|
|
S_ISREG(inode->i_mode)) {
|
2016-07-10 12:01:03 -06:00
|
|
|
ctx = fscrypt_get_ctx(inode, GFP_NOFS);
|
2015-04-11 22:56:10 -06:00
|
|
|
if (IS_ERR(ctx))
|
|
|
|
goto set_error_page;
|
|
|
|
}
|
2015-04-07 22:00:32 -06:00
|
|
|
bio = bio_alloc(GFP_KERNEL,
|
2015-05-19 06:31:01 -06:00
|
|
|
min_t(int, nr_pages, BIO_MAX_PAGES));
|
2015-04-11 22:56:10 -06:00
|
|
|
if (!bio) {
|
|
|
|
if (ctx)
|
2016-07-10 12:01:03 -06:00
|
|
|
fscrypt_release_ctx(ctx);
|
2015-04-07 22:00:32 -06:00
|
|
|
goto set_error_page;
|
2015-04-11 22:56:10 -06:00
|
|
|
}
|
2015-04-07 22:00:32 -06:00
|
|
|
bio->bi_bdev = bdev;
|
|
|
|
bio->bi_iter.bi_sector = blocks[0] << (blkbits - 9);
|
|
|
|
bio->bi_end_io = mpage_end_io;
|
2015-04-11 22:56:10 -06:00
|
|
|
bio->bi_private = ctx;
|
2016-06-05 13:31:48 -06:00
|
|
|
bio_set_op_attrs(bio, REQ_OP_READ, 0);
|
2015-04-07 22:00:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
length = first_hole << blkbits;
|
|
|
|
if (bio_add_page(bio, page, length, 0) < length)
|
|
|
|
goto submit_and_realloc;
|
|
|
|
|
|
|
|
if (((map.m_flags & EXT4_MAP_BOUNDARY) &&
|
|
|
|
(relative_block == map.m_len)) ||
|
|
|
|
(first_hole != blocks_per_page)) {
|
2016-06-05 13:31:41 -06:00
|
|
|
submit_bio(bio);
|
2015-04-07 22:00:32 -06:00
|
|
|
bio = NULL;
|
|
|
|
} else
|
|
|
|
last_block_in_bio = blocks[blocks_per_page - 1];
|
|
|
|
goto next_page;
|
|
|
|
confused:
|
|
|
|
if (bio) {
|
2016-06-05 13:31:41 -06:00
|
|
|
submit_bio(bio);
|
2015-04-07 22:00:32 -06:00
|
|
|
bio = NULL;
|
|
|
|
}
|
|
|
|
if (!PageUptodate(page))
|
|
|
|
block_read_full_page(page, ext4_get_block);
|
|
|
|
else
|
|
|
|
unlock_page(page);
|
|
|
|
next_page:
|
|
|
|
if (pages)
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 06:29:47 -06:00
|
|
|
put_page(page);
|
2015-04-07 22:00:32 -06:00
|
|
|
}
|
|
|
|
BUG_ON(pages && !list_empty(pages));
|
|
|
|
if (bio)
|
2016-06-05 13:31:41 -06:00
|
|
|
submit_bio(bio);
|
2015-04-07 22:00:32 -06:00
|
|
|
return 0;
|
|
|
|
}
|