Skip to content

Commit 7837845

Browse files
authored
Linux: Set spl_kmem_cache_slab_limit when page size !4K
For small objects the kernel's slab implementation is very fast and space efficient. However, as the allocation size increases to require multiple pages performance suffers. The SPL kmem cache allocator was designed to better handle these large allocation sizes. Therefore, on Linux the kmem_cache_* compatibility wrappers prefer to use the kernel's slab allocator for small objects and the custom SPL kmem cache allocator for larger objects. This logic was effectively disabled for all architectures using a non-4K page size which caused all kmem caches to only use the SPL implementation. Functionally this is fine, but the SPL code which calculates the target number of objects per-slab does not take in to account that __vmalloc() always returns page-aligned memory. This can result in a massive amount of wasted space when allocating tiny objects on a platform using large pages (64k). To resolve this issue we set the spl_kmem_cache_slab_limit cutoff to 16K for all architectures. This particular change does not attempt to update the logic used to calculate the optimal number of pages per slab. This remains an issue which should be addressed in a future change. Reviewed-by: Matthew Ahrens <[email protected]> Reviewed-by: Tony Nguyen <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #12152 Closes #11429 Closes #11574 Closes #12150
1 parent 739cfb9 commit 7837845

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

module/os/linux/spl/spl-kmem-cache.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,10 @@ MODULE_PARM_DESC(spl_kmem_cache_max_size, "Maximum size of slab in MB");
100100
* For small objects the Linux slab allocator should be used to make the most
101101
* efficient use of the memory. However, large objects are not supported by
102102
* the Linux slab and therefore the SPL implementation is preferred. A cutoff
103-
* of 16K was determined to be optimal for architectures using 4K pages.
103+
* of 16K was determined to be optimal for architectures using 4K pages and
104+
* to also work well on architecutres using larger 64K page sizes.
104105
*/
105-
#if PAGE_SIZE == 4096
106106
unsigned int spl_kmem_cache_slab_limit = 16384;
107-
#else
108-
unsigned int spl_kmem_cache_slab_limit = 0;
109-
#endif
110107
module_param(spl_kmem_cache_slab_limit, uint, 0644);
111108
MODULE_PARM_DESC(spl_kmem_cache_slab_limit,
112109
"Objects less than N bytes use the Linux slab");

0 commit comments

Comments
 (0)