License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 06:20:36 +08: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 16:04:11 +08:00
|
|
|
#include <linux/gfp.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/swap.h>
|
|
|
|
#include <linux/bio.h>
|
|
|
|
#include <linux/swapops.h>
|
2012-08-01 07:44:55 +08:00
|
|
|
#include <linux/buffer_head.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/writeback.h>
|
2012-04-10 07:08:06 +08:00
|
|
|
#include <linux/frontswap.h>
|
2013-07-04 06:01:24 +08:00
|
|
|
#include <linux/blkdev.h>
|
2019-12-01 09:58:29 +08:00
|
|
|
#include <linux/psi.h>
|
2015-02-23 00:58:50 +08:00
|
|
|
#include <linux/uio.h>
|
2017-08-03 04:32:09 +08:00
|
|
|
#include <linux/sched/task.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-07-20 21:29:37 +08:00
|
|
|
void end_swap_bio_write(struct bio *bio)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2017-12-18 20:22:04 +08:00
|
|
|
struct page *page = bio_first_page_all(bio);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-06-03 15:38:06 +08:00
|
|
|
if (bio->bi_status) {
|
2005-04-17 06:20:36 +08:00
|
|
|
SetPageError(page);
|
2006-09-26 14:31:26 +08: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.
|
|
|
|
*
|
2020-12-08 14:25:39 +08:00
|
|
|
* Also clear PG_reclaim to avoid folio_rotate_reclaimable()
|
2006-09-26 14:31:26 +08:00
|
|
|
*/
|
|
|
|
set_page_dirty(page);
|
2021-02-25 04:03:01 +08:00
|
|
|
pr_alert_ratelimited("Write-error on swap-device (%u:%u:%llu)\n",
|
|
|
|
MAJOR(bio_dev(bio)), MINOR(bio_dev(bio)),
|
|
|
|
(unsigned long long)bio->bi_iter.bi_sector);
|
2006-09-26 14:31:26 +08:00
|
|
|
ClearPageReclaim(page);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
end_page_writeback(page);
|
|
|
|
bio_put(bio);
|
|
|
|
}
|
|
|
|
|
2016-03-23 05:24:36 +08:00
|
|
|
static void swap_slot_free_notify(struct page *page)
|
|
|
|
{
|
|
|
|
struct swap_info_struct *sis;
|
|
|
|
struct gendisk *disk;
|
2019-11-16 09:35:00 +08:00
|
|
|
swp_entry_t entry;
|
2016-03-23 05:24:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
2020-08-15 08:31:20 +08:00
|
|
|
if (data_race(!(sis->flags & SWP_BLKDEV)))
|
2016-03-23 05:24:36 +08:00
|
|
|
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;
|
2019-11-16 09:35:00 +08:00
|
|
|
entry.val = page_private(page);
|
|
|
|
if (disk->fops->swap_slot_free_notify && __swap_count(entry) == 1) {
|
2016-03-23 05:24:36 +08:00
|
|
|
unsigned long offset;
|
|
|
|
|
|
|
|
offset = swp_offset(entry);
|
|
|
|
|
|
|
|
SetPageDirty(page);
|
|
|
|
disk->fops->swap_slot_free_notify(sis->bdev,
|
|
|
|
offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-20 21:29:37 +08:00
|
|
|
static void end_swap_bio_read(struct bio *bio)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2017-12-18 20:22:04 +08:00
|
|
|
struct page *page = bio_first_page_all(bio);
|
swap: add block io poll in swapin path
For fast flash disk, async IO could introduce overhead because of
context switch. block-mq now supports IO poll, which improves
performance and latency a lot. swapin is a good place to use this
technique, because the task is waiting for the swapin page to continue
execution.
In my virtual machine, directly read 4k data from a NVMe with iopoll is
about 60% better than that without poll. With iopoll support in swapin
patch, my microbenchmark (a task does random memory write) is about
10%~25% faster. CPU utilization increases a lot though, 2x and even 3x
CPU utilization. This will depend on disk speed.
While iopoll in swapin isn't intended for all usage cases, it's a win
for latency sensistive workloads with high speed swap disk. block layer
has knob to control poll in runtime. If poll isn't enabled in block
layer, there should be no noticeable change in swapin.
I got a chance to run the same test in a NVMe with DRAM as the media.
In simple fio IO test, blkpoll boosts 50% performance in single thread
test and ~20% in 8 threads test. So this is the base line. In above
swap test, blkpoll boosts ~27% performance in single thread test.
blkpoll uses 2x CPU time though.
If we enable hybid polling, the performance gain has very slight drop
but CPU time is only 50% worse than that without blkpoll. Also we can
adjust parameter of hybid poll, with it, the CPU time penality is
reduced further. In 8 threads test, blkpoll doesn't help though. The
performance is similar to that without blkpoll, but cpu utilization is
similar too. There is lock contention in swap path. The cpu time
spending on blkpoll isn't high. So overall, blkpoll swapin isn't worse
than that without it.
The swapin readahead might read several pages in in the same time and
form a big IO request. Since the IO will take longer time, it doesn't
make sense to do poll, so the patch only does iopoll for single page
swapin.
[akpm@linux-foundation.org: coding-style fixes]
Link: http://lkml.kernel.org/r/070c3c3e40b711e7b1390002c991e86a-b5408f0@7511894063d3764ff01ea8111f5a004d7dd700ed078797c204a24e620ddb965c
Signed-off-by: Shaohua Li <shli@fb.com>
Cc: Tim Chen <tim.c.chen@intel.com>
Cc: Huang Ying <ying.huang@intel.com>
Cc: Jens Axboe <axboe@fb.com>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-07-11 06:47:11 +08:00
|
|
|
struct task_struct *waiter = bio->bi_private;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-06-03 15:38:06 +08:00
|
|
|
if (bio->bi_status) {
|
2005-04-17 06:20:36 +08:00
|
|
|
SetPageError(page);
|
|
|
|
ClearPageUptodate(page);
|
2021-02-25 04:03:01 +08:00
|
|
|
pr_alert_ratelimited("Read-error on swap-device (%u:%u:%llu)\n",
|
|
|
|
MAJOR(bio_dev(bio)), MINOR(bio_dev(bio)),
|
|
|
|
(unsigned long long)bio->bi_iter.bi_sector);
|
2013-07-04 06:01:24 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2013-07-04 06:01:24 +08:00
|
|
|
|
|
|
|
SetPageUptodate(page);
|
2016-03-23 05:24:36 +08:00
|
|
|
swap_slot_free_notify(page);
|
2013-07-04 06:01:24 +08:00
|
|
|
out:
|
2005-04-17 06:20:36 +08:00
|
|
|
unlock_page(page);
|
swap: add block io poll in swapin path
For fast flash disk, async IO could introduce overhead because of
context switch. block-mq now supports IO poll, which improves
performance and latency a lot. swapin is a good place to use this
technique, because the task is waiting for the swapin page to continue
execution.
In my virtual machine, directly read 4k data from a NVMe with iopoll is
about 60% better than that without poll. With iopoll support in swapin
patch, my microbenchmark (a task does random memory write) is about
10%~25% faster. CPU utilization increases a lot though, 2x and even 3x
CPU utilization. This will depend on disk speed.
While iopoll in swapin isn't intended for all usage cases, it's a win
for latency sensistive workloads with high speed swap disk. block layer
has knob to control poll in runtime. If poll isn't enabled in block
layer, there should be no noticeable change in swapin.
I got a chance to run the same test in a NVMe with DRAM as the media.
In simple fio IO test, blkpoll boosts 50% performance in single thread
test and ~20% in 8 threads test. So this is the base line. In above
swap test, blkpoll boosts ~27% performance in single thread test.
blkpoll uses 2x CPU time though.
If we enable hybid polling, the performance gain has very slight drop
but CPU time is only 50% worse than that without blkpoll. Also we can
adjust parameter of hybid poll, with it, the CPU time penality is
reduced further. In 8 threads test, blkpoll doesn't help though. The
performance is similar to that without blkpoll, but cpu utilization is
similar too. There is lock contention in swap path. The cpu time
spending on blkpoll isn't high. So overall, blkpoll swapin isn't worse
than that without it.
The swapin readahead might read several pages in in the same time and
form a big IO request. Since the IO will take longer time, it doesn't
make sense to do poll, so the patch only does iopoll for single page
swapin.
[akpm@linux-foundation.org: coding-style fixes]
Link: http://lkml.kernel.org/r/070c3c3e40b711e7b1390002c991e86a-b5408f0@7511894063d3764ff01ea8111f5a004d7dd700ed078797c204a24e620ddb965c
Signed-off-by: Shaohua Li <shli@fb.com>
Cc: Tim Chen <tim.c.chen@intel.com>
Cc: Huang Ying <ying.huang@intel.com>
Cc: Jens Axboe <axboe@fb.com>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-07-11 06:47:11 +08:00
|
|
|
WRITE_ONCE(bio->bi_private, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
bio_put(bio);
|
2019-07-05 06:14:49 +08:00
|
|
|
if (waiter) {
|
|
|
|
blk_wake_io_task(waiter);
|
|
|
|
put_task_struct(waiter);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-08-01 07:44:57 +08: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;
|
|
|
|
|
|
|
|
/*
|
mm, swap: use rbtree for swap_extent
swap_extent is used to map swap page offset to backing device's block
offset. For a continuous block range, one swap_extent is used and all
these swap_extents are managed in a linked list.
These swap_extents are used by map_swap_entry() during swap's read and
write path. To find out the backing device's block offset for a page
offset, the swap_extent list will be traversed linearly, with
curr_swap_extent being used as a cache to speed up the search.
This works well as long as swap_extents are not huge or when the number
of processes that access swap device are few, but when the swap device
has many extents and there are a number of processes accessing the swap
device concurrently, it can be a problem. On one of our servers, the
disk's remaining size is tight:
$df -h
Filesystem Size Used Avail Use% Mounted on
... ...
/dev/nvme0n1p1 1.8T 1.3T 504G 72% /home/t4
When creating a 80G swapfile there, there are as many as 84656 swap
extents. The end result is, kernel spends abou 30% time in
map_swap_entry() and swap throughput is only 70MB/s.
As a comparison, when I used smaller sized swapfile, like 4G whose
swap_extent dropped to 2000, swap throughput is back to 400-500MB/s and
map_swap_entry() is about 3%.
One downside of using rbtree for swap_extent is, 'struct rbtree' takes
24 bytes while 'struct list_head' takes 16 bytes, that's 8 bytes more
for each swap_extent. For a swapfile that has 80k swap_extents, that
means 625KiB more memory consumed.
Test:
Since it's not possible to reboot that server, I can not test this patch
diretly there. Instead, I tested it on another server with NVMe disk.
I created a 20G swapfile on an NVMe backed XFS fs. By default, the
filesystem is quite clean and the created swapfile has only 2 extents.
Testing vanilla and this patch shows no obvious performance difference
when swapfile is not fragmented.
To see the patch's effects, I used some tweaks to manually fragment the
swapfile by breaking the extent at 1M boundary. This made the swapfile
have 20K extents.
nr_task=4
kernel swapout(KB/s) map_swap_entry(perf) swapin(KB/s) map_swap_entry(perf)
vanilla 165191 90.77% 171798 90.21%
patched 858993 +420% 2.16% 715827 +317% 0.77%
nr_task=8
kernel swapout(KB/s) map_swap_entry(perf) swapin(KB/s) map_swap_entry(perf)
vanilla 306783 92.19% 318145 87.76%
patched 954437 +211% 2.35% 1073741 +237% 1.57%
swapout: the throughput of swap out, in KB/s, higher is better 1st
map_swap_entry: cpu cycles percent sampled by perf swapin: the
throughput of swap in, in KB/s, higher is better. 2nd map_swap_entry:
cpu cycles percent sampled by perf
nr_task=1 doesn't show any difference, this is due to the curr_swap_extent
can be effectively used to cache the correct swap extent for single task
workload.
[akpm@linux-foundation.org: s/BUG_ON(1)/BUG()/]
Link: http://lkml.kernel.org/r/20190523142404.GA181@aaronlu
Signed-off-by: Aaron Lu <ziqian.lzq@antfin.com>
Cc: Huang Ying <ying.huang@intel.com>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-07-12 11:55:41 +08:00
|
|
|
* Map all the blocks into the extent tree. This code doesn't try
|
2012-08-01 07:44:57 +08:00
|
|
|
* 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 06:48:47 +08:00
|
|
|
cond_resched();
|
|
|
|
|
2020-01-09 21:30:41 +08:00
|
|
|
first_block = probe_block;
|
|
|
|
ret = bmap(inode, &first_block);
|
|
|
|
if (ret || !first_block)
|
2012-08-01 07:44:57 +08:00
|
|
|
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;
|
|
|
|
|
2020-01-09 21:30:41 +08:00
|
|
|
block = probe_block + block_in_page;
|
|
|
|
ret = bmap(inode, &block);
|
|
|
|
if (ret || !block)
|
2012-08-01 07:44:57 +08:00
|
|
|
goto bad_bmap;
|
2020-01-09 21:30:41 +08:00
|
|
|
|
2012-08-01 07:44:57 +08:00
|
|
|
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-18 05:19:50 +08:00
|
|
|
pr_err("swapon: swapfile has holes\n");
|
2012-08-01 07:44:57 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08: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 06:08:34 +08:00
|
|
|
int ret = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-01-07 06:39:36 +08:00
|
|
|
if (try_to_free_swap(page)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
unlock_page(page);
|
|
|
|
goto out;
|
|
|
|
}
|
2020-05-13 23:37:49 +08:00
|
|
|
/*
|
|
|
|
* Arch code may have to preserve more data than just the page
|
|
|
|
* contents, e.g. memory tags.
|
|
|
|
*/
|
|
|
|
ret = arch_prepare_to_swap(page);
|
|
|
|
if (ret) {
|
|
|
|
set_page_dirty(page);
|
|
|
|
unlock_page(page);
|
|
|
|
goto out;
|
|
|
|
}
|
2012-05-15 23:32:15 +08:00
|
|
|
if (frontswap_store(page) == 0) {
|
2012-04-10 07:08:06 +08:00
|
|
|
set_page_writeback(page);
|
|
|
|
unlock_page(page);
|
|
|
|
end_page_writeback(page);
|
|
|
|
goto out;
|
|
|
|
}
|
2013-04-30 06:08:35 +08:00
|
|
|
ret = __swap_writepage(page, wbc, end_swap_bio_write);
|
2013-04-30 06:08:34 +08:00
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-07 07:22:30 +08:00
|
|
|
static inline void count_swpout_vm_event(struct page *page)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
|
|
|
|
if (unlikely(PageTransHuge(page)))
|
|
|
|
count_vm_event(THP_SWPOUT);
|
|
|
|
#endif
|
2020-08-15 08:30:37 +08:00
|
|
|
count_vm_events(PSWPOUT, thp_nr_pages(page));
|
2017-09-07 07:22:30 +08:00
|
|
|
}
|
|
|
|
|
2020-06-27 15:31:50 +08:00
|
|
|
#if defined(CONFIG_MEMCG) && defined(CONFIG_BLK_CGROUP)
|
|
|
|
static void bio_associate_blkg_from_page(struct bio *bio, struct page *page)
|
|
|
|
{
|
|
|
|
struct cgroup_subsys_state *css;
|
mm: memcontrol: Use helpers to read page's memcg data
Patch series "mm: allow mapping accounted kernel pages to userspace", v6.
Currently a non-slab kernel page which has been charged to a memory cgroup
can't be mapped to userspace. The underlying reason is simple: PageKmemcg
flag is defined as a page type (like buddy, offline, etc), so it takes a
bit from a page->mapped counter. Pages with a type set can't be mapped to
userspace.
But in general the kmemcg flag has nothing to do with mapping to
userspace. It only means that the page has been accounted by the page
allocator, so it has to be properly uncharged on release.
Some bpf maps are mapping the vmalloc-based memory to userspace, and their
memory can't be accounted because of this implementation detail.
This patchset removes this limitation by moving the PageKmemcg flag into
one of the free bits of the page->mem_cgroup pointer. Also it formalizes
accesses to the page->mem_cgroup and page->obj_cgroups using new helpers,
adds several checks and removes a couple of obsolete functions. As the
result the code became more robust with fewer open-coded bit tricks.
This patch (of 4):
Currently there are many open-coded reads of the page->mem_cgroup pointer,
as well as a couple of read helpers, which are barely used.
It creates an obstacle on a way to reuse some bits of the pointer for
storing additional bits of information. In fact, we already do this for
slab pages, where the last bit indicates that a pointer has an attached
vector of objcg pointers instead of a regular memcg pointer.
This commits uses 2 existing helpers and introduces a new helper to
converts all read sides to calls of these helpers:
struct mem_cgroup *page_memcg(struct page *page);
struct mem_cgroup *page_memcg_rcu(struct page *page);
struct mem_cgroup *page_memcg_check(struct page *page);
page_memcg_check() is intended to be used in cases when the page can be a
slab page and have a memcg pointer pointing at objcg vector. It does
check the lowest bit, and if set, returns NULL. page_memcg() contains a
VM_BUG_ON_PAGE() check for the page not being a slab page.
To make sure nobody uses a direct access, struct page's
mem_cgroup/obj_cgroups is converted to unsigned long memcg_data.
Signed-off-by: Roman Gushchin <guro@fb.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Michal Hocko <mhocko@suse.com>
Link: https://lkml.kernel.org/r/20201027001657.3398190-1-guro@fb.com
Link: https://lkml.kernel.org/r/20201027001657.3398190-2-guro@fb.com
Link: https://lore.kernel.org/bpf/20201201215900.3569844-2-guro@fb.com
2020-12-02 05:58:27 +08:00
|
|
|
struct mem_cgroup *memcg;
|
2020-06-27 15:31:50 +08:00
|
|
|
|
mm: memcontrol: Use helpers to read page's memcg data
Patch series "mm: allow mapping accounted kernel pages to userspace", v6.
Currently a non-slab kernel page which has been charged to a memory cgroup
can't be mapped to userspace. The underlying reason is simple: PageKmemcg
flag is defined as a page type (like buddy, offline, etc), so it takes a
bit from a page->mapped counter. Pages with a type set can't be mapped to
userspace.
But in general the kmemcg flag has nothing to do with mapping to
userspace. It only means that the page has been accounted by the page
allocator, so it has to be properly uncharged on release.
Some bpf maps are mapping the vmalloc-based memory to userspace, and their
memory can't be accounted because of this implementation detail.
This patchset removes this limitation by moving the PageKmemcg flag into
one of the free bits of the page->mem_cgroup pointer. Also it formalizes
accesses to the page->mem_cgroup and page->obj_cgroups using new helpers,
adds several checks and removes a couple of obsolete functions. As the
result the code became more robust with fewer open-coded bit tricks.
This patch (of 4):
Currently there are many open-coded reads of the page->mem_cgroup pointer,
as well as a couple of read helpers, which are barely used.
It creates an obstacle on a way to reuse some bits of the pointer for
storing additional bits of information. In fact, we already do this for
slab pages, where the last bit indicates that a pointer has an attached
vector of objcg pointers instead of a regular memcg pointer.
This commits uses 2 existing helpers and introduces a new helper to
converts all read sides to calls of these helpers:
struct mem_cgroup *page_memcg(struct page *page);
struct mem_cgroup *page_memcg_rcu(struct page *page);
struct mem_cgroup *page_memcg_check(struct page *page);
page_memcg_check() is intended to be used in cases when the page can be a
slab page and have a memcg pointer pointing at objcg vector. It does
check the lowest bit, and if set, returns NULL. page_memcg() contains a
VM_BUG_ON_PAGE() check for the page not being a slab page.
To make sure nobody uses a direct access, struct page's
mem_cgroup/obj_cgroups is converted to unsigned long memcg_data.
Signed-off-by: Roman Gushchin <guro@fb.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Michal Hocko <mhocko@suse.com>
Link: https://lkml.kernel.org/r/20201027001657.3398190-1-guro@fb.com
Link: https://lkml.kernel.org/r/20201027001657.3398190-2-guro@fb.com
Link: https://lore.kernel.org/bpf/20201201215900.3569844-2-guro@fb.com
2020-12-02 05:58:27 +08:00
|
|
|
memcg = page_memcg(page);
|
|
|
|
if (!memcg)
|
2020-06-27 15:31:50 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
mm: memcontrol: Use helpers to read page's memcg data
Patch series "mm: allow mapping accounted kernel pages to userspace", v6.
Currently a non-slab kernel page which has been charged to a memory cgroup
can't be mapped to userspace. The underlying reason is simple: PageKmemcg
flag is defined as a page type (like buddy, offline, etc), so it takes a
bit from a page->mapped counter. Pages with a type set can't be mapped to
userspace.
But in general the kmemcg flag has nothing to do with mapping to
userspace. It only means that the page has been accounted by the page
allocator, so it has to be properly uncharged on release.
Some bpf maps are mapping the vmalloc-based memory to userspace, and their
memory can't be accounted because of this implementation detail.
This patchset removes this limitation by moving the PageKmemcg flag into
one of the free bits of the page->mem_cgroup pointer. Also it formalizes
accesses to the page->mem_cgroup and page->obj_cgroups using new helpers,
adds several checks and removes a couple of obsolete functions. As the
result the code became more robust with fewer open-coded bit tricks.
This patch (of 4):
Currently there are many open-coded reads of the page->mem_cgroup pointer,
as well as a couple of read helpers, which are barely used.
It creates an obstacle on a way to reuse some bits of the pointer for
storing additional bits of information. In fact, we already do this for
slab pages, where the last bit indicates that a pointer has an attached
vector of objcg pointers instead of a regular memcg pointer.
This commits uses 2 existing helpers and introduces a new helper to
converts all read sides to calls of these helpers:
struct mem_cgroup *page_memcg(struct page *page);
struct mem_cgroup *page_memcg_rcu(struct page *page);
struct mem_cgroup *page_memcg_check(struct page *page);
page_memcg_check() is intended to be used in cases when the page can be a
slab page and have a memcg pointer pointing at objcg vector. It does
check the lowest bit, and if set, returns NULL. page_memcg() contains a
VM_BUG_ON_PAGE() check for the page not being a slab page.
To make sure nobody uses a direct access, struct page's
mem_cgroup/obj_cgroups is converted to unsigned long memcg_data.
Signed-off-by: Roman Gushchin <guro@fb.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Michal Hocko <mhocko@suse.com>
Link: https://lkml.kernel.org/r/20201027001657.3398190-1-guro@fb.com
Link: https://lkml.kernel.org/r/20201027001657.3398190-2-guro@fb.com
Link: https://lore.kernel.org/bpf/20201201215900.3569844-2-guro@fb.com
2020-12-02 05:58:27 +08:00
|
|
|
css = cgroup_e_css(memcg->css.cgroup, &io_cgrp_subsys);
|
2020-06-27 15:31:50 +08:00
|
|
|
bio_associate_blkg_from_css(bio, css);
|
|
|
|
rcu_read_unlock();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define bio_associate_blkg_from_page(bio, page) do { } while (0)
|
|
|
|
#endif /* CONFIG_MEMCG && CONFIG_BLK_CGROUP */
|
|
|
|
|
2013-04-30 06:08:35 +08:00
|
|
|
int __swap_writepage(struct page *page, struct writeback_control *wbc,
|
2015-07-20 21:29:37 +08:00
|
|
|
bio_end_io_t end_write_func)
|
2013-04-30 06:08:34 +08:00
|
|
|
{
|
|
|
|
struct bio *bio;
|
2016-06-06 03:31:41 +08:00
|
|
|
int ret;
|
2013-04-30 06:08:34 +08:00
|
|
|
struct swap_info_struct *sis = page_swap_info(page);
|
2012-08-01 07:44:55 +08:00
|
|
|
|
2016-10-08 08:00:52 +08:00
|
|
|
VM_BUG_ON_PAGE(!PageSwapCache(page), page);
|
2020-10-14 07:52:04 +08:00
|
|
|
if (data_race(sis->flags & SWP_FS_OPS)) {
|
2012-08-01 07:44:55 +08:00
|
|
|
struct kiocb kiocb;
|
|
|
|
struct file *swap_file = sis->swap_file;
|
|
|
|
struct address_space *mapping = swap_file->f_mapping;
|
2014-04-05 11:12:29 +08:00
|
|
|
struct bio_vec bv = {
|
|
|
|
.bv_page = page,
|
|
|
|
.bv_len = PAGE_SIZE,
|
|
|
|
.bv_offset = 0
|
|
|
|
};
|
2015-01-23 14:08:07 +08:00
|
|
|
struct iov_iter from;
|
2012-08-01 07:44:55 +08:00
|
|
|
|
2018-10-20 07:57:56 +08:00
|
|
|
iov_iter_bvec(&from, WRITE, &bv, 1, PAGE_SIZE);
|
2012-08-01 07:44:55 +08:00
|
|
|
init_sync_kiocb(&kiocb, swap_file);
|
|
|
|
kiocb.ki_pos = page_file_offset(page);
|
|
|
|
|
2013-04-30 06:08:48 +08:00
|
|
|
set_page_writeback(page);
|
2012-08-01 07:44:55 +08:00
|
|
|
unlock_page(page);
|
2016-04-07 23:51:58 +08:00
|
|
|
ret = mapping->a_ops->direct_IO(&kiocb, &from);
|
2012-08-01 07:44:55 +08:00
|
|
|
if (ret == PAGE_SIZE) {
|
|
|
|
count_vm_event(PSWPOUT);
|
|
|
|
ret = 0;
|
2013-04-30 06:08:47 +08:00
|
|
|
} else {
|
2013-04-30 06:08:48 +08: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
|
2020-12-08 14:25:39 +08:00
|
|
|
* folio_rotate_reclaimable but rate-limit the
|
2013-04-30 06:08:48 +08:00
|
|
|
* messages but do not flag PageError like
|
|
|
|
* the normal direct-to-bio case as it could
|
|
|
|
* be temporary.
|
|
|
|
*/
|
2013-04-30 06:08:47 +08:00
|
|
|
set_page_dirty(page);
|
2013-04-30 06:08:48 +08:00
|
|
|
ClearPageReclaim(page);
|
2016-03-18 05:19:50 +08:00
|
|
|
pr_err_ratelimited("Write error on dio swapfile (%llu)\n",
|
|
|
|
page_file_offset(page));
|
2012-08-01 07:44:55 +08:00
|
|
|
}
|
2013-04-30 06:08:48 +08:00
|
|
|
end_page_writeback(page);
|
2012-08-01 07:44:55 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-06-05 07:07:48 +08:00
|
|
|
ret = bdev_write_page(sis->bdev, swap_page_sector(page), page, wbc);
|
|
|
|
if (!ret) {
|
2017-09-07 07:22:30 +08:00
|
|
|
count_swpout_vm_event(page);
|
2014-06-05 07:07:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-26 22:52:47 +08:00
|
|
|
bio = bio_alloc(GFP_NOIO, 1);
|
|
|
|
bio_set_dev(bio, sis->bdev);
|
|
|
|
bio->bi_iter.bi_sector = swap_page_sector(page);
|
2018-07-03 23:14:53 +08:00
|
|
|
bio->bi_opf = REQ_OP_WRITE | REQ_SWAP | wbc_to_write_flags(wbc);
|
2021-01-26 22:52:47 +08:00
|
|
|
bio->bi_end_io = end_write_func;
|
|
|
|
bio_add_page(bio, page, thp_size(page), 0);
|
|
|
|
|
2018-12-06 01:10:33 +08:00
|
|
|
bio_associate_blkg_from_page(bio, page);
|
2017-09-07 07:22:30 +08:00
|
|
|
count_swpout_vm_event(page);
|
2005-04-17 06:20:36 +08:00
|
|
|
set_page_writeback(page);
|
|
|
|
unlock_page(page);
|
2016-06-06 03:31:41 +08:00
|
|
|
submit_bio(bio);
|
2020-10-14 07:52:21 +08:00
|
|
|
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2017-11-16 09:33:07 +08:00
|
|
|
int swap_readpage(struct page *page, bool synchronous)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct bio *bio;
|
|
|
|
int ret = 0;
|
2012-08-01 07:44:55 +08:00
|
|
|
struct swap_info_struct *sis = page_swap_info(page);
|
2019-12-01 09:58:29 +08:00
|
|
|
unsigned long pflags;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-11-16 09:33:07 +08:00
|
|
|
VM_BUG_ON_PAGE(!PageSwapCache(page) && !synchronous, page);
|
2014-01-24 07:52:54 +08:00
|
|
|
VM_BUG_ON_PAGE(!PageLocked(page), page);
|
|
|
|
VM_BUG_ON_PAGE(PageUptodate(page), page);
|
2019-12-01 09:58:29 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Count submission time as memory stall. When the device is congested,
|
|
|
|
* or the submitting cgroup IO-throttled, submission can be a
|
|
|
|
* significant part of overall IO time.
|
|
|
|
*/
|
|
|
|
psi_memstall_enter(&pflags);
|
|
|
|
|
2012-05-15 23:32:15 +08:00
|
|
|
if (frontswap_load(page) == 0) {
|
2012-04-10 07:08:06 +08:00
|
|
|
SetPageUptodate(page);
|
|
|
|
unlock_page(page);
|
|
|
|
goto out;
|
|
|
|
}
|
2012-08-01 07:44:55 +08:00
|
|
|
|
2020-10-14 07:52:04 +08:00
|
|
|
if (data_race(sis->flags & SWP_FS_OPS)) {
|
2012-08-01 07:44:55 +08:00
|
|
|
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);
|
2019-12-01 09:58:29 +08:00
|
|
|
goto out;
|
2012-08-01 07:44:55 +08:00
|
|
|
}
|
|
|
|
|
2020-09-24 14:51:37 +08:00
|
|
|
if (sis->flags & SWP_SYNCHRONOUS_IO) {
|
|
|
|
ret = bdev_read_page(sis->bdev, swap_page_sector(page), page);
|
|
|
|
if (!ret) {
|
|
|
|
if (trylock_page(page)) {
|
|
|
|
swap_slot_free_notify(page);
|
|
|
|
unlock_page(page);
|
|
|
|
}
|
2016-04-29 07:18:41 +08:00
|
|
|
|
2020-09-24 14:51:37 +08:00
|
|
|
count_vm_event(PSWPIN);
|
|
|
|
goto out;
|
|
|
|
}
|
2014-06-05 07:07:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2021-01-26 22:52:47 +08:00
|
|
|
bio = bio_alloc(GFP_KERNEL, 1);
|
|
|
|
bio_set_dev(bio, sis->bdev);
|
|
|
|
bio->bi_opf = REQ_OP_READ;
|
|
|
|
bio->bi_iter.bi_sector = swap_page_sector(page);
|
|
|
|
bio->bi_end_io = end_swap_bio_read;
|
|
|
|
bio_add_page(bio, page, thp_size(page), 0);
|
2017-08-03 04:32:09 +08:00
|
|
|
/*
|
|
|
|
* Keep this task valid during swap readpage because the oom killer may
|
|
|
|
* attempt to access it in the page fault retry time check.
|
|
|
|
*/
|
2019-07-05 06:14:49 +08:00
|
|
|
if (synchronous) {
|
2021-10-12 19:12:21 +08:00
|
|
|
bio->bi_opf |= REQ_POLLED;
|
2019-07-05 06:14:49 +08:00
|
|
|
get_task_struct(current);
|
|
|
|
bio->bi_private = current;
|
|
|
|
}
|
2006-06-30 16:55:45 +08:00
|
|
|
count_vm_event(PSWPIN);
|
swap: add block io poll in swapin path
For fast flash disk, async IO could introduce overhead because of
context switch. block-mq now supports IO poll, which improves
performance and latency a lot. swapin is a good place to use this
technique, because the task is waiting for the swapin page to continue
execution.
In my virtual machine, directly read 4k data from a NVMe with iopoll is
about 60% better than that without poll. With iopoll support in swapin
patch, my microbenchmark (a task does random memory write) is about
10%~25% faster. CPU utilization increases a lot though, 2x and even 3x
CPU utilization. This will depend on disk speed.
While iopoll in swapin isn't intended for all usage cases, it's a win
for latency sensistive workloads with high speed swap disk. block layer
has knob to control poll in runtime. If poll isn't enabled in block
layer, there should be no noticeable change in swapin.
I got a chance to run the same test in a NVMe with DRAM as the media.
In simple fio IO test, blkpoll boosts 50% performance in single thread
test and ~20% in 8 threads test. So this is the base line. In above
swap test, blkpoll boosts ~27% performance in single thread test.
blkpoll uses 2x CPU time though.
If we enable hybid polling, the performance gain has very slight drop
but CPU time is only 50% worse than that without blkpoll. Also we can
adjust parameter of hybid poll, with it, the CPU time penality is
reduced further. In 8 threads test, blkpoll doesn't help though. The
performance is similar to that without blkpoll, but cpu utilization is
similar too. There is lock contention in swap path. The cpu time
spending on blkpoll isn't high. So overall, blkpoll swapin isn't worse
than that without it.
The swapin readahead might read several pages in in the same time and
form a big IO request. Since the IO will take longer time, it doesn't
make sense to do poll, so the patch only does iopoll for single page
swapin.
[akpm@linux-foundation.org: coding-style fixes]
Link: http://lkml.kernel.org/r/070c3c3e40b711e7b1390002c991e86a-b5408f0@7511894063d3764ff01ea8111f5a004d7dd700ed078797c204a24e620ddb965c
Signed-off-by: Shaohua Li <shli@fb.com>
Cc: Tim Chen <tim.c.chen@intel.com>
Cc: Huang Ying <ying.huang@intel.com>
Cc: Jens Axboe <axboe@fb.com>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-07-11 06:47:11 +08:00
|
|
|
bio_get(bio);
|
2021-10-12 19:12:24 +08:00
|
|
|
submit_bio(bio);
|
2017-11-16 09:33:07 +08:00
|
|
|
while (synchronous) {
|
2019-01-03 02:46:03 +08:00
|
|
|
set_current_state(TASK_UNINTERRUPTIBLE);
|
swap: add block io poll in swapin path
For fast flash disk, async IO could introduce overhead because of
context switch. block-mq now supports IO poll, which improves
performance and latency a lot. swapin is a good place to use this
technique, because the task is waiting for the swapin page to continue
execution.
In my virtual machine, directly read 4k data from a NVMe with iopoll is
about 60% better than that without poll. With iopoll support in swapin
patch, my microbenchmark (a task does random memory write) is about
10%~25% faster. CPU utilization increases a lot though, 2x and even 3x
CPU utilization. This will depend on disk speed.
While iopoll in swapin isn't intended for all usage cases, it's a win
for latency sensistive workloads with high speed swap disk. block layer
has knob to control poll in runtime. If poll isn't enabled in block
layer, there should be no noticeable change in swapin.
I got a chance to run the same test in a NVMe with DRAM as the media.
In simple fio IO test, blkpoll boosts 50% performance in single thread
test and ~20% in 8 threads test. So this is the base line. In above
swap test, blkpoll boosts ~27% performance in single thread test.
blkpoll uses 2x CPU time though.
If we enable hybid polling, the performance gain has very slight drop
but CPU time is only 50% worse than that without blkpoll. Also we can
adjust parameter of hybid poll, with it, the CPU time penality is
reduced further. In 8 threads test, blkpoll doesn't help though. The
performance is similar to that without blkpoll, but cpu utilization is
similar too. There is lock contention in swap path. The cpu time
spending on blkpoll isn't high. So overall, blkpoll swapin isn't worse
than that without it.
The swapin readahead might read several pages in in the same time and
form a big IO request. Since the IO will take longer time, it doesn't
make sense to do poll, so the patch only does iopoll for single page
swapin.
[akpm@linux-foundation.org: coding-style fixes]
Link: http://lkml.kernel.org/r/070c3c3e40b711e7b1390002c991e86a-b5408f0@7511894063d3764ff01ea8111f5a004d7dd700ed078797c204a24e620ddb965c
Signed-off-by: Shaohua Li <shli@fb.com>
Cc: Tim Chen <tim.c.chen@intel.com>
Cc: Huang Ying <ying.huang@intel.com>
Cc: Jens Axboe <axboe@fb.com>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-07-11 06:47:11 +08:00
|
|
|
if (!READ_ONCE(bio->bi_private))
|
|
|
|
break;
|
|
|
|
|
2021-10-12 23:24:29 +08:00
|
|
|
if (!bio_poll(bio, NULL, 0))
|
2020-08-07 14:20:17 +08:00
|
|
|
blk_io_schedule();
|
swap: add block io poll in swapin path
For fast flash disk, async IO could introduce overhead because of
context switch. block-mq now supports IO poll, which improves
performance and latency a lot. swapin is a good place to use this
technique, because the task is waiting for the swapin page to continue
execution.
In my virtual machine, directly read 4k data from a NVMe with iopoll is
about 60% better than that without poll. With iopoll support in swapin
patch, my microbenchmark (a task does random memory write) is about
10%~25% faster. CPU utilization increases a lot though, 2x and even 3x
CPU utilization. This will depend on disk speed.
While iopoll in swapin isn't intended for all usage cases, it's a win
for latency sensistive workloads with high speed swap disk. block layer
has knob to control poll in runtime. If poll isn't enabled in block
layer, there should be no noticeable change in swapin.
I got a chance to run the same test in a NVMe with DRAM as the media.
In simple fio IO test, blkpoll boosts 50% performance in single thread
test and ~20% in 8 threads test. So this is the base line. In above
swap test, blkpoll boosts ~27% performance in single thread test.
blkpoll uses 2x CPU time though.
If we enable hybid polling, the performance gain has very slight drop
but CPU time is only 50% worse than that without blkpoll. Also we can
adjust parameter of hybid poll, with it, the CPU time penality is
reduced further. In 8 threads test, blkpoll doesn't help though. The
performance is similar to that without blkpoll, but cpu utilization is
similar too. There is lock contention in swap path. The cpu time
spending on blkpoll isn't high. So overall, blkpoll swapin isn't worse
than that without it.
The swapin readahead might read several pages in in the same time and
form a big IO request. Since the IO will take longer time, it doesn't
make sense to do poll, so the patch only does iopoll for single page
swapin.
[akpm@linux-foundation.org: coding-style fixes]
Link: http://lkml.kernel.org/r/070c3c3e40b711e7b1390002c991e86a-b5408f0@7511894063d3764ff01ea8111f5a004d7dd700ed078797c204a24e620ddb965c
Signed-off-by: Shaohua Li <shli@fb.com>
Cc: Tim Chen <tim.c.chen@intel.com>
Cc: Huang Ying <ying.huang@intel.com>
Cc: Jens Axboe <axboe@fb.com>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-07-11 06:47:11 +08:00
|
|
|
}
|
|
|
|
__set_current_state(TASK_RUNNING);
|
|
|
|
bio_put(bio);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
out:
|
2019-12-01 09:58:29 +08:00
|
|
|
psi_memstall_leave(&pflags);
|
2005-04-17 06:20:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2012-08-01 07:44:55 +08:00
|
|
|
|
|
|
|
int swap_set_page_dirty(struct page *page)
|
|
|
|
{
|
|
|
|
struct swap_info_struct *sis = page_swap_info(page);
|
|
|
|
|
2020-10-14 07:52:04 +08:00
|
|
|
if (data_race(sis->flags & SWP_FS_OPS)) {
|
2012-08-01 07:44:55 +08:00
|
|
|
struct address_space *mapping = sis->swap_file->f_mapping;
|
2016-10-08 08:00:52 +08:00
|
|
|
|
|
|
|
VM_BUG_ON_PAGE(!PageSwapCache(page), page);
|
2012-08-01 07:44:55 +08:00
|
|
|
return mapping->a_ops->set_page_dirty(page);
|
|
|
|
} else {
|
|
|
|
return __set_page_dirty_no_writeback(page);
|
|
|
|
}
|
|
|
|
}
|