From patchwork Fri Mar 19 09:26:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 12150447 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2555CC433DB for ; Fri, 19 Mar 2021 09:26:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9524C64F73 for ; Fri, 19 Mar 2021 09:26:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9524C64F73 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E7D596B0072; Fri, 19 Mar 2021 05:26:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E53BC6B0073; Fri, 19 Mar 2021 05:26:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1BA36B0074; Fri, 19 Mar 2021 05:26:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0085.hostedemail.com [216.40.44.85]) by kanga.kvack.org (Postfix) with ESMTP id B3B886B0072 for ; Fri, 19 Mar 2021 05:26:44 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 777BA180FDDBC for ; Fri, 19 Mar 2021 09:26:44 +0000 (UTC) X-FDA: 77936093886.24.F7F5179 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf05.hostedemail.com (Postfix) with ESMTP id B54AFE0011C3 for ; Fri, 19 Mar 2021 09:26:43 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 7DDE3AC2E; Fri, 19 Mar 2021 09:26:42 +0000 (UTC) From: Oscar Salvador To: Andrew Morton Cc: David Hildenbrand , Michal Hocko , Anshuman Khandual , Vlastimil Babka , Pavel Tatashin , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [PATCH v5 0/5] Allocate memmap from hotadded memory (per device) Date: Fri, 19 Mar 2021 10:26:30 +0100 Message-Id: <20210319092635.6214-1-osalvador@suse.de> X-Mailer: git-send-email 2.13.7 X-Stat-Signature: k9ie9uic3fzw91faug5acsqyc8r9ko93 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: B54AFE0011C3 Received-SPF: none (suse.de>: No applicable sender policy available) receiver=imf05; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: none/none X-HE-Tag: 1616146003-598442 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: Changes from v4 -> v5: - Addressed feedback from David (patch#1) - Tested on x86_64 with different struct page sizes and on large/small memory blocks - Tested on arm64 with 4K, 64K (with and without THP) and with different struct page sizes NOTE: We might need to make this feature and hugetlb-vmemmap feature [1] mutually exclusive. I raised an issue I see in [2]. Hugetlb-vmemmap feature has been withdrawn for the time being due to the need in further changes wrt. locking/freeing context. I will keep an eye, and when the time comes again I will see how the two features play together and how one another can be disabled when needed. Changes from v3 -> v4: - Addressed feedback from David - Wrap memmap_on_memory module thingy with #ifdef on MHP_MEMMAP_ON_MEMORY - Move "depend on MEMORY_HOTPLUG" to MHP_MEMMAP_ON_MEMORY in generic mm/Kconfig - Collect David's Reviewed-bys Changes from v2 -> v3: - Addressed feedback from David - Squash former patch#4 and and patch#5 into patch#1 - Fix config dependency CONFIR_SPARSE_VMEMMAP vs CONFIG_SPARSE_VMEMMAP_ENABLE - Simplify module parameter functions Changes from v1 -> v2 - Addressed feedback from David - Fence off the feature in case struct page size is not multiple of PMD size or pageblock alignment cannot be guaranted - Tested on x86_64 small and large memory_blocks - Tested on arm64 4KB and 64KB page sizes (for some reason I cannot boot my VM with 16KB page size). Arm64 with 4KB page size behaves like x86_64 after [1], which made section size smaller. With 64KB, the feature gets fenced off due to pageblock alignment. Changes from RFCv3 -> v1: - Addressed feedback from David - Re-order patches Changes from v2 -> v3 (RFC): - Re-order patches (Michal) - Fold "mm,memory_hotplug: Introduce MHP_MEMMAP_ON_MEMORY" in patch#1 - Add kernel boot option to enable this feature (Michal) Changes from v1 -> v2 (RFC): - Addressed feedback provided by David - Add a arch_support_memmap_on_memory to be called from mhp_supports_memmap_on_memory, as atm, only ARM, powerpc and x86_64 have altmat support. [1] https://lore.kernel.org/lkml/cover.1611206601.git.sudaraja@codeaurora.org/ Original cover letter: ---- The primary goal of this patchset is to reduce memory overhead of the hot-added memory (at least for SPARSEMEM_VMEMMAP memory model). The current way we use to populate memmap (struct page array) has two main drawbacks: a) it consumes an additional memory until the hotadded memory itself is onlined and b) memmap might end up on a different numa node which is especially true for movable_node configuration. c) due to fragmentation we might end up populating memmap with base pages One way to mitigate all these issues is to simply allocate memmap array (which is the largest memory footprint of the physical memory hotplug) from the hot-added memory itself. SPARSEMEM_VMEMMAP memory model allows us to map any pfn range so the memory doesn't need to be online to be usable for the array. See patch 3 for more details. This feature is only usable when CONFIG_SPARSEMEM_VMEMMAP is set. [Overall design]: Implementation wise we reuse vmem_altmap infrastructure to override the default allocator used by vmemap_populate. memory_block structure gained a new field called nr_vmemmap_pages. This plays well for two reasons: 1) {offline/online}_pages know the difference between start_pfn and buddy_start_pfn, which is start_pfn + nr_vmemmap_pages. In this way all isolation/migration operations are done to within the right range of memory without vmemmap pages. This allows us for a much cleaner handling. 2) In try_remove_memory, we construct a new vmemap_altmap struct with the right information based on memory_block->nr_vmemap_pages, so we end up calling vmem_altmap_free instead of free_pagetable when removing the memory. Oscar Salvador (5): mm,memory_hotplug: Allocate memmap from the added memory range acpi,memhotplug: Enable MHP_MEMMAP_ON_MEMORY when supported mm,memory_hotplug: Add kernel boot option to enable memmap_on_memory x86/Kconfig: Introduce ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE arm64/Kconfig: Introduce ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE Documentation/admin-guide/kernel-parameters.txt | 16 +++ arch/arm64/Kconfig | 3 + arch/x86/Kconfig | 3 + drivers/acpi/acpi_memhotplug.c | 5 +- drivers/base/memory.c | 20 +-- include/linux/memory.h | 8 +- include/linux/memory_hotplug.h | 21 ++- include/linux/memremap.h | 2 +- include/linux/mmzone.h | 5 + mm/Kconfig | 5 + mm/Makefile | 5 +- mm/memory_hotplug.c | 166 +++++++++++++++++++++--- mm/page_alloc.c | 4 +- 13 files changed, 225 insertions(+), 38 deletions(-)