summaryrefslogtreecommitdiffstats
path: root/module/zfs
diff options
context:
space:
mode:
authorMateusz Guzik <[email protected]>2021-04-17 21:36:04 +0200
committerBrian Behlendorf <[email protected]>2021-04-19 15:22:58 -0700
commit14a1980b35c6ecc07defedf71e26562c2c8d1de6 (patch)
tree196026c80f34c5ab741799c1a818fbd61fc7b4dc /module/zfs
parent9747310cc13d7bda1af44c7611c6b2ff236f55ac (diff)
Combine zio caches if possible
This deduplicates 2 sets of caches which use the same allocation size. Memory savings fluctuate a lot, one sample result is FreeBSD running "make buildworld" saving ~180MB RAM in reduced page count associated with zio caches. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Mateusz Guzik <[email protected]> Closes #11877
Diffstat (limited to 'module/zfs')
-rw-r--r--module/zfs/zio.c74
1 files changed, 50 insertions, 24 deletions
diff --git a/module/zfs/zio.c b/module/zfs/zio.c
index 5f56f67ff..87ccb6861 100644
--- a/module/zfs/zio.c
+++ b/module/zfs/zio.c
@@ -205,6 +205,19 @@ zio_init(void)
if (align != 0) {
char name[36];
+ if (cflags == data_cflags) {
+ /*
+ * Resulting kmem caches would be identical.
+ * Save memory by creating only one.
+ */
+ (void) snprintf(name, sizeof (name),
+ "zio_buf_comb_%lu", (ulong_t)size);
+ zio_buf_cache[c] = kmem_cache_create(name,
+ size, align, NULL, NULL, NULL, NULL, NULL,
+ cflags);
+ zio_data_buf_cache[c] = zio_buf_cache[c];
+ continue;
+ }
(void) snprintf(name, sizeof (name), "zio_buf_%lu",
(ulong_t)size);
zio_buf_cache[c] = kmem_cache_create(name, size,
@@ -235,37 +248,50 @@ zio_init(void)
void
zio_fini(void)
{
- size_t c;
- kmem_cache_t *last_cache = NULL;
- kmem_cache_t *last_data_cache = NULL;
+ size_t n = SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT;
- for (c = 0; c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT; c++) {
-#ifdef _ILP32
- /*
- * Cache size limited to 1M on 32-bit platforms until ARC
- * buffers no longer require virtual address space.
- */
- if (((c + 1) << SPA_MINBLOCKSHIFT) > zfs_max_recordsize)
- break;
-#endif
#if defined(ZFS_DEBUG) && !defined(_KERNEL)
- if (zio_buf_cache_allocs[c] != zio_buf_cache_frees[c])
+ for (size_t i = 0; i < n; i++) {
+ if (zio_buf_cache_allocs[i] != zio_buf_cache_frees[i])
(void) printf("zio_fini: [%d] %llu != %llu\n",
- (int)((c + 1) << SPA_MINBLOCKSHIFT),
- (long long unsigned)zio_buf_cache_allocs[c],
- (long long unsigned)zio_buf_cache_frees[c]);
+ (int)((i + 1) << SPA_MINBLOCKSHIFT),
+ (long long unsigned)zio_buf_cache_allocs[i],
+ (long long unsigned)zio_buf_cache_frees[i]);
+ }
#endif
- if (zio_buf_cache[c] != last_cache) {
- last_cache = zio_buf_cache[c];
- kmem_cache_destroy(zio_buf_cache[c]);
+
+ /*
+ * The same kmem cache can show up multiple times in both zio_buf_cache
+ * and zio_data_buf_cache. Do a wasteful but trivially correct scan to
+ * sort it out.
+ */
+ for (size_t i = 0; i < n; i++) {
+ kmem_cache_t *cache = zio_buf_cache[i];
+ if (cache == NULL)
+ continue;
+ for (size_t j = i; j < n; j++) {
+ if (cache == zio_buf_cache[j])
+ zio_buf_cache[j] = NULL;
+ if (cache == zio_data_buf_cache[j])
+ zio_data_buf_cache[j] = NULL;
}
- zio_buf_cache[c] = NULL;
+ kmem_cache_destroy(cache);
+ }
- if (zio_data_buf_cache[c] != last_data_cache) {
- last_data_cache = zio_data_buf_cache[c];
- kmem_cache_destroy(zio_data_buf_cache[c]);
+ for (size_t i = 0; i < n; i++) {
+ kmem_cache_t *cache = zio_data_buf_cache[i];
+ if (cache == NULL)
+ continue;
+ for (size_t j = i; j < n; j++) {
+ if (cache == zio_data_buf_cache[j])
+ zio_data_buf_cache[j] = NULL;
}
- zio_data_buf_cache[c] = NULL;
+ kmem_cache_destroy(cache);
+ }
+
+ for (size_t i = 0; i < n; i++) {
+ VERIFY3P(zio_buf_cache[i], ==, NULL);
+ VERIFY3P(zio_data_buf_cache[i], ==, NULL);
}
kmem_cache_destroy(zio_link_cache);