Skip to content

Commit fa9949d

Browse files
Hugh Dickinstorvalds
authored andcommitted
mm: use __SetPageSwapBacked and dont ClearPageSwapBacked
v3.16 commit 07a4278 ("mm: shmem: avoid atomic operation during shmem_getpage_gfp") rightly replaced one instance of SetPageSwapBacked by __SetPageSwapBacked, pointing out that the newly allocated page is not yet visible to other users (except speculative get_page_unless_zero- ers, who may not update page flags before their further checks). That was part of a series in which Mel was focused on tmpfs profiles: but almost all SetPageSwapBacked uses can be so optimized, with the same justification. Remove ClearPageSwapBacked from __read_swap_cache_async() error path: it's not an error to free a page with PG_swapbacked set. Follow a convention of __SetPageLocked, __SetPageSwapBacked instead of doing it differently in different places; but that's for tidiness - if the ordering actually mattered, we should not be using the __variants. There's probably scope for further __SetPageFlags in other places, but SwapBacked is the one I'm interested in at the moment. Signed-off-by: Hugh Dickins <hughd@google.com> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Andres Lagar-Cavilla <andreslc@google.com> Cc: Yang Shi <yang.shi@linaro.org> Cc: Ning Qu <quning@gmail.com> Reviewed-by: Mel Gorman <mgorman@techsingularity.net> Cc: Konstantin Khlebnikov <koct9i@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9d5e6a9 commit fa9949d

4 files changed

Lines changed: 7 additions & 8 deletions

File tree

‎mm/migrate.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ int migrate_page_move_mapping(struct address_space *mapping,
332332
newpage->index = page->index;
333333
newpage->mapping = page->mapping;
334334
if (PageSwapBacked(page))
335-
SetPageSwapBacked(newpage);
335+
__SetPageSwapBacked(newpage);
336336

337337
return MIGRATEPAGE_SUCCESS;
338338
}
@@ -378,7 +378,7 @@ int migrate_page_move_mapping(struct address_space *mapping,
378378
newpage->index = page->index;
379379
newpage->mapping = page->mapping;
380380
if (PageSwapBacked(page))
381-
SetPageSwapBacked(newpage);
381+
__SetPageSwapBacked(newpage);
382382

383383
get_page(newpage); /* add cache reference */
384384
if (PageSwapCache(page)) {
@@ -1791,7 +1791,7 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm,
17911791

17921792
/* Prepare a page as a migration target */
17931793
__SetPageLocked(new_page);
1794-
SetPageSwapBacked(new_page);
1794+
__SetPageSwapBacked(new_page);
17951795

17961796
/* anon mapping, we can simply copy page->mapping to the new page: */
17971797
new_page->mapping = page->mapping;

‎mm/rmap.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ void page_add_new_anon_rmap(struct page *page,
12491249
int nr = compound ? hpage_nr_pages(page) : 1;
12501250

12511251
VM_BUG_ON_VMA(address < vma->vm_start || address >= vma->vm_end, vma);
1252-
SetPageSwapBacked(page);
1252+
__SetPageSwapBacked(page);
12531253
if (compound) {
12541254
VM_BUG_ON_PAGE(!PageTransHuge(page), page);
12551255
/* increment count (starts at -1) */

‎mm/shmem.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,8 +1085,8 @@ static int shmem_replace_page(struct page **pagep, gfp_t gfp,
10851085
flush_dcache_page(newpage);
10861086

10871087
__SetPageLocked(newpage);
1088+
__SetPageSwapBacked(newpage);
10881089
SetPageUptodate(newpage);
1089-
SetPageSwapBacked(newpage);
10901090
set_page_private(newpage, swap_index);
10911091
SetPageSwapCache(newpage);
10921092

@@ -1276,8 +1276,8 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
12761276
goto decused;
12771277
}
12781278

1279-
__SetPageSwapBacked(page);
12801279
__SetPageLocked(page);
1280+
__SetPageSwapBacked(page);
12811281
if (sgp == SGP_WRITE)
12821282
__SetPageReferenced(page);
12831283

‎mm/swap_state.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
358358

359359
/* May fail (-ENOMEM) if radix-tree node allocation failed. */
360360
__SetPageLocked(new_page);
361-
SetPageSwapBacked(new_page);
361+
__SetPageSwapBacked(new_page);
362362
err = __add_to_swap_cache(new_page, entry);
363363
if (likely(!err)) {
364364
radix_tree_preload_end();
@@ -370,7 +370,6 @@ struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
370370
return new_page;
371371
}
372372
radix_tree_preload_end();
373-
ClearPageSwapBacked(new_page);
374373
__ClearPageLocked(new_page);
375374
/*
376375
* add_to_swap_cache() doesn't return -EEXIST, so we can safely

0 commit comments

Comments
 (0)