From patchwork Thu Oct 4 21:41:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 10626903 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 E98E51731 for ; Thu, 4 Oct 2018 21:41:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7AB129600 for ; Thu, 4 Oct 2018 21:41:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAC2D29644; Thu, 4 Oct 2018 21:41:24 +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 B925A29600 for ; Thu, 4 Oct 2018 21:41:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 607EE6B0006; Thu, 4 Oct 2018 17:41:22 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5DD936B0007; Thu, 4 Oct 2018 17:41:22 -0400 (EDT) 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 4A6656B026B; Thu, 4 Oct 2018 17:41:22 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f72.google.com (mail-yw1-f72.google.com [209.85.161.72]) by kanga.kvack.org (Postfix) with ESMTP id 1DA3C6B0006 for ; Thu, 4 Oct 2018 17:41:22 -0400 (EDT) Received: by mail-yw1-f72.google.com with SMTP id 131-v6so5786968ywe.1 for ; Thu, 04 Oct 2018 14:41:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:dkim-signature:from:to:cc:subject :thread-topic:thread-index:date:message-id:accept-language :content-language:spamdiagnosticoutput:spamdiagnosticmetadata :content-transfer-encoding:mime-version; bh=NRPERSulB+CgiyoKzWIV43HlBDw3Wje3bt9jlCGX1Bo=; b=tf9M5/IUGGLrmOFDYnr5fu7KGUHs6q9nAT6y3STXkF8JqfpEgEsSjxwNoXj6BB/uWq +zP6QNIIvtRbZONRZtVM+V3YCJZE+NliEHIKQRII2UQZ6UzOicEc/0+yruueAQzthoVu wYiYsg3ZQR8UqUxDHmb67Fx+OA5Rp6TDg2AQHgRrZtTPFraTGw+8z+Vg5oKdxrztaHdH SLXA1MNZSDdnlsj2lzWsyyj+MBFUf29zc2AL63e8s3BqYW7lkZtKEWG1Em6iwHBGRsCV YcM14J3sdlm2fQu9GVGz0Nm9AOYYROrjUvQwvRtsRmhkSir7tB6ZsWzq5O1zeidVZ+ic +owQ== X-Gm-Message-State: ABuFfoiOGLg7VJ1Ccf4k3cM3TDX8dvYHUq1ttu+Izcg8/MINzJ8LHzLM C95IOUhPeu4c+C06p2oCGTzSe0bsmGXG+gLF/Qhcf/vY7xSBxqNv+DKT/VniVTETytFgGcWYMTt vNTbNzTcrvfn+KqsgS5XzwxyWhF32jPJhT/Zm86POCCqF28M3MoOyn6SLCHBFoh6aJg== X-Received: by 2002:a81:1cd0:: with SMTP id c199-v6mr4697949ywc.193.1538689281813; Thu, 04 Oct 2018 14:41:21 -0700 (PDT) X-Google-Smtp-Source: ACcGV62sw4JD+4BAIz7EItsiH/zw3t2Kes/eF4sSx6urbGo6IrdFbd3SHzmwadqr5bDXqgsldmb6 X-Received: by 2002:a81:1cd0:: with SMTP id c199-v6mr4697923ywc.193.1538689281090; Thu, 04 Oct 2018 14:41:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538689281; cv=none; d=google.com; s=arc-20160816; b=gjROVZvFhyHolkEZc1XhUR19xfhkYbfwO4J3WYZedqD+i2S3hSPoWdo6bMradR2m5r t/0vw5caTt8QQnIBNez0xGZFoTQOws82I0Nj413nqGeoMqYxEh3i5lPpj4KGHE+XQb4H iaBEJyp1Lwu+m6jCVKJRkAbLw3S3i+6UoC/fk609n4wd6ngohGdoGPIUo7QvSiUVGe4B MpwresOSOZ05kLWZryCN3KwDLP6yfh3ouqRtocxTu1NSkHT2gdwEflD3PLlJiU75sUM4 o/6SLIKAnGpJPvHTeVq/Gakfbvphwx5nwOxtSSgroB685cR0h7VBXUPrFJx4P7TOnk8z nUUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:content-transfer-encoding:spamdiagnosticmetadata :spamdiagnosticoutput:content-language:accept-language:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature :dkim-signature; bh=NRPERSulB+CgiyoKzWIV43HlBDw3Wje3bt9jlCGX1Bo=; b=B+FdIqEbRMxKeI4+FCvaoAk/xvBkXTeTM586SgHSFQRb+5YCYSm/a+DIQgoVxGwn/+ uvongBzfAxCNtd0fJfEfk+MUx4seG68f6qOEfwUrtMRg+dp36wHyvnbInXaZX8MpNept h7HZ0zxUPYvARsMBue2U+F8Y8/oPaKX1Q2qs/ZTvgrn6PSlfj/e+7XOOpr2gbxfMGp9K 17LZPrZfYG2sCb9nAxqmWCLremsSGRcK5DSwkr6fvyDGsrZCufAadnaGrYDDbLfGO1/M 1Z4C7h2VYPiB47EW1QLt0qOEDKz76W8zlCkDNNiYvAyxu7Q+sNUVclYTtsg8bTF4Efru QowA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b="oPR/GZCH"; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=Zf6dfcgi; spf=pass (google.com: domain of prvs=3815c02a06=guro@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=3815c02a06=guro@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com. [67.231.153.30]) by mx.google.com with ESMTPS id p7-v6si1329488ybc.559.2018.10.04.14.41.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Oct 2018 14:41:21 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=3815c02a06=guro@fb.com designates 67.231.153.30 as permitted sender) client-ip=67.231.153.30; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b="oPR/GZCH"; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=Zf6dfcgi; spf=pass (google.com: domain of prvs=3815c02a06=guro@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=3815c02a06=guro@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w94LXpkR028278; Thu, 4 Oct 2018 14:41:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=facebook; bh=NRPERSulB+CgiyoKzWIV43HlBDw3Wje3bt9jlCGX1Bo=; b=oPR/GZCHU6uxgMl+VQCh2/f4uMTwwrw0JyKRj82uWzk0HzeRqEmOMB9DLkQMhIsMtqNF agEldVI6qK+uapQg7kKPTDPcq244gVqiPyo45S1liMxRqZJIWAq+EXWUcVs5Iy+t6yol 90FaZuksACcqbJdjrSYcPofWxzpIpvevcR8= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2mwqw7rn6m-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 04 Oct 2018 14:41:15 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.24) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 4 Oct 2018 14:41:14 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NRPERSulB+CgiyoKzWIV43HlBDw3Wje3bt9jlCGX1Bo=; b=Zf6dfcgihiioNPpUOUm3li9aRylQXR38oaM8U7NnkDJDsTJPMvNLTE78DsR0f6KtAo8zsusMqbH/QCEMzPb3QGhRM2njLWeoxFx+uZS/3el3WzI1Z3yRlxknDEBexGBDaEBwlI0zb/ruMjquEeGsEr23NWP3IkBrmp0f1qZ0ueA= Received: from BY2PR15MB0167.namprd15.prod.outlook.com (10.163.64.141) by BY2PR15MB0886.namprd15.prod.outlook.com (10.164.171.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.25; Thu, 4 Oct 2018 21:41:09 +0000 Received: from BY2PR15MB0167.namprd15.prod.outlook.com ([fe80::19fd:7871:6103:1dba]) by BY2PR15MB0167.namprd15.prod.outlook.com ([fe80::19fd:7871:6103:1dba%4]) with mapi id 15.20.1185.024; Thu, 4 Oct 2018 21:41:09 +0000 From: Roman Gushchin To: "linux-mm@kvack.org" , Andrew Morton CC: Michal Hocko , David Rientjes , "linux-kernel@vger.kernel.org" , Kernel Team , Roman Gushchin , Johannes Weiner , Vladimir Davydov Subject: [PATCH v2] mm: don't raise MEMCG_OOM event due to failed high-order allocation Thread-Topic: [PATCH v2] mm: don't raise MEMCG_OOM event due to failed high-order allocation Thread-Index: AQHUXCr2abwffTuYv0uLv4BJ3OKA6w== Date: Thu, 4 Oct 2018 21:41:09 +0000 Message-ID: <20181004214050.7417-1-guro@fb.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR21CA0057.namprd21.prod.outlook.com (2603:10b6:300:db::19) To BY2PR15MB0167.namprd15.prod.outlook.com (2a01:111:e400:58e0::13) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [2620:10d:c090:200::6:7869] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;BY2PR15MB0886;20:L0sfQIXGxZCFxBTV1W9wkugzFAFp0EaZoWRwkLRh7r3tZKLHvvfmg0ucHX5wfQsU2FI3xuHcoDwzQGpiSBIhyq8dH1OUq5i4COW65h3kJaAlkft12551cXIWT2y0eRp4nI6jTvaFgyhYQGzePfKEHyqL+qpQJGwOQx0NxuaqTKE= x-ms-office365-filtering-correlation-id: da7f1787-c249-4b7b-8f6f-08d62a421871 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:BY2PR15MB0886; x-ms-traffictypediagnostic: BY2PR15MB0886: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(17755550239193)(67672495146484)(211936372134217)(153496737603132)(85827821059158); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(823302091)(10201501046)(3231355)(11241501184)(944501410)(52105095)(3002001)(93006095)(93001095)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(20161123562045)(20161123560045)(201708071742011)(7699051);SRVR:BY2PR15MB0886;BCL:0;PCL:0;RULEID:;SRVR:BY2PR15MB0886; x-forefront-prvs: 0815F8251E x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39860400002)(396003)(346002)(136003)(366004)(376002)(52314003)(189003)(199004)(316002)(256004)(486006)(39060400002)(36756003)(54906003)(2900100001)(102836004)(106356001)(6512007)(5250100002)(386003)(476003)(2616005)(2501003)(4326008)(305945005)(7736002)(14444005)(71190400001)(71200400001)(6506007)(53936002)(25786009)(46003)(86362001)(575784001)(186003)(6436002)(8936002)(5660300001)(8676002)(6116002)(81166006)(97736004)(1076002)(2906002)(6486002)(81156014)(110136005)(105586002)(14454004)(478600001)(52116002)(68736007)(99286004)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:BY2PR15MB0886;H:BY2PR15MB0167.namprd15.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: fb.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: TxkyFpSOLCGXSfWfC8YEhlDN8jyTV0tFHaw+g/OidLxfsbAgagClGMDGxXTE29Hx5wP2m/S1ywpJ2Ds/Qg2e9o20jrqnu2avyj1CZjzTqn+k+kHe1mN6HZ0cLYvrFKzKihv7Etp6uVZsb6o/xaknp2xUe8KsCxbUfGeMqnUf5MM+50i8+52RNAaCfcAyYywAjLyn0GF5MJz9XqzHVN5DsRMNrkY/JJUzK6ijQOxLNETNfffhc9SxJDrWTlKk2PfA8yLQJMLCjJObiIqXxbBpXZkWNIxf45db8aXOOJhzMoaoCy/yFoP/4O6R0Ukkq6W/Tam32PVI/JL8eQpbsoFZ/iNSdQfSJkcp/wMwptwWrm0= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: da7f1787-c249-4b7b-8f6f-08d62a421871 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Oct 2018 21:41:09.6745 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR15MB0886 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-10-04_09:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe 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 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 --- 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 8389d6f72a77..8384c681a4b2 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1133,6 +1133,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 7bebe2ddec05..81b47d0b14d7 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