All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thorsten Blum <blum@kernel.org>
To: Jan Kara <jack@suse.cz>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] initramfs: Reduce hardlink hash allocation sizes
Date: Tue, 22 Sep 2026 12:08:43 +0200	[thread overview]
Message-ID: <arJTq4TiVgyVLGA3@kernel.org> (raw)
In-Reply-To: <cbvwd3loa6edt7tjnd24vuv4dqnu6gul2ysbaooftx7d7o7zlo@xwg2ixm5ac37>

On Tue, Sep 22, 2026 at 11:45:37AM +0200, Jan Kara wrote:
> On Sat 19-09-26 23:39:00, Thorsten Blum wrote:
> > Each hardlink hash entry reserves N_ALIGN(PATH_MAX) bytes for its name.
> > This makes every allocation larger than 4 KiB, placing it in the
> > kmalloc-8k bucket even for short names.
> > 
> > Use a flexible array with the already validated cpio name_len to reduce
> > allocation sizes.
> > 
> > Also use const for the read-only name parameter.
> > 
> > Signed-off-by: Thorsten Blum <blum@kernel.org>
> 
> ...
> 
> > @@ -106,14 +106,15 @@ static char __init *find_link(int major, int minor, int ino,
> >  			continue;
> >  		return (*p)->name;
> >  	}
> > -	q = kmalloc_obj(struct hash);
> > +
> > +	q = kmalloc_flex(struct hash, name, nlen);
> >  	if (!q)
> >  		panic_show_mem("can't allocate link hash entry");
> >  	q->major = major;
> >  	q->minor = minor;
> >  	q->ino = ino;
> >  	q->mode = mode;
> > -	strscpy(q->name, name);
> > +	strscpy(q->name, name, nlen);
> >  	q->next = NULL;
> >  	*p = q;
> >  	hardlink_seen = true;
> 
> What about the space for terminating \0 ? This way the stored 'name' will
> be actually one character shorter because strscpy() will overwrite the last
> character by \0. Or do I miss something?

do_name() guarantees that collected[name_len - 1] == '\0' before calling
maybe_link(), so name_len already includes the NUL terminator and no
character is overwritten.

  reply	other threads:[~2026-09-22 10:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-19 21:39 [PATCH] initramfs: Reduce hardlink hash allocation sizes Thorsten Blum
2026-09-22  9:45 ` Jan Kara
2026-09-22 10:08   ` Thorsten Blum [this message]
2026-09-23 10:38     ` Jan Kara
2026-09-25 15:17 ` Christian Brauner

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=arJTq4TiVgyVLGA3@kernel.org \
    --to=blum@kernel.org \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.