Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3356829pxb; Mon, 17 Jan 2022 18:28:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJyEno/7c3A5tBISSlRXJP3/vkbx4A4oz9LtxFJTCLHL0tQAkx8hNBv2ajlB94Q8voLpf0jL X-Received: by 2002:a17:902:e84f:b0:14a:84d8:911b with SMTP id t15-20020a170902e84f00b0014a84d8911bmr22514074plg.81.1642472913649; Mon, 17 Jan 2022 18:28:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642472913; cv=none; d=google.com; s=arc-20160816; b=obl/eE3IHoLqpfAgMZDKC7A8ma05mi9zH68fACj3cS16CaKhtj/91SExPv2wDJLxIH SAR4fOoyPozCjMWfvxzfFGsDKfkmPa+cYkx+2FjeqfgkwnQountKs5kZEu2m6RhiEV27 LlCINsWWnHWvpovb+fmv3ZI0y8fWCoW9apB+LP4tzRHW/WwLx0IBeykX7EFUV/XS4EB8 Bg9vxq6hdLyn8rSB52y0tkb/a/P7wmviq+kPPzSni3GT1yrLvOmLTeU6LxOf4uRFgAde 48KilnpUSNO4nx4BEAV0UgvPNHdXJRlr+8clDXpyVjcVnGEFnJGWz7qBECnvcnmjeGMs hmFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wOyNSE44kK6xC41+HeY9o5KMHdWeZPag8nufqG7r+kQ=; b=ANc1GxDegT+coBBXUaGsgQjYWFUGKJhYdtKkMw7yUhnVQQGwfptsxrGQ9XzORluIaf Hy5oVHJLcRqMGOO9tq3sEEuOReXV4FiHkSLxZOrtlqt9QjjoM+gBYmF7dLT+GAOlztDg MOGGPItXJipWT+E+YRs7PSOym2WbUOEiP4U+bnppMUfTJ3Af/0su7RP2k0yb8iFE/Qmi MbzFoTqcGmlsOHdlFw/mKcGe5U0SN78UoSJ55qFDPCmCyCHn52N6G5R+n845AlB9zDnZ HeHuasOJ076xEK/KGTfGJDTKZS0Rbitw0Z1ppLZ4wOtT4KYbTeupszuV5yXHdW9aNwGC Q1hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b="a2pt+/qP"; 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=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z16si18996952plg.389.2022.01.17.18.28.21; Mon, 17 Jan 2022 18:28:33 -0800 (PST) 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=@suse.com header.s=susede1 header.b="a2pt+/qP"; 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=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234390AbiAQNrJ (ORCPT + 99 others); Mon, 17 Jan 2022 08:47:09 -0500 Received: from smtp-out1.suse.de ([195.135.220.28]:44622 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232312AbiAQNrI (ORCPT ); Mon, 17 Jan 2022 08:47:08 -0500 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 85B6B21122; Mon, 17 Jan 2022 13:47:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642427227; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wOyNSE44kK6xC41+HeY9o5KMHdWeZPag8nufqG7r+kQ=; b=a2pt+/qPhTSug69pW6RB6v4uzknMCkQhWVvqoHvVCncCefvImDNkaElNJ+HjVJshxFxXS6 208ptyY9gfUT9VwlFirdumwjt29oeZObXFMr6a/ndgWUhYbsbqa1vm8iZFMJo6SQNH0caX x8Hqmewhq4/7WgAA0lTtRoBGgNeQunI= Received: from suse.cz (unknown [10.100.201.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 432B5A3B88; Mon, 17 Jan 2022 13:47:07 +0000 (UTC) Date: Mon, 17 Jan 2022 14:47:06 +0100 From: Michal Hocko To: Minchan Kim Cc: Andrew Morton , David Hildenbrand , linux-mm , LKML , Suren Baghdasaryan , John Dias Subject: Re: [RESEND][PATCH v2] mm: don't call lru draining in the nested lru_cache_disable Message-ID: References: <20211230193627.495145-1-minchan@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211230193627.495145-1-minchan@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 30-12-21 11:36:27, Minchan Kim wrote: > lru_cache_disable involves IPIs to drain pagevec of each core, > which sometimes takes quite long time to complete depending > on cpu's business, which makes allocation too slow up to > sveral hundredth milliseconds. Furthermore, the repeated draining > in the alloc_contig_range makes thing worse considering caller > of alloc_contig_range usually tries multiple times in the loop. > > This patch makes the lru_cache_disable aware of the fact the > pagevec was already disabled. With that, user of alloc_contig_range > can disable the lru cache in advance in their context during the > repeated trial so they can avoid the multiple costly draining > in cma allocation. Do you have any numbers on any improvements? Now to the change. I do not like this much to be honest. LRU cache disabling is a complex synchronization scheme implemented in __lru_add_drain_all now you are stacking another level on top of that. More fundamentally though. I am not sure I understand the problem TBH. What prevents you from calling lru_cache_disable at the cma level in the first place? > Signed-off-by: Minchan Kim > --- > * from v1 - https://lore.kernel.org/lkml/20211206221006.946661-1-minchan@kernel.org/ > * fix lru_cache_disable race - akpm > > include/linux/swap.h | 14 ++------------ > mm/cma.c | 5 +++++ > mm/swap.c | 30 ++++++++++++++++++++++++++++-- > 3 files changed, 35 insertions(+), 14 deletions(-) > > diff --git a/include/linux/swap.h b/include/linux/swap.h > index ba52f3a3478e..fe18e86a4f13 100644 > --- a/include/linux/swap.h > +++ b/include/linux/swap.h > @@ -348,19 +348,9 @@ extern void lru_note_cost_page(struct page *); > extern void lru_cache_add(struct page *); > extern void mark_page_accessed(struct page *); > > -extern atomic_t lru_disable_count; > - > -static inline bool lru_cache_disabled(void) > -{ > - return atomic_read(&lru_disable_count); > -} > - > -static inline void lru_cache_enable(void) > -{ > - atomic_dec(&lru_disable_count); > -} > - > +extern bool lru_cache_disabled(void); > extern void lru_cache_disable(void); > +extern void lru_cache_enable(void); > extern void lru_add_drain(void); > extern void lru_add_drain_cpu(int cpu); > extern void lru_add_drain_cpu_zone(struct zone *zone); > diff --git a/mm/cma.c b/mm/cma.c > index 995e15480937..60be555c5b95 100644 > --- a/mm/cma.c > +++ b/mm/cma.c > @@ -30,6 +30,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -453,6 +454,8 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, > if (bitmap_count > bitmap_maxno) > goto out; > > + lru_cache_disable(); > + > for (;;) { > spin_lock_irq(&cma->lock); > bitmap_no = bitmap_find_next_zero_area_off(cma->bitmap, > @@ -492,6 +495,8 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, > start = bitmap_no + mask + 1; > } > > + lru_cache_enable(); > + > trace_cma_alloc_finish(cma->name, pfn, page, count, align); > > /* > diff --git a/mm/swap.c b/mm/swap.c > index af3cad4e5378..5f89d7c9a54e 100644 > --- a/mm/swap.c > +++ b/mm/swap.c > @@ -847,7 +847,17 @@ void lru_add_drain_all(void) > } > #endif /* CONFIG_SMP */ > > -atomic_t lru_disable_count = ATOMIC_INIT(0); > +static atomic_t lru_disable_count = ATOMIC_INIT(0); > + > +bool lru_cache_disabled(void) > +{ > + return atomic_read(&lru_disable_count) != 0; > +} > + > +void lru_cache_enable(void) > +{ > + atomic_dec(&lru_disable_count); > +} > > /* > * lru_cache_disable() needs to be called before we start compiling > @@ -859,7 +869,21 @@ atomic_t lru_disable_count = ATOMIC_INIT(0); > */ > void lru_cache_disable(void) > { > - atomic_inc(&lru_disable_count); > + static DEFINE_MUTEX(lock); > + > + /* > + * The lock gaurantees lru_cache is drained when the function > + * returned. > + */ > + mutex_lock(&lock); > + /* > + * If someone is already disabled lru_cache, just return with > + * increasing the lru_disable_count. > + */ > + if (atomic_inc_not_zero(&lru_disable_count)) { > + mutex_unlock(&lock); > + return; > + } > #ifdef CONFIG_SMP > /* > * lru_add_drain_all in the force mode will schedule draining on > @@ -873,6 +897,8 @@ void lru_cache_disable(void) > #else > lru_add_and_bh_lrus_drain(); > #endif > + atomic_inc(&lru_disable_count); > + mutex_unlock(&lock); > } > > /** > -- > 2.34.1.448.ga2b2bfdf31-goog -- Michal Hocko SUSE Labs