From patchwork Tue Jul 24 23:55:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Tatashin X-Patchwork-Id: 10543339 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EFCE714BC for ; Tue, 24 Jul 2018 23:55:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFF6929769 for ; Tue, 24 Jul 2018 23:55:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3058297F1; Tue, 24 Jul 2018 23:55:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C3D829769 for ; Tue, 24 Jul 2018 23:55:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CCAC56B0007; Tue, 24 Jul 2018 19:55:45 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C289A6B0008; Tue, 24 Jul 2018 19:55:45 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A52DA6B000A; Tue, 24 Jul 2018 19:55:45 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ua0-f197.google.com (mail-ua0-f197.google.com [209.85.217.197]) by kanga.kvack.org (Postfix) with ESMTP id 75E7F6B0007 for ; Tue, 24 Jul 2018 19:55:45 -0400 (EDT) Received: by mail-ua0-f197.google.com with SMTP id m10-v6so1840020uao.9 for ; Tue, 24 Jul 2018 16:55:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:subject:date:message-id :in-reply-to:references; bh=I2FasBF0aIFRoHs4rlBGSdoIJv5z2OYszEDfER7UDpk=; b=CPbTLx4kNmxK9Kui0r2joG4jbmSjPh3zxQbkL73yUJn8MpTsyKyOuedWW5gYDe4CBR ENYHvwDP17jfpZdAitKjczfYEcoQ5ohHPKgK3W5PQnP8EG6ngWCGzI7HmKwDBXEtYzty I7NODdFsdswV2Jv17e29MsESQmRRqeijRI6E3wOAcErJRbUj3kso+jYM9TWMnBb6eYxO SNZzaTcb2Zbfu51aucq0HB9aJVPQH8Prm25JlXCpVRBQ2NK5eWeJFgL5GEtkKhZCTPCe D3H1R75MZMmkDp0sywybia0cf3avzrXeLMWT6hlzkivxzthkKWrakVFdk6eCDoUijqi/ uvBw== X-Gm-Message-State: AOUpUlGhz0sLWxDMfQA+DPHQOGqKNB5HhheYoEcwocp7uqYXFaCOJDgq FhgSjFHFGV8/VRdwnmTHG++6HgFZE/lC123e7y3yi66mxvAHpLFnALc024iFJ75X5i/4Hklvr4N jaKtBz+DMPn9CjlrCYKqRQ7VuI5pvRKXd5RqJ//OF2nInqZT2bkM/Lv5NU/ZO94MpCg== X-Received: by 2002:a9f:30c5:: with SMTP id k5-v6mr12970628uab.13.1532476545167; Tue, 24 Jul 2018 16:55:45 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdwh1V9w+Pdf/phoGQgRNA97eMYrRzoJZvwm941vBHB6mnSqWXGOGUbbCms0hblqjlUk4EE X-Received: by 2002:a9f:30c5:: with SMTP id k5-v6mr12970613uab.13.1532476544509; Tue, 24 Jul 2018 16:55:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532476544; cv=none; d=google.com; s=arc-20160816; b=d+DANWDwtffF0Id+ihhMkP/sViHMCWZaip2icD6gyMoWqsK2P+lICc+LHuqnuMOELU ad4TuNfCz1XhMqlUw9rWNw5t21DF1ViyWHuhqRwqg89o6wQEmdmX1qjN5gTdP6Q5AWVH dG1KC2T1W5qdPwOvrxOMYFBpABXvwrkZg01kDpGjYUOGYrTshdNejtCiwe3rKEnNz423 NiF+dIyG5u/Sfxl1bx19Goh8T9zGQryCyYgMcimXho686JY6SVB6I1HeD+v66W4Y9/Cl KL3eBiDHegVI2BDJWT/TKl/QRe9XnxnXf4gwAerNT+7/Fl4F+RVr73pX4mTyMoauuglj dSDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-authentication-results; bh=I2FasBF0aIFRoHs4rlBGSdoIJv5z2OYszEDfER7UDpk=; b=Db4guqs312J5sV3BbWbzq50FU2bfXDsv3k+xR8Nrj3giEKXOnaHPgUC9NLocC3iZbU MBSE5sFE/CXjpFlvyjQ993i54OCjGkPbh3rtm0da6cGyfSCrm/5woYVWFPfrc5uSW2cB QcnQ3UHoGchsjgR95uQKlWiJc2xgeIGUfgTsnddMuD7twBv/FA842MbtyXOgMwXjbZ99 GargozOrRASwbbi212HFsk8/EjnSrecOedArMkQrY1UZ11SpRM4l3ZKuUsk+3RfyNjdN skUqj9esxI2OO0r6Afyg4LZAebRW+5b2456tROJ+AGkyqsgyBA9Y1Qm5ia8fy2+4jEzQ Mglg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=sY3stGZJ; spf=pass (google.com: domain of pasha.tatashin@oracle.com designates 156.151.31.86 as permitted sender) smtp.mailfrom=pasha.tatashin@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from userp2130.oracle.com (userp2130.oracle.com. [156.151.31.86]) by mx.google.com with ESMTPS id 11-v6si6259254uaf.51.2018.07.24.16.55.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Jul 2018 16:55:44 -0700 (PDT) Received-SPF: pass (google.com: domain of pasha.tatashin@oracle.com designates 156.151.31.86 as permitted sender) client-ip=156.151.31.86; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=sY3stGZJ; spf=pass (google.com: domain of pasha.tatashin@oracle.com designates 156.151.31.86 as permitted sender) smtp.mailfrom=pasha.tatashin@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w6ONrqAj101316; Tue, 24 Jul 2018 23:55:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=I2FasBF0aIFRoHs4rlBGSdoIJv5z2OYszEDfER7UDpk=; b=sY3stGZJgwoP+W3pJRbD/NC+RoBKNS5IrCOjVIrYY/R5O9A+0tF43xoXv7tQ153cgchf P1Yz+SzQWVKpmFCDnGBxsCN/snGW4/rCkzNkJ1NT6JKbFOLFV8/+Gj7NBKr+QuFZVqrL kEVymq6LRn+jEOvo1Du0v9FJ4y2fEZ5Qd10uD5TJy/bFZNNO8t3DW6Xz3gaOmYWVfF2r bBO8Zvjyy4SZ0S1KgnVPEXXahKR22R3BAfTWcfufYETss6r8OQi2fTPRvnNQieVyji5/ vo+EreX3NGb3atY0LEHZkFYOxgaeWspsFToJSGPTIKqb+BLXlXjbaQizhpO8XiaBmJ1P sw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2kbv8t394f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 Jul 2018 23:55:36 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w6ONtZvV003816 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 Jul 2018 23:55:35 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w6ONtVaQ019125; Tue, 24 Jul 2018 23:55:31 GMT Received: from localhost.localdomain (/73.69.118.222) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 24 Jul 2018 16:55:31 -0700 From: Pavel Tatashin To: steven.sistare@oracle.com, daniel.m.jordan@oracle.com, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, kirill.shutemov@linux.intel.com, mhocko@suse.com, linux-mm@kvack.org, dan.j.williams@intel.com, jack@suse.cz, jglisse@redhat.com, jrdr.linux@gmail.com, bhe@redhat.com, gregkh@linuxfoundation.org, vbabka@suse.cz, richard.weiyang@gmail.com, dave.hansen@intel.com, rientjes@google.com, mingo@kernel.org, osalvador@techadventures.net, pasha.tatashin@oracle.com, abdhalee@linux.vnet.ibm.com, mpe@ellerman.id.au Subject: [PATCH 3/3] mm: move mirrored memory specific code outside of memmap_init_zone Date: Tue, 24 Jul 2018 19:55:20 -0400 Message-Id: <20180724235520.10200-4-pasha.tatashin@oracle.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724235520.10200-1-pasha.tatashin@oracle.com> References: <20180724235520.10200-1-pasha.tatashin@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8964 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807240248 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP memmap_init_zone, is getting complex, because it is called from different contexts: hotplug, and during boot, and also because it must handle some architecture quirks. One of them is mirroed memory. Move the code that decides whether to skip mirrored memory outside of memmap_init_zone, into a separate function. Signed-off-by: Pavel Tatashin Reviewed-by: Oscar Salvador --- mm/page_alloc.c | 70 ++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 86c678cec6bd..d7dce4ccefd5 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5454,6 +5454,29 @@ void __ref build_all_zonelists(pg_data_t *pgdat) #endif } +/* If zone is ZONE_MOVABLE but memory is mirrored, it is an overlapped init */ +static inline bool overlap_memmap_init(unsigned long zone, unsigned long *pfn) +{ +#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP + static struct memblock_region *r; + + if (mirrored_kernelcore && zone == ZONE_MOVABLE) { + if (!r || *pfn >= memblock_region_memory_end_pfn(r)) { + for_each_memblock(memory, r) { + if (*pfn < memblock_region_memory_end_pfn(r)) + break; + } + } + if (*pfn >= memblock_region_memory_base_pfn(r) && + memblock_is_mirror(r)) { + *pfn = memblock_region_memory_end_pfn(r); + return true; + } + } +#endif + return false; +} + /* * Initially all pages are reserved - free ones are freed * up by free_all_bootmem() once the early boot process is @@ -5463,12 +5486,8 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, unsigned long start_pfn, enum memmap_context context, struct vmem_altmap *altmap) { - unsigned long end_pfn = start_pfn + size; - unsigned long pfn; + unsigned long pfn, end_pfn = start_pfn + size; struct page *page; -#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP - struct memblock_region *r = NULL, *tmp; -#endif if (highest_memmap_pfn < end_pfn - 1) highest_memmap_pfn = end_pfn - 1; @@ -5485,39 +5504,17 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, * There can be holes in boot-time mem_map[]s handed to this * function. They do not exist on hotplugged memory. */ - if (context != MEMMAP_EARLY) - goto not_early; - - if (!early_pfn_valid(pfn)) - continue; - if (!early_pfn_in_nid(pfn, nid)) - continue; - -#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP - /* - * Check given memblock attribute by firmware which can affect - * kernel memory layout. If zone==ZONE_MOVABLE but memory is - * mirrored, it's an overlapped memmap init. skip it. - */ - if (mirrored_kernelcore && zone == ZONE_MOVABLE) { - if (!r || pfn >= memblock_region_memory_end_pfn(r)) { - for_each_memblock(memory, tmp) - if (pfn < memblock_region_memory_end_pfn(tmp)) - break; - r = tmp; - } - if (pfn >= memblock_region_memory_base_pfn(r) && - memblock_is_mirror(r)) { - /* already initialized as NORMAL */ - pfn = memblock_region_memory_end_pfn(r); + if (context == MEMMAP_EARLY) { + if (!early_pfn_valid(pfn)) continue; - } + if (!early_pfn_in_nid(pfn, nid)) + continue; + if (overlap_memmap_init(zone, &pfn)) + continue; + if (defer_init(nid, pfn, end_pfn)) + break; } -#endif - if (defer_init(nid, pfn, end_pfn)) - break; -not_early: page = pfn_to_page(pfn); __init_single_page(page, pfn, zone, nid); if (context == MEMMAP_HOTPLUG) @@ -5534,9 +5531,6 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, * can be created for invalid pages (for alignment) * check here not to call set_pageblock_migratetype() against * pfn out of zone. - * - * Please note that MEMMAP_HOTPLUG path doesn't clear memmap - * because this is done early in sparse_add_one_section */ if (!(pfn & (pageblock_nr_pages - 1))) { set_pageblock_migratetype(page, MIGRATE_MOVABLE);