From: Dave Hansen <dave@linux.vnet.ibm.com>
To: Russell King - ARM Linux <linux@arm.linux.org.uk>
Cc: Minchan Kim <minchan.kim@gmail.com>,
Christoph Lameter <cl@linux-foundation.org>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
Milton Miller <miltonm@bga.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Andrew Morton <akpm@linux-foundation.org>,
Mel Gorman <mel@csn.ul.ie>, Johannes Weiner <hannes@cmpxchg.org>,
Kukjin Kim <kgene.kim@samsung.com>
Subject: Re: [PATCH] Tight check of pfn_valid on sparsemem - v4
Date: Wed, 11 Aug 2010 08:31:29 -0700 [thread overview]
Message-ID: <1281540689.6988.50.camel@nimitz> (raw)
In-Reply-To: <20100731103849.GH23886@n2100.arm.linux.org.uk>
On Sat, 2010-07-31 at 11:38 +0100, Russell King - ARM Linux wrote:
> On Fri, Jul 30, 2010 at 06:32:04PM +0900, Minchan Kim wrote:
> > On Fri, Jul 30, 2010 at 5:55 AM, Dave Hansen <dave@linux.vnet.ibm.com> wrote:
> > > If you free up parts of the mem_map[] array, how does the buddy
> > > allocator still work? I thought we required at 'struct page's to be
> > > contiguous and present for at least 2^MAX_ORDER-1 pages in one go.
>
> (Dave, I don't seem to have your mail to reply to.)
>
> What you say is correct, and memory banks as a rule of thumb tend to be
> powers of two.
>
> We do have the ability to change MAX_ORDER (which we need to do for some
> platforms where there's only 1MB of DMA-able memory.)
>
> However, in the case of two 512KB banks, the buddy allocator won't try
> to satisfy a 1MB request as it'll only have two separate 2x512K free
> 'pages' to deal with, and 0x1M free 'pages'.
Right, it won't try to _coalesce_ those pages, but it will go trying to
look for the freed page's buddy in the empty area. This is probably a
pretty rare issue, but I think it's real. Take a look at
__free_one_page():
...
while (order < MAX_ORDER-1) {
buddy = __page_find_buddy(page, page_idx, order);
if (!page_is_buddy(page, buddy, order))
break;
We look at the page, and the order of the page that just got freed. We
go looking to see whether the page's buddy at this order is in the buddy
system, and _that_ tells us whether a coalesce can be done. However, we
do this with some funky math on the original page's 'struct page *':
static inline struct page *
__page_find_buddy(struct page *page, unsigned long page_idx, unsigned int order)
{
unsigned long buddy_idx = page_idx ^ (1 << order);
return page + (buddy_idx - page_idx);
}
That relies on all 'struct pages' within the current 2^MAX_ORDER to be
virtually contiguous. If you free up section_mem_map[] 'struct page'
blocks within the MAX_ORDER, the free'd page's buddy's 'struct page'
might fall in the area that got freed. In that case, you'll get an
effectively random PageBuddy() value, and might mistakenly coalesce the
page.
In practice with a 1MB MAX_ORDER and 512KB banks, it'll only happen if
you free the page representing the entire 512KB bank, and if the memory
for the other half 'struct page' has already gotten reused. That's
probably why you've never seen it.
-- Dave
--
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>
next prev parent reply other threads:[~2010-08-11 15:31 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-26 15:46 [PATCH] Tight check of pfn_valid on sparsemem - v4 Minchan Kim
2010-07-26 16:40 ` Christoph Lameter
2010-07-26 22:47 ` Minchan Kim
[not found] ` <pfn.valid.v4.reply.1@mdm.bga.com>
[not found] ` <AANLkTimtTVvorrR9pDVTyPKj0HbYOYY3aR7B-QWGhTei@mail.gmail.com>
2010-07-27 8:12 ` Milton Miller
2010-07-27 8:13 ` KAMEZAWA Hiroyuki
2010-07-27 10:01 ` Minchan Kim
2010-07-27 14:34 ` Christoph Lameter
2010-07-27 22:33 ` Minchan Kim
2010-07-28 15:14 ` Christoph Lameter
2010-07-28 15:56 ` Minchan Kim
2010-07-28 17:02 ` Christoph Lameter
2010-07-28 22:57 ` Minchan Kim
2010-07-29 15:46 ` Christoph Lameter
2010-07-29 16:18 ` Minchan Kim
2010-07-29 16:47 ` Christoph Lameter
2010-07-29 17:03 ` Minchan Kim
2010-07-29 17:30 ` Christoph Lameter
2010-07-29 18:33 ` Russell King - ARM Linux
2010-07-29 19:55 ` Christoph Lameter
2010-07-29 21:13 ` Russell King - ARM Linux
2010-07-29 20:55 ` Dave Hansen
2010-07-29 22:14 ` Russell King - ARM Linux
2010-07-29 22:28 ` Christoph Lameter
2010-07-30 0:38 ` Dave Hansen
2010-07-30 9:43 ` Minchan Kim
2010-07-30 12:48 ` Christoph Lameter
2010-07-30 15:43 ` Dave Hansen
2010-07-31 15:30 ` Russell King - ARM Linux
2010-08-02 15:48 ` Christoph Lameter
2010-07-30 9:32 ` Minchan Kim
2010-07-31 10:38 ` Russell King - ARM Linux
2010-08-11 15:31 ` Dave Hansen [this message]
2010-07-27 9:56 ` Minchan Kim
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=1281540689.6988.50.camel@nimitz \
--to=dave@linux.vnet.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=cl@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=kgene.kim@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux@arm.linux.org.uk \
--cc=mel@csn.ul.ie \
--cc=miltonm@bga.com \
--cc=minchan.kim@gmail.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).