From: Liu Bo <bo.li.liu@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 6/7] Btrfs: fix eb memory leak due to readpage failure
Date: Fri, 13 May 2016 17:07:01 -0700 [thread overview]
Message-ID: <1463184422-13584-6-git-send-email-bo.li.liu@oracle.com> (raw)
In-Reply-To: <1463184422-13584-1-git-send-email-bo.li.liu@oracle.com>
eb->io_pages is set in read_extent_buffer_pages().
In case of readpage failure, for pages that have been added to bio,
it calls bio_endio and later readpage_io_failed_hook() does the work.
When this eb's page (couldn't be the 1st page) fails to add itself to bio
due to failure in merge_bio(), it cannot decrease eb->io_pages via bio_endio,
and ends up with a memory leak eventually.
This adds the 'atomic_dec(&eb->io_pages)' to the readpage error handling.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
fs/btrfs/extent_io.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 99286d1..2327200 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -3069,6 +3069,30 @@ static int __do_readpage(struct extent_io_tree *tree,
*bio_flags = this_bio_flag;
} else {
SetPageError(page);
+ /*
+ * Only metadata io request has this issue, for data it
+ * just unlocks extent and releases page's lock.
+ *
+ * eb->io_pages is set in read_extent_buffer_pages().
+ *
+ * When this eb's page fails to add itself to bio,
+ * it cannot decrease eb->io_pages via bio_endio, and
+ * ends up with extent_buffer_under_io() always being
+ * true, because of that, eb won't be freed and we have
+ * a memory leak eventually.
+ *
+ * Here we still hold this page's lock, and other tasks
+ * who're also reading this eb are blocked.
+ */
+ if (rw & REQ_META) {
+ struct extent_buffer *eb;
+
+ WARN_ON_ONCE(!PagePrivate(page));
+ eb = (struct extent_buffer *)page->private;
+
+ WARN_ON_ONCE(atomic_read(&eb->io_pages) < 1);
+ atomic_dec(&eb->io_pages);
+ }
unlock_extent(tree, cur, cur + iosize - 1);
}
cur = cur + iosize;
--
2.5.5
next prev parent reply other threads:[~2016-05-14 0:05 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-14 0:06 [PATCH 1/7] Btrfs: replace BUG() with WARN_ONCE in raid56 Liu Bo
2016-05-14 0:06 ` [PATCH 2/7] Btrfs: replace BUG_ON with WARN_ONCE in cow_file_range Liu Bo
2016-05-14 0:06 ` [PATCH 3/7] Btrfs: check if extent buffer is aligned to sectorsize Liu Bo
2016-05-14 10:30 ` Qu Wenruo
2016-05-16 18:01 ` Liu Bo
2016-05-17 9:39 ` David Sterba
2016-05-17 17:38 ` Liu Bo
2016-05-14 0:06 ` [PATCH 4/7] Btrfs: free sys_array eb as soon as possible Liu Bo
2016-05-16 8:45 ` David Sterba
2016-05-14 0:07 ` [PATCH 5/7] Btrfs: replace BUG_ON with WARN in merge_bio Liu Bo
2016-05-16 8:44 ` David Sterba
2016-05-16 17:24 ` Liu Bo
2016-05-17 9:55 ` David Sterba
2016-05-17 17:30 ` Liu Bo
2016-05-18 13:54 ` David Sterba
2016-05-14 0:07 ` Liu Bo [this message]
2016-05-18 19:38 ` [PATCH 6/7] Btrfs: fix eb memory leak due to readpage failure Josef Bacik
2016-05-14 0:07 ` [PATCH 7/7] Btrfs: fix memory leak due to invalid btree height Liu Bo
2016-09-06 16:50 ` David Sterba
2016-09-06 22:04 ` Liu Bo
2016-05-14 10:42 ` [PATCH 1/7] Btrfs: replace BUG() with WARN_ONCE in raid56 Qu Wenruo
2016-05-15 14:19 ` Holger Hoffstätte
2016-05-16 8:32 ` David Sterba
2016-10-12 15:06 ` David Sterba
2016-10-12 19:14 ` Liu Bo
2016-06-30 0:57 ` [PATCH v2] Btrfs: remove BUG() " Liu Bo
2016-07-26 16:58 ` David Sterba
2016-07-27 5:11 ` Liu Bo
2016-07-27 18:56 ` [PATCH v3] " Liu Bo
2016-07-29 16:53 ` David Sterba
2016-07-29 17:57 ` [PATCH v4] " Liu Bo
2016-08-24 12:11 ` David Sterba
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=1463184422-13584-6-git-send-email-bo.li.liu@oracle.com \
--to=bo.li.liu@oracle.com \
--cc=linux-btrfs@vger.kernel.org \
/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).