Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp1604802imd; Sun, 4 Nov 2018 06:10:31 -0800 (PST) X-Google-Smtp-Source: AJdET5eT14TlZ2o55znDxPCCxWJwnHozL1w8YZaMLokbOL39CIMz3BFstDgRKZ45dgm1SMw7iAWF X-Received: by 2002:a17:902:5a43:: with SMTP id f3-v6mr9813906plm.57.1541340631723; Sun, 04 Nov 2018 06:10:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541340631; cv=none; d=google.com; s=arc-20160816; b=y9LgmSmuORUYLVeXNkZGECDTxhvFeYdikMVHcdxqzIwAZH8kK4Wn4BZaAsbo5nvlcP F9eviVdWTLwA6HUZ9OzGskW7USHj/bYLw03lCyLwm2mFutN1o+Q/DdxUn9mzOFyNsXMW 1CuL2bNQuJnkiO8oUFMYyzktitv+2PYdOSynnQv3woUpjXqVCrZMSUSgXIGrN2DowiNm Ozy4l8qcR1nmpf83Lx4rHCrnIyhelLAx5D7vVk9nGM8vFRoiHLs7WxjIAl2OfX6l/zw5 WiY4zae1B1SUOz9zchtOUmcwu0AJZY3DP5CgJ6m6ucClPrAuwRcwCMwq8zrZFMB2Vw0w OznA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=pVOyTXgERRQ5UTOrDAafcKpVSUaHeepA5Cs1hAhU/xI=; b=o+YptU/GaInFEoziW74SBiQ7/sJBZWZgoLJyi1f2ghIOPb7nYDY2V0pSunMO57q9XS L2SBjD/DNgm5UVdG8WGL2zLvmdTw4lztDEIQc1KciUXMRgJpshr2eh5f0W7JCAjI/mQp nIuBa0hXPC0LEdHRTwFw3kVOpyuKUD1EgpN1WBiAZs9Bt8jsYPyUp4p09YKadGKOv9T/ Nq7ejTcL02Xjehitv6om9xqlEsrTSyCy5aahOmYhPktKfb/M5p1uVEmjSFzID5sEG3gL rMmTdIw4vLFuLujV6VfXGpWmGAvp87bVzevRwTokZZ9sVym8vUBYUTU9eaLySNNj5NLf 1fkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=djFy+vxq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b1-v6si26528409pgw.151.2018.11.04.06.10.16; Sun, 04 Nov 2018 06:10:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=djFy+vxq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729895AbeKDXG4 (ORCPT + 99 others); Sun, 4 Nov 2018 18:06:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:44078 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729867AbeKDXGz (ORCPT ); Sun, 4 Nov 2018 18:06:55 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (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 9204920854; Sun, 4 Nov 2018 13:51:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541339511; bh=yJj7yxwCd9gAJEYNBBa6SsMFc1+V44MjmokWsyOmifw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=djFy+vxqhrPBPKsk5h4K7NWCNADLe7Azrdu+sx8HcSyrwhDBwOgPwEftzJryTxbPD cGZbrHzJCGFN4CMGwDawP1WdnIWoXpdgFAHCTHYVUL/VXgjnrF2cKfPkTOI9I/652g O/nok4rYkHuJKPHDHdMlCmykZlatsxSZeIM8Nxfk= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Roman Gushchin , Vladimir Davydov , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH AUTOSEL 4.19 04/57] mm: don't raise MEMCG_OOM event due to failed high-order allocation Date: Sun, 4 Nov 2018 08:50:51 -0500 Message-Id: <20181104135144.88324-4-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181104135144.88324-1-sashal@kernel.org> References: <20181104135144.88324-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- 2.17.1