Skip to content

Commit fe3cba1

Browse files
Fengguang WuLinus Torvalds
authored andcommitted
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: Fengguang Wu <wfg@mail.ustc.edu.cn> Cc: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d898391 commit fe3cba1

4 files changed

Lines changed: 10 additions & 8 deletions

File tree

‎include/linux/page-flags.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,16 @@
8383
#define PG_private 11 /* If pagecache, has fs-private data */
8484

8585
#define PG_writeback 12 /* Page is under writeback */
86-
#define PG_readahead 13 /* Reminder to do async read-ahead */
8786
#define PG_compound 14 /* Part of a compound page */
8887
#define PG_swapcache 15 /* Swap page: swp_entry_t in private */
8988

9089
#define PG_mappedtodisk 16 /* Has blocks allocated on-disk */
9190
#define PG_reclaim 17 /* To be reclaimed asap */
9291
#define PG_buddy 19 /* Page is free, on buddy lists */
9392

93+
/* PG_readahead is only used for file reads; PG_reclaim is only for writes */
94+
#define PG_readahead PG_reclaim /* Reminder to do async read-ahead */
95+
9496
/* PG_owner_priv_1 users should have descriptive aliases */
9597
#define PG_checked PG_owner_priv_1 /* Used by some filesystems */
9698
#define PG_pinned PG_owner_priv_1 /* Xen pinned pagetable */

‎mm/page-writeback.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,7 @@ int clear_page_dirty_for_io(struct page *page)
920920

921921
BUG_ON(!PageLocked(page));
922922

923+
ClearPageReclaim(page);
923924
if (mapping && mapping_cap_account_dirty(mapping)) {
924925
/*
925926
* Yes, Virginia, this is indeed insane.

‎mm/page_alloc.c‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,6 @@ static inline int free_pages_check(struct page *page)
453453
1 << PG_reserved |
454454
1 << PG_buddy ))))
455455
bad_page(page);
456-
/*
457-
* PageReclaim == PageTail. It is only an error
458-
* for PageReclaim to be set if PageCompound is clear.
459-
*/
460-
if (unlikely(!PageCompound(page) && PageReclaim(page)))
461-
bad_page(page);
462456
if (PageDirty(page))
463457
__ClearPageDirty(page);
464458
/*
@@ -602,7 +596,6 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
602596
1 << PG_locked |
603597
1 << PG_active |
604598
1 << PG_dirty |
605-
1 << PG_reclaim |
606599
1 << PG_slab |
607600
1 << PG_swapcache |
608601
1 << PG_writeback |

‎mm/readahead.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,12 @@ page_cache_readahead_ondemand(struct address_space *mapping,
448448
return 0;
449449

450450
if (page) {
451+
/*
452+
* It can be PG_reclaim.
453+
*/
454+
if (PageWriteback(page))
455+
return 0;
456+
451457
ClearPageReadahead(page);
452458

453459
/*

0 commit comments

Comments
 (0)