linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Christian Brauner <brauner@kernel.org>
Cc: Jeff Layton <jlayton@kernel.org>, Jan Kara <jack@suse.com>,
	Christoph Hellwig <hch@lst.de>, Jens Axboe <axboe@kernel.dk>,
	Josef Bacik <josef@toxicpanda.com>,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH RFC DRAFT DOESNOTBUILD] inode: free up more space
Date: Fri, 18 Jul 2025 09:04:14 -0700	[thread overview]
Message-ID: <20250718160414.GC1574@quark> (raw)
In-Reply-To: <20250715-work-inode-fscrypt-v1-1-aa3ef6f44b6b@kernel.org>

On Tue, Jul 15, 2025 at 04:35:24PM +0200, Christian Brauner wrote:
> struct inode is bloated as everyone is aware and we should try and
> shrink it as that's potentially a lot of memory savings. I've already
> freed up around 8 bytes but we can probably do better.
> 
> There's a bunch of stuff that got shoved into struct inode that I don't
> think deserves a spot in there. There are two members I'm currently
> particularly interested in:
> 
> (1) #ifdef CONFIG_FS_ENCRYPTION
>             struct fscrypt_inode_info *i_crypt_info;
>     #endif
> 
>     ceph, ext4, f2fs, ubifs
> 
> (2) #ifdef CONFIG_FS_VERITY
>             struct fsverity_info *i_verity_info;
>     #endif
> 
>     btrfs, ext4, f2fs
> 
> So we have 4 users for fscrypt and 3 users for fsverity with both
> features having been around for a decent amount of time.
> 
> For all other filesystems the 16 bytes are just wasted bloating inodes
> for every pseudo filesystem and most other regular filesystems.
> 
> We should be able to move both of these out of struct inode by adding
> inode operations and making it the filesystem's responsibility to
> accommodate the information in their respective inodes.
> 
> Unless there are severe performance penalties for the extra pointer
> dereferences getting our hands on 16 bytes is a good reason to at least
> consider doing this.
> 
> I've drafted one way of doing this using ext4 as my victim^wexample. I'd
> like to hear some early feedback whether this is something we would want
> to pursue.
> 
> Build failures very much expected!
> 
> Not-Signed-off-by: Christian Brauner <brauner@kernel.org>
> ---
>  fs/crypto/bio.c             |  2 +-
>  fs/crypto/crypto.c          |  8 ++++----
>  fs/crypto/fname.c           |  8 ++++----
>  fs/crypto/fscrypt_private.h |  3 +--
>  fs/crypto/hooks.c           |  2 +-
>  fs/crypto/inline_crypt.c    | 10 +++++-----
>  fs/crypto/keysetup.c        | 21 ++++----------------
>  fs/crypto/policy.c          |  8 ++++----
>  fs/ext4/ext4.h              |  9 +++++++++
>  fs/ext4/file.c              |  4 ++++
>  fs/ext4/namei.c             | 22 +++++++++++++++++++++
>  fs/ext4/super.c             |  6 +++++-
>  fs/ext4/symlink.c           | 12 ++++++++++++
>  include/linux/fs.h          |  9 +++++----
>  include/linux/fscrypt.h     | 47 ++++++++++++++++++++++++++++++---------------
>  15 files changed, 112 insertions(+), 59 deletions(-)

This should have been Cc'ed to linux-fscrypt@vger.kernel.org and
fsverity@lists.linux.dev.  I almost missed this.

If done properly, fixing this would be great.  I've tried to minimize
the overhead of CONFIG_FS_ENCRYPTION and CONFIG_FS_VERITY when those
features are not actually being used at runtime.  The struct inode
fields are the main case where we still don't do a good job at that.

However, as was mentioned elsewhere in the thread, unfortunately
indirect calls are really expensive and would not be a great solution.
I've been cleaning up indirect calls in other parts of the kernel, such
as the crypto and crc subsystems, and getting some significant
performance improvements from that.  It would be unfortunate to add a
large number of indirect calls for basically all operations done on
encrypted and/or verity files.

Doing the dereferences to get an offset stored in the inode_operations
(or fscrypt_operations or fsverity_operations, or maybe even super_block
which would just need one dereference rather than two?), and then doing
the pointer arithmetic, would be faster than an indirect call.  It won't
be all that great either, but it would do.

There are some cases where we could instead modify the functions in
fs/crypto/ to have the filesystem pass in a pointer to the
fscrypt_inode_info.  But that won't work in all cases.

