Message ID | 20230613-vv-kmem_memmap-v1-1-f6de9c6af2c6@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp944823vqr; Thu, 15 Jun 2023 15:14:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7uAZh2CphzPYvG4XnYyx3VcG7MJtBVCfJ7nnjRmPYRd7NDUwo+eqpU2yqplS1rEFoDpoqV X-Received: by 2002:aa7:d4d2:0:b0:514:9b60:ea65 with SMTP id t18-20020aa7d4d2000000b005149b60ea65mr102720edr.16.1686867260245; Thu, 15 Jun 2023 15:14:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686867260; cv=none; d=google.com; s=arc-20160816; b=pkmTKzyYDAX/AYoDX8IqOCJ+DQRB9QhLb7L8bqdJKAnq56VGCBItMnApXx6RUw7e5l Yu7S81tARzMPQUzNkYKtW078/Ie4F9BdvH1SnPdpLSE/9M/madBKFosnY0hro1vgCAxz iyyTvlVd6jllrCWK7if+oCMjhAf9sJJ9bsA/7T7qNZW84+R7skupF63LZwe/L7ofQT/N GLUjhf3FkgGN2vXn5CQtO47P+ooKDKgbMdmzbaBXXrP8h6twmY7u8XOluYRBuxWLyEV5 4QIguLCJsas8WUyX5naLHRhVNXqQAvxpI7RbiELDVsucld2WuHedX1HTuBtm8Wq91wh6 bKyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=rj4bV30cPb9K9sKsHExCZ8luQEyBWvqpIuDdC97URtA=; b=VaFqwdZEmx0Vj0dGYeoaqVSsqcCcyLmA+r2vw9W0wR67ZLEt1dwmDci+iqWvpD5TwF 9EVP1GDKywOzgj0DT1w/exZh5+S3wqMowxrSL2HvhuFXHKbQsXwa7hxGH9KHtgJJDSQc kEjzj+uKQENi1tGPYcivnQvX6/UDg3XO/wW/kO0RSIQMQQRIIW5el3+D8HwDifj+vxeX F/D35faoIiyzsqafiAQWChQNCVCHBKBreoWzpbt/lgUyQY8+r8x9dhkMbyi5tugIPQg/ tA1Qgm/ULS1W1nDvm4RPFZYg//M9AUGtR5izb9fJ54ywKuogv9pDNocwIehjRRRx1N90 8DIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jJRSesBq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i14-20020a056402054e00b00516a29f61acsi10784535edx.649.2023.06.15.15.13.55; Thu, 15 Jun 2023 15:14:20 -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=@intel.com header.s=Intel header.b=jJRSesBq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237188AbjFOWBP (ORCPT <rfc822;maxin.john@gmail.com> + 99 others); Thu, 15 Jun 2023 18:01:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232139AbjFOWBG (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 15 Jun 2023 18:01:06 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB5F9296C; Thu, 15 Jun 2023 15:01:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686866464; x=1718402464; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=y9Fdd4CaXjYhM8c/kYRc/ffM8uFuEd3rHTJq5W9ozIE=; b=jJRSesBqLUd0urCv9o194jwNNzu4qMqaGTDmQ4n4qnPNrnMSmuTAR86q BP2sh/aOYCumaxuy+oVXIvRhS0YcejEucDVx7xePs5XnvWQtof6HULkgG jfjVfhj2LzMqtcwWNkdQBD0tEgEdXTLbvZlFuFBmnQ4pEW8CvkDeRnAaq zkxQKhTPjVHlsvDkYeqCynTH3a7/T1ZB3Lv6DOlbs1ZeDlUUlFx/glKyK 6JIM9b26z5NEfqYAfXvxTq2QLvjiI+5GuPS4spQrr0moNG6I/i+IRd+87 vlm6BPXIqfQnGuIZuyYl4EDc/OIixOwP7F4lcTf9xz1p3xbvNLzpwzrnh Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="343791130" X-IronPort-AV: E=Sophos;i="6.00,245,1681196400"; d="scan'208";a="343791130" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2023 15:01:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="715770091" X-IronPort-AV: E=Sophos;i="6.00,245,1681196400"; d="scan'208";a="715770091" Received: from smaurice-mobl.amr.corp.intel.com (HELO [192.168.1.200]) ([10.212.120.175]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2023 15:01:00 -0700 From: Vishal Verma <vishal.l.verma@intel.com> Date: Thu, 15 Jun 2023 16:00:23 -0600 Subject: [PATCH 1/3] mm/memory_hotplug: Allow an override for the memmap_on_memory param MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230613-vv-kmem_memmap-v1-1-f6de9c6af2c6@intel.com> References: <20230613-vv-kmem_memmap-v1-0-f6de9c6af2c6@intel.com> In-Reply-To: <20230613-vv-kmem_memmap-v1-0-f6de9c6af2c6@intel.com> To: "Rafael J. Wysocki" <rafael@kernel.org>, Len Brown <lenb@kernel.org>, Andrew Morton <akpm@linux-foundation.org>, David Hildenbrand <david@redhat.com>, Oscar Salvador <osalvador@suse.de>, Dan Williams <dan.j.williams@intel.com>, Dave Jiang <dave.jiang@intel.com> Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, Huang Ying <ying.huang@intel.com>, Dave Hansen <dave.hansen@linux.intel.com>, Vishal Verma <vishal.l.verma@intel.com> X-Mailer: b4 0.13-dev-02a79 X-Developer-Signature: v=1; a=openpgp-sha256; l=5348; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=y9Fdd4CaXjYhM8c/kYRc/ffM8uFuEd3rHTJq5W9ozIE=; b=owGbwMvMwCXGf25diOft7jLG02pJDCndXdJbnAJ++yhZVS3cvOTdxff5fUeOOrvs/W7jtJclP WTj/uU/OkpZGMS4GGTFFFn+7vnIeExuez5PYIIjzBxWJpAhDFycAjARjZWMDOcv2YmZnLWzVvS7 ZmDA/pxvkXo8w7k/p3WUixhuPrsgsYuR4cuznZa5advZfkrwz5A/cUmgei/3H+NlJ99c6hPf5ON 4lxcA X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768808524316234987?= X-GMAIL-MSGID: =?utf-8?q?1768808524316234987?= |
Series |
mm: use memmap_on_memory semantics for dax/kmem
|
|
Commit Message
Verma, Vishal L
June 15, 2023, 10 p.m. UTC
For memory hotplug to consider MHP_MEMMAP_ON_MEMORY behavior, the
'memmap_on_memory' module parameter was a hard requirement.
In preparation for the dax/kmem driver to use memmap_on_memory
semantics, arrange for the module parameter check to be bypassed via the
appropriate mhp_flag.
Recall that the kmem driver could contribute huge amounts of hotplugged
memory originating from special purposes devices such as CXL memory
expanders. In some cases memmap_on_memory may be the /only/ way this new
memory can be hotplugged. Hence it makes sense for kmem to have a way to
force memmap_on_memory without depending on a module param, if all the
other conditions for it are met.
The only other user of this interface is acpi/acpi_memoryhotplug.c,
which only enables the mhp_flag if an initial
mhp_supports_memmap_on_memory() test passes. Maintain the existing
behavior and semantics for this by performing the initial check from
acpi without the MHP_MEMMAP_ON_MEMORY flag, so its decision falls back
to the module parameter.
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Len Brown <lenb@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Huang Ying <ying.huang@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
include/linux/memory_hotplug.h | 2 +-
drivers/acpi/acpi_memhotplug.c | 2 +-
mm/memory_hotplug.c | 24 ++++++++++++++++--------
3 files changed, 18 insertions(+), 10 deletions(-)
Comments
Hi, Vishal, Thanks for your patch! Vishal Verma <vishal.l.verma@intel.com> writes: > For memory hotplug to consider MHP_MEMMAP_ON_MEMORY behavior, the > 'memmap_on_memory' module parameter was a hard requirement. > > In preparation for the dax/kmem driver to use memmap_on_memory > semantics, arrange for the module parameter check to be bypassed via the > appropriate mhp_flag. > > Recall that the kmem driver could contribute huge amounts of hotplugged > memory originating from special purposes devices such as CXL memory > expanders. In some cases memmap_on_memory may be the /only/ way this new > memory can be hotplugged. Hence it makes sense for kmem to have a way to > force memmap_on_memory without depending on a module param, if all the > other conditions for it are met. > > The only other user of this interface is acpi/acpi_memoryhotplug.c, > which only enables the mhp_flag if an initial > mhp_supports_memmap_on_memory() test passes. Maintain the existing > behavior and semantics for this by performing the initial check from > acpi without the MHP_MEMMAP_ON_MEMORY flag, so its decision falls back > to the module parameter. > > Cc: "Rafael J. Wysocki" <rafael@kernel.org> > Cc: Len Brown <lenb@kernel.org> > Cc: Andrew Morton <akpm@linux-foundation.org> > Cc: David Hildenbrand <david@redhat.com> > Cc: Oscar Salvador <osalvador@suse.de> > Cc: Dan Williams <dan.j.williams@intel.com> > Cc: Dave Jiang <dave.jiang@intel.com> > Cc: Dave Hansen <dave.hansen@linux.intel.com> > Cc: Huang Ying <ying.huang@intel.com> > Signed-off-by: Vishal Verma <vishal.l.verma@intel.com> > --- > include/linux/memory_hotplug.h | 2 +- > drivers/acpi/acpi_memhotplug.c | 2 +- > mm/memory_hotplug.c | 24 ++++++++++++++++-------- > 3 files changed, 18 insertions(+), 10 deletions(-) > > diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h > index 9fcbf5706595..c9ddcd3cad70 100644 > --- a/include/linux/memory_hotplug.h > +++ b/include/linux/memory_hotplug.h > @@ -358,7 +358,7 @@ extern struct zone *zone_for_pfn_range(int online_type, int nid, > extern int arch_create_linear_mapping(int nid, u64 start, u64 size, > struct mhp_params *params); > void arch_remove_linear_mapping(u64 start, u64 size); > -extern bool mhp_supports_memmap_on_memory(unsigned long size); > +extern bool mhp_supports_memmap_on_memory(unsigned long size, mhp_t mhp_flags); > #endif /* CONFIG_MEMORY_HOTPLUG */ > > #endif /* __LINUX_MEMORY_HOTPLUG_H */ > diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c > index 24f662d8bd39..119d3bb49753 100644 > --- a/drivers/acpi/acpi_memhotplug.c > +++ b/drivers/acpi/acpi_memhotplug.c > @@ -211,7 +211,7 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) > if (!info->length) > continue; > > - if (mhp_supports_memmap_on_memory(info->length)) > + if (mhp_supports_memmap_on_memory(info->length, 0)) > mhp_flags |= MHP_MEMMAP_ON_MEMORY; > result = __add_memory(mgid, info->start_addr, info->length, > mhp_flags); > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index 8e0fa209d533..bb3845830922 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -1283,15 +1283,21 @@ static int online_memory_block(struct memory_block *mem, void *arg) > return device_online(&mem->dev); > } > > -bool mhp_supports_memmap_on_memory(unsigned long size) > +bool mhp_supports_memmap_on_memory(unsigned long size, mhp_t mhp_flags) > { > unsigned long nr_vmemmap_pages = size / PAGE_SIZE; > unsigned long vmemmap_size = nr_vmemmap_pages * sizeof(struct page); > unsigned long remaining_size = size - vmemmap_size; > > /* > - * Besides having arch support and the feature enabled at runtime, we > - * need a few more assumptions to hold true: > + * The MHP_MEMMAP_ON_MEMORY flag indicates a caller that wants to force > + * memmap_on_memory (if other conditions are met), regardless of the > + * module parameter. drivers/dax/kmem.c is an example, where large > + * amounts of hotplug memory may come from, and the only option to > + * successfully online all of it is to place the memmap on this memory. > + * > + * Besides having arch support and the feature enabled at runtime or > + * via the mhp_flag, we need a few more assumptions to hold true: > * > * a) We span a single memory block: memory onlining/offlinin;g happens > * in memory block granularity. We don't want the vmemmap of online > @@ -1315,10 +1321,12 @@ 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 mhp_memmap_on_memory() && > - size == memory_block_size_bytes() && > - IS_ALIGNED(vmemmap_size, PMD_SIZE) && > - IS_ALIGNED(remaining_size, (pageblock_nr_pages << PAGE_SHIFT)); > + > + if ((mhp_flags & MHP_MEMMAP_ON_MEMORY) || mhp_memmap_on_memory()) > + return size == memory_block_size_bytes() && > + IS_ALIGNED(vmemmap_size, PMD_SIZE) && > + IS_ALIGNED(remaining_size, (pageblock_nr_pages << PAGE_SHIFT)); > + return false; > } > > /* > @@ -1375,7 +1383,7 @@ int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) > * Self hosted memmap array > */ > if (mhp_flags & MHP_MEMMAP_ON_MEMORY) { > - if (!mhp_supports_memmap_on_memory(size)) { > + if (!mhp_supports_memmap_on_memory(size, mhp_flags)) { > ret = -EINVAL; > goto error; > } It appears that we need to deal with the hot-remove path too. try_remove_memory() will call mhp_memmap_on_memory() and only work with MHP_MEMMAP_ON_MEMORY properly if it returns true. Best Regards, Huang, Ying
On 16.06.23 00:00, Vishal Verma wrote: > For memory hotplug to consider MHP_MEMMAP_ON_MEMORY behavior, the > 'memmap_on_memory' module parameter was a hard requirement. > > In preparation for the dax/kmem driver to use memmap_on_memory > semantics, arrange for the module parameter check to be bypassed via the > appropriate mhp_flag. > > Recall that the kmem driver could contribute huge amounts of hotplugged > memory originating from special purposes devices such as CXL memory > expanders. In some cases memmap_on_memory may be the /only/ way this new > memory can be hotplugged. Hence it makes sense for kmem to have a way to > force memmap_on_memory without depending on a module param, if all the > other conditions for it are met. Just let the admin configure it. After all, an admin is involved in configuring the dax/kmem device to begin with. If add_memory() fails you could give a useful hint to the admin.
On Fri, 16 Jun 2023 09:46:59 +0200 David Hildenbrand <david@redhat.com> wrote: > On 16.06.23 00:00, Vishal Verma wrote: > > For memory hotplug to consider MHP_MEMMAP_ON_MEMORY behavior, the > > 'memmap_on_memory' module parameter was a hard requirement. > > > > In preparation for the dax/kmem driver to use memmap_on_memory > > semantics, arrange for the module parameter check to be bypassed via the > > appropriate mhp_flag. > > > > Recall that the kmem driver could contribute huge amounts of hotplugged > > memory originating from special purposes devices such as CXL memory > > expanders. In some cases memmap_on_memory may be the /only/ way this new > > memory can be hotplugged. Hence it makes sense for kmem to have a way to > > force memmap_on_memory without depending on a module param, if all the > > other conditions for it are met. > > Just let the admin configure it. After all, an admin is involved in > configuring the dax/kmem device to begin with. If add_memory() fails you > could give a useful hint to the admin. > Agreed. If it were just the default then fine, but making it the only option limits admin choices. Jonathan
Vishal Verma <vishal.l.verma@intel.com> writes: > For memory hotplug to consider MHP_MEMMAP_ON_MEMORY behavior, the > 'memmap_on_memory' module parameter was a hard requirement. > > In preparation for the dax/kmem driver to use memmap_on_memory > semantics, arrange for the module parameter check to be bypassed via the > appropriate mhp_flag. > > Recall that the kmem driver could contribute huge amounts of hotplugged > memory originating from special purposes devices such as CXL memory > expanders. In some cases memmap_on_memory may be the /only/ way this new > memory can be hotplugged. Hence it makes sense for kmem to have a way to > force memmap_on_memory without depending on a module param, if all the > other conditions for it are met. > > The only other user of this interface is acpi/acpi_memoryhotplug.c, > which only enables the mhp_flag if an initial > mhp_supports_memmap_on_memory() test passes. Maintain the existing > behavior and semantics for this by performing the initial check from > acpi without the MHP_MEMMAP_ON_MEMORY flag, so its decision falls back > to the module parameter. > > Cc: "Rafael J. Wysocki" <rafael@kernel.org> > Cc: Len Brown <lenb@kernel.org> > Cc: Andrew Morton <akpm@linux-foundation.org> > Cc: David Hildenbrand <david@redhat.com> > Cc: Oscar Salvador <osalvador@suse.de> > Cc: Dan Williams <dan.j.williams@intel.com> > Cc: Dave Jiang <dave.jiang@intel.com> > Cc: Dave Hansen <dave.hansen@linux.intel.com> > Cc: Huang Ying <ying.huang@intel.com> > Signed-off-by: Vishal Verma <vishal.l.verma@intel.com> > --- > include/linux/memory_hotplug.h | 2 +- > drivers/acpi/acpi_memhotplug.c | 2 +- > mm/memory_hotplug.c | 24 ++++++++++++++++-------- > 3 files changed, 18 insertions(+), 10 deletions(-) > > diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h > index 9fcbf5706595..c9ddcd3cad70 100644 > --- a/include/linux/memory_hotplug.h > +++ b/include/linux/memory_hotplug.h > @@ -358,7 +358,7 @@ extern struct zone *zone_for_pfn_range(int online_type, int nid, > extern int arch_create_linear_mapping(int nid, u64 start, u64 size, > struct mhp_params *params); > void arch_remove_linear_mapping(u64 start, u64 size); > -extern bool mhp_supports_memmap_on_memory(unsigned long size); > +extern bool mhp_supports_memmap_on_memory(unsigned long size, mhp_t mhp_flags); > #endif /* CONFIG_MEMORY_HOTPLUG */ > > #endif /* __LINUX_MEMORY_HOTPLUG_H */ > diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c > index 24f662d8bd39..119d3bb49753 100644 > --- a/drivers/acpi/acpi_memhotplug.c > +++ b/drivers/acpi/acpi_memhotplug.c > @@ -211,7 +211,7 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) > if (!info->length) > continue; > > - if (mhp_supports_memmap_on_memory(info->length)) > + if (mhp_supports_memmap_on_memory(info->length, 0)) > mhp_flags |= MHP_MEMMAP_ON_MEMORY; > result = __add_memory(mgid, info->start_addr, info->length, > mhp_flags); > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index 8e0fa209d533..bb3845830922 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -1283,15 +1283,21 @@ static int online_memory_block(struct memory_block *mem, void *arg) > return device_online(&mem->dev); > } > > -bool mhp_supports_memmap_on_memory(unsigned long size) > +bool mhp_supports_memmap_on_memory(unsigned long size, mhp_t mhp_flags) > { > unsigned long nr_vmemmap_pages = size / PAGE_SIZE; > unsigned long vmemmap_size = nr_vmemmap_pages * sizeof(struct page); > unsigned long remaining_size = size - vmemmap_size; > > /* > - * Besides having arch support and the feature enabled at runtime, we > - * need a few more assumptions to hold true: > + * The MHP_MEMMAP_ON_MEMORY flag indicates a caller that wants to force > + * memmap_on_memory (if other conditions are met), regardless of the > + * module parameter. drivers/dax/kmem.c is an example, where large > + * amounts of hotplug memory may come from, and the only option to > + * successfully online all of it is to place the memmap on this memory. > + * > + * Besides having arch support and the feature enabled at runtime or > + * via the mhp_flag, we need a few more assumptions to hold true: > * > * a) We span a single memory block: memory onlining/offlinin;g happens > * in memory block granularity. We don't want the vmemmap of online > @@ -1315,10 +1321,12 @@ 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 mhp_memmap_on_memory() && > - size == memory_block_size_bytes() && > - IS_ALIGNED(vmemmap_size, PMD_SIZE) && > - IS_ALIGNED(remaining_size, (pageblock_nr_pages << PAGE_SHIFT)); > + > + if ((mhp_flags & MHP_MEMMAP_ON_MEMORY) || mhp_memmap_on_memory()) > + return size == memory_block_size_bytes() && > + IS_ALIGNED(vmemmap_size, PMD_SIZE) && > + IS_ALIGNED(remaining_size, (pageblock_nr_pages << PAGE_SHIFT)); > + return false; > } > > /* > @@ -1375,7 +1383,7 @@ int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) > * Self hosted memmap array > */ > if (mhp_flags & MHP_MEMMAP_ON_MEMORY) { > - if (!mhp_supports_memmap_on_memory(size)) { > + if (!mhp_supports_memmap_on_memory(size, mhp_flags)) { > ret = -EINVAL; > goto error; > } > I was working on enabling memmap_on_memory for ppc64 and came across this. Can we do this as below? commit d55eddf71032cad3e057d8fa4c61ad2b8e05aaa8 Author: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> Date: Fri Jun 23 12:11:31 2023 +0530 mm/hotplug: Allow to force enable memmap on memory In some cases like DAX kmem, we want to enable memmap on memory even if we have memory_hotplug.memmap_on_memory disabled. This patch enables such usage. DAX kmem can use MHP_MEMMAP_ON_MEMORY directly to request for memmap on memory. Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c index 24f662d8bd39..4d0096fc4cc2 100644 --- a/drivers/acpi/acpi_memhotplug.c +++ b/drivers/acpi/acpi_memhotplug.c @@ -211,8 +211,7 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) if (!info->length) continue; - if (mhp_supports_memmap_on_memory(info->length)) - mhp_flags |= MHP_MEMMAP_ON_MEMORY; + mhp_flags |= get_memmap_on_memory_flags(); result = __add_memory(mgid, info->start_addr, info->length, mhp_flags); diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 9fcbf5706595..f7f534084393 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -359,6 +359,13 @@ extern int arch_create_linear_mapping(int nid, u64 start, u64 size, struct mhp_params *params); void arch_remove_linear_mapping(u64 start, u64 size); extern bool mhp_supports_memmap_on_memory(unsigned long size); +bool mhp_memmap_on_memory(void); #endif /* CONFIG_MEMORY_HOTPLUG */ +static inline unsigned long get_memmap_on_memory_flags(void) +{ + if (mhp_memmap_on_memory()) + return MHP_MEMMAP_ON_MEMORY; + return 0; +} #endif /* __LINUX_MEMORY_HOTPLUG_H */ diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index eb18d1ac7e84..85d29909fd89 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -50,7 +50,7 @@ static bool memmap_on_memory __ro_after_init; module_param(memmap_on_memory, bool, 0444); MODULE_PARM_DESC(memmap_on_memory, "Enable memmap on memory for memory hotplug"); -static inline bool mhp_memmap_on_memory(void) +bool mhp_memmap_on_memory(void) { return memmap_on_memory; } @@ -1316,10 +1316,9 @@ 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 mhp_memmap_on_memory() && - size == memory_block_size_bytes() && - IS_ALIGNED(vmemmap_size, PMD_SIZE) && - IS_ALIGNED(remaining_size, (pageblock_nr_pages << PAGE_SHIFT)); + return size == memory_block_size_bytes() && + IS_ALIGNED(vmemmap_size, PMD_SIZE) && + IS_ALIGNED(remaining_size, (pageblock_nr_pages << PAGE_SHIFT)); } /*
On 23.06.23 10:40, Aneesh Kumar K.V wrote: > Vishal Verma <vishal.l.verma@intel.com> writes: > >> For memory hotplug to consider MHP_MEMMAP_ON_MEMORY behavior, the >> 'memmap_on_memory' module parameter was a hard requirement. >> >> In preparation for the dax/kmem driver to use memmap_on_memory >> semantics, arrange for the module parameter check to be bypassed via the >> appropriate mhp_flag. >> >> Recall that the kmem driver could contribute huge amounts of hotplugged >> memory originating from special purposes devices such as CXL memory >> expanders. In some cases memmap_on_memory may be the /only/ way this new >> memory can be hotplugged. Hence it makes sense for kmem to have a way to >> force memmap_on_memory without depending on a module param, if all the >> other conditions for it are met. >> >> The only other user of this interface is acpi/acpi_memoryhotplug.c, >> which only enables the mhp_flag if an initial >> mhp_supports_memmap_on_memory() test passes. Maintain the existing >> behavior and semantics for this by performing the initial check from >> acpi without the MHP_MEMMAP_ON_MEMORY flag, so its decision falls back >> to the module parameter. >> >> Cc: "Rafael J. Wysocki" <rafael@kernel.org> >> Cc: Len Brown <lenb@kernel.org> >> Cc: Andrew Morton <akpm@linux-foundation.org> >> Cc: David Hildenbrand <david@redhat.com> >> Cc: Oscar Salvador <osalvador@suse.de> >> Cc: Dan Williams <dan.j.williams@intel.com> >> Cc: Dave Jiang <dave.jiang@intel.com> >> Cc: Dave Hansen <dave.hansen@linux.intel.com> >> Cc: Huang Ying <ying.huang@intel.com> >> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com> >> --- >> include/linux/memory_hotplug.h | 2 +- >> drivers/acpi/acpi_memhotplug.c | 2 +- >> mm/memory_hotplug.c | 24 ++++++++++++++++-------- >> 3 files changed, 18 insertions(+), 10 deletions(-) >> >> diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h >> index 9fcbf5706595..c9ddcd3cad70 100644 >> --- a/include/linux/memory_hotplug.h >> +++ b/include/linux/memory_hotplug.h >> @@ -358,7 +358,7 @@ extern struct zone *zone_for_pfn_range(int online_type, int nid, >> extern int arch_create_linear_mapping(int nid, u64 start, u64 size, >> struct mhp_params *params); >> void arch_remove_linear_mapping(u64 start, u64 size); >> -extern bool mhp_supports_memmap_on_memory(unsigned long size); >> +extern bool mhp_supports_memmap_on_memory(unsigned long size, mhp_t mhp_flags); >> #endif /* CONFIG_MEMORY_HOTPLUG */ >> >> #endif /* __LINUX_MEMORY_HOTPLUG_H */ >> diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c >> index 24f662d8bd39..119d3bb49753 100644 >> --- a/drivers/acpi/acpi_memhotplug.c >> +++ b/drivers/acpi/acpi_memhotplug.c >> @@ -211,7 +211,7 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) >> if (!info->length) >> continue; >> >> - if (mhp_supports_memmap_on_memory(info->length)) >> + if (mhp_supports_memmap_on_memory(info->length, 0)) >> mhp_flags |= MHP_MEMMAP_ON_MEMORY; >> result = __add_memory(mgid, info->start_addr, info->length, >> mhp_flags); >> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c >> index 8e0fa209d533..bb3845830922 100644 >> --- a/mm/memory_hotplug.c >> +++ b/mm/memory_hotplug.c >> @@ -1283,15 +1283,21 @@ static int online_memory_block(struct memory_block *mem, void *arg) >> return device_online(&mem->dev); >> } >> >> -bool mhp_supports_memmap_on_memory(unsigned long size) >> +bool mhp_supports_memmap_on_memory(unsigned long size, mhp_t mhp_flags) >> { >> unsigned long nr_vmemmap_pages = size / PAGE_SIZE; >> unsigned long vmemmap_size = nr_vmemmap_pages * sizeof(struct page); >> unsigned long remaining_size = size - vmemmap_size; >> >> /* >> - * Besides having arch support and the feature enabled at runtime, we >> - * need a few more assumptions to hold true: >> + * The MHP_MEMMAP_ON_MEMORY flag indicates a caller that wants to force >> + * memmap_on_memory (if other conditions are met), regardless of the >> + * module parameter. drivers/dax/kmem.c is an example, where large >> + * amounts of hotplug memory may come from, and the only option to >> + * successfully online all of it is to place the memmap on this memory. >> + * >> + * Besides having arch support and the feature enabled at runtime or >> + * via the mhp_flag, we need a few more assumptions to hold true: >> * >> * a) We span a single memory block: memory onlining/offlinin;g happens >> * in memory block granularity. We don't want the vmemmap of online >> @@ -1315,10 +1321,12 @@ 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 mhp_memmap_on_memory() && >> - size == memory_block_size_bytes() && >> - IS_ALIGNED(vmemmap_size, PMD_SIZE) && >> - IS_ALIGNED(remaining_size, (pageblock_nr_pages << PAGE_SHIFT)); >> + >> + if ((mhp_flags & MHP_MEMMAP_ON_MEMORY) || mhp_memmap_on_memory()) >> + return size == memory_block_size_bytes() && >> + IS_ALIGNED(vmemmap_size, PMD_SIZE) && >> + IS_ALIGNED(remaining_size, (pageblock_nr_pages << PAGE_SHIFT)); >> + return false; >> } >> >> /* >> @@ -1375,7 +1383,7 @@ int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) >> * Self hosted memmap array >> */ >> if (mhp_flags & MHP_MEMMAP_ON_MEMORY) { >> - if (!mhp_supports_memmap_on_memory(size)) { >> + if (!mhp_supports_memmap_on_memory(size, mhp_flags)) { >> ret = -EINVAL; >> goto error; >> } >> > > I was working on enabling memmap_on_memory for ppc64 and came across > this. Can we do this as below? > > commit d55eddf71032cad3e057d8fa4c61ad2b8e05aaa8 > Author: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> > Date: Fri Jun 23 12:11:31 2023 +0530 > > mm/hotplug: Allow to force enable memmap on memory > > In some cases like DAX kmem, we want to enable memmap on memory > even if we have memory_hotplug.memmap_on_memory disabled. This > patch enables such usage. DAX kmem can use MHP_MEMMAP_ON_MEMORY > directly to request for memmap on memory. > > Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> > > diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c > index 24f662d8bd39..4d0096fc4cc2 100644 > --- a/drivers/acpi/acpi_memhotplug.c > +++ b/drivers/acpi/acpi_memhotplug.c > @@ -211,8 +211,7 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) > if (!info->length) > continue; > > - if (mhp_supports_memmap_on_memory(info->length)) > - mhp_flags |= MHP_MEMMAP_ON_MEMORY; > + mhp_flags |= get_memmap_on_memory_flags(); > result = __add_memory(mgid, info->start_addr, info->length, > mhp_flags); > > diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h > index 9fcbf5706595..f7f534084393 100644 > --- a/include/linux/memory_hotplug.h > +++ b/include/linux/memory_hotplug.h > @@ -359,6 +359,13 @@ extern int arch_create_linear_mapping(int nid, u64 start, u64 size, > struct mhp_params *params); > void arch_remove_linear_mapping(u64 start, u64 size); > extern bool mhp_supports_memmap_on_memory(unsigned long size); > +bool mhp_memmap_on_memory(void); > #endif /* CONFIG_MEMORY_HOTPLUG */ > > +static inline unsigned long get_memmap_on_memory_flags(void) > +{ > + if (mhp_memmap_on_memory()) > + return MHP_MEMMAP_ON_MEMORY; > + return 0; > +} > #endif /* __LINUX_MEMORY_HOTPLUG_H */ > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index eb18d1ac7e84..85d29909fd89 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -50,7 +50,7 @@ static bool memmap_on_memory __ro_after_init; > module_param(memmap_on_memory, bool, 0444); > MODULE_PARM_DESC(memmap_on_memory, "Enable memmap on memory for memory hotplug"); > > -static inline bool mhp_memmap_on_memory(void) > +bool mhp_memmap_on_memory(void) > { > return memmap_on_memory; > } > @@ -1316,10 +1316,9 @@ 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 mhp_memmap_on_memory() && > - size == memory_block_size_bytes() && > - IS_ALIGNED(vmemmap_size, PMD_SIZE) && > - IS_ALIGNED(remaining_size, (pageblock_nr_pages << PAGE_SHIFT)); > + return size == memory_block_size_bytes() && > + IS_ALIGNED(vmemmap_size, PMD_SIZE) && > + IS_ALIGNED(remaining_size, (pageblock_nr_pages << PAGE_SHIFT)); > } > > /* > Any forced enablement will have to cleanly handle try_remove_memory() as well. memmap_on_memory needs a doc update then, and even the "forced enablement" has to still be explicitly enabled by the admin. ... but I'm still not convinced that memmap_on_memory should be overridden. Needs good justification.
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 9fcbf5706595..c9ddcd3cad70 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -358,7 +358,7 @@ extern struct zone *zone_for_pfn_range(int online_type, int nid, extern int arch_create_linear_mapping(int nid, u64 start, u64 size, struct mhp_params *params); void arch_remove_linear_mapping(u64 start, u64 size); -extern bool mhp_supports_memmap_on_memory(unsigned long size); +extern bool mhp_supports_memmap_on_memory(unsigned long size, mhp_t mhp_flags); #endif /* CONFIG_MEMORY_HOTPLUG */ #endif /* __LINUX_MEMORY_HOTPLUG_H */ diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c index 24f662d8bd39..119d3bb49753 100644 --- a/drivers/acpi/acpi_memhotplug.c +++ b/drivers/acpi/acpi_memhotplug.c @@ -211,7 +211,7 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) if (!info->length) continue; - if (mhp_supports_memmap_on_memory(info->length)) + if (mhp_supports_memmap_on_memory(info->length, 0)) mhp_flags |= MHP_MEMMAP_ON_MEMORY; result = __add_memory(mgid, info->start_addr, info->length, mhp_flags); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 8e0fa209d533..bb3845830922 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1283,15 +1283,21 @@ static int online_memory_block(struct memory_block *mem, void *arg) return device_online(&mem->dev); } -bool mhp_supports_memmap_on_memory(unsigned long size) +bool mhp_supports_memmap_on_memory(unsigned long size, mhp_t mhp_flags) { unsigned long nr_vmemmap_pages = size / PAGE_SIZE; unsigned long vmemmap_size = nr_vmemmap_pages * sizeof(struct page); unsigned long remaining_size = size - vmemmap_size; /* - * Besides having arch support and the feature enabled at runtime, we - * need a few more assumptions to hold true: + * The MHP_MEMMAP_ON_MEMORY flag indicates a caller that wants to force + * memmap_on_memory (if other conditions are met), regardless of the + * module parameter. drivers/dax/kmem.c is an example, where large + * amounts of hotplug memory may come from, and the only option to + * successfully online all of it is to place the memmap on this memory. + * + * Besides having arch support and the feature enabled at runtime or + * via the mhp_flag, we need a few more assumptions to hold true: * * a) We span a single memory block: memory onlining/offlinin;g happens * in memory block granularity. We don't want the vmemmap of online @@ -1315,10 +1321,12 @@ 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 mhp_memmap_on_memory() && - size == memory_block_size_bytes() && - IS_ALIGNED(vmemmap_size, PMD_SIZE) && - IS_ALIGNED(remaining_size, (pageblock_nr_pages << PAGE_SHIFT)); + + if ((mhp_flags & MHP_MEMMAP_ON_MEMORY) || mhp_memmap_on_memory()) + return size == memory_block_size_bytes() && + IS_ALIGNED(vmemmap_size, PMD_SIZE) && + IS_ALIGNED(remaining_size, (pageblock_nr_pages << PAGE_SHIFT)); + return false; } /* @@ -1375,7 +1383,7 @@ int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) * Self hosted memmap array */ if (mhp_flags & MHP_MEMMAP_ON_MEMORY) { - if (!mhp_supports_memmap_on_memory(size)) { + if (!mhp_supports_memmap_on_memory(size, mhp_flags)) { ret = -EINVAL; goto error; }