Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Hugh Dickins
Date: Wednesday, December 1, 2010 - 12:23 pm

On Wed, 1 Dec 2010, Trond Myklebust wrote:

Yes, I was wondering quite how we would define this ->freepage thing,
if it gets called from one place that removes from page cache and not
from others.

Another minor problem with it: it would probably need to take the
struct address_space *mapping as arg as well as struct page *page:
because by this time page->mapping has been reset to NULL.

But I'm not at all keen on adding a calllback in this very special
frozen-to-0-references place: please let's not do it without an okay
from Nick Piggin (now Cc'ed).

I agree completely with what Linus said originally about how the
page cannot be freed while there's a reference to it, and it should
be possible to work this without your additional page locks.

Your ->releasepage should be able to judge whether the page is likely
(not certain) to be freed - page_count 3? 1 for the page cache, 1 for
the page_private reference, 1 for vmscan's reference, I think.  Then
it can mark !PageUptodate and proceed with freeing the stuff you had
allocated, undo page_has_private and its reference, and return 1 (or
return 0 if it decides to hold on to the page).

If something races in and grabs another reference to prevent removal
from page cache and freeing, then won't read_cache_page(), seeing
!Uptodate, do the right thing and set up the required info again?

Or perhaps I haven't looked far enough, and you do have races which
actually need your page locks, I can see they make it easier to think
about.

But I'd prefer us not to throw in another callback if it's well
workable with the ->releasepage we already have.  (If it helps,
perhaps we could adjust shrink_page_list() to allow for the page
being removed from page cache inside try_to_release_page() - but
I don't think that should be necessary.)

Hugh
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 2/3] NFS: lock the readdir page while it is in use, Trond Myklebust, (Tue Nov 30, 8:47 pm)
[PATCH 3/3] NFS: Fix a memory leak in nfs_readdir, Trond Myklebust, (Tue Nov 30, 8:47 pm)
[PATCH v2 0/3] Fix more NFS readdir regressions, Trond Myklebust, (Wed Dec 1, 8:36 am)
[PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir, Trond Myklebust, (Wed Dec 1, 8:36 am)
Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir, Linus Torvalds, (Wed Dec 1, 9:17 am)
Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir, Linus Torvalds, (Wed Dec 1, 9:47 am)
Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir, Trond Myklebust, (Wed Dec 1, 10:58 am)
Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir, Miklos Szeredi, (Wed Dec 1, 11:29 am)
Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir, Trond Myklebust, (Wed Dec 1, 11:54 am)
Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir, Hugh Dickins, (Wed Dec 1, 12:23 pm)
Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir, Linus Torvalds, (Wed Dec 1, 12:47 pm)
Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir, Linus Torvalds, (Wed Dec 1, 12:52 pm)
Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir, Trond Myklebust, (Wed Dec 1, 1:05 pm)
Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir, Trond Myklebust, (Wed Dec 1, 1:10 pm)
Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir, Linus Torvalds, (Wed Dec 1, 1:18 pm)
Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir, Trond Myklebust, (Wed Dec 1, 2:51 pm)
Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir, Linus Torvalds, (Wed Dec 1, 3:24 pm)
Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir, Trond Myklebust, (Wed Dec 1, 3:47 pm)
Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir, Trond Myklebust, (Wed Dec 1, 4:21 pm)
Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir, Linus Torvalds, (Wed Dec 1, 4:31 pm)
Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir, Trond Myklebust, (Wed Dec 1, 4:43 pm)
Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir, Trond Myklebust, (Wed Dec 1, 4:56 pm)
Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir, Linus Torvalds, (Wed Dec 1, 6:05 pm)
Re: [PATCH v2 3/3] NFS: Fix a memory leak in nfs_readdir, Linus Torvalds, (Wed Dec 1, 6:42 pm)
[PATCH v3 0/3] Fix more NFS readdir regressions, Trond Myklebust, (Wed Dec 1, 8:08 pm)
[PATCH v3 3/3] NFS: Fix a memory leak in nfs_readdir, Trond Myklebust, (Wed Dec 1, 8:08 pm)
[PATCH v4 0/3] Fix more NFS readdir regressions, Trond Myklebust, (Mon Dec 6, 9:59 am)
[PATCH v4 3/3] NFS: Fix a memory leak in nfs_readdir, Trond Myklebust, (Mon Dec 6, 9:59 am)