2012-10-08 15:41:58

by Rabin Vincent

[permalink] [raw]
Subject: CMA and zone watermarks

It appears that when CMA is enabled, the zone watermarks are not properly
respected, leading to for example GFP_NOWAIT allocations getting access to the
high pools.

I ran the following test code which simply allocates pages with GFP_NOWAIT
until it fails, and then tries GFP_ATOMIC. Without CMA, the GFP_ATOMIC
allocation succeeds, with CMA, it fails too.

Logs attached (includes my patch which prints the migration type in the failure
message http://marc.info/?l=linux-mm&m=134971041701306&w=2), taken on 3.6
kernel.

Thanks.

diff --git a/arch/arm/mach-ux500/board-mop500.c
b/arch/arm/mach-ux500/board-mop500.c
index a534d88..b98d0df 100644
--- a/arch/arm/mach-ux500/board-mop500.c
+++ b/arch/arm/mach-ux500/board-mop500.c
@@ -854,3 +854,25 @@ DT_MACHINE_START(U8500_DT, "ST-Ericsson U8500
platform (Device Tree Support)")
.dt_compat = u8500_dt_board_compat,
MACHINE_END
#endif
+
+static int __init late(void)
+{
+ while (1) {
+ void *p;
+
+ p = alloc_page(GFP_NOWAIT);
+ if (!p) {
+ pr_err("GFP_NOWAIT failed, checking GFP_ATOMIC");
+
+ p = alloc_page(GFP_ATOMIC);
+ if (!p)
+ panic("GFP_ATOMIC failed too, fail!");
+
+ panic("GFP_ATOMIC OK, all good\n");
+ }
+
+ }
+
+ return 0;
+}
+late_initcall(late);


Attachments:
cmalog.txt.gz (5.98 kB)

2012-10-09 00:37:24

by Marek Szyprowski

[permalink] [raw]
Subject: Re: CMA and zone watermarks

Hello,

On 10/8/2012 5:41 PM, Rabin Vincent wrote:

> It appears that when CMA is enabled, the zone watermarks are not properly
> respected, leading to for example GFP_NOWAIT allocations getting access to the
> high pools.
>
> I ran the following test code which simply allocates pages with GFP_NOWAIT
> until it fails, and then tries GFP_ATOMIC. Without CMA, the GFP_ATOMIC
> allocation succeeds, with CMA, it fails too.

Could You run your test with latest linux-next kernel? There have been
some patches merged to akpm tree which should fix accounting for free
and free cma pages. I hope it should fix this issue.

Best regards
--
Marek Szyprowski
Samsung Poland R&D Center

2012-10-09 03:06:15

by Minchan Kim

[permalink] [raw]
Subject: Re: CMA and zone watermarks

Hello,

On Mon, Oct 08, 2012 at 05:41:14PM +0200, Rabin Vincent wrote:
> It appears that when CMA is enabled, the zone watermarks are not properly
> respected, leading to for example GFP_NOWAIT allocations getting access to the
> high pools.
>
> I ran the following test code which simply allocates pages with GFP_NOWAIT
> until it fails, and then tries GFP_ATOMIC. Without CMA, the GFP_ATOMIC
> allocation succeeds, with CMA, it fails too.

Good spot. By wrong zone_watermark_check, it can consume reserved memory pool.

>
> Logs attached (includes my patch which prints the migration type in the failure
> message http://marc.info/?l=linux-mm&m=134971041701306&w=2), taken on 3.6
> kernel.
>

Fortunately, recently, Bart sent a patch about that.
http://marc.info/?l=linux-mm&m=134763299016693&w=2

Could you test above patches in your kernel?
You have to apply [2/4], [3/4], [4/4] and don't need [1/4].

Thanks.

--
Kind regards,
Minchan Kim

2012-10-09 03:11:57

by Marek Szyprowski

[permalink] [raw]
Subject: Re: CMA and zone watermarks

Hello,

On 10/9/2012 5:10 AM, Minchan Kim wrote:

> On Mon, Oct 08, 2012 at 05:41:14PM +0200, Rabin Vincent wrote:
>> It appears that when CMA is enabled, the zone watermarks are not properly
>> respected, leading to for example GFP_NOWAIT allocations getting access to the
>> high pools.
>>
>> I ran the following test code which simply allocates pages with GFP_NOWAIT
>> until it fails, and then tries GFP_ATOMIC. Without CMA, the GFP_ATOMIC
>> allocation succeeds, with CMA, it fails too.
>
> Good spot. By wrong zone_watermark_check, it can consume reserved memory pool.

That was the main reason for the Bartek's research.

>> Logs attached (includes my patch which prints the migration type in the failure
>> message http://marc.info/?l=linux-mm&m=134971041701306&w=2), taken on 3.6
>> kernel.
>>
>
> Fortunately, recently, Bart sent a patch about that.
> http://marc.info/?l=linux-mm&m=134763299016693&w=2
>
> Could you test above patches in your kernel?
> You have to apply [2/4], [3/4], [4/4] and don't need [1/4].

AFAIR without patch [1/4], free cma page counter will go below zero and
weird thing will happen, so better apply the complete patchset.

Best regards
--
Marek Szyprowski
Samsung Poland R&D Center

2012-10-09 04:39:11

by Minchan Kim

[permalink] [raw]
Subject: Re: CMA and zone watermarks

On Tue, Oct 09, 2012 at 05:12:21AM +0200, Marek Szyprowski wrote:
> Hello,
>
> On 10/9/2012 5:10 AM, Minchan Kim wrote:
>
> >On Mon, Oct 08, 2012 at 05:41:14PM +0200, Rabin Vincent wrote:
> >>It appears that when CMA is enabled, the zone watermarks are not properly
> >>respected, leading to for example GFP_NOWAIT allocations getting access to the
> >>high pools.
> >>
> >>I ran the following test code which simply allocates pages with GFP_NOWAIT
> >>until it fails, and then tries GFP_ATOMIC. Without CMA, the GFP_ATOMIC
> >>allocation succeeds, with CMA, it fails too.
> >
> >Good spot. By wrong zone_watermark_check, it can consume reserved memory pool.
>
> That was the main reason for the Bartek's research.

Okay. It shoud have written down for more good description at that time. :)

>
> >>Logs attached (includes my patch which prints the migration type in the failure
> >>message http://marc.info/?l=linux-mm&m=134971041701306&w=2), taken on 3.6
> >>kernel.
> >>
> >
> >Fortunately, recently, Bart sent a patch about that.
> >http://marc.info/?l=linux-mm&m=134763299016693&w=2
> >
> >Could you test above patches in your kernel?
> >You have to apply [2/4], [3/4], [4/4] and don't need [1/4].
>
> AFAIR without patch [1/4], free cma page counter will go below zero
> and weird thing will happen, so better apply the complete patchset.

I can't understand your point. [1/4] is just fix for correcting trace
No?

http://marc.info/?l=linux-mm&m=134763301216713&w=2


>
> Best regards
> --
> Marek Szyprowski
> Samsung Poland R&D Center
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to [email protected]. For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

--
Kind regards,
Minchan Kim

2012-10-09 04:53:04

by Marek Szyprowski

[permalink] [raw]
Subject: Re: CMA and zone watermarks

Hello,

On 10/9/2012 6:43 AM, Minchan Kim wrote:
> On Tue, Oct 09, 2012 at 05:12:21AM +0200, Marek Szyprowski wrote:
>> On 10/9/2012 5:10 AM, Minchan Kim wrote:
>>> On Mon, Oct 08, 2012 at 05:41:14PM +0200, Rabin Vincent wrote:

>>> Fortunately, recently, Bart sent a patch about that.
>>> http://marc.info/?l=linux-mm&m=134763299016693&w=2
>>>
>>> Could you test above patches in your kernel?
>>> You have to apply [2/4], [3/4], [4/4] and don't need [1/4].
>>
>> AFAIR without patch [1/4], free cma page counter will go below zero
>> and weird thing will happen, so better apply the complete patchset.
>
> I can't understand your point. [1/4] is just fix for correcting trace
> No?

I just remember we ran into such strange negative number of free cma
pages issue without that patch, but maybe the final patchset will simply
fail to apply without the first patch.

Best regards
--
Marek Szyprowski
Samsung Poland R&D Center

2012-10-09 05:03:40

by Minchan Kim

[permalink] [raw]
Subject: Re: CMA and zone watermarks

On Tue, Oct 09, 2012 at 06:53:29AM +0200, Marek Szyprowski wrote:
> Hello,
>
> On 10/9/2012 6:43 AM, Minchan Kim wrote:
> >On Tue, Oct 09, 2012 at 05:12:21AM +0200, Marek Szyprowski wrote:
> >>On 10/9/2012 5:10 AM, Minchan Kim wrote:
> >>>On Mon, Oct 08, 2012 at 05:41:14PM +0200, Rabin Vincent wrote:
>
> >>>Fortunately, recently, Bart sent a patch about that.
> >>>http://marc.info/?l=linux-mm&m=134763299016693&w=2
> >>>
> >>>Could you test above patches in your kernel?
> >>>You have to apply [2/4], [3/4], [4/4] and don't need [1/4].
> >>
> >>AFAIR without patch [1/4], free cma page counter will go below zero
> >>and weird thing will happen, so better apply the complete patchset.
> >
> >I can't understand your point. [1/4] is just fix for correcting trace
> >No?
>
> I just remember we ran into such strange negative number of free cma
> pages issue without that patch, but maybe the final patchset will
> simply fail to apply without the first patch.

I have no objection to apply them all, of course.
But note that if you suffer from such strange bug without [1/4],
it should be dug in without buring into just "fixing of the trace"
comment. As I saw the code without [1/4], I can't find any fault.
Could you elaborat it more if you have any guessing in mind?

>
> Best regards
> --
> Marek Szyprowski
> Samsung Poland R&D Center
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to [email protected]. For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

--
Kind regards,
Minchan Kim

2012-10-09 05:15:57

by Marek Szyprowski

[permalink] [raw]
Subject: Re: CMA and zone watermarks

Hello,

On 10/9/2012 7:07 AM, Minchan Kim wrote:
> On Tue, Oct 09, 2012 at 06:53:29AM +0200, Marek Szyprowski wrote:
>> Hello,
>>
>> On 10/9/2012 6:43 AM, Minchan Kim wrote:
>>> On Tue, Oct 09, 2012 at 05:12:21AM +0200, Marek Szyprowski wrote:
>>>> On 10/9/2012 5:10 AM, Minchan Kim wrote:
>>>>> On Mon, Oct 08, 2012 at 05:41:14PM +0200, Rabin Vincent wrote:
>>
>>>>> Fortunately, recently, Bart sent a patch about that.
>>>>> http://marc.info/?l=linux-mm&m=134763299016693&w=2
>>>>>
>>>>> Could you test above patches in your kernel?
>>>>> You have to apply [2/4], [3/4], [4/4] and don't need [1/4].
>>>>
>>>> AFAIR without patch [1/4], free cma page counter will go below zero
>>>> and weird thing will happen, so better apply the complete patchset.
>>>
>>> I can't understand your point. [1/4] is just fix for correcting trace
>>> No?
>>
>> I just remember we ran into such strange negative number of free cma
>> pages issue without that patch, but maybe the final patchset will
>> simply fail to apply without the first patch.
>
> I have no objection to apply them all, of course.
> But note that if you suffer from such strange bug without [1/4],
> it should be dug in without buring into just "fixing of the trace"
> comment. As I saw the code without [1/4], I can't find any fault.
> Could you elaborate it more if you have any guessing in mind?

I remember that in one version of the Bartek's patches,
page_private(page) has been used directly for getting the migratetype
after a call to __free_one_page() (the same way as
trace_mm_page_pcpu_drain() used it), what resulted in incorrect counting
of free pages. The issue has been fixed then by the patch [1/4].

Now I've check that the next patches use mt variable instead of
page_private(page), so they will simply not apply without [1/4]. No
other issues should be expected. I'm sorry for confusion.

Best regards
--
Marek Szyprowski
Samsung Poland R&D Center

2012-10-09 15:25:50

by Rabin Vincent

[permalink] [raw]
Subject: Re: CMA and zone watermarks

Hi Marek, Minchan,

2012/10/9 Marek Szyprowski <[email protected]>:
> Could You run your test with latest linux-next kernel? There have been some
> patches merged to akpm tree which should fix accounting for free and free
> cma pages. I hope it should fix this issue.

I've tested with the mentioned patches (which seem to have also reached
Linus' tree today) and they appear to resolve the problem.

Thanks.