From patchwork Fri Feb 12 17:01:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12085691 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AD9AC433DB for ; Fri, 12 Feb 2021 17:02:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 375D764E42 for ; Fri, 12 Feb 2021 17:02:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 375D764E42 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D57298D006F; Fri, 12 Feb 2021 12:02:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D08148D0060; Fri, 12 Feb 2021 12:02:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA8CC8D006F; Fri, 12 Feb 2021 12:02:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0158.hostedemail.com [216.40.44.158]) by kanga.kvack.org (Postfix) with ESMTP id A39408D0060 for ; Fri, 12 Feb 2021 12:02:25 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 6183C8248047 for ; Fri, 12 Feb 2021 17:02:25 +0000 (UTC) X-FDA: 77810234250.17.EF41B5A Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf11.hostedemail.com (Postfix) with ESMTP id 6B68320053DA for ; Fri, 12 Feb 2021 17:02:19 +0000 (UTC) Received: by mail-pl1-f176.google.com with SMTP id a16so163873plh.8 for ; Fri, 12 Feb 2021 09:02:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bcYt0NSihifXZf17H55Cj5Hl2GUjQyX5Z/whSKEEhxI=; b=QXdiNtz4icRE9wYOkzwNj/MEYjknOPfl+3qraA/tVpTL1yVUQ1uW/Egvq3zevZw11m 20DnFlwvQipf18yyHzSbhvGpWQ214vwvIYstobFglcVWyBKXAYFVQKqdebGoExkRRSK5 eiQft2Jyww09TKCwpm9fRe6tkSks1kczSXEdcv/laOSq5Cy74ohKIYxLVjPANARtpaLa liZ+acD0FILIz+lrXrA0/L9tZrDVhVAsNAGcQONgLpjgPGdqpzEP9NdCgVeVK6fjDxQo CXm7xNS6alE/sydQVkPcpDYcXQZrJZE64mOIICrRUaLwpDpPS5NX11mhQxdktolhNWPw vO4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bcYt0NSihifXZf17H55Cj5Hl2GUjQyX5Z/whSKEEhxI=; b=Cw4pF5XsWLGRf0axhiztjImZx6wDE7fKinu9Db/DLpdK0y+JvT+/pp5BtDcIw8blsJ bx9gMAhPJGdEPjZrDPkiiFwIPWLn4EFvete2KNch/43Uyvq0w9kWna9tvZjlTkJBH95L +mDDXKP8Y6CGm9uIGygpZCuoqgR9MS9DDQ0qbdZOYxS/kBV4Ha/yM64B2jCKCD2436Ar wtSXnhwvhRqVhG1aGrzXwKCsYoSSuugzXc70gK4k+WO7xwrJ/yyNfcKh4UXzILeW3isK IJwuyadELH79Zn3TWTtzwckDCm59LdxZRawuwl6MJwuEGxDk9tqFXKbDDVSc/eWxl2V6 DYPA== X-Gm-Message-State: AOAM5304zOcVDSrqRk2yOPjF4mRiD7LuBMjslPrN9fnHrmlC0bNl9w9w 9gJfeFYDijSdsk1/PIEyXQn9iQ== X-Google-Smtp-Source: ABdhPJy3fzcN97TILH5Pd2p9CjYCM+6s/EotNHOwcpsaLTt2cNdlvuafFJYbAs//bwycN8+3HlIfWA== X-Received: by 2002:a17:903:31c4:b029:e1:8840:8ab9 with SMTP id v4-20020a17090331c4b02900e188408ab9mr3441164ple.70.1613149340708; Fri, 12 Feb 2021 09:02:20 -0800 (PST) Received: from localhost.bytedance.net ([139.177.225.254]) by smtp.gmail.com with ESMTPSA id e21sm9317815pgv.74.2021.02.12.09.02.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Feb 2021 09:02:19 -0800 (PST) From: Muchun Song To: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH 2/4] mm: memcontrol: add missing memcg_oom_recover() when uncharge slab page Date: Sat, 13 Feb 2021 01:01:57 +0800 Message-Id: <20210212170159.32153-2-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210212170159.32153-1-songmuchun@bytedance.com> References: <20210212170159.32153-1-songmuchun@bytedance.com> MIME-Version: 1.0 X-Stat-Signature: d4mtcuz5o1f77pr7azbgytt5rjii49m5 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 6B68320053DA Received-SPF: none (bytedance.com>: No applicable sender policy available) receiver=imf11; identity=mailfrom; envelope-from=""; helo=mail-pl1-f176.google.com; client-ip=209.85.214.176 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1613149339-98059 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When we uncharge a page, we wake up oom victims when the memcg oom handling is outsourced to the userspace. The uncharge_batch do that for normal and kmem pages but not slab pages. It is likely an omission. So add the missing memcg_oom_recover() to __memcg_kmem_uncharge(). And the function of memory.oom_control is only suitable for cgroup v1. So guard this test (memcg->under_oom) by the cgroup_subsys_on_dfl(memory_cgrp_subsys). Signed-off-by: Muchun Song --- mm/memcontrol.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 7afca9677693..a3f26522765a 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3126,8 +3126,10 @@ static int __memcg_kmem_charge(struct mem_cgroup *memcg, gfp_t gfp, */ static void __memcg_kmem_uncharge(struct mem_cgroup *memcg, unsigned int nr_pages) { - if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) { page_counter_uncharge(&memcg->kmem, nr_pages); + memcg_oom_recover(memcg); + } refill_stock(memcg, nr_pages); } @@ -6806,11 +6808,15 @@ static void uncharge_batch(const struct uncharge_gather *ug) if (!mem_cgroup_is_root(ug->memcg)) { page_counter_uncharge(&ug->memcg->memory, ug->nr_pages); - if (do_memsw_account()) - page_counter_uncharge(&ug->memcg->memsw, ug->nr_pages); - if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && ug->nr_kmem) - page_counter_uncharge(&ug->memcg->kmem, ug->nr_kmem); - memcg_oom_recover(ug->memcg); + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) { + if (!cgroup_memory_noswap) + page_counter_uncharge(&ug->memcg->memsw, + ug->nr_pages); + if (ug->nr_kmem) + page_counter_uncharge(&ug->memcg->kmem, + ug->nr_kmem); + memcg_oom_recover(ug->memcg); + } } local_irq_save(flags);