From nobody Thu Jun 29 08:19:58 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QsBFp6MSbz4knT1; Thu, 29 Jun 2023 08:19:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QsBFp5YzWz3sWf; Thu, 29 Jun 2023 08:19:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1688026798; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=spX6D6rXptJzzDqCjK2llHo5OJX3f3dOKgQM1iAElL8=; b=fRFjYDqNZbBSsrmg/81SpcHonOrACLiee4i7z3gzmH8rfHk5sPG0H5BZ+Tsdivh4loKxGI R/a0+W0kQkm6U1ry5PEZb2g5CA1uCKCD0FWvU4u3fg1gJJl5lYKBdeRVb68l7g9MA4jTIj HPvkRZ72cyrhmDq11NaHAGVRx4oheBkof8nkKbjSaKVBA1e+8n3U7QlH/yJLi9ukP17QMB EGGiAqg0xt/XZHMUKs2DSjhJZOvu6k7zbcD8qoDlcuS8+xqWyROO8dHpZNIY0ov94wcRm5 nsJ9DzdlgAVEOCJDVZAoj9e1ladPPDjk0cJJcGg5a/TAz/ZcnCuG31U78+vDlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1688026798; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=spX6D6rXptJzzDqCjK2llHo5OJX3f3dOKgQM1iAElL8=; b=yRyWmKdjdF5MLXYQo80O2REMFB0vKVbRuX4w1u/NE/COWxPXBZihkSx2xrpw1FDJ2B+0Vy HSnKJ3C0e53e9/u+Bh8F05gK70o1GaqRcg0TUhUHnZKO3UQrVhT5zM7h3HiCIDkM7/zyca bUGeviHo3ANMVIdsfHhexaT/7Z5vj5msvJMgWcPGJ5+t2995WRd4cfNlnLJ5h+BqB5TmFg NOw8CMIFjdvbKyM+cWK/RovYpAhopdQ7fjhHThxNM7pSg/oEyljjUNbVZu6C/bhQO98bTg 4qui2SWSjBUROADsQdkGhdg+gb6nZvDyrHt8aeeYLRS4pvTsx4vwTjv+J7cRxg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1688026798; a=rsa-sha256; cv=none; b=L9AwA8JuA3WfIN79k9R+VEgzD5zEz4TWvNXB37vo1MODgosHwUQvo631A7GtnBW2EHcBSY bgyZfsTGp2GJ9f+xU12hYgDibIDq86kzyRr41/riSRIMi7kG6k2ZPUReVQpGICWrw48cmh WH/k49cQmT95yfptvzjxPVo/It0U/Ih+fUFKokuMGAjoQSPrXUxGrXPDmsscH+t+F5HDGx Dbc8eIk2gY/qwNntCoBK/gmkxb0pcdCmIufb29zJ7DtDJtc5yBK8vL5aWsAzHoQ+8iy3Fk wb9i9ugOq3KTlgF4wiqJj9tFvzs7CfismgoQwvpI+fUNeMDc0y6Jb7T9g/n5wg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QsBFp3VrMz17q1; Thu, 29 Jun 2023 08:19:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 35T8JwBh074492; Thu, 29 Jun 2023 08:19:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 35T8Jws5074491; Thu, 29 Jun 2023 08:19:58 GMT (envelope-from git) Date: Thu, 29 Jun 2023 08:19:58 GMT Message-Id: <202306290819.35T8Jws5074491@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dmitry Chagin Subject: git: 14ee31bcccfb - stable/13 - pseudofs: Microoptimize struct pfs_node List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 14ee31bcccfbd6ef14548f0129fcaa5a113e4c82 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=14ee31bcccfbd6ef14548f0129fcaa5a113e4c82 commit 14ee31bcccfbd6ef14548f0129fcaa5a113e4c82 Author: Dmitry Chagin AuthorDate: 2023-04-02 08:20:07 +0000 Commit: Dmitry Chagin CommitDate: 2023-06-29 08:15:17 +0000 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 (cherry picked from commit 7f72324346ea154a92671fc913dbe82c0287501a) --- sys/fs/pseudofs/pseudofs.c | 8 +++++--- 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 3c82021a8148..15a714e23bc6 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 */ }; /*