From patchwork Sun Mar 5 13:37:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13160143 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 AA640C678DB for ; Sun, 5 Mar 2023 13:41:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E0C86B0075; Sun, 5 Mar 2023 08:41:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6FF8A6B0078; Sun, 5 Mar 2023 08:41:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D01F6B007B; Sun, 5 Mar 2023 08:41:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3B3A66B0075 for ; Sun, 5 Mar 2023 08:41:50 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 134921207F7 for ; Sun, 5 Mar 2023 13:41:50 +0000 (UTC) X-FDA: 80534957580.16.079F12E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 59CFAC000B for ; Sun, 5 Mar 2023 13:41:48 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JOCV+AHS; spf=pass (imf10.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mtosatti@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678023708; 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-type:content-transfer-encoding:in-reply-to: references:references:dkim-signature; bh=HEd4Z20qHewy4816S06cVIYXHbFUi/GbntWDJMKAj40=; b=VJS5NoCq9ngKuDsiXWdHk/7Us9CSoTdYeT0eYHyOhOCcV9RbQDQg1Y+rWWkJ+INLu61bLW rkT6/DAjcXlqNrViUHV3vZoZHp6WPnOJZ53zd8piVJDPcF0A2hrxjpfIfEox8y3vwxdm7R 7Ky7TiV63g/H+I3BgAVkZN+AxRWZPo4= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JOCV+AHS; spf=pass (imf10.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mtosatti@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678023708; a=rsa-sha256; cv=none; b=3xF1gPbMK3Grj3KNOUe7K3Q3GqhYAtrCepD5FRXp1txvgNzli9/MKTSEBsI1PtPYT+jqLE /+YdYQ0QK2BZw0eLTQU25ASJmhvcr5VBLL1dvOme7vTWHQfnIf4ETA0XH+SZERHD0CMeMN TTb0xQEEQEG+lpx1BwHgcxoHZLpU7Ps= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678023707; 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: references:references; bh=HEd4Z20qHewy4816S06cVIYXHbFUi/GbntWDJMKAj40=; b=JOCV+AHSLn/PbV5GAQO+G7z7GjYTf01EMv6nY+SL2+87eArxBCGtWGS3zF58lYCXeFkVlH LnmLjAPnOUZZMwcUGbBTCZUqpivGt6iAmWj5uoo0tQAtXycvvi8edlTVFnvAa8BfZgN4dE sLFdc8/PusctUtCRnrEypGUJ4LXENXE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-558--pV2x-S5NLK2R9p0DNh-wg-1; Sun, 05 Mar 2023 08:41:43 -0500 X-MC-Unique: -pV2x-S5NLK2R9p0DNh-wg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EEB34800B23; Sun, 5 Mar 2023 13:41:42 +0000 (UTC) Received: from tpad.localdomain (ovpn-112-2.gru2.redhat.com [10.97.112.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B673D401B290; Sun, 5 Mar 2023 13:41:42 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 48C48401A1D9F; Sun, 5 Mar 2023 10:41:23 -0300 (-03) Message-ID: <20230305134053.711640642@redhat.com> User-Agent: quilt/0.67 Date: Sun, 05 Mar 2023 10:37:09 -0300 From: Marcelo Tosatti To: Christoph Lameter Cc: Aaron Tomlin , Frederic Weisbecker , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Russell King , Huacai Chen , Heiko Carstens , x86@kernel.org, Marcelo Tosatti Subject: [PATCH v4 12/12] mm/vmstat: refresh stats remotely instead of via work item References: <20230305133657.255737580@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 59CFAC000B X-Stat-Signature: yd5t4kmzi791w6394dsjm3zb4imy4sha X-Rspam-User: X-HE-Tag: 1678023708-481250 X-HE-Meta: U2FsdGVkX1/j0v7L8n7r2N8w5rYbgGjAOQSSeGOgpdXc2IUvQiX3CB5gI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wiTQIYQBmKttCgJHkiU6GKwZ9vFyiPBKWStm4BCVxy+etqchCwM5KGiJydqhncqHs9MLp/eDL198IBNA= 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: Refresh per-CPU stats remotely, instead of queueing work items, for the stat_refresh procfs method. This fixes sosreport hang (which uses vmstat_refresh) with spinning SCHED_FIFO process. Signed-off-by: Marcelo Tosatti Index: linux-vmstat-remote/mm/vmstat.c =================================================================== --- linux-vmstat-remote.orig/mm/vmstat.c +++ linux-vmstat-remote/mm/vmstat.c @@ -1860,11 +1860,21 @@ static DEFINE_PER_CPU(struct delayed_wor int sysctl_stat_interval __read_mostly = HZ; #ifdef CONFIG_PROC_FS + +#ifdef CONFIG_HAVE_CMPXCHG_LOCAL +static int refresh_all_vm_stats(void); +#else static void refresh_vm_stats(struct work_struct *work) { refresh_cpu_vm_stats(); } +static int refresh_all_vm_stats(void) +{ + return schedule_on_each_cpu(refresh_vm_stats); +} +#endif + int vmstat_refresh(struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos) { @@ -1886,7 +1896,7 @@ int vmstat_refresh(struct ctl_table *tab * transiently negative values, report an error here if any of * the stats is negative, so we know to go looking for imbalance. */ - err = schedule_on_each_cpu(refresh_vm_stats); + err = refresh_all_vm_stats(); if (err) return err; for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) { @@ -2006,7 +2016,7 @@ static DECLARE_DEFERRABLE_WORK(shepherd, #ifdef CONFIG_HAVE_CMPXCHG_LOCAL /* Flush counters remotely if CPU uses cmpxchg to update its per-CPU counters */ -static void vmstat_shepherd(struct work_struct *w) +static int refresh_all_vm_stats(void) { int cpu; @@ -2016,7 +2026,12 @@ static void vmstat_shepherd(struct work_ cond_resched(); } cpus_read_unlock(); + return 0; +} +static void vmstat_shepherd(struct work_struct *w) +{ + refresh_all_vm_stats(); schedule_delayed_work(&shepherd, round_jiffies_relative(sysctl_stat_interval)); }