Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755216Ab0LAVvQ (ORCPT ); Wed, 1 Dec 2010 16:51:16 -0500 Received: from mx2.netapp.com ([216.240.18.37]:36857 "EHLO mx2.netapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752882Ab0LAVvP convert rfc822-to-8bit (ORCPT ); Wed, 1 Dec 2010 16:51:15 -0500 X-IronPort-AV: E=Sophos;i="4.59,285,1288594800"; d="scan'208";a="489712432" Subject: Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir From: Trond Myklebust To: Andrew Morton Cc: Hugh Dickins , Linus Torvalds , Nick Piggin , Nick Bowler , Linux Kernel Mailing List , linux-nfs@vger.kernel.org, Rik van Riel , Christoph Hellwig , Al Viro In-Reply-To: <20101201133831.ea6ba10a.akpm@linux-foundation.org> References: <1291217804-11257-1-git-send-email-Trond.Myklebust@netapp.com> <1291217804-11257-2-git-send-email-Trond.Myklebust@netapp.com> <20101201150428.GA2879@elliptictech.com> <1291217804-11257-3-git-send-email-Trond.Myklebust@netapp.com> <1291217804-11257-4-git-send-email-Trond.Myklebust@netapp.com> <1291229669.6609.24.camel@heimdal.trondhjem.org> <1291234251.6609.39.camel@heimdal.trondhjem.org> <20101201123341.d12ef362.akpm@linux-foundation.org> <20101201133831.ea6ba10a.akpm@linux-foundation.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Organization: NetApp Inc Date: Wed, 01 Dec 2010 16:51:12 -0500 Message-ID: <1291240272.6609.50.camel@heimdal.trondhjem.org> Mime-Version: 1.0 X-Mailer: Evolution 2.32.1 (2.32.1-1.fc14) X-OriginalArrivalTime: 01 Dec 2010 21:51:14.0449 (UTC) FILETIME=[E006B810:01CB91A1] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3180 Lines: 71 On Wed, 2010-12-01 at 13:38 -0800, Andrew Morton wrote: > On Wed, 1 Dec 2010 13:15:07 -0800 (PST) > Hugh Dickins wrote: > > > On Wed, 1 Dec 2010, Hugh Dickins wrote: > > > On Wed, 1 Dec 2010, Andrew Morton wrote: > > > > On Wed, 01 Dec 2010 15:10:50 -0500 > > > > Trond Myklebust wrote: > > > > > > > > > --- a/include/linux/fs.h > > > > > +++ b/include/linux/fs.h > > > > > @@ -602,6 +602,7 @@ struct address_space_operations { > > > > > sector_t (*bmap)(struct address_space *, sector_t); > > > > > void (*invalidatepage) (struct page *, unsigned long); > > > > > int (*releasepage) (struct page *, gfp_t); > > > > > + void (*freepage)(struct page *); > > > > > ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov, > > > > > loff_t offset, unsigned long nr_segs); > > > > > int (*get_xip_mem)(struct address_space *, pgoff_t, int, > > > > > > > > It would be good to think about and then clearly spell out exactly what > > > > state the page is in here. It is locked, and I assume clean and not > > > > under writeback. What about its refcount, freezedness status and > > > > eligibility for lookups? > > > > > > > > And as Hugh pointed out, some callees might needs the address_space* > > > > although we can perhaps defer that until such a callee turns up. > > > > If/when that happens we might have a problem though: if this locked > > > > page is no longer attached to the address_space then what now pins the > > > > address_space, protecting it from inode reclaim? > > > > > > That's an excellent point and trumps mine: it would be actively wrong > > > to provide the struct address_space *mapping arg I was asking for. > > > (Bet someone then tries stashing it away via page->private though.) > > > > Hmm, thinking further along the same lines: can we even guarantee that > > the filesystem module is still loaded at that point? i.e. might > > mapping->freepage now be pointing off into the garbage heap? > > I don't see anything on the VFS side which would prevent a module > unload. Or, more realistically, a concurrent unmount, freeing of the > superblock and everything associated with it. All we have here is a > page*. > > Probably on most call paths we'll be OK - if a process is in the middle > of a file truncate, holdin a file* ref which holds an inode ref then > nobody will be unmounting that fs and hence nobody will be unloading > that module. > > However on the random_code->alloc_page->vmscan->releasepage path, none > of that applies. Just out of interest, what ensures that the mapping is still around for the 'spin_unlock_irq(&mapping->tree_lock);' in __remove_mapping()? I'm clearly missing whatever mechanism prevents iput_final() from racing with vmscan if the latter clears out the last page from the mapping. -- Trond Myklebust Linux NFS client maintainer NetApp Trond.Myklebust@netapp.com www.netapp.com -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/