Just throwing another idea out there: there could also be an
optimization for the case where only a single *filesystem type* is using
fscrypt (or fsverity) at runtime, which is the usual case.  This would
look something like:

    if (static_branch_likely(&fscrypt_single_fs_type))
            ci = *(struct fscrypt_inode_info **)((void *)inode + fscrypt_crypt_info_offset);
    else
            ci = // get it in slower way.  Maybe even just the indirect call.

In theory, the first case could even use a "runtime_const" for
fscrypt_crypt_info_offset.  In that case, the only difference between
the fast code path (where fscrypt_single_fs_type==true) and the current
inode->i_crypt_info would be the nop associated with the static branch.

But, that might be too fancy.  For now we probably should go with a
single code path that loads the offset from a per-filesystem-instance
struct, like inode_operations or super_block.

- Eric

  parent reply	other threads:[~2025-07-18 16:04 UTC|newest]

Thread overview: 96+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-15 14:35 [PATCH RFC DRAFT DOESNOTBUILD] inode: free up more space Christian Brauner
2025-07-15 14:52 ` Jeff Layton
2025-07-15 16:09 ` Matthew Wilcox
2025-07-16 12:53   ` Christian Brauner
2025-07-16 13:02   ` Christoph Hellwig
2025-07-17  7:48     ` Christian Brauner
2025-07-17  7:51       ` Christoph Hellwig
2025-07-17 15:55         ` Darrick J. Wong
2025-07-16  9:15 ` Jan Kara
2025-07-16  9:50   ` Christian Brauner
2025-07-16 11:21 ` Christoph Hellwig
2025-07-16 12:19   ` Christian Brauner
2025-07-16 12:38     ` Jeff Layton
2025-07-16 14:08       ` Matthew Wilcox
2025-07-16 14:10         ` Christoph Hellwig
2025-07-17  8:32           ` Christian Brauner
2025-07-17 10:54             ` Jan Kara
2025-07-17 11:40               ` Christian Brauner
2025-07-17 11:43                 ` Christoph Hellwig
2025-07-17 12:57     ` Jan Kara
2025-07-18  8:24       ` Christian Brauner
2025-07-18  8:32         ` Christoph Hellwig
2025-07-18  8:58           ` Christian Brauner
2025-07-18 16:04 ` Eric Biggers [this message]
2025-07-18 17:11   ` Eric Biggers
2025-07-21  6:14   ` Christoph Hellwig
2025-07-21 23:55     ` Eric Biggers
2025-07-22  5:49       ` Christoph Hellwig
2025-07-22  7:52       ` Jan Kara
2025-07-22 12:57         ` [PATCH RFC DRAFT v2 00/13] Move fscrypt and fsverity out of struct inode Christian Brauner
2025-07-22 12:57           ` [PATCH RFC DRAFT v2 01/13] fs: add fscrypt offset Christian Brauner
2025-07-22 12:57           ` [PATCH RFC DRAFT v2 02/13] fs/crypto: use accessors Christian Brauner
2025-07-22 12:57           ` [PATCH RFC DRAFT v2 03/13] ext4: move fscrypt to filesystem inode Christian Brauner
2025-07-22 12:57           ` [PATCH RFC DRAFT v2 04/13] ubifs: " Christian Brauner
2025-07-22 12:57           ` [PATCH RFC DRAFT v2 05/13] f2fs: " Christian Brauner
2025-07-22 12:57           ` [PATCH RFC DRAFT v2 06/13] ceph: " Christian Brauner
2025-07-22 12:57           ` [PATCH RFC DRAFT v2 07/13] fs: drop i_crypt_info from struct inode Christian Brauner
2025-07-22 12:57           ` [PATCH RFC DRAFT v2 08/13] fs: add fsverity offset Christian Brauner
2025-07-22 12:57           ` [PATCH RFC DRAFT v2 09/13] fs/verity: use accessors Christian Brauner
2025-07-22 12:57           ` [PATCH RFC DRAFT v2 10/13] btrfs: move fsverity to filesystem inode Christian Brauner
2025-07-22 12:57           ` [PATCH RFC DRAFT v2 11/13] ext4: " Christian Brauner
2025-07-22 12:57           ` [PATCH RFC DRAFT v2 12/13] f2fs: " Christian Brauner
2025-07-22 12:57           ` [PATCH RFC DRAFT v2 13/13] fs: drop i_verity_info from struct inode Christian Brauner
2025-07-22 13:09           ` [PATCH RFC DRAFT v2 00/13] Move fscrypt and fsverity out of " Christian Brauner
2025-07-22 19:27             ` [PATCH v3 " Christian Brauner
2025-07-22 19:27               ` [PATCH v3 01/13] fs: add fscrypt offset Christian Brauner
2025-07-22 20:02                 ` Eric Biggers
2025-07-23  7:48                   ` Christian Brauner
2025-07-23  3:49                 ` Al Viro
2025-07-22 19:27               ` [PATCH v3 02/13] fs/crypto: use accessors Christian Brauner
2025-07-22 19:27               ` [PATCH v3 03/13] ext4: move fscrypt to filesystem inode Christian Brauner
2025-07-22 20:07                 ` Eric Biggers
2025-07-23  8:59                   ` Christian Brauner
2025-07-22 19:27               ` [PATCH v3 04/13] ubifs: " Christian Brauner
2025-07-22 19:27               ` [PATCH v3 05/13] f2fs: " Christian Brauner
2025-07-22 19:27               ` [PATCH v3 06/13] ceph: " Christian Brauner
2025-07-22 20:14                 ` Eric Biggers
2025-07-23  8:58                   ` Christian Brauner
2025-07-22 19:27               ` [PATCH v3 07/13] fs: drop i_crypt_info from struct inode Christian Brauner
2025-07-22 20:19                 ` Eric Biggers
2025-07-23  8:52                   ` Christian Brauner
2025-07-22 19:27               ` [PATCH v3 08/13] fs: add fsverity offset Christian Brauner
2025-07-23  3:53                 ` Al Viro
2025-07-22 19:27               ` [PATCH v3 09/13] fs/verity: use accessors Christian Brauner
2025-07-22 20:25                 ` Eric Biggers
2025-07-23  8:55                   ` Christian Brauner
2025-07-22 19:27               ` [PATCH v3 10/13] btrfs: move fsverity to filesystem inode Christian Brauner
2025-07-22 19:27               ` [PATCH v3 11/13] ext4: " Christian Brauner
2025-07-22 19:27               ` [PATCH v3 12/13] f2fs: " Christian Brauner
2025-07-22 19:27               ` [PATCH v3 13/13] fs: drop i_verity_info from struct inode Christian Brauner
2025-07-23 10:57               ` [PATCH v4 00/15] Move fscrypt and fsverity out of " Christian Brauner
2025-07-23 10:57                 ` [PATCH v4 01/15] fs: add fscrypt offset Christian Brauner
2025-07-23 10:57                 ` [PATCH v4 02/15] fs/crypto: use accessors Christian Brauner
2025-07-25  0:29                   ` Eric Biggers
2025-07-25  4:01                   ` Eric Biggers
2025-07-23 10:57                 ` [PATCH v4 03/15] ext4: move fscrypt to filesystem inode Christian Brauner
2025-07-25  0:32                   ` Eric Biggers
2025-07-23 10:57                 ` [PATCH v4 04/15] ubifs: " Christian Brauner
2025-07-23 10:57                 ` [PATCH v4 05/15] f2fs: " Christian Brauner
2025-07-23 10:57                 ` [PATCH v4 06/15] ceph: " Christian Brauner
2025-07-25  0:34                   ` Eric Biggers
2025-07-25  8:15                     ` Christian Brauner
2025-07-23 10:57                 ` [PATCH v4 07/15] fs: drop i_crypt_info from struct inode Christian Brauner
2025-07-25  0:38                   ` Eric Biggers
2025-07-23 10:57                 ` [PATCH v4 08/15] fscrypt: rephrase documentation and comments Christian Brauner
2025-07-25  0:35                   ` Eric Biggers
2025-07-23 10:57                 ` [PATCH v4 09/15] fs: add fsverity offset Christian Brauner
2025-07-25  0:45                   ` Eric Biggers
2025-07-23 10:57                 ` [PATCH v4 10/15] fs/verity: use accessors Christian Brauner
2025-07-23 10:57                 ` [PATCH v4 11/15] btrfs: move fsverity to filesystem inode Christian Brauner
2025-07-23 10:57                 ` [PATCH v4 12/15] ext4: " Christian Brauner
2025-07-23 10:57                 ` [PATCH v4 13/15] f2fs: " Christian Brauner
2025-07-23 10:57                 ` [PATCH v4 14/15] fs: drop i_verity_info from struct inode Christian Brauner
2025-07-25  0:43                   ` Eric Biggers
2025-07-23 10:57                 ` [PATCH v4 15/15] fsverity: rephrase documentation and comments Christian Brauner
2025-07-22 13:50           ` [PATCH RFC DRAFT v2 00/13] Move fscrypt and fsverity out of struct inode Jeff Layton

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=20250718160414.GC1574@quark \
    --to=ebiggers@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=hch@lst.de \
    --cc=jack@suse.com \
    --cc=jlayton@kernel.org \
    --cc=josef@toxicpanda.com \
    --cc=linux-fsdevel@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;
as well as URLs for NNTP newsgroup(s).