From: Tyler Hicks <code@tyhicks.com>
To: Yichong Chen <chenyichong@uniontech.com>
Cc: Christian Brauner <brauner@kernel.org>,
Taotao Chen <chentaotao@didiglobal.com>,
ecryptfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ecryptfs: avoid heap allocation for inode size write
Date: Tue, 30 Jun 2026 23:35:30 -0500 [thread overview]
Message-ID: <akSZEhSVoRRVLyRh@yaupon> (raw)
In-Reply-To: <20260630030800.191457-1-chenyichong@uniontech.com>
On 2026-06-30 11:08:00, Yichong Chen wrote:
> ecryptfs_write_inode_size_to_header() allocates an 8-byte buffer only
> to write the encoded inode size to the lower file header.
>
> Use a stack __be64 value instead. This avoids an unnecessary allocation
> and removes a failure path without changing the data written to disk.
>
> Signed-off-by: Yichong Chen <chenyichong@uniontech.com>
This is much better. Thanks for the improvement!
I'll put your patches through some testing and then respond when they've
been applied. Thanks!
Tyler
> ---
> fs/ecryptfs/mmap.c | 15 ++++-----------
> 1 file changed, 4 insertions(+), 11 deletions(-)
>
> diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c
> index 2c2b12fedeae..0222f98143ab 100644
> --- a/fs/ecryptfs/mmap.c
> +++ b/fs/ecryptfs/mmap.c
> @@ -355,24 +355,17 @@ static int ecryptfs_write_begin(const struct kiocb *iocb,
> */
> static int ecryptfs_write_inode_size_to_header(struct inode *ecryptfs_inode)
> {
> - char *file_size_virt;
> + __be64 file_size;
> int rc;
>
> - file_size_virt = kmalloc(sizeof(u64), GFP_KERNEL);
> - if (!file_size_virt) {
> - rc = -ENOMEM;
> - goto out;
> - }
> - put_unaligned_be64(i_size_read(ecryptfs_inode), file_size_virt);
> - rc = ecryptfs_write_lower(ecryptfs_inode, file_size_virt, 0,
> - sizeof(u64));
> - kfree(file_size_virt);
> + file_size = cpu_to_be64(i_size_read(ecryptfs_inode));
> + rc = ecryptfs_write_lower(ecryptfs_inode, (char *)&file_size, 0,
> + sizeof(file_size));
> if (rc < 0)
> printk(KERN_ERR "%s: Error writing file size to header; "
> "rc = [%d]\n", __func__, rc);
> else
> rc = 0;
> -out:
> return rc;
> }
>
> --
> 2.51.0
>
prev parent reply other threads:[~2026-07-01 4:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-30 3:08 [PATCH] ecryptfs: avoid heap allocation for inode size write Yichong Chen
2026-07-01 4:35 ` Tyler Hicks [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=akSZEhSVoRRVLyRh@yaupon \
--to=code@tyhicks.com \
--cc=brauner@kernel.org \
--cc=chentaotao@didiglobal.com \
--cc=chenyichong@uniontech.com \
--cc=ecryptfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox