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 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-16 22:20:36 +00: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 08:04:11 +00:00
|
|
|
#include <linux/gfp.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/swap.h>
|
|
|
|
#include <linux/bio.h>
|
|
|
|
#include <linux/swapops.h>
|
|
|
|
#include <linux/writeback.h>
|
2013-07-03 22:01:24 +00:00
|
|
|
#include <linux/blkdev.h>
|
2019-12-01 01:58:29 +00:00
|
|
|
#include <linux/psi.h>
|
2015-02-22 16:58:50 +00:00
|
|
|
#include <linux/uio.h>
|
2017-08-02 20:32:09 +00:00
|
|
|
#include <linux/sched/task.h>
|
2022-01-20 02:10:02 +00:00
|
|
|
#include <linux/delayacct.h>
|
2023-07-17 16:02:27 +00:00
|
|
|
#include <linux/zswap.h>
|
2022-05-10 01:20:47 +00:00
|
|
|
#include "swap.h"
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2023-01-25 13:34:36 +00:00
|
|
|
static void __end_swap_bio_write(struct bio *bio)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2023-07-21 03:44:45 +00:00
|
|
|
struct folio *folio = bio_first_folio_all(bio);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-06-03 07:38:06 +00:00
|
|
|
if (bio->bi_status) {
|
2006-09-26 06:31:26 +00: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 06:25:39 +00:00
|
|
|
* Also clear PG_reclaim to avoid folio_rotate_reclaimable()
|
2006-09-26 06:31:26 +00:00
|
|
|
*/
|
2023-07-21 03:44:45 +00:00
|
|
|
folio_mark_dirty(folio);
|
2021-02-24 20:03:01 +00: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);
|
2023-07-21 03:44:45 +00:00
|
|
|
folio_clear_reclaim(folio);
|
2006-09-26 06:31:26 +00:00
|
|
|
}
|
2023-07-21 03:44:45 +00:00
|
|
|
folio_end_writeback(folio);
|
2023-01-25 13:34:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void end_swap_bio_write(struct bio *bio)
|
|
|
|
{
|
|
|
|
__end_swap_bio_write(bio);
|
2005-04-16 22:20:36 +00:00
|
|
|
bio_put(bio);
|
|
|
|
}
|
|
|
|
|
2023-01-25 13:34:33 +00:00
|
|
|
static void __end_swap_bio_read(struct bio *bio)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2023-07-21 03:44:46 +00:00
|
|
|
struct folio *folio = bio_first_folio_all(bio);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-06-03 07:38:06 +00:00
|
|
|
if (bio->bi_status) {
|
2021-02-24 20:03:01 +00: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);
|
2023-01-25 13:34:33 +00:00
|
|
|
} else {
|
2023-07-21 03:44:46 +00:00
|
|
|
folio_mark_uptodate(folio);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2023-07-21 03:44:46 +00:00
|
|
|
folio_unlock(folio);
|
2023-01-25 13:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void end_swap_bio_read(struct bio *bio)
|
|
|
|
{
|
|
|
|
__end_swap_bio_read(bio);
|
2005-04-16 22:20:36 +00:00
|
|
|
bio_put(bio);
|
|
|
|
}
|
|
|
|
|
2012-07-31 23:44:57 +00: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 03:55:41 +00:00
|
|
|
* Map all the blocks into the extent tree. This code doesn't try
|
2012-07-31 23:44:57 +00: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-28 22:48:47 +00:00
|
|
|
cond_resched();
|
|
|
|
|
2020-01-09 13:30:41 +00:00
|
|
|
first_block = probe_block;
|
|
|
|
ret = bmap(inode, &first_block);
|
|
|
|
if (ret || !first_block)
|
2012-07-31 23:44:57 +00: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 13:30:41 +00:00
|
|
|
block = probe_block + block_in_page;
|
|
|
|
ret = bmap(inode, &block);
|
|
|
|
if (ret || !block)
|
2012-07-31 23:44:57 +00:00
|
|
|
goto bad_bmap;
|
2020-01-09 13:30:41 +00:00
|
|
|
|
2012-07-31 23:44:57 +00: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-17 21:19:50 +00:00
|
|
|
pr_err("swapon: swapfile has holes\n");
|
2012-07-31 23:44:57 +00:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00: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)
|
|
|
|
{
|
2022-09-02 19:46:36 +00:00
|
|
|
struct folio *folio = page_folio(page);
|
2023-01-25 13:34:34 +00:00
|
|
|
int ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2022-09-02 19:46:36 +00:00
|
|
|
if (folio_free_swap(folio)) {
|
|
|
|
folio_unlock(folio);
|
2023-01-25 13:34:34 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2020-05-13 15:37:49 +00:00
|
|
|
/*
|
|
|
|
* Arch code may have to preserve more data than just the page
|
|
|
|
* contents, e.g. memory tags.
|
|
|
|
*/
|
arm64: mm: swap: support THP_SWAP on hardware with MTE
Commit d0637c505f8a1 ("arm64: enable THP_SWAP for arm64") brings up
THP_SWAP on ARM64, but it doesn't enable THP_SWP on hardware with MTE as
the MTE code works with the assumption tags save/restore is always
handling a folio with only one page.
The limitation should be removed as more and more ARM64 SoCs have this
feature. Co-existence of MTE and THP_SWAP becomes more and more
important.
This patch makes MTE tags saving support large folios, then we don't need
to split large folios into base pages for swapping out on ARM64 SoCs with
MTE any more.
arch_prepare_to_swap() should take folio rather than page as parameter
because we support THP swap-out as a whole. It saves tags for all pages
in a large folio.
As now we are restoring tags based-on folio, in arch_swap_restore(), we
may increase some extra loops and early-exitings while refaulting a large
folio which is still in swapcache in do_swap_page(). In case a large
folio has nr pages, do_swap_page() will only set the PTE of the particular
page which is causing the page fault. Thus do_swap_page() runs nr times,
and each time, arch_swap_restore() will loop nr times for those subpages
in the folio. So right now the algorithmic complexity becomes O(nr^2).
Once we support mapping large folios in do_swap_page(), extra loops and
early-exitings will decrease while not being completely removed as a large
folio might get partially tagged in corner cases such as, 1. a large
folio in swapcache can be partially unmapped, thus, MTE tags for the
unmapped pages will be invalidated; 2. users might use mprotect() to set
MTEs on a part of a large folio.
arch_thp_swp_supported() is dropped since ARM64 MTE was the only one who
needed it.
Link: https://lkml.kernel.org/r/20240322114136.61386-2-21cnbao@gmail.com
Signed-off-by: Barry Song <v-songbaohua@oppo.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Acked-by: Chris Li <chrisl@kernel.org>
Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Kemeng Shi <shikemeng@huaweicloud.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Peter Collingbourne <pcc@google.com>
Cc: Yosry Ahmed <yosryahmed@google.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Lorenzo Stoakes <lstoakes@gmail.com>
Cc: "Mike Rapoport (IBM)" <rppt@kernel.org>
Cc: Hugh Dickins <hughd@google.com>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>
Cc: Rick Edgecombe <rick.p.edgecombe@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-03-22 11:41:36 +00:00
|
|
|
ret = arch_prepare_to_swap(folio);
|
2020-05-13 15:37:49 +00:00
|
|
|
if (ret) {
|
2022-09-02 19:46:36 +00:00
|
|
|
folio_mark_dirty(folio);
|
|
|
|
folio_unlock(folio);
|
2023-01-25 13:34:34 +00:00
|
|
|
return ret;
|
2020-05-13 15:37:49 +00:00
|
|
|
}
|
2023-07-15 04:23:40 +00:00
|
|
|
if (zswap_store(folio)) {
|
2022-09-02 19:46:36 +00:00
|
|
|
folio_unlock(folio);
|
2023-01-25 13:34:34 +00:00
|
|
|
return 0;
|
2012-04-09 23:08:06 +00:00
|
|
|
}
|
zswap: memcontrol: implement zswap writeback disabling
During our experiment with zswap, we sometimes observe swap IOs due to
occasional zswap store failures and writebacks-to-swap. These swapping
IOs prevent many users who cannot tolerate swapping from adopting zswap to
save memory and improve performance where possible.
This patch adds the option to disable this behavior entirely: do not
writeback to backing swapping device when a zswap store attempt fail, and
do not write pages in the zswap pool back to the backing swap device (both
when the pool is full, and when the new zswap shrinker is called).
This new behavior can be opted-in/out on a per-cgroup basis via a new
cgroup file. By default, writebacks to swap device is enabled, which is
the previous behavior. Initially, writeback is enabled for the root
cgroup, and a newly created cgroup will inherit the current setting of its
parent.
Note that this is subtly different from setting memory.swap.max to 0, as
it still allows for pages to be stored in the zswap pool (which itself
consumes swap space in its current form).
This patch should be applied on top of the zswap shrinker series:
https://lore.kernel.org/linux-mm/20231130194023.4102148-1-nphamcs@gmail.com/
as it also disables the zswap shrinker, a major source of zswap
writebacks.
For the most part, this feature is motivated by internal parties who
have already established their opinions regarding swapping - the
workloads that are highly sensitive to IO, and especially those who are
using servers with really slow disk performance (for instance, massive
but slow HDDs). For these folks, it's impossible to convince them to
even entertain zswap if swapping also comes as a packaged deal.
Writeback disabling is quite a useful feature in these situations - on
a mixed workloads deployment, they can disable writeback for the more
IO-sensitive workloads, and enable writeback for other background
workloads.
For instance, on a server with HDD, I allocate memories and populate
them with random values (so that zswap store will always fail), and
specify memory.high low enough to trigger reclaim. The time it takes
to allocate the memories and just read through it a couple of times
(doing silly things like computing the values' average etc.):
zswap.writeback disabled:
real 0m30.537s
user 0m23.687s
sys 0m6.637s
0 pages swapped in
0 pages swapped out
zswap.writeback enabled:
real 0m45.061s
user 0m24.310s
sys 0m8.892s
712686 pages swapped in
461093 pages swapped out
(the last two lines are from vmstat -s).
[nphamcs@gmail.com: add a comment about recurring zswap store failures leading to reclaim inefficiency]
Link: https://lkml.kernel.org/r/20231221005725.3446672-1-nphamcs@gmail.com
Link: https://lkml.kernel.org/r/20231207192406.3809579-1-nphamcs@gmail.com
Signed-off-by: Nhat Pham <nphamcs@gmail.com>
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Yosry Ahmed <yosryahmed@google.com>
Acked-by: Chris Li <chrisl@kernel.org>
Cc: Dan Streetman <ddstreet@ieee.org>
Cc: David Heidelberg <david@ixit.cz>
Cc: Domenico Cerasuolo <cerasuolodomenico@gmail.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Seth Jennings <sjenning@redhat.com>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Vitaly Wool <vitaly.wool@konsulko.com>
Cc: Zefan Li <lizefan.x@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-12-07 19:24:06 +00:00
|
|
|
if (!mem_cgroup_zswap_writeback_enabled(folio_memcg(folio))) {
|
|
|
|
folio_mark_dirty(folio);
|
|
|
|
return AOP_WRITEPAGE_ACTIVATE;
|
|
|
|
}
|
|
|
|
|
2023-12-13 21:58:31 +00:00
|
|
|
__swap_writepage(folio, wbc);
|
2023-01-25 13:34:34 +00:00
|
|
|
return 0;
|
2013-04-29 22:08:34 +00:00
|
|
|
}
|
|
|
|
|
2023-07-21 03:44:50 +00:00
|
|
|
static inline void count_swpout_vm_event(struct folio *folio)
|
2017-09-06 23:22:30 +00:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
|
mm: memcg: add THP swap out info for anonymous reclaim
At present, we support per-memcg reclaim strategy, however we do not know
the number of transparent huge pages being reclaimed, as we know the
transparent huge pages need to be splited before reclaim them, and they
will bring some performance bottleneck effect. for example, when two
memcg (A & B) are doing reclaim for anonymous pages at same time, and 'A'
memcg is reclaiming a large number of transparent huge pages, we can
better analyze that the performance bottleneck will be caused by 'A'
memcg. therefore, in order to better analyze such problems, there add THP
swap out info for per-memcg.
[akpm@linux-foundation.orgL fix swap_writepage_fs(), per Johannes]
Link: https://lkml.kernel.org/r/20230913213343.GB48476@cmpxchg.org
Link: https://lkml.kernel.org/r/20230913164938.16918-1-vernhao@tencent.com
Signed-off-by: Xin Hao <vernhao@tencent.com>
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Muchun Song <songmuchun@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-09-13 16:49:37 +00:00
|
|
|
if (unlikely(folio_test_pmd_mappable(folio))) {
|
|
|
|
count_memcg_folio_events(folio, THP_SWPOUT, 1);
|
2017-09-06 23:22:30 +00:00
|
|
|
count_vm_event(THP_SWPOUT);
|
mm: memcg: add THP swap out info for anonymous reclaim
At present, we support per-memcg reclaim strategy, however we do not know
the number of transparent huge pages being reclaimed, as we know the
transparent huge pages need to be splited before reclaim them, and they
will bring some performance bottleneck effect. for example, when two
memcg (A & B) are doing reclaim for anonymous pages at same time, and 'A'
memcg is reclaiming a large number of transparent huge pages, we can
better analyze that the performance bottleneck will be caused by 'A'
memcg. therefore, in order to better analyze such problems, there add THP
swap out info for per-memcg.
[akpm@linux-foundation.orgL fix swap_writepage_fs(), per Johannes]
Link: https://lkml.kernel.org/r/20230913213343.GB48476@cmpxchg.org
Link: https://lkml.kernel.org/r/20230913164938.16918-1-vernhao@tencent.com
Signed-off-by: Xin Hao <vernhao@tencent.com>
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Muchun Song <songmuchun@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-09-13 16:49:37 +00:00
|
|
|
}
|
2024-05-23 02:36:39 +00:00
|
|
|
count_mthp_stat(folio_order(folio), MTHP_STAT_SWPOUT);
|
2017-09-06 23:22:30 +00:00
|
|
|
#endif
|
2023-07-21 03:44:50 +00:00
|
|
|
count_vm_events(PSWPOUT, folio_nr_pages(folio));
|
2017-09-06 23:22:30 +00:00
|
|
|
}
|
|
|
|
|
2020-06-27 07:31:50 +00:00
|
|
|
#if defined(CONFIG_MEMCG) && defined(CONFIG_BLK_CGROUP)
|
2023-07-21 03:44:51 +00:00
|
|
|
static void bio_associate_blkg_from_page(struct bio *bio, struct folio *folio)
|
2020-06-27 07:31:50 +00:00
|
|
|
{
|
|
|
|
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-01 21:58:27 +00:00
|
|
|
struct mem_cgroup *memcg;
|
2020-06-27 07:31:50 +00:00
|
|
|
|
2023-07-21 03:44:51 +00:00
|
|
|
memcg = folio_memcg(folio);
|
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-01 21:58:27 +00:00
|
|
|
if (!memcg)
|
2020-06-27 07:31:50 +00: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-01 21:58:27 +00:00
|
|
|
css = cgroup_e_css(memcg->css.cgroup, &io_cgrp_subsys);
|
2020-06-27 07:31:50 +00:00
|
|
|
bio_associate_blkg_from_css(bio, css);
|
|
|
|
rcu_read_unlock();
|
|
|
|
}
|
|
|
|
#else
|
2023-07-21 03:44:51 +00:00
|
|
|
#define bio_associate_blkg_from_page(bio, folio) do { } while (0)
|
2020-06-27 07:31:50 +00:00
|
|
|
#endif /* CONFIG_MEMCG && CONFIG_BLK_CGROUP */
|
|
|
|
|
2022-05-10 01:20:48 +00:00
|
|
|
struct swap_iocb {
|
|
|
|
struct kiocb iocb;
|
2022-05-10 01:20:49 +00:00
|
|
|
struct bio_vec bvec[SWAP_CLUSTER_MAX];
|
|
|
|
int pages;
|
2022-05-10 01:20:49 +00:00
|
|
|
int len;
|
2022-05-10 01:20:48 +00:00
|
|
|
};
|
|
|
|
static mempool_t *sio_pool;
|
|
|
|
|
|
|
|
int sio_pool_init(void)
|
2013-04-29 22:08:34 +00:00
|
|
|
{
|
2022-05-10 01:20:48 +00:00
|
|
|
if (!sio_pool) {
|
|
|
|
mempool_t *pool = mempool_create_kmalloc_pool(
|
|
|
|
SWAP_CLUSTER_MAX, sizeof(struct swap_iocb));
|
|
|
|
if (cmpxchg(&sio_pool, NULL, pool))
|
|
|
|
mempool_destroy(pool);
|
|
|
|
}
|
|
|
|
if (!sio_pool)
|
|
|
|
return -ENOMEM;
|
|
|
|
return 0;
|
|
|
|
}
|
2012-07-31 23:44:55 +00:00
|
|
|
|
2022-05-10 01:20:48 +00:00
|
|
|
static void sio_write_complete(struct kiocb *iocb, long ret)
|
|
|
|
{
|
|
|
|
struct swap_iocb *sio = container_of(iocb, struct swap_iocb, iocb);
|
2022-05-10 01:20:49 +00:00
|
|
|
struct page *page = sio->bvec[0].bv_page;
|
2022-05-10 01:20:49 +00:00
|
|
|
int p;
|
2012-07-31 23:44:55 +00:00
|
|
|
|
2022-05-10 01:20:49 +00:00
|
|
|
if (ret != sio->len) {
|
2022-05-10 01:20:48 +00: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
|
|
|
|
* folio_rotate_reclaimable but rate-limit the
|
2024-08-07 19:35:25 +00:00
|
|
|
* messages.
|
2022-05-10 01:20:48 +00:00
|
|
|
*/
|
|
|
|
pr_err_ratelimited("Write error %ld on dio swapfile (%llu)\n",
|
2024-05-21 17:58:50 +00:00
|
|
|
ret, swap_dev_pos(page_swap_entry(page)));
|
2022-05-10 01:20:49 +00:00
|
|
|
for (p = 0; p < sio->pages; p++) {
|
|
|
|
page = sio->bvec[p].bv_page;
|
2013-04-29 22:08:47 +00:00
|
|
|
set_page_dirty(page);
|
2013-04-29 22:08:48 +00:00
|
|
|
ClearPageReclaim(page);
|
2012-07-31 23:44:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-10 01:20:49 +00:00
|
|
|
for (p = 0; p < sio->pages; p++)
|
|
|
|
end_page_writeback(sio->bvec[p].bv_page);
|
|
|
|
|
2022-05-10 01:20:48 +00:00
|
|
|
mempool_free(sio, sio_pool);
|
|
|
|
}
|
|
|
|
|
2023-12-13 21:58:32 +00:00
|
|
|
static void swap_writepage_fs(struct folio *folio, struct writeback_control *wbc)
|
2022-05-10 01:20:48 +00:00
|
|
|
{
|
2022-05-10 01:20:49 +00:00
|
|
|
struct swap_iocb *sio = NULL;
|
2023-12-13 21:58:32 +00:00
|
|
|
struct swap_info_struct *sis = swp_swap_info(folio->swap);
|
2022-05-10 01:20:48 +00:00
|
|
|
struct file *swap_file = sis->swap_file;
|
2024-05-21 17:58:50 +00:00
|
|
|
loff_t pos = swap_dev_pos(folio->swap);
|
2022-05-10 01:20:48 +00:00
|
|
|
|
2023-12-13 21:58:32 +00:00
|
|
|
count_swpout_vm_event(folio);
|
|
|
|
folio_start_writeback(folio);
|
|
|
|
folio_unlock(folio);
|
2022-05-10 01:20:49 +00:00
|
|
|
if (wbc->swap_plug)
|
|
|
|
sio = *wbc->swap_plug;
|
|
|
|
if (sio) {
|
|
|
|
if (sio->iocb.ki_filp != swap_file ||
|
2022-05-10 01:20:49 +00:00
|
|
|
sio->iocb.ki_pos + sio->len != pos) {
|
2022-05-10 01:20:49 +00:00
|
|
|
swap_write_unplug(sio);
|
|
|
|
sio = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!sio) {
|
|
|
|
sio = mempool_alloc(sio_pool, GFP_NOIO);
|
|
|
|
init_sync_kiocb(&sio->iocb, swap_file);
|
|
|
|
sio->iocb.ki_complete = sio_write_complete;
|
|
|
|
sio->iocb.ki_pos = pos;
|
|
|
|
sio->pages = 0;
|
2022-05-10 01:20:49 +00:00
|
|
|
sio->len = 0;
|
2022-05-10 01:20:49 +00:00
|
|
|
}
|
2023-12-13 21:58:32 +00:00
|
|
|
bvec_set_folio(&sio->bvec[sio->pages], folio, folio_size(folio), 0);
|
|
|
|
sio->len += folio_size(folio);
|
2022-05-10 01:20:49 +00:00
|
|
|
sio->pages += 1;
|
|
|
|
if (sio->pages == ARRAY_SIZE(sio->bvec) || !wbc->swap_plug) {
|
|
|
|
swap_write_unplug(sio);
|
|
|
|
sio = NULL;
|
|
|
|
}
|
|
|
|
if (wbc->swap_plug)
|
|
|
|
*wbc->swap_plug = sio;
|
2022-05-10 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2023-12-13 21:58:33 +00:00
|
|
|
static void swap_writepage_bdev_sync(struct folio *folio,
|
2023-01-25 13:34:35 +00:00
|
|
|
struct writeback_control *wbc, struct swap_info_struct *sis)
|
2013-04-29 22:08:34 +00:00
|
|
|
{
|
2023-01-25 13:34:36 +00:00
|
|
|
struct bio_vec bv;
|
|
|
|
struct bio bio;
|
2012-07-31 23:44:55 +00:00
|
|
|
|
2023-01-25 13:34:36 +00:00
|
|
|
bio_init(&bio, sis->bdev, &bv, 1,
|
|
|
|
REQ_OP_WRITE | REQ_SWAP | wbc_to_write_flags(wbc));
|
2023-12-13 21:58:38 +00:00
|
|
|
bio.bi_iter.bi_sector = swap_folio_sector(folio);
|
2023-12-13 21:58:33 +00:00
|
|
|
bio_add_folio_nofail(&bio, folio, folio_size(folio), 0);
|
2012-07-31 23:44:55 +00:00
|
|
|
|
2023-07-21 03:44:51 +00:00
|
|
|
bio_associate_blkg_from_page(&bio, folio);
|
2023-07-21 03:44:50 +00:00
|
|
|
count_swpout_vm_event(folio);
|
2023-01-25 13:34:36 +00:00
|
|
|
|
2023-07-21 03:44:48 +00:00
|
|
|
folio_start_writeback(folio);
|
|
|
|
folio_unlock(folio);
|
2023-01-25 13:34:36 +00:00
|
|
|
|
|
|
|
submit_bio_wait(&bio);
|
|
|
|
__end_swap_bio_write(&bio);
|
|
|
|
}
|
|
|
|
|
2023-12-13 21:58:34 +00:00
|
|
|
static void swap_writepage_bdev_async(struct folio *folio,
|
2023-01-25 13:34:36 +00:00
|
|
|
struct writeback_control *wbc, struct swap_info_struct *sis)
|
|
|
|
{
|
|
|
|
struct bio *bio;
|
2014-06-04 23:07:48 +00:00
|
|
|
|
2022-01-24 09:11:05 +00:00
|
|
|
bio = bio_alloc(sis->bdev, 1,
|
|
|
|
REQ_OP_WRITE | REQ_SWAP | wbc_to_write_flags(wbc),
|
|
|
|
GFP_NOIO);
|
2023-12-13 21:58:38 +00:00
|
|
|
bio->bi_iter.bi_sector = swap_folio_sector(folio);
|
2022-08-11 14:17:41 +00:00
|
|
|
bio->bi_end_io = end_swap_bio_write;
|
2023-12-13 21:58:34 +00:00
|
|
|
bio_add_folio_nofail(bio, folio, folio_size(folio), 0);
|
2021-01-26 14:52:47 +00:00
|
|
|
|
2023-07-21 03:44:51 +00:00
|
|
|
bio_associate_blkg_from_page(bio, folio);
|
2023-07-21 03:44:50 +00:00
|
|
|
count_swpout_vm_event(folio);
|
2023-07-21 03:44:49 +00:00
|
|
|
folio_start_writeback(folio);
|
|
|
|
folio_unlock(folio);
|
2016-06-05 19:31:41 +00:00
|
|
|
submit_bio(bio);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2020-10-13 23:52:21 +00:00
|
|
|
|
2023-12-13 21:58:31 +00:00
|
|
|
void __swap_writepage(struct folio *folio, struct writeback_control *wbc)
|
2023-01-25 13:34:35 +00:00
|
|
|
{
|
2023-12-13 21:58:31 +00:00
|
|
|
struct swap_info_struct *sis = swp_swap_info(folio->swap);
|
2023-01-25 13:34:35 +00:00
|
|
|
|
2023-12-13 21:58:31 +00:00
|
|
|
VM_BUG_ON_FOLIO(!folio_test_swapcache(folio), folio);
|
2023-01-25 13:34:35 +00:00
|
|
|
/*
|
|
|
|
* ->flags can be updated non-atomicially (scan_swap_map_slots),
|
|
|
|
* but that will never affect SWP_FS_OPS, so the data_race
|
|
|
|
* is safe.
|
|
|
|
*/
|
|
|
|
if (data_race(sis->flags & SWP_FS_OPS))
|
2023-12-13 21:58:32 +00:00
|
|
|
swap_writepage_fs(folio, wbc);
|
2024-07-11 16:32:30 +00:00
|
|
|
/*
|
|
|
|
* ->flags can be updated non-atomicially (scan_swap_map_slots),
|
|
|
|
* but that will never affect SWP_SYNCHRONOUS_IO, so the data_race
|
|
|
|
* is safe.
|
|
|
|
*/
|
|
|
|
else if (data_race(sis->flags & SWP_SYNCHRONOUS_IO))
|
2023-12-13 21:58:33 +00:00
|
|
|
swap_writepage_bdev_sync(folio, wbc, sis);
|
2023-01-25 13:34:35 +00:00
|
|
|
else
|
2023-12-13 21:58:34 +00:00
|
|
|
swap_writepage_bdev_async(folio, wbc, sis);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 01:20:49 +00:00
|
|
|
void swap_write_unplug(struct swap_iocb *sio)
|
|
|
|
{
|
|
|
|
struct iov_iter from;
|
|
|
|
struct address_space *mapping = sio->iocb.ki_filp->f_mapping;
|
|
|
|
int ret;
|
|
|
|
|
2022-09-16 00:25:47 +00:00
|
|
|
iov_iter_bvec(&from, ITER_SOURCE, sio->bvec, sio->pages, sio->len);
|
2022-05-10 01:20:49 +00:00
|
|
|
ret = mapping->a_ops->swap_rw(&sio->iocb, &from);
|
|
|
|
if (ret != -EIOCBQUEUED)
|
|
|
|
sio_write_complete(&sio->iocb, ret);
|
|
|
|
}
|
|
|
|
|
2022-05-10 01:20:48 +00:00
|
|
|
static void sio_read_complete(struct kiocb *iocb, long ret)
|
|
|
|
{
|
|
|
|
struct swap_iocb *sio = container_of(iocb, struct swap_iocb, iocb);
|
2022-05-10 01:20:49 +00:00
|
|
|
int p;
|
2022-05-10 01:20:48 +00:00
|
|
|
|
2022-05-10 01:20:49 +00:00
|
|
|
if (ret == sio->len) {
|
2022-05-10 01:20:49 +00:00
|
|
|
for (p = 0; p < sio->pages; p++) {
|
2023-07-21 03:44:47 +00:00
|
|
|
struct folio *folio = page_folio(sio->bvec[p].bv_page);
|
2022-05-10 01:20:49 +00:00
|
|
|
|
2023-07-21 03:44:47 +00:00
|
|
|
folio_mark_uptodate(folio);
|
|
|
|
folio_unlock(folio);
|
2022-05-10 01:20:49 +00:00
|
|
|
}
|
|
|
|
count_vm_events(PSWPIN, sio->pages);
|
2022-05-10 01:20:48 +00:00
|
|
|
} else {
|
2022-05-10 01:20:49 +00:00
|
|
|
for (p = 0; p < sio->pages; p++) {
|
2023-07-21 03:44:47 +00:00
|
|
|
struct folio *folio = page_folio(sio->bvec[p].bv_page);
|
2022-05-10 01:20:49 +00:00
|
|
|
|
2023-07-21 03:44:47 +00:00
|
|
|
folio_unlock(folio);
|
2022-05-10 01:20:49 +00:00
|
|
|
}
|
|
|
|
pr_alert_ratelimited("Read-error on swap-device\n");
|
2022-05-10 01:20:48 +00:00
|
|
|
}
|
|
|
|
mempool_free(sio, sio_pool);
|
|
|
|
}
|
|
|
|
|
2023-12-13 21:58:39 +00:00
|
|
|
static void swap_read_folio_fs(struct folio *folio, struct swap_iocb **plug)
|
2022-05-10 01:20:48 +00:00
|
|
|
{
|
2023-12-13 21:58:35 +00:00
|
|
|
struct swap_info_struct *sis = swp_swap_info(folio->swap);
|
2022-05-10 01:20:49 +00:00
|
|
|
struct swap_iocb *sio = NULL;
|
2024-05-21 17:58:50 +00:00
|
|
|
loff_t pos = swap_dev_pos(folio->swap);
|
2022-05-10 01:20:48 +00:00
|
|
|
|
2022-05-10 01:20:49 +00:00
|
|
|
if (plug)
|
|
|
|
sio = *plug;
|
|
|
|
if (sio) {
|
|
|
|
if (sio->iocb.ki_filp != sis->swap_file ||
|
2022-05-10 01:20:49 +00:00
|
|
|
sio->iocb.ki_pos + sio->len != pos) {
|
2022-05-10 01:20:49 +00:00
|
|
|
swap_read_unplug(sio);
|
|
|
|
sio = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!sio) {
|
|
|
|
sio = mempool_alloc(sio_pool, GFP_KERNEL);
|
|
|
|
init_sync_kiocb(&sio->iocb, sis->swap_file);
|
|
|
|
sio->iocb.ki_pos = pos;
|
|
|
|
sio->iocb.ki_complete = sio_read_complete;
|
|
|
|
sio->pages = 0;
|
2022-05-10 01:20:49 +00:00
|
|
|
sio->len = 0;
|
2022-05-10 01:20:49 +00:00
|
|
|
}
|
2023-12-13 21:58:35 +00:00
|
|
|
bvec_set_folio(&sio->bvec[sio->pages], folio, folio_size(folio), 0);
|
|
|
|
sio->len += folio_size(folio);
|
2022-05-10 01:20:49 +00:00
|
|
|
sio->pages += 1;
|
|
|
|
if (sio->pages == ARRAY_SIZE(sio->bvec) || !plug) {
|
|
|
|
swap_read_unplug(sio);
|
|
|
|
sio = NULL;
|
|
|
|
}
|
|
|
|
if (plug)
|
|
|
|
*plug = sio;
|
2022-05-10 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2023-12-13 21:58:39 +00:00
|
|
|
static void swap_read_folio_bdev_sync(struct folio *folio,
|
2023-01-25 13:34:32 +00:00
|
|
|
struct swap_info_struct *sis)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2023-01-25 13:34:33 +00:00
|
|
|
struct bio_vec bv;
|
|
|
|
struct bio bio;
|
2012-07-31 23:44:55 +00:00
|
|
|
|
2023-01-25 13:34:33 +00:00
|
|
|
bio_init(&bio, sis->bdev, &bv, 1, REQ_OP_READ);
|
2023-12-13 21:58:38 +00:00
|
|
|
bio.bi_iter.bi_sector = swap_folio_sector(folio);
|
2023-12-13 21:58:36 +00:00
|
|
|
bio_add_folio_nofail(&bio, folio, folio_size(folio), 0);
|
2017-08-02 20:32:09 +00:00
|
|
|
/*
|
|
|
|
* Keep this task valid during swap readpage because the oom killer may
|
|
|
|
* attempt to access it in the page fault retry time check.
|
|
|
|
*/
|
2023-01-25 13:34:33 +00:00
|
|
|
get_task_struct(current);
|
2006-06-30 08:55:45 +00:00
|
|
|
count_vm_event(PSWPIN);
|
2023-01-25 13:34:33 +00:00
|
|
|
submit_bio_wait(&bio);
|
|
|
|
__end_swap_bio_read(&bio);
|
|
|
|
put_task_struct(current);
|
|
|
|
}
|
|
|
|
|
2023-12-13 21:58:39 +00:00
|
|
|
static void swap_read_folio_bdev_async(struct folio *folio,
|
2023-01-25 13:34:33 +00:00
|
|
|
struct swap_info_struct *sis)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct bio *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-10 22:47:11 +00:00
|
|
|
|
2023-01-25 13:34:33 +00:00
|
|
|
bio = bio_alloc(sis->bdev, 1, REQ_OP_READ, GFP_KERNEL);
|
2023-12-13 21:58:38 +00:00
|
|
|
bio->bi_iter.bi_sector = swap_folio_sector(folio);
|
2023-01-25 13:34:33 +00:00
|
|
|
bio->bi_end_io = end_swap_bio_read;
|
2023-12-13 21:58:37 +00:00
|
|
|
bio_add_folio_nofail(bio, folio, folio_size(folio), 0);
|
2023-01-25 13:34:33 +00:00
|
|
|
count_vm_event(PSWPIN);
|
|
|
|
submit_bio(bio);
|
2023-01-25 13:34:32 +00:00
|
|
|
}
|
|
|
|
|
2024-06-07 04:55:15 +00:00
|
|
|
void swap_read_folio(struct folio *folio, struct swap_iocb **plug)
|
2023-01-25 13:34:32 +00:00
|
|
|
{
|
2023-12-13 21:58:39 +00:00
|
|
|
struct swap_info_struct *sis = swp_swap_info(folio->swap);
|
2024-06-07 04:55:15 +00:00
|
|
|
bool synchronous = sis->flags & SWP_SYNCHRONOUS_IO;
|
2023-07-15 04:23:42 +00:00
|
|
|
bool workingset = folio_test_workingset(folio);
|
2019-12-01 01:58:29 +00:00
|
|
|
unsigned long pflags;
|
2022-08-15 07:28:37 +00:00
|
|
|
bool in_thrashing;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2023-07-15 04:23:42 +00:00
|
|
|
VM_BUG_ON_FOLIO(!folio_test_swapcache(folio) && !synchronous, folio);
|
|
|
|
VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
|
|
|
|
VM_BUG_ON_FOLIO(folio_test_uptodate(folio), folio);
|
2019-12-01 01:58:29 +00:00
|
|
|
|
|
|
|
/*
|
2022-08-15 07:28:37 +00:00
|
|
|
* Count submission time as memory stall and delay. When the device
|
|
|
|
* is congested, or the submitting cgroup IO-throttled, submission
|
|
|
|
* can be a significant part of overall IO time.
|
2019-12-01 01:58:29 +00:00
|
|
|
*/
|
2022-08-15 07:28:37 +00:00
|
|
|
if (workingset) {
|
|
|
|
delayacct_thrashing_start(&in_thrashing);
|
2022-03-22 21:46:30 +00:00
|
|
|
psi_memstall_enter(&pflags);
|
2022-08-15 07:28:37 +00:00
|
|
|
}
|
2022-01-20 02:10:02 +00:00
|
|
|
delayacct_swapin_start();
|
2019-12-01 01:58:29 +00:00
|
|
|
|
2023-07-15 04:23:43 +00:00
|
|
|
if (zswap_load(folio)) {
|
2023-07-15 04:23:42 +00:00
|
|
|
folio_unlock(folio);
|
zswap: track swapins from disk more accurately
Currently, there are a couple of issues with our disk swapin tracking for
dynamic zswap shrinker heuristics:
1. We only increment the swapin counter on pivot pages. This means we
are not taking into account pages that also need to be swapped in,
but are already taken care of as part of the readahead window.
2. We are also incrementing when the pages are read from the zswap pool,
which is inaccurate.
This patch rectifies these issues by incrementing the counter whenever we
need to perform a non-zswap read. Note that we are slightly overcounting,
as a page might be read into memory by the readahead algorithm even though
it will not be neeeded by users - however, this is an acceptable
inaccuracy, as the readahead logic itself will adapt to these kind of
scenarios.
To test this change, I built the kernel under a cgroup with its memory.max
set to 2 GB:
real: 236.66s
user: 4286.06s
sys: 652.86s
swapins: 81552
For comparison, with just the new second chance algorithm, the build time
is as follows:
real: 244.85s
user: 4327.22s
sys: 664.39s
swapins: 94663
Without neither:
real: 263.89s
user: 4318.11s
sys: 673.29s
swapins: 227300.5
(average over 5 runs)
With this change, the kernel CPU time reduces by a further 1.7%, and the
real time is reduced by another 3.3%, compared to just the second chance
algorithm by itself. The swapins count also reduces by another 13.85%.
Combinng the two changes, we reduce the real time by 10.32%, kernel CPU
time by 3%, and number of swapins by 64.12%.
To gauge the new scheme's ability to offload cold data, I ran another
benchmark, in which the kernel was built under a cgroup with memory.max
set to 3 GB, but with 0.5 GB worth of cold data allocated before each
build (in a shmem file).
Under the old scheme:
real: 197.18s
user: 4365.08s
sys: 289.02s
zswpwb: 72115.2
Under the new scheme:
real: 195.8s
user: 4362.25s
sys: 290.14s
zswpwb: 87277.8
(average over 5 runs)
Notice that we actually observe a 21% increase in the number of written
back pages - so the new scheme is just as good, if not better at
offloading pages from the zswap pool when they are cold. Build time
reduces by around 0.7% as a result.
[nphamcs@gmail.com: squeeze a comment into a single line]
Link: https://lkml.kernel.org/r/20240806004518.3183562-1-nphamcs@gmail.com
Link: https://lkml.kernel.org/r/20240805232243.2896283-3-nphamcs@gmail.com
Fixes: b5ba474f3f51 ("zswap: shrink zswap pool based on memory pressure")
Signed-off-by: Nhat Pham <nphamcs@gmail.com>
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Yosry Ahmed <yosryahmed@google.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Chengming Zhou <chengming.zhou@linux.dev>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Takero Funaki <flintglass@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-08-05 23:22:43 +00:00
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We have to read from slower devices. Increase zswap protection. */
|
|
|
|
zswap_folio_swapin(folio);
|
|
|
|
|
|
|
|
if (data_race(sis->flags & SWP_FS_OPS)) {
|
2023-12-13 21:58:39 +00:00
|
|
|
swap_read_folio_fs(folio, plug);
|
2024-06-07 04:55:15 +00:00
|
|
|
} else if (synchronous) {
|
2023-12-13 21:58:39 +00:00
|
|
|
swap_read_folio_bdev_sync(folio, sis);
|
2023-01-25 13:34:32 +00:00
|
|
|
} else {
|
2023-12-13 21:58:39 +00:00
|
|
|
swap_read_folio_bdev_async(folio, sis);
|
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-10 22:47:11 +00:00
|
|
|
}
|
|
|
|
|
zswap: track swapins from disk more accurately
Currently, there are a couple of issues with our disk swapin tracking for
dynamic zswap shrinker heuristics:
1. We only increment the swapin counter on pivot pages. This means we
are not taking into account pages that also need to be swapped in,
but are already taken care of as part of the readahead window.
2. We are also incrementing when the pages are read from the zswap pool,
which is inaccurate.
This patch rectifies these issues by incrementing the counter whenever we
need to perform a non-zswap read. Note that we are slightly overcounting,
as a page might be read into memory by the readahead algorithm even though
it will not be neeeded by users - however, this is an acceptable
inaccuracy, as the readahead logic itself will adapt to these kind of
scenarios.
To test this change, I built the kernel under a cgroup with its memory.max
set to 2 GB:
real: 236.66s
user: 4286.06s
sys: 652.86s
swapins: 81552
For comparison, with just the new second chance algorithm, the build time
is as follows:
real: 244.85s
user: 4327.22s
sys: 664.39s
swapins: 94663
Without neither:
real: 263.89s
user: 4318.11s
sys: 673.29s
swapins: 227300.5
(average over 5 runs)
With this change, the kernel CPU time reduces by a further 1.7%, and the
real time is reduced by another 3.3%, compared to just the second chance
algorithm by itself. The swapins count also reduces by another 13.85%.
Combinng the two changes, we reduce the real time by 10.32%, kernel CPU
time by 3%, and number of swapins by 64.12%.
To gauge the new scheme's ability to offload cold data, I ran another
benchmark, in which the kernel was built under a cgroup with memory.max
set to 3 GB, but with 0.5 GB worth of cold data allocated before each
build (in a shmem file).
Under the old scheme:
real: 197.18s
user: 4365.08s
sys: 289.02s
zswpwb: 72115.2
Under the new scheme:
real: 195.8s
user: 4362.25s
sys: 290.14s
zswpwb: 87277.8
(average over 5 runs)
Notice that we actually observe a 21% increase in the number of written
back pages - so the new scheme is just as good, if not better at
offloading pages from the zswap pool when they are cold. Build time
reduces by around 0.7% as a result.
[nphamcs@gmail.com: squeeze a comment into a single line]
Link: https://lkml.kernel.org/r/20240806004518.3183562-1-nphamcs@gmail.com
Link: https://lkml.kernel.org/r/20240805232243.2896283-3-nphamcs@gmail.com
Fixes: b5ba474f3f51 ("zswap: shrink zswap pool based on memory pressure")
Signed-off-by: Nhat Pham <nphamcs@gmail.com>
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Yosry Ahmed <yosryahmed@google.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Chengming Zhou <chengming.zhou@linux.dev>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Takero Funaki <flintglass@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-08-05 23:22:43 +00:00
|
|
|
finish:
|
2022-08-15 07:28:37 +00:00
|
|
|
if (workingset) {
|
|
|
|
delayacct_thrashing_end(&in_thrashing);
|
2022-03-22 21:46:30 +00:00
|
|
|
psi_memstall_leave(&pflags);
|
2022-08-15 07:28:37 +00:00
|
|
|
}
|
2022-01-20 02:10:02 +00:00
|
|
|
delayacct_swapin_end();
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2012-07-31 23:44:55 +00:00
|
|
|
|
2022-05-10 01:20:49 +00:00
|
|
|
void __swap_read_unplug(struct swap_iocb *sio)
|
2012-07-31 23:44:55 +00:00
|
|
|
{
|
2022-05-10 01:20:49 +00:00
|
|
|
struct iov_iter from;
|
|
|
|
struct address_space *mapping = sio->iocb.ki_filp->f_mapping;
|
|
|
|
int ret;
|
2016-10-08 00:00:52 +00:00
|
|
|
|
2022-09-16 00:25:47 +00:00
|
|
|
iov_iter_bvec(&from, ITER_DEST, sio->bvec, sio->pages, sio->len);
|
2022-05-10 01:20:49 +00:00
|
|
|
ret = mapping->a_ops->swap_rw(&sio->iocb, &from);
|
|
|
|
if (ret != -EIOCBQUEUED)
|
|
|
|
sio_read_complete(&sio->iocb, ret);
|
2012-07-31 23:44:55 +00:00
|
|
|
}
|