From bb48255cf5eff1c8e2716a13165cde88af185a8a Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Mon, 10 Aug 2020 12:05:55 +0000 Subject: [PATCH] cache: resize struct namecache to a multiply of alignment For example struct namecache on amd64 is 100 bytes, but it has to occupies 104. Use the extra bytes to support longer names. --- sys/kern/vfs_cache.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index 0d176ed8fc51..eddc6e20716f 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -159,6 +159,17 @@ struct namecache_ts { * alignment for everyone. Note this is a nop for 64-bit platforms. */ #define CACHE_ZONE_ALIGNMENT UMA_ALIGNOF(time_t) +#define CACHE_PATH_CUTOFF 39 + +#define CACHE_ZONE_SMALL_SIZE (sizeof(struct namecache) + CACHE_PATH_CUTOFF + 1) +#define CACHE_ZONE_SMALL_TS_SIZE (sizeof(struct namecache_ts) + CACHE_PATH_CUTOFF + 1) +#define CACHE_ZONE_LARGE_SIZE (sizeof(struct namecache) + NAME_MAX + 1) +#define CACHE_ZONE_LARGE_TS_SIZE (sizeof(struct namecache_ts) + NAME_MAX + 1) + +_Static_assert((CACHE_ZONE_SMALL_SIZE % (CACHE_ZONE_ALIGNMENT + 1)) == 0, "bad zone size"); +_Static_assert((CACHE_ZONE_SMALL_TS_SIZE % (CACHE_ZONE_ALIGNMENT + 1)) == 0, "bad zone size"); +_Static_assert((CACHE_ZONE_LARGE_SIZE % (CACHE_ZONE_ALIGNMENT + 1)) == 0, "bad zone size"); +_Static_assert((CACHE_ZONE_LARGE_TS_SIZE % (CACHE_ZONE_ALIGNMENT + 1)) == 0, "bad zone size"); #define nc_vp n_un.nu_vp #define nc_neg n_un.nu_neg @@ -339,8 +350,6 @@ static uma_zone_t __read_mostly cache_zone_small_ts; static uma_zone_t __read_mostly cache_zone_large; static uma_zone_t __read_mostly cache_zone_large_ts; -#define CACHE_PATH_CUTOFF 35 - static struct namecache * cache_alloc(int len, int ts) { @@ -2095,22 +2104,14 @@ nchinit(void *dummy __unused) { u_int i; - cache_zone_small = uma_zcreate("S VFS Cache", - sizeof(struct namecache) + CACHE_PATH_CUTOFF + 1, - NULL, NULL, NULL, NULL, CACHE_ZONE_ALIGNMENT, - UMA_ZONE_ZINIT); - cache_zone_small_ts = uma_zcreate("STS VFS Cache", - sizeof(struct namecache_ts) + CACHE_PATH_CUTOFF + 1, - NULL, NULL, NULL, NULL, CACHE_ZONE_ALIGNMENT, - UMA_ZONE_ZINIT); - cache_zone_large = uma_zcreate("L VFS Cache", - sizeof(struct namecache) + NAME_MAX + 1, - NULL, NULL, NULL, NULL, CACHE_ZONE_ALIGNMENT, - UMA_ZONE_ZINIT); - cache_zone_large_ts = uma_zcreate("LTS VFS Cache", - sizeof(struct namecache_ts) + NAME_MAX + 1, - NULL, NULL, NULL, NULL, CACHE_ZONE_ALIGNMENT, - UMA_ZONE_ZINIT); + cache_zone_small = uma_zcreate("S VFS Cache", CACHE_ZONE_SMALL_SIZE, + NULL, NULL, NULL, NULL, CACHE_ZONE_ALIGNMENT, UMA_ZONE_ZINIT); + cache_zone_small_ts = uma_zcreate("STS VFS Cache", CACHE_ZONE_SMALL_TS_SIZE, + NULL, NULL, NULL, NULL, CACHE_ZONE_ALIGNMENT, UMA_ZONE_ZINIT); + cache_zone_large = uma_zcreate("L VFS Cache", CACHE_ZONE_LARGE_SIZE, + NULL, NULL, NULL, NULL, CACHE_ZONE_ALIGNMENT, UMA_ZONE_ZINIT); + cache_zone_large_ts = uma_zcreate("LTS VFS Cache", CACHE_ZONE_LARGE_TS_SIZE, + NULL, NULL, NULL, NULL, CACHE_ZONE_ALIGNMENT, UMA_ZONE_ZINIT); VFS_SMR_ZONE_SET(cache_zone_small); VFS_SMR_ZONE_SET(cache_zone_small_ts);