From patchwork Fri Feb 11 06:49:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 12742928 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85880C433F5 for ; Fri, 11 Feb 2022 06:50:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0EB7C6B007D; Fri, 11 Feb 2022 01:50:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 09BCF6B007E; Fri, 11 Feb 2022 01:50:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA6336B0080; Fri, 11 Feb 2022 01:49:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id DB2896B007D for ; Fri, 11 Feb 2022 01:49:59 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A1B2623B94 for ; Fri, 11 Feb 2022 06:49:59 +0000 (UTC) X-FDA: 79129574118.05.9837FC0 Received: from mail-ot1-f74.google.com (mail-ot1-f74.google.com [209.85.210.74]) by imf06.hostedemail.com (Postfix) with ESMTP id 2059E180004 for ; Fri, 11 Feb 2022 06:49:58 +0000 (UTC) Received: by mail-ot1-f74.google.com with SMTP id e21-20020a9d7315000000b005a6d56ac70bso4811171otk.21 for ; Thu, 10 Feb 2022 22:49:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=+8rN+YKf6ok+x08l31cPg9Z1f+kTrw1cXJDsx6RQzpQ=; b=BSR393aKc6QG8wWOZWMfrPQRJdGzUlEYw+Xm72Fj+l1HA0QTOlh+tjEKyBgFzMW5dh yMc5fn9Y/A3FfgNSdOvbIJTLWXMoYdbIp/vvqzQXMLbWsG9nJxhfo+fKE3NGJifj+L55 3LoH8v37N4wzh6cZ6ZelxTm1tTnyY0hKMYUvTMKIKyIycqhn6OLw7MJT5WtKpDt36DPf wCMwOA8QiMTaXEP2zn6vCRFegcEHws0MuunzFrr6o1UAxCnt9V9kQaR9FJs/brjoGool gPl1ffvPeA1Ff7JE3BrPzFA4t8pldf9Fk2M0Op9O4qxcn/XyTm8w2rz+eUBX0/iLhkxa f4vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=+8rN+YKf6ok+x08l31cPg9Z1f+kTrw1cXJDsx6RQzpQ=; b=ZQpQWDFN83fsVqj4wrjsoT52oc8uJrz2W482msUdc6XpkmhiiCxBEC/BNOujyYqxxh y0ziVo2Gb5C/qIuXjOwJIG4LxI9Oo/ubnV+NIUkuNoMnFp7zuA0/sqBm8wguE9P4p/qB IwcCKNm4YtJGsw+2SY1VoGInA5Bus8geYTQXaoPlL7bWWaBQLnEW1Upw9eUcKzSvf4gP kgD/FMqmgWIchaR4t2phmG5f8dyufCqiHOkeK55czR9wTPZ+ADLysFV2kKiSHpttMt3G K52payQg7fXFvpGnqLPmhYrg9sSYzTr9mQ+CnO63NwJTppSQXTGBaHUvVPWKQ0o/YBBE ns/w== X-Gm-Message-State: AOAM532l8/vAhrn0Yjh/ktENrS5TGJDymP3Ib3t0O0iYhC6smdA2IDdD jHZrN/oTqQ4hcK0+dOciRJOlC2xfV25FUQ== X-Google-Smtp-Source: ABdhPJx+FPelF0U4y0S0ru7GypuLQN66L/vIwUT5nqHv0csa/+RSKZQiVXDUKNso1ijCAHAvOmABsg8qgMR59A== X-Received: from shakeelb.svl.corp.google.com ([2620:15c:2cd:202:9a07:ef1a:2fee:57f1]) (user=shakeelb job=sendgmr) by 2002:a05:6870:8682:: with SMTP id p2mr257108oam.205.1644562198389; Thu, 10 Feb 2022 22:49:58 -0800 (PST) Date: Thu, 10 Feb 2022 22:49:17 -0800 In-Reply-To: <20220211064917.2028469-1-shakeelb@google.com> Message-Id: <20220211064917.2028469-5-shakeelb@google.com> Mime-Version: 1.0 References: <20220211064917.2028469-1-shakeelb@google.com> X-Mailer: git-send-email 2.35.1.265.g69c8d7142f-goog Subject: [PATCH v2 4/4] memcg: synchronously enforce memory.high for large overcharges From: Shakeel Butt To: Johannes Weiner , Michal Hocko , Roman Gushchin Cc: Chris Down , Andrew Morton , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Shakeel Butt Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=BSR393aK; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of 3FgcGYggKCFMD2v5zz6w19916z.x97638FI-775Gvx5.9C1@flex--shakeelb.bounces.google.com designates 209.85.210.74 as permitted sender) smtp.mailfrom=3FgcGYggKCFMD2v5zz6w19916z.x97638FI-775Gvx5.9C1@flex--shakeelb.bounces.google.com X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 2059E180004 X-Stat-Signature: btsgtj835siak6ecxoanjamhr3cwfccn X-HE-Tag: 1644562198-801475 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: The high limit is used to throttle the workload without invoking the oom-killer. Recently we tried to use the high limit to right size our internal workloads. More specifically dynamically adjusting the limits of the workload without letting the workload get oom-killed. However due to the limitation of the implementation of high limit enforcement, we observed the mechanism fails for some real workloads. The high limit is enforced on return-to-userspace i.e. the kernel let the usage goes over the limit and when the execution returns to userspace, the high reclaim is triggered and the process can get throttled as well. However this mechanism fails for workloads which do large allocations in a single kernel entry e.g. applications that mlock() a large chunk of memory in a single syscall. Such applications bypass the high limit and can trigger the oom-killer. To make high limit enforcement more robust, this patch makes the limit enforcement synchronous only if the accumulated overcharge becomes larger than MEMCG_CHARGE_BATCH. So, most of the allocations would still be throttled on the return-to-userspace path but only the extreme allocations which accumulates large amount of overcharge without returning to the userspace will be throttled synchronously. The value MEMCG_CHARGE_BATCH is a bit arbitrary but most of other places in the memcg codebase uses this constant therefore for now uses the same one. Signed-off-by: Shakeel Butt Reviewed-by: Roman Gushchin Acked-by: Chris Down --- Changes since v1: - Based on Roman's comment simply the sync enforcement and only target the extreme cases. mm/memcontrol.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 292b0b99a2c7..0da4be4798e7 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2703,6 +2703,11 @@ static int try_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp_mask, } } while ((memcg = parent_mem_cgroup(memcg))); + if (current->memcg_nr_pages_over_high > MEMCG_CHARGE_BATCH && + !(current->flags & PF_MEMALLOC) && + gfpflags_allow_blocking(gfp_mask)) { + mem_cgroup_handle_over_high(); + } return 0; }