summaryrefslogtreecommitdiffstats
path: root/module/spl
diff options
context:
space:
mode:
authorUbuntu <[email protected]>2016-10-28 20:56:38 +0000
committerBrian Behlendorf <[email protected]>2016-11-02 10:34:19 -0700
commit1b457bcbe502eb29333a34b0518c1dca0e2ee974 (patch)
tree6f1bf489e55c479b950c896dd372d2247b408174 /module/spl
parent7b25c48e6ec6aa55bd5fead2d57ade01bfb0777b (diff)
Fix vmem_size()
Add a minimal implementation of vmem_size() which accounts for the virtual memory usage of the SPL's kmem cache. This functionality is only useful on 32-bit systems with a small virtual address space. The following assumptions are made: 1) The major SPL consumer of virtual memory is the kmem cache. 2) Memory allocated with vmem_alloc() is short lived and can be ignored. 3) Allow a 4MB floor as a generous pad given normal consumption. 4) The spl_kmem_cache_sem only contends with cache create/destroy. Signed-off-by: Brian Behlendorf <[email protected]>
Diffstat (limited to 'module/spl')
-rw-r--r--module/spl/spl-vmem.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/module/spl/spl-vmem.c b/module/spl/spl-vmem.c
index e177988a7..dd10607dc 100644
--- a/module/spl/spl-vmem.c
+++ b/module/spl/spl-vmem.c
@@ -24,6 +24,7 @@
#include <sys/debug.h>
#include <sys/vmem.h>
+#include <sys/kmem_cache.h>
#include <linux/mm_compat.h>
#include <linux/module.h>
@@ -36,14 +37,39 @@ EXPORT_SYMBOL(zio_alloc_arena);
vmem_t *zio_arena = NULL;
EXPORT_SYMBOL(zio_arena);
+#define VMEM_FLOOR_SIZE (4 * 1024 * 1024) /* 4MB floor */
+
+/*
+ * Return approximate virtual memory usage based on these assumptions:
+ *
+ * 1) The major SPL consumer of virtual memory is the kmem cache.
+ * 2) Memory allocated with vmem_alloc() is short lived and can be ignored.
+ * 3) Allow a 4MB floor as a generous pad given normal consumption.
+ * 4) The spl_kmem_cache_sem only contends with cache create/destroy.
+ */
size_t
vmem_size(vmem_t *vmp, int typemask)
{
- ASSERT3P(vmp, ==, NULL);
- ASSERT3S(typemask & VMEM_ALLOC, ==, VMEM_ALLOC);
- ASSERT3S(typemask & VMEM_FREE, ==, VMEM_FREE);
+ spl_kmem_cache_t *skc;
+ size_t alloc = VMEM_FLOOR_SIZE;
+
+ if ((typemask & VMEM_ALLOC) && (typemask & VMEM_FREE))
+ return (VMALLOC_TOTAL);
+
+
+ down_read(&spl_kmem_cache_sem);
+ list_for_each_entry(skc, &spl_kmem_cache_list, skc_list) {
+ if (skc->skc_flags & KMC_VMEM)
+ alloc += skc->skc_slab_size * skc->skc_slab_total;
+ }
+ up_read(&spl_kmem_cache_sem);
- return (VMALLOC_TOTAL);
+ if (typemask & VMEM_ALLOC)
+ return (MIN(alloc, VMALLOC_TOTAL));
+ else if (typemask & VMEM_FREE)
+ return (MAX(VMALLOC_TOTAL - alloc, 0));
+ else
+ return (0);
}
EXPORT_SYMBOL(vmem_size);