Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Liu Bo <bo.li.liu@oracle.com>
To: Josef Bacik <jbacik@fusionio.com>
Cc: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH 2/2] Btrfs: fix memory leak on extent map after fsync
Date: Fri, 25 Jan 2013 09:38:06 +0800	[thread overview]
Message-ID: <20130125013805.GB11440@liubo> (raw)
In-Reply-To: <20130124164433.GE2349@localhost.localdomain>

On Thu, Jan 24, 2013 at 11:44:33AM -0500, Josef Bacik wrote:
> On Tue, Jan 08, 2013 at 07:49:21AM -0700, Liu Bo wrote:
> > During fsync, we put the changed parts(i.e. extent map) into the log tree,
> > and we ship these parts from a list of modified_extents to a local list
> > to process, of course, we must increment the refs of the extent maps to
> > avoid it from getting evicted from cache.
> > 
> > The problem is
> > we don't hold the tree writer lock all the time of iterating the local list,
> > and it is possible that other threads hack in and delete the extent map from
> > the local list silently.  So we'll end up with memory leak here.
> > 
> > I hit this when testing xfstest 274 with mount options 'autodefrag,compress=zlib'.
> > 
> > With this fix, the memory leak has gone away.
> 
> This isn't going to work, we use the LOGGING flag to make sure the em isn't
> merged as well.  Thanks,

A quick grep shows,

   1     16  fs/btrfs/extent_map.h <<GLOBAL>>
             #define EXTENT_FLAG_LOGGING 4
   2    406  fs/btrfs/extent_map.c <<remove_extent_mapping>>
             if (!test_bit(EXTENT_FLAG_LOGGING, &em->flags))
   3   3403  fs/btrfs/tree-log.c <<btrfs_log_changed_extents>>
             set_bit(EXTENT_FLAG_LOGGING, &em->flags);
   4   3413  fs/btrfs/tree-log.c <<btrfs_log_changed_extents>>
             clear_bit(EXTENT_FLAG_LOGGING, &em->flags);

how does the flag avoid merging em?

Seems we lost the check.

static int mergable_maps(struct extent_map *prev, struct extent_map *next)       
{                                                                                
        if (test_bit(EXTENT_FLAG_PINNED, &prev->flags))                          
                return 0;                                                        
                                                                                 
        /*                                                                       
         * don't merge compressed extents, we need to know their                 
         * actual size                                                           
         */                                                                      
        if (test_bit(EXTENT_FLAG_COMPRESSED, &prev->flags))                      
                return 0;                                                        

	...
}
                                                                                 
thanks,
liubo

  reply	other threads:[~2013-01-25  1:40 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-08 14:49 [PATCH 1/2] Btrfs: add leak debug for extent map Liu Bo
2013-01-08 14:49 ` [PATCH 2/2] Btrfs: fix memory leak on extent map after fsync Liu Bo
2013-01-24 16:44   ` Josef Bacik
2013-01-25  1:38     ` Liu Bo [this message]
2013-01-25  2:23       ` Liu Bo
2013-01-24 16:52   ` Josef Bacik
2013-01-08 20:07 ` [PATCH 1/2] Btrfs: add leak debug for extent map Zach Brown
2013-01-10  2:05   ` Liu Bo
2013-01-10 11:54     ` David Sterba
2013-01-10 13:11       ` Liu Bo
2013-01-11 15:31         ` David Sterba
2013-01-10 17:06     ` Zach Brown
2013-01-11  8:45       ` Liu Bo
2013-01-11 20:54         ` Zach Brown
2013-01-13 12:18           ` Liu Bo

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=20130125013805.GB11440@liubo \
    --to=bo.li.liu@oracle.com \
    --cc=jbacik@fusionio.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