Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp100797iog; Thu, 16 Jun 2022 23:10:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1viyUS9RA0JI3DSVm0dyvteeTpQsBBNZPHmtZupi17ekWQ0rHKOYJnRFHd62aS2LxdyikS5 X-Received: by 2002:a65:404c:0:b0:3c6:4018:ffbf with SMTP id h12-20020a65404c000000b003c64018ffbfmr7880128pgp.408.1655446200752; Thu, 16 Jun 2022 23:10:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655446200; cv=none; d=google.com; s=arc-20160816; b=Xb3BhZDS7CVh1blWVEDPwC7Bt1ESA12XQD9+kQHjsgYDvxIFZzXyX+d2vbll5xwe77 koDYuBbjeXDD+3XC20HnMSr0O3iHaZ4N2FPgkw/3BAB9NL+XQqvz9m8y5/mK7Gzl78tQ 049a8ml86mI3TLC4l6s1l4Nq4ChZhLKqjkTR38tqJfV3YjAJgocW1s03O8weaEw8LyA0 S4F2ILDHgFdCN9/OiQ7HErMp/tMvL005wnr0m4IFDax7/j5r//NTlFTq2xQYxjObZF3O MXlo7rhBiaCRyybXakLk8Oryl3/zjNTbAhF45GB+TVQWIVXgFETbxM/qXPRJn8KPgEOY Vg9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=3nN0uwMwYHIGnvGf1je2kTJf72RD7LvC05n350gAJao=; b=OF2AgGdlYLkjsfIq/GOXQ6N5kkyj+Le8qwfEdQG1TKUD6sBaoOzwZo9Wtj16tdhCgY mUtdGnth+et1Zy/fUoRitc4mA1rxW/7gjGTnszjpiQKu15Qg/hYmvMLJc/6L9xkIR+Cl v2IXnMlMRncsDzoWACf2uBOynzU2auB7wXPYZNMehaqKtUM27nMk2MFSv+VPuxfQy59F hnwOR4hZtr+ffPJGznacUgYraOhNvqHVEFH5DUK5urtHzwlIMsITYw4VBDS9R9l/iRpV 1/rXHiFGH+WfM88FBrTz2YvkYbG052Yuq0F9hieZAC5J8U5iMtXBLVHrudS6Q7H92DB0 LfFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=M8mPJFXa; dkim=neutral (no key) header.i=@suse.de header.b=y9n6WNPT; 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=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h10-20020a65404a000000b003db8bb45f56si4667953pgp.104.2022.06.16.23.09.33; Thu, 16 Jun 2022 23:10:00 -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=@suse.de header.s=susede2_rsa header.b=M8mPJFXa; dkim=neutral (no key) header.i=@suse.de header.b=y9n6WNPT; 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=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380016AbiFQFrA (ORCPT + 99 others); Fri, 17 Jun 2022 01:47:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229696AbiFQFq6 (ORCPT ); Fri, 17 Jun 2022 01:46:58 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EF7266C9C; Thu, 16 Jun 2022 22:46:57 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B76E01FAF7; Fri, 17 Jun 2022 05:46:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1655444815; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=3nN0uwMwYHIGnvGf1je2kTJf72RD7LvC05n350gAJao=; b=M8mPJFXaFRl8/xy8Tz42A0gFlxI4KziLyoj++3uQDgNavMd6xnlh2txXAnkRy8hkDsTzh1 B0YGRyP0LGre7vtdrdxltbCmtMNWAA9WwY0oUOoxkwm++eFZXkAt22XEwZn3FOWCiffSEA Z5LTjH3ey/rK6EDbp8+0XxnxxM0HP2A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1655444815; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=3nN0uwMwYHIGnvGf1je2kTJf72RD7LvC05n350gAJao=; b=y9n6WNPT2pFDQWR9Lis2ZM020dZ/WkbveEmcOy9KbJPQXT1iS+gVKpL2e5noqK5OD3RXPd HRMGwxNk/JhyCZDg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 18B741330D; Fri, 17 Jun 2022 05:46:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id F6AlA08VrGJmVAAAMHmgww (envelope-from ); Fri, 17 Jun 2022 05:46:55 +0000 Date: Fri, 17 Jun 2022 07:46:53 +0200 From: Oscar Salvador To: David Hildenbrand Cc: Muchun Song , corbet@lwn.net, akpm@linux-foundation.org, paulmck@kernel.org, mike.kravetz@oracle.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, duanxiongchun@bytedance.com, smuchun@gmail.com Subject: Re: [PATCH v2 2/2] mm: memory_hotplug: introduce SECTION_CANNOT_OPTIMIZE_VMEMMAP Message-ID: References: <20220520025538.21144-1-songmuchun@bytedance.com> <20220520025538.21144-3-songmuchun@bytedance.com> <53024884-0182-df5f-9ca2-00652c64ce36@redhat.com> <24d5ec20-9c9e-93aa-11f4-c4619f51f7d1@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <24d5ec20-9c9e-93aa-11f4-c4619f51f7d1@redhat.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,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: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 16, 2022 at 09:30:33AM +0200, David Hildenbrand wrote: > IIRC, that was used to skip these patches on the offlining path before > we provided the ranges to offline_pages(). Yeah, it was designed for that purpose back then. > I'd not mess with PG_reserved, and give them a clearer name, to not > confuse them with other, ordinary, vmemmap pages that are not > self-hosted (maybe in the future we might want to flag all vmemmap pages > with a new type?). Not sure whether a new type is really needed, or to put it another way, I cannot see the benefit. > > I'd just try reusing the flag PG_owner_priv_1. And eventually, flag all > (v)memmap pages with a type PG_memmap. However, the latter would be > optional and might not be strictly required > > > So what think could make sense is > > /* vmemmap pages that are self-hosted and cannot be optimized/freed. */ > PG_vmemmap_self_hosted = PG_owner_priv_1, Sure, I just lightly tested the below, and seems to work, but not sure whether that is what you are referring to. @Munchun: thoughts? diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index e66f7aa3191d..a4556afd7bda 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -193,6 +193,11 @@ enum pageflags { /* Only valid for buddy pages. Used to track pages that are reported */ PG_reported = PG_uptodate, + +#ifdef CONFIG_MEMORY_HOTPLUG + /* For self-hosted memmap pages */ + PG_vmemmap_self_hosted = PG_owner_priv_1, +#endif }; #define PAGEFLAGS_MASK ((1UL << NR_PAGEFLAGS) - 1) @@ -628,6 +633,10 @@ PAGEFLAG_FALSE(SkipKASanPoison, skip_kasan_poison) */ __PAGEFLAG(Reported, reported, PF_NO_COMPOUND) +#ifdef CONFIG_MEMORY_HOTPLUG +PAGEFLAG(Vmemmap_self_hosted, vmemmap_self_hosted, PF_ANY) +#endif + /* * On an anonymous page mapped into a user virtual memory area, * page->mapping points to its anon_vma, not to a struct address_space; diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 1089ea8a9c98..e2de7ed27e9e 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -101,6 +101,14 @@ void hugetlb_vmemmap_free(struct hstate *h, struct page *head) { unsigned long vmemmap_addr = (unsigned long)head; unsigned long vmemmap_end, vmemmap_reuse, vmemmap_pages; + struct mem_section *ms = __pfn_to_section(page_to_pfn(head)); + struct page *memmap; + + memmap = sparse_decode_mem_map(ms->section_mem_map, + pfn_to_section_nr(page_to_pfn(head))); + + if (PageVmemmap_self_hosted(memmap)) + return; vmemmap_pages = hugetlb_optimize_vmemmap_pages(h); if (!vmemmap_pages) @@ -199,10 +207,10 @@ static struct ctl_table hugetlb_vmemmap_sysctls[] = { static __init int hugetlb_vmemmap_sysctls_init(void) { /* - * If "memory_hotplug.memmap_on_memory" is enabled or "struct page" - * crosses page boundaries, the vmemmap pages cannot be optimized. + * If "struct page" crosses page boundaries, the vmemmap pages cannot + * be optimized. */ - if (!mhp_memmap_on_memory() && is_power_of_2(sizeof(struct page))) + if (is_power_of_2(sizeof(struct page))) register_sysctl_init("vm", hugetlb_vmemmap_sysctls); return 0; diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 1213d0c67a53..863966c2c6f1 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -45,8 +45,6 @@ #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); } @@ -1032,6 +1030,7 @@ int mhp_init_memmap_on_memory(unsigned long pfn, unsigned long nr_pages, { unsigned long end_pfn = pfn + nr_pages; int ret; + int i; ret = kasan_add_zero_shadow(__va(PFN_PHYS(pfn)), PFN_PHYS(nr_pages)); if (ret) @@ -1039,6 +1038,12 @@ int mhp_init_memmap_on_memory(unsigned long pfn, unsigned long nr_pages, move_pfn_range_to_zone(zone, pfn, nr_pages, NULL, MIGRATE_UNMOVABLE); + /* + * Let us flag self-hosted memmap + */ + for (i = 0; i < nr_pages; i++) + SetPageVmemmap_self_hosted(pfn_to_page(pfn + i)); + /* * It might be that the vmemmap_pages fully span sections. If that is * the case, mark those sections online here as otherwise they will be -- Oscar Salvador SUSE Labs