summary refs log tree commit diff
path: root/mm/vmscan.c
diff options
context:
space:
mode:
authorChristian König <ckoenig.leichtzumerken@gmail.com>2021-04-15 13:56:23 +0200
committerChristian König <christian.koenig@amd.com>2021-08-27 09:55:15 +0200
commit880121be1179a0db3eb4fdb198108d9475b8be4c (patch)
tree60547e431f158d6a5cf33d96f60dab470253486e /mm/vmscan.c
parent28210a3f5412c7dfe93cf1579c512fd30aef727e (diff)
downloadlinux-880121be1179a0db3eb4fdb198108d9475b8be4c.tar.gz
mm/vmscan: add sync_shrinkers function v3
While unplugging a device the TTM shrinker implementation
needs a barrier to make sure that all concurrent shrink
operations are done and no other CPU is referring to a
device specific pool any more.

Taking and releasing the shrinker semaphore on the write
side after unmapping and freeing all pages from the device
pool should make sure that no shrinker is running in
paralell.

This allows us to avoid the contented mutex in the TTM pool
implementation for every alloc/free operation.

v2: rework the commit message to make clear why we need this
v3: rename the function and add more doc as suggested by Daniel

Signed-off-by: Christian König <christian.koenig@amd.com>
Acked-by: Huang Rui <ray.huang@amd.com>
Acked-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210820120528.81114-2-christian.koenig@amd.com
Diffstat (limited to 'mm/vmscan.c')
-rw-r--r--mm/vmscan.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 4620df62f0ff..5d22a63472f0 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -638,6 +638,21 @@ void unregister_shrinker(struct shrinker *shrinker)
 }
 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);
+
 #define SHRINK_BATCH 128
 
 static unsigned long do_shrink_slab(struct shrink_control *shrinkctl,