Skip to content

Commit

Permalink
page-flags: move code around
Browse files Browse the repository at this point in the history
The preparation patch: we are going to use compound_head(), PageTail()
and PageCompound() to define page-flags helpers.

Let's define them before macros.

We cannot user PageHead() helper in PageCompound() as it's not yet
defined -- use test_bit(PG_head, &page->flags) instead.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Rik van Riel <riel@redhat.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Christoph Lameter <cl@linux.com>
Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: Steve Capper <steve.capper@linaro.org>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Jerome Marchand <jmarchan@redhat.com>
Cc: Jérôme Glisse <jglisse@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Kirill A. Shutemov authored and Linus Torvalds committed Jan 16, 2016
1 parent d8c1bde commit 0e6d31a
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions include/linux/page-flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,27 @@ enum pageflags {

#ifndef __GENERATING_BOUNDS_H

struct page; /* forward declaration */

static inline struct page *compound_head(struct page *page)
{
unsigned long head = READ_ONCE(page->compound_head);

if (unlikely(head & 1))
return (struct page *) (head - 1);
return page;
}

static inline int PageTail(struct page *page)
{
return READ_ONCE(page->compound_head) & 1;
}

static inline int PageCompound(struct page *page)
{
return test_bit(PG_head, &page->flags) || PageTail(page);
}

/*
* Macros to create function definitions for page flags
*/
Expand Down Expand Up @@ -204,7 +225,6 @@ static inline int __TestClearPage##uname(struct page *page) { return 0; }
#define TESTSCFLAG_FALSE(uname) \
TESTSETFLAG_FALSE(uname) TESTCLEARFLAG_FALSE(uname)

struct page; /* forward declaration */

TESTPAGEFLAG(Locked, locked)
PAGEFLAG(Error, error) TESTCLEARFLAG(Error, error)
Expand Down Expand Up @@ -395,11 +415,6 @@ static inline void set_page_writeback_keepwrite(struct page *page)

__PAGEFLAG(Head, head) CLEARPAGEFLAG(Head, head)

static inline int PageTail(struct page *page)
{
return READ_ONCE(page->compound_head) & 1;
}

static inline void set_compound_head(struct page *page, struct page *head)
{
WRITE_ONCE(page->compound_head, (unsigned long)head + 1);
Expand All @@ -410,20 +425,6 @@ static inline void clear_compound_head(struct page *page)
WRITE_ONCE(page->compound_head, 0);
}

static inline struct page *compound_head(struct page *page)
{
unsigned long head = READ_ONCE(page->compound_head);

if (unlikely(head & 1))
return (struct page *) (head - 1);
return page;
}

static inline int PageCompound(struct page *page)
{
return PageHead(page) || PageTail(page);

}
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
static inline void ClearPageCompound(struct page *page)
{
Expand Down

0 comments on commit 0e6d31a

Please sign in to comment.