All of lore.kernel.org
 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 14/46] mm/memcg: Add folio_charge_cgroup()
Date: Tue, 22 Jun 2021 13:15:19 +0100	[thread overview]
Message-ID: <20210622121551.3398730-15-willy@infradead.org> (raw)
In-Reply-To: <20210622121551.3398730-1-willy@infradead.org>

mem_cgroup_charge() already assumed it was being passed a non-tail
page (and looking at the callers, that's true; it's called for freshly
allocated pages).  The only real change here is that folio_nr_pages()
doesn't compile away like thp_nr_pages() does as folio support
is not conditional on transparent hugepage support.  Reimplement
mem_cgroup_charge() as a wrapper around folio_charge_cgroup().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/memcontrol.h |  8 ++++++++
 mm/folio-compat.c          |  7 +++++++
 mm/memcontrol.c            | 26 +++++++++++++-------------
 3 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 4460ff0e70a1..a50e5cee6d2c 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -704,6 +704,8 @@ static inline bool mem_cgroup_below_min(struct mem_cgroup *memcg)
 		page_counter_read(&memcg->memory);
 }
 
+int folio_charge_cgroup(struct folio *, struct mm_struct *, gfp_t);
+
 int mem_cgroup_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask);
 int mem_cgroup_swapin_charge_page(struct page *page, struct mm_struct *mm,
 				  gfp_t gfp, swp_entry_t entry);
@@ -1216,6 +1218,12 @@ static inline bool mem_cgroup_below_min(struct mem_cgroup *memcg)
 	return false;
 }
 
+static inline int folio_charge_cgroup(struct folio *folio,
+		struct mm_struct *mm, gfp_t gfp)
+{
+	return 0;
+}
+
 static inline int mem_cgroup_charge(struct page *page, struct mm_struct *mm,
 				    gfp_t gfp_mask)
 {
diff --git a/mm/folio-compat.c b/mm/folio-compat.c
index a374747ae1c6..1d71b8b587f8 100644
--- a/mm/folio-compat.c
+++ b/mm/folio-compat.c
@@ -48,3 +48,10 @@ void mark_page_accessed(struct page *page)
 	folio_mark_accessed(page_folio(page));
 }
 EXPORT_SYMBOL(mark_page_accessed);
+
+#ifdef CONFIG_MEMCG
+int mem_cgroup_charge(struct page *page, struct mm_struct *mm, gfp_t gfp)
+{
+	return folio_charge_cgroup(page_folio(page), mm, gfp);
+}
+#endif
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 7939e4e9118d..69638f84d11b 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -6503,10 +6503,9 @@ void mem_cgroup_calculate_protection(struct mem_cgroup *root,
 			atomic_long_read(&parent->memory.children_low_usage)));
 }
 
-static int __mem_cgroup_charge(struct page *page, struct mem_cgroup *memcg,
+static int __mem_cgroup_charge(struct folio *folio, struct mem_cgroup *memcg,
 			       gfp_t gfp)
 {
-	struct folio *folio = page_folio(page);
 	unsigned int nr_pages = folio_nr_pages(folio);
 	int ret;
 
@@ -6519,26 +6518,26 @@ static int __mem_cgroup_charge(struct page *page, struct mem_cgroup *memcg,
 
 	local_irq_disable();
 	mem_cgroup_charge_statistics(memcg, nr_pages);
-	memcg_check_events(memcg, page);
+	memcg_check_events(memcg, &folio->page);
 	local_irq_enable();
 out:
 	return ret;
 }
 
 /**
- * mem_cgroup_charge - charge a newly allocated page to a cgroup
- * @page: page to charge
- * @mm: mm context of the victim
- * @gfp_mask: reclaim mode
+ * folio_charge_cgroup - Charge a newly allocated folio to a cgroup.
+ * @folio: Folio to charge.
+ * @mm: mm context of the allocating task.
+ * @gfp: reclaim mode
  *
- * Try to charge @page to the memcg that @mm belongs to, reclaiming
- * pages according to @gfp_mask if necessary.
+ * Try to charge @folio to the memcg that @mm belongs to, reclaiming
+ * pages according to @gfp if necessary.
  *
- * Do not use this for pages allocated for swapin.
+ * Do not use this for folios allocated for swapin.
  *
  * Returns 0 on success. Otherwise, an error code is returned.
  */
-int mem_cgroup_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask)
+int folio_charge_cgroup(struct folio *folio, struct mm_struct *mm, gfp_t gfp)
 {
 	struct mem_cgroup *memcg;
 	int ret;
@@ -6547,7 +6546,7 @@ int mem_cgroup_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask)
 		return 0;
 
 	memcg = get_mem_cgroup_from_mm(mm);
-	ret = __mem_cgroup_charge(page, memcg, gfp_mask);
+	ret = __mem_cgroup_charge(folio, memcg, gfp);
 	css_put(&memcg->css);
 
 	return ret;
@@ -6568,6 +6567,7 @@ int mem_cgroup_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask)
 int mem_cgroup_swapin_charge_page(struct page *page, struct mm_struct *mm,
 				  gfp_t gfp, swp_entry_t entry)
 {
+	struct folio *folio = page_folio(page);
 	struct mem_cgroup *memcg;
 	unsigned short id;
 	int ret;
@@ -6582,7 +6582,7 @@ int mem_cgroup_swapin_charge_page(struct page *page, struct mm_struct *mm,
 		memcg = get_mem_cgroup_from_mm(mm);
 	rcu_read_unlock();
 
-	ret = __mem_cgroup_charge(page, memcg, gfp);
+	ret = __mem_cgroup_charge(folio, memcg, gfp);
 
 	css_put(&memcg->css);
 	return ret;
-- 
2.30.2


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

Thread overview: 129+ 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-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 ` Matthew Wilcox (Oracle) [this message]
2021-06-23  8:15   ` [PATCH v2 14/46] mm/memcg: Add folio_charge_cgroup() 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 ` [PATCH v2 37/46] mm/workingset: Convert workingset_refault() to take a folio Matthew Wilcox (Oracle)
2021-06-23  9:52   ` 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-15-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.