From: Hui Zhu <teawater@gmail.com>
To: akpm@linux-foundation.org, mgorman@suse.de, vbabka@suse.cz,
hannes@cmpxchg.org, rientjes@google.com, iamjoonsoo.kim@lge.com,
sasha.levin@oracle.com, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Cc: teawater@gmail.com, Hui Zhu <zhuhui@xiaomi.com>
Subject: [PATCH] mm/page_alloc: Fix race conditions on getting migratetype in buffered_rmqueue
Date: Sun, 18 Jan 2015 17:17:14 +0800 [thread overview]
Message-ID: <1421572634-3399-1-git-send-email-teawater@gmail.com> (raw)
From: Hui Zhu <zhuhui@xiaomi.com>
To test the patch [1], I use KGTP and a script [2] to show NR_FREE_CMA_PAGES
and gross of cma_nr_free. The values are always not same.
I check the code of pages alloc and free and found that race conditions
on getting migratetype in buffered_rmqueue.
Then I add move the code of getting migratetype inside the zone->lock
protection part.
Because this issue will affect system even if the Linux kernel does't
have [1]. So I post this patch separately.
This patchset is based on fc7f0dd381720ea5ee5818645f7d0e9dece41cb0.
[1] https://lkml.org/lkml/2015/1/18/28
[2] https://github.com/teawater/kgtp/blob/dev/add-ons/cma_free.py
Signed-off-by: Hui Zhu <zhuhui@xiaomi.com>
---
mm/page_alloc.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 7633c50..f3d6922 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1694,11 +1694,12 @@ again:
}
spin_lock_irqsave(&zone->lock, flags);
page = __rmqueue(zone, order, migratetype);
+ if (page)
+ migratetype = get_pageblock_migratetype(page);
+ else
+ goto failed_unlock;
spin_unlock(&zone->lock);
- if (!page)
- goto failed;
- __mod_zone_freepage_state(zone, -(1 << order),
- get_freepage_migratetype(page));
+ __mod_zone_freepage_state(zone, -(1 << order), migratetype);
}
__mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
@@ -1715,6 +1716,8 @@ again:
goto again;
return page;
+failed_unlock:
+ spin_unlock(&zone->lock);
failed:
local_irq_restore(flags);
return NULL;
--
1.9.3
--
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 reply other threads:[~2015-01-18 9:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-18 9:17 Hui Zhu [this message]
2015-01-18 10:19 ` Vlastimil Babka
2015-01-19 2:04 ` Hui Zhu
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=1421572634-3399-1-git-send-email-teawater@gmail.com \
--to=teawater@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=iamjoonsoo.kim@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@suse.de \
--cc=rientjes@google.com \
--cc=sasha.levin@oracle.com \
--cc=vbabka@suse.cz \
--cc=zhuhui@xiaomi.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