From: Qi Zheng <zhengqi.arch@bytedance.com>
To: "Christian König" <christian.koenig@amd.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	dri-devel@lists.freedesktop.org, linux-fsdevel@vger.kernel.org,
	Muchun Song <songmuchun@bytedance.com>,
	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, joel@joelfernandes.org
Subject: Re: [PATCH 4/5] drm/ttm: introduce pool_shrink_rwsem
Date: Wed, 16 Aug 2023 17:20:32 +0800	[thread overview]
Message-ID: <a0238a1b-8be8-85c7-5839-d0a9e36206b2@bytedance.com> (raw)
In-Reply-To: <01213258-6e27-f304-b420-f3d915e54ed1@amd.com>
Hi Christian,
On 2023/8/16 17:14, Christian König wrote:
> Am 16.08.23 um 10:34 schrieb Qi Zheng:
>> 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 <zhengqi.arch@bytedance.com>
>> Reviewed-by: Muchun Song <songmuchun@bytedance.com>
>> ---
>>   drivers/gpu/drm/ttm/ttm_pool.c | 15 +++++++++++++++
>>   include/linux/shrinker.h       |  1 -
>>   mm/shrinker.c                  | 15 ---------------
>>   3 files changed, 15 insertions(+), 16 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/ttm/ttm_pool.c 
>> b/drivers/gpu/drm/ttm/ttm_pool.c
>> index cddb9151d20f..713b1c0a70e1 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)
> 
> Please rename that function to ttm_pool_synchronize_shrinkers().
OK, will do.
> 
> With that done feel free to add Reviewed-by: Christian König 
> <christian.koenig@amd.com>
> 
Thanks,
Qi
> Regards,
> Christian.
> 
>> +{
>> +    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 8dc15aa37410..6b5843c3b827 100644
>> --- a/include/linux/shrinker.h
>> +++ b/include/linux/shrinker.h
>> @@ -103,7 +103,6 @@ extern int __printf(2, 3) register_shrinker(struct 
>> shrinker *shrinker,
>>                           const char *fmt, ...);
>>   extern void unregister_shrinker(struct shrinker *shrinker);
>>   extern void free_prealloced_shrinker(struct shrinker *shrinker);
>> -extern void synchronize_shrinkers(void);
>>   #ifdef CONFIG_SHRINKER_DEBUG
>>   extern int __printf(2, 3) shrinker_debugfs_rename(struct shrinker 
>> *shrinker,
>> diff --git a/mm/shrinker.c b/mm/shrinker.c
>> index 043c87ccfab4..a16cd448b924 100644
>> --- a/mm/shrinker.c
>> +++ b/mm/shrinker.c
>> @@ -692,18 +692,3 @@ void unregister_shrinker(struct shrinker *shrinker)
>>       shrinker->nr_deferred = NULL;
>>   }
>>   EXPORT_SYMBOL(unregister_shrinker);
>> -
>> -/**
>> - * 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);
> 
next prev parent reply	other threads:[~2023-08-16  9:22 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-16  8:34 [PATCH 0/5] use refcount+RCU method to implement lockless slab shrink (part 1) Qi Zheng
2023-08-16  8:34 ` [PATCH 1/5] mm: move some shrinker-related function declarations to mm/internal.h Qi Zheng
2023-08-16 13:14   ` kernel test robot
2023-08-16 13:57   ` kernel test robot
2023-08-16 15:01   ` kernel test robot
2023-08-17  3:04     ` Qi Zheng
2023-08-16  8:34 ` [PATCH 2/5] mm: vmscan: move shrinker-related code into a separate file Qi Zheng
2023-08-16  8:34 ` [PATCH 3/5] mm: shrinker: remove redundant shrinker_rwsem in debugfs operations Qi Zheng
2023-08-16  8:34 ` [PATCH 4/5] drm/ttm: introduce pool_shrink_rwsem Qi Zheng
2023-08-16  9:14   ` Christian König
2023-08-16  9:20     ` Qi Zheng [this message]
2023-08-16  8:34 ` [PATCH 5/5] mm: shrinker: add a secondary array for shrinker_info::{map, nr_deferred} Qi Zheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox
  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):
  git send-email \
    --in-reply-to=a0238a1b-8be8-85c7-5839-d0a9e36206b2@bytedance.com \
    --to=zhengqi.arch@bytedance.com \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=cel@kernel.org \
    --cc=christian.koenig@amd.com \
    --cc=david@fromorbit.com \
    --cc=djwong@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=joel@joelfernandes.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@linux.dev \
    --cc=paulmck@kernel.org \
    --cc=roman.gushchin@linux.dev \
    --cc=senozhatsky@chromium.org \
    --cc=songmuchun@bytedance.com \
    --cc=steven.price@arm.com \
    --cc=tkhai@ya.ru \
    --cc=tytso@mit.edu \
    --cc=vbabka@suse.cz \
    --cc=yujie.liu@intel.com \
    /path/to/YOUR_REPLY
  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
  Be sure your reply has a Subject: header at the top and a blank line
  before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).