Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752997AbbF0Cbf (ORCPT ); Fri, 26 Jun 2015 22:31:35 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:33649 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752183AbbF0Cb1 (ORCPT ); Fri, 26 Jun 2015 22:31:27 -0400 Message-ID: <558E0A28.6060607@huawei.com> Date: Sat, 27 Jun 2015 10:27:52 +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: Andrew Morton , "H. Peter Anvin" , Ingo Molnar , "Luck, Tony" , Hanjun Guo , Xiexiuqi , , Kamezawa Hiroyuki , Dave Hansen , Naoya Horiguchi , Vlastimil Babka , Mel Gorman CC: Xishi Qiu , Linux MM , LKML Subject: [RFC v2 PATCH 7/8] mm: add the buddy system interface References: <558E084A.60900@huawei.com> In-Reply-To: <558E084A.60900@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 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4009 Lines: 106 Add the buddy system interface for address range mirroring feature. Use mirrored memory for all kernel allocations. If there is no mirrored pages left, try to use other types pages. Signed-off-by: Xishi Qiu --- include/linux/memblock.h | 1 + mm/memblock.c | 6 +++--- mm/page_alloc.c | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 53be030..8c33ac0 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -81,6 +81,7 @@ int memblock_mark_hotplug(phys_addr_t base, phys_addr_t size); int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size); int memblock_mark_mirror(phys_addr_t base, phys_addr_t size); ulong choose_memblock_flags(void); +extern struct static_key system_has_mirror; #ifdef CONFIG_MEMORY_MIRROR void memblock_mark_migratemirror(void); #endif diff --git a/mm/memblock.c b/mm/memblock.c index 0d0b210..430ad87 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -55,14 +55,14 @@ int memblock_debug __initdata_memblock; #ifdef CONFIG_MOVABLE_NODE bool movable_node_enabled __initdata_memblock = false; #endif -static bool system_has_some_mirror __initdata_memblock = false; +struct static_key system_has_mirror = STATIC_KEY_INIT; static int memblock_can_resize __initdata_memblock; static int memblock_memory_in_slab __initdata_memblock = 0; static int memblock_reserved_in_slab __initdata_memblock = 0; ulong __init_memblock choose_memblock_flags(void) { - return system_has_some_mirror ? MEMBLOCK_MIRROR : MEMBLOCK_NONE; + return static_key_false(&system_has_mirror) ? MEMBLOCK_MIRROR : MEMBLOCK_NONE; } /* inline so we don't get a warning when pr_debug is compiled out */ @@ -814,7 +814,7 @@ int __init_memblock memblock_clear_hotplug(phys_addr_t base, phys_addr_t size) */ int __init_memblock memblock_mark_mirror(phys_addr_t base, phys_addr_t size) { - system_has_some_mirror = true; + static_key_slow_inc(&system_has_mirror); return memblock_setclr_flag(base, size, 1, MEMBLOCK_MIRROR); } diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 4c5bc50..8a6125e 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1033,6 +1033,9 @@ static int fallbacks[MIGRATE_TYPES][4] = { [MIGRATE_UNMOVABLE] = { MIGRATE_RECLAIMABLE, MIGRATE_MOVABLE, MIGRATE_RESERVE }, [MIGRATE_RECLAIMABLE] = { MIGRATE_UNMOVABLE, MIGRATE_MOVABLE, MIGRATE_RESERVE }, [MIGRATE_MOVABLE] = { MIGRATE_RECLAIMABLE, MIGRATE_UNMOVABLE, MIGRATE_RESERVE }, +#ifdef CONFIG_MEMORY_MIRROR + [MIGRATE_MIRROR] = { MIGRATE_RESERVE }, /* Never used */ +#endif #ifdef CONFIG_CMA [MIGRATE_CMA] = { MIGRATE_RESERVE }, /* Never used */ #endif @@ -1295,6 +1298,15 @@ retry_reserve: page = __rmqueue_smallest(zone, order, migratetype); if (unlikely(!page) && migratetype != MIGRATE_RESERVE) { + /* + * If there is no mirrored memory left, alloc other types + * memory. But we should not change the pageblock's + * migratetype between mirror and others, so just use + * MIGRATE_RECLAIMABLE to retry + */ + if (is_migrate_mirror(migratetype)) + return __rmqueue(zone, order, MIGRATE_RECLAIMABLE); + if (migratetype == MIGRATE_MOVABLE) page = __rmqueue_cma_fallback(zone, order); @@ -2872,6 +2884,13 @@ __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 + /* Alloc mirrored memory for kernel */ + if (static_key_false(&system_has_mirror) + && !(gfp_mask & __GFP_MOVABLE)) + ac.migratetype = MIGRATE_MIRROR; +#endif + retry_cpuset: cpuset_mems_cookie = read_mems_allowed_begin(); -- 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/