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 smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8D63FEE49B0 for ; Tue, 22 Aug 2023 13:56:30 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 039B281332; Tue, 22 Aug 2023 13:56:30 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 039B281332 Authentication-Results: smtp1.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.a=rsa-sha256 header.s=google header.b=OvQvaauB X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id u_Dwyl8ImuT4; Tue, 22 Aug 2023 13:56:29 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 7232E8139C; Tue, 22 Aug 2023 13:56:28 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 7232E8139C Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 4B76DC0071; Tue, 22 Aug 2023 13:56:28 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7A029C0032 for ; Tue, 22 Aug 2023 13:56:26 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 47FAA813A1 for ; Tue, 22 Aug 2023 13:56:26 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 47FAA813A1 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9s155IjQVfH2 for ; Tue, 22 Aug 2023 13:56:25 +0000 (UTC) Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by smtp1.osuosl.org (Postfix) with ESMTPS id C3A4D8139C for ; Tue, 22 Aug 2023 13:56:24 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org C3A4D8139C Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3175e1bb38cso748732f8f.1 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=M+UKHvrsiUqd8YIhXL07tWWv/NmP+Sa5DYKVWQ3yHD+XFE7GzmKMzbW3/iMP59L/ED IVSmiougzlVUOTHSrOg75fgokP8aeMt+j8/lEapRng6zf8Xp+5Hjo9xlvurmIca4BfuT YS6uI+OLYtw2g5Fi5bpLr5QjrnBWVeZPpKRM2bKjPYZOdQAIribGh1h3um0JVzJbwIFS SsAcV8sZd36FsH1k76F04IJlC5lAeNgpWdz/E7cc9uMOS/g2d5SJ5O63hiO6a+X8UEsV yJkG/c78XhH6QEhAB3BG/WIa53X1Cmp83Hbzsmhki79TIe6AlOs7n/P/q97nq+m04kV3 /jIQ== X-Gm-Message-State: AOJu0YyA4UgxWptRBGyFX/m6BJZqqft5kKghLp7nR0iROO3e9yxe2Z2H bBfzi0HQSh0QwLj2Ua8opdhWcQ== 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 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-Disposition: inline In-Reply-To: <20230807110936.21819-44-zhengqi.arch@bytedance.com> X-Operating-System: Linux phenom 6.3.0-2-amd64 Cc: kvm@vger.kernel.org, djwong@kernel.org, roman.gushchin@linux.dev, david@fromorbit.com, dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org, linux-mm@kvack.org, dm-devel@redhat.com, linux-mtd@lists.infradead.org, cel@kernel.org, x86@kernel.org, steven.price@arm.com, cluster-devel@redhat.com, simon.horman@corigine.com, xen-devel@lists.xenproject.org, linux-ext4@vger.kernel.org, paulmck@kernel.org, linux-arm-msm@vger.kernel.org, linux-nfs@vger.kernel.org, rcu@vger.kernel.org, linux-bcache@vger.kernel.org, dlemoal@kernel.org, Muchun Song , yujie.liu@intel.com, vbabka@suse.cz, linux-raid@vger.kernel.org, brauner@kernel.org, tytso@mit.edu, gregkh@linuxfoundation.org, muchun.song@linux.dev, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, senozhatsky@chromium.org, netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org, akpm@linux-foundation.org, linux-erofs@lists.ozlabs.org, linux-btrfs@vger.kernel.org, tkhai@ya.ru X-BeenThere: virtualization@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux virtualization List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: virtualization-bounces@lists.linux-foundation.org Sender: "Virtualization" 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 _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization