Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3347658imm; Mon, 8 Oct 2018 02:24:07 -0700 (PDT) X-Google-Smtp-Source: ACcGV62t9bVm4GNGi0kpw1jjm+FQfWbiPXaVAN/K5ii3pVuHcW0AeUjZcWMdWg5guG3nRVOzKy/b X-Received: by 2002:a62:d286:: with SMTP id c128-v6mr24072002pfg.14.1538990647300; Mon, 08 Oct 2018 02:24:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538990647; cv=none; d=google.com; s=arc-20160816; b=FWfZiWsrTz0RBcgXRC6jLzD2k+SaHOLqUD/OGyq7KTFr14tVgnIb0Tlk3b9/GyY27M 3fFKgIeok1EprW+RK2DZjbUkYYdNhSDPPAu3ncWGvAzkmudukTmkrDkL1CdV8xC5DDTP uOwb05WOaraEOCenzqoHr/BPipPGsMTiGsIRbEaF7PT0QmjU5T/DPR8ul2Ihq9ssco1l b+UYlts8FVcLaQsFtM2IgjXAqkpqdavdrcuVjNgmLbO/q4P/v2FuYwDNbJq3fil3dGfY HSIqb4tNJV4r5hKBYLpfLXy+kaAlQ9kZgZhvRrFIrfhhX0lP9aBtSMztUEJkktEowp54 WAmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=c8ce6qwlR7ZgNdRvowCzs1yAJcRG7bHhm9H9XCXD5tg=; b=PGo7aEsi8dStvwBsZljoZPFGWC20UG4tZrvaXQyo8xscmtF53wzzhDvmXtVLtFlIT5 YhWZUk5gpeikz8a2H7RsHe+PgUj5dqZyDeqqSGbaizJaM0Ky85IbW5yH4Y1a/IrWvcL3 mCFFm4w7x3i9r8Nw0yTrQO7rsRD+x9vFHA1VExLjHs11euFQ8M/cbUjNBub1NW0bjPmc dVJfiERWbYC0Q+cOJusubJ5msVNF7EEsicLQ6qoi+YT+eBFoBOiOsYfddl4KEOlB5Cmi l71qmBfSwNf7WVr+yoMKUfDaY3SwxQNlAJnJfET667f0SA9Mjdp4J5Qx77kebJgloUTP VRVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=z+Z8PesT; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q25-v6si18562133pfj.116.2018.10.08.02.23.51; Mon, 08 Oct 2018 02:24:07 -0700 (PDT) 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=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=z+Z8PesT; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727278AbeJHQdA (ORCPT + 99 others); Mon, 8 Oct 2018 12:33:00 -0400 Received: from mail-yw1-f66.google.com ([209.85.161.66]:41983 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726193AbeJHQdA (ORCPT ); Mon, 8 Oct 2018 12:33:00 -0400 Received: by mail-yw1-f66.google.com with SMTP id 135-v6so964005ywo.8 for ; Mon, 08 Oct 2018 02:22:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=c8ce6qwlR7ZgNdRvowCzs1yAJcRG7bHhm9H9XCXD5tg=; b=z+Z8PesTOxMOdL6wGaeDSrlwXKMODDyOT4gN3Hks3NNyxdFYGadceBff3lYuoDV+kg MITVodt1uWylixgIIDwgIiCHA+7BEfYfSr2UY3W+8Jdy1zM9nkKmOi9838A22cVrqp0b WB6vNkvd4PqY+ijtJ/CCg52Gvp0r/tT1/wyNyMDIVr1uRgaTSgtBjO6I5piALetY6ow1 0ujXXQvh7vQTPfJ2d1fiq6Sn9Yp3c91S1FoUNABN5E6vnuveGf6Iy/7dEDhHc11GVMS/ RN8ytqnqgBKG9TBEuNNt7H123lCEEBW1MNk28/yYP4WXUHm7FY7Knts2sv0BOZ5RIo7v 4Zmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=c8ce6qwlR7ZgNdRvowCzs1yAJcRG7bHhm9H9XCXD5tg=; b=IK746CPq3UhmqDmZrarauPokm0DaETn8YXQFcd8h/O3PTG7HYae70PvgNW+Hd5EhHX jm+EetoI35Yk0+mfQY2lZaY7vCUToi9pVe8rVDq6RzgNadsxdOM2mpeIDRwjuhqgfB8K +zJIDEhEAiibUHOfDiVj7Km64ZRUAHqjJGC/FZYtBL7UqmDhbSbWd0mFqHyoEVZHOYi8 gVhktk+hZqA6RkvCMRNSRwI3vziYI8RdGPa11CUuxbELXt/A8/6rXvLfhpJtsiy7UAZG ijnnONj2iByCdPPk/Yno5cDnaf52tWZLm1U6qRhTziIq+3FUPsm+BqfjymZpNEvKX0rL aG0w== X-Gm-Message-State: ABuFfoiYKv8GWKBM5q5KXfbeBjaYc10S8R2S/+gyKnfD/nvWCSY+vbNP NS//wl0dFPlR6/C8EFK+k03HPg== X-Received: by 2002:a0d:ed82:: with SMTP id w124-v6mr10081729ywe.447.1538990534371; Mon, 08 Oct 2018 02:22:14 -0700 (PDT) Received: from localhost ([2620:10d:c091:180::1:7d10]) by smtp.gmail.com with ESMTPSA id 203-v6sm6269930ywv.34.2018.10.08.02.22.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Oct 2018 02:22:13 -0700 (PDT) Date: Mon, 8 Oct 2018 05:22:11 -0400 From: Johannes Weiner To: Roman Gushchin Cc: "linux-mm@kvack.org" , Andrew Morton , Michal Hocko , David Rientjes , "linux-kernel@vger.kernel.org" , Kernel Team , Vladimir Davydov Subject: Re: [PATCH v2] mm: don't raise MEMCG_OOM event due to failed high-order allocation Message-ID: <20181008092211.GA7515@cmpxchg.org> References: <20181004214050.7417-1-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181004214050.7417-1-guro@fb.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 04, 2018 at 09:41:09PM +0000, Roman Gushchin wrote: > I 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. > > Signed-off-by: Roman Gushchin > Acked-by: David Rientjes > Acked-by: Michal Hocko > Cc: Johannes Weiner > Cc: Vladimir Davydov Acked-by: Johannes Weiner