Skip to content

Commit b2e1853

Browse files
Rik van Rieltorvalds
authored andcommitted
define page_file_cache() function
Define page_file_cache() function to answer the question: is page backed by a file? Originally part of Rik van Riel's split-lru patch. Extracted to make available for other, independent reclaim patches. Moved inline function to linux/mm_inline.h where it will be needed by subsequent "split LRU" and "noreclaim" patches. Unfortunately this needs to use a page flag, since the PG_swapbacked state needs to be preserved all the way to the point where the page is last removed from the LRU. Trying to derive the status from other info in the page resulted in wrong VM statistics in earlier split VM patchsets. The total number of page flags in use on a 32 bit machine after this patch is 19. [akpm@linux-foundation.org: fix up out-of-order merge fallout] [hugh@veritas.com: splitlru: shmem_getpage SetPageSwapBacked sooner[ Signed-off-by: Rik van Riel <riel@redhat.com> Signed-off-by: Lee Schermerhorn <lee.schermerhorn@hp.com> Signed-off-by: MinChan Kim <minchan.kim@gmail.com> Signed-off-by: Hugh Dickins <hugh@veritas.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 68a2239 commit b2e1853

7 files changed

Lines changed: 44 additions & 2 deletions

File tree

‎include/linux/mm_inline.h‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
#ifndef LINUX_MM_INLINE_H
2+
#define LINUX_MM_INLINE_H
3+
4+
/**
5+
* page_is_file_cache - should the page be on a file LRU or anon LRU?
6+
* @page: the page to test
7+
*
8+
* Returns !0 if @page is page cache page backed by a regular filesystem,
9+
* or 0 if @page is anonymous, tmpfs or otherwise ram or swap backed.
10+
* Used by functions that manipulate the LRU lists, to sort a page
11+
* onto the right LRU list.
12+
*
13+
* We would like to get this info without a page flag, but the state
14+
* needs to survive until the page is last deleted from the LRU, which
15+
* could be as far down as __page_cache_release.
16+
*/
17+
static inline int page_is_file_cache(struct page *page)
18+
{
19+
if (PageSwapBacked(page))
20+
return 0;
21+
22+
/* The page is page cache backed by a normal filesystem. */
23+
return 1;
24+
}
25+
126
static inline void
227
add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list l)
328
{
@@ -65,3 +90,5 @@ static inline enum lru_list page_lru(struct page *page)
6590

6691
return lru;
6792
}
93+
94+
#endif

‎include/linux/page-flags.h‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ enum pageflags {
9393
PG_mappedtodisk, /* Has blocks allocated on-disk */
9494
PG_reclaim, /* To be reclaimed asap */
9595
PG_buddy, /* Page is free, on buddy lists */
96+
PG_swapbacked, /* Page is backed by RAM/swap */
9697
#ifdef CONFIG_IA64_UNCACHED_ALLOCATOR
9798
PG_uncached, /* Page has been mapped as uncached */
9899
#endif
@@ -176,6 +177,7 @@ PAGEFLAG(SavePinned, savepinned); /* Xen */
176177
PAGEFLAG(Reserved, reserved) __CLEARPAGEFLAG(Reserved, reserved)
177178
PAGEFLAG(Private, private) __CLEARPAGEFLAG(Private, private)
178179
__SETPAGEFLAG(Private, private)
180+
PAGEFLAG(SwapBacked, swapbacked) __CLEARPAGEFLAG(SwapBacked, swapbacked)
179181

180182
__PAGEFLAG(SlobPage, slob_page)
181183
__PAGEFLAG(SlobFree, slob_free)
@@ -334,7 +336,8 @@ static inline void __ClearPageTail(struct page *page)
334336
* Flags checked in bad_page(). Pages on the free list should not have
335337
* these flags set. It they are, there is a problem.
336338
*/
337-
#define PAGE_FLAGS_CLEAR_WHEN_BAD (PAGE_FLAGS | 1 << PG_reclaim | 1 << PG_dirty)
339+
#define PAGE_FLAGS_CLEAR_WHEN_BAD (PAGE_FLAGS | \
340+
1 << PG_reclaim | 1 << PG_dirty | 1 << PG_swapbacked)
338341

