]> git.hungrycats.org Git - linux/commitdiff
[PATCH] debug check for leaked blockdev buffers
authorAndrew Morton <akpm@zip.com.au>
Thu, 4 Jul 2002 15:30:25 +0000 (08:30 -0700)
committerLinus Torvalds <torvalds@home.transmeta.com>
Thu, 4 Jul 2002 15:30:25 +0000 (08:30 -0700)
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.

fs/buffer.c
include/linux/sched.h
mm/filemap.c

index d46b55b0cf2c11c1ff908cf55cc45b6d9809030d..6ba5de4d2051512946c2a1c9eb8264f03ef4b388 100644 (file)
@@ -467,7 +467,9 @@ void invalidate_bdev(struct block_device *bdev, int destroy_dirty_buffers)
         * We really want to use invalidate_inode_pages2() for
         * that, but not until that's cleaned up.
         */
+       current->flags |= PF_INVALIDATE;
        invalidate_inode_pages(bdev->bd_inode);
+       current->flags &= ~PF_INVALIDATE;
 }
 
 void __invalidate_buffers(kdev_t dev, int destroy_dirty_buffers)
index 390627c2f1f6069b638a4adfaca623098574bfcd..90fb402ee8025b0259739156edd21b5a1b959483 100644 (file)
@@ -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_IOTHREAD    0x00020000      /* this thread is needed for doing I/O to swap */
 #define PF_FROZEN      0x00040000      /* frozen for system suspend */
-
+#define PF_INVALIDATE  0x00080000      /* debug: unmounting an fs. killme. */
 /*
  * Ptrace flags
  */
index a31fbce9e1961c0eabe992c6236bc4532b7ecb32..86ea3c15e6e8173dc3804a627d7745c0f630c282 100644 (file)
@@ -177,8 +177,13 @@ static inline void truncate_partial_page(struct page *page, unsigned partial)
 static void truncate_complete_page(struct page *page)
 {
        /* 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);
+       } else {
+               if (current->flags & PF_INVALIDATE)
+                       printk("%s: buffer heads were leaked\n",
+                               current->comm);
+       }
        ClearPageDirty(page);
        ClearPageUptodate(page);
        remove_inode_page(page);