Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932135AbbFDNJq (ORCPT ); Thu, 4 Jun 2015 09:09:46 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:16019 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932075AbbFDNJn (ORCPT ); Thu, 4 Jun 2015 09:09:43 -0400 Message-ID: <55704CC4.8040707@huawei.com> Date: Thu, 4 Jun 2015 21:04:04 +0800 From: Xishi Qiu User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 To: Xishi Qiu , Andrew Morton , , Yinghai Lu , "H. Peter Anvin" , Thomas Gleixner , , Xiexiuqi , Hanjun Guo , "Luck, Tony" CC: Linux MM , LKML Subject: [RFC PATCH 10/12] mm: add the buddy system interface References: <55704A7E.5030507@huawei.com> In-Reply-To: <55704A7E.5030507@huawei.com> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.25.179] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020205.55704CCF.036F,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 988c3f09e69dc9fbc48c50cb2a2183bd Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2652 Lines: 93 Add the buddy system interface for address range mirroring feature. Allocate mirrored pages in MIGRATE_MIRROR list. If there is no mirrored pages left, use other types pages. Signed-off-by: Xishi Qiu --- mm/page_alloc.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index d4d2066..0fb55288 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -599,6 +599,26 @@ static inline bool is_mirror_pfn(unsigned long pfn) return false; } + +static inline bool change_to_mirror(gfp_t gfp_flags, int high_zoneidx) +{ + /* + * Do not alloc mirrored memory below 4G, because 0-4G is + * all mirrored by default, and the list is always empty. + */ + if (high_zoneidx < ZONE_NORMAL) + return false; + + /* Alloc mirrored memory for only kernel */ + if (gfp_flags & __GFP_MIRROR) + return true; + + /* Alloc mirrored memory for both user and kernel */ + if (sysctl_mirrorable) + return true; + + return false; +} #endif /* @@ -1796,7 +1816,10 @@ struct page *buffered_rmqueue(struct zone *preferred_zone, WARN_ON_ONCE(order > 1); } spin_lock_irqsave(&zone->lock, flags); - page = __rmqueue(zone, order, migratetype); + if (is_migrate_mirror(migratetype)) + page = __rmqueue_smallest(zone, order, migratetype); + else + page = __rmqueue(zone, order, migratetype); spin_unlock(&zone->lock); if (!page) goto failed; @@ -2928,6 +2951,11 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order, if (IS_ENABLED(CONFIG_CMA) && ac.migratetype == MIGRATE_MOVABLE) alloc_flags |= ALLOC_CMA; +#ifdef CONFIG_MEMORY_MIRROR + if (change_to_mirror(gfp_mask, ac.high_zoneidx)) + ac.migratetype = MIGRATE_MIRROR; +#endif + retry_cpuset: cpuset_mems_cookie = read_mems_allowed_begin(); @@ -2943,9 +2971,19 @@ retry_cpuset: /* First allocation attempt */ alloc_mask = gfp_mask|__GFP_HARDWALL; +retry: page = get_page_from_freelist(alloc_mask, order, alloc_flags, &ac); if (unlikely(!page)) { /* + * If there is no mirrored memory, we will alloc other + * types memory. + */ + if (is_migrate_mirror(ac.migratetype)) { + ac.migratetype = gfpflags_to_migratetype(gfp_mask); + goto retry; + } + + /* * Runtime PM, block IO and its error handling path * can deadlock because I/O on the device might not * complete. -- 2.0.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/