Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2488788pxb; Fri, 17 Sep 2021 10:52:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7FaDVoTpeR/reMHCiTxzBE5RYTr4rbJNIlZAeG9XIpOpdgG7lghswCO44gQwk1gbMcGZC X-Received: by 2002:a17:906:689b:: with SMTP id n27mr14319329ejr.459.1631901138170; Fri, 17 Sep 2021 10:52:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631901138; cv=none; d=google.com; s=arc-20160816; b=wZ0mUvYaQu0X1D9RSuttpR9TV4qCO1GB8grZYWchbgAKb8VE6AUuJEnPTLt33rMMTd b86YJri7hxGCzen6OKjzHjUgc7+QIGs55T30WnS23IiZNDBslm9wqphNzWKEjUjn3izd YOYSQSpuhiL+jJTGA/5BmfywgbqjZqbUgGMvC16AY7FO2vEzz8MtxA+tkCOGXpoBh2z7 ARJu3EyQmy0Pn6PNtKuEEOZzyAHtbob6nMiOdADMdtsmz/1FzKTEpwq521loUbMvEYeY tzGhasazeoLtk37H75IoLVqbw3v7zbUuUS6Vlz3e6Jg7mfHPb0tfndDt4tT4e1Pj4daN t+hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:subject:from:dkim-signature; bh=vNgx/3n9bi2etAGIYh4+okt/y0F7gydwzwqScVihv4w=; b=zyyAUW2Nxd3NEeAWYmbGIun6X8rtrWw0Hi0o9slbg88jL+VfBXNKN3G0BPgxPHw0Fz 5G1pgV5xmh3NUp5H2YCaU49cQ3+nWCjw2H6T1TJ80W2G1jgxvLG8J0N37utEMV1N+PH9 /mSlnXEDTk0r/9EedS9ygilrk3EsW1JG6etgjVA+//lFLp9sgYnfHmg++wWzjn77yz2G 9EXboRYT3z03Nl321hoOSxqy5BSVc1QjdHDR6qlw9sTcF3cvPaXyJdPrYWdfG4CpEbQ9 /8rGfLSw4xzaK+I4LpwXvgxA6jMlOitr0se/67eOJghsgM2HDitGfP3X4f7GilceTjzb yU9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=iE23CrPu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b5si7708035edj.573.2021.09.17.10.51.54; Fri, 17 Sep 2021 10:52:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=iE23CrPu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245438AbhIQIJv (ORCPT + 99 others); Fri, 17 Sep 2021 04:09:51 -0400 Received: from relay.sw.ru ([185.231.240.75]:35812 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245027AbhIQIJZ (ORCPT ); Fri, 17 Sep 2021 04:09:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Content-Type:MIME-Version:Date:Message-ID:Subject :From; bh=vNgx/3n9bi2etAGIYh4+okt/y0F7gydwzwqScVihv4w=; b=iE23CrPuqYwx6L+WuP0 MSRozyky9urm64czXwWLrNZ/9ayDJS3aSLwMOheJcHJmfyOFUBrdXFadLP1BGBDronLgyS7h3usB1 piWpEhLqoM1qklkFq3aRzLuG0vmdNKeGMym8Xsi1sQMvfui8ccy6JpnJzOA3VxSbOB8PjqsSCNM=; Received: from [10.93.0.56] by relay.sw.ru with esmtp (Exim 4.94.2) (envelope-from ) id 1mR8tW-002Gyw-D9; Fri, 17 Sep 2021 11:06:50 +0300 From: Vasily Averin Subject: [PATCH mm] vmalloc: back off when the current task is OOM-killed To: Michal Hocko , Johannes Weiner , Vladimir Davydov , Andrew Morton , Tetsuo Handa Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel@openvz.org References: Message-ID: Date: Fri, 17 Sep 2021 11:06:49 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Huge vmalloc allocation on heavy loaded node can lead to a global memory shortage. A task called vmalloc can have the worst badness and be chosen by OOM-killer, however received fatal signal and oom victim mark does not interrupt allocation cycle. Vmalloc will continue allocating pages over and over again, exacerbating the crisis and consuming the memory freed up by another killed tasks. This patch allows OOM-killer to break vmalloc cycle, makes OOM more effective and avoid host panic. Unfortunately it is not 100% safe. Previous attempt to break vmalloc cycle was reverted by commit b8c8a338f75e ("Revert "vmalloc: back off when the current task is killed"") due to some vmalloc callers did not handled failures properly. Found issues was resolved, however, there may be other similar places. Such failures may be acceptable for emergencies, such as OOM. On the other hand, we would like to detect them earlier. However they are quite rare, and will be hidden by OOM messages, so I'm afraid they wikk have quite small chance of being noticed and reported. To improve the detection of such places this patch also interrupts the vmalloc allocation cycle for all fatal signals. The checks are hidden under DEBUG_VM config option to do not break unaware production kernels. Vmalloc uses new alloc_pages_bulk subsystem, so newly added checks can affect other users of this subsystem. Signed-off-by: Vasily Averin --- mm/page_alloc.c | 5 +++++ mm/vmalloc.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index b37435c274cf..133d52e507ff 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5288,6 +5288,11 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, continue; } + if (tsk_is_oom_victim(current) || + (IS_ENABLED(CONFIG_DEBUG_VM) && + fatal_signal_pending(current))) + break; + page = __rmqueue_pcplist(zone, 0, ac.migratetype, alloc_flags, pcp, pcp_list); if (unlikely(!page)) { diff --git a/mm/vmalloc.c b/mm/vmalloc.c index c3b8e3e5cfc5..04b291076726 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -2860,6 +2861,11 @@ vm_area_alloc_pages(gfp_t gfp, int nid, struct page *page; int i; + if (tsk_is_oom_victim(current) || + (IS_ENABLED(CONFIG_DEBUG_VM) && + fatal_signal_pending(current))) + break; + page = alloc_pages_node(nid, gfp, order); if (unlikely(!page)) break; -- 2.31.1