Message ID | 20230727080502.77895-1-zhengqi.arch@bytedance.com |
---|---|
Headers | show |
Series | use refcount+RCU method to implement lockless slab shrink | expand |
On 7/28/23 07:59, Dave Chinner wrote: > On Thu, Jul 27, 2023 at 07:20:46PM +0900, Damien Le Moal wrote: >> On 7/27/23 17:55, Qi Zheng wrote: >>>>> goto err; >>>>> } >>>>> + zmd->mblk_shrinker->count_objects = dmz_mblock_shrinker_count; >>>>> + zmd->mblk_shrinker->scan_objects = dmz_mblock_shrinker_scan; >>>>> + zmd->mblk_shrinker->seeks = DEFAULT_SEEKS; >>>>> + zmd->mblk_shrinker->private_data = zmd; >>>>> + >>>>> + shrinker_register(zmd->mblk_shrinker); >>>> >>>> I fail to see how this new shrinker API is better... Why isn't there a >>>> shrinker_alloc_and_register() function ? That would avoid adding all this code >>>> all over the place as the new API call would be very similar to the current >>>> shrinker_register() call with static allocation. >>> >>> In some registration scenarios, memory needs to be allocated in advance. >>> So we continue to use the previous prealloc/register_prepared() >>> algorithm. The shrinker_alloc_and_register() is just a helper function >>> that combines the two, and this increases the number of APIs that >>> shrinker exposes to the outside, so I choose not to add this helper. >> >> And that results in more code in many places instead of less code + a simple >> inline helper in the shrinker header file... > > It's not just a "simple helper" - it's a function that has to take 6 > or 7 parameters with a return value that must be checked and > handled. > > This was done in the first versions of the patch set - the amount of > code in each caller does not go down and, IMO, was much harder to > read and determine "this is obviously correct" that what we have > now. > >> So not adding that super simple >> helper is not exactly the best choice in my opinion. > > Each to their own - I much prefer the existing style/API over having > to go look up a helper function every time I want to check some > random shrinker has been set up correctly.... OK. All fair points.
On Thu, Jul 27, 2023 at 04:04:17PM +0800, Qi Zheng wrote: > The debugfs_remove_recursive() will wait for debugfs_file_put() to return, > so the shrinker will not be freed when doing debugfs operations (such as > shrinker_debugfs_count_show() and shrinker_debugfs_scan_write()), so there > is no need to hold shrinker_rwsem during debugfs operations. > > Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com> > Reviewed-by: Muchun Song <songmuchun@bytedance.com> > --- > mm/shrinker_debug.c | 14 -------------- > 1 file changed, 14 deletions(-) > > diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c > index 3ab53fad8876..f1becfd45853 100644 > --- a/mm/shrinker_debug.c > +++ b/mm/shrinker_debug.c > @@ -55,11 +55,6 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v) > if (!count_per_node) > return -ENOMEM; > > - ret = down_read_killable(&shrinker_rwsem); > - if (ret) { > - kfree(count_per_node); > - return ret; > - } > rcu_read_lock(); Hi Qi Zheng, As can be seen in the next hunk, this function returns 'ret'. However, with this change 'ret' is uninitialised unless signal_pending() returns non-zero in the while loop below. This is flagged in a clan-16 W=1 build. mm/shrinker_debug.c:87:11: warning: variable 'ret' is used uninitialized whenever 'do' loop exits because its condition is false [-Wsometimes-uninitialized] } while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ mm/shrinker_debug.c:92:9: note: uninitialized use occurs here return ret; ^~~ mm/shrinker_debug.c:87:11: note: remove the condition if it is always true } while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 mm/shrinker_debug.c:77:7: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] if (!memcg_aware) { ^~~~~~~~~~~~ mm/shrinker_debug.c:92:9: note: uninitialized use occurs here return ret; ^~~ mm/shrinker_debug.c:77:3: note: remove the 'if' if its condition is always false if (!memcg_aware) { ^~~~~~~~~~~~~~~~~~~ mm/shrinker_debug.c:52:9: note: initialize the variable 'ret' to silence this warning int ret, nid; ^ = 0 > > memcg_aware = shrinker->flags & SHRINKER_MEMCG_AWARE; > @@ -92,7 +87,6 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v) > } while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL); > > rcu_read_unlock(); > - up_read(&shrinker_rwsem); > > kfree(count_per_node); > return ret; ...
Hi Simon, On 2023/7/28 16:13, Simon Horman wrote: > On Thu, Jul 27, 2023 at 04:04:17PM +0800, Qi Zheng wrote: >> The debugfs_remove_recursive() will wait for debugfs_file_put() to return, >> so the shrinker will not be freed when doing debugfs operations (such as >> shrinker_debugfs_count_show() and shrinker_debugfs_scan_write()), so there >> is no need to hold shrinker_rwsem during debugfs operations. >> >> Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com> >> Reviewed-by: Muchun Song <songmuchun@bytedance.com> >> --- >> mm/shrinker_debug.c | 14 -------------- >> 1 file changed, 14 deletions(-) >> >> diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c >> index 3ab53fad8876..f1becfd45853 100644 >> --- a/mm/shrinker_debug.c >> +++ b/mm/shrinker_debug.c >> @@ -55,11 +55,6 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v) >> if (!count_per_node) >> return -ENOMEM; >> >> - ret = down_read_killable(&shrinker_rwsem); >> - if (ret) { >> - kfree(count_per_node); >> - return ret; >> - } >> rcu_read_lock(); > > Hi Qi Zheng, > > As can be seen in the next hunk, this function returns 'ret'. > However, with this change 'ret' is uninitialised unless > signal_pending() returns non-zero in the while loop below. Thanks for your feedback, the 'ret' should be initialized to 0, will fix it. Thanks, Qi > > This is flagged in a clan-16 W=1 build. > > mm/shrinker_debug.c:87:11: warning: variable 'ret' is used uninitialized whenever 'do' loop exits because its condition is false [-Wsometimes-uninitialized] > } while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > mm/shrinker_debug.c:92:9: note: uninitialized use occurs here > return ret; > ^~~ > mm/shrinker_debug.c:87:11: note: remove the condition if it is always true > } while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 1 > mm/shrinker_debug.c:77:7: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] > if (!memcg_aware) { > ^~~~~~~~~~~~ > mm/shrinker_debug.c:92:9: note: uninitialized use occurs here > return ret; > ^~~ > mm/shrinker_debug.c:77:3: note: remove the 'if' if its condition is always false > if (!memcg_aware) { > ^~~~~~~~~~~~~~~~~~~ > mm/shrinker_debug.c:52:9: note: initialize the variable 'ret' to silence this warning > int ret, nid; > ^ > = 0 > >> >> memcg_aware = shrinker->flags & SHRINKER_MEMCG_AWARE; >> @@ -92,7 +87,6 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v) >> } while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL); >> >> rcu_read_unlock(); >> - up_read(&shrinker_rwsem); >> >> kfree(count_per_node); >> return ret; > > ...