Commit fe3cba17 authored by Fengguang Wu's avatar Fengguang Wu Committed by Linus Torvalds

mm: share PG_readahead and PG_reclaim

Share the same page flag bit for PG_readahead and PG_reclaim.

One is used only on file reads, another is only for emergency writes.  One
is used mostly for fresh/young pages, another is for old pages.

Combinations of possible interactions are:

a) clear PG_reclaim => implicit clear of PG_readahead
	it will delay an asynchronous readahead into a synchronous one
	it actually does _good_ for readahead:
		the pages will be reclaimed soon, it's readahead thrashing!
		in this case, synchronous readahead makes more sense.

b) clear PG_readahead => implicit clear of PG_reclaim
	one(and only one) page will not be reclaimed in time
	it can be avoided by checking PageWriteback(page) in readahead first

c) set PG_reclaim => implicit set of PG_readahead
	will confuse readahead and make it restart the size rampup process
	it's a trivial problem, and can mostly be avoided by checking
	PageWriteback(page) first in readahead

d) set PG_readahead => implicit set of PG_reclaim
	PG_readahead will never be set on already cached pages.
	PG_reclaim will always be cleared on dirtying a page.
	so not a problem.

In summary,
	a)   we get better behavior
	b,d) possible interactions can be avoided
	c)   racy condition exists that might affect readahead, but the chance
	     is _really_ low, and the hurt on readahead is trivial.

Compound pages also use PG_reclaim, but for now they do not interact with
reclaim/readahead code.
Signed-off-by: default avatarFengguang Wu <wfg@mail.ustc.edu.cn>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d8983910
...@@ -83,7 +83,6 @@ ...@@ -83,7 +83,6 @@
#define PG_private 11 /* If pagecache, has fs-private data */ #define PG_private 11 /* If pagecache, has fs-private data */
#define PG_writeback 12 /* Page is under writeback */ #define PG_writeback 12 /* Page is under writeback */
#define PG_readahead 13 /* Reminder to do async read-ahead */
#define PG_compound 14 /* Part of a compound page */ #define PG_compound 14 /* Part of a compound page */
#define PG_swapcache 15 /* Swap page: swp_entry_t in private */ #define PG_swapcache 15 /* Swap page: swp_entry_t in private */
...@@ -91,6 +90,9 @@ ...@@ -91,6 +90,9 @@
#define PG_reclaim 17 /* To be reclaimed asap */ #define PG_reclaim 17 /* To be reclaimed asap */
#define PG_buddy 19 /* Page is free, on buddy lists */ #define PG_buddy 19 /* Page is free, on buddy lists */
/* 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 */
/* PG_owner_priv_1 users should have descriptive aliases */ /* PG_owner_priv_1 users should have descriptive aliases */
#define PG_checked PG_owner_priv_1 /* Used by some filesystems */ #define PG_checked PG_owner_priv_1 /* Used by some filesystems */
#define PG_pinned PG_owner_priv_1 /* Xen pinned pagetable */ #define PG_pinned PG_owner_priv_1 /* Xen pinned pagetable */
......
...@@ -920,6 +920,7 @@ int clear_page_dirty_for_io(struct page *page) ...@@ -920,6 +920,7 @@ int clear_page_dirty_for_io(struct page *page)
BUG_ON(!PageLocked(page)); BUG_ON(!PageLocked(page));
ClearPageReclaim(page);
if (mapping && mapping_cap_account_dirty(mapping)) { if (mapping && mapping_cap_account_dirty(mapping)) {
/* /*
* Yes, Virginia, this is indeed insane. * Yes, Virginia, this is indeed insane.
......
...@@ -453,12 +453,6 @@ static inline int free_pages_check(struct page *page) ...@@ -453,12 +453,6 @@ static inline int free_pages_check(struct page *page)
1 << PG_reserved | 1 << PG_reserved |
1 << PG_buddy )))) 1 << PG_buddy ))))
bad_page(page); bad_page(page);
/*
* PageReclaim == PageTail. It is only an error
* for PageReclaim to be set if PageCompound is clear.
*/
if (unlikely(!PageCompound(page) && PageReclaim(page)))
bad_page(page);
if (PageDirty(page)) if (PageDirty(page))
__ClearPageDirty(page); __ClearPageDirty(page);
/* /*
...@@ -602,7 +596,6 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags) ...@@ -602,7 +596,6 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
1 << PG_locked | 1 << PG_locked |
1 << PG_active | 1 << PG_active |
1 << PG_dirty | 1 << PG_dirty |
1 << PG_reclaim |
1 << PG_slab | 1 << PG_slab |
1 << PG_swapcache | 1 << PG_swapcache |
1 << PG_writeback | 1 << PG_writeback |
......
...@@ -448,6 +448,12 @@ page_cache_readahead_ondemand(struct address_space *mapping, ...@@ -448,6 +448,12 @@ page_cache_readahead_ondemand(struct address_space *mapping,
return 0; return 0;
if (page) { if (page) {
/*
* It can be PG_reclaim.
*/
if (PageWriteback(page))
return 0;
ClearPageReadahead(page); ClearPageReadahead(page);
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment