linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Adam Litke <agl@us.ibm.com>
To: Dave Hansen <haveblue@us.ibm.com>
Cc: linux-mm@kvack.org, mel@csn.ul.ie, apw@shadowen.org,
	nacc@linux.vnet.ibm.com, agl@linux.vnet.ibm.com
Subject: Re: [PATCH 1/3] hugetlb: Correct page count for surplus huge pages
Date: Tue, 26 Feb 2008 10:53:35 -0600	[thread overview]
Message-ID: <1204044815.3837.45.camel@localhost.localdomain> (raw)
In-Reply-To: <1203981109.11846.22.camel@nimitz.home.sr71.net>

On Mon, 2008-02-25 at 15:11 -0800, Dave Hansen wrote:
<snip>
> I wonder if it might get simpler if you just make the pages on the
> freelists "virgin buddy pages".  Basically don't touch pages much until
> after they're dequeued.  Flip flop (a la John Kerry) the order around a
> bit:
> 
> 1. alloc from the buddy list
> 2. enqueue_huge_page()
> 3. somebody does dequeue_huge_page() and before it returns, we:
> 4. initialize to set ->dtor, page->_count, etc...
> 
> This has the disadvantage of shifting some work from a "once per alloc
> from the buddy list" to "once per en/dequeue".  Basically, just try and
> re-think when you turn pages from plain buddy pages into
> hugetlb-flavored pages.  

This is an interesting idea and I will think about it some more.
However, switching this around will introduce more of the churn that
makes people nervous.  So I would appeal that we put forth my original
idea (with your suggested modification) because it is a simple and
verifiable bug fix.  Amended patch follows:

commit 635ff936930f5c56be23feffd06764554f88f8ad
Author: Adam Litke <agl@us.ibm.com>
Date:   Tue Feb 26 08:42:33 2008 -0800

    hugetlb: Correct page count for surplus huge pages
    
    Free pages in the hugetlb pool are free and as such have a reference
    count of zero.  Regular allocations into the pool from the buddy are
    "freed" into the pool which results in their page_count dropping to zero.
    However, surplus pages are directly utilized by the caller without first
    being freed so an explicit reset of the reference count is needed.
    
    This hasn't effected end users because the bad page count is reset before
    the page is handed off.  However, under CONFIG_DEBUG_VM this triggers a BUG
    when the page count is validated.
    
    Thanks go to Mel for first spotting this issue and providing an initial
    fix.
    
    Signed-off-by: Adam Litke <agl@us.ibm.com>
    Cc: Mel Gorman <mel@csn.ul.ie>

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index db861d8..5afcacb 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -267,6 +267,11 @@ static struct page *alloc_buddy_huge_page(struct vm_area_struct *vma,
 
 	spin_lock(&hugetlb_lock);
 	if (page) {
+		/*
+		 * This page is now managed by the hugetlb allocator and has
+		 * no current users -- reset its reference count.
+		 */
+		BUG_ON(!put_page_testzero(page));
 		nid = page_to_nid(page);
 		set_compound_page_dtor(page, free_huge_page);
 		/*
@@ -345,13 +350,14 @@ free:
 			enqueue_huge_page(page);
 		else {
 			/*
-			 * Decrement the refcount and free the page using its
-			 * destructor.  This must be done with hugetlb_lock
+			 * The page has a reference count of zero already, so
+			 * call free_huge_page directly instead of using
+			 * put_page.  This must be done with hugetlb_lock
 			 * unlocked which is safe because free_huge_page takes
 			 * hugetlb_lock before deciding how to free the page.
 			 */
 			spin_unlock(&hugetlb_lock);
-			put_page(page);
+			free_huge_page(page);
 			spin_lock(&hugetlb_lock);
 		}
 	}


-- 
Adam Litke - (agl at us.ibm.com)
IBM Linux Technology Center

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2008-02-26 16:45 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-25 22:01 [PATCH 0/3] hugetlb: Dynamic pool resize improvements Adam Litke
2008-02-25 22:01 ` [PATCH 1/3] hugetlb: Correct page count for surplus huge pages Adam Litke
2008-02-25 22:26   ` Dave Hansen
2008-02-25 23:03     ` Adam Litke
2008-02-25 23:11       ` Dave Hansen
2008-02-26 16:53         ` Adam Litke [this message]
2008-02-26 16:48           ` Dave Hansen
2008-02-25 22:01 ` [PATCH 2/3] hugetlb: Close a difficult to trigger reservation race Adam Litke
2008-02-25 22:01 ` [PATCH 3/3] hugetlb: Decrease hugetlb_lock cycling in gather_surplus_huge_pages Adam Litke
2008-02-25 22:31   ` Dave Hansen
2008-02-25 22:51     ` Adam Litke
  -- strict thread matches above, loose matches on Subject: below --
2008-03-03 18:06 [PATCH 0/3] hugetlb: Dynamic pool resize improvements Adam Litke
2008-03-03 18:06 ` [PATCH 1/3] hugetlb: Correct page count for surplus huge pages Adam Litke

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=1204044815.3837.45.camel@localhost.localdomain \
    --to=agl@us.ibm.com \
    --cc=agl@linux.vnet.ibm.com \
    --cc=apw@shadowen.org \
    --cc=haveblue@us.ibm.com \
    --cc=linux-mm@kvack.org \
    --cc=mel@csn.ul.ie \
    --cc=nacc@linux.vnet.ibm.com \
    /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).