Skip to content

Commit 85a1333

Browse files
Matthew Wilcoxakpm00
authored andcommitted
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>
1 parent cfeed8f commit 85a1333

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

include/linux/mm_types.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@ static inline struct page *encoded_page_ptr(struct encoded_page *page)
248248
return (struct page *)(~ENCODE_PAGE_BITS & (unsigned long)page);
249249
}
250250

251+
/*
252+
* A swap entry has to fit into a "unsigned long", as the entry is hidden
253+
* in the "index" field of the swapper address space.
254+
*/
255+
typedef struct {
256+
unsigned long val;
257+
} swp_entry_t;
258+
251259
/**
252260
* struct folio - Represents a contiguous set of bytes.
253261
* @flags: Identical to the page flags.
@@ -258,7 +266,7 @@ static inline struct page *encoded_page_ptr(struct encoded_page *page)
258266
* @index: Offset within the file, in units of pages. For anonymous memory,
259267
* this is the index from the beginning of the mmap.
260268
* @private: Filesystem per-folio data (see folio_attach_private()).
261-
* Used for swp_entry_t if folio_test_swapcache().
269+
* @swap: Used for swp_entry_t if folio_test_swapcache().
262270
* @_mapcount: Do not access this member directly. Use folio_mapcount() to
263271
* find out how many times this folio is mapped by userspace.
264272
* @_refcount: Do not access this member directly. Use folio_ref_count()
@@ -301,7 +309,10 @@ struct folio {
301309
};
302310
struct address_space *mapping;
303311
pgoff_t index;
304-
void *private;
312+
union {
313+
void *private;
314+
swp_entry_t swap;
315+
};
305316
atomic_t _mapcount;
306317
atomic_t _refcount;
307318
#ifdef CONFIG_MEMCG
@@ -1209,14 +1220,6 @@ enum tlb_flush_reason {
12091220
NR_TLB_FLUSH_REASONS,
12101221
};
12111222

1212-
/*
1213-
* A swap entry has to fit into a "unsigned long", as the entry is hidden
1214-
* in the "index" field of the swapper address space.
1215-
*/
1216-
typedef struct {
1217-
unsigned long val;
1218-
} swp_entry_t;
1219-
12201223
/**
12211224
* enum fault_flag - Fault flag definitions.
12221225
* @FAULT_FLAG_WRITE: Fault was a write fault.

include/linux/swap.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,7 @@ struct swap_info_struct {
335335

336336
static inline swp_entry_t folio_swap_entry(struct folio *folio)
337337
{
338-
swp_entry_t entry = { .val = page_private(&folio->page) };
339-
return entry;
338+
return folio->swap;
340339
}
341340

342341
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)
350349

351350
static inline void folio_set_swap_entry(struct folio *folio, swp_entry_t entry)
352351
{
353-
folio->private = (void *)entry.val;
352+
folio->swap = entry;
354353
}
355354

356355
/* linux/mm/workingset.c */

0 commit comments

Comments
 (0)