Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2209483ybh; Fri, 13 Mar 2020 15:02:39 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsl9LFMP/ZAb/YLJc3esLmDi07Leeeqlds519m0k6HEN3ne8EVaKSV17IGMOs54zgtCnw8t X-Received: by 2002:aca:e106:: with SMTP id y6mr8994025oig.131.1584136959097; Fri, 13 Mar 2020 15:02:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584136959; cv=none; d=google.com; s=arc-20160816; b=KKVPleQfmTIx1fMBD6n8oLj7j9YGJLnt41MjispiiqxvVvAltlD3kRPx92ZfQPZrVA 0eKT24EastZ4x5ahw9RsUUZhHFS/qYjLHOskHyrcc99cl4Ca5KSRKINtE9UXH7JUJWRo e32iXYKoSPC4WuNsMjjHhwTl3S9h/XHZaOQ4O7HAq114qxkssgJ3SHG7Oc/btDr5OEiy ClVx/0zt/rSzYlZ8VaLZfjwwjKrCzlnnoJFq2N0mAmHsAz0tWMS2pB2PvP2aDHdavwfW oNlNzUI6W8gfEhUqii11fzp1JQXjGuaZyhx3gwWgVoi4UqLx8PTtTle7PTi4DBQ0L383 21mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=UFE9bZCG4sWGzF0InHa1jECdp69Y2rcipLo/idzivo8=; b=1A/3usSbH06lZSWUEZs2PeYhX0I39hCUZtH7Uu/pdixpMcRVYdkugw6bwqpB0WL72P Q2pzoZSNsKSVSU9xF6adrZ7hkAY0T2jKffMK/rV5Zc4ygCbwRDbPuGHjrWjfbT7lP0gn 3ygAQ4yNz6UQAb7tfMetgGaaEX3/WFgpLrIiCr9rY/dKTLbaurTm5HsvpSoP5P3wMdGd 4/y6R0mJEDCJOQE2kNTw712t21dTBsa/dc3tCCLR+5Ejjo4MGQ59Sie0T4E82gUg72I9 JNH7/SnagiKM8y6e1x13VHgNI6HzUx3av8QHqi0DISb8OSVYP947AVBMyNvRo1GF+cAg sy+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=o6zQrGkf; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p25si5388940oto.168.2020.03.13.15.02.25; Fri, 13 Mar 2020 15:02:39 -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=@google.com header.s=20161025 header.b=o6zQrGkf; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727505AbgCMWBU (ORCPT + 99 others); Fri, 13 Mar 2020 18:01:20 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:37727 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726543AbgCMWBU (ORCPT ); Fri, 13 Mar 2020 18:01:20 -0400 Received: by mail-pf1-f195.google.com with SMTP id p14so6087066pfn.4 for ; Fri, 13 Mar 2020 15:01:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=UFE9bZCG4sWGzF0InHa1jECdp69Y2rcipLo/idzivo8=; b=o6zQrGkfIrtt5FoOA5+Q0j4dDaC/p7dfapsUM9vxhhM+DfktEGLaFpmG+oJu7R2wsa /ERomm2bMVyt5ZDEjmCApn34tTXPJQ7eL1gY0xIl5qobH2D22pkddabiBGWAIrW9fxEK r/KErvHJfEzlAvSdcCbPAlENTb7rhpHa6+qK2KP980KgDmZH5wTO3qEw7uiocAHiSqGT eRERMZ8rirAGZmQN3OtCje2+L/Wcg7rBc4PpBWK9ziK7nT4VGQlLAAxontaTVAWvv3VI oF+L+fwq6A2V0o/HjtLHDGpu4RccNKhjSRtfT1//gJRJKJBfUu8U0NsPd9qqMpIY2xhf UA4g== 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:in-reply-to:message-id :references:user-agent:mime-version; bh=UFE9bZCG4sWGzF0InHa1jECdp69Y2rcipLo/idzivo8=; b=uMFg1z3FXAjUrX1M92+kmu0SqqsS3CFosb+LgkjFsjmvdFLZCZ3u0XXdbyM1pRjRa3 I5IhdqEgXe2mI1NlTeplxNky27Epv2W177rFB6NCvPnOg4BvaEvSeoPyN69SnQi1HbBm sz8rlwAxWWH3CLBZ5SftEJzoh7nbCboPcH4xNc2jkWUrTkYBIWII0/D3k0gYoa6qGlnO PFmAb9mFukDXlWAInoUtcLi6El70kSXUAVSq4EEdGTX7kpncYQq1wwGOpUMfaDJpdzE6 A+peyqCQIFSRe+BDjohmw/Wf3RMfbkVVlYPzHINRi4D7ps+4otnzpVaWoQyU9W/w1OzN TCXg== X-Gm-Message-State: ANhLgQ2GQXI+Ok4FfmHdDMsUi3inwrzH9PhJkn3xOnuZ1EMekkA4TjsF KnxZnBhuwdLV8I/AxmTt31wS9aOpFFY= X-Received: by 2002:a63:e50b:: with SMTP id r11mr6530266pgh.178.1584136877223; Fri, 13 Mar 2020 15:01:17 -0700 (PDT) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id d6sm8199581pfn.214.2020.03.13.15.01.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Mar 2020 15:01:16 -0700 (PDT) Date: Fri, 13 Mar 2020 15:01:15 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Tetsuo Handa cc: Andrew Morton , Vlastimil Babka , Michal Hocko , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [patch] mm, oom: prevent soft lockup on memcg oom for UP systems In-Reply-To: <202003130015.02D0F9uT079462@www262.sakura.ne.jp> Message-ID: References: <202003120012.02C0CEUB043533@www262.sakura.ne.jp> <202003130015.02D0F9uT079462@www262.sakura.ne.jp> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 13 Mar 2020, Tetsuo Handa wrote: > > On an UP kernel with swap disabled, you limit a memcg to 100MB and start > > three processes that each fault 40MB attached to it. Same reproducer as > > the "mm, oom: make a last minute check to prevent unnecessary memcg oom > > kills" patch except in that case there are two cores. > > > > I'm not a heavy memcg user. Please provide steps for reproducing your problem > in a "copy and pastable" way (e.g. bash script, C program). > Use Documentation/admin-guide/cgroup-v1/memory.rst or Documentation/admin-guide/cgroup-v2.rst to setup a memcg depending on which cgroup version you use, limit it to 100MB, and attach your process to it. Run three programs that fault 40MB. To do that, you need to use mmap: (void)mmap(NULL, 40 << 20, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_POPULATE, 0, 0); Have it stall after populating the memory: for (;;); > > > @@ -1576,6 +1576,7 @@ static bool mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask, > > > */ > > > ret = should_force_charge() || out_of_memory(&oc); > > > mutex_unlock(&oom_lock); > > > + schedule_timeout_killable(1); > > > return ret; > > > } > > > > > > > If current was process chosen for oom kill, this would actually induce the > > problem, not fix it. > > > > Why? Memcg OOM path allows using forced charge path if should_force_charge() == true. > > Since your lockup report > > Call Trace: > shrink_node+0x40d/0x7d0 > do_try_to_free_pages+0x13f/0x470 > try_to_free_mem_cgroup_pages+0x16d/0x230 > try_charge+0x247/0xac0 > mem_cgroup_try_charge+0x10a/0x220 > mem_cgroup_try_charge_delay+0x1e/0x40 > handle_mm_fault+0xdf2/0x15f0 > do_user_addr_fault+0x21f/0x420 > page_fault+0x2f/0x40 > > says that allocating thread was calling try_to_free_mem_cgroup_pages() from try_charge(), > allocating thread must be able to reach mem_cgroup_out_of_memory() from mem_cgroup_oom() > from try_charge(). And actually > > Memory cgroup out of memory: Killed process 808 (repro) total-vm:41944kB, anon-rss:35344kB, file-rss:504kB, shmem-rss:0kB, UID:0 pgtables:108kB oom_score_adj:0 > > says that allocating thread did reach mem_cgroup_out_of_memory(). Then, allocating thread > must be able to sleep at mem_cgroup_out_of_memory() if schedule_timeout_killable(1) is > mem_cgroup_out_of_memory(). > > Also, if current process was chosen for OOM-kill, current process will be able to leave > try_charge() due to should_force_charge() == true, won't it? > > Thus, how can "this would actually induce the problem, not fix it." happen? The entire issue is that the victim never gets a chance to run because the allocator doesn't give it a chance to run on an UP system. Your patch is broken because if the victim is current, you've lost your golden opportunity to actually exit and ceded control to the allocator that will now starve the victim.