+ memcg-force-charge-kmem-counter-too.patch added to -mm tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch titled
     Subject: memcg: force charge kmem counter too
has been added to the -mm tree.  Its filename is
     memcg-force-charge-kmem-counter-too.patch

This patch should soon appear at
    http://ozlabs.org/~akpm/mmots/broken-out/memcg-force-charge-kmem-counter-too.patch
and later at
    http://ozlabs.org/~akpm/mmotm/broken-out/memcg-force-charge-kmem-counter-too.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: Shakeel Butt <shakeelb@xxxxxxxxxx>
Subject: memcg: force charge kmem counter too

Based on several conditions the kernel can decide to force charge an
allocation for a memcg i.e.  overcharge memcg->memory and memcg->memsw
counters.  Do the same for memcg->kmem counter too.  In cgroup-v1, this
bug can cause a __GFP_NOFAIL kmem allocation fail if an explicit limit on
kmem counter is set and reached.

Link: http://lkml.kernel.org/r/20180525185501.82098-1-shakeelb@xxxxxxxxxx
Signed-off-by: Shakeel Butt <shakeelb@xxxxxxxxxx>
Cc: Michal Hocko <mhocko@xxxxxxxxxx>
Cc: Greg Thelen <gthelen@xxxxxxxxxx>
Cc: Johannes Weiner <hannes@xxxxxxxxxxx>
Cc: Vladimir Davydov <vdavydov.dev@xxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

 mm/memcontrol.c |   21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff -puN mm/memcontrol.c~memcg-force-charge-kmem-counter-too mm/memcontrol.c
--- a/mm/memcontrol.c~memcg-force-charge-kmem-counter-too
+++ a/mm/memcontrol.c
@@ -1894,6 +1894,18 @@ void mem_cgroup_handle_over_high(void)
 	current->memcg_nr_pages_over_high = 0;
 }
 
+/*
+ * Based on try_charge() force charge conditions.
+ */
+static inline bool should_force_charge(gfp_t gfp_mask)
+{
+	return (unlikely(tsk_is_oom_victim(current) ||
+			 fatal_signal_pending(current) ||
+			 current->flags & PF_EXITING ||
+			 current->flags & PF_MEMALLOC ||
+			 gfp_mask & __GFP_NOFAIL));
+}
+
 static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask,
 		      unsigned int nr_pages)
 {
@@ -2009,6 +2021,8 @@ force:
 	 * The allocation either can't fail or will lead to more memory
 	 * being freed very soon.  Allow memory usage go over the limit
 	 * temporarily by force charging it.
+	 *
+	 * NOTE: Please keep the should_force_charge() conditions in sync.
 	 */
 	page_counter_charge(&memcg->memory, nr_pages);
 	if (do_memsw_account())
@@ -2332,8 +2346,11 @@ int memcg_kmem_charge_memcg(struct page
 
 	if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) &&
 	    !page_counter_try_charge(&memcg->kmem, nr_pages, &counter)) {
-		cancel_charge(memcg, nr_pages);
-		return -ENOMEM;
+		if (!should_force_charge(gfp)) {
+			cancel_charge(memcg, nr_pages);
+			return -ENOMEM;
+		}
+		page_counter_charge(&memcg->kmem, nr_pages);
 	}
 
 	page->mem_cgroup = memcg;
_

Patches currently in -mm which might be from shakeelb@xxxxxxxxxx are

mm-fix-race-between-kmem_cache-destroy-create-and-deactivate.patch
mm-fix-race-between-kmem_cache-destroy-create-and-deactivate-v2.patch
mm-memcg-remote-memcg-charging-for-kmem-allocations.patch
fs-fsnotify-account-fsnotify-metadata-to-kmemcg.patch
mm-memcontrol-drain-stocks-on-resize-limit.patch
mm-save-two-stranding-bit-in-gfp_mask.patch
memcg-force-charge-kmem-counter-too.patch

--
To unsubscribe from this list: send the line "unsubscribe mm-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux