Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1921898iob; Fri, 29 Apr 2022 16:30:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwiyGQ2C8V2bmWPYehkR0MmuC+BwvavoY3pxCw+kZl/2Lf3oT/QsRyGuIj6/3F7Ipd5dQcE X-Received: by 2002:a17:90a:e641:b0:1da:43b8:95b7 with SMTP id ep1-20020a17090ae64100b001da43b895b7mr1524693pjb.180.1651275033392; Fri, 29 Apr 2022 16:30:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651275033; cv=none; d=google.com; s=arc-20160816; b=gHF+/4kF7ef8EM2ATbWrebeXZE9k9imXK9fi9RBGcxVzFgKmRdXKjCCQFxF3Y6RjDM oNbYC8XMMYHsGte8osaqDSTSfbOCKrQCY32ojJsWM9IrlcvzqRHYQSWd0leMC+dRk8dA YeVma0EEUlvVEZs/WQ7Cr+4UK4Z+9i+lVZOaTkFhLY/Jj1IgPc87QaIdSmhdBoE5CA7c 1/AgXB9YfrTURW2Rr0dIksnuF6fuo6uZiGEhiDaF/Mrn7sZ28G8ujhSaactHUJaB8A3T L9d4ABv5GJYIE98nktjWkTr60ES/n1LSAjK0VT9o/lnYvVIqcT2iWfACX3ZAxqsv7iX3 Tzcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nJJ2yjd2/4fpAJdLzUZPduPx0rYtfHlVNZ/74R+S6Q4=; b=AQQvs0RzyKetZLHfX/qpSfLRtEkh0zC6AyN/BaSJlr8AMfZHVVB16loFFtQ0vK6Fzw 3M0ZElkSBggv1dyjFW/fJbi/MFGVP2QVhs52vgsJ4HuohKDpv4NWLc1D7nPs/E6ExL6W SeZhk8qI+zF4DKqOd/rv+WMYPk97ZVJCyOYlLy4MCX3A6gVcfSH0YVlgdq1sWcWx6VkC EkJN5DHPl3VZpcaaqg9o089UV/TqlWui2VucvYtLcvlrh53eQNrIMORX1WXdPHXahE20 0AgT+7SCqW4loVoLKYzykQwrd9eT9EDi+dvegEF4ZK8vEI/7+vIl0mY1aY0UiWuHBvnz 9qDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=LQd2JOMl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x21-20020a17090300d500b0015b2e9ae552si7168553plc.276.2022.04.29.16.30.17; Fri, 29 Apr 2022 16:30:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=LQd2JOMl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359007AbiD2MWE (ORCPT + 99 others); Fri, 29 Apr 2022 08:22:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358999AbiD2MWC (ORCPT ); Fri, 29 Apr 2022 08:22:02 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2357EC866F for ; Fri, 29 Apr 2022 05:18:44 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id r9so6955331pjo.5 for ; Fri, 29 Apr 2022 05:18:44 -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=nJJ2yjd2/4fpAJdLzUZPduPx0rYtfHlVNZ/74R+S6Q4=; b=LQd2JOMlImsT/p4HS41D/RtsHSJZpYb3+IgaBw60oQMRt6xScDB2h3Cyv1Qgjeu9FP b8bzT9WGQeRMlS7OuyfciF4JYpY8ls0XRS1bKUgVCVt5DBlLWj4lG+cPRGPpcVC2XtTE F5v37DJLI/0QKaTs+yal0pE+KhbU0B9ch6P6DRcQpgXDBaPiwrd1Lwpe9GtDh2M4ark7 0cdobSG90wKyu0bVuPGgv2HxsN6B3wFfiXNClO//SmKe8T/SdM6ObvpJNJ6Ud6c4AvYl WMft94Lmfu0J6U9LbnBiK/xoT5tuljWb9LLQSJSXyxlTEzT03Gjl4YkVbeUyzhylRQls MhPg== 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=nJJ2yjd2/4fpAJdLzUZPduPx0rYtfHlVNZ/74R+S6Q4=; b=uctEVRZS9vqQ+lSN1c77Vjb/omitdS0fmx+6LffMTaApCEmXyu0rsFhupzLjFI8hLR +0yRT+r/nkNtRBZ2YpWkRL64aEHQsGof+jzWlBLwkT3hWwVLKR1NvLTXHOS+XEau3XEo efCq/5zM1rrkRY4H4GanhI5srnzbCqTtqC9HfhQ1pQXj3N3VfboE4PbqLfTSSwwzK0+X 7fPVOPg+wYw3M9VEEXX3j6BIYE9rNnR8BdX67wBcOp4D5a67lnEXAC7Zfc7UxDf6VMDK 4nYU1ZfZ7Tu4LhdH/fYh8PP3m5l1l5Qu/mRAFbjXVOJpviMxqr276Dk6yyxf9360+kQp y7xA== X-Gm-Message-State: AOAM5302me71BrT6Ofsb3tqtszBFHf2sy9bs4QCMq+Nd1gC3W8H8vQez 2Szik/LTAdBscHt3I8nAvIjRBQ== X-Received: by 2002:a17:90a:dd46:b0:1b8:8:7303 with SMTP id u6-20020a17090add4600b001b800087303mr3592108pjv.197.1651234723558; Fri, 29 Apr 2022 05:18:43 -0700 (PDT) Received: from FVFYT0MHHV2J.bytedance.net ([139.177.225.239]) by smtp.gmail.com with ESMTPSA id k11-20020a056a00168b00b004f7e1555538sm3101421pfc.190.2022.04.29.05.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 05:18:43 -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 v9 2/4] mm: memory_hotplug: override memmap_on_memory when hugetlb_free_vmemmap=on Date: Fri, 29 Apr 2022 20:18:14 +0800 Message-Id: <20220429121816.37541-3-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220429121816.37541-1-songmuchun@bytedance.com> References: <20220429121816.37541-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When "hugetlb_free_vmemmap=on" and "memory_hotplug.memmap_on_memory" are both passed to boot cmdline, the variable of "memmap_on_memory" will be set to 1 even if the vmemmap pages will not be allocated from the hotadded memory since the former takes precedence over the latter. In the next patch, we want to enable or disable the feature of freeing vmemmap pages of HugeTLB via sysctl. We need a way to know if the feature of memory_hotplug.memmap_on_memory is enabled when enabling the feature of freeing vmemmap pages since those two features are not compatible, however, the variable of "memmap_on_memory" cannot indicate this nowadays. Do not set "memmap_on_memory" to 1 when both parameters are passed to cmdline, in this case, "memmap_on_memory" could indicate if this feature is enabled by the users. 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 --- 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) { -- 2.11.0