From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f199.google.com (mail-pf0-f199.google.com [209.85.192.199]) by kanga.kvack.org (Postfix) with ESMTP id 87A7C6B0253 for ; Wed, 20 Dec 2017 10:56:01 -0500 (EST) Received: by mail-pf0-f199.google.com with SMTP id v25so16660518pfg.14 for ; Wed, 20 Dec 2017 07:56:01 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id o3si13123435pld.65.2017.12.20.07.56.00 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Dec 2017 07:56:00 -0800 (PST) From: Matthew Wilcox Subject: [PATCH v2 0/8] Restructure struct page Date: Wed, 20 Dec 2017 07:55:44 -0800 Message-Id: <20171220155552.15884-1-willy@infradead.org> Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org Cc: akpm@linuxfoundation.org, Matthew Wilcox From: Matthew Wilcox This series does not attempt any grand restructuring as I proposed last week. Instead, it cures the worst of the indentitis, fixes the documentation and reduces the ifdeffery. The only layout change is compound_dtor and compound_order are each reduced to one byte. Changes v2: - Add acks - Improve changelogs (mostly at Michal's suggestion) - Improve documentation (patch 7) with Randy's suggestion and add a note about the treatment of _mapcount. Matthew Wilcox (8): mm: Align struct page more aesthetically mm: De-indent struct page mm: Remove misleading alignment claims mm: Improve comment on page->mapping mm: Introduce _slub_counter_t mm: Store compound_dtor / compound_order as bytes mm: Document how to use struct page mm: Remove reference to PG_buddy include/linux/mm_types.h | 153 ++++++++++++++++++++++------------------------- 1 file changed, 73 insertions(+), 80 deletions(-) -- 2.15.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f200.google.com (mail-pf0-f200.google.com [209.85.192.200]) by kanga.kvack.org (Postfix) with ESMTP id EBF726B025F for ; Wed, 20 Dec 2017 10:56:01 -0500 (EST) Received: by mail-pf0-f200.google.com with SMTP id 8so16562866pfv.12 for ; Wed, 20 Dec 2017 07:56:01 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id q80si13367154pfj.192.2017.12.20.07.56.00 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Dec 2017 07:56:00 -0800 (PST) From: Matthew Wilcox Subject: [PATCH v2 1/8] mm: Align struct page more aesthetically Date: Wed, 20 Dec 2017 07:55:45 -0800 Message-Id: <20171220155552.15884-2-willy@infradead.org> In-Reply-To: <20171220155552.15884-1-willy@infradead.org> References: <20171220155552.15884-1-willy@infradead.org> Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org Cc: akpm@linuxfoundation.org, Matthew Wilcox From: Matthew Wilcox instead of an ifdef block at the end of the struct, which needed its own comment, define _struct_page_alignment up at the top where it fits nicely with the existing comment. Signed-off-by: Matthew Wilcox Acked-by: Kirill A. Shutemov Acked-by: Michal Hocko Acked-by: Christoph Lameter --- include/linux/mm_types.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index cfd0ac4e5e0e..4509f0cfaf39 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -39,6 +39,12 @@ struct hmm; * allows the use of atomic double word operations on the flags/mapping * and lru list pointers also. */ +#ifdef CONFIG_HAVE_ALIGNED_STRUCT_PAGE +#define _struct_page_alignment __aligned(2 * sizeof(unsigned long)) +#else +#define _struct_page_alignment +#endif + struct page { /* First double word block */ unsigned long flags; /* Atomic flags, some possibly @@ -212,15 +218,7 @@ struct page { #ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS int _last_cpupid; #endif -} -/* - * The struct page can be forced to be double word aligned so that atomic ops - * on double words work. The SLUB allocator can make use of such a feature. - */ -#ifdef CONFIG_HAVE_ALIGNED_STRUCT_PAGE - __aligned(2 * sizeof(unsigned long)) -#endif -; +} _struct_page_alignment; #define PAGE_FRAG_CACHE_MAX_SIZE __ALIGN_MASK(32768, ~PAGE_MASK) #define PAGE_FRAG_CACHE_MAX_ORDER get_order(PAGE_FRAG_CACHE_MAX_SIZE) -- 2.15.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id 3A4AC6B025E for ; Wed, 20 Dec 2017 10:56:02 -0500 (EST) Received: by mail-pl0-f69.google.com with SMTP id m39so8186892plg.19 for ; Wed, 20 Dec 2017 07:56:02 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id t134si12081117pgc.384.2017.12.20.07.56.01 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Dec 2017 07:56:01 -0800 (PST) From: Matthew Wilcox Subject: [PATCH v2 2/8] mm: De-indent struct page Date: Wed, 20 Dec 2017 07:55:46 -0800 Message-Id: <20171220155552.15884-3-willy@infradead.org> In-Reply-To: <20171220155552.15884-1-willy@infradead.org> References: <20171220155552.15884-1-willy@infradead.org> Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org Cc: akpm@linuxfoundation.org, Matthew Wilcox From: Matthew Wilcox I found the struct { union { struct { union { struct { } } } } } layout rather confusing. Fortunately, there is an easier way to write this. The innermost union is of four things which are the size of an int, so the ones which are used by slab/slob/slub can be pulled up two levels to be in the outermost union with 'counters'. That leaves us with struct { union { struct { atomic_t; atomic_t; } } } which has the same layout, but is easier to read. Output from the current git version of pahole, diffed with -uw to ignore the whitespace changes from the indentation: @@ -11,9 +11,6 @@ }; /* 16 8 */ union { long unsigned int counters; /* 24 8 */ - struct { - union { - atomic_t _mapcount; /* 24 4 */ unsigned int active; /* 24 4 */ struct { unsigned int inuse:16; /* 24:16 4 */ @@ -21,7 +18,8 @@ unsigned int frozen:1; /* 24: 0 4 */ }; /* 24 4 */ int units; /* 24 4 */ - }; /* 24 4 */ + struct { + atomic_t _mapcount; /* 24 4 */ atomic_t _refcount; /* 28 4 */ }; /* 24 8 */ }; /* 24 8 */ Signed-off-by: Matthew Wilcox Acked-by: Kirill A. Shutemov Acked-by: Michal Hocko Acked-by: Christoph Lameter --- include/linux/mm_types.h | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 4509f0cfaf39..27973166af28 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -84,28 +84,26 @@ struct page { */ unsigned counters; #endif - struct { + unsigned int active; /* SLAB */ + struct { /* SLUB */ + unsigned inuse:16; + unsigned objects:15; + unsigned frozen:1; + }; + int units; /* SLOB */ + + struct { /* Page cache */ + /* + * Count of ptes mapped in mms, to show when + * page is mapped & limit reverse map searches. + * + * Extra information about page type may be + * stored here for pages that are never mapped, + * in which case the value MUST BE <= -2. + * See page-flags.h for more details. + */ + atomic_t _mapcount; - union { - /* - * Count of ptes mapped in mms, to show when - * page is mapped & limit reverse map searches. - * - * Extra information about page type may be - * stored here for pages that are never mapped, - * in which case the value MUST BE <= -2. - * See page-flags.h for more details. - */ - atomic_t _mapcount; - - unsigned int active; /* SLAB */ - struct { /* SLUB */ - unsigned inuse:16; - unsigned objects:15; - unsigned frozen:1; - }; - int units; /* SLOB */ - }; /* * Usage count, *USE WRAPPER FUNCTION* when manual * accounting. See page_ref.h -- 2.15.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f200.google.com (mail-pf0-f200.google.com [209.85.192.200]) by kanga.kvack.org (Postfix) with ESMTP id A885B6B026D for ; Wed, 20 Dec 2017 10:56:02 -0500 (EST) Received: by mail-pf0-f200.google.com with SMTP id a74so16653034pfg.20 for ; Wed, 20 Dec 2017 07:56:02 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id s22si4679527pgo.363.2017.12.20.07.56.01 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Dec 2017 07:56:01 -0800 (PST) From: Matthew Wilcox Subject: [PATCH v2 3/8] mm: Remove misleading alignment claims Date: Wed, 20 Dec 2017 07:55:47 -0800 Message-Id: <20171220155552.15884-4-willy@infradead.org> In-Reply-To: <20171220155552.15884-1-willy@infradead.org> References: <20171220155552.15884-1-willy@infradead.org> Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org Cc: akpm@linuxfoundation.org, Matthew Wilcox From: Matthew Wilcox The "third double word block" isn't on 32-bit systems. The layout looks like this: unsigned long flags; struct address_space *mapping pgoff_t index; atomic_t _mapcount; atomic_t _refcount; which is 32 bytes on 64-bit, but 20 bytes on 32-bit. Nobody is trying to use the fact that it's double-word aligned today, so just remove the misleading claims. Signed-off-by: Matthew Wilcox Acked-by: Kirill A. Shutemov Acked-by: Christoph Lameter --- include/linux/mm_types.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 27973166af28..c2294e6204e8 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -33,11 +33,11 @@ struct hmm; * a page, though if it is a pagecache page, rmap structures can tell us * who is mapping it. * - * The objects in struct page are organized in double word blocks in - * order to allows us to use atomic double word operations on portions - * of struct page. That is currently only used by slub but the arrangement - * allows the use of atomic double word operations on the flags/mapping - * and lru list pointers also. + * SLUB uses cmpxchg_double() to atomically update its freelist and + * counters. That requires that freelist & counters be adjacent and + * double-word aligned. We align all struct pages to double-word + * boundaries, and ensure that 'freelist' is aligned within the + * struct. */ #ifdef CONFIG_HAVE_ALIGNED_STRUCT_PAGE #define _struct_page_alignment __aligned(2 * sizeof(unsigned long)) @@ -113,8 +113,6 @@ struct page { }; /* - * Third double word block - * * WARNING: bit 0 of the first word encode PageTail(). That means * the rest users of the storage space MUST NOT use the bit to * avoid collision and false-positive PageTail(). @@ -175,7 +173,6 @@ struct page { #endif }; - /* Remainder is not double word aligned */ union { unsigned long private; /* Mapping-private opaque data: * usually used for buffer_heads -- 2.15.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id D3A246B0261 for ; Wed, 20 Dec 2017 10:56:02 -0500 (EST) Received: by mail-pl0-f69.google.com with SMTP id 3so8170292plv.17 for ; Wed, 20 Dec 2017 07:56:02 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id 70si13406605pfr.84.2017.12.20.07.56.01 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Dec 2017 07:56:01 -0800 (PST) From: Matthew Wilcox Subject: [PATCH v2 4/8] mm: Improve comment on page->mapping Date: Wed, 20 Dec 2017 07:55:48 -0800 Message-Id: <20171220155552.15884-5-willy@infradead.org> In-Reply-To: <20171220155552.15884-1-willy@infradead.org> References: <20171220155552.15884-1-willy@infradead.org> Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org Cc: akpm@linuxfoundation.org, Matthew Wilcox From: Matthew Wilcox The comment on page->mapping is terse, and out of date (it does not mention the possibility of PAGE_MAPPING_MOVABLE). Instead, point the interested reader to page-flags.h where there is a much better comment. Signed-off-by: Matthew Wilcox Acked-by: Kirill A. Shutemov Acked-by: Michal Hocko Acked-by: Christoph Lameter --- include/linux/mm_types.h | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index c2294e6204e8..8c3b8cea22ee 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -50,15 +50,9 @@ struct page { unsigned long flags; /* Atomic flags, some possibly * updated asynchronously */ union { - struct address_space *mapping; /* If low bit clear, points to - * inode address_space, or NULL. - * If page mapped as anonymous - * memory, low bit is set, and - * it points to anon_vma object - * or KSM private structure. See - * PAGE_MAPPING_ANON and - * PAGE_MAPPING_KSM. - */ + /* See page-flags.h for the definition of PAGE_MAPPING_FLAGS */ + struct address_space *mapping; + void *s_mem; /* slab first object */ atomic_t compound_mapcount; /* first tail page */ /* page_deferred_list().next -- second tail page */ -- 2.15.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f197.google.com (mail-pf0-f197.google.com [209.85.192.197]) by kanga.kvack.org (Postfix) with ESMTP id 4A9276B0261 for ; Wed, 20 Dec 2017 10:56:03 -0500 (EST) Received: by mail-pf0-f197.google.com with SMTP id e26so16649927pfi.15 for ; Wed, 20 Dec 2017 07:56:03 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id r6si13573511pli.733.2017.12.20.07.56.02 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Dec 2017 07:56:02 -0800 (PST) From: Matthew Wilcox Subject: [PATCH v2 5/8] mm: Introduce _slub_counter_t Date: Wed, 20 Dec 2017 07:55:49 -0800 Message-Id: <20171220155552.15884-6-willy@infradead.org> In-Reply-To: <20171220155552.15884-1-willy@infradead.org> References: <20171220155552.15884-1-willy@infradead.org> Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org Cc: akpm@linuxfoundation.org, Matthew Wilcox From: Matthew Wilcox Instead of putting the ifdef in the middle of the definition of struct page, pull it forward to the rest of the ifdeffery around the SLUB cmpxchg_double optimisation. Signed-off-by: Matthew Wilcox Acked-by: Kirill A. Shutemov Acked-by: Michal Hocko --- include/linux/mm_types.h | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 8c3b8cea22ee..5521c9799c50 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -41,9 +41,15 @@ struct hmm; */ #ifdef CONFIG_HAVE_ALIGNED_STRUCT_PAGE #define _struct_page_alignment __aligned(2 * sizeof(unsigned long)) +#if defined(CONFIG_HAVE_CMPXCHG_DOUBLE) +#define _slub_counter_t unsigned long #else -#define _struct_page_alignment +#define _slub_counter_t unsigned int #endif +#else /* !CONFIG_HAVE_ALIGNED_STRUCT_PAGE */ +#define _struct_page_alignment +#define _slub_counter_t unsigned int +#endif /* !CONFIG_HAVE_ALIGNED_STRUCT_PAGE */ struct page { /* First double word block */ @@ -66,18 +72,7 @@ struct page { }; union { -#if defined(CONFIG_HAVE_CMPXCHG_DOUBLE) && \ - defined(CONFIG_HAVE_ALIGNED_STRUCT_PAGE) - /* Used for cmpxchg_double in slub */ - unsigned long counters; -#else - /* - * Keep _refcount separate from slub cmpxchg_double data. - * As the rest of the double word is protected by slab_lock - * but _refcount is not. - */ - unsigned counters; -#endif + _slub_counter_t counters; unsigned int active; /* SLAB */ struct { /* SLUB */ unsigned inuse:16; -- 2.15.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f198.google.com (mail-pf0-f198.google.com [209.85.192.198]) by kanga.kvack.org (Postfix) with ESMTP id E7A296B026F for ; Wed, 20 Dec 2017 10:56:03 -0500 (EST) Received: by mail-pf0-f198.google.com with SMTP id r88so16555070pfi.23 for ; Wed, 20 Dec 2017 07:56:03 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id v1si11334472ply.506.2017.12.20.07.56.02 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Dec 2017 07:56:02 -0800 (PST) From: Matthew Wilcox Subject: [PATCH v2 6/8] mm: Store compound_dtor / compound_order as bytes Date: Wed, 20 Dec 2017 07:55:50 -0800 Message-Id: <20171220155552.15884-7-willy@infradead.org> In-Reply-To: <20171220155552.15884-1-willy@infradead.org> References: <20171220155552.15884-1-willy@infradead.org> Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org Cc: akpm@linuxfoundation.org, Matthew Wilcox From: Matthew Wilcox Neither of these values get even close to 256; compound_dtor is currently at a maximum of 3, and compound_order can't be over 64. No machine has inefficient access to bytes since EV5, and while those are still supported, we don't optimise for them any more. This does not shrink struct page, but it removes an ifdef and frees up 2-6 bytes for future use. diff of pahole output: @@ -34,8 +34,8 @@ struct callback_head callback_head; /* 32 16 */ struct { long unsigned int compound_head; /* 32 8 */ - unsigned int compound_dtor; /* 40 4 */ - unsigned int compound_order; /* 44 4 */ + unsigned char compound_dtor; /* 40 1 */ + unsigned char compound_order; /* 41 1 */ }; /* 32 16 */ }; /* 32 16 */ union { Signed-off-by: Matthew Wilcox Acked-by: Kirill A. Shutemov Acked-by: Michal Hocko --- include/linux/mm_types.h | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 5521c9799c50..1a3ba1f1605d 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -136,19 +136,8 @@ struct page { unsigned long compound_head; /* If bit zero is set */ /* First tail page only */ -#ifdef CONFIG_64BIT - /* - * On 64 bit system we have enough space in struct page - * to encode compound_dtor and compound_order with - * unsigned int. It can help compiler generate better or - * smaller code on some archtectures. - */ - unsigned int compound_dtor; - unsigned int compound_order; -#else - unsigned short int compound_dtor; - unsigned short int compound_order; -#endif + unsigned char compound_dtor; + unsigned char compound_order; }; #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && USE_SPLIT_PMD_PTLOCKS -- 2.15.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl0-f70.google.com (mail-pl0-f70.google.com [209.85.160.70]) by kanga.kvack.org (Postfix) with ESMTP id 69E0B6B0271 for ; Wed, 20 Dec 2017 10:56:04 -0500 (EST) Received: by mail-pl0-f70.google.com with SMTP id d3so9702894plj.22 for ; Wed, 20 Dec 2017 07:56:04 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id k192si12003825pgc.650.2017.12.20.07.56.03 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Dec 2017 07:56:03 -0800 (PST) From: Matthew Wilcox Subject: [PATCH v2 7/8] mm: Document how to use struct page Date: Wed, 20 Dec 2017 07:55:51 -0800 Message-Id: <20171220155552.15884-8-willy@infradead.org> In-Reply-To: <20171220155552.15884-1-willy@infradead.org> References: <20171220155552.15884-1-willy@infradead.org> Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org Cc: akpm@linuxfoundation.org, Matthew Wilcox From: Matthew Wilcox Be really explicit about what bits / bytes are reserved for users that want to store extra information about the pages they allocate. Signed-off-by: Matthew Wilcox Acked-by: Kirill A. Shutemov Reviewed-by: Randy Dunlap Acked-by: Michal Hocko --- include/linux/mm_types.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 1a3ba1f1605d..ef35ea524c26 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -31,7 +31,29 @@ struct hmm; * it to keep track of whatever it is we are using the page for at the * moment. Note that we have no way to track which tasks are using * a page, though if it is a pagecache page, rmap structures can tell us - * who is mapping it. + * who is mapping it. If you allocate the page using alloc_pages(), you + * can use some of the space in struct page for your own purposes. + * + * Pages that were once in the page cache may be found under the RCU lock + * even after they have been recycled to a different purpose. The page + * cache reads and writes some of the fields in struct page to pin the + * page before checking that it's still in the page cache. It is vital + * that all users of struct page: + * 1. Use the first word as PageFlags. + * 2. Clear or preserve bit 0 of page->compound_head. It is used as + * PageTail for compound pages, and the page cache must not see false + * positives. Some users put a pointer here (guaranteed to be at least + * 4-byte aligned), other users avoid using the field altogether. + * 3. page->_refcount must either not be used, or must be used in such a + * way that other CPUs temporarily incrementing and then decrementing the + * refcount does not cause problems. On receiving the page from + * alloc_pages(), the refcount will be positive. + * 4. Either preserve page->_mapcount or restore it to -1 before freeing it. + * + * If you allocate pages of order > 0, you can use the fields in the struct + * page associated with each page, but bear in mind that the pages may have + * been inserted individually into the page cache, so you must use the above + * four fields in a compatible way for each struct page. * * SLUB uses cmpxchg_double() to atomically update its freelist and * counters. That requires that freelist & counters be adjacent and -- 2.15.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg0-f72.google.com (mail-pg0-f72.google.com [74.125.83.72]) by kanga.kvack.org (Postfix) with ESMTP id B8D686B0273 for ; Wed, 20 Dec 2017 10:56:04 -0500 (EST) Received: by mail-pg0-f72.google.com with SMTP id v190so14492323pgv.11 for ; Wed, 20 Dec 2017 07:56:04 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id a20si13364114pfg.38.2017.12.20.07.56.03 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Dec 2017 07:56:03 -0800 (PST) From: Matthew Wilcox Subject: [PATCH v2 8/8] mm: Remove reference to PG_buddy Date: Wed, 20 Dec 2017 07:55:52 -0800 Message-Id: <20171220155552.15884-9-willy@infradead.org> In-Reply-To: <20171220155552.15884-1-willy@infradead.org> References: <20171220155552.15884-1-willy@infradead.org> Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org Cc: akpm@linuxfoundation.org, Matthew Wilcox From: Matthew Wilcox PG_buddy doesn't exist any more. It's called PageBuddy now. Signed-off-by: Matthew Wilcox Acked-by: Kirill A. Shutemov Acked-by: Michal Hocko Acked-by: Christoph Lameter --- include/linux/mm_types.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index ef35ea524c26..9b154b4e912e 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -174,13 +174,13 @@ struct page { }; union { - unsigned long private; /* Mapping-private opaque data: - * usually used for buffer_heads - * if PagePrivate set; used for - * swp_entry_t if PageSwapCache; - * indicates order in the buddy - * system if PG_buddy is set. - */ + /* + * 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 #if ALLOC_SPLIT_PTLOCKS spinlock_t *ptl; -- 2.15.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f72.google.com (mail-wm0-f72.google.com [74.125.82.72]) by kanga.kvack.org (Postfix) with ESMTP id 6E30D6B0069 for ; Wed, 20 Dec 2017 18:39:11 -0500 (EST) Received: by mail-wm0-f72.google.com with SMTP id p190so3274820wmd.0 for ; Wed, 20 Dec 2017 15:39:11 -0800 (PST) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org. [140.211.169.12]) by mx.google.com with ESMTPS id n188si3752598wma.203.2017.12.20.15.39.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Dec 2017 15:39:10 -0800 (PST) Date: Wed, 20 Dec 2017 15:39:07 -0800 From: Andrew Morton Subject: Re: [PATCH v2 6/8] mm: Store compound_dtor / compound_order as bytes Message-Id: <20171220153907.7f3994967cba32c6f654982c@linux-foundation.org> In-Reply-To: <20171220155552.15884-7-willy@infradead.org> References: <20171220155552.15884-1-willy@infradead.org> <20171220155552.15884-7-willy@infradead.org> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Matthew Wilcox Cc: linux-mm@kvack.org, Matthew Wilcox On Wed, 20 Dec 2017 07:55:50 -0800 Matthew Wilcox wrote: > From: Matthew Wilcox > > Neither of these values get even close to 256; compound_dtor is > currently at a maximum of 3, and compound_order can't be over 64. > No machine has inefficient access to bytes since EV5, and while > those are still supported, we don't optimise for them any more. So we couild fit compound_dtor and compound_order into a single byte if desperate? > This does not shrink struct page, but it removes an ifdef and > frees up 2-6 bytes for future use. Can we add a little comment telling readers "hey there's a gap here!"? -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f200.google.com (mail-pf0-f200.google.com [209.85.192.200]) by kanga.kvack.org (Postfix) with ESMTP id 3C5506B0038 for ; Wed, 20 Dec 2017 19:01:47 -0500 (EST) Received: by mail-pf0-f200.google.com with SMTP id f64so17270853pfd.6 for ; Wed, 20 Dec 2017 16:01:47 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id a64si13949456pfc.349.2017.12.20.16.01.45 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Dec 2017 16:01:45 -0800 (PST) Date: Wed, 20 Dec 2017 16:01:44 -0800 From: Matthew Wilcox Subject: Re: [PATCH v2 6/8] mm: Store compound_dtor / compound_order as bytes Message-ID: <20171221000144.GB2980@bombadil.infradead.org> References: <20171220155552.15884-1-willy@infradead.org> <20171220155552.15884-7-willy@infradead.org> <20171220153907.7f3994967cba32c6f654982c@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171220153907.7f3994967cba32c6f654982c@linux-foundation.org> Sender: owner-linux-mm@kvack.org List-ID: To: Andrew Morton Cc: linux-mm@kvack.org, Matthew Wilcox On Wed, Dec 20, 2017 at 03:39:07PM -0800, Andrew Morton wrote: > On Wed, 20 Dec 2017 07:55:50 -0800 Matthew Wilcox wrote: > > > From: Matthew Wilcox > > > > Neither of these values get even close to 256; compound_dtor is > > currently at a maximum of 3, and compound_order can't be over 64. > > No machine has inefficient access to bytes since EV5, and while > > those are still supported, we don't optimise for them any more. > > So we couild fit compound_dtor and compound_order into a single byte if > desperate? Yes ... unless we find another kind of destructor we need for compound pages. > > This does not shrink struct page, but it removes an ifdef and > > frees up 2-6 bytes for future use. > > Can we add a little comment telling readers "hey there's a gap here!"? I think they should have to work to find it! Here's a replacement patch: From: Matthew Wilcox Date: Fri, 15 Dec 2017 23:29:11 -0500 Subject: [PATCH] mm: Store compound_dtor / compound_order as bytes Neither of these values get even close to 256; compound_dtor is currently at a maximum of 3, and compound_order can't be over 64. No machine has inefficient access to bytes since EV5, and while those are still supported, we don't optimise for them any more. This does not shrink struct page, but it removes an ifdef and frees up 2-6 bytes for future use. diff of pahole output: @@ -34,8 +34,8 @@ struct callback_head callback_head; /* 32 16 */ struct { long unsigned int compound_head; /* 32 8 */ - unsigned int compound_dtor; /* 40 4 */ - unsigned int compound_order; /* 44 4 */ + unsigned char compound_dtor; /* 40 1 */ + unsigned char compound_order; /* 41 1 */ }; /* 32 16 */ }; /* 32 16 */ union { Signed-off-by: Matthew Wilcox Acked-by: Kirill A. Shutemov Acked-by: Michal Hocko --- include/linux/mm_types.h | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 5521c9799c50..3e7e99784656 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -136,19 +136,9 @@ struct page { unsigned long compound_head; /* If bit zero is set */ /* First tail page only */ -#ifdef CONFIG_64BIT - /* - * On 64 bit system we have enough space in struct page - * to encode compound_dtor and compound_order with - * unsigned int. It can help compiler generate better or - * smaller code on some archtectures. - */ - unsigned int compound_dtor; - unsigned int compound_order; -#else - unsigned short int compound_dtor; - unsigned short int compound_order; -#endif + unsigned char compound_dtor; + unsigned char compound_order; + /* two/six bytes available here */ }; #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && USE_SPLIT_PMD_PTLOCKS -- 2.15.1 Seriously, this is only available in the first tail page of a compound page, so they'll have to go through Kirill to have it assigned to them ... I don't want to pretend like it's available for general use. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org