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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA0B0EE49A3 for ; Tue, 22 Aug 2023 13:56:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236215AbjHVN4h (ORCPT ); Tue, 22 Aug 2023 09:56:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236209AbjHVN42 (ORCPT ); Tue, 22 Aug 2023 09:56:28 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53627CDD for ; Tue, 22 Aug 2023 06:56:24 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-31c5ee810e3so184740f8f.0 for ; Tue, 22 Aug 2023 06:56:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; t=1692712583; x=1693317383; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=LXzMnEM8moHL5KfliVx5cD1lb3aAd5NGNjk14fqFYLY=; b=OvQvaauBf9P71X6OM3iV6zJjVstVKwDXVeR2TcNPjDcJz2f399JP5BZxFUiXHkTWc/ r5lP7XQ7vkvpSMptW40PFm8KnzYip/IftCKI/V7U1LWv+OZcsOEZqcqKXDKRf7oBDJOP RNOespNYAQNJ9FavrWx3YuWYiBeKAeIF+XsTA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692712583; x=1693317383; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LXzMnEM8moHL5KfliVx5cD1lb3aAd5NGNjk14fqFYLY=; b=I6/cmXfkceajWinxEBj9eCLwtEm5WSKcaQBoqKtg+0N+izKiUauOhQYCPTmNF6MqUs 3vSYUZ0Vk/mGluk5YJ1iY+Gq1KR5C/uxIvhuYJQmuaCezqk1hg9CGnL2DagjEK7nQAPe Men8ZcjU8dU4V/t2AR1eJNYOBkK4MjjyE/GdS09PYOvogdaAPqdBPregIX2630SzbK2b R0IFTwtlr9QvTkp1AG8sRCFppyAf5TXwEfTmGomml2HDRkJHYHf+aIrN+i29IrPqmI6n tiwxe3m53OW0JaTu+XlCcxKItwk/KQy9xpiqgR752JyojFrAEMH+dqT7hiOkEY90MQUk mppQ== X-Gm-Message-State: AOJu0YwynwS33yFmMTu5qd9L9jQ2wKs+CP1XHPv4ncnZ9xEl9ahdWIjz ifQb3aYjT+GOeuJ4WdqZASnSuA== X-Google-Smtp-Source: AGHT+IHJQrlSrCu8WgUX5s8XkdDm6/hR/jwfxds8mVBdQgFEL5tBYnuf/oIT+VMpj8Z6S8wRiH/+Kw== X-Received: by 2002:a5d:65c5:0:b0:319:8dcf:5c10 with SMTP id e5-20020a5d65c5000000b003198dcf5c10mr6979657wrw.6.1692712582669; Tue, 22 Aug 2023 06:56:22 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id u5-20020a05600c210500b003fc02e8ea68sm19456835wml.13.2023.08.22.06.56.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 06:56:22 -0700 (PDT) Date: Tue, 22 Aug 2023 15:56:19 +0200 From: Daniel Vetter To: Qi Zheng Cc: akpm@linux-foundation.org, david@fromorbit.com, tkhai@ya.ru, vbabka@suse.cz, roman.gushchin@linux.dev, djwong@kernel.org, brauner@kernel.org, paulmck@kernel.org, tytso@mit.edu, steven.price@arm.com, cel@kernel.org, senozhatsky@chromium.org, yujie.liu@intel.com, gregkh@linuxfoundation.org, muchun.song@linux.dev, simon.horman@corigine.com, dlemoal@kernel.org, kvm@vger.kernel.org, dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org, linux-mm@kvack.org, dm-devel@redhat.com, linux-mtd@lists.infradead.org, x86@kernel.org, cluster-devel@redhat.com, xen-devel@lists.xenproject.org, linux-ext4@vger.kernel.org, linux-arm-msm@vger.kernel.org, rcu@vger.kernel.org, linux-bcache@vger.kernel.org, Muchun Song , linux-raid@vger.kernel.org, linux-nfs@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-erofs@lists.ozlabs.org, linux-btrfs@vger.kernel.org Subject: Re: [PATCH v4 43/48] drm/ttm: introduce pool_shrink_rwsem Message-ID: Mail-Followup-To: Qi Zheng , akpm@linux-foundation.org, david@fromorbit.com, tkhai@ya.ru, vbabka@suse.cz, roman.gushchin@linux.dev, djwong@kernel.org, brauner@kernel.org, paulmck@kernel.org, tytso@mit.edu, steven.price@arm.com, cel@kernel.org, senozhatsky@chromium.org, yujie.liu@intel.com, gregkh@linuxfoundation.org, muchun.song@linux.dev, simon.horman@corigine.com, dlemoal@kernel.org, kvm@vger.kernel.org, dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org, linux-mm@kvack.org, dm-devel@redhat.com, linux-mtd@lists.infradead.org, x86@kernel.org, cluster-devel@redhat.com, xen-devel@lists.xenproject.org, linux-ext4@vger.kernel.org, linux-arm-msm@vger.kernel.org, rcu@vger.kernel.org, linux-bcache@vger.kernel.org, Muchun Song , linux-raid@vger.kernel.org, linux-nfs@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-erofs@lists.ozlabs.org, linux-btrfs@vger.kernel.org References: <20230807110936.21819-1-zhengqi.arch@bytedance.com> <20230807110936.21819-44-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230807110936.21819-44-zhengqi.arch@bytedance.com> X-Operating-System: Linux phenom 6.3.0-2-amd64 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org On Mon, Aug 07, 2023 at 07:09:31PM +0800, Qi Zheng wrote: > Currently, the synchronize_shrinkers() is only used by TTM pool. It only > requires that no shrinkers run in parallel. > > After we use RCU+refcount method to implement the lockless slab shrink, > we can not use shrinker_rwsem or synchronize_rcu() to guarantee that all > shrinker invocations have seen an update before freeing memory. > > So we introduce a new pool_shrink_rwsem to implement a private > synchronize_shrinkers(), so as to achieve the same purpose. > > Signed-off-by: Qi Zheng > Reviewed-by: Muchun Song On the 5 drm patches (I counted 2 ttm and 3 drivers) for merging through some other tree (since I'm assuming that's how this will land): Acked-by: Daniel Vetter > --- > drivers/gpu/drm/ttm/ttm_pool.c | 15 +++++++++++++++ > include/linux/shrinker.h | 2 -- > mm/shrinker.c | 15 --------------- > 3 files changed, 15 insertions(+), 17 deletions(-) > > diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c > index c9c9618c0dce..38b4c280725c 100644 > --- a/drivers/gpu/drm/ttm/ttm_pool.c > +++ b/drivers/gpu/drm/ttm/ttm_pool.c > @@ -74,6 +74,7 @@ static struct ttm_pool_type global_dma32_uncached[MAX_ORDER + 1]; > static spinlock_t shrinker_lock; > static struct list_head shrinker_list; > static struct shrinker *mm_shrinker; > +static DECLARE_RWSEM(pool_shrink_rwsem); > > /* Allocate pages of size 1 << order with the given gfp_flags */ > static struct page *ttm_pool_alloc_page(struct ttm_pool *pool, gfp_t gfp_flags, > @@ -317,6 +318,7 @@ static unsigned int ttm_pool_shrink(void) > unsigned int num_pages; > struct page *p; > > + down_read(&pool_shrink_rwsem); > spin_lock(&shrinker_lock); > pt = list_first_entry(&shrinker_list, typeof(*pt), shrinker_list); > list_move_tail(&pt->shrinker_list, &shrinker_list); > @@ -329,6 +331,7 @@ static unsigned int ttm_pool_shrink(void) > } else { > num_pages = 0; > } > + up_read(&pool_shrink_rwsem); > > return num_pages; > } > @@ -572,6 +575,18 @@ void ttm_pool_init(struct ttm_pool *pool, struct device *dev, > } > EXPORT_SYMBOL(ttm_pool_init); > > +/** > + * synchronize_shrinkers - Wait for all running shrinkers to complete. > + * > + * This is useful to guarantee that all shrinker invocations have seen an > + * update, before freeing memory, similar to rcu. > + */ > +static void synchronize_shrinkers(void) > +{ > + down_write(&pool_shrink_rwsem); > + up_write(&pool_shrink_rwsem); > +} > + > /** > * ttm_pool_fini - Cleanup a pool > * > diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h > index c55c07c3f0cb..025c8070dd86 100644 > --- a/include/linux/shrinker.h > +++ b/include/linux/shrinker.h > @@ -103,8 +103,6 @@ struct shrinker *shrinker_alloc(unsigned int flags, const char *fmt, ...); > void shrinker_register(struct shrinker *shrinker); > void shrinker_free(struct shrinker *shrinker); > > -extern void synchronize_shrinkers(void); > - > #ifdef CONFIG_SHRINKER_DEBUG > extern int __printf(2, 3) shrinker_debugfs_rename(struct shrinker *shrinker, > const char *fmt, ...); > diff --git a/mm/shrinker.c b/mm/shrinker.c > index 3ab301ff122d..a27779ed3798 100644 > --- a/mm/shrinker.c > +++ b/mm/shrinker.c > @@ -650,18 +650,3 @@ void shrinker_free(struct shrinker *shrinker) > kfree(shrinker); > } > EXPORT_SYMBOL_GPL(shrinker_free); > - > -/** > - * synchronize_shrinkers - Wait for all running shrinkers to complete. > - * > - * This is equivalent to calling unregister_shrink() and register_shrinker(), > - * but atomically and with less overhead. This is useful to guarantee that all > - * shrinker invocations have seen an update, before freeing memory, similar to > - * rcu. > - */ > -void synchronize_shrinkers(void) > -{ > - down_write(&shrinker_rwsem); > - up_write(&shrinker_rwsem); > -} > -EXPORT_SYMBOL(synchronize_shrinkers); > -- > 2.30.2 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch