Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1036818imm; Wed, 10 Oct 2018 08:12:43 -0700 (PDT) X-Google-Smtp-Source: ACcGV63fnVNFF0RzV3p6PVfUEYC4exBViuZM7ncdJfdxVwBs26YmZLS9eQjb9rCRjvO3JaiaCm4f X-Received: by 2002:a63:5605:: with SMTP id k5-v6mr30201230pgb.189.1539184362958; Wed, 10 Oct 2018 08:12:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539184362; cv=none; d=google.com; s=arc-20160816; b=DDvZoypvL7aXLdijY/aqRVtZN+Xc1cCLAibSs8vgwPM4I7kyUXq2PnQr3mMeRz7ELs ZYkyYlV94ZNSKKrlKljnE8ExixoOqHl7aD3Gqp4kzbx2/6bb3TC+Ze7sN/7oZazcjVdV Tzv5dF36yHLCf12KOm3QUg71HiCmXZ5iNhEXjlRUDXDOQYLeynk++ZeSHECskZw1NUgy BaaNS2V1yu4sT05EOy7IInnwj298NuLTFfJ3QMfaXxjthTWGT1zC7Mncayl6NhnfmNYK hGu9SDn9iK3QY77jyiDSipCH9slp1l/y2PTycPGbYZRyR5gCKMgw7Srjn4ZIkojsQCOj EZbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=33kccVia1YlGhF8vy6H40nEgUB+nCabXE9vEglMNrys=; b=w1nuhrGB7mIm5OHWUbpnUaDjCx0BKyxQxoXxgck2C36eBxWydbd4f2LXomCG6zZsaQ 1XFZQH8Z/oruz5MNirwk8KbpUCrT/l+nMqld5jYqEqzYn/AAOH+qbArkx1CijHCzQ4qY 1DkDjHSbCsz+BXrqOsZqkh7o0kD4bt6WfLcqlFEDKqR/B7BzLvEq+7g5OBaP7sJB9V92 DR/c6NxQWfgxNaL43dsRSO/vXTHjK3Y85IJugACilEXOcbSW6+KHvoYGFauG2bQeD+Du 5cZfCZ5we5t2RTGRBof6uOvqbRLbAqXjZqaPqyh++vowccDz2adlLlHBIwRmE5adVXbX GVwA== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a8-v6si23867513plz.170.2018.10.10.08.12.25; Wed, 10 Oct 2018 08:12:42 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726728AbeJJWe3 (ORCPT + 99 others); Wed, 10 Oct 2018 18:34:29 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:41203 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726503AbeJJWe3 (ORCPT ); Wed, 10 Oct 2018 18:34:29 -0400 Received: by mail-ed1-f67.google.com with SMTP id x31-v6so5265786edd.8 for ; Wed, 10 Oct 2018 08:11:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=33kccVia1YlGhF8vy6H40nEgUB+nCabXE9vEglMNrys=; b=F7wvXTOiXN98feOwNRI6aDBPKu38Dh+L/G5ARSRUOB+gIxke2sRoPF+rMAob6EPZuZ doktL28RQ1glrQee8TUprRjk8IWS5Ftg9t0NiwWH+KKdjUCLgHTDywS8sv6s+UMxgEf3 gP8DPw9Wofmo2vPcLwidqzXEkS/N0b//++J36jjTKr6BKveW5UQ1KjWoXQXXiwEGqEl7 3IXDcXFj/lzrc5QuTWtrMbiuPLvh59f16VsXXSFvd3CU2TUzR7XzLA0YM9aJFnhkYXE/ tqQsAK8iN66/eaViv/MlUU19u+kekpl16DEJektBElV5PSLBO1+8MUDT3jDbYVMEjMLZ ZoSg== X-Gm-Message-State: ABuFfogtwrPV51lUzScOO1LnXRVDzQuUmKSmbXST9h1dKmAlfjvzFOzY pyNMO+/hyWk32KkC4BNmy3U= X-Received: by 2002:a50:ae21:: with SMTP id c30-v6mr20969554edd.20.1539184310207; Wed, 10 Oct 2018 08:11:50 -0700 (PDT) Received: from tiehlicka.suse.cz (ip-37-188-149-132.eurotel.cz. [37.188.149.132]) by smtp.gmail.com with ESMTPSA id x53-v6sm8129625edx.63.2018.10.10.08.11.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Oct 2018 08:11:48 -0700 (PDT) From: Michal Hocko To: Cc: syzkaller-bugs@googlegroups.com, Michal Hocko , guro@fb.com, hannes@cmpxchg.org, kirill.shutemov@linux.intel.com, linux-kernel@vger.kernel.org, penguin-kernel@i-love.sakura.ne.jp, rientjes@google.com, yang.s@alibaba-inc.com Subject: [RFC PATCH] memcg, oom: throttle dump_header for memcg ooms without eligible tasks Date: Wed, 10 Oct 2018 17:11:35 +0200 Message-Id: <20181010151135.25766-1-mhocko@kernel.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <000000000000dc48d40577d4a587@google.com> References: <000000000000dc48d40577d4a587@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michal Hocko syzbot has noticed that it can trigger RCU stalls from the memcg oom path: RIP: 0010:dump_stack+0x358/0x3ab lib/dump_stack.c:118 Code: 74 0c 48 c7 c7 f0 f5 31 89 e8 9f 0e 0e fa 48 83 3d 07 15 7d 01 00 0f 84 63 fe ff ff e8 1c 89 c9 f9 48 8b bd 70 ff ff ff 57 9d <0f> 1f 44 00 00 e8 09 89 c9 f9 48 8b 8d 68 ff ff ff b8 ff ff 37 00 RSP: 0018:ffff88017d3a5c70 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff13 RAX: 0000000000040000 RBX: 1ffffffff1263ebe RCX: ffffc90001e5a000 RDX: 0000000000040000 RSI: ffffffff87b4e0f4 RDI: 0000000000000246 RBP: ffff88017d3a5d18 R08: ffff8801d7e02480 R09: fffffbfff13da030 R10: fffffbfff13da030 R11: 0000000000000003 R12: 1ffff1002fa74b96 R13: 00000000ffffffff R14: 0000000000000200 R15: 0000000000000000 dump_header+0x27b/0xf72 mm/oom_kill.c:441 out_of_memory.cold.30+0xf/0x184 mm/oom_kill.c:1109 mem_cgroup_out_of_memory+0x15e/0x210 mm/memcontrol.c:1386 mem_cgroup_oom mm/memcontrol.c:1701 [inline] try_charge+0xb7c/0x1710 mm/memcontrol.c:2260 mem_cgroup_try_charge+0x627/0xe20 mm/memcontrol.c:5892 mem_cgroup_try_charge_delay+0x1d/0xa0 mm/memcontrol.c:5907 shmem_getpage_gfp+0x186b/0x4840 mm/shmem.c:1784 shmem_fault+0x25f/0x960 mm/shmem.c:1982 __do_fault+0x100/0x6b0 mm/memory.c:2996 do_read_fault mm/memory.c:3408 [inline] do_fault mm/memory.c:3531 [inline] The primary reason of the stall lies in an expensive printk handling of oom report flood because a misconfiguration on the syzbot side caused that there is simply no eligible task because they have OOM_SCORE_ADJ_MIN set. This generates the oom report for each allocation from the memcg context. While normal workloads should be much more careful about potential heavy memory consumers that are OOM disabled it makes some sense to rate limit a potentially expensive oom reports for cases when there is no eligible victim found. Do that by moving the rate limit logic inside dump_header. We no longer rely on the caller to do that. It was only oom_kill_process which has been throttling. Other two call sites simply didn't have to care because one just paniced on the OOM when configured that way and no eligible task would panic for the global case as well. Memcg changed the picture because we do not panic and we might have multiple sources of the same event. Once we are here, make sure that the reason to trigger the OOM is printed without ratelimiting because this is really valuable to debug what happened. Reported-by: syzbot+77e6b28a7a7106ad0def@syzkaller.appspotmail.com Cc: guro@fb.com Cc: hannes@cmpxchg.org Cc: kirill.shutemov@linux.intel.com Cc: linux-kernel@vger.kernel.org Cc: penguin-kernel@i-love.sakura.ne.jp Cc: rientjes@google.com Cc: yang.s@alibaba-inc.com Signed-off-by: Michal Hocko --- mm/oom_kill.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index f10aa5360616..4ee393c85e27 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -430,6 +430,9 @@ static void dump_tasks(struct mem_cgroup *memcg, const nodemask_t *nodemask) static void dump_header(struct oom_control *oc, struct task_struct *p) { + static DEFINE_RATELIMIT_STATE(oom_rs, DEFAULT_RATELIMIT_INTERVAL, + DEFAULT_RATELIMIT_BURST); + pr_warn("%s invoked oom-killer: gfp_mask=%#x(%pGg), nodemask=%*pbl, order=%d, oom_score_adj=%hd\n", current->comm, oc->gfp_mask, &oc->gfp_mask, nodemask_pr_args(oc->nodemask), oc->order, @@ -437,6 +440,9 @@ static void dump_header(struct oom_control *oc, struct task_struct *p) if (!IS_ENABLED(CONFIG_COMPACTION) && oc->order) pr_warn("COMPACTION is disabled!!!\n"); + if (!__ratelimit(&oom_rs)) + return; + cpuset_print_current_mems_allowed(); dump_stack(); if (is_memcg_oom(oc)) @@ -931,8 +937,6 @@ static void oom_kill_process(struct oom_control *oc, const char *message) struct task_struct *t; struct mem_cgroup *oom_group; unsigned int victim_points = 0; - static DEFINE_RATELIMIT_STATE(oom_rs, DEFAULT_RATELIMIT_INTERVAL, - DEFAULT_RATELIMIT_BURST); /* * If the task is already exiting, don't alarm the sysadmin or kill @@ -949,8 +953,7 @@ static void oom_kill_process(struct oom_control *oc, const char *message) } task_unlock(p); - if (__ratelimit(&oom_rs)) - dump_header(oc, p); + dump_header(oc, p); pr_err("%s: Kill process %d (%s) score %u or sacrifice child\n", message, task_pid_nr(p), p->comm, points); -- 2.19.0