Commit 5226cca6 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] debug check for leaked blockdev buffers

Having just fiddled with the refcounts of blockdev buffers, I want some
way of assuring that the code is correct and is not leaking
buffer_heads.

There's no easy way to do this: if a blockdev page has pinned buffers
then truncate_complete_page just cuts it loose and we leak memory.

The patch adds a bit of debug code to catch these leaks.  This code,
PF_RADIX_TREE and buffer_error() need to be removed later on.
parent 34cb9226
...@@ -467,7 +467,9 @@ void invalidate_bdev(struct block_device *bdev, int destroy_dirty_buffers) ...@@ -467,7 +467,9 @@ void invalidate_bdev(struct block_device *bdev, int destroy_dirty_buffers)
* We really want to use invalidate_inode_pages2() for * We really want to use invalidate_inode_pages2() for
* that, but not until that's cleaned up. * that, but not until that's cleaned up.
*/ */
current->flags |= PF_INVALIDATE;
invalidate_inode_pages(bdev->bd_inode); invalidate_inode_pages(bdev->bd_inode);
current->flags &= ~PF_INVALIDATE;
} }
void __invalidate_buffers(kdev_t dev, int destroy_dirty_buffers) void __invalidate_buffers(kdev_t dev, int destroy_dirty_buffers)
......
...@@ -391,7 +391,7 @@ do { if (atomic_dec_and_test(&(tsk)->usage)) __put_task_struct(tsk); } while(0) ...@@ -391,7 +391,7 @@ do { if (atomic_dec_and_test(&(tsk)->usage)) __put_task_struct(tsk); } while(0)
#define PF_FREEZE 0x00010000 /* this task should be frozen for suspend */ #define PF_FREEZE 0x00010000 /* this task should be frozen for suspend */
#define PF_IOTHREAD 0x00020000 /* this thread is needed for doing I/O to swap */ #define PF_IOTHREAD 0x00020000 /* this thread is needed for doing I/O to swap */
#define PF_FROZEN 0x00040000 /* frozen for system suspend */ #define PF_FROZEN 0x00040000 /* frozen for system suspend */
#define PF_INVALIDATE 0x00080000 /* debug: unmounting an fs. killme. */
/* /*
* Ptrace flags * Ptrace flags
*/ */
......
...@@ -177,8 +177,13 @@ static inline void truncate_partial_page(struct page *page, unsigned partial) ...@@ -177,8 +177,13 @@ static inline void truncate_partial_page(struct page *page, unsigned partial)
static void truncate_complete_page(struct page *page) static void truncate_complete_page(struct page *page)
{ {
/* Leave it on the LRU if it gets converted into anonymous buffers */ /* Leave it on the LRU if it gets converted into anonymous buffers */
if (!PagePrivate(page) || do_invalidatepage(page, 0)) if (!PagePrivate(page) || do_invalidatepage(page, 0)) {
lru_cache_del(page); lru_cache_del(page);
} else {
if (current->flags & PF_INVALIDATE)
printk("%s: buffer heads were leaked\n",
current->comm);
}
ClearPageDirty(page); ClearPageDirty(page);
ClearPageUptodate(page); ClearPageUptodate(page);
remove_inode_page(page); remove_inode_page(page);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment