Skip to content

Commit 1378a5e

Browse files
Matthew Wilcox (Oracle)torvalds
authored andcommitted
mm: store compound_nr as well as compound_order
Patch series "THP prep patches". These are some generic cleanups and improvements, which I would like merged into mmotm soon. The first one should be a performance improvement for all users of compound pages, and the others are aimed at getting code to compile away when CONFIG_TRANSPARENT_HUGEPAGE is disabled (ie small systems). Also better documented / less confusing than the current prefix mixture of compound, hpage and thp. This patch (of 7): This removes a few instructions from functions which need to know how many pages are in a compound page. The storage used is either page->mapping on 64-bit or page->index on 32-bit. Both of these are fine to overlay on tail pages. Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Reviewed-by: William Kucharski <[email protected]> Reviewed-by: Zi Yan <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Mike Kravetz <[email protected]> Cc: "Kirill A. Shutemov" <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent 14a36a4 commit 1378a5e

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

include/linux/mm.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,12 +922,15 @@ static inline int compound_pincount(struct page *page)
922922
static inline void set_compound_order(struct page *page, unsigned int order)
923923
{
924924
page[1].compound_order = order;
925+
page[1].compound_nr = 1U << order;
925926
}
926927

927928
/* Returns the number of pages in this potentially compound page. */
928929
static inline unsigned long compound_nr(struct page *page)
929930
{
930-
return 1UL << compound_order(page);
931+
if (!PageHead(page))
932+
return 1;
933+
return page[1].compound_nr;
931934
}
932935

933936
/* Returns the number of bytes in this potentially compound page. */

include/linux/mm_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ struct page {
134134
unsigned char compound_dtor;
135135
unsigned char compound_order;
136136
atomic_t compound_mapcount;
137+
unsigned int compound_nr; /* 1 << compound_order */
137138
};
138139
struct { /* Second tail page of compound page */
139140
unsigned long _compound_pad_1; /* compound_head */

mm/page_alloc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,15 +666,16 @@ void prep_compound_page(struct page *page, unsigned int order)
666666
int i;
667667
int nr_pages = 1 << order;
668668

669-
set_compound_page_dtor(page, COMPOUND_PAGE_DTOR);
670-
set_compound_order(page, order);
671669
__SetPageHead(page);
672670
for (i = 1; i < nr_pages; i++) {
673671
struct page *p = page + i;
674672
set_page_count(p, 0);
675673
p->mapping = TAIL_MAPPING;
676674
set_compound_head(p, page);
677675
}
676+
677+
set_compound_page_dtor(page, COMPOUND_PAGE_DTOR);
678+
set_compound_order(page, order);
678679
atomic_set(compound_mapcount_ptr(page), -1);
679680
if (hpage_pincount_available(page))
680681
atomic_set(compound_pincount_ptr(page), 0);

0 commit comments

Comments
 (0)