public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Eric Sandeen <sandeen@sandeen.net>
Cc: "Darrick J. Wong" <darrick.wong@oracle.com>, linux-xfs@vger.kernel.org
Subject: Re: [PATCH 6/8] libxfs: manage xfs_buf_zone count within cache
Date: Fri, 12 Jan 2018 09:09:51 +1100	[thread overview]
Message-ID: <20180111220951.GV16421@dastard> (raw)
In-Reply-To: <f55b38bc-09eb-46f9-4b64-97f1117ac7ca@sandeen.net>

On Thu, Jan 11, 2018 at 02:48:33PM -0600, Eric Sandeen wrote:
> 
> 
> On 1/11/18 2:20 PM, Darrick J. Wong wrote:
> > On Thu, Jan 11, 2018 at 01:37:36PM -0600, Eric Sandeen wrote:
> >> Fake up the xfs_buf_zone allocated count a bit to account
> >> for buffers freed to and allocated from cache.
> >>
> >> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> >> Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
> >> ---
> >>  libxfs/rdwr.c | 3 +++
> >>  1 file changed, 3 insertions(+)
> >>
> >> diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
> >> index 474e5eb..c5ffd4d 100644
> >> --- a/libxfs/rdwr.c
> >> +++ b/libxfs/rdwr.c
> >> @@ -665,6 +665,7 @@ __libxfs_getbufr(int blen)
> >>  				free(bp->b_maps);
> >>  			bp->b_maps = NULL;
> >>  		}
> >> +		xfs_buf_zone->allocated++;
> > 
> > I'm confused.  kmem_zone_zalloc increments zone->allocated and
> > kmem_zone_free decrements it.  Now we're messing with ->allocated
> > ourselves, which means that buffers that have ended up on
> > xfs_buf_freelist are still allocated (according to the heap) but the
> > zone accounting thinks the buffer is freed?
> > 
> > <goes away, reviews the next patch, comes back>
> > 
> > The next patch has xfs_buf_freelist frees the buffer directly and
> > bypassing kmem_zone_free.  So I wonder, if you change the next patch to
> > call kmem_zone_free and kill this patch, won't the accounting work out?
> > 
> > (xfs buf zone allocated == 0)
> > 
> > bp = _zone_alloc()
> > xfs_buf_zone->allocated++
> > 
> > ...do stuff with buffer...
> > 
> > xfs_buf_relse(bp)
> > list_add(bp, xfs_buf_freelist)
> > 
> > ...buffer still allocated, xfs_buf_zone->allocated == 1...
> > 
> > libxfs_bcache_free()
> > _zone_free(bp)
> > xfs_buf_zone->allocated--
> > 
> > ...exit program, and:
> > xfs_buf_zone->allocated == 0
> > 
> > I think killing this patch and teaching the next one to kmem_zone_free
> > the buffer works, right?  Or am I missing some subtlety here, in which
> > case said subtlety needs comments.
> 
> Yes, it would work out.  This patch was trying to fake up actual use
> by libxfs, because my main goal was to be able to find leaks in libxfs.
> Counting it as still allocated when libxfs thinks it's put it away
> seems to confuse that goal.
> 
> In the end, it's just where I want to draw the line for the accounting.
> 
> In this way I was hoping to keep the cache details out of that
> accounting.  When libxfs says the buffer is done and puts the last ref,
> it's considered to be freed by libxfs, whether or not the cache chooses
> to hang on to it, discard it later, or whatever.

It's not the job of the zone allocator to track whether something
is cached or not - it just tracks how many objects are allocated.

Indeed, the libxfs cache iitself keeps track of how many objects it
has remaining in it, and if you define CACHE_DEBUG it will issue a
warning if the cache is not empty after it has been purged and is
being torn down.  i.e. we already have debug mechanisms to tell if
we are leaking objects through the cache...

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

  reply	other threads:[~2018-01-11 22:14 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-11 19:37 [PATCH 0/8] libxfs: cleanup & leak detection Eric Sandeen
2018-01-11 19:37 ` [PATCH 1/8] xfs: remove wrappers around b_fspriv Eric Sandeen
2018-01-11 19:42   ` Darrick J. Wong
2018-01-11 19:37 ` [PATCH 2/8] xfs: add a proper transaction pointer to struct xfs_buf Eric Sandeen
2018-01-11 19:43   ` Darrick J. Wong
2018-01-11 19:37 ` [PATCH 3/8] xfs: remove unused buf_fsprivate3 Eric Sandeen
2018-01-11 19:44   ` Darrick J. Wong
2018-01-11 19:37 ` [PATCH 4/8] libxfs: use a memory zone for transactions Eric Sandeen
2018-01-11 19:48   ` Darrick J. Wong
2018-01-25 19:01   ` [PATCH 4/8 V2] " Eric Sandeen
2018-01-25 19:22     ` Darrick J. Wong
2018-01-11 19:37 ` [PATCH 5/8] libxfs: use a memory zone for log items Eric Sandeen
2018-01-11 19:49   ` Darrick J. Wong
2018-01-11 19:37 ` [PATCH 6/8] libxfs: manage xfs_buf_zone count within cache Eric Sandeen
2018-01-11 20:20   ` Darrick J. Wong
2018-01-11 20:48     ` Eric Sandeen
2018-01-11 22:09       ` Dave Chinner [this message]
2018-01-11 19:37 ` [PATCH 7/8] libxfs: add function to free all bufferse in bcache Eric Sandeen
2018-01-11 20:05   ` Darrick J. Wong
2018-01-11 20:11     ` Eric Sandeen
2018-01-11 20:22       ` Darrick J. Wong
2018-01-11 19:37 ` [PATCH 8/8] libxfs: Catch non-empty zones on destroy Eric Sandeen
2018-01-11 20:29   ` Darrick J. Wong
2018-01-11 23:42     ` Eric Sandeen

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=20180111220951.GV16421@dastard \
    --to=david@fromorbit.com \
    --cc=darrick.wong@oracle.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@sandeen.net \
    /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