From: Filipe Manana <fdmanana@kernel.org>
To: Anand Jain <anand.jain@oracle.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 02/12] btrfs: free the path earlier when creating a new inode
Date: Wed, 1 Jun 2022 10:34:33 +0100 [thread overview]
Message-ID: <20220601093433.GA3279070@falcondesktop> (raw)
In-Reply-To: <44eeb8b2-e826-4aa0-56dd-5ec90e157018@oracle.com>
On Wed, Jun 01, 2022 at 04:52:54AM +0530, Anand Jain wrote:
> On 5/31/22 20:36, fdmanana@kernel.org wrote:
> > From: Filipe Manana <fdmanana@suse.com>
> >
> > When creating an inode, through btrfs_create_new_inode(), we release the
> > path we allocated before once we don't need it anymore. But we keep it
> > allocated until we return from that function, which is wasteful because
> > after we release the path we do several things that can allocate yet
> > another path: inheriting properties, setting the xattrs used by ACLs and
> > secutiry modules, adding an orphan item (O_TMPFILE case) or adding a
> > dir item (for the non-O_TMPFILE case).
> >
> > So instead of releasing the path once we don't need it anymore, free it
> > instead. This way we avoid having two paths allocated until we return
> > from btrfs_create_new_inode().
> >
> > Signed-off-by: Filipe Manana <fdmanana@suse.com>
> > ---
> > fs/btrfs/inode.c | 11 ++++++++---
> > 1 file changed, 8 insertions(+), 3 deletions(-)
> >
> > diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> > index 06d5bfa84d38..3ede3e873c2a 100644
> > --- a/fs/btrfs/inode.c
> > +++ b/fs/btrfs/inode.c
> > @@ -6380,7 +6380,13 @@ int btrfs_create_new_inode(struct btrfs_trans_handle *trans,
> > }
> > btrfs_mark_buffer_dirty(path->nodes[0]);
> > - btrfs_release_path(path);
> > + /*
> > + * We don't need the path anymore, plus inheriting properties, adding
> > + * ACLs, security xattrs, orphan item or adding the link, will result in
> > + * allocating yet another path. So just free our path.
> > + */
> > + btrfs_free_path(path);
> > + path = NULL;
> > if (args->subvol) {
> > struct inode *parent;
>
>
>
> > @@ -6437,8 +6443,7 @@ int btrfs_create_new_inode(struct btrfs_trans_handle *trans,
> > goto discard;
> > }
>
> At discard, we free path again and leads to double free.
No, there's no double free. The path was set to NULL after being freed.
>
> Thanks, Anand
>
> > > - ret = 0;
> > - goto out;
> > + return 0;
> > discard:
> > /*
>
next prev parent reply other threads:[~2022-06-01 9:34 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-31 15:06 [PATCH 00/12] btrfs: some improvements and cleanups around delayed items fdmanana
2022-05-31 15:06 ` [PATCH 01/12] btrfs: balance btree dirty pages and delayed items after a rename fdmanana
2022-05-31 15:16 ` Nikolay Borisov
2022-05-31 23:13 ` Anand Jain
2022-05-31 15:06 ` [PATCH 02/12] btrfs: free the path earlier when creating a new inode fdmanana
2022-05-31 15:21 ` Nikolay Borisov
2022-05-31 23:22 ` Anand Jain
2022-06-01 9:34 ` Filipe Manana [this message]
2022-06-01 11:11 ` Anand Jain
2022-06-01 11:51 ` David Sterba
2022-05-31 15:06 ` [PATCH 03/12] btrfs: balance btree dirty pages and delayed items after clone and dedupe fdmanana
2022-06-01 0:54 ` Anand Jain
2022-05-31 15:06 ` [PATCH 04/12] btrfs: add assertions when deleting batches of delayed items fdmanana
2022-06-01 1:34 ` Anand Jain
2022-05-31 15:06 ` [PATCH 05/12] btrfs: deal with deletion errors when deleting " fdmanana
2022-06-01 1:44 ` Anand Jain
2022-05-31 15:06 ` [PATCH 06/12] btrfs: refactor the delayed item deletion entry point fdmanana
2022-05-31 15:06 ` [PATCH 07/12] btrfs: improve batch deletion of delayed dir index items fdmanana
2022-06-02 8:24 ` Nikolay Borisov
2022-06-02 8:55 ` Filipe Manana
2022-05-31 15:06 ` [PATCH 08/12] btrfs: assert that delayed item is a dir index item when adding it fdmanana
2022-05-31 15:06 ` [PATCH 09/12] btrfs: improve batch insertion of delayed dir index items fdmanana
2022-05-31 15:06 ` [PATCH 10/12] btrfs: do not BUG_ON() on failure to reserve metadata for delayed item fdmanana
2022-05-31 15:06 ` [PATCH 11/12] btrfs: set delayed item type when initializing it fdmanana
2022-05-31 15:06 ` [PATCH 12/12] btrfs: reduce amount of reserved metadata for delayed item insertion fdmanana
2022-06-08 15:23 ` [btrfs] 62bd8124e2: WARNING:at_fs/btrfs/block-rsv.c:#btrfs_release_global_block_rsv[btrfs] kernel test robot
2022-06-09 9:46 ` Filipe Manana
2022-06-10 1:26 ` Oliver Sang
2022-06-12 14:36 ` Oliver Sang
2022-06-13 10:50 ` Filipe Manana
2022-06-16 2:42 ` Oliver Sang
2022-06-17 10:32 ` Filipe Manana
2022-06-01 18:35 ` [PATCH 00/12] btrfs: some improvements and cleanups around delayed items David Sterba
2022-06-02 9:34 ` Nikolay Borisov
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=20220601093433.GA3279070@falcondesktop \
--to=fdmanana@kernel.org \
--cc=anand.jain@oracle.com \
--cc=linux-btrfs@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