2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* linux/mm/page_io.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
|
|
|
|
*
|
|
|
|
* Swap reorganised 29.12.95,
|
|
|
|
* Asynchronous swapping added 30.12.95. Stephen Tweedie
|
|
|
|
* Removed race in async swapping. 14.4.1996. Bruno Haible
|
|
|
|
* Add swap of shared pages through the page cache. 20.2.1998. Stephen Tweedie
|
|
|
|
* Always use brw_page, life becomes simpler. 12 May 1998 Eric Biederman
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/kernel_stat.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 09:04:11 +01:00
|
|
|
#include <linux/gfp.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/swap.h>
|
|
|
|
#include <linux/bio.h>
|
|
|
|
#include <linux/swapops.h>
|
2012-08-01 01:44:55 +02:00
|
|
|
#include <linux/buffer_head.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <linux/writeback.h>
|
2012-04-10 01:08:06 +02:00
|
|
|
#include <linux/frontswap.h>
|
2013-07-04 00:01:24 +02:00
|
|
|
#include <linux/blkdev.h>
|
2015-02-22 17:58:50 +01:00
|
|
|
#include <linux/uio.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <asm/pgtable.h>
|
|
|
|
|
2009-12-15 02:58:40 +01:00
|
|
|
static struct bio *get_swap_bio(gfp_t gfp_flags,
|
2005-04-17 00:20:36 +02:00
|
|
|
struct page *page, bio_end_io_t end_io)
|
|
|
|
{
|
|
|
|
struct bio *bio;
|
|
|
|
|
|
|
|
bio = bio_alloc(gfp_flags, 1);
|
|
|
|
if (bio) {
|
2013-10-12 00:44:27 +02:00
|
|
|
bio->bi_iter.bi_sector = map_swap_page(page, &bio->bi_bdev);
|
|
|
|
bio->bi_iter.bi_sector <<= PAGE_SHIFT - 9;
|
2005-04-17 00:20:36 +02:00
|
|
|
bio->bi_end_io = end_io;
|
2014-12-22 12:48:42 +01:00
|
|
|
|
|
|
|
bio_add_page(bio, page, PAGE_SIZE, 0);
|
|
|
|
BUG_ON(bio->bi_iter.bi_size != PAGE_SIZE);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
return bio;
|
|
|
|
}
|
|
|
|
|
2015-07-20 15:29:37 +02:00
|
|
|
void end_swap_bio_write(struct bio *bio)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct page *page = bio->bi_io_vec[0].bv_page;
|
|
|
|
|
2015-07-20 15:29:37 +02:00
|
|
|
if (bio->bi_error) {
|
2005-04-17 00:20:36 +02:00
|
|
|
SetPageError(page);
|
2006-09-26 08:31:26 +02:00
|
|
|
/*
|
|
|
|
* We failed to write the page out to swap-space.
|
|
|
|
* Re-dirty the page in order to avoid it being reclaimed.
|
|
|
|
* Also print a dire warning that things will go BAD (tm)
|
|
|
|
* very quickly.
|
|
|
|
*
|
|
|
|
* Also clear PG_reclaim to avoid rotate_reclaimable_page()
|
|
|
|
*/
|
|
|
|
set_page_dirty(page);
|
2016-03-17 22:19:50 +01:00
|
|
|
pr_alert("Write-error on swap-device (%u:%u:%llu)\n",
|
|
|
|
imajor(bio->bi_bdev->bd_inode),
|
|
|
|
iminor(bio->bi_bdev->bd_inode),
|
|
|
|
(unsigned long long)bio->bi_iter.bi_sector);
|
2006-09-26 08:31:26 +02:00
|
|
|
ClearPageReclaim(page);
|
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
end_page_writeback(page);
|
|
|
|
bio_put(bio);
|
|
|
|
}
|
|
|
|
|
2016-03-22 22:24:36 +01:00
|
|
|
static void swap_slot_free_notify(struct page *page)
|
|
|
|
{
|
|
|
|
struct swap_info_struct *sis;
|
|
|
|
struct gendisk *disk;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There is no guarantee that the page is in swap cache - the software
|
|
|
|
* suspend code (at least) uses end_swap_bio_read() against a non-
|
|
|
|
* swapcache page. So we must check PG_swapcache before proceeding with
|
|
|
|
* this optimization.
|
|
|
|
*/
|
|
|
|
if (unlikely(!PageSwapCache(page)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
sis = page_swap_info(page);
|
|
|
|
if (!(sis->flags & SWP_BLKDEV))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The swap subsystem performs lazy swap slot freeing,
|
|
|
|
* expecting that the page will be swapped out again.
|
|
|
|
* So we can avoid an unnecessary write if the page
|
|
|
|
* isn't redirtied.
|
|
|
|
* This is good for real swap storage because we can
|
|
|
|
* reduce unnecessary I/O and enhance wear-leveling
|
|
|
|
* if an SSD is used as the as swap device.
|
|
|
|
* But if in-memory swap device (eg zram) is used,
|
|
|
|
* this causes a duplicated copy between uncompressed
|
|
|
|
* data in VM-owned memory and compressed data in
|
|
|
|
* zram-owned memory. So let's free zram-owned memory
|
|
|
|
* and make the VM-owned decompressed page *dirty*,
|
|
|
|
* so the page should be swapped out somewhere again if
|
|
|
|
* we again wish to reclaim it.
|
|
|
|
*/
|
|
|
|
disk = sis->bdev->bd_disk;
|
|
|
|
if (disk->fops->swap_slot_free_notify) {
|
|
|
|
swp_entry_t entry;
|
|
|
|
unsigned long offset;
|
|
|
|
|
|
|
|
entry.val = page_private(page);
|
|
|
|
offset = swp_offset(entry);
|
|
|
|
|
|
|
|
SetPageDirty(page);
|
|
|
|
disk->fops->swap_slot_free_notify(sis->bdev,
|
|
|
|
offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-20 15:29:37 +02:00
|
|
|
static void end_swap_bio_read(struct bio *bio)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct page *page = bio->bi_io_vec[0].bv_page;
|
|
|
|
|
2015-07-20 15:29:37 +02:00
|
|
|
if (bio->bi_error) {
|
2005-04-17 00:20:36 +02:00
|
|
|
SetPageError(page);
|
|
|
|
ClearPageUptodate(page);
|
2016-03-17 22:19:50 +01:00
|
|
|
pr_alert("Read-error on swap-device (%u:%u:%llu)\n",
|
|
|
|
imajor(bio->bi_bdev->bd_inode),
|
|
|
|
iminor(bio->bi_bdev->bd_inode),
|
|
|
|
(unsigned long long)bio->bi_iter.bi_sector);
|
2013-07-04 00:01:24 +02:00
|
|
|
goto out;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2013-07-04 00:01:24 +02:00
|
|
|
|
|
|
|
SetPageUptodate(page);
|
2016-03-22 22:24:36 +01:00
|
|
|
swap_slot_free_notify(page);
|
2013-07-04 00:01:24 +02:00
|
|
|
out:
|
2005-04-17 00:20:36 +02:00
|
|
|
unlock_page(page);
|
|
|
|
bio_put(bio);
|
|
|
|
}
|
|
|
|
|
2012-08-01 01:44:57 +02:00
|
|
|
int generic_swapfile_activate(struct swap_info_struct *sis,
|
|
|
|
struct file *swap_file,
|
|
|
|
sector_t *span)
|
|
|
|
{
|
|
|
|
struct address_space *mapping = swap_file->f_mapping;
|
|
|
|
struct inode *inode = mapping->host;
|
|
|
|
unsigned blocks_per_page;
|
|
|
|
unsigned long page_no;
|
|
|
|
unsigned blkbits;
|
|
|
|
sector_t probe_block;
|
|
|
|
sector_t last_block;
|
|
|
|
sector_t lowest_block = -1;
|
|
|
|
sector_t highest_block = 0;
|
|
|
|
int nr_extents = 0;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
blkbits = inode->i_blkbits;
|
|
|
|
blocks_per_page = PAGE_SIZE >> blkbits;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map all the blocks into the extent list. This code doesn't try
|
|
|
|
* to be very smart.
|
|
|
|
*/
|
|
|
|
probe_block = 0;
|
|
|
|
page_no = 0;
|
|
|
|
last_block = i_size_read(inode) >> blkbits;
|
|
|
|
while ((probe_block + blocks_per_page) <= last_block &&
|
|
|
|
page_no < sis->max) {
|
|
|
|
unsigned block_in_page;
|
|
|
|
sector_t first_block;
|
|
|
|
|
2016-07-29 00:48:47 +02:00
|
|
|
cond_resched();
|
|
|
|
|
2012-08-01 01:44:57 +02:00
|
|
|
first_block = bmap(inode, probe_block);
|
|
|
|
if (first_block == 0)
|
|
|
|
goto bad_bmap;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It must be PAGE_SIZE aligned on-disk
|
|
|
|
*/
|
|
|
|
if (first_block & (blocks_per_page - 1)) {
|
|
|
|
probe_block++;
|
|
|
|
goto reprobe;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (block_in_page = 1; block_in_page < blocks_per_page;
|
|
|
|
block_in_page++) {
|
|
|
|
sector_t block;
|
|
|
|
|
|
|
|
block = bmap(inode, probe_block + block_in_page);
|
|
|
|
if (block == 0)
|
|
|
|
goto bad_bmap;
|
|
|
|
if (block != first_block + block_in_page) {
|
|
|
|
/* Discontiguity */
|
|
|
|
probe_block++;
|
|
|
|
goto reprobe;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
first_block >>= (PAGE_SHIFT - blkbits);
|
|
|
|
if (page_no) { /* exclude the header page */
|
|
|
|
if (first_block < lowest_block)
|
|
|
|
lowest_block = first_block;
|
|
|
|
if (first_block > highest_block)
|
|
|
|
highest_block = first_block;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We found a PAGE_SIZE-length, PAGE_SIZE-aligned run of blocks
|
|
|
|
*/
|
|
|
|
ret = add_swap_extent(sis, page_no, 1, first_block);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
nr_extents += ret;
|
|
|
|
page_no++;
|
|
|
|
probe_block += blocks_per_page;
|
|
|
|
reprobe:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ret = nr_extents;
|
|
|
|
*span = 1 + highest_block - lowest_block;
|
|
|
|
if (page_no == 0)
|
|
|
|
page_no = 1; /* force Empty message */
|
|
|
|
sis->max = page_no;
|
|
|
|
sis->pages = page_no - 1;
|
|
|
|
sis->highest_bit = page_no - 1;
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
bad_bmap:
|
2016-03-17 22:19:50 +01:00
|
|
|
pr_err("swapon: swapfile has holes\n");
|
2012-08-01 01:44:57 +02:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* We may have stale swap cache pages in memory: notice
|
|
|
|
* them here and get rid of the unnecessary final write.
|
|
|
|
*/
|
|
|
|
int swap_writepage(struct page *page, struct writeback_control *wbc)
|
|
|
|
{
|
2013-04-30 00:08:34 +02:00
|
|
|
int ret = 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2009-01-06 23:39:36 +01:00
|
|
|
if (try_to_free_swap(page)) {
|
2005-04-17 00:20:36 +02:00
|
|
|
unlock_page(page);
|
|
|
|
goto out;
|
|
|
|
}
|
2012-05-15 17:32:15 +02:00
|
|
|
if (frontswap_store(page) == 0) {
|
2012-04-10 01:08:06 +02:00
|
|
|
set_page_writeback(page);
|
|
|
|
unlock_page(page);
|
|
|
|
end_page_writeback(page);
|
|
|
|
goto out;
|
|
|
|
}
|
2013-04-30 00:08:35 +02:00
|
|
|
ret = __swap_writepage(page, wbc, end_swap_bio_write);
|
2013-04-30 00:08:34 +02:00
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-06-05 01:07:48 +02:00
|
|
|
static sector_t swap_page_sector(struct page *page)
|
|
|
|
{
|
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 14:29:47 +02:00
|
|
|
return (sector_t)__page_file_index(page) << (PAGE_SHIFT - 9);
|
2014-06-05 01:07:48 +02:00
|
|
|
}
|
|
|
|
|
2013-04-30 00:08:35 +02:00
|
|
|
int __swap_writepage(struct page *page, struct writeback_control *wbc,
|
2015-07-20 15:29:37 +02:00
|
|
|
bio_end_io_t end_write_func)
|
2013-04-30 00:08:34 +02:00
|
|
|
{
|
|
|
|
struct bio *bio;
|
2016-06-05 21:31:41 +02:00
|
|
|
int ret;
|
2013-04-30 00:08:34 +02:00
|
|
|
struct swap_info_struct *sis = page_swap_info(page);
|
2012-08-01 01:44:55 +02:00
|
|
|
|
2016-10-08 02:00:52 +02:00
|
|
|
VM_BUG_ON_PAGE(!PageSwapCache(page), page);
|
2012-08-01 01:44:55 +02:00
|
|
|
if (sis->flags & SWP_FILE) {
|
|
|
|
struct kiocb kiocb;
|
|
|
|
struct file *swap_file = sis->swap_file;
|
|
|
|
struct address_space *mapping = swap_file->f_mapping;
|
2014-04-05 05:12:29 +02:00
|
|
|
struct bio_vec bv = {
|
|
|
|
.bv_page = page,
|
|
|
|
.bv_len = PAGE_SIZE,
|
|
|
|
.bv_offset = 0
|
|
|
|
};
|
2015-01-23 07:08:07 +01:00
|
|
|
struct iov_iter from;
|
2012-08-01 01:44:55 +02:00
|
|
|
|
2015-01-23 07:08:07 +01:00
|
|
|
iov_iter_bvec(&from, ITER_BVEC | WRITE, &bv, 1, PAGE_SIZE);
|
2012-08-01 01:44:55 +02:00
|
|
|
init_sync_kiocb(&kiocb, swap_file);
|
|
|
|
kiocb.ki_pos = page_file_offset(page);
|
|
|
|
|
2013-04-30 00:08:48 +02:00
|
|
|
set_page_writeback(page);
|
2012-08-01 01:44:55 +02:00
|
|
|
unlock_page(page);
|
2016-04-07 17:51:58 +02:00
|
|
|
ret = mapping->a_ops->direct_IO(&kiocb, &from);
|
2012-08-01 01:44:55 +02:00
|
|
|
if (ret == PAGE_SIZE) {
|
|
|
|
count_vm_event(PSWPOUT);
|
|
|
|
ret = 0;
|
2013-04-30 00:08:47 +02:00
|
|
|
} else {
|
2013-04-30 00:08:48 +02:00
|
|
|
/*
|
|
|
|
* In the case of swap-over-nfs, this can be a
|
|
|
|
* temporary failure if the system has limited
|
|
|
|
* memory for allocating transmit buffers.
|
|
|
|
* Mark the page dirty and avoid
|
|
|
|
* rotate_reclaimable_page but rate-limit the
|
|
|
|
* messages but do not flag PageError like
|
|
|
|
* the normal direct-to-bio case as it could
|
|
|
|
* be temporary.
|
|
|
|
*/
|
2013-04-30 00:08:47 +02:00
|
|
|
set_page_dirty(page);
|
2013-04-30 00:08:48 +02:00
|
|
|
ClearPageReclaim(page);
|
2016-03-17 22:19:50 +01:00
|
|
|
pr_err_ratelimited("Write error on dio swapfile (%llu)\n",
|
|
|
|
page_file_offset(page));
|
2012-08-01 01:44:55 +02:00
|
|
|
}
|
2013-04-30 00:08:48 +02:00
|
|
|
end_page_writeback(page);
|
2012-08-01 01:44:55 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-06-05 01:07:48 +02:00
|
|
|
ret = bdev_write_page(sis->bdev, swap_page_sector(page), page, wbc);
|
|
|
|
if (!ret) {
|
|
|
|
count_vm_event(PSWPOUT);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2013-04-30 00:08:35 +02:00
|
|
|
bio = get_swap_bio(GFP_NOIO, page, end_write_func);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (bio == NULL) {
|
|
|
|
set_page_dirty(page);
|
|
|
|
unlock_page(page);
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (wbc->sync_mode == WB_SYNC_ALL)
|
2016-08-01 17:38:44 +02:00
|
|
|
bio_set_op_attrs(bio, REQ_OP_WRITE, REQ_SYNC);
|
|
|
|
else
|
|
|
|
bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
|
2006-06-30 10:55:45 +02:00
|
|
|
count_vm_event(PSWPOUT);
|
2005-04-17 00:20:36 +02:00
|
|
|
set_page_writeback(page);
|
|
|
|
unlock_page(page);
|
2016-06-05 21:31:41 +02:00
|
|
|
submit_bio(bio);
|
2005-04-17 00:20:36 +02:00
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-06-17 00:33:02 +02:00
|
|
|
int swap_readpage(struct page *page)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct bio *bio;
|
|
|
|
int ret = 0;
|
2012-08-01 01:44:55 +02:00
|
|
|
struct swap_info_struct *sis = page_swap_info(page);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2016-10-08 02:00:52 +02:00
|
|
|
VM_BUG_ON_PAGE(!PageSwapCache(page), page);
|
2014-01-24 00:52:54 +01:00
|
|
|
VM_BUG_ON_PAGE(!PageLocked(page), page);
|
|
|
|
VM_BUG_ON_PAGE(PageUptodate(page), page);
|
2012-05-15 17:32:15 +02:00
|
|
|
if (frontswap_load(page) == 0) {
|
2012-04-10 01:08:06 +02:00
|
|
|
SetPageUptodate(page);
|
|
|
|
unlock_page(page);
|
|
|
|
goto out;
|
|
|
|
}
|
2012-08-01 01:44:55 +02:00
|
|
|
|
|
|
|
if (sis->flags & SWP_FILE) {
|
|
|
|
struct file *swap_file = sis->swap_file;
|
|
|
|
struct address_space *mapping = swap_file->f_mapping;
|
|
|
|
|
|
|
|
ret = mapping->a_ops->readpage(swap_file, page);
|
|
|
|
if (!ret)
|
|
|
|
count_vm_event(PSWPIN);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-06-05 01:07:48 +02:00
|
|
|
ret = bdev_read_page(sis->bdev, swap_page_sector(page), page);
|
|
|
|
if (!ret) {
|
2016-04-29 01:18:41 +02:00
|
|
|
if (trylock_page(page)) {
|
|
|
|
swap_slot_free_notify(page);
|
|
|
|
unlock_page(page);
|
|
|
|
}
|
|
|
|
|
2014-06-05 01:07:48 +02:00
|
|
|
count_vm_event(PSWPIN);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2009-12-15 02:58:40 +01:00
|
|
|
bio = get_swap_bio(GFP_KERNEL, page, end_swap_bio_read);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (bio == NULL) {
|
|
|
|
unlock_page(page);
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2016-06-05 21:31:48 +02:00
|
|
|
bio_set_op_attrs(bio, REQ_OP_READ, 0);
|
2006-06-30 10:55:45 +02:00
|
|
|
count_vm_event(PSWPIN);
|
2016-06-05 21:31:41 +02:00
|
|
|
submit_bio(bio);
|
2005-04-17 00:20:36 +02:00
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
2012-08-01 01:44:55 +02:00
|
|
|
|
|
|
|
int swap_set_page_dirty(struct page *page)
|
|
|
|
{
|
|
|
|
struct swap_info_struct *sis = page_swap_info(page);
|
|
|
|
|
|
|
|
if (sis->flags & SWP_FILE) {
|
|
|
|
struct address_space *mapping = sis->swap_file->f_mapping;
|
2016-10-08 02:00:52 +02:00
|
|
|
|
|
|
|
VM_BUG_ON_PAGE(!PageSwapCache(page), page);
|
2012-08-01 01:44:55 +02:00
|
|
|
return mapping->a_ops->set_page_dirty(page);
|
|
|
|
} else {
|
|
|
|
return __set_page_dirty_no_writeback(page);
|
|
|
|
}
|
|
|
|
}
|