From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20051C433EF for ; Thu, 7 Oct 2021 19:55:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F3013610C8 for ; Thu, 7 Oct 2021 19:55:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240919AbhJGT5h (ORCPT ); Thu, 7 Oct 2021 15:57:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:40244 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232829AbhJGT5g (ORCPT ); Thu, 7 Oct 2021 15:57:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5F1C360F6E; Thu, 7 Oct 2021 19:55:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1633636542; bh=l66xkvwo5JDJqPQgPip89gZwXEOnO407CqbFPpfYp94=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=NSeYGN3XXLrQYf0fPcCt6hWBohOXv+xiotZkcXFQ7+M4XEPsvno7qUvSzhInEfkdm na9gMTTn3OoaSGuNFnHSOIEs1c+kqJVJe+nyBfC4krIYIcGU/spgPCxbMvUP/9futO kEDwoSwwNI8UT31HhqEGNTNN+DhPwAyl8Aej+Ruo= Date: Thu, 7 Oct 2021 12:55:41 -0700 From: Andrew Morton To: Vasily Averin Cc: Michal Hocko , Johannes Weiner , Vladimir Davydov , Tetsuo Handa , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel@openvz.org Subject: Re: [PATCH mm v2] vmalloc: back off when the current task is OOM-killed Message-Id: <20211007125541.db0f3ff2bdbd8fa7dc1db03d@linux-foundation.org> In-Reply-To: <83efc664-3a65-2adb-d7c4-2885784cf109@virtuozzo.com> References: <83efc664-3a65-2adb-d7c4-2885784cf109@virtuozzo.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 5 Oct 2021 16:52:40 +0300 Vasily Averin wrote: > Huge vmalloc allocation on heavy loaded node can lead to a global > memory shortage. Task called vmalloc can have worst badness and > be selected by OOM-killer, however taken fatal signal does not > interrupt allocation cycle. Vmalloc repeat page allocaions > again and again, exacerbating the crisis and consuming the memory > freed up by another killed tasks. > > After a successful completion of the allocation procedure, a fatal > signal will be processed and task will be destroyed finally. > However it may not release the consumed memory, since the allocated > object may have a lifetime unrelated to the completed task. > In the worst case, this can lead to the host will panic > due to "Out of memory and no killable processes..." > > This patch allows OOM-killer to break vmalloc cycle, makes OOM more > effective and avoid host panic. It does not check oom condition directly, > however, and breaks page allocation cycle when fatal signal was received. > > This may trigger some hidden problems, when caller does not handle > vmalloc failures, or when rollaback after failed vmalloc calls own > vmallocs inside. However all of these scenarios are incorrect: > vmalloc does not guarantee successful allocation, it has never been called > with __GFP_NOFAIL and threfore either should not be used for any rollbacks > or should handle such errors correctly and not lead to critical > failures. > This needed a little rework due to https://lkml.kernel.org/r/20210928121040.2547407-1-chenwandun@huawei.com. Please check and retest sometime? --- a/mm/vmalloc.c~vmalloc-back-off-when-the-current-task-is-oom-killed +++ a/mm/vmalloc.c @@ -2887,6 +2887,9 @@ vm_area_alloc_pages(gfp_t gfp, int nid, page = NULL; while (nr_allocated < nr_pages) { + if (fatal_signal_pending(current)) + break; + if (nid == NUMA_NO_NODE) page = alloc_pages(gfp, order); else _ From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Morton Subject: Re: [PATCH mm v2] vmalloc: back off when the current task is OOM-killed Date: Thu, 7 Oct 2021 12:55:41 -0700 Message-ID: <20211007125541.db0f3ff2bdbd8fa7dc1db03d@linux-foundation.org> References: <83efc664-3a65-2adb-d7c4-2885784cf109@virtuozzo.com> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1633636542; bh=l66xkvwo5JDJqPQgPip89gZwXEOnO407CqbFPpfYp94=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=NSeYGN3XXLrQYf0fPcCt6hWBohOXv+xiotZkcXFQ7+M4XEPsvno7qUvSzhInEfkdm na9gMTTn3OoaSGuNFnHSOIEs1c+kqJVJe+nyBfC4krIYIcGU/spgPCxbMvUP/9futO kEDwoSwwNI8UT31HhqEGNTNN+DhPwAyl8Aej+Ruo= In-Reply-To: <83efc664-3a65-2adb-d7c4-2885784cf109-5HdwGun5lf+gSpxsJD1C4w@public.gmane.org> List-ID: Content-Type: text/plain; charset="us-ascii" To: Vasily Averin Cc: Michal Hocko , Johannes Weiner , Vladimir Davydov , Tetsuo Handa , cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, kernel-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org On Tue, 5 Oct 2021 16:52:40 +0300 Vasily Averin wrote: > Huge vmalloc allocation on heavy loaded node can lead to a global > memory shortage. Task called vmalloc can have worst badness and > be selected by OOM-killer, however taken fatal signal does not > interrupt allocation cycle. Vmalloc repeat page allocaions > again and again, exacerbating the crisis and consuming the memory > freed up by another killed tasks. > > After a successful completion of the allocation procedure, a fatal > signal will be processed and task will be destroyed finally. > However it may not release the consumed memory, since the allocated > object may have a lifetime unrelated to the completed task. > In the worst case, this can lead to the host will panic > due to "Out of memory and no killable processes..." > > This patch allows OOM-killer to break vmalloc cycle, makes OOM more > effective and avoid host panic. It does not check oom condition directly, > however, and breaks page allocation cycle when fatal signal was received. > > This may trigger some hidden problems, when caller does not handle > vmalloc failures, or when rollaback after failed vmalloc calls own > vmallocs inside. However all of these scenarios are incorrect: > vmalloc does not guarantee successful allocation, it has never been called > with __GFP_NOFAIL and threfore either should not be used for any rollbacks > or should handle such errors correctly and not lead to critical > failures. > This needed a little rework due to https://lkml.kernel.org/r/20210928121040.2547407-1-chenwandun-hv44wF8Li92Xj1p+fO2waQ@public.gmane.org Please check and retest sometime? --- a/mm/vmalloc.c~vmalloc-back-off-when-the-current-task-is-oom-killed +++ a/mm/vmalloc.c @@ -2887,6 +2887,9 @@ vm_area_alloc_pages(gfp_t gfp, int nid, page = NULL; while (nr_allocated < nr_pages) { + if (fatal_signal_pending(current)) + break; + if (nid == NUMA_NO_NODE) page = alloc_pages(gfp, order); else _