diff options
author | Dmitry Chagin <dchagin@FreeBSD.org> | 2023-04-02 08:20:07 +0000 |
---|---|---|
committer | Dmitry Chagin <dchagin@FreeBSD.org> | 2023-04-02 08:20:07 +0000 |
commit | 7f72324346ea154a92671fc913dbe82c0287501a (patch) | |
tree | 1fa35f3f2186db1ebe8dd2be99c363bf0c889643 /sys/fs | |
parent | 7ee18f5aada07f03433504545c1b7bed91cbda82 (diff) | |
download | src-7f72324346ea154a92671fc913dbe82c0287501a.tar.gz src-7f72324346ea154a92671fc913dbe82c0287501a.zip |
pseudofs: Microoptimize struct pfs_node
Since 81167243b the size of struct pfs_node is 280 bytes, so the kernel
memory allocator takes memory from 384 bytes sized bucket. However, the
length of the node name is mostly short, e.g., for Linux emulation layer
it is up to 16 bytes. The size of struct pfs_node w/o pfs_name is 152
bytes, i.e., we have 104 bytes left to fit the node name into the 256
bytes-sized bucket.
Reviewed by: des
Differential revision: https://reviews.freebsd.org/D39381
MFC after: 1 month
Diffstat (limited to 'sys/fs')
-rw-r--r-- | sys/fs/pseudofs/pseudofs.c | 8 | ||||
-rw-r--r-- | sys/fs/pseudofs/pseudofs.h | 2 |
2 files changed, 6 insertions, 4 deletions
diff --git a/sys/fs/pseudofs/pseudofs.c b/sys/fs/pseudofs/pseudofs.c index 44473a926182..29071b34bd06 100644 --- a/sys/fs/pseudofs/pseudofs.c +++ b/sys/fs/pseudofs/pseudofs.c @@ -72,18 +72,20 @@ pfs_alloc_node_flags(struct pfs_info *pi, const char *name, pfs_type_t type, int { struct pfs_node *pn; int malloc_flags; + size_t len; - KASSERT(strlen(name) < PFS_NAMELEN, + len = strlen(name); + KASSERT(len < PFS_NAMELEN, ("%s(): node name is too long", __func__)); if (flags & PFS_NOWAIT) malloc_flags = M_NOWAIT | M_ZERO; else malloc_flags = M_WAITOK | M_ZERO; - pn = malloc(sizeof *pn, M_PFSNODES, malloc_flags); + pn = malloc(sizeof(*pn) + len + 1, M_PFSNODES, malloc_flags); if (pn == NULL) return (NULL); mtx_init(&pn->pn_mutex, "pfs_node", NULL, MTX_DEF | MTX_DUPOK); - strlcpy(pn->pn_name, name, sizeof pn->pn_name); + memcpy(pn->pn_name, name, len); pn->pn_type = type; pn->pn_info = pi; return (pn); diff --git a/sys/fs/pseudofs/pseudofs.h b/sys/fs/pseudofs/pseudofs.h index 158f74575e33..e355e5f5609f 100644 --- a/sys/fs/pseudofs/pseudofs.h +++ b/sys/fs/pseudofs/pseudofs.h @@ -219,7 +219,6 @@ struct pfs_info { * is not enforcable by WITNESS. */ struct pfs_node { - char pn_name[PFS_NAMELEN]; pfs_type_t pn_type; int pn_flags; struct mtx pn_mutex; @@ -240,6 +239,7 @@ struct pfs_node { struct pfs_node *pn_nodes; /* (o) */ struct pfs_node *pn_last_node; /* (o) */ struct pfs_node *pn_next; /* (p) */ + char pn_name[]; /* Keep it last */ }; /* |