From: Matthew Wilcox <mawilcox@xxxxxxxxxxxxx> By combining these three one-word unions into one three-word union, we make it easier for users to add their own multi-word fields to struct page, as well as making it obvious that SLUB needs to keep its double-word alignment for its freelist & counters. No field moves position; verified with pahole. Signed-off-by: Matthew Wilcox <mawilcox@xxxxxxxxxxxxx> Acked-by: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx> --- include/linux/mm_types.h | 65 ++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 04d9dc442029..f0ccb699641d 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -70,45 +70,44 @@ struct hmm; #endif struct page { - /* First double word block */ unsigned long flags; /* Atomic flags, some possibly * updated asynchronously */ - union { - /* See page-flags.h for the definition of PAGE_MAPPING_FLAGS */ - struct address_space *mapping; - - struct kmem_cache *slab_cache; /* SL[AU]B: Pointer to slab */ + union { /* This union is three words (12/24 bytes) in size */ + struct { /* Page cache and anonymous pages */ + /* See page-flags.h for PAGE_MAPPING_FLAGS */ + struct address_space *mapping; + pgoff_t index; /* Our offset within mapping. */ + /** + * @private: Mapping-private opaque data. + * Usually used for buffer_heads if PagePrivate. + * Used for swp_entry_t if PageSwapCache. + * Indicates order in the buddy system if PageBuddy. + */ + unsigned long private; + }; + struct { /* slab, slob and slub */ + struct kmem_cache *slab_cache; /* (slub) */ + void *freelist; /* first free object (slub) */ + void *s_mem; /* first object */ + }; + struct { /* slub */ + struct kmem_cache *slub_cache; /* shared with slab */ + /* Double-word boundary */ + void *slub_freelist; /* shared with slab */ + unsigned inuse:16; + unsigned objects:15; + unsigned frozen:1; + }; atomic_t compound_mapcount; /* first tail page */ - /* page_deferred_list().next -- second tail page */ - }; - - /* Second double word */ - union { - pgoff_t index; /* Our offset within mapping. */ - void *freelist; /* sl[aou]b first free object */ - /* page_deferred_list().prev -- second tail page */ - }; - - union { - /* - * Mapping-private opaque data: - * Usually used for buffer_heads if PagePrivate - * Used for swp_entry_t if PageSwapCache - * Indicates order in the buddy system if PageBuddy - */ - unsigned long private; -#if USE_SPLIT_PTE_PTLOCKS + struct list_head deferred_list; /* second tail page */ + struct { /* Page table pages */ + unsigned long _pt_pad_2; /* mapping */ + unsigned long _pt_pad_3; #if ALLOC_SPLIT_PTLOCKS - spinlock_t *ptl; + spinlock_t *ptl; #else - spinlock_t ptl; -#endif + spinlock_t ptl; #endif - void *s_mem; /* slab first object */ - struct { /* SLUB */ - unsigned inuse:16; - unsigned objects:15; - unsigned frozen:1; }; }; -- 2.17.0