From: David Gibson <dwg@au1.ibm.com>
To: Hugh Dickins <hughd@google.com>
Cc: kvm <kvm@vger.kernel.org>,
linux-kernel@vger.kernel.org,
Marcelo Tosatti <mtosatti@redhat.com>,
agraf@suse.de, qemu-devel@nongnu.org, Adam Litke <agl@us.ibm.com>,
Minchan Kim <minchan.kim@gmail.com>,
Jan Kiszka <jan.kiszka@web.de>, Avi Kivity <avi@redhat.com>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
Andrew Hastings <abh@cray.com>, Paul Mackerras <paulus@samba.org>,
Andrew Morton <akpm@linux-foundation.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
Mel Gorman <mgorman@suse.de>
Subject: Re: [Qemu-devel] Fix refcounting in hugetlbfs quota handling
Date: Sat, 13 Aug 2011 11:08:39 +1000 [thread overview]
Message-ID: <20110813010839.GC30552@yookeroo.fritz.box> (raw)
In-Reply-To: <alpine.LSU.2.00.1108121126560.1290@sister.anvils>
On Fri, Aug 12, 2011 at 12:15:21PM -0700, Hugh Dickins wrote:
> On Fri, 12 Aug 2011, Minchan Kim wrote:
> > On Fri, Aug 12, 2011 at 9:48 AM, Linus Torvalds
> > <torvalds@linux-foundation.org> wrote:
> > > On Wed, Aug 10, 2011 at 11:40 PM, David Gibson
> > > <david@gibson.dropbear.id.au> wrote:
> > >>
> > >> This patch, therefore, stores a pointer to the inode instead of the
> > >> address_space in the page private data for hugepages. More
> > >> importantly it correctly adjusts the reference count on the inodes
> > >> when they're added to the page private data. This ensures that the
> > >> inode (and therefore the super block) will not be freed before we use
> > >> it from free_huge_page.
> > >
> > > Looks sane, but I *really* want some acks from people who use/know
> > > hugetlbfs. Who would that be? I'm adding random people who have
> > > acked/signed-off patches to hugetlbfs recently..
> >
> > At least, code itself looks good to me but your random choice was failed.
> > Maybe people you want are as follows.
> > http://marc.info/?t=126928975800003&r=1&w=2
> >
> > Ccing right persons.
>
> I don't know much about hugetlbfs these days, but I think the patch
> is very wrong.
>
> The real change is where alloc_huge_page() does igrab(inode) and
> free_huge_pages() does iput(inode)?
>
> That makes me very nervous, partly because a final iput() is a complex
> operation, which we wouldn't expect to be doing when "freeing" a page.
>
> My first worry was that free_huge_page() could actually get called at
> interrupt time (when it's in a pagevec of pages to be freed as a batch,
> then another put_page is done at interrupt time which frees that batch):
> I worried that we use spin_lock not spin_lock_irqsave on inode->i_lock.
> To be honest though, I've not followed up whether that's actually a
> possibility, the compound page path is too twisty for a quick answer;
> and even if it's a possibility, it's one that's already ignored in the
> case of hugetlb_lock.
>
> Setting that aside, I think this thing of grabbing a reference to inode
> for each page just does not work as you wish: when we unlink an inode,
> all its pages should be freed; but because they are themselves holding
> references to the inode, it and its pages stick around forever.
Ugh, yes. You're absolutely right. That circular reference will mess
everything up. Thinking it through and testing fail.
> A quick experiment with your patch versus without confirmed that:
> meminfo HugePages_Free stayed down with your patch, but went back to
> HugePages_Total without it. Please check, perhaps I'm just mistaken.
>
> Sorry, I've not looked into what a constructive alternative might be;
> and it's not the first time we've had this difficulty - it came up last
> year when the ->freepage function was added, that the inode may be gone
> by the time ->freepage(page) is called.
Ok, so. In fact the quota functions we call at free time only need
the super block, not the inode per se. If we put a superblock pointer
instead of an inode pointer in page private, and refcounted that, I
think that should remove the circular ref. The only reason I didn't
do it before is that the superblock refcounting functions didn't seem
to be globally visible in an obvious way.
Does that sound like a reasonable approach?
> On a side note, very good description - thank you, but I wish you'd
> split the patch into two, the fix and then the inode-instead-of-mapping
> cleanup. Though personally I'd prefer not to make that "cleanup": it's
> normal for a struct address space * to be used in struct page (if I delved
> I guess I'd find good reason why this one is in page->private instead of
> page->mapping: perhaps because it's needed after page->mapping is reset
> to NULL, perhaps because it's needed on COWed copies of hugetlbfs pages).
That is an interesting question. But it doesn't address the basic
point. mappings aren't refcounted themselves, and as far as I can
tell their lifetime is bound to that of their inode.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
next prev parent reply other threads:[~2011-08-13 2:19 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-11 6:40 [Qemu-devel] Fix refcounting in hugetlbfs quota handling David Gibson
2011-08-12 0:48 ` Linus Torvalds
2011-08-12 4:34 ` Minchan Kim
2011-08-12 19:15 ` Hugh Dickins
2011-08-13 1:08 ` David Gibson [this message]
2011-08-15 18:00 ` Hugh Dickins
2011-08-15 20:25 ` Andrew Barry
2011-08-16 3:47 ` David Gibson
2011-08-16 17:45 ` [Qemu-devel] [RFC PATCH] mm/hugepages: Fix race between hugetlbfs umount and quota update Andrew Barry
2011-08-16 17:45 ` [Qemu-devel] Fix refcounting in hugetlbfs quota handling Andrew Barry
2011-08-12 22:20 ` Christoph Hellwig
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=20110813010839.GC30552@yookeroo.fritz.box \
--to=dwg@au1.ibm.com \
--cc=abh@cray.com \
--cc=agl@us.ibm.com \
--cc=agraf@suse.de \
--cc=akpm@linux-foundation.org \
--cc=avi@redhat.com \
--cc=hughd@google.com \
--cc=jan.kiszka@web.de \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=minchan.kim@gmail.com \
--cc=mtosatti@redhat.com \
--cc=paulus@samba.org \
--cc=qemu-devel@nongnu.org \
--cc=torvalds@linux-foundation.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).