From patchwork Mon Jul 21 03:46:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 33944 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f200.google.com (mail-pd0-f200.google.com [209.85.192.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 41F4720492 for ; Mon, 21 Jul 2014 03:59:39 +0000 (UTC) Received: by mail-pd0-f200.google.com with SMTP id w10sf40073324pde.7 for ; Sun, 20 Jul 2014 20:59:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=hczXonTgV8LeFKndTtGGhd3l/rUg8NmFxzPOIF7jMdA=; b=A5FmkL6auBcS5H3jcbtmaIpr+uQBnYaCDYSNA3FP5LsMn5Mc8E88U81ZWEdPTCr53z 26gHBCtsSxh1/Iwffi49eV//O0qv4aC9Sal5hq2zR+qt2PKVUoEWnPf0E0THsizFcaf2 x5hpWS7+d9+RqPdTje+/VTb4nvRws1zNhCtOIqkWhGC+8H22pRj/aQpQnQYh97fMLO6N 7yBlh4w8WXAqfpxVhRS7CGqrsemAYF6qcNnP7aQRi6UyxJnZhes6A3ZYi9mhDPlP87ho ufwTFiQmHgCWvdxXPIevJgzSt7wAVma09qwkezrssUzNVIUYp2w12/WD0ygDI0rjlo9f An0A== X-Gm-Message-State: ALoCoQmLZog/KUFVb9L2rbV0RjdDRjoXcAX5irTmho1O4bwtwhsZvGJzUlWJIXZo2ymgfqURYUBg X-Received: by 10.66.216.161 with SMTP id or1mr11536048pac.38.1405915178547; Sun, 20 Jul 2014 20:59:38 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.109.245 with SMTP id l108ls1787308qgf.83.gmail; Sun, 20 Jul 2014 20:59:38 -0700 (PDT) X-Received: by 10.52.244.81 with SMTP id xe17mr22091055vdc.24.1405915178398; Sun, 20 Jul 2014 20:59:38 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id yy7si10637745vdb.10.2014.07.20.20.59.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 20 Jul 2014 20:59:38 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id ij19so11267224vcb.39 for ; Sun, 20 Jul 2014 20:59:38 -0700 (PDT) X-Received: by 10.52.0.177 with SMTP id 17mr22186811vdf.12.1405915178294; Sun, 20 Jul 2014 20:59:38 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp80063vcb; Sun, 20 Jul 2014 20:59:37 -0700 (PDT) X-Received: by 10.70.42.38 with SMTP id k6mr5612761pdl.120.1405915177464; Sun, 20 Jul 2014 20:59:37 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v1si6451733pdn.271.2014.07.20.20.59.36 for ; Sun, 20 Jul 2014 20:59:36 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752702AbaGUD5A (ORCPT + 9 others); Sun, 20 Jul 2014 23:57:00 -0400 Received: from szxga01-in.huawei.com ([119.145.14.64]:25256 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751720AbaGUD46 (ORCPT ); Sun, 20 Jul 2014 23:56:58 -0400 Received: from 172.24.2.119 (EHLO lggeml420-hub.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BYZ66470; Mon, 21 Jul 2014 11:56:45 +0800 (CST) Received: from kernel-host.huawei (10.107.197.247) by lggeml420-hub.china.huawei.com (10.72.61.115) with Microsoft SMTP Server id 14.3.158.1; Mon, 21 Jul 2014 11:56:31 +0800 From: Wang Nan To: Ingo Molnar , Yinghai Lu , "Mel Gorman" , Andrew Morton , "Dave Hansen" , Zhang Yanfei CC: , , , , , , , Subject: [PATCH v2 1/7] memory-hotplug: add zone_for_memory() for selecting zone for new memory Date: Mon, 21 Jul 2014 11:46:36 +0800 Message-ID: <1405914402-66212-2-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.4 In-Reply-To: <1405914402-66212-1-git-send-email-wangnan0@huawei.com> References: <1405914402-66212-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.197.247] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: wangnan0@huawei.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch introduces a zone_for_memory function in arch independent code for arch_add_memory() using. Many arch_add_memory() function simply selects ZONE_HIGHMEM or ZONE_NORMAL and add new memory into it. However, with the existance of ZONE_MOVABLE, the selection method should be carefully considered: if new, higher memory is added after ZONE_MOVABLE is setup, the default zone and ZONE_MOVABLE may overlap each other. should_add_memory_movable() checks the status of ZONE_MOVABLE. If it has already contain memory, compare the address of new memory and movable memory. If new memory is higher than movable, it should be added into ZONE_MOVABLE instead of default zone. Signed-off-by: Wang Nan Cc: Zhang Yanfei Cc: Dave Hansen --- include/linux/memory_hotplug.h | 1 + mm/memory_hotplug.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 010d125..3de3d02 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -258,6 +258,7 @@ static inline void remove_memory(int nid, u64 start, u64 size) {} extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, void *arg, int (*func)(struct memory_block *, void *)); extern int add_memory(int nid, u64 start, u64 size); +extern int zone_for_memory(int nid, u64 start, u64 size, int zone_default); extern int arch_add_memory(int nid, u64 start, u64 size); extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); extern bool is_memblock_offlined(struct memory_block *mem); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 469bbf5..348fda7 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1156,6 +1156,34 @@ static int check_hotplug_memory_range(u64 start, u64 size) return 0; } +/* + * If movable zone has already been setup, newly added memory should be check. + * If its address is higher than movable zone, it should be added as movable. + * Without this check, movable zone may overlap with other zone. + */ +static int should_add_memory_movable(int nid, u64 start, u64 size) +{ + unsigned long start_pfn = start >> PAGE_SHIFT; + pg_data_t *pgdat = NODE_DATA(nid); + struct zone *movable_zone = pgdat->node_zones + ZONE_MOVABLE; + + if (zone_is_empty(movable_zone)) + return 0; + + if (movable_zone->zone_start_pfn <= start_pfn) + return 1; + + return 0; +} + +int zone_for_memory(int nid, u64 start, u64 size, int zone_default) +{ + if (should_add_memory_movable(nid, start, size)) + return ZONE_MOVABLE; + + return zone_default; +} + /* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ int __ref add_memory(int nid, u64 start, u64 size) {