Commit 97b76796 authored by Matthew Wilcox (Oracle)'s avatar Matthew Wilcox (Oracle) Committed by Andrew Morton

swap: convert swapon() to use a folio

Retrieve a folio from the page cache rather than a page.  Saves a couple
of conversions between page & folio.

Link: https://lkml.kernel.org/r/20240826202138.3804238-1-willy@infradead.orgSigned-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 8175ebfd
...@@ -3357,7 +3357,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) ...@@ -3357,7 +3357,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
unsigned char *swap_map = NULL; unsigned char *swap_map = NULL;
unsigned long *zeromap = NULL; unsigned long *zeromap = NULL;
struct swap_cluster_info *cluster_info = NULL; struct swap_cluster_info *cluster_info = NULL;
struct page *page = NULL; struct folio *folio = NULL;
struct inode *inode = NULL; struct inode *inode = NULL;
bool inced_nr_rotate_swap = false; bool inced_nr_rotate_swap = false;
...@@ -3415,12 +3415,12 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) ...@@ -3415,12 +3415,12 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
error = -EINVAL; error = -EINVAL;
goto bad_swap_unlock_inode; goto bad_swap_unlock_inode;
} }
page = read_mapping_page(mapping, 0, swap_file); folio = read_mapping_folio(mapping, 0, swap_file);
if (IS_ERR(page)) { if (IS_ERR(folio)) {
error = PTR_ERR(page); error = PTR_ERR(folio);
goto bad_swap_unlock_inode; goto bad_swap_unlock_inode;
} }
swap_header = kmap(page); swap_header = kmap_local_folio(folio, 0);
maxpages = read_swap_header(si, swap_header, inode); maxpages = read_swap_header(si, swap_header, inode);
if (unlikely(!maxpages)) { if (unlikely(!maxpages)) {
...@@ -3574,10 +3574,8 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) ...@@ -3574,10 +3574,8 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
if (swap_file) if (swap_file)
filp_close(swap_file, NULL); filp_close(swap_file, NULL);
out: out:
if (page && !IS_ERR(page)) { if (!IS_ERR_OR_NULL(folio))
kunmap(page); folio_release_kmap(folio, swap_header);
put_page(page);
}
if (name) if (name)
putname(name); putname(name);
if (inode) if (inode)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment