mm/swap: use dedicated entry for swap in folio

Let's stop working on the private field and use an explicit swap field. 
We have to move the swp_entry_t typedef.

Link: https://lkml.kernel.org/r/20230821160849.531668-3-david@redhat.com
Signed-off-by: Matthew Wilcox <willy@infradead.org>
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Chris Li <chrisl@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dan Streetman <ddstreet@ieee.org>
Cc: Hugh Dickins <hughd@google.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Seth Jennings <sjenning@redhat.com>
Cc: Vitaly Wool <vitaly.wool@konsulko.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
Matthew Wilcox 2023-08-21 18:08:47 +02:00 committed by Andrew Morton
parent cfeed8ffe5
commit 85a1333417
2 changed files with 15 additions and 13 deletions

View file

@ -248,6 +248,14 @@ static inline struct page *encoded_page_ptr(struct encoded_page *page)
return (struct page *)(~ENCODE_PAGE_BITS & (unsigned long)page); return (struct page *)(~ENCODE_PAGE_BITS & (unsigned long)page);
} }
/*
* A swap entry has to fit into a "unsigned long", as the entry is hidden
* in the "index" field of the swapper address space.
*/
typedef struct {
unsigned long val;
} swp_entry_t;
/** /**
* struct folio - Represents a contiguous set of bytes. * struct folio - Represents a contiguous set of bytes.
* @flags: Identical to the page flags. * @flags: Identical to the page flags.
@ -258,7 +266,7 @@ static inline struct page *encoded_page_ptr(struct encoded_page *page)
* @index: Offset within the file, in units of pages. For anonymous memory, * @index: Offset within the file, in units of pages. For anonymous memory,
* this is the index from the beginning of the mmap. * this is the index from the beginning of the mmap.
* @private: Filesystem per-folio data (see folio_attach_private()). * @private: Filesystem per-folio data (see folio_attach_private()).
* Used for swp_entry_t if folio_test_swapcache(). * @swap: Used for swp_entry_t if folio_test_swapcache().
* @_mapcount: Do not access this member directly. Use folio_mapcount() to * @_mapcount: Do not access this member directly. Use folio_mapcount() to
* find out how many times this folio is mapped by userspace. * find out how many times this folio is mapped by userspace.
* @_refcount: Do not access this member directly. Use folio_ref_count() * @_refcount: Do not access this member directly. Use folio_ref_count()
@ -301,7 +309,10 @@ struct folio {
}; };
struct address_space *mapping; struct address_space *mapping;
pgoff_t index; pgoff_t index;
void *private; union {
void *private;
swp_entry_t swap;
};
atomic_t _mapcount; atomic_t _mapcount;
atomic_t _refcount; atomic_t _refcount;
#ifdef CONFIG_MEMCG #ifdef CONFIG_MEMCG
@ -1209,14 +1220,6 @@ enum tlb_flush_reason {
NR_TLB_FLUSH_REASONS, NR_TLB_FLUSH_REASONS,
}; };
/*
* A swap entry has to fit into a "unsigned long", as the entry is hidden
* in the "index" field of the swapper address space.
*/
typedef struct {
unsigned long val;
} swp_entry_t;
/** /**
* enum fault_flag - Fault flag definitions. * enum fault_flag - Fault flag definitions.
* @FAULT_FLAG_WRITE: Fault was a write fault. * @FAULT_FLAG_WRITE: Fault was a write fault.

View file

@ -335,8 +335,7 @@ struct swap_info_struct {
static inline swp_entry_t folio_swap_entry(struct folio *folio) static inline swp_entry_t folio_swap_entry(struct folio *folio)
{ {
swp_entry_t entry = { .val = page_private(&folio->page) }; return folio->swap;
return entry;
} }
static inline swp_entry_t page_swap_entry(struct page *page) static inline swp_entry_t page_swap_entry(struct page *page)
@ -350,7 +349,7 @@ static inline swp_entry_t page_swap_entry(struct page *page)
static inline void folio_set_swap_entry(struct folio *folio, swp_entry_t entry) static inline void folio_set_swap_entry(struct folio *folio, swp_entry_t entry)
{ {
folio->private = (void *)entry.val; folio->swap = entry;
} }
/* linux/mm/workingset.c */ /* linux/mm/workingset.c */