From patchwork Thu Jun 9 04:03:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12874823 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FB39C43334 for ; Thu, 9 Jun 2022 04:04:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236703AbiFIEEq (ORCPT ); Thu, 9 Jun 2022 00:04:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229752AbiFIEEn (ORCPT ); Thu, 9 Jun 2022 00:04:43 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 656FB1A4096 for ; Wed, 8 Jun 2022 21:04:42 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id q12-20020a17090a304c00b001e2d4fb0eb4so25596352pjl.4 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=jFDbbzBUjIuMlzMgVqW4DkpJoTegdyJiIR5yd2QAcDpvL/FV03OJ5lu0GKJVqNxSmV arNdS3rgZzot5s6tnGULRLj6lLR1+AaH7IOBsoD5kCE0dt7Fz1OAUXsb1tpuLRnppzrf A0YGySF+J5lpMDP0V6gQNS3nhdHiEHdubKQtymtJ0LODpdAdcsPxhAqfHdXEQ3c9a5xC xNj2XQjLwV6uDE0SbP1S91hentMWbCO1qide+JRxwjPpdKuaUwm4kJ/0GrlwC6+jP0js uU1rl2cwKFvKK4KxxyqTuLaWTrheGUzbnSj4/Dq5aRatKBfZl9fCxkHEtXwiGwNffjvo QlVA== X-Gm-Message-State: AOAM53008zrOU/agt4QyGwQeHEX9pZ+2Fgvg/o1AV7g06bZAUFAzHcXb L5nMT0x+b2JazbyCGuMvmPWekg== X-Google-Smtp-Source: ABdhPJwLD5D90RbLdd1NhQp9diUE2EhXlyXUqaO7S6k3tR7O5xwtfMN8z7LwN9K2fHURcGSStMdhCA== 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 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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