339342
/*
340343
* Flags checked when a page is freed. Pages being freed should not have
@@ -347,7 +350,8 @@ static inline void __ClearPageTail(struct page *page)
347350
* Pages being prepped should not have these flags set. It they are, there
348351
* is a problem.
349352
*/
350-
#define PAGE_FLAGS_CHECK_AT_PREP (PAGE_FLAGS | 1 << PG_reserved | 1 << PG_dirty)
353+
#define PAGE_FLAGS_CHECK_AT_PREP (PAGE_FLAGS | \
354+
1 << PG_reserved | 1 << PG_dirty | 1 << PG_swapbacked)
351355

352356
#endif /* !__GENERATING_BOUNDS_H */
353357
#endif /* PAGE_FLAGS_H */

‎mm/memory.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,6 +1888,7 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma,
18881888
ptep_clear_flush_notify(vma, address, page_table);
18891889
set_pte_at(mm, address, page_table, entry);
18901890
update_mmu_cache(vma, address, entry);
1891+
SetPageSwapBacked(new_page);
18911892
lru_cache_add_active(new_page);
18921893
page_add_new_anon_rmap(new_page, vma, address);
18931894

@@ -2382,6 +2383,7 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
23822383
if (!pte_none(*page_table))
23832384
goto release;
23842385
inc_mm_counter(mm, anon_rss);
2386+
SetPageSwapBacked(page);
23852387
lru_cache_add_active(page);
23862388
page_add_new_anon_rmap(page, vma, address);
23872389
set_pte_at(mm, address, page_table, entry);
@@ -2523,6 +2525,7 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
25232525
set_pte_at(mm, address, page_table, entry);
25242526
if (anon) {
25252527
inc_mm_counter(mm, anon_rss);
2528+
SetPageSwapBacked(page);
25262529
lru_cache_add_active(page);
25272530
page_add_new_anon_rmap(page, vma, address);
25282531
} else {

‎mm/migrate.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,8 @@ static int move_to_new_page(struct page *newpage, struct page *page)
572572
/* Prepare mapping for the new page.*/
573573
newpage->index = page->index;
574574
newpage->mapping = page->mapping;
575+
if (PageSwapBacked(page))
576+
SetPageSwapBacked(newpage);
575577

576578
mapping = page_mapping(page);
577579
if (!mapping)

‎mm/page_alloc.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,8 @@ static inline int free_pages_check(struct page *page)
462462
bad_page(page);
463463
if (PageDirty(page))
464464
__ClearPageDirty(page);
465+
if (PageSwapBacked(page))
466+
__ClearPageSwapBacked(page);
465467
/*
466468
* For now, we report if PG_reserved was found set, but do not
467469
* clear it, and do not free the page. But we shall soon need

‎mm/shmem.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,7 @@ static int shmem_getpage(struct inode *inode, unsigned long idx,
13671367
error = -ENOMEM;
13681368
goto failed;
13691369
}
1370+
SetPageSwapBacked(filepage);
13701371

13711372
/* Precharge page while we can wait, compensate after */
13721373
error = mem_cgroup_cache_charge(filepage, current->mm,

‎mm/swap_state.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ int add_to_swap_cache(struct page *page, swp_entry_t entry, gfp_t gfp_mask)
7575
BUG_ON(!PageLocked(page));
7676
BUG_ON(PageSwapCache(page));
7777
BUG_ON(PagePrivate(page));
78+
BUG_ON(!PageSwapBacked(page));
7879
error = radix_tree_preload(gfp_mask);
7980
if (!error) {
8081
page_cache_get(page);
@@ -303,6 +304,7 @@ struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
303304
* May fail (-ENOMEM) if radix-tree node allocation failed.
304305
*/
305306
set_page_locked(new_page);
307+
SetPageSwapBacked(new_page);
306308
err = add_to_swap_cache(new_page, entry, gfp_mask & GFP_KERNEL);
307309
if (likely(!err)) {
308310
/*
@@ -312,6 +314,7 @@ struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
312314
swap_readpage(NULL, new_page);
313315
return new_page;
314316
}
317+
ClearPageSwapBacked(new_page);
315318
clear_page_locked(new_page);
316319
swap_free(entry);
317320
} while (err != -ENOMEM);

0 commit comments

Comments
 (0)