linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@zip.com.au>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: lkml <linux-kernel@vger.kernel.org>, ext2-devel@lists.sourceforge.net
Subject: [patch 6/27] dbeug check for leaked blockdev buffers
Date: Thu, 04 Jul 2002 16:54:04 -0700	[thread overview]
Message-ID: <3D24E01C.84EF4ABD@zip.com.au> (raw)



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           |    2 ++
 include/linux/sched.h |    2 +-
 mm/filemap.c          |    7 ++++++-
 3 files changed, 9 insertions(+), 2 deletions(-)

--- 2.5.24/mm/filemap.c~buffer-leak-check	Thu Jul  4 16:17:12 2002
+++ 2.5.24-akpm/mm/filemap.c	Thu Jul  4 16:22:11 2002
@@ -177,8 +177,13 @@ static inline void truncate_partial_page
 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);
--- 2.5.24/fs/buffer.c~buffer-leak-check	Thu Jul  4 16:17:12 2002
+++ 2.5.24-akpm/fs/buffer.c	Thu Jul  4 16:22:11 2002
@@ -467,7 +467,9 @@ void invalidate_bdev(struct block_device
 	 * 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)
--- 2.5.24/include/linux/sched.h~buffer-leak-check	Thu Jul  4 16:17:12 2002
+++ 2.5.24-akpm/include/linux/sched.h	Thu Jul  4 16:22:11 2002
@@ -391,7 +391,7 @@ do { if (atomic_dec_and_test(&(tsk)->usa
 #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
  */

-

                 reply	other threads:[~2002-07-04 23:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=3D24E01C.84EF4ABD@zip.com.au \
    --to=akpm@zip.com.au \
    --cc=ext2-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /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;
as well as URLs for NNTP newsgroup(s).