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: 12874824 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 27099C433EF for ; Thu, 9 Jun 2022 04:04:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B04C76B0073; Thu, 9 Jun 2022 00:04:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A8B2A6B0074; Thu, 9 Jun 2022 00:04:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92B576B0075; Thu, 9 Jun 2022 00:04:44 -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 7F2C56B0073 for ; Thu, 9 Jun 2022 00:04:44 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 49C782071D for ; Thu, 9 Jun 2022 04:04:44 +0000 (UTC) X-FDA: 79557356088.10.DFC2822 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf09.hostedemail.com (Postfix) with ESMTP id 32DDF140061 for ; Thu, 9 Jun 2022 04:04:43 +0000 (UTC) Received: by mail-pl1-f175.google.com with SMTP id q18so19271473pln.12 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=5C9yP6/AUqrDU1mgLoX1N+nf9GdTkz4a41KEiIYGoOjubDAx0hYXKYFIAinV4KVkJP c1ctNDZYNmUfckCivdklm0mciFD+LNbingclg8BRACAXINl456NE4uH1JYiiDblgxmkS FILuaoNifGYDHyzIYmkFeG7yzlvG6NN/5b18mYi3GQLEQiT225IZ+p/7k4lV9gTkWa5t ZlLbApzsysb/qajQjMXH4YY2E/iFZIu1Kstjb9Ls9LS0QjbzZZRF+JQZ+urBdAscX6SZ rQBJkw/oo9NaAh0gWAaUEixbDfNuAR5fC1Zhp14aEVEX+EtDUTFdZP1nmz4xmaALg1HO ieUg== X-Gm-Message-State: AOAM532kQfYr6jFk+a8BQe1sj8DNfgnrQgGKRv8gVncuuHXDhBWKfJRl Pm7GngCHTsL5kV9Gz2ZwN7lmfg== 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654747483; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=zY5mFinMaMydRM+H9UjtKkuWSUe8T7k3YskeQQPjglc=; b=kqQrFXH5zCEglLEuD3FRfLHBwkubHbrQwFLJ7oTwmecbb6AUWP8BBqPXb9HD6lvJPZTjgn ojRf0+dJ9PQ086KJ17TYCT6L5Rs0lnlEOaPPpGrMSj9amAL+ukKBjlipoqOiZAi+LoBRKv utGT5KCFDH3uggS7OtxJqP5AgrSi80g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654747483; a=rsa-sha256; cv=none; b=S3rQB/XNIQGIkLF87jd10k1nLUNIw7s2MqUF6zsnV58hX62x7qcWcyFgeM7BQICplX+AT0 UrQ5rje3lEZEyJ6D2INvNWKncGmJaEDvZXsycMpkyPnnsNsUIfsMLHim+C3NWTgX7PX82B P9Rdtlft0MqpJ6XgPdO4f/iJanlaSSE= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=5pcuzgGc; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf09.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=5pcuzgGc; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf09.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-Rspamd-Server: rspam08 X-Rspam-User: X-Stat-Signature: qgskg5nta6zpjxod4j8z183jdo55xek5 X-Rspamd-Queue-Id: 32DDF140061 X-HE-Tag: 1654747483-781707 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: "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