linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: akpm@linux-foundation.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
	linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2 37/46] mm/workingset: Convert workingset_refault() to take a folio
Date: Tue, 22 Jun 2021 13:15:42 +0100	[thread overview]
Message-ID: <20210622121551.3398730-38-willy@infradead.org> (raw)
In-Reply-To: <20210622121551.3398730-1-willy@infradead.org>

This nets us 178 bytes of savings from removing calls to compound_head.
The three callers all grow a little, but each of them will be converted
to use folios soon, so that's fine.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/swap.h |  4 ++--
 mm/filemap.c         |  2 +-
 mm/memory.c          |  3 ++-
 mm/swap.c            |  6 +++---
 mm/swap_state.c      |  2 +-
 mm/workingset.c      | 34 +++++++++++++++++-----------------
 6 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/include/linux/swap.h b/include/linux/swap.h
index d1cb67cdb476..35d3dba422a8 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -323,7 +323,7 @@ static inline swp_entry_t folio_swap_entry(struct folio *folio)
 /* linux/mm/workingset.c */
 void workingset_age_nonresident(struct lruvec *lruvec, unsigned long nr_pages);
 void *workingset_eviction(struct page *page, struct mem_cgroup *target_memcg);
-void workingset_refault(struct page *page, void *shadow);
+void workingset_refault(struct folio *folio, void *shadow);
 void workingset_activation(struct folio *folio);
 
 /* Only track the nodes of mappings with shadow entries */
@@ -344,7 +344,7 @@ extern unsigned long nr_free_buffer_pages(void);
 /* linux/mm/swap.c */
 extern void lru_note_cost(struct lruvec *lruvec, bool file,
 			  unsigned int nr_pages);
-extern void lru_note_cost_page(struct page *);
+extern void lru_note_cost_folio(struct folio *);
 extern void lru_cache_add(struct page *);
 void mark_page_accessed(struct page *);
 void folio_mark_accessed(struct folio *);
diff --git a/mm/filemap.c b/mm/filemap.c
index dd360721c72b..673094ce67da 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -981,7 +981,7 @@ int add_to_page_cache_lru(struct page *page, struct address_space *mapping,
 		 */
 		WARN_ON_ONCE(PageActive(page));
 		if (!(gfp_mask & __GFP_WRITE) && shadow)
-			workingset_refault(page, shadow);
+			workingset_refault(page_folio(page), shadow);
 		lru_cache_add(page);
 	}
 	return ret;
diff --git a/mm/memory.c b/mm/memory.c
index a8f0ddd9e84a..d37f0f898f65 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3364,7 +3364,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
 
 				shadow = get_shadow_from_swap_cache(entry);
 				if (shadow)
-					workingset_refault(page, shadow);
+					workingset_refault(page_folio(page),
+								shadow);
 
 				lru_cache_add(page);
 
diff --git a/mm/swap.c b/mm/swap.c
index 53422f6b7db1..2ed00cfd03ac 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -313,10 +313,10 @@ void lru_note_cost(struct lruvec *lruvec, bool file, unsigned int nr_pages)
 	} while ((lruvec = parent_lruvec(lruvec)));
 }
 
-void lru_note_cost_page(struct page *page)
+void lru_note_cost_folio(struct folio *folio)
 {
-	lru_note_cost(mem_cgroup_page_lruvec(page, page_pgdat(page)),
-		      page_is_file_lru(page), thp_nr_pages(page));
+	lru_note_cost(mem_cgroup_folio_lruvec(folio),
+		      folio_is_file_lru(folio), folio_nr_pages(folio));
 }
 
 static void __folio_activate(struct folio *folio, struct lruvec *lruvec)
diff --git a/mm/swap_state.c b/mm/swap_state.c
index 272ea2108c9d..1c8e8b3aa10b 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -503,7 +503,7 @@ struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
 	mem_cgroup_swapin_uncharge_swap(entry);
 
 	if (shadow)
-		workingset_refault(page, shadow);
+		workingset_refault(page_folio(page), shadow);
 
 	/* Caller will initiate read into locked page */
 	lru_cache_add(page);
diff --git a/mm/workingset.c b/mm/workingset.c
index 37cdcda96afd..2c8f211daafe 100644
--- a/mm/workingset.c
+++ b/mm/workingset.c
@@ -271,17 +271,17 @@ void *workingset_eviction(struct page *page, struct mem_cgroup *target_memcg)
 }
 
 /**
- * workingset_refault - evaluate the refault of a previously evicted page
- * @page: the freshly allocated replacement page
- * @shadow: shadow entry of the evicted page
+ * workingset_refault - evaluate the refault of a previously evicted folio
+ * @page: the freshly allocated replacement folio
+ * @shadow: shadow entry of the evicted folio
  *
  * Calculates and evaluates the refault distance of the previously
- * evicted page in the context of the node and the memcg whose memory
+ * evicted folio in the context of the node and the memcg whose memory
  * pressure caused the eviction.
  */
-void workingset_refault(struct page *page, void *shadow)
+void workingset_refault(struct folio *folio, void *shadow)
 {
-	bool file = page_is_file_lru(page);
+	bool file = folio_is_file_lru(folio);
 	struct mem_cgroup *eviction_memcg;
 	struct lruvec *eviction_lruvec;
 	unsigned long refault_distance;
@@ -299,10 +299,10 @@ void workingset_refault(struct page *page, void *shadow)
 	rcu_read_lock();
 	/*
 	 * Look up the memcg associated with the stored ID. It might
-	 * have been deleted since the page's eviction.
+	 * have been deleted since the folio's eviction.
 	 *
 	 * Note that in rare events the ID could have been recycled
-	 * for a new cgroup that refaults a shared page. This is
+	 * for a new cgroup that refaults a shared folio. This is
 	 * impossible to tell from the available data. However, this
 	 * should be a rare and limited disturbance, and activations
 	 * are always speculative anyway. Ultimately, it's the aging
@@ -338,14 +338,14 @@ void workingset_refault(struct page *page, void *shadow)
 	refault_distance = (refault - eviction) & EVICTION_MASK;
 
 	/*
-	 * The activation decision for this page is made at the level
+	 * The activation decision for this folio is made at the level
 	 * where the eviction occurred, as that is where the LRU order
-	 * during page reclaim is being determined.
+	 * during folio reclaim is being determined.
 	 *
-	 * However, the cgroup that will own the page is the one that
+	 * However, the cgroup that will own the folio is the one that
 	 * is actually experiencing the refault event.
 	 */
-	memcg = page_memcg(page);
+	memcg = folio_memcg(folio);
 	lruvec = mem_cgroup_lruvec(memcg, pgdat);
 
 	inc_lruvec_state(lruvec, WORKINGSET_REFAULT_BASE + file);
@@ -373,15 +373,15 @@ void workingset_refault(struct page *page, void *shadow)
 	if (refault_distance > workingset_size)
 		goto out;
 
-	SetPageActive(page);
-	workingset_age_nonresident(lruvec, thp_nr_pages(page));
+	folio_set_active_flag(folio);
+	workingset_age_nonresident(lruvec, folio_nr_pages(folio));
 	inc_lruvec_state(lruvec, WORKINGSET_ACTIVATE_BASE + file);
 
-	/* Page was active prior to eviction */
+	/* Folio was active prior to eviction */
 	if (workingset) {
-		SetPageWorkingset(page);
+		folio_set_workingset_flag(folio);
 		/* XXX: Move to lru_cache_add() when it supports new vs putback */
-		lru_note_cost_page(page);
+		lru_note_cost_folio(folio);
 		inc_lruvec_state(lruvec, WORKINGSET_RESTORE_BASE + file);
 	}
 out:
-- 
2.30.2



  parent reply	other threads:[~2021-06-22 12:51 UTC|newest]

Thread overview: 128+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-22 12:15 [PATCH v2 00/46] Folio-enabling the page cache Matthew Wilcox (Oracle)
2021-06-22 12:15 ` [PATCH v2 01/46] mm: Add folio_to_pfn() Matthew Wilcox (Oracle)
2021-06-23  7:49   ` Christoph Hellwig
2021-06-24 15:12     ` Matthew Wilcox
2021-06-28  6:18       ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 02/46] mm: Add folio_rmapping() Matthew Wilcox (Oracle)
2021-06-23  7:56   ` Christoph Hellwig
2021-06-24 15:51     ` Matthew Wilcox
2021-06-22 12:15 ` [PATCH v2 03/46] mm: Add kmap_local_folio() Matthew Wilcox (Oracle)
2021-06-23  7:58   ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 04/46] mm: Add flush_dcache_folio() Matthew Wilcox (Oracle)
2021-06-22 12:15 ` [PATCH v2 05/46] mm: Add arch_make_folio_accessible() Matthew Wilcox (Oracle)
2021-06-23  8:00   ` Christoph Hellwig
2021-06-24 15:57     ` Matthew Wilcox
2021-06-28  6:21       ` Christoph Hellwig
2021-06-28 14:07         ` Matthew Wilcox
2021-06-22 12:15 ` [PATCH v2 06/46] mm: Add folio_young() and folio_idle() Matthew Wilcox (Oracle)
2021-06-22 12:15 ` [PATCH v2 07/46] mm/workingset: Convert workingset_activation to take a folio Matthew Wilcox (Oracle)
2021-06-23  8:02   ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 08/46] mm/swap: Add folio_activate() Matthew Wilcox (Oracle)
2021-06-23  8:04   ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 09/46] mm/swap: Add folio_mark_accessed() Matthew Wilcox (Oracle)
2021-06-23  8:07   ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 10/46] mm/rmap: Add folio_mkclean() Matthew Wilcox (Oracle)
2021-06-23  8:08   ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 11/46] mm/memcg: Remove 'page' parameter to mem_cgroup_charge_statistics() Matthew Wilcox (Oracle)
2021-06-23  8:09   ` Christoph Hellwig
2021-06-25  7:58   ` Michal Hocko
2021-06-22 12:15 ` [PATCH v2 12/46] mm/memcg: Use the node id in mem_cgroup_update_tree() Matthew Wilcox (Oracle)
2021-06-23  8:12   ` Christoph Hellwig
2021-06-24 16:19     ` Matthew Wilcox
2021-06-25  8:05       ` Michal Hocko
2021-06-22 12:15 ` [PATCH v2 13/46] mm/memcg: Convert commit_charge() to take a folio Matthew Wilcox (Oracle)
2021-06-23  8:13   ` Christoph Hellwig
2021-06-25  8:11   ` Michal Hocko
2021-06-22 12:15 ` [PATCH v2 14/46] mm/memcg: Add folio_charge_cgroup() Matthew Wilcox (Oracle)
2021-06-23  8:15   ` Christoph Hellwig
2021-06-24 16:42     ` Matthew Wilcox
2021-06-25  8:22       ` Michal Hocko
2021-06-25 11:34         ` Matthew Wilcox
2021-06-22 12:15 ` [PATCH v2 15/46] mm/memcg: Add folio_uncharge_cgroup() Matthew Wilcox (Oracle)
2021-06-23  8:16   ` Christoph Hellwig
2021-06-25  8:25   ` Michal Hocko
2021-06-25 11:21     ` Matthew Wilcox
2021-06-25 13:21       ` Michal Hocko
2021-06-22 12:15 ` [PATCH v2 16/46] mm/memcg: Add folio_migrate_cgroup() Matthew Wilcox (Oracle)
2021-06-23  8:19   ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 17/46] mm/memcg: Convert mem_cgroup_track_foreign_dirty_slowpath() to folio Matthew Wilcox (Oracle)
2021-06-23  8:21   ` Christoph Hellwig
2021-06-24 17:37     ` Matthew Wilcox
2021-06-28  6:24       ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 18/46] mm/migrate: Add folio_migrate_mapping() Matthew Wilcox (Oracle)
2021-06-23  8:22   ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 19/46] mm/migrate: Add folio_migrate_flags() Matthew Wilcox (Oracle)
2021-06-23  8:28   ` Christoph Hellwig
2021-06-24 17:55     ` Matthew Wilcox
2021-06-22 12:15 ` [PATCH v2 20/46] mm/migrate: Add folio_migrate_copy() Matthew Wilcox (Oracle)
2021-06-23  8:35   ` Christoph Hellwig
2021-06-24 18:02     ` Matthew Wilcox
2021-06-28  6:26       ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 21/46] mm/writeback: Rename __add_wb_stat() to wb_stat_mod() Matthew Wilcox (Oracle)
2021-06-23  8:37   ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 22/46] flex_proportions: Allow N events instead of 1 Matthew Wilcox (Oracle)
2021-06-23  8:41   ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 23/46] mm/writeback: Change __wb_writeout_inc() to __wb_writeout_add() Matthew Wilcox (Oracle)
2021-06-23  8:45   ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 24/46] mm/writeback: Add __folio_end_writeback() Matthew Wilcox (Oracle)
2021-06-23  9:15   ` Christoph Hellwig
2021-06-24 18:20     ` Matthew Wilcox
2021-06-28  6:33       ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 25/46] mm/writeback: Add folio_start_writeback() Matthew Wilcox (Oracle)
2021-06-23  9:18   ` Christoph Hellwig
2021-06-24 18:33     ` Matthew Wilcox
2021-06-22 12:15 ` [PATCH v2 26/46] mm/writeback: Add folio_mark_dirty() Matthew Wilcox (Oracle)
2021-06-23  9:21   ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 27/46] mm/writeback: Add __folio_mark_dirty() Matthew Wilcox (Oracle)
2021-06-23  9:27   ` Christoph Hellwig
2021-06-24 18:37     ` Matthew Wilcox
2021-06-28  6:03       ` Christoph Hellwig
2021-06-28 15:43         ` Matthew Wilcox
2021-06-22 12:15 ` [PATCH v2 28/46] mm/writeback: Add filemap_dirty_folio() Matthew Wilcox (Oracle)
2021-06-23  9:32   ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 29/46] mm/writeback: Add folio_account_cleaned() Matthew Wilcox (Oracle)
2021-06-23  9:36   ` Christoph Hellwig
2021-06-24 20:06     ` Matthew Wilcox
2021-06-22 12:15 ` [PATCH v2 30/46] mm/writeback: Add folio_cancel_dirty() Matthew Wilcox (Oracle)
2021-06-23  9:39   ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 31/46] mm/writeback: Add folio_clear_dirty_for_io() Matthew Wilcox (Oracle)
2021-06-23  9:43   ` Christoph Hellwig
2021-06-24 20:09     ` Matthew Wilcox
2021-06-22 12:15 ` [PATCH v2 32/46] mm/writeback: Add folio_account_redirty() Matthew Wilcox (Oracle)
2021-06-23  9:44   ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 33/46] mm/writeback: Add folio_redirty_for_writepage() Matthew Wilcox (Oracle)
2021-06-23  9:45   ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 34/46] mm/filemap: Add i_blocks_per_folio() Matthew Wilcox (Oracle)
2021-06-23  9:46   ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 35/46] mm/filemap: Add folio_mkwrite_check_truncate() Matthew Wilcox (Oracle)
2021-06-23  9:47   ` Christoph Hellwig
2021-06-23 13:19     ` Matthew Wilcox
2021-06-22 12:15 ` [PATCH v2 36/46] mm/filemap: Add readahead_folio() Matthew Wilcox (Oracle)
2021-06-23  9:50   ` Christoph Hellwig
2021-06-24 23:46     ` Matthew Wilcox
2021-06-22 12:15 ` Matthew Wilcox (Oracle) [this message]
2021-06-23  9:52   ` [PATCH v2 37/46] mm/workingset: Convert workingset_refault() to take a folio Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 38/46] mm: Add folio_evictable() Matthew Wilcox (Oracle)
2021-06-23  9:54   ` Christoph Hellwig
2021-06-24 23:50     ` Matthew Wilcox
2021-06-22 12:15 ` [PATCH v2 39/46] mm/lru: Convert __pagevec_lru_add_fn to take a folio Matthew Wilcox (Oracle)
2021-06-23  9:55   ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 40/46] mm/lru: Add folio_add_lru() Matthew Wilcox (Oracle)
2021-06-23  9:56   ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 41/46] mm/page_alloc: Add folio allocation functions Matthew Wilcox (Oracle)
2021-06-23  9:58   ` Christoph Hellwig
2021-06-25  1:06     ` Matthew Wilcox
2021-06-22 12:15 ` [PATCH v2 42/46] mm/filemap: Add filemap_alloc_folio Matthew Wilcox (Oracle)
2021-06-23  9:59   ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 43/46] mm/filemap: Add filemap_add_folio Matthew Wilcox (Oracle)
2021-06-23 11:30   ` Christoph Hellwig
2021-06-25  1:57     ` Matthew Wilcox
2021-06-22 12:15 ` [PATCH v2 44/46] mm/filemap: Convert mapping_get_entry to return a folio Matthew Wilcox (Oracle)
2021-06-23 11:32   ` Christoph Hellwig
2021-06-25  3:29     ` Matthew Wilcox
2021-06-28  6:07       ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 45/46] mm/filemap: Add filemap_get_folio Matthew Wilcox (Oracle)
2021-06-23 11:39   ` Christoph Hellwig
2021-06-22 12:15 ` [PATCH v2 46/46] mm/filemap: Add FGP_STABLE Matthew Wilcox (Oracle)
2021-06-23 11:43   ` Christoph Hellwig
2021-06-23 12:15     ` Matthew Wilcox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210622121551.3398730-38-willy@infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).