Commit 9de4f22a authored by Huang Ying's avatar Huang Ying Committed by Linus Torvalds
Browse files

mm: code cleanup for MADV_FREE



Some comments for MADV_FREE is revised and added to help people understand
the MADV_FREE code, especially the page flag, PG_swapbacked.  This makes
page_is_file_cache() isn't consistent with its comments.  So the function
is renamed to page_is_file_lru() to make them consistent again.  All these
are put in one patch as one logical change.

Suggested-by: default avatarDavid Hildenbrand <david@redhat.com>
Suggested-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
Suggested-by: default avatarDavid Rientjes <rientjes@google.com>
Signed-off-by: default avatar"Huang, Ying" <ying.huang@intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Acked-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
Acked-by: default avatarDavid Rientjes <rientjes@google.com>
Acked-by: default avatarMichal Hocko <mhocko@kernel.org>
Acked-by: default avatarPankaj Gupta <pankaj.gupta.linux@gmail.com>
Acked-by: default avatarVlastimil Babka <vbabka@suse.cz>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Hugh Dickins <hughd@google.com>
Cc: Rik van Riel <riel@surriel.com>
Link: http://lkml.kernel.org/r/20200317100342.2730705-1-ying.huang@intel.com


Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 7a9547fd
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -6,19 +6,20 @@
#include <linux/swap.h>

/**
 * page_is_file_cache - should the page be on a file LRU or anon LRU?
 * page_is_file_lru - should the page be on a file LRU or anon LRU?
 * @page: the page to test
 *
 * Returns 1 if @page is page cache page backed by a regular filesystem,
 * or 0 if @page is anonymous, tmpfs or otherwise ram or swap backed.
 * Used by functions that manipulate the LRU lists, to sort a page
 * onto the right LRU list.
 * Returns 1 if @page is a regular filesystem backed page cache page or a lazily
 * freed anonymous page (e.g. via MADV_FREE).  Returns 0 if @page is a normal
 * anonymous page, a tmpfs page or otherwise ram or swap backed page.  Used by
 * functions that manipulate the LRU lists, to sort a page onto the right LRU
 * list.
 *
 * We would like to get this info without a page flag, but the state
 * needs to survive until the page is last deleted from the LRU, which
 * could be as far down as __page_cache_release.
 */
static inline int page_is_file_cache(struct page *page)
static inline int page_is_file_lru(struct page *page)
{
	return !PageSwapBacked(page);
}
@@ -75,7 +76,7 @@ static __always_inline void del_page_from_lru_list(struct page *page,
 */
static inline enum lru_list page_lru_base_type(struct page *page)
{
	if (page_is_file_cache(page))
	if (page_is_file_lru(page))
		return LRU_INACTIVE_FILE;
	return LRU_INACTIVE_ANON;
}
+5 −0
Original line number Diff line number Diff line
@@ -63,6 +63,11 @@
 * page_waitqueue(page) is a wait queue of all tasks waiting for the page
 * to become unlocked.
 *
 * PG_swapbacked is set when a page uses swap as a backing storage.  This are
 * usually PageAnon or shmem pages but please note that even anonymous pages
 * might lose their PG_swapbacked flag when they simply can be dropped (e.g. as
 * a result of MADV_FREE).
 *
 * PG_uptodate tells whether the page's contents is valid.  When a read
 * completes, the page becomes uptodate, unless a disk I/O error happened.
 *
+1 −1
Original line number Diff line number Diff line
@@ -323,7 +323,7 @@ TRACE_EVENT(mm_vmscan_writepage,
	TP_fast_assign(
		__entry->pfn = page_to_pfn(page);
		__entry->reclaim_flags = trace_reclaim_flags(
						page_is_file_cache(page));
						page_is_file_lru(page));
	),

	TP_printk("page=%p pfn=%lu flags=%s",
+1 −1
Original line number Diff line number Diff line
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
		/* Successfully isolated */
		del_page_from_lru_list(page, lruvec, page_lru(page));
		mod_node_page_state(page_pgdat(page),
				NR_ISOLATED_ANON + page_is_file_cache(page),
				NR_ISOLATED_ANON + page_is_file_lru(page),
				hpage_nr_pages(page));

isolate_success:
+1 −1
Original line number Diff line number Diff line
@@ -1677,7 +1677,7 @@ check_again:
					list_add_tail(&head->lru, &cma_page_list);
					mod_node_page_state(page_pgdat(head),
							    NR_ISOLATED_ANON +
							    page_is_file_cache(head),
							    page_is_file_lru(head),
							    hpage_nr_pages(head));
				}
			}
Loading