All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] mm/vmap: Add a notifier for when we run out of vmap address space
@ 2016-03-17 11:59 ` Chris Wilson
  0 siblings, 0 replies; 27+ messages in thread
From: Chris Wilson @ 2016-03-17 11:59 UTC (permalink / raw)
  To: intel-gfx
  Cc: Chris Wilson, Andrew Morton, David Rientjes, Roman Pen,
	Mel Gorman, linux-mm, linux-kernel

vmaps are temporary kernel mappings that may be of long duration.
Reusing a vmap on an object is preferrable for a driver as the cost of
setting up the vmap can otherwise dominate the operation on the object.
However, the vmap address space is rather limited on 32bit systems and
so we add a notification for vmap pressure in order for the driver to
release any cached vmappings.

The interface is styled after the oom-notifier where the callees are
passed a pointer to an unsigned long counter for them to indicate if they
have freed any space.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Roman Pen <r.peniaev@gmail.com>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
---
 include/linux/vmalloc.h |  4 ++++
 mm/vmalloc.c            | 22 ++++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index d1f1d338af20..edd676b8e112 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -187,4 +187,8 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
 #define VMALLOC_TOTAL 0UL
 #endif
 
+struct notitifer_block;
+int register_vmap_purge_notifier(struct notifier_block *nb);
+int unregister_vmap_purge_notifier(struct notifier_block *nb);
+
 #endif /* _LINUX_VMALLOC_H */
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index fb42a5bffe47..fd2ca94c2732 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -21,6 +21,7 @@
 #include <linux/debugobjects.h>
 #include <linux/kallsyms.h>
 #include <linux/list.h>
+#include <linux/notifier.h>
 #include <linux/rbtree.h>
 #include <linux/radix-tree.h>
 #include <linux/rcupdate.h>
@@ -344,6 +345,8 @@ static void __insert_vmap_area(struct vmap_area *va)
 
 static void purge_vmap_area_lazy(void);
 
+static BLOCKING_NOTIFIER_HEAD(vmap_notify_list);
+
 /*
  * Allocate a region of KVA of the specified size and alignment, within the
  * vstart and vend.
@@ -356,6 +359,7 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
 	struct vmap_area *va;
 	struct rb_node *n;
 	unsigned long addr;
+	unsigned long freed;
 	int purged = 0;
 	struct vmap_area *first;
 
@@ -468,6 +472,12 @@ overflow:
 		purged = 1;
 		goto retry;
 	}
+	freed = 0;
+	blocking_notifier_call_chain(&vmap_notify_list, 0, &freed);
+	if (freed > 0) {
+		purged = 0;
+		goto retry;
+	}
 	if (printk_ratelimit())
 		pr_warn("vmap allocation for size %lu failed: "
 			"use vmalloc=<size> to increase size.\n", size);
@@ -475,6 +485,18 @@ overflow:
 	return ERR_PTR(-EBUSY);
 }
 
+int register_vmap_purge_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_register(&vmap_notify_list, nb);
+}
+EXPORT_SYMBOL_GPL(register_vmap_purge_notifier);
+
+int unregister_vmap_purge_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_unregister(&vmap_notify_list, nb);
+}
+EXPORT_SYMBOL_GPL(unregister_vmap_purge_notifier);
+
 static void __free_vmap_area(struct vmap_area *va)
 {
 	BUG_ON(RB_EMPTY_NODE(&va->rb_node));
-- 
2.8.0.rc3

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

end of thread, other threads:[~2016-03-29 12:56 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-17 11:59 [PATCH 1/2] mm/vmap: Add a notifier for when we run out of vmap address space Chris Wilson
2016-03-17 11:59 ` Chris Wilson
2016-03-17 11:59 ` Chris Wilson
2016-03-17 11:59 ` [PATCH 2/2] drm/i915/shrinker: Hook up vmap allocation failure notifier Chris Wilson
2016-03-17 11:59   ` Chris Wilson
2016-03-17 12:37 ` [PATCH 1/2] mm/vmap: Add a notifier for when we run out of vmap address space Roman Peniaev
2016-03-17 12:37   ` Roman Peniaev
2016-03-17 12:57   ` Chris Wilson
2016-03-17 12:57     ` Chris Wilson
2016-03-17 13:21     ` Roman Peniaev
2016-03-17 13:21       ` Roman Peniaev
2016-03-17 13:30       ` Chris Wilson
2016-03-17 13:30         ` Chris Wilson
2016-03-17 13:34 ` [PATCH v2] " Chris Wilson
2016-03-17 13:34   ` Chris Wilson
2016-03-17 13:34   ` Chris Wilson
2016-03-17 13:41   ` Chris Wilson
2016-03-17 13:41     ` Chris Wilson
2016-03-28 23:15     ` Andrew Morton
2016-03-28 23:15       ` Andrew Morton
2016-03-29  8:16       ` [PATCH v3] " Chris Wilson
2016-03-29  8:16         ` Chris Wilson
2016-03-29  8:16         ` Chris Wilson
2016-03-18  7:03 ` ✗ Fi.CI.BAT: failure for series starting with [v2] mm/vmap: Add a notifier for when we run out of vmap address space (rev2) Patchwork
2016-03-29  8:34 ` ✗ Fi.CI.BAT: failure for series starting with [v3] mm/vmap: Add a notifier for when we run out of vmap address space (rev3) Patchwork
2016-03-29 12:51   ` Marius Vlad
2016-03-29 12:56     ` Chris Wilson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.