[Devel] [PATCH RHEL9 COMMIT] mm: Fix mem_cgroup_migrate's warn_on itself
Konstantin Khorenko
khorenko at virtuozzo.com
Tue Feb 21 16:35:59 MSK 2023
The commit is pushed to "branch-rh9-5.14.0-162.6.1.vz9.18.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-162.6.1.vz9.18.10
------>
commit 6c6835cdae7442cfbf7bfbac5ff157754eb18266
Author: Alexander Atanasov <alexander.atanasov at virtuozzo.com>
Date: Wed Feb 15 10:57:56 2023 +0200
mm: Fix mem_cgroup_migrate's warn_on itself
The original check in vz7 commit only expected to have Anon,Swap and
Cached pages. Which is not a valid assumption any more since folios have
more folio types.
To fix this update the condition to handle more folio types and change
its logic to be in form of:
flag && (any other flag)
rather than
flag != (!any other flag).
Do this to avoid warn_on if new flags are added.
Ressurect and rewrite a comment about what does the check do,
also put an explanation why the check is in mem_cgroup_migrate()
and not when updating the flags.
Fixes: b8bc3dbf5e18 ("mm: per memory cgroup page cache limit")
https://jira.sw.ru/browse/PSBM-144609
Signed-off-by: Alexander Atanasov <alexander.atanasov at virtuozzo.com>
---
mm/memcontrol.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 9f566fd438ef..8cd3a134c226 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -7687,8 +7687,25 @@ void mem_cgroup_migrate(struct folio *old, struct folio *new)
page_counter_charge(&memcg->memsw, nr_pages);
}
- WARN_ON((!PageAnon(&new->page) && !PageSwapBacked(&new->page)) !=
- folio_memcg_cache(new));
+ /*
+ * finist explained the idea behind adding a WARN_ON() here:
+ * - we do not want to check flags correctness on each flag change
+ * because of performance
+ * - we do want to have a warning in case we somehow messed-up and
+ * have got a folio with wrong bits set
+ * - we do not insist to catch every first buggy page with wrong
+ * bits
+ *
+ * But we still want to get a warning about the problem sooner or
+ * later if the problem with flags exists.
+ *
+ * To achieve this check if a folio that is marked as cache does
+ * not have any other incompatible flags set.
+ */
+ WARN_ON(folio_memcg_cache(new) &&
+ (folio_test_slab(new) || folio_test_anon(new) ||
+ folio_test_swapbacked(new) || folio_test_swapcache(new) ||
+ folio_test_mappedtodisk(new) || folio_test_ksm(new)));
if (folio_memcg_cache(new))
page_counter_charge(&memcg->cache, nr_pages);
More information about the Devel
mailing list