Free buffer pages array unconditionally
PATCH 1/1 Free buffer pages array unconditionally
The code in xfs_free_buf() only attempts to free the b_pages array if the buffer is a page cache backed or page allocated buffer. The extra log buffer that is used when the log wraps uses pages that are allocated to a different log buffer, but it still has a b_pages array allocated when those pages are associated to with the extra buffer in xfs_buf_associate_memory.
Hence we need to always attempt to free the b_pages array when tearing down a buffer, not just on buffers that are explicitly marked as page bearing buffers. This fixes a leak detected by the kernel memory leak code.
--- fs/xfs/linux-2.6/xfs_buf.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
fs/xfs/linux-2.6/xfs_buf.c +2 -2
@@ -316,7 +316,7 @@ STATIC void_xfs_buf_free_pages ( xfs_buf_t *bp) { -if (bp->b_pages != bp->b_page_array) { +if (bp->b_pages && bp->b_pages != bp->b_page_array) {kmem_free (bp->b_pages); } }
@@ -349,9 +349,9 @@ xfs_buf_free(ASSERT (!PagePrivate (page));page_cache_release (page); } -_xfs_buf_free_pages (bp); } +_xfs_buf_free_pages (bp);xfs_buf_deallocate (bp); }
Signature · 6 lines
1.6.5 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 20 lines · Dave Chinner
The code in
xfs_free_buf()only attempts to free theb_pagesarray if the buffer is a page cache backed or page allocated buffer. The extra log buffer that is used when the log wraps uses pages that are allocated to a different log buffer, but it still has ab_pagesarray allocated when those pages are associated to with the extra buffer inxfs_buf_associate_memory.Hence we need to always attempt to free the
b_pagesarray when tearing down a buffer, not just on buffers that are explicitly marked as page bearing buffers. This fixes a leak detected by the kernel memory leak code.Signed-off-by Dave Chinner <[email protected]>--- fs/xfs/linux-2.6/xfs_buf.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)fs/xfs/linux-2.6/xfs_buf.c +0
-0
fs/xfs/linux-2.6/xfs_buf.c STATIC void · line 320
Quoted 6 lines
fs/xfs/linux-2.6/xfs_buf.c +1
-1@@ -316,7 +316,7 @@ STATIC void_xfs_buf_free_pages ( xfs_buf_t *bp) { -if (bp->b_pages != bp->b_page_array) { +if (bp->b_pages && bp->b_pages != bp->b_page_array) {kmem_free (bp->b_pages);
kmem_free happily takes a NULL pointer, so this is unessecary.
fs/xfs/linux-2.6/xfs_buf.c xfs_buf_free( · line 354
Quoted 8 lines
fs/xfs/linux-2.6/xfs_buf.c +1
-1@@ -349,9 +349,9 @@ xfs_buf_free(ASSERT (!PagePrivate (page));page_cache_release (page); } -_xfs_buf_free_pages (bp); } +_xfs_buf_free_pages (bp);
This part looks correct, good catch.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 16 lines · Christoph Hellwig
Quoted 15 lines · Dave Chinner
The code in
xfs_free_buf()only attempts to free theb_pagesarray if the buffer is a page cache backed or page allocated buffer. The extra log buffer that is used when the log wraps uses pages that are allocated to a different log buffer, but it still has ab_pagesarray allocated when those pages are associated to with the extra buffer inxfs_buf_associate_memory.Hence we need to always attempt to free the
b_pagesarray when tearing down a buffer, not just on buffers that are explicitly marked as page bearing buffers. This fixes a leak detected by the kernel memory leak code.Signed-off-by Dave Chinner <[email protected]>--- fs/xfs/linux-2.6/xfs_buf.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
Quoted 13 lines
fs/xfs/linux-2.6/xfs_buf.c STATIC void · line 320
Quoted 11 lines
fs/xfs/linux-2.6/xfs_buf.c +1
-1@@ -316,7 +316,7 @@ STATIC void_xfs_buf_free_pages ( xfs_buf_t *bp) { -if (bp->b_pages != bp->b_page_array) { +if (bp->b_pages && bp->b_pages != bp->b_page_array) {kmem_free (bp->b_pages);
kmem_freehappily takes a NULL pointer, so this is unessecary.
Yes, it does, but I wanted to make sure that b_pages had been assigned before doing the comparison because this is now called unconditionally. I´ll remove the check and retest.
Hmmm - I suspect that this function needs to NULL b_pages in case it _xfs_buf_free_pages() is called prior to calling xfs_buf_free()...
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 9 lines · Dave Chinner
Quoted 1 line
kmem_freehappily takes a NULL pointer, so this is unessecary.Yes, it does, but I wanted to make sure that
b_pageshad been assigned before doing the comparison because this is now called unconditionally. I?ll remove the check and retest.Hmmm - I suspect that this function needs to NULL
b_pagesin case it_xfs_buf_free_pages()is called prior to callingxfs_buf_free()...
Yes, at least for now. Long term we should stop messing with the page array on a live buffer. The only place where we currently do that is xfs_buf_associate_memory, which has two callers, one for the log wrap reserver buffer, and the other in various places in log recovery for aligned v2 logs.
For the first one we know the max number of pages we might have to deal with so we can pass it when allocating the buffer, and for the second one the number of pages can't be bigger than the original number of pages for the buffer every so there's no need to do the reallocation game at all.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs