From patchwork Tue Nov 13 05:49:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 10679575 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B05D513BB for ; Tue, 13 Nov 2018 05:50:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A08E62A267 for ; Tue, 13 Nov 2018 05:50:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E9D92A278; Tue, 13 Nov 2018 05:50:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8CF62A2C4 for ; Tue, 13 Nov 2018 05:50:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 619266B026C; Tue, 13 Nov 2018 00:50:48 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 57A2C6B026D; Tue, 13 Nov 2018 00:50:48 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 442FE6B026E; Tue, 13 Nov 2018 00:50:48 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id 01CAB6B026C for ; Tue, 13 Nov 2018 00:50:48 -0500 (EST) Received: by mail-pg1-f197.google.com with SMTP id h10so4954102pgv.20 for ; Mon, 12 Nov 2018 21:50:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=pVOyTXgERRQ5UTOrDAafcKpVSUaHeepA5Cs1hAhU/xI=; b=T7tAsuUj02UHmQpUzx5sJNwvvGwxPaa/8jUIVg2Jk1Obak/VBLIelGLh9vEB+tWxTm 1VAWepU1IV/SEqZWPyL5VJ555xI37lGEntY1M0zAicWlhJaJQoCg6m7SZuxJLJbA7dLt UEQqkFrpGuXUM6E4yqX8m8JECbgggySrE5MIRuIreAVr+CuTVxkwmGmOvtvfiG9desX/ LJeN2vJNiX1Rf/G5vfUCIb0fxz8OpyFDETe/Wl5bSY9vIBJ5II9WHmoci0ZegZNw4Qb/ sbSCsspgJo1X1JIsqOW4ovOAEvycmyRli77iVSIwerkpZOgWWTYKwzKeFEvPm8oAXxsj i7Vw== X-Gm-Message-State: AGRZ1gJnjhvCAc8H5Z9TnI4hqaxYIcgkEKvjW8VwNe/s5YjgjYud6AKZ SLMhTPvUABdXGtrv9AHjoiucMZglVcgxwdGwncSOOyYyftVLVE0O2sJtbE6jBpGsSs9KJsgzEQ9 SIrubaslWryr7Uh+9epMXgAubbHejMiEe5i84C7npf7sJtBILf2//MfZ1KQmvLZ+pGQ== X-Received: by 2002:a63:d441:: with SMTP id i1-v6mr3490321pgj.31.1542088247645; Mon, 12 Nov 2018 21:50:47 -0800 (PST) X-Google-Smtp-Source: AJdET5eCRSy42BQQpf5cty4JsKL7GwgDRVvTc5ImEKigYMnZndn7lFSgRuNpLuiLveyhayRt7fxH X-Received: by 2002:a63:d441:: with SMTP id i1-v6mr3490287pgj.31.1542088246352; Mon, 12 Nov 2018 21:50:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542088246; cv=none; d=google.com; s=arc-20160816; b=Y1GJxTGa3bO6G1Tu/gO7U4nH6x3j48ImJjKbDjBs2D+TzwL1m77ysLRptuPqFTymBT 0ZBz1p0NX5rG5+fUrYaFzBgo7ct14d3AwONmCkh9y8r2GupbSnTvkF7rRvlXOHsvJxzY /8wXqO4lcFeDi7x/YQHyu6ER2vGHX0xpeatmV4/O3phq41qNkUcSa06A7H4vBhHo9z1r Zq7majduqql3ZzBI/lNblbXhRxznu6GOvafOvJchlJt7tlrh0DsKtywrbq7zkUc5a5+3 yrepIssxG+OYrPzbRJpDH/CagAlxDMTh/zacnFTomhFwNIavlyhhtpgTo3jWQ7gEkKrb uXEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pVOyTXgERRQ5UTOrDAafcKpVSUaHeepA5Cs1hAhU/xI=; b=0PKesql6fl1iRuKKrqbXD9v5yXVu6tC+8NJVF3tyDTJydF/C84OVO73ryLrgjDV8wK p80RUrKvFmHnkOKBppH4qCgzM0vQeBGZ8peDGHwd4SiggQv9UBh9RmID1YIqhK0HmNb2 XyUsnKgP0395EtVDeZ93nrrUIc765e5WiJmhG2rWKPWcK2+ZeOA4A4D8o8o/FmE94tIR 3+VpDB8dSs9WFBP1uTGL5DsSrQemLEKmtC+CE5xWrGDagzKWyjllcWNS7Wb6LVkAR/RT HWrRznUYbcE+yGTBDIaSPZsLgpCfRg58DjegC0WePmiahYoVCJEmb/naVYIbaJ2csXP2 +K3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="oJ/BqPST"; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mail.kernel.org (mail.kernel.org. [198.145.29.99]) by mx.google.com with ESMTPS id p188-v6si22201860pfp.119.2018.11.12.21.50.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 21:50:46 -0800 (PST) Received-SPF: pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) client-ip=198.145.29.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="oJ/BqPST"; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sasha-vm.mshome.net (unknown [64.114.255.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E07DC22510; Tue, 13 Nov 2018 05:50:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542088246; bh=yJj7yxwCd9gAJEYNBBa6SsMFc1+V44MjmokWsyOmifw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oJ/BqPSTiVKImYZKS8eXSi0Hrkn0lKHFA+WpCLOYwSLgXFbUCiGsA5+AqWwBqZHlo 8U+BKfZXko9Enx/fLikn1jQ/7RfuJb+/VoXrULkjnL4L9xyZ6H5duG7s9847hhXfYJ BieMUCDK4wBDhyADD31Wl/2mRFfSFjksHyKnVWV4= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Roman Gushchin , Vladimir Davydov , Andrew Morton , Linus Torvalds , Sasha Levin , linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.19 40/44] mm: don't raise MEMCG_OOM event due to failed high-order allocation Date: Tue, 13 Nov 2018 00:49:46 -0500 Message-Id: <20181113054950.77898-40-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181113054950.77898-1-sashal@kernel.org> References: <20181113054950.77898-1-sashal@kernel.org> 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Roman Gushchin [ Upstream commit 7a1adfddaf0d11a39fdcaf6e82a88e9c0586e08b ] It was reported that on some of our machines containers were restarted with OOM symptoms without an obvious reason. Despite there were almost no memory pressure and plenty of page cache, MEMCG_OOM event was raised occasionally, causing the container management software to think, that OOM has happened. However, no tasks have been killed. The following investigation showed that the problem is caused by a failing attempt to charge a high-order page. In such case, the OOM killer is never invoked. As shown below, it can happen under conditions, which are very far from a real OOM: e.g. there is plenty of clean page cache and no memory pressure. There is no sense in raising an OOM event in this case, as it might confuse a user and lead to wrong and excessive actions (e.g. restart the workload, as in my case). Let's look at the charging path in try_charge(). If the memory usage is about memory.max, which is absolutely natural for most memory cgroups, we try to reclaim some pages. Even if we were able to reclaim enough memory for the allocation, the following check can fail due to a race with another concurrent allocation: if (mem_cgroup_margin(mem_over_limit) >= nr_pages) goto retry; For regular pages the following condition will save us from triggering the OOM: if (nr_reclaimed && nr_pages <= (1 << PAGE_ALLOC_COSTLY_ORDER)) goto retry; But for high-order allocation this condition will intentionally fail. The reason behind is that we'll likely fall to regular pages anyway, so it's ok and even preferred to return ENOMEM. In this case the idea of raising MEMCG_OOM looks dubious. Fix this by moving MEMCG_OOM raising to mem_cgroup_oom() after allocation order check, so that the event won't be raised for high order allocations. This change doesn't affect regular pages allocation and charging. Link: http://lkml.kernel.org/r/20181004214050.7417-1-guro@fb.com Signed-off-by: Roman Gushchin Acked-by: David Rientjes Acked-by: Michal Hocko Acked-by: Johannes Weiner Cc: Vladimir Davydov Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- Documentation/admin-guide/cgroup-v2.rst | 4 ++++ mm/memcontrol.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 184193bcb262..5d9939388a78 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1127,6 +1127,10 @@ PAGE_SIZE multiple when read back. disk readahead. For now OOM in memory cgroup kills tasks iff shortage has happened inside page fault. + This event is not raised if the OOM killer is not + considered as an option, e.g. for failed high-order + allocations. + oom_kill The number of processes belonging to this cgroup killed by any kind of OOM killer. diff --git a/mm/memcontrol.c b/mm/memcontrol.c index e79cb59552d9..07c7af6f5e59 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1669,6 +1669,8 @@ static enum oom_status mem_cgroup_oom(struct mem_cgroup *memcg, gfp_t mask, int if (order > PAGE_ALLOC_COSTLY_ORDER) return OOM_SKIPPED; + memcg_memory_event(memcg, MEMCG_OOM); + /* * We are in the middle of the charge context here, so we * don't want to block when potentially sitting on a callstack @@ -2250,8 +2252,6 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask, if (fatal_signal_pending(current)) goto force; - memcg_memory_event(mem_over_limit, MEMCG_OOM); - /* * keep retrying as long as the memcg oom killer is able to make * a forward progress or bypass the charge if the oom killer