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
This commit is contained in:
Dmitry Chagin 2023-04-02 11:20:07 +03:00
parent 7ee18f5aad
commit 7f72324346
2 changed files with 6 additions and 4 deletions

View File

@ -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);

View File

@ -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 */
};
/*