Skip to content

Commit 632c0a1

Browse files
Vladimir Davydovtorvalds
authored andcommitted
mm: clean up non-standard page->_mapcount users
- Add a proper comment to page->_mapcount. - Introduce a macro for generating helper functions. - Place all special page->_mapcount values next to each other so that readers can see all possible values and so we don't get duplicates. Link: http://lkml.kernel.org/r/502f49000e0b63e6c62e338fac6b420bf34fb526.1464079537.git.vdavydov@virtuozzo.com Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@kernel.org> Cc: Eric Dumazet <eric.dumazet@gmail.com> Cc: Minchan Kim <minchan@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 99691ad commit 632c0a1

File tree

3 files changed

+40
-41
lines changed

3 files changed

+40
-41
lines changed

include/linux/mm_types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ struct page {
8585
/*
8686
* Count of ptes mapped in mms, to show when
8787
* page is mapped & limit reverse map searches.
88+
*
89+
* Extra information about page type may be
90+
* stored here for pages that are never mapped,
91+
* in which case the value MUST BE <= -2.
92+
* See page-flags.h for more details.
8893
*/
8994
atomic_t _mapcount;
9095

include/linux/page-flags.h

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -604,54 +604,45 @@ TESTPAGEFLAG_FALSE(DoubleMap)
604604
#endif
605605

606606
/*
607-
* PageBuddy() indicate that the page is free and in the buddy system
608-
* (see mm/page_alloc.c).
609-
*
610-
* PAGE_BUDDY_MAPCOUNT_VALUE must be <= -2 but better not too close to
611-
* -2 so that an underflow of the page_mapcount() won't be mistaken
612-
* for a genuine PAGE_BUDDY_MAPCOUNT_VALUE. -128 can be created very
613-
* efficiently by most CPU architectures.
607+
* For pages that are never mapped to userspace, page->mapcount may be
608+
* used for storing extra information about page type. Any value used
609+
* for this purpose must be <= -2, but it's better start not too close
610+
* to -2 so that an underflow of the page_mapcount() won't be mistaken
611+
* for a special page.
614612
*/
615-
#define PAGE_BUDDY_MAPCOUNT_VALUE (-128)
616-
617-
static inline int PageBuddy(struct page *page)
618-
{
619-
return atomic_read(&page->_mapcount) == PAGE_BUDDY_MAPCOUNT_VALUE;
613+
#define PAGE_MAPCOUNT_OPS(uname, lname) \
614+
static __always_inline int Page##uname(struct page *page) \
615+
{ \
616+
return atomic_read(&page->_mapcount) == \
617+
PAGE_##lname##_MAPCOUNT_VALUE; \
618+
} \
619+
static __always_inline void __SetPage##uname(struct page *page) \
620+
{ \
621+
VM_BUG_ON_PAGE(atomic_read(&page->_mapcount) != -1, page); \
622+
atomic_set(&page->_mapcount, PAGE_##lname##_MAPCOUNT_VALUE); \
623+
} \
624+
static __always_inline void __ClearPage##uname(struct page *page) \
625+
{ \
626+
VM_BUG_ON_PAGE(!Page##uname(page), page); \
627+
atomic_set(&page->_mapcount, -1); \
620628
}
621629

622-
static inline void __SetPageBuddy(struct page *page)
623-
{
624-
VM_BUG_ON_PAGE(atomic_read(&page->_mapcount) != -1, page);
625-
atomic_set(&page->_mapcount, PAGE_BUDDY_MAPCOUNT_VALUE);
626-
}
630+
/*
631+
* PageBuddy() indicate that the page is free and in the buddy system
632+
* (see mm/page_alloc.c).
633+
*/
634+
#define PAGE_BUDDY_MAPCOUNT_VALUE (-128)
635+
PAGE_MAPCOUNT_OPS(Buddy, BUDDY)
627636

628-
static inline void __ClearPageBuddy(struct page *page)
629-
{
630-
VM_BUG_ON_PAGE(!PageBuddy(page), page);
631-
atomic_set(&page->_mapcount, -1);
632-
}
637+
/*
638+
* PageBalloon() is set on pages that are on the balloon page list
639+
* (see mm/balloon_compaction.c).
640+
*/
641+
#define PAGE_BALLOON_MAPCOUNT_VALUE (-256)
642+
PAGE_MAPCOUNT_OPS(Balloon, BALLOON)
633643

634644
extern bool is_free_buddy_page(struct page *page);
635645

636-
#define PAGE_BALLOON_MAPCOUNT_VALUE (-256)
637-
638-
static inline int PageBalloon(struct page *page)
639-
{
640-
return atomic_read(&page->_mapcount) == PAGE_BALLOON_MAPCOUNT_VALUE;
641-
}
642-
643-
static inline void __SetPageBalloon(struct page *page)
644-
{
645-
VM_BUG_ON_PAGE(atomic_read(&page->_mapcount) != -1, page);
646-
atomic_set(&page->_mapcount, PAGE_BALLOON_MAPCOUNT_VALUE);
647-
}
648-
649-
static inline void __ClearPageBalloon(struct page *page)
650-
{
651-
VM_BUG_ON_PAGE(!PageBalloon(page), page);
652-
atomic_set(&page->_mapcount, -1);
653-
}
654-
655646
__PAGEFLAG(Isolated, isolated, PF_ANY);
656647

657648
/*

scripts/tags.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ regex_c=(
185185
'/\<CLEARPAGEFLAG_NOOP(\([[:alnum:]_]*\).*/ClearPage\1/'
186186
'/\<__CLEARPAGEFLAG_NOOP(\([[:alnum:]_]*\).*/__ClearPage\1/'
187187
'/\<TESTCLEARFLAG_FALSE(\([[:alnum:]_]*\).*/TestClearPage\1/'
188+
'/^PAGE_MAPCOUNT_OPS(\([[:alnum:]_]*\).*/Page\1/'
189+
'/^PAGE_MAPCOUNT_OPS(\([[:alnum:]_]*\).*/__SetPage\1/'
190+
'/^PAGE_MAPCOUNT_OPS(\([[:alnum:]_]*\).*/__ClearPage\1/'
188191
'/^TASK_PFA_TEST([^,]*, *\([[:alnum:]_]*\))/task_\1/'
189192
'/^TASK_PFA_SET([^,]*, *\([[:alnum:]_]*\))/task_set_\1/'
190193
'/^TASK_PFA_CLEAR([^,]*, *\([[:alnum:]_]*\))/task_clear_\1/'

0 commit comments

Comments
 (0)