dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] mm/vmscan: add sync_shrinkers function
@ 2021-04-15 11:56 Christian König
  2021-04-15 11:56 ` [PATCH 2/2] drm/ttm: optimize the pool shrinker a bit v2 Christian König
  2021-04-15 13:23 ` [PATCH 1/2] mm/vmscan: add sync_shrinkers function Daniel Vetter
  0 siblings, 2 replies; 8+ messages in thread
From: Christian König @ 2021-04-15 11:56 UTC (permalink / raw)
  To: linux-mm, linux-kernel, dri-devel; +Cc: akpm, ray.huang, vbabka

To be able to switch to a spinlock and reduce lock contention in the TTM
shrinker we don't want to hold a mutex while unmapping and freeing pages
from the pool.

But then we somehow need to prevent a race between (for example) the shrinker
trying to free pages and hotplug trying to remove the device which those pages
belong to.

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

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 include/linux/shrinker.h |  1 +
 mm/vmscan.c              | 10 ++++++++++
 2 files changed, 11 insertions(+)

diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h
index 0f80123650e2..6b75dc372fce 100644
--- a/include/linux/shrinker.h
+++ b/include/linux/shrinker.h
@@ -92,4 +92,5 @@ extern void register_shrinker_prepared(struct shrinker *shrinker);
 extern int register_shrinker(struct shrinker *shrinker);
 extern void unregister_shrinker(struct shrinker *shrinker);
 extern void free_prealloced_shrinker(struct shrinker *shrinker);
+extern void sync_shrinkers(void);
 #endif
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 562e87cbd7a1..46cd9c215d73 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -408,6 +408,16 @@ void unregister_shrinker(struct shrinker *shrinker)
 }
 EXPORT_SYMBOL(unregister_shrinker);
 
+/**
+ * sync_shrinker - Wait for all running shrinkers to complete.
+ */
+void sync_shrinkers(void)
+{
+	down_write(&shrinker_rwsem);
+	up_write(&shrinker_rwsem);
+}
+EXPORT_SYMBOL(sync_shrinkers);
+
 #define SHRINK_BATCH 128
 
 static unsigned long do_shrink_slab(struct shrink_control *shrinkctl,
-- 
2.25.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 8+ messages in thread
* Adding sync_shrinkers function for TTM pool optimization
@ 2021-08-20 12:05 Christian König
  2021-08-20 12:05 ` [PATCH 2/2] drm/ttm: optimize the pool shrinker a bit v2 Christian König
  0 siblings, 1 reply; 8+ messages in thread
From: Christian König @ 2021-08-20 12:05 UTC (permalink / raw)
  To: akpm; +Cc: dri-devel, daniel

Hi Andrew,

Daniel suggested that I ping you once more about this.

Basically we want to add a barrier function to make sure that our TTM pool shrinker is not freeing up pages from a device while the device is being unplugged.

Currently we are having a global mutex to serialize all of this, but this caused contention for unmapping the freed pages in the IOMMU.

We just need your Acked-by and I hope my explanation is now more understandable than the last time.

Cheers,
Christian.



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-08-20 12:05 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-15 11:56 [PATCH 1/2] mm/vmscan: add sync_shrinkers function Christian König
2021-04-15 11:56 ` [PATCH 2/2] drm/ttm: optimize the pool shrinker a bit v2 Christian König
2021-04-15 14:33   ` Huang Rui
2021-04-15 20:33   ` Andrew Morton
2021-04-16  7:08     ` Christian König
2021-04-26 11:15       ` Christian König
2021-04-15 13:23 ` [PATCH 1/2] mm/vmscan: add sync_shrinkers function Daniel Vetter
2021-08-20 12:05 Adding sync_shrinkers function for TTM pool optimization Christian König
2021-08-20 12:05 ` [PATCH 2/2] drm/ttm: optimize the pool shrinker a bit v2 Christian König

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).