From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from userp1040.oracle.com ([156.151.31.81]:50802 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751013AbcGKWss (ORCPT ); Mon, 11 Jul 2016 18:48:48 -0400 Date: Mon, 11 Jul 2016 15:48:38 -0700 From: Liu Bo To: Chris Mason Cc: linux-btrfs@vger.kernel.org, David Sterba Subject: Re: [PATCH v3] Btrfs: fix eb memory leak due to readpage failure Message-ID: <20160711224838.GA27394@localhost.localdomain> Reply-To: bo.li.liu@oracle.com References: <1464980918-8365-1-git-send-email-bo.li.liu@oracle.com> <1468258747-19617-1-git-send-email-bo.li.liu@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii In-Reply-To: Sender: linux-btrfs-owner@vger.kernel.org List-ID: On Mon, Jul 11, 2016 at 02:27:39PM -0400, Chris Mason wrote: > > > On 07/11/2016 01:39 PM, Liu Bo wrote: > > 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 lets __do_readpage propagate errors to callers and adds the > > 'atomic_dec(&eb->io_pages)'. > > Thanks for looking at this Liu, how is it currently being tested? I have a btrfs disk image which was corrupted by btrfs-corrupt-block tool, in that image, the chunk tree's content has been removed while the chunk node can be read from read successfully, so we'd get -EIO when trying to read tree root's node since __btrfs_map_block() would fail to find the right item in chunk mapping_tree. Thus, we can test our error handling path in read_extent_buffer_pages(). Thanks, -liubo > > -chris