Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1249643pxf; Fri, 9 Apr 2021 04:01:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuEp9toxSM4B0D3TIyb8qcHFuio09wzRkXjZyFif366UgAlopDBErP2p5lixk3b/3n2th1 X-Received: by 2002:a05:6a00:174a:b029:1fc:d9ba:da96 with SMTP id j10-20020a056a00174ab02901fcd9bada96mr12171749pfc.40.1617966093253; Fri, 09 Apr 2021 04:01:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617966093; cv=none; d=google.com; s=arc-20160816; b=G9goQCvIVNZytpunWWKdHQI7l25BIgPAmcShfN4GIJQrO/z2cp1eHKF+oaa+BXWZe9 OK/LJhFu6RpkgeCWKgfSykBi01IdOC1JR+dv2FSJUl4rROfKfmrhBcwfq4FMUGd+0wHU c5wKE/0V19fNoiGlH5M81FqCMYd77hX2NMJUIVIIhGhoX5bH7Ry5edM7se1w81cD9XcI /hU+skD/g46RzdIKG2Q10RekK0JQHQDUCL3klkFFnRgb02ZwDyJUniHSOtou8w4/bxU4 2qGB7z/iXkkMDQipwxgzo0df7/QE5Ui+bSiGCNOT7p6hBArSrgQKBk2w7jM4JUZm1wI0 4ITA== 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:from:references :cc:to:subject; bh=5yIzUN7ua2DfVadnXw3LK9xkeiInGV5BqhQmPvNPjeQ=; b=v/WIFKRehz84Gd1FH0wsorpCRnLT3J+CTde2nEfeN3mqHg/KcKTYhkyJ8HXVgKwnji Znlgy9J+rwL9az0UXM2xDyH1knEGWtpUvjfnAcMVJl4BPKknTOW0OJAoHgqhCY+/Vdmp wdXRpfZAN+fVd/iKUg+p+RiT+9NeD1i+Z1ulDtBFmuhWQW9RVjNcneLFw0zbH/aW9kyo Q50feEGj4Acq7ZcmIh9lTMYbG1yC1AOEwCqU889BCavV08jx0FSRo4Srgz9+90fjS0mB exp/U0QBDnQcK/U1Dz+V6vtQI7k2kW7Nf3KZGGeXRMQcmlC0oxrkn7zecWJapffaTocp HGRw== 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 x12si2538853pfi.50.2021.04.09.04.01.13; Fri, 09 Apr 2021 04:01:33 -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 S233755AbhDILAg (ORCPT + 99 others); Fri, 9 Apr 2021 07:00:36 -0400 Received: from mx2.suse.de ([195.135.220.15]:34272 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233670AbhDILAg (ORCPT ); Fri, 9 Apr 2021 07:00:36 -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 9B536B147; Fri, 9 Apr 2021 11:00:22 +0000 (UTC) Subject: Re: [PATCH 1/2] mm/vmscan: add sync_shrinkers function To: =?UTF-8?Q?Christian_K=c3=b6nig?= , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: ray.huang@amd.com, daniel@ffwll.ch, akpm@linux-foundation.org References: <20210409071725.1532-1-christian.koenig@amd.com> From: Vlastimil Babka Message-ID: <462c2a51-4aa8-47ba-1c67-171ca651b016@suse.cz> Date: Fri, 9 Apr 2021 13:00:22 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210409071725.1532-1-christian.koenig@amd.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/9/21 9:17 AM, Christian König wrote: > To be able to switch to a spinlock and reduce lock contention in the TTM > shrinker we don't want to hold a mutex while unmapping and freeing pages > from the pool. Does using spinlock instead of mutex really reduce lock contention? > But then we somehow need to prevent a race between (for example) the shrinker > trying to free pages and hotplug trying to remove the device which those pages > belong to. > > Taking and releasing the shrinker semaphore on the write side after > unmapping and freeing all pages should make sure that no shrinker is running in > paralell any more. So you explain this in this commit log for adding the function, but then the next patch just adds a sync_shrinkers() call without any comment. I would expect there a comment explaining why it's done there - what it protects against, as it's not an obvious pattern IMHO. > Signed-off-by: Christian König > --- > include/linux/shrinker.h | 1 + > mm/vmscan.c | 10 ++++++++++ > 2 files changed, 11 insertions(+) > > diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h > index 0f80123650e2..6b75dc372fce 100644 > --- a/include/linux/shrinker.h > +++ b/include/linux/shrinker.h > @@ -92,4 +92,5 @@ extern void register_shrinker_prepared(struct shrinker *shrinker); > extern int register_shrinker(struct shrinker *shrinker); > extern void unregister_shrinker(struct shrinker *shrinker); > extern void free_prealloced_shrinker(struct shrinker *shrinker); > +extern void sync_shrinkers(void); > #endif > diff --git a/mm/vmscan.c b/mm/vmscan.c > index 562e87cbd7a1..46cd9c215d73 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -408,6 +408,16 @@ void unregister_shrinker(struct shrinker *shrinker) > } > EXPORT_SYMBOL(unregister_shrinker); > > +/** > + * sync_shrinker - Wait for all running shrinkers to complete. > + */ > +void sync_shrinkers(void) > +{ > + down_write(&shrinker_rwsem); > + up_write(&shrinker_rwsem); > +} > +EXPORT_SYMBOL(sync_shrinkers); > + > #define SHRINK_BATCH 128 > > static unsigned long do_shrink_slab(struct shrink_control *shrinkctl, >