Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp46319iol; Wed, 8 Jun 2022 21:21:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhGSH9w3lt1aiicZcIY/Pvdt4Cz9L+CHVL6q6mQQlUHIvGTj5oLuSVjl8k58PtoXiG4Nfs X-Received: by 2002:a17:90b:4c8f:b0:1e6:9bf9:1ab8 with SMTP id my15-20020a17090b4c8f00b001e69bf91ab8mr1394455pjb.215.1654748469877; Wed, 08 Jun 2022 21:21:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654748469; cv=none; d=google.com; s=arc-20160816; b=tfgHzr6U3e8LmMIxlTnodCAPDSHXcajsOHBDC6DFi6IRdAVRNosbyRWb/xj4yInqy/ B0utSyZNic7rf8IHE6o/vMbySxbhlsiasTRXB5g0Du4ep5MgXaxL/UYOnP8mt6oIcxtf UtZPsSXz5+WgO8MtW3yh3NxVhyJRiD5dX4Wbriyn55qOTKgrP+o344mVS/FqwRRfDjCZ aPkpBn/iB+1Pl6X9lbRldPV0IbVCSxty2dWilztJao7N3xjS6pCJa87m2J/jbUFjpICW bEdQ6F6L5WqOFMT+LO+gG2qMqg2z4BZ/nU6pB5Vfvpje7J2JDEumU+JU1uvda2iIgoI2 8/1g== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=zY5mFinMaMydRM+H9UjtKkuWSUe8T7k3YskeQQPjglc=; b=vzmLxOjNW18rkcDg51y5+GvyQCkUmiJ2HnwVQ/rpujSdJH248VZXODXTAV1mqMKRYh 41d1v+XYiNsRIWLla5XUo1YxqBk/vFeMZ5U9QihuUnX8X6IlnI4WjmoBYV2OuO8KGUBH uxSGZFfWKxFuqxfGCkO0UqXfUHzDXYhwho1dCeI+3EqXaNmJ1/8XIrYRhvwWrOTxCfvQ w5GWwHlFeSxoklT7fb0gFTTPtOhCHu2O1vH+Q0t2m9+lBIiz64xBiAS3U6GYiWtk4V7v rUHUhWJKG1s9AVqJOR2oBM2xP3SE+6C8i0oAcF6g+ULGkfElf8X0uK23oh5KIbIV39Jt qxGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=5pcuzgGc; 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 x17-20020a170902821100b001619ccff412si28967106pln.410.2022.06.08.21.20.54; Wed, 08 Jun 2022 21:21:09 -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=5pcuzgGc; 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 S237038AbiFIEEs (ORCPT + 99 others); Thu, 9 Jun 2022 00:04:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236175AbiFIEEo (ORCPT ); Thu, 9 Jun 2022 00:04:44 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65BDE21F9C8 for ; Wed, 8 Jun 2022 21:04:42 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id i15so2534107plr.1 for ; Wed, 08 Jun 2022 21:04:42 -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:mime-version :content-transfer-encoding; bh=zY5mFinMaMydRM+H9UjtKkuWSUe8T7k3YskeQQPjglc=; b=5pcuzgGc3KBBFq/TL1YCOhhPlIrvGxqmJS9pDZOYdOG1VGHxT+uZqf9JOa/4l1K6X5 092+6X4ZZO+JXbC4846duJGZd5Wq/uOAFkUeq2NAJ2U6oXcxvor25M8/SfcMktkETzH/ VUgKoR43Ka+v5PDqZYzLlChYpe24PNasEDGR9GsJepygHa7n0+SCzVXSIuGBxxHwFM6l dngHYNvRBLMCxY5jYSBB4eAtY1IUsdAOZJNY7GNU7+aBOdX01+Jdp+vktzgtWKmb5saH 0NUlHFKxQzknqYr/D26kG/DXegbR0aA6vk/0i+YgfrR7aXTAO9qy0t/ykINGPvQwmZtQ /RlA== 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:mime-version :content-transfer-encoding; bh=zY5mFinMaMydRM+H9UjtKkuWSUe8T7k3YskeQQPjglc=; b=0LzRb32TiZvdhMUALp4C4v48AaR2ZM+cU1lNXnV+bFByJtmpASVbSbe6XbcggYlGnu 1J/ZFoCOWPecOXXqpGAYtAYlsDt3MncuhM+E9ZId3/l2HITx6j+Jax7qYXY41tGYCshG MG+YT690LcfuJfWFJH/CVIK0r6xsSX091ty1BUepB1QG3VZcHOhbkavau88bmma7/PTe 2e7uE5Foywk+og+HdYFYpe8Gt9pJAd29DG8T/8idDshLuWf9TqaSV7HdavqH4HilPiMq 7jVvDdBrcccN2Oru41tV7F/4oKP1F08XxAZ6kdG1lHWc6LC0CvdJ6oCqud4XlEunFtkZ /EaA== X-Gm-Message-State: AOAM533OpcVPAf6Q6YSau/n0cAW9jGEev6MDCKiUAe7RTV3II+pQgtvR PknpQJfPI7Cjwzh0ic+Rkc5ziA== X-Received: by 2002:a17:903:228c:b0:163:baf6:582a with SMTP id b12-20020a170903228c00b00163baf6582amr37184890plh.43.1654747481887; Wed, 08 Jun 2022 21:04:41 -0700 (PDT) Received: from FVFYT0MHHV2J.bytedance.net ([139.177.225.238]) by smtp.gmail.com with ESMTPSA id t5-20020a170902e84500b00163ffe73300sm15887049plg.137.2022.06.08.21.04.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 21:04:41 -0700 (PDT) From: Muchun Song To: mcgrof@kernel.org, keescook@chromium.org, yzaikin@google.com, akpm@linux-foundation.org, vbabka@suse.cz, mgorman@techsingularity.net, peterz@infradead.org, dhowells@redhat.com, willy@infradead.org, Liam.Howlett@Oracle.com, kemi.wang@intel.com, mhocko@suse.com Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Muchun Song , stable@vger.kernel.org Subject: [PATCH] mm: sysctl: fix missing numa_stat when !CONFIG_HUGETLB_PAGE Date: Thu, 9 Jun 2022 12:03:42 +0800 Message-Id: <20220609040342.2703-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.1 (Apple Git-133) 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, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 "numa_stat" should not be included in the scope of CONFIG_HUGETLB_PAGE, if CONFIG_HUGETLB_PAGE is not configured even if CONFIG_NUMA is configured, "numa_stat" is missed form /proc. Remove it out of CONFIG_HUGETLB_PAGE and move numa_stat sysctl handling to mm/vmstat.c. Fixes: 4518085e127d ("mm, sysctl: make NUMA stats configurable") Signed-off-by: Muchun Song Cc: --- include/linux/vmstat.h | 5 ----- kernel/sysctl.c | 9 --------- mm/vmstat.c | 52 +++++++++++++++++++++++++------------------------- 3 files changed, 26 insertions(+), 40 deletions(-) diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h index bfe38869498d..1297a6b8ba23 100644 --- a/include/linux/vmstat.h +++ b/include/linux/vmstat.h @@ -13,12 +13,7 @@ extern int sysctl_stat_interval; #ifdef CONFIG_NUMA -#define ENABLE_NUMA_STAT 1 -#define DISABLE_NUMA_STAT 0 -extern int sysctl_vm_numa_stat; DECLARE_STATIC_KEY_TRUE(vm_numa_stat_key); -int sysctl_vm_numa_stat_handler(struct ctl_table *table, int write, - void *buffer, size_t *length, loff_t *ppos); #endif struct reclaim_stat { diff --git a/kernel/sysctl.c b/kernel/sysctl.c index e52b6e372c60..3d6f36f230bb 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -2107,15 +2107,6 @@ static struct ctl_table vm_table[] = { .mode = 0644, .proc_handler = &hugetlb_mempolicy_sysctl_handler, }, - { - .procname = "numa_stat", - .data = &sysctl_vm_numa_stat, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = sysctl_vm_numa_stat_handler, - .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_ONE, - }, #endif { .procname = "hugetlb_shm_group", diff --git a/mm/vmstat.c b/mm/vmstat.c index 373d2730fcf2..e10afbee888e 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -33,8 +33,6 @@ #include "internal.h" #ifdef CONFIG_NUMA -int sysctl_vm_numa_stat = ENABLE_NUMA_STAT; - /* zero numa counters within a zone */ static void zero_zone_numa_counters(struct zone *zone) { @@ -73,35 +71,37 @@ static void invalid_numa_statistics(void) zero_global_numa_counters(); } -static DEFINE_MUTEX(vm_numa_stat_lock); - -int sysctl_vm_numa_stat_handler(struct ctl_table *table, int write, - void *buffer, size_t *length, loff_t *ppos) +static int sysctl_numa_stat_handler(struct ctl_table *table, int write, + void *buffer, size_t *length, loff_t *ppos) { - int ret, oldval; + int ret; + struct static_key *key = table->data; + static DEFINE_MUTEX(lock); - mutex_lock(&vm_numa_stat_lock); - if (write) - oldval = sysctl_vm_numa_stat; - ret = proc_dointvec_minmax(table, write, buffer, length, ppos); - if (ret || !write) - goto out; - - if (oldval == sysctl_vm_numa_stat) - goto out; - else if (sysctl_vm_numa_stat == ENABLE_NUMA_STAT) { - static_branch_enable(&vm_numa_stat_key); - pr_info("enable numa statistics\n"); - } else { - static_branch_disable(&vm_numa_stat_key); + mutex_lock(&lock); + ret = proc_do_static_key(table, write, buffer, length, ppos); + if (!ret && write && !static_key_enabled(key)) invalid_numa_statistics(); - pr_info("disable numa statistics, and clear numa counters\n"); - } - -out: - mutex_unlock(&vm_numa_stat_lock); + mutex_unlock(&lock); return ret; } + +static struct ctl_table numa_stat_sysctl[] = { + { + .procname = "numa_stat", + .data = &vm_numa_stat_key.key, + .mode = 0644, + .proc_handler = sysctl_numa_stat_handler, + }, + { } +}; + +static int __init numa_stat_sysctl_init(void) +{ + register_sysctl_init("vm", numa_stat_sysctl); + return 0; +} +late_initcall(numa_stat_sysctl_init); #endif #ifdef CONFIG_VM_EVENT_COUNTERS -- 2.11.0