Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp235824iog; Mon, 13 Jun 2022 01:13:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0+fpqdNEynQTcflCbQIf0bIQXhVsDUJmGGRLA05y3IXa5RraCViswB3E53IwVb8dnyZK4 X-Received: by 2002:a17:907:1b14:b0:6ef:a5c8:afbd with SMTP id mp20-20020a1709071b1400b006efa5c8afbdmr52184454ejc.151.1655108031562; Mon, 13 Jun 2022 01:13:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655108031; cv=none; d=google.com; s=arc-20160816; b=O8OaXYZh+TDzEQTb2SeAn5PxJYtj2Lj4jxMgH3xRcmfEppK7lLsSj/p+5EskgmNyjj 3mgmtH8Yc4JBlrwBV8tF6C4XQvrEwDw6EtLwSghqRXKak+spY0wsJV685Aqmkpuy29oQ Hn9ME/fyKC70PPba3THWgi4DF+UoFce+eH6RyOAapwBJPn4j3DJUjTdLw8elVWNFUVhv TsVaZZM4xtsh6JPtonvkTJ9KJ5xAVnmQCNSWIfX0we0QASGxfN70cs3QnUno1U/pklsp 6absu//xuIVPyPcKbCEy103Fo3Wd6tqBEl20VNlmtDpojTH1vSpGYjKyYodf+FejAhvP 9VFA== 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=3gX01sey3U8CCSAGhSSb8DIikXknEWnqb+fuJzKhhcI=; b=VatFejuX8eJBW9EJ73rRGVJzf96jewEs10+mvcw/8+XIcO/JHInsY+N4wzx5Ip/gW6 p6CWr8HnTEv7mIl2XQ07omto9/dwvPmCHOyyJ7yF85TBFA4lLLdII8DWB932UMR2n5AU MXt5kCUCcD4RXWQxHIaDZMN2oVgvh/CodlKy0t0Uuu7Vwi3SMMACrj5NH+gyqLh2oqwq Kezo99h5uI08Gii3MNfvsQ1GK0mqicTu4lpZ6qkI0IoW8xr+F5/Hy20JXLPNlxnq/CbL Z5in4GKP10/9ybI/naCOVaouQuAANYKegUlLzfZSxsi2rXqbErO8uDdrk1edsq0wn4cl DpUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=xNzQJkhA; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=gLycz0xH; 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 j10-20020a05640211ca00b00423ed4c5c02si8600082edw.205.2022.06.13.01.13.26; Mon, 13 Jun 2022 01:13:51 -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=xNzQJkhA; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=gLycz0xH; 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 S238663AbiFMIKb (ORCPT + 99 others); Mon, 13 Jun 2022 04:10:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239585AbiFMIKM (ORCPT ); Mon, 13 Jun 2022 04:10:12 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A34431E3DD; Mon, 13 Jun 2022 01:10:11 -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 3E03D1FAC2; Mon, 13 Jun 2022 08:10:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1655107810; 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=3gX01sey3U8CCSAGhSSb8DIikXknEWnqb+fuJzKhhcI=; b=xNzQJkhAxH68lbQ2fQKbUYQvw520KSkP1h5NHyYCvL/KKAqw0MQahh3QfTERcAu2lEiYZN ekxMgOXq41YFXsdwvcCIcIce9fxCLI7BY5tz+yRtkkFBFfzUAyJK/gKmXmzC81itEskvIb SShkxuSAMaGEuuz/4HODB/F5vQ37/dI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1655107810; 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=3gX01sey3U8CCSAGhSSb8DIikXknEWnqb+fuJzKhhcI=; b=gLycz0xHDPt69/IdsWDlUKNzvabkzQy77VT/mTBzD2gVzeK0QyI+Te3W3864W5XbO9ah8X gU8uwyP/hlV7ajAQ== 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 B331613443; Mon, 13 Jun 2022 08:10:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id R5r+KOHwpmJMIgAAMHmgww (envelope-from ); Mon, 13 Jun 2022 08:10:09 +0000 Date: Mon, 13 Jun 2022 10:10:08 +0200 From: Oscar Salvador To: Muchun Song Cc: mike.kravetz@oracle.com, david@redhat.com, akpm@linux-foundation.org, corbet@lwn.net, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Subject: Re: [PATCH 2/6] mm: hugetlb_vmemmap: optimize vmemmap_optimize_mode handling Message-ID: References: <20220613063512.17540-1-songmuchun@bytedance.com> <20220613063512.17540-3-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220613063512.17540-3-songmuchun@bytedance.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 Mon, Jun 13, 2022 at 02:35:08PM +0800, Muchun Song wrote: > We hold an another reference to hugetlb_optimize_vmemmap_key when > making vmemmap_optimize_mode on, because we use static_key to tell > memory_hotplug that memory_hotplug.memmap_on_memory should be > overridden. However, this rule has gone when we have introduced > SECTION_CANNOT_OPTIMIZE_VMEMMAP. Therefore, we could simplify > vmemmap_optimize_mode handling by not holding an another reference > to hugetlb_optimize_vmemmap_key. > > Signed-off-by: Muchun Song LGTM, and it looks way nicer, so Reviewed-by: Oscar Salvador One question below though > -static enum vmemmap_optimize_mode vmemmap_optimize_mode = > +static bool vmemmap_optimize_enabled = > IS_ENABLED(CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP_DEFAULT_ON); So, by default vmemmap_optimize_enabled will be on if we have CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP_DEFAULT_ON, but we can always override that via cmdline, as below, right? > > -static void vmemmap_optimize_mode_switch(enum vmemmap_optimize_mode to) > -{ > - if (vmemmap_optimize_mode == to) > - return; > - > - if (to == VMEMMAP_OPTIMIZE_OFF) > - static_branch_dec(&hugetlb_optimize_vmemmap_key); > - else > - static_branch_inc(&hugetlb_optimize_vmemmap_key); > - WRITE_ONCE(vmemmap_optimize_mode, to); > -} > - > static int __init hugetlb_vmemmap_early_param(char *buf) > { > - bool enable; > - enum vmemmap_optimize_mode mode; > - > - if (kstrtobool(buf, &enable)) > - return -EINVAL; > - > - mode = enable ? VMEMMAP_OPTIMIZE_ON : VMEMMAP_OPTIMIZE_OFF; > - vmemmap_optimize_mode_switch(mode); > - > - return 0; > + return kstrtobool(buf, &vmemmap_optimize_enabled); > } > early_param("hugetlb_free_vmemmap", hugetlb_vmemmap_early_param); > > @@ -103,7 +76,7 @@ static unsigned int optimizable_vmemmap_pages(struct hstate *h, > unsigned long pfn = page_to_pfn(head); > unsigned long end = pfn + pages_per_huge_page(h); > > - if (READ_ONCE(vmemmap_optimize_mode) == VMEMMAP_OPTIMIZE_OFF) > + if (!READ_ONCE(vmemmap_optimize_enabled)) > return 0; > > for (; pfn < end; pfn += PAGES_PER_SECTION) { > @@ -155,7 +128,6 @@ void __init hugetlb_vmemmap_init(struct hstate *h) > > if (!is_power_of_2(sizeof(struct page))) { > pr_warn_once("cannot optimize vmemmap pages because \"struct page\" crosses page boundaries\n"); > - static_branch_disable(&hugetlb_optimize_vmemmap_key); > return; > } > > @@ -176,36 +148,13 @@ void __init hugetlb_vmemmap_init(struct hstate *h) > } > > #ifdef CONFIG_PROC_SYSCTL > -static int hugetlb_optimize_vmemmap_handler(struct ctl_table *table, int write, > - void *buffer, size_t *length, > - loff_t *ppos) > -{ > - int ret; > - enum vmemmap_optimize_mode mode; > - static DEFINE_MUTEX(sysctl_mutex); > - > - if (write && !capable(CAP_SYS_ADMIN)) > - return -EPERM; > - > - mutex_lock(&sysctl_mutex); > - mode = vmemmap_optimize_mode; > - table->data = &mode; > - ret = proc_dointvec_minmax(table, write, buffer, length, ppos); > - if (write && !ret) > - vmemmap_optimize_mode_switch(mode); > - mutex_unlock(&sysctl_mutex); > - > - return ret; > -} > - > static struct ctl_table hugetlb_vmemmap_sysctls[] = { > { > .procname = "hugetlb_optimize_vmemmap", > - .maxlen = sizeof(enum vmemmap_optimize_mode), > + .data = &vmemmap_optimize_enabled, > + .maxlen = sizeof(int), > .mode = 0644, > - .proc_handler = hugetlb_optimize_vmemmap_handler, > - .extra1 = SYSCTL_ZERO, > - .extra2 = SYSCTL_ONE, > + .proc_handler = proc_dobool, > }, > { } > }; > -- > 2.11.0 > > -- Oscar Salvador SUSE Labs