From mboxrd@z Thu Jan 1 00:00:00 1970 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 18962C0015E for ; Fri, 23 Jun 2023 12:35:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 688CD8D0002; Fri, 23 Jun 2023 08:35:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6391F8D0001; Fri, 23 Jun 2023 08:35:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 501498D0002; Fri, 23 Jun 2023 08:35:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 42ABB8D0001 for ; Fri, 23 Jun 2023 08:35:20 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0EE42AFD96 for ; Fri, 23 Jun 2023 12:35:20 +0000 (UTC) X-FDA: 80933958000.24.289017B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id C91C71A000B for ; Fri, 23 Jun 2023 12:35:16 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="cdX/aeer"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687523716; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kOH7WzwTI4VChT7oNEuEyQV7U0mT1MDvKKV+43PfARA=; b=5Pn+CRYytwCaefTPQcvPO7YR34zpzXqcG5CvB2giZ9ZFTL1h4CM4999U11TG5EvDp/v/T2 QwGNcDD23M6Q1XCABKt4PuHSg76BPESdonbu/FTBqD3F9AAozqStLlbnuOFpxxqBzoEOv3 rZzEXRe3Vu06ezlYGh4Dd2DyVK1UYqY= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="cdX/aeer"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687523716; a=rsa-sha256; cv=none; b=kec9MCwx0KmoOSwqst2Bsc3IOMcTETczj3urG5aaUzRsHmgeDgfZxFng4YzMQZpt5oqItT yYlJevxm+IabtySuvGik1UFc/EBzFslQHY9I66cGa0QSkhe4PpdtKToRsMxDShnYt/KhYy 6nl5cSQxs0CgFZuvFzP7nrWoF4D3xOE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687523716; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kOH7WzwTI4VChT7oNEuEyQV7U0mT1MDvKKV+43PfARA=; b=cdX/aeerWPg8q2roqTZ0LZSnHSIyW16ZWYmp3aFy/RyWaQ2wTkPj8ljRtlgymhECxg15JO T4d1qYmT7BdfbTKLM202C2d9dbaFng+Fq6oPNM+UL673pA6bnfeePJbvUg62Fj+wcGkQfv ewwxH4NnNjvN+IFl247onaqHTXLmmV8= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-627-YPDtn6X9NcafkHfsa0klqg-1; Fri, 23 Jun 2023 08:35:14 -0400 X-MC-Unique: YPDtn6X9NcafkHfsa0klqg-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-3fa77cc7df1so4326105e9.3 for ; Fri, 23 Jun 2023 05:35:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687523713; x=1690115713; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kOH7WzwTI4VChT7oNEuEyQV7U0mT1MDvKKV+43PfARA=; b=IETolxu/Dz95v1VNeDDHa2cXOZXytk5CaQxpu56dLMYMLluZjvs/QFGMP/lrUQpzx3 jCAGeam904mD+YU17SKTbtoJbdvSor9kUpj/coRapSAFUZd/KxyfUvzJj+iN6qAwFcow UNc8EBg0bxg76ZegB8MAaDx+wAtiAoI5qSOUkbIfqBTG/K0P20qbzlVBkhYDHQCBgd2E YqOIx/dBby7M4Mprh0tweormRYK01PdlkBs7DXc00WoVTwTvN18tbzFFLMB1HiDQRcr/ gslxClbYkA366zmMWAWkKET/gJhm6otpdKmnTV/gV3+1NnLueeUyeY0aaV6PsyFW/0at LNSA== X-Gm-Message-State: AC+VfDz9ap7G5m8AAAdJAHaI60JLFZZShgTEq0I8hIG0pztAInXhDS0d O2CU6rnSnoJ1k5YLr4WdMft/kZFOB9L3BwTQJiqAdouJ3aSu/enU5IdNKypb1BqMZgIWa2zLnMG BU+DzAKOnrP0= X-Received: by 2002:a05:600c:299:b0:3f9:ba2:5d19 with SMTP id 25-20020a05600c029900b003f90ba25d19mr12835813wmk.33.1687523713254; Fri, 23 Jun 2023 05:35:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Y0g/ua8drcZZs4ihly3xkcq6phAdx3XddFTb5zM1PH+jlNfkw8ytfERFImOnmq5MJYMecVQ== X-Received: by 2002:a05:600c:299:b0:3f9:ba2:5d19 with SMTP id 25-20020a05600c029900b003f90ba25d19mr12835796wmk.33.1687523712888; Fri, 23 Jun 2023 05:35:12 -0700 (PDT) Received: from ?IPV6:2003:cb:c729:1700:9783:58ba:9db:1221? (p200300cbc7291700978358ba09db1221.dip0.t-ipconnect.de. [2003:cb:c729:1700:9783:58ba:9db:1221]) by smtp.gmail.com with ESMTPSA id p8-20020a7bcc88000000b003f7e4639aabsm2310854wma.10.2023.06.23.05.35.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 23 Jun 2023 05:35:12 -0700 (PDT) Message-ID: Date: Fri, 23 Jun 2023 14:35:11 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH 1/3] mm/memory_hotplug: Allow an override for the memmap_on_memory param To: "Aneesh Kumar K.V" , Vishal Verma , "Rafael J. Wysocki" , Len Brown , Andrew Morton , Oscar Salvador , Dan Williams , Dave Jiang 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 , Dave Hansen References: <20230613-vv-kmem_memmap-v1-0-f6de9c6af2c6@intel.com> <20230613-vv-kmem_memmap-v1-1-f6de9c6af2c6@intel.com> <87mt0qy3j9.fsf@linux.ibm.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <87mt0qy3j9.fsf@linux.ibm.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspam-User: X-Stat-Signature: o39qfu4jnfipmyfc784639jftk5mq7z5 X-Rspamd-Server: rspam07 X-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96TK2Qn8n9VA1qfRnNMnd/HdrQc1QjcHXNbQt/FLkPAzL8Jf4xEdHJxrno8YxFFux/SQwcLwS/8Y8d3M6Vf7ufwTcqH9xbmsrYPWesl04VMcvIaTEboBW2MFKdDY046FXY+rKf9CX0qyjDvrX8ckHX7uCGIO+MU0APjAJNyYkc1lnzbMbWcQHbLsDBWYrW7JOCDqK5onKiJEATon1bEgWWLU9w6PG/48FOnPgkVmT1cuiKmwD8yXrugNJezjcNDYBBvZgjAL/MJVEkKkMeDaSDeK5l87ScL7q5l/Fghj4LxYfY5gvNDBBi/Sp7EPQThVqRWGItVe0Fr5/DLX5pshoHFXaKi30jgxYNFF5wRRyIEH4RV6h5FA2FimZrGMVNGsjcLEwNL2YUSqXAT4VpuZKVtsYXtiJ05+vpcZKoWjknJA/KL5iTlT/Y92UKwCU/PWBja/xGqKUtl5e+li5MUcOxhJtRsKo0/Ssv+p+K+SYjd0CxOYP8ciqrqh67bVec+HdJLJjP/zPqW5o/JyqMOL3Uy2hMKBLv4RrAFSBY89wkHwcu4eDO+co89vDiYcA/Q1uVDteo7ae3IJMfBY56Jybw== 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: On 23.06.23 10:40, Aneesh Kumar K.V wrote: > Vishal Verma 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" >> Cc: Len Brown >> Cc: Andrew Morton >> Cc: David Hildenbrand >> Cc: Oscar Salvador >> Cc: Dan Williams >> Cc: Dave Jiang >> Cc: Dave Hansen >> Cc: Huang Ying >> Signed-off-by: Vishal Verma >> --- >> 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 > 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 > > 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. -- Cheers, David / dhildenb