Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2208232pxk; Mon, 14 Sep 2020 07:26:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3XES2yi9Q3x0ue4deGpQNGeApQm6bdGO7LatQtXeFLMpTds7mi/g9eOUXVDC/uQ2wTV/P X-Received: by 2002:a17:906:724b:: with SMTP id n11mr15189455ejk.328.1600093586570; Mon, 14 Sep 2020 07:26:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600093586; cv=none; d=google.com; s=arc-20160816; b=ClejlLUeZbfJEf76rTZnSobFr/aogCbkplfjY9irKXDL9G2Lqda5Qxb9ThKZqLx+u1 5tLuVSwdKeJMjJ1EuKKvuYjomHnfZ/qNZ0qofMfksXeuL+in7XEOlB9ljZZG0M8JiYQO b3MaXrThEPEy54rCDZ8Z5B/dU6edXI3swbxWCFnTceSfDlY3q6cD/otD2aFuFg8Wt58n YZwu2KHMGUdS59GC/DYA9JuY5t/o4DdSzs2fHl8dn6wGrCQYCQvZYYbfI9pLOaSq4gxl /XaquZS0qamXTpIv1xJcCH6t4iE4zE0jmXj1iuMPlY7v5IlR9jkp+iojG3Ael+JU8Rq5 SaWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=a2MkjsgdRLpsCSjd6CTOxEdj9rIY1dMFM9/ErnxG8c8=; b=d2E0y9arDA1gjVGzbZ4Y3z/b2glQgeZczBxmYHczEdjx00Tl/lDqAGxQQypkjbjF/j Tvzyr5KqKA+h3twhBdwBfHqyJFsFiZ0RMpg1MqxHyg7F6oiuMUmUbVNtaXpR93BPMj0q L6M9mM1yj3qK0vND48NrkxbZssZsGd3bxOjALSSsAMlBGcBI8fXcnX/0oxDA64IQUPYh cTr2LDDSTZ8lZoR14NaVa2lyHuDPLn5SKAQoeSe5xiqzLslNfsdNhqX4PZRaaoNjAy9y E/H3/cBJUUTxj2WipaE1LSkJitb04mzrkFdyo5jhv+DpfsnnIDFrVBt4MuP80PsoDKxn teFA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c12si8036642edx.274.2020.09.14.07.26.03; Mon, 14 Sep 2020 07:26:26 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726689AbgINOY7 (ORCPT + 99 others); Mon, 14 Sep 2020 10:24:59 -0400 Received: from mx2.suse.de ([195.135.220.15]:55708 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726695AbgINOWf (ORCPT ); Mon, 14 Sep 2020 10:22:35 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 090E8AE07; Mon, 14 Sep 2020 14:22:49 +0000 (UTC) Date: Mon, 14 Sep 2020 16:22:33 +0200 From: Michal Hocko To: mateusznosek0@gmail.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org Subject: Re: [RFC PATCH] mm/page_alloc.c: micro-optimization reduce oom critical section size Message-ID: <20200914142233.GT16999@dhcp22.suse.cz> References: <20200914100654.21746-1-mateusznosek0@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200914100654.21746-1-mateusznosek0@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 14-09-20 12:06:54, mateusznosek0@gmail.com wrote: > From: Mateusz Nosek > > Most operations from '__alloc_pages_may_oom' do not require oom_mutex hold. > Exception is 'out_of_memory'. The patch refactors '__alloc_pages_may_oom' > to reduce critical section size and improve overall system performance. This is a real slow path. What is the point of optimizing it? Do you have any numbers? Also I am not convinced the patch is entirely safe. At least the last allocation attempt is meant to be done under the lock to allow only one task to perform this. I have forgot the complete reasoning behind that but at least the changelog should argue why that is ok. > Signed-off-by: Mateusz Nosek > --- > mm/page_alloc.c | 45 ++++++++++++++++++++++++--------------------- > 1 file changed, 24 insertions(+), 21 deletions(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index b9bd75cacf02..b07f950a5825 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -3935,18 +3935,7 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order, > .order = order, > }; > struct page *page; > - > - *did_some_progress = 0; > - > - /* > - * Acquire the oom lock. If that fails, somebody else is > - * making progress for us. > - */ > - if (!mutex_trylock(&oom_lock)) { > - *did_some_progress = 1; > - schedule_timeout_uninterruptible(1); > - return NULL; > - } > + bool success; > > /* > * Go through the zonelist yet one more time, keep very high watermark > @@ -3959,14 +3948,17 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order, > ~__GFP_DIRECT_RECLAIM, order, > ALLOC_WMARK_HIGH|ALLOC_CPUSET, ac); > if (page) > - goto out; > + return page; > + > + /* Check if somebody else is making progress for us. */ > + *did_some_progress = mutex_is_locked(&oom_lock); > > /* Coredumps can quickly deplete all memory reserves */ > if (current->flags & PF_DUMPCORE) > - goto out; > + return NULL; > /* The OOM killer will not help higher order allocs */ > if (order > PAGE_ALLOC_COSTLY_ORDER) > - goto out; > + return NULL; > /* > * We have already exhausted all our reclaim opportunities without any > * success so it is time to admit defeat. We will skip the OOM killer > @@ -3976,12 +3968,12 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order, > * The OOM killer may not free memory on a specific node. > */ > if (gfp_mask & (__GFP_RETRY_MAYFAIL | __GFP_THISNODE)) > - goto out; > + return NULL; > /* The OOM killer does not needlessly kill tasks for lowmem */ > if (ac->highest_zoneidx < ZONE_NORMAL) > - goto out; > + return NULL; > if (pm_suspended_storage()) > - goto out; > + return NULL; > /* > * XXX: GFP_NOFS allocations should rather fail than rely on > * other request to make a forward progress. > @@ -3992,8 +3984,20 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order, > * failures more gracefully we should just bail out here. > */ > > + /* > + * Acquire the oom lock. If that fails, somebody else is > + * making progress for us. > + */ > + if (!mutex_trylock(&oom_lock)) { > + *did_some_progress = 1; > + schedule_timeout_uninterruptible(1); > + return NULL; > + } > + success = out_of_memory(&oc); > + mutex_unlock(&oom_lock); > + > /* Exhausted what can be done so it's blame time */ > - if (out_of_memory(&oc) || WARN_ON_ONCE(gfp_mask & __GFP_NOFAIL)) { > + if (success || WARN_ON_ONCE(gfp_mask & __GFP_NOFAIL)) { > *did_some_progress = 1; > > /* > @@ -4004,8 +4008,7 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order, > page = __alloc_pages_cpuset_fallback(gfp_mask, order, > ALLOC_NO_WATERMARKS, ac); > } > -out: > - mutex_unlock(&oom_lock); > + > return page; > } > > -- > 2.20.1 > -- Michal Hocko SUSE Labs