Compound Page Enhancements
Subsystems (4)
cover Compound Page Enhancements
This patch enhances the handling of compound pages in the VM. It may also be important also for the antifrag patches that need to manage a set of higher order free pages and also for other uses of compound pages.
For now it simplifies accounting for SLUB pages but the groundwork here is important for the large block size patches and for allowing to page migration of larger pages. With this framework we may be able to get to a point where compound pages keep their flags while they are free and Mel may avoid having special functions for determining the page order of higher order freed pages. If we can avoid the setup and teardown of higher order pages then allocation and release of compound pages will be faster.
Looking at the handling of compound pages we see that the fact that a page is part of a higher order page is not that interesting. The differentiation is mainly for head pages and tail pages of higher order pages. Head pages usually need special handling to accomodate the larger size. It is usually an error if tail pages are encountered. Or else they need to be treated like PAGE_SIZE pages. So a compound flag in the page flags is not what we need. Instead we introduce a flag for the head page and another for the tail page. The PageCompound test is preserved for backward compatibility and will test if either PageTail or PageHead has been set.
After this patchset the uses of CompoundPage() will be reduced significantly in the core VM. The I/O layer will still use CompoundPage() for direct I/O. However, if we at some point convert direct I/O to also support compound pages as a single unit then CompoundPage() there may become unecessary as well as the leftover check in mm/swap.c. We may end up mostly with checks for PageTail and PageHead.
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/6 Compound page handling enhancements
This patch enhances the handling of compound pages in the VM. It may also be important also for the antifrag patches that need to manage a set of higher order free pages and also for other uses of compound pages.
For now it simplifies accounting for SLUB pages but the groundwork here is important for the large block size patches and for allowing to page migration of larger pages. With this framework we may be able to get to a point where compound pages keep their flags while they are free and Mel may avoid having special functions for determining the page order of higher order freed pages. If we can avoid the setup and teardown of higher order pages then allocation and release of compound pages will be faster.
Looking at the handling of compound pages we see that the fact that a page is part of a higher order page is not that interesting. The differentiation is mainly for head pages and tail pages of higher order pages. Head pages usually need special handling to accomodate the larger size. It is usually an error if tail pages are encountered. Or else they need to be treated like PAGE_SIZE pages. So a compound flag in the page flags is not what we need. Instead we introduce a flag for the head page and another for the tail page. The PageCompound test is preserved for backward compatibility and will test if either PageTail or PageHead has been set.
After this patchset the uses of CompoundPage() will be reduced significantly in the core VM. The I/O layer will still use CompoundPage() for direct I/O. However, if we at some point convert direct I/O to also support compound pages as a single unit then CompoundPage() there may become unecessary as well as the leftover check in mm/swap.c. We may end up mostly with checks for PageTail and PageHead.
This patch:
Use two separate page flags for the head and tail of compound pages. PageHead() and PageTail() become more efficient.
PageCompound then becomes a check for PageTail || PageHead. Over time it is expected that PageCompound will mostly go away since the head page processing will be different from tail page processing is most situations.
We can remove the compound page check from set_page_refcounted since PG_reclaim is no longer overloaded.
Also the check in _free_one_page can only be for PageHead. We cannot free a tail page.
--- include/linux/page-flags.h | 43 ++++++++++++------------------------------- mm/internal.h | 2 +- mm/page_alloc.c | 2 +- 3 files changed, 14 insertions(+), 33 deletions(-)
include/linux/page-flags.h +12 -31
@@ -83,7 +83,6 @@#define PG_private 11/* If pagecache, has fs-private data */ #define PG_writeback 12/* Page is under writeback */ -#define PG_compound 13/* Part of a compound page */ #define PG_swapcache 14/* Swap page: swp_entry_t in private */ #define PG_mappedtodisk 15/* Has blocks allocated on-disk */
@@ -92,6 +91,9 @@#define PG_lazyfree 18/* MADV_FREE potential throwaway */ #define PG_booked 19/* Has blocks reserved on-disk */ +#define PG_head 21/* Page is head of a compound page */ +#define PG_tail 22/* Page is tail of a compound page */ +/* PG_readahead is only used for file reads; PG_reclaim is only for writes */ #define PG_readahead PG_reclaim/* Reminder to do async read-ahead */
@@ -227,37 +229,16 @@ static inline void SetPageUptodate(struc#define ClearPageLazyFree (page) clear_bit(PG_lazyfree, &(page)->flags)#define __ClearPageLazyFree (page) __clear_bit(PG_lazyfree, &(page)->flags) -#define PageCompound (page) test_bit(PG_compound, &(page)->flags) -#define __SetPageCompound (page) __set_bit(PG_compound, &(page)->flags) -#define __ClearPageCompound (page) __clear_bit(PG_compound, &(page)->flags) - -/* -* PG_reclaim is used in combination with PG_compound to mark the -* head and tail of a compound page -* -* PG_compound & PG_reclaim => Tail page -* PG_compound & ~PG_reclaim => Head page -*/ - -#define PG_head_tail_mask ((1L << PG_compound) | (1L << PG_reclaim)) - -#define PageTail (page) ((page->flags & PG_head_tail_mask) \ - == PG_head_tail_mask) - -static inline void __SetPageTail (struct page *page) -{ - page->flags |= PG_head_tail_mask; -} - -static inline void __ClearPageTail (struct page *page) -{ - page->flags &= ~PG_head_tail_mask; -} +#define PageHead (page) test_bit(PG_head, &(page)->flags) +#define __SetPageHead (page) __set_bit(PG_head, &(page)->flags) +#define __ClearPageHead (page) __clear_bit(PG_head, &(page)->flags) + +#define PageTail (page) test_bit(PG_tail, &(page->flags)) +#define __SetPageTail (page) __set_bit(PG_tail, &(page)->flags) +#define __ClearPageTail (page) __clear_bit(PG_tail, &(page)->flags) -#define PageHead (page) ((page->flags & PG_head_tail_mask) \ - == (1L << PG_compound)) -#define __SetPageHead (page) __SetPageCompound(page) -#define __ClearPageHead (page) __ClearPageCompound(page) +#define PageCompound (page) ((page)->flags & \ + ((1L << PG_head) | (1L << PG_tail)))#ifdef CONFIG_SWAP #define PageSwapCache (page) test_bit(PG_swapcache, &(page)->flags)
mm/internal.h +1 -1
@@ -24,7 +24,7 @@ static inline void set_page_count(struct*/ static inline void set_page_refcounted (struct page *page) { -VM_BUG_ON (PageCompound (page) &&PageTail (page)); +VM_BUG_ON (PageTail (page));VM_BUG_ON (atomic_read (&page->_count));set_page_count (page,1 ); }
mm/page_alloc.c +1 -1
@@ -449,7 +449,7 @@ static inline void __free_one_page(strucint order_size =1 << order;int migratetype =get_pageblock_migratetype (page); -if (unlikely (PageCompound (page))) +if (unlikely (PageHead (page)))destroy_compound_page (page, order); page_idx =page_to_pfn (page) & ((1 <<MAX_ORDER ) -1 );
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/6 compound pages: Add new support functions
In reply to [email protected]compound_pages(page) -> Determines base pages of a compound page
compound_shift(page) -> Determine the page shift of a compound page
compound_size(page) -> Determine the size of a compound page
--- include/linux/mm.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
include/linux/mm.h +15 -0
@@ -366,6 +366,21 @@ static inline void set_compound_order(st page[1 ].lru.prev = (void *)order; } +static inline int compound_pages (struct page *page) +{ +return 1 <<compound_order (page); +} + +static inline int compound_shift (struct page *page) +{ +return PAGE_SHIFT +compound_order (page); +} + +static inline int compound_size (struct page *page) +{ +return PAGE_SIZE <<compound_order (page); +} +/* * Multiple processes may "see" the same page. E.g. for untouched * mappings of /dev/null, all processes see the same page full of
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 3/6 compound pages: vmstat support
In reply to [email protected]Add support for compound pages so that
inc_xxxx and dec_xxx
will increment the ZVCs by the number of pages of the compound page.
--- include/linux/vmstat.h | 5 ++--- mm/vmstat.c | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 8 deletions(-)
include/linux/vmstat.h +2 -3
@@ -234,7 +234,7 @@ static inline void __inc_zone_state(strustatic inline void __inc_zone_page_state (struct page *page,enum zone_stat_item item) { -__inc_zone_state (page_zone (page), item); +__mod_zone_page_state (page_zone (page), item,compound_pages (page)); }static inline void __dec_zone_state (struct zone *zone,enum zone_stat_item item)
@@ -246,8 +246,7 @@ static inline void __dec_zone_state(strustatic inline void __dec_zone_page_state (struct page *page,enum zone_stat_item item) { -atomic_long_dec (&page_zone (page)->vm_stat[item]); -atomic_long_dec (&vm_stat[item]); +__mod_zone_page_state (page_zone (page), item, -compound_pages (page)); }/*
mm/vmstat.c +13 -5
@@ -224,7 +224,12 @@ void __inc_zone_state(struct zone *zone,void __inc_zone_page_state (struct page *page,enum zone_stat_item item) { -__inc_zone_state (page_zone (page), item); +struct zone *z =page_zone (page); + +if (likely (!PageHead (page))) +__inc_zone_state (z, item); +else +__mod_zone_page_state (z, item,compound_pages (page)); }EXPORT_SYMBOL (__inc_zone_page_state);
@@ -245,7 +250,12 @@ void __dec_zone_state(struct zone *zone,void __dec_zone_page_state (struct page *page,enum zone_stat_item item) { -__dec_zone_state (page_zone (page), item); +struct zone *z =page_zone (page); + +if (likely (!PageHead (page))) +__dec_zone_state (z, item); +else +__mod_zone_page_state (z, item, -compound_pages (page)); }EXPORT_SYMBOL (__dec_zone_page_state);
@@ -261,11 +271,9 @@ void inc_zone_state(struct zone *zone, evoid inc_zone_page_state (struct page *page,enum zone_stat_item item) {unsigned long flags; -struct zone *zone; - zone =page_zone (page);local_irq_save (flags); -__inc_zone_state (zone, item); +__inc_zone_page_state (page, item);local_irq_restore (flags); }EXPORT_SYMBOL (inc_zone_page_state);
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 4/6 compound pages: Use new compound vmstat functions in SLUB
In reply to [email protected]Use the new dec/inc functions to simplify SLUB's accounting of pages.
--- mm/slub.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
mm/slub.c +4 -9
@@ -965,7 +965,6 @@ static inline void kmem_cache_open_debugstatic struct page *allocate_slab (struct kmem_cache *s,gfp_t flags,int node) {struct page * page; -int pages =1 << s->order;if (s->order) flags |= __GFP_COMP;
@@ -984,10 +983,9 @@ static struct page *allocate_slab(structif (!page)return NULL ; -mod_zone_page_state (page_zone (page), +inc_zone_page_state (page, (s->flags &SLAB_RECLAIM_ACCOUNT ) ? -NR_SLAB_RECLAIMABLE :NR_SLAB_UNRECLAIMABLE , - pages); +NR_SLAB_RECLAIMABLE :NR_SLAB_UNRECLAIMABLE );return page; }
@@ -1054,8 +1052,6 @@ out:static void __free_slab (struct kmem_cache *s,struct page *page) { -int pages =1 << s->order; -if (unlikely (SlabDebug (page))) {void *p;
@@ -1064,10 +1060,9 @@ static void __free_slab(struct kmem_cachcheck_object (s, page, p,0 ); } -mod_zone_page_state (page_zone (page), +dec_zone_page_state (page, (s->flags &SLAB_RECLAIM_ACCOUNT ) ? -NR_SLAB_RECLAIMABLE :NR_SLAB_UNRECLAIMABLE , - - pages); +NR_SLAB_RECLAIMABLE :NR_SLAB_UNRECLAIMABLE ); page->mapping =NULL ;__free_pages (page, s->order);
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 5/6 compound pages: Allow use of get_page_unless_zero with compound pages
In reply to [email protected]This will be needed by targeted slab reclaim in order to ensure that a compound page allocated by SLUB will not go away under us.
It also may be needed if Mel starts to implement defragmentation. The moving of compound pages may require the establishment of a reference before the use of page migration functions.
--- include/linux/mm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/mm.h +1 -1
@@ -293,7 +293,7 @@ static inline int put_page_testzero(stru*/ static inline int get_page_unless_zero (struct page *page) { -VM_BUG_ON (PageCompound (page)); +VM_BUG_ON (PageTail (page));return atomic_inc_not_zero (&page->_count); }
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 6/6 compound pages: Allow freeing of compound pages via pagevec
In reply to [email protected]Allow the freeing of compound pages via pagevec.
In release_pages() we currently special case for compound pages in order to be sure to always decrement the page count of the head page and not the tail page. However that redirection to the head page is only necessary for tail pages. So use PageTail instead of PageCompound. No change therefore for the handling of tail pages.
The head page of a compound pages now represents single page large page. We do the usual processing including checking if its on the LRU and removing it (not useful right now but later when compound pages are on the LRU this will work). Then we add the compound page to the pagevec. Only head pages will end up on the pagevec not tail pages.
In __pagevec_free() we then check if we are freeing a head page and if so call the destructor for the compound page.
--- mm/page_alloc.c | 13 +++++++++++-- mm/swap.c | 8 +++++++- 2 files changed, 18 insertions(+), 3 deletions(-)
mm/page_alloc.c +11 -2
@@ -1760,8 +1760,17 @@ void __pagevec_free(struct pagevec *pvec {int i =pagevec_count (pvec); -while (--i >=0 ) -free_hot_cold_page (pvec->pages[i], pvec->cold); +while (--i >=0 ) { +struct page *page = pvec->pages[i]; + +if (PageHead (page)) { +compound_page_dtor *dtor; + + dtor =get_compound_page_dtor (page); + (*dtor)(page); + }else +free_hot_cold_page (page, pvec->cold); + } } fastcall void __free_pages(struct page *page, unsigned int order)
mm/swap.c +7 -1
@@ -307,7 +307,13 @@ void release_pages(struct page **pages,for (i =0 ; i < nr; i++) {struct page *page = pages[i]; -if (unlikely (PageCompound (page))) { +/* +* If we have a tail page on the LRU then we need to +* decrement the page count of the head page. There +* is no further need to do anything since tail pages +* cannot be on the LRU. +*/ +if (unlikely (PageTail (page))) {if (zone) {spin_unlock_irq (&zone->lru_lock); zone =NULL ;
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 22 lines · On Thu, 24 May 2007 22:17:16 -0700 [email protected] wrote:
This patch enhances the handling of compound pages in the VM. It may also be important also for the antifrag patches that need to manage a set of higher order free pages and also for other uses of compound pages.
For now it simplifies accounting for SLUB pages but the groundwork here is important for the large block size patches and for allowing to page migration of larger pages. With this framework we may be able to get to a point where compound pages keep their flags while they are free and Mel may avoid having special functions for determining the page order of higher order freed pages. If we can avoid the setup and teardown of higher order pages then allocation and release of compound pages will be faster.
Looking at the handling of compound pages we see that the fact that a page is part of a higher order page is not that interesting. The differentiation is mainly for head pages and tail pages of higher order pages. Head pages usually need special handling to accomodate the larger size. It is usually an error if tail pages are encountered. Or else they need to be treated like
PAGE_SIZEpages. So a compound flag in the page flags is not what we need. Instead we introduce a flag for the head page and another for the tail page. The PageCompound test is preserved for backward compatibility and will test if either PageTail or PageHead has been set.
Quoted 7 lines
After this patchset the uses of
CompoundPage()will be reduced significantly in the core VM. The I/O layer will still useCompoundPage()for direct I/O. However, if we at some point convert direct I/O to also support compound pages as a single unit thenCompoundPage()there may become unecessary as well as the leftover check inmm/swap.c. We may end up mostly with checks for PageTail and PageHead.
Well I've read that, and I've read the patches and I still don't see what the point in all this is.
And looking back on it, I don't see the point in that PG_head_tail_mask hack either. We could have done
static inline int page_tail(struct page *page)
{
return PageCompound(page) && (page->first_page != page);
}Confused. Don't know where this is all headed.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 2 lines · Andrew Morton
Well I've read that, and I've read the patches and I still don't see what the point in all this is.
A. vmstat can handle compound pages. No need to determine the size
of a compound page to update VM statistics.
B. PageCompound is not useful in the long run. The processing of compound
pages in the VM requires the knowledge if this is a head or tail page. That a page is part of a compound page is not that useful knowlege.
C. Provide some more support for higher order page handling issues that
Mel and I encounter.
D. Compound pages may be useful to handle higher order blocks on the
freelists if they can be handled efficiently. If we use the same format for the freelist as for compound pages elsewhere then we will have a common set of function to determine sizes etc etc.
E. Expands usefulness of get_page_unless_zero to compound pages. This
is necessary to allow the moving of slabs and the moving of higher order pages for memory defragmentation.
F. Lays groundwork for large blocksize support.
Quoted 9 lines
And looking back on it, I don't see the point in that
PG_head_tail_maskhack either. We could have donestatic inline int
page_tail(struct page *page){ return PageCompound(page) && (page->first_page != page); }Confused. Don't know where this is all headed.
To a better nicer looking VM.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines · Andrew Morton
And looking back on it, I don't see the point in that
PG_head_tail_maskhack either. We could have donestatic inline int
page_tail(struct page *page){ return PageCompound(page) && (page->first_page != page); }
But then PageHead(page) wont work anymore. pagehead->first_page is in use for some other purpose.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 5 lines · On Fri, 25 May 2007 07:03:22 -0700 (PDT) Christoph Lameter <[email protected]>…
Quoted 3 lines · Andrew Morton
And looking back on it, I don't see the point in that
PG_head_tail_maskhack either. We could have done
Quoted 7 lines
Quoted 4 lines
static inline int
page_tail(struct page *page){ return PageCompound(page) && (page->first_page != page); }But then PageHead(page) wont work anymore.
pagehead->first_pageis in use for some other purpose.
That's only because slub came along and screwed it all up. The compound page management used to be consistent, and simple.
Specifically: that lockless_freelist afterthought rendered us unable to fix this mess.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 5 lines · Andrew Morton
Quoted 2 lines
But then PageHead(page) wont work anymore.
pagehead->first_pageis in use for some other purpose.That's only because slub came along and screwed it all up. The compound page management used to be consistent, and simple.
Yeah I tried to keep it that way. Had to mess it up with the strange bit checks to get it in.
Quoted 2 lines
Specifically: that
lockless_freelistafterthought rendered us unable to fix this mess.
The main mess of page->private not being usable was fixed up. Now this can be even cleaner if we had PageTail and PageHead.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 4 lines · On Thu, 24 May 2007 22:17:16 -0700 [email protected] wrote:
This patch enhances the handling of compound pages in the VM. It may also be important also for the antifrag patches that need to manage a set of higher order free pages and also for other uses of compound pages.
Quoted 8 lines
For now it simplifies accounting for SLUB pages but the groundwork here is important for the large block size patches and for allowing to page migration of larger pages. With this framework we may be able to get to a point where compound pages keep their flags while they are free and Mel may avoid having special functions for determining the page order of higher order freed pages. If we can avoid the setup and teardown of higher order pages then allocation and release of compound pages will be faster.
Keeping "free high order page" as "free compound page" in free_area[]-> and avoid calling prep_compound_page() in page allocation ?
-Kame
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 2 lines · KAMEZAWA Hiroyuki
Keeping "free high order page" as "free compound page" in free_area[]-> and avoid calling
prep_compound_page()in page allocation ?
Right. That would be one benefit.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>