From patchwork Tue Nov 17 16:28:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 11912717 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB6D5C56202 for ; Tue, 17 Nov 2020 16:28:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 158D424654 for ; Tue, 17 Nov 2020 16:28:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="foKhtjoM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 158D424654 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 298646B0071; Tue, 17 Nov 2020 11:28:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 24AA46B0072; Tue, 17 Nov 2020 11:28:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 111AD6B0073; Tue, 17 Nov 2020 11:28:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0028.hostedemail.com [216.40.44.28]) by kanga.kvack.org (Postfix) with ESMTP id D8C426B0071 for ; Tue, 17 Nov 2020 11:28:36 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 7D1078249980 for ; Tue, 17 Nov 2020 16:28:36 +0000 (UTC) X-FDA: 77494443432.15.party07_550d47827333 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 5442E1814B0C7 for ; Tue, 17 Nov 2020 16:28:36 +0000 (UTC) X-HE-Tag: party07_550d47827333 X-Filterd-Recvd-Size: 5881 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Tue, 17 Nov 2020 16:28:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605630515; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=E8dmZgPmUycyKGeB+KdzXbwo1wV1HsqMjlkPMXJeaKw=; b=foKhtjoMJiW6+FBzr5whgpipIqO7ucb+UUygHCnLEAPz7yN+clTdSGmYDtfQqiFnyJDILA 6hhTiz8pPi2EgHr4PKdkU5kg3TefNxD3HnyORaH4AObTnDoeDar9vvwuHCoBtQ2pnfdFt+ KA6p+mVyWOtC8CrkO+ldGcwPHaCrCLo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-449-6kQKRWFnNouAgFoO7dupVA-1; Tue, 17 Nov 2020 11:28:31 -0500 X-MC-Unique: 6kQKRWFnNouAgFoO7dupVA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8DBB66D586; Tue, 17 Nov 2020 16:28:30 +0000 (UTC) Received: from fuller.cnet (ovpn-112-7.gru2.redhat.com [10.97.112.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 19E3310013D0; Tue, 17 Nov 2020 16:28:30 +0000 (UTC) Received: by fuller.cnet (Postfix, from userid 1000) id 0D782417F26A; Tue, 17 Nov 2020 13:28:06 -0300 (-03) Date: Tue, 17 Nov 2020 13:28:06 -0300 From: Marcelo Tosatti To: Christoph Lameter Cc: linux-mm@kvack.org, Andrew Morton Subject: [PATCH] mm: introduce sysctl file to flush per-cpu vmstat statistics Message-ID: <20201117162805.GA274911@fuller.cnet> MIME-Version: 1.0 User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mtosatti@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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: For isolated applications that busy loop (packet processing with DPDK, for example), workqueue functions either stall (if the -rt app priority is higher than kworker thread priority) or interrupt the -rt app (if the -rt app priority is lower than kworker thread priority. For those cases, it is ideal to avoid the workqueue function in the first place. For the vmstat_update function, which syncs per-cpu statistics to global stats, one can modify the -rt app to explicitly flush before the realtime loop starts. Suggested by Christoph Lameter at https://lkml.org/lkml/2017/5/12/364. Suggested-by: Christoph Lameter Signed-off-by: Marcelo Tosatti Reported-by: kernel test robot diff --git a/Documentation/admin-guide/sysctl/vm.rst b/Documentation/admin-guide/sysctl/vm.rst index f455fa00c00f..ea4ad1f9f82f 100644 --- a/Documentation/admin-guide/sysctl/vm.rst +++ b/Documentation/admin-guide/sysctl/vm.rst @@ -67,6 +67,7 @@ Currently, these files are in /proc/sys/vm: - percpu_pagelist_fraction - stat_interval - stat_refresh +- quiet_vmstat - numa_stat - swappiness - unprivileged_userfaultfd @@ -827,6 +828,21 @@ as 0) and "fails" with EINVAL if any are found, with a warning in dmesg. (At time of writing, a few stats are known sometimes to be found negative, with no ill effects: errors and warnings on these stats are suppressed.) +quiet_vmstat +============ + +Any read or write flushes the current cpu's per-cpu vm statistics into +their global totals, and flushes pending updates. + +This is useful for isolated realtime applications that, in the setup +phase, use services that modify per-cpu vm statistics (mlock, for example). + +Performing an explicit flush before starting the time sensitive loop removes +the need for it to happen at workqueue time (which would interrupt the +application). + +Note that without pinning the task to a particular CPU, which CPU has its +per-cpu vm statistics flushed is not well defined. numa_stat ========= diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h index 322dcbfcc933..da98cc28b3ca 100644 --- a/include/linux/vmstat.h +++ b/include/linux/vmstat.h @@ -290,6 +290,8 @@ void refresh_zone_stat_thresholds(void); struct ctl_table; int vmstat_refresh(struct ctl_table *, int write, void *buffer, size_t *lenp, loff_t *ppos); +int proc_quiet_vmstat(struct ctl_table *table, int write, void *buffer, + size_t *lenp, loff_t *ppos); void drain_zonestat(struct zone *zone, struct per_cpu_pageset *); diff --git a/kernel/sysctl.c b/kernel/sysctl.c index afad085960b8..71b28311b950 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -3016,6 +3016,13 @@ static struct ctl_table vm_table[] = { .mode = 0600, .proc_handler = vmstat_refresh, }, + { + .procname = "quiet_vmstat", + .data = NULL, + .maxlen = 0, + .mode = 0600, + .proc_handler = proc_quiet_vmstat, + }, #endif #ifdef CONFIG_MMU { diff --git a/mm/vmstat.c b/mm/vmstat.c index 698bc0bc18d1..cec8e5c32f97 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1936,6 +1936,24 @@ void quiet_vmstat(void) refresh_cpu_vm_stats(false); } +int proc_quiet_vmstat(struct ctl_table *table, int write, + void *buffer, size_t *lenp, loff_t *ppos) +{ + if (write) + *ppos += *lenp; + else + *lenp = 0; + + preempt_disable(); + if (need_update(smp_processor_id()) == true) + refresh_cpu_vm_stats(false); + preempt_enable(); + + flush_delayed_work(this_cpu_ptr(&vmstat_work)); + + return 0; +} + /* * Shepherd worker thread that checks the * differentials of processors that have their worker