From patchwork Mon May 9 06:27:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12843062 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3368C433EF for ; Mon, 9 May 2022 06:29:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 296C16B0074; Mon, 9 May 2022 02:29:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 245206B0075; Mon, 9 May 2022 02:29:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10F676B0078; Mon, 9 May 2022 02:29:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 019646B0074 for ; Mon, 9 May 2022 02:29:29 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id D21296097E for ; Mon, 9 May 2022 06:29:29 +0000 (UTC) X-FDA: 79445228058.17.1C0694C Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by imf02.hostedemail.com (Postfix) with ESMTP id AC55E80074 for ; Mon, 9 May 2022 06:29:22 +0000 (UTC) Received: by mail-pg1-f169.google.com with SMTP id r192so7022986pgr.6 for ; Sun, 08 May 2022 23:29:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TxGePxN899QZhoK9/ghhqKhjvB6kwBatns9zvkXLNoM=; b=YxJIkB+tjVeh+3RaEuq0lx22G52hqRP2Q41/98aBO7PbNanU0ZAG/2VYybdqoy7A9G NMUXQFOd0c0pmsmXy+HaT2LDFlWv5g5lewOhRall6jZaP7EaHXIRTmKbhLMvQJu8U0Z2 KD0/h6+ozi2Qm+EGZh7LEP+B6OSR1gFw+hOA2mZy2JOIZOdQ9Gu5iF2EblTcQHtyBNHD HFdPX8PW+nM7stUaD0vTKqmz6t8ps5QUjKtNLW/JM7V457xk441c9ZwHf0Uaqa3hQqIJ sD5wJ69vhdY8VHBVEl7SGO6pZjj3slZUUYcA8gL9PtZ4GTtPMNGbsoC7QudoKYbgfAod B3aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TxGePxN899QZhoK9/ghhqKhjvB6kwBatns9zvkXLNoM=; b=0n2t8mnuQ40WhYEw93wp7DCrCk6G1XC2pCkvVjCEpMgxKehqluKZGBJ5uY5bjpP0sa 19HvafHHgHZQQAVmWBVk5tNspL73BLVHDdCx0a0LSNybB0+zHZ2RvCAXrn4v+G2EeSxC ZN1c7pAPa+jK+WlQDINE9zouflpPNG+HZsFnqjqVTQWh0y/W77nS+e+u2B56wOkWY5AE Awf3vsegY+cv+o01yBYJeBn8t20g5Fx1xFwCOktdJ9kjFcxtjzpPUNgXlH3xPBvvmvfS qFLnwBuyfHABp1SkEz+PpJkvTOyXvyMwxjlPnxe6eJMy1LgDMKPMJJBNHNAnXpSBFE68 4jGw== X-Gm-Message-State: AOAM532J8xWSquIkFUa2z2GmGzSLlNHvUSwfHlUnYGPWirCWBMXeZq8T qCkN7adeGp4zDIkIophV38KKqQ== X-Google-Smtp-Source: ABdhPJx/EFqVRRy5eL0t3+AS10kjTooGOitYJZKGi7Xtf2ozkJgteJkT0pgvGVy/dc2m1ku/jQuGXw== X-Received: by 2002:a65:6a16:0:b0:39d:4f3:67e6 with SMTP id m22-20020a656a16000000b0039d04f367e6mr12242601pgu.84.1652077768485; Sun, 08 May 2022 23:29:28 -0700 (PDT) Received: from FVFYT0MHHV2J.bytedance.net ([139.177.225.250]) by smtp.gmail.com with ESMTPSA id k17-20020a170902ba9100b0015e8d4eb2c2sm6162001pls.268.2022.05.08.23.29.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 23:29:28 -0700 (PDT) From: Muchun Song To: corbet@lwn.net, mike.kravetz@oracle.com, akpm@linux-foundation.org, mcgrof@kernel.org, keescook@chromium.org, yzaikin@google.com, osalvador@suse.de, david@redhat.com, masahiroy@kernel.org Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, duanxiongchun@bytedance.com, smuchun@gmail.com, Muchun Song Subject: [PATCH v10 2/4] mm: memory_hotplug: override memmap_on_memory when hugetlb_free_vmemmap=on Date: Mon, 9 May 2022 14:27:01 +0800 Message-Id: <20220509062703.64249-3-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220509062703.64249-1-songmuchun@bytedance.com> References: <20220509062703.64249-1-songmuchun@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: AC55E80074 X-Stat-Signature: 38eqc5drwb9awdmtwqy9kzg41yesyfxp Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=YxJIkB+t; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf02.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1652077762-956126 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: Optimizing HugeTLB vmemmap pages is not compatible with allocating memmap on hot added memory. If "hugetlb_free_vmemmap=on" and memory_hotplug.memmap_on_memory" are both passed on the kernel command line, optimizing hugetlb pages takes precedence. However, the global variable memmap_on_memory will still be set to 1, even though we will not try to allocate memmap on hot added memory. Also introduce mhp_memmap_on_memory() helper to move the definition of "memmap_on_memory" to the scope of CONFIG_MHP_MEMMAP_ON_MEMORY. In the next patch, mhp_memmap_on_memory() will also be exported to be used in hugetlb_vmemmap.c. Signed-off-by: Muchun Song Acked-by: Mike Kravetz --- mm/memory_hotplug.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 111684878fd9..a6101ae402f9 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -42,14 +42,36 @@ #include "internal.h" #include "shuffle.h" +#ifdef CONFIG_MHP_MEMMAP_ON_MEMORY +static int memmap_on_memory_set(const char *val, const struct kernel_param *kp) +{ + if (hugetlb_optimize_vmemmap_enabled()) + return 0; + return param_set_bool(val, kp); +} + +static const struct kernel_param_ops memmap_on_memory_ops = { + .flags = KERNEL_PARAM_OPS_FL_NOARG, + .set = memmap_on_memory_set, + .get = param_get_bool, +}; /* * memory_hotplug.memmap_on_memory parameter */ static bool memmap_on_memory __ro_after_init; -#ifdef CONFIG_MHP_MEMMAP_ON_MEMORY -module_param(memmap_on_memory, bool, 0444); +module_param_cb(memmap_on_memory, &memmap_on_memory_ops, &memmap_on_memory, 0444); MODULE_PARM_DESC(memmap_on_memory, "Enable memmap on memory for memory hotplug"); + +static inline bool mhp_memmap_on_memory(void) +{ + return memmap_on_memory; +} +#else +static inline bool mhp_memmap_on_memory(void) +{ + return false; +} #endif enum { @@ -1263,9 +1285,7 @@ bool mhp_supports_memmap_on_memory(unsigned long size) * altmap as an alternative source of memory, and we do not exactly * populate a single PMD. */ - return memmap_on_memory && - !hugetlb_optimize_vmemmap_enabled() && - IS_ENABLED(CONFIG_MHP_MEMMAP_ON_MEMORY) && + return mhp_memmap_on_memory() && size == memory_block_size_bytes() && IS_ALIGNED(vmemmap_size, PMD_SIZE) && IS_ALIGNED(remaining_size, (pageblock_nr_pages << PAGE_SHIFT)); @@ -2083,7 +2103,7 @@ static int __ref try_remove_memory(u64 start, u64 size) * We only support removing memory added with MHP_MEMMAP_ON_MEMORY in * the same granularity it was added - a single memory block. */ - if (memmap_on_memory) { + if (mhp_memmap_on_memory()) { nr_vmemmap_pages = walk_memory_blocks(start, size, NULL, get_nr_vmemmap_pages_cb); if (nr_vmemmap_pages) {