Skip to content

Commit 6326fec

Browse files
npiggintorvalds
authored andcommitted
mm: Use owner_priv bit for PageSwapCache, valid when PageSwapBacked
A page is not added to the swap cache without being swap backed, so PageSwapBacked mappings can use PG_owner_priv_1 for PageSwapCache. Signed-off-by: Nicholas Piggin <npiggin@gmail.com> Acked-by: Hugh Dickins <hughd@google.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Bob Peterson <rpeterso@redhat.com> Cc: Steven Whitehouse <swhiteho@redhat.com> Cc: Andrew Lutomirski <luto@kernel.org> Cc: Andreas Gruenbacher <agruenba@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Mel Gorman <mgorman@techsingularity.net> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 7c0f6ba commit 6326fec

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

include/linux/page-flags.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ enum pageflags {
8787
PG_private_2, /* If pagecache, has fs aux data */
8888
PG_writeback, /* Page is under writeback */
8989
PG_head, /* A head page */
90-
PG_swapcache, /* Swap page: swp_entry_t in private */
9190
PG_mappedtodisk, /* Has blocks allocated on-disk */
9291
PG_reclaim, /* To be reclaimed asap */
9392
PG_swapbacked, /* Page is backed by RAM/swap */
@@ -110,6 +109,9 @@ enum pageflags {
110109
/* Filesystems */
111110
PG_checked = PG_owner_priv_1,
112111

112+
/* SwapBacked */
113+
PG_swapcache = PG_owner_priv_1, /* Swap page: swp_entry_t in private */
114+
113115
/* Two page bits are conscripted by FS-Cache to maintain local caching
114116
* state. These bits are set on pages belonging to the netfs's inodes
115117
* when those inodes are being locally cached.
@@ -314,7 +316,13 @@ PAGEFLAG_FALSE(HighMem)
314316
#endif
315317

316318
#ifdef CONFIG_SWAP
317-
PAGEFLAG(SwapCache, swapcache, PF_NO_COMPOUND)
319+
static __always_inline int PageSwapCache(struct page *page)
320+
{
321+
return PageSwapBacked(page) && test_bit(PG_swapcache, &page->flags);
322+
323+
}
324+
SETPAGEFLAG(SwapCache, swapcache, PF_NO_COMPOUND)
325+
CLEARPAGEFLAG(SwapCache, swapcache, PF_NO_COMPOUND)
318326
#else
319327
PAGEFLAG_FALSE(SwapCache)
320328
#endif
@@ -701,12 +709,12 @@ static inline void ClearPageSlabPfmemalloc(struct page *page)
701709
* Flags checked when a page is freed. Pages being freed should not have
702710
* these flags set. It they are, there is a problem.
703711
*/
704-
#define PAGE_FLAGS_CHECK_AT_FREE \
705-
(1UL << PG_lru | 1UL << PG_locked | \
706-
1UL << PG_private | 1UL << PG_private_2 | \
707-
1UL << PG_writeback | 1UL << PG_reserved | \
708-
1UL << PG_slab | 1UL << PG_swapcache | 1UL << PG_active | \
709-
1UL << PG_unevictable | __PG_MLOCKED)
712+
#define PAGE_FLAGS_CHECK_AT_FREE \
713+
(1UL << PG_lru | 1UL << PG_locked | \
714+
1UL << PG_private | 1UL << PG_private_2 | \
715+
1UL << PG_writeback | 1UL << PG_reserved | \
716+
1UL << PG_slab | 1UL << PG_active | \
717+
1UL << PG_unevictable | __PG_MLOCKED)
710718

711719
/*
712720
* Flags checked when a page is prepped for return by the page allocator.

include/trace/events/mmflags.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
{1UL << PG_private_2, "private_2" }, \
9696
{1UL << PG_writeback, "writeback" }, \
9797
{1UL << PG_head, "head" }, \
98-
{1UL << PG_swapcache, "swapcache" }, \
9998
{1UL << PG_mappedtodisk, "mappedtodisk" }, \
10099
{1UL << PG_reclaim, "reclaim" }, \
101100
{1UL << PG_swapbacked, "swapbacked" }, \

mm/memory-failure.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,12 +764,11 @@ static int me_huge_page(struct page *p, unsigned long pfn)
764764
*/
765765

766766
#define dirty (1UL << PG_dirty)
767-
#define sc (1UL << PG_swapcache)
767+
#define sc ((1UL << PG_swapcache) | (1UL << PG_swapbacked))
768768
#define unevict (1UL << PG_unevictable)
769769
#define mlock (1UL << PG_mlocked)
770770
#define writeback (1UL << PG_writeback)
771771
#define lru (1UL << PG_lru)
772-
#define swapbacked (1UL << PG_swapbacked)
773772
#define head (1UL << PG_head)
774773
#define slab (1UL << PG_slab)
775774
#define reserved (1UL << PG_reserved)
@@ -819,7 +818,6 @@ static struct page_state {
819818
#undef mlock
820819
#undef writeback
821820
#undef lru
822-
#undef swapbacked
823821
#undef head
824822
#undef slab
825823
#undef reserved

mm/migrate.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -466,13 +466,15 @@ int migrate_page_move_mapping(struct address_space *mapping,
466466
*/
467467
newpage->index = page->index;
468468
newpage->mapping = page->mapping;
469-
if (PageSwapBacked(page))
470-
__SetPageSwapBacked(newpage);
471-
472469
get_page(newpage); /* add cache reference */
473-
if (PageSwapCache(page)) {
474-
SetPageSwapCache(newpage);
475-
set_page_private(newpage, page_private(page));
470+
if (PageSwapBacked(page)) {
471+
__SetPageSwapBacked(newpage);
472+
if (PageSwapCache(page)) {
473+
SetPageSwapCache(newpage);
474+
set_page_private(newpage, page_private(page));
475+
}
476+
} else {
477+
VM_BUG_ON_PAGE(PageSwapCache(page), page);
476478
}
477479

478480
/* Move dirty while page refs frozen and newpage not yet exposed */

0 commit comments

Comments
 (0)