From patchwork Fri Dec 28 03:00:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 10744103 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 A52EB91E for ; Fri, 28 Dec 2018 03:00:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A26C28DF3 for ; Fri, 28 Dec 2018 03:00:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DADD28DF7; Fri, 28 Dec 2018 03:00:33 +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,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable 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 EF23528DF3 for ; Fri, 28 Dec 2018 03:00:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF4498E002A; Thu, 27 Dec 2018 22:00:31 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C7EA28E0001; Thu, 27 Dec 2018 22:00:31 -0500 (EST) 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 B1E2D8E002A; Thu, 27 Dec 2018 22:00:31 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by kanga.kvack.org (Postfix) with ESMTP id 6B6288E0001 for ; Thu, 27 Dec 2018 22:00:31 -0500 (EST) Received: by mail-pg1-f199.google.com with SMTP id y8so18916231pgq.12 for ; Thu, 27 Dec 2018 19:00:31 -0800 (PST) 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:cc:subject:date :message-id:in-reply-to:references; bh=utqMO7rFICkXWGRPQf4AEPGgKb/tTK2f5Z60c7Pe4V4=; b=rqnpp7rDxx70eXhWgUsCbJAW2XOK2fqjPPFtcfMzaYYXibIVXdGtrHbw/iAuFDZhq0 N4elw/7cpo87hgmhPavgOC/eznaujFyKwhaoU5jdT2nZWFkMvsJMr9DuiSldopOhAsuQ D5OdfDQzizU+eM/pj3QsiBfDcLBnBXQqfDRR9zuiSbdEFvofDHAjyMeq8QoRx8vntBLw ivPYFTHK0j/4lGl4i/1AbLVGV7b0bKmg45qR7S8zpK2eoWaKdHTgcVhhC2rFlADCSVAj Ypa6RxpzLsJUYe5Lq98HBOTzo0SfkeZFwbgig3dxdfokRWiB2TmL8EXpkW0iagfXed42 MfZA== X-Gm-Message-State: AJcUukdPBBHYjz8YUy7jeld08v/51xbMscz+/9+R0a7OAOwMbJJ77Liy zPmYI9u21AZwL9YS1n/79L/D+v0myorjX7pnwTdcKRED+pBwI+HrWeBGqCRnfkJfl2PMjNxx+CE e6/YmeugRDYbBt3hTVffd6NhSEmAEtghfw7Jc62yW0YJnBHvCv48IkS4tXUzDoZKBGKzM5QkamW SIZY3tNtsR4nsCWLzd+RgKoMIh4X4EvbULMBae1o5Zth0YBmmNkvp2q9WCcupeYoO9jzywWQjGy P3FsUVI0AVonlgdnMRTpdBO+8eae47TiyR5CWSv6ZgcsUd9ERqrD1LMWse+NyKwYXhc2ESbdo0e l4kH1t+ddZwFyjSD52mes5TGtIo8mZ3mOjFlGW547H2usloNOMmVITjwqZwH8n1TEoAC1nxiGB6 G X-Received: by 2002:a17:902:c5:: with SMTP id a63mr26344131pla.267.1545966030921; Thu, 27 Dec 2018 19:00:30 -0800 (PST) X-Received: by 2002:a17:902:c5:: with SMTP id a63mr26344052pla.267.1545966029546; Thu, 27 Dec 2018 19:00:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545966029; cv=none; d=google.com; s=arc-20160816; b=B4lMDQyuCUHiiLyA3ZYKtNfiypIId6u0Y4MMLFJN2KXdbN1auaX0tvwgOljxQOrr7I VkaNFf1dXI2XeFszxlJ020+EgVsTfV4O2SlhFIHgY0QUwHeg3PmcSFY2yANsgKDcJWwL LW3PiF2lwAn45OpuD9YvP97geVYLlMvd48Owdl6SH8LR252+2PoLX7xqDfeoB0iW//+s PHVBpwlFNDO8wPYehoUvVGhLiQSOiIO5k2P+3mvyd5Lp1lBXpwlnuYb2Ti5tmkcZyBWO 1gq7jybJx/w9okLSWxPoje//zqAStw/EOfMl+47+eY/esjkPpfPoghPa1p+ctYij3gsO trGw== 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:cc:to:from :dkim-signature; bh=utqMO7rFICkXWGRPQf4AEPGgKb/tTK2f5Z60c7Pe4V4=; b=U+7JRNbzXDUaDgB6T5GZgab5jLz0c8rEIBHxkIOuhnOrKvCgNYuB3te+sTx0Ntq90Y nWfP9mpkkgBW5tcV6iVSRZ2O1UYpkFI+eaV6xcX4hXL3uqpcJjoKErBoHAGtfIPIfd4X H7R2U/FI6B5il/VQvu9yWfODL/Mf1em1LS1xi6loFcXe8JVNZevkbqDmhPcikbBO7H0t 0rMG22kq1+RfK2rCQ92s9SgHuGzVgpyIGXoOMeuHoEuceh87kbbQ3EDzv9yKp8Vh0zYn 3byAoLJsL3QwKlkeroHyf0D35norbV0qkZeJ1ua4FrDZe6uYJoPKP/rZmU/MPoZxX3MA /lGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BUi18dw8; spf=pass (google.com: domain of kernelfans@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=kernelfans@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id j6sor1323955pgq.46.2018.12.27.19.00.29 for (Google Transport Security); Thu, 27 Dec 2018 19:00:29 -0800 (PST) Received-SPF: pass (google.com: domain of kernelfans@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BUi18dw8; spf=pass (google.com: domain of kernelfans@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=kernelfans@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=utqMO7rFICkXWGRPQf4AEPGgKb/tTK2f5Z60c7Pe4V4=; b=BUi18dw8kuhZpD/rEHe5XiZUCnoHtgu1EtYJVs3GNgJE5bQiCQb8cMwdSfpb4IBEJu 8521eV4nMG+0pxmvH906NSRJKw6ftZ82yWJ7DAzQ33eXT0cCdzg7pLzDQyDcYMqDfo5z 4/yvLq1pWWF/xwxTOFmO4Eb2N5an9iNZKMMPXu4f6UnHxWLD3CF/5WMl2uVmgzNppkgN NxMyZuu94WLtOG6o1MTLlgd6PTSUupX07BF9LhcJPhRMOX8n8fYOmpC4+uO+U+MseL3Q bFcnxs/NiF3raRLjTFBhBZpy9We6/+v5t9/RImLkTdicADc0hrKWPEkDqDC3K3xnV4VI 6leA== X-Google-Smtp-Source: ALg8bN6Z4CgnipeBNmTZ9DngS5sCwR81xBZvukBWpEADltwaXqlztHIGPEHhB/RV3HBCQgQohAGy2g== X-Received: by 2002:a63:e445:: with SMTP id i5mr24757805pgk.307.1545966029228; Thu, 27 Dec 2018 19:00:29 -0800 (PST) Received: from mylaptop.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id 202sm80185958pfy.87.2018.12.27.19.00.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 19:00:28 -0800 (PST) From: Pingfan Liu To: linux-acpi@vger.kernel.org, linux-mm@kvack.org, kexec@lists.infradead.org Cc: Pingfan Liu , Tang Chen , "Rafael J. Wysocki" , Len Brown , Andrew Morton , Mike Rapoport , Michal Hocko , Jonathan Corbet , Yaowei Bai , Pavel Tatashin , Nicholas Piggin , Naoya Horiguchi , Daniel Vacek , Mathieu Malaterre , Stefan Agner , Dave Young , Baoquan He , yinghai@kernel.org, vgoyal@redhat.com, linux-kernel@vger.kernel.org Subject: [PATCHv3 1/2] mm/memblock: extend the limit inferior of bottom-up after parsing hotplug attr Date: Fri, 28 Dec 2018 11:00:01 +0800 Message-Id: <1545966002-3075-2-git-send-email-kernelfans@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1545966002-3075-1-git-send-email-kernelfans@gmail.com> References: <1545966002-3075-1-git-send-email-kernelfans@gmail.com> 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 The bottom-up allocation style is introduced to cope with movable_node, where the limit inferior of allocation starts from kernel's end, due to lack of knowledge of memory hotplug info at this early time. But if later, hotplug info has been got, the limit inferior can be extend to 0. 'kexec -c' prefers to reuse this style to alloc mem at lower address, since if the reserved region is beyond 4G, then it requires extra mem (default is 16M) for swiotlb. Signed-off-by: Pingfan Liu Cc: Tang Chen Cc: "Rafael J. Wysocki" Cc: Len Brown Cc: Andrew Morton Cc: Mike Rapoport Cc: Michal Hocko Cc: Jonathan Corbet Cc: Yaowei Bai Cc: Pavel Tatashin Cc: Nicholas Piggin Cc: Naoya Horiguchi Cc: Daniel Vacek Cc: Mathieu Malaterre Cc: Stefan Agner Cc: Dave Young Cc: Baoquan He Cc: yinghai@kernel.org, Cc: vgoyal@redhat.com Cc: linux-kernel@vger.kernel.org --- drivers/acpi/numa.c | 4 ++++ include/linux/memblock.h | 1 + mm/memblock.c | 58 +++++++++++++++++++++++++++++------------------- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c index 2746994..3eea4e4 100644 --- a/drivers/acpi/numa.c +++ b/drivers/acpi/numa.c @@ -462,6 +462,10 @@ int __init acpi_numa_init(void) cnt = acpi_table_parse_srat(ACPI_SRAT_TYPE_MEMORY_AFFINITY, acpi_parse_memory_affinity, 0); + +#if defined(CONFIG_X86) || defined(CONFIG_ARM64) + mark_mem_hotplug_parsed(); +#endif } /* SLIT: System Locality Information Table */ diff --git a/include/linux/memblock.h b/include/linux/memblock.h index aee299a..d89ed9e 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -125,6 +125,7 @@ int memblock_reserve(phys_addr_t base, phys_addr_t size); void memblock_trim_memory(phys_addr_t align); bool memblock_overlaps_region(struct memblock_type *type, phys_addr_t base, phys_addr_t size); +void mark_mem_hotplug_parsed(void); 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); diff --git a/mm/memblock.c b/mm/memblock.c index 81ae63c..a3f5e46 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -231,6 +231,12 @@ __memblock_find_range_top_down(phys_addr_t start, phys_addr_t end, return 0; } +static bool mem_hotmovable_parsed __initdata_memblock; +void __init_memblock mark_mem_hotplug_parsed(void) +{ + mem_hotmovable_parsed = true; +} + /** * memblock_find_in_range_node - find free area in given range and node * @size: size of free area to find @@ -259,7 +265,7 @@ phys_addr_t __init_memblock memblock_find_in_range_node(phys_addr_t size, phys_addr_t end, int nid, enum memblock_flags flags) { - phys_addr_t kernel_end, ret; + phys_addr_t kernel_end, ret = 0; /* pump up @end */ if (end == MEMBLOCK_ALLOC_ACCESSIBLE) @@ -270,34 +276,40 @@ phys_addr_t __init_memblock memblock_find_in_range_node(phys_addr_t size, end = max(start, end); kernel_end = __pa_symbol(_end); - /* - * try bottom-up allocation only when bottom-up mode - * is set and @end is above the kernel image. - */ - if (memblock_bottom_up() && end > kernel_end) { - phys_addr_t bottom_up_start; + if (memblock_bottom_up()) { + phys_addr_t bottom_up_start = start; - /* make sure we will allocate above the kernel */ - bottom_up_start = max(start, kernel_end); - - /* ok, try bottom-up allocation first */ - ret = __memblock_find_range_bottom_up(bottom_up_start, end, - size, align, nid, flags); - if (ret) + if (mem_hotmovable_parsed) { + ret = __memblock_find_range_bottom_up( + bottom_up_start, end, size, align, nid, + flags); return ret; /* - * we always limit bottom-up allocation above the kernel, - * but top-down allocation doesn't have the limit, so - * retrying top-down allocation may succeed when bottom-up - * allocation failed. - * - * bottom-up allocation is expected to be fail very rarely, - * so we use WARN_ONCE() here to see the stack trace if - * fail happens. + * if mem hotplug info is not parsed yet, try bottom-up + * allocation with @end above the kernel image. */ - WARN_ONCE(IS_ENABLED(CONFIG_MEMORY_HOTREMOVE), + } else if (!mem_hotmovable_parsed && end > kernel_end) { + /* make sure we will allocate above the kernel */ + bottom_up_start = max(start, kernel_end); + ret = __memblock_find_range_bottom_up( + bottom_up_start, end, size, align, nid, + flags); + if (ret) + return ret; + /* + * we always limit bottom-up allocation above the + * kernel, but top-down allocation doesn't have + * the limit, so retrying top-down allocation may + * succeed when bottom-up allocation failed. + * + * bottom-up allocation is expected to be fail + * very rarely, so we use WARN_ONCE() here to see + * the stack trace if fail happens. + */ + WARN_ONCE(IS_ENABLED(CONFIG_MEMORY_HOTREMOVE), "memblock: bottom-up allocation failed, memory hotremove may be affected\n"); + } } return __memblock_find_range_top_down(start, end, size, align, nid,