From patchwork Thu Feb 10 08:14:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 12741536 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 12D0AC433F5 for ; Thu, 10 Feb 2022 08:15:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 78DE56B007D; Thu, 10 Feb 2022 03:15:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 717016B007E; Thu, 10 Feb 2022 03:15:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 590306B0080; Thu, 10 Feb 2022 03:15:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 472AA6B007D for ; Thu, 10 Feb 2022 03:15:16 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 19EE5204F9 for ; Thu, 10 Feb 2022 08:15:16 +0000 (UTC) X-FDA: 79126160232.05.BCD0283 Received: from mail-oo1-f73.google.com (mail-oo1-f73.google.com [209.85.161.73]) by imf04.hostedemail.com (Postfix) with ESMTP id AA5354000C for ; Thu, 10 Feb 2022 08:15:15 +0000 (UTC) Received: by mail-oo1-f73.google.com with SMTP id v10-20020a4ade8a000000b003177422e81dso3206602oou.3 for ; Thu, 10 Feb 2022 00:15:15 -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=fMIRROeDCCygpucOKIXnuDRE53blx2Fd4oRcgvywHRM=; b=FRPbX4D29kIW+qlbRohcly9kDDAZugoZr12c4pn83sXCQupHVz5i02c232pWifGcJX f2VKxeODp/d70mILcDiRehpZ84CcGH2l4Jn8IWMs4foCylEa2D1UArVeTuzjixJC4rGk b0lpopdNyBq7R31A1Xpm2gJf9dqmgq86WKoAW4JWyZkT0TVi9iUwsw/k72UOWMw0GRU/ QwbJNQCB1nO+jRIaSvwfKU42p7UXYBKyV9mgSFEGC+oPAVPT/hlWXU2lWmHOp6OqocJT xCfPQ42G1pJE/BGDOmZi69jA2Ce89s0XXfjxxywhmito7sKfPstoFHyxIl1vspcP3YBe 8Ucw== 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=fMIRROeDCCygpucOKIXnuDRE53blx2Fd4oRcgvywHRM=; b=5NM98k6SlosaiFCyRE9ukr7cZKzDU8IGW8NaeD8o1oKecOriKkh1/mDEKxg0qid8dQ DIL9JGRi0STi/99hRg6d+7CLdXpfE8z5LaG4ju+Kk3JNvafs/8xIp/eLDUtQE9wOSJC+ bbapYozEHe6H1KccN0tkiWT2pCAaJnaOPOATnSNU1v75FfhygaKJyGLsYAAf8z3gcleJ Id6xXJe9DjQRN/aIbFb6rkV2GMx7EMT3aCxR+EuPv8IUYa8vePsWyo4GwPY7DuX72+A6 YC6OkxK9hqGgaTiFzl0WvaEWox3bTsHCBLpEwdhnShrWzs0JxYwI0qywY7nK1X9Drb2+ N76g== X-Gm-Message-State: AOAM5308BBv5ynwkxM57+kQQ6oKV2lTF5729TfMrwv9e38/YGETHVZUf WIiGOdALMWvXQBiFbrGp7So3pWiUVVUD6g== X-Google-Smtp-Source: ABdhPJz+on117snT7bOCtSLvD9iOqUc+SsXLOOIUNv5jfVv7ihoMT5nMaQ/B9QQRCQ3v0WFDclrnAWBpAbrChg== X-Received: from shakeelb.svl.corp.google.com ([2620:15c:2cd:202:6801:6774:cb90:c600]) (user=shakeelb job=sendgmr) by 2002:a05:6870:9514:: with SMTP id u20mr427457oal.84.1644480914945; Thu, 10 Feb 2022 00:15:14 -0800 (PST) Date: Thu, 10 Feb 2022 00:14:35 -0800 In-Reply-To: <20220210081437.1884008-1-shakeelb@google.com> Message-Id: <20220210081437.1884008-3-shakeelb@google.com> Mime-Version: 1.0 References: <20220210081437.1884008-1-shakeelb@google.com> X-Mailer: git-send-email 2.35.1.265.g69c8d7142f-goog Subject: [PATCH 2/4] memcg: unify force charging conditions 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: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=FRPbX4D2; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3kskEYggKCE89yr1vv2sx55x2v.t532z4BE-331Crt1.58x@flex--shakeelb.bounces.google.com designates 209.85.161.73 as permitted sender) smtp.mailfrom=3kskEYggKCE89yr1vv2sx55x2v.t532z4BE-331Crt1.58x@flex--shakeelb.bounces.google.com X-Rspamd-Server: rspam03 X-Rspam-User: X-Stat-Signature: 8gbs4ub3rmrjqe9wi6tmzs17tqtchzzq X-Rspamd-Queue-Id: AA5354000C X-HE-Tag: 1644480915-949016 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: Currently the kernel force charges the allocations which have __GFP_HIGH flag without triggering the memory reclaim. __GFP_HIGH indicates that the caller is high priority and since commit 869712fd3de5 ("mm: memcontrol: fix network errors from failing __GFP_ATOMIC charges") the kernel let such allocations do force charging. Please note that __GFP_ATOMIC has been replaced by __GFP_HIGH. __GFP_HIGH does not tell if the caller can block or can trigger reclaim. There are separate checks to determine that. So, there is no need to skip reclaim for __GFP_HIGH allocations. So, handle __GFP_HIGH together with __GFP_NOFAIL which also does force charging. Please note that this is a noop change as there are no __GFP_HIGH allocators in kernel which also have __GFP_ACCOUNT (or SLAB_ACCOUNT) and does not allow reclaim for now. The reason for this patch is to simplify the reasoning of the following patches. Signed-off-by: Shakeel Butt Reviewed-by: Roman Gushchin to the patch. --- mm/memcontrol.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index c40c27822802..ae73a40818b0 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2560,15 +2560,6 @@ static int try_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp_mask, goto retry; } - /* - * Memcg doesn't have a dedicated reserve for atomic - * allocations. But like the global atomic pool, we need to - * put the burden of reclaim on regular allocation requests - * and let these go through as privileged allocations. - */ - if (gfp_mask & __GFP_HIGH) - goto force; - /* * Prevent unbounded recursion when reclaim operations need to * allocate memory. This might exceed the limits temporarily, @@ -2642,7 +2633,13 @@ static int try_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp_mask, goto retry; } nomem: - if (!(gfp_mask & __GFP_NOFAIL)) + /* + * Memcg doesn't have a dedicated reserve for atomic + * allocations. But like the global atomic pool, we need to + * put the burden of reclaim on regular allocation requests + * and let these go through as privileged allocations. + */ + if (!(gfp_mask & (__GFP_NOFAIL | __GFP_HIGH))) return -ENOMEM; force: /*