From patchwork Fri Mar 3 19:58:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13159450 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 18C31C64EC4 for ; Fri, 3 Mar 2023 20:00:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 64EE66B0078; Fri, 3 Mar 2023 15:00:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 56CCE6B007D; Fri, 3 Mar 2023 15:00:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36CD66B0080; Fri, 3 Mar 2023 15:00:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C0AF36B0078 for ; Fri, 3 Mar 2023 15:00:39 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 940858134F for ; Fri, 3 Mar 2023 20:00:39 +0000 (UTC) X-FDA: 80528654598.18.7CBD49D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id CEEB440029 for ; Fri, 3 Mar 2023 20:00:37 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HlHhTNWF; spf=pass (imf01.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.129.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=1677873637; 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=lzFiK75TsopniVCkp3ZjpE3jGOC4MVbCs3+2E+rU9QJlu8iUlveXrpzlw6neV5er7DHggJ vCeVTCUHmB4ZSZh9XBeFY4foAj/4XU28U3/MlIMPkwMME6MLk8anT9r3cqG9olTreLg5O9 tU26uYIEveB5NyaVA04gL89ELiIvS9Q= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HlHhTNWF; spf=pass (imf01.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.129.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=1677873637; a=rsa-sha256; cv=none; b=NdBBligIn3bbSmlQm9m0bIaVIW6SyEI43kJR4GDhozzKkohbj9RWCT5sw5Xe1eqiqxohsX dNoH+UTBdR6TMOENJp2i6PZTurIyMyBBrop/74hAPG52NaZuQyJ43PaNRWdWJsUKylAPBX CpQFR9Gk9Uh/G0H80z5rMwBkWr6/Qj8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677873637; 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=HlHhTNWFB/lIB4oewSYfnJNqQi9uzsmYXovDUQCFYQsbLdHWD4U1IoUS4nHfMe2Uv2VFGc mZnWFFW7ou3q+zYdUFUJOWmSK2808Ov/NS1YbTNykho3dpOuXWUvvJlsu06jERKDZuhO7G eHekWoykK3h2Idepu8UoDLFKcUjleGk= 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-643-joKSBS7lOOC_ZiriZUzjGQ-1; Fri, 03 Mar 2023 15:00:33 -0500 X-MC-Unique: joKSBS7lOOC_ZiriZUzjGQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 42FA480D0F3; Fri, 3 Mar 2023 20:00:32 +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 17CA02026D4B; Fri, 3 Mar 2023 20:00:32 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id B4B3642919634; Fri, 3 Mar 2023 17:00:12 -0300 (-03) Message-ID: <20230303195909.029065935@redhat.com> User-Agent: quilt/0.67 Date: Fri, 03 Mar 2023 16:58:52 -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 v3 11/11] mm/vmstat: refresh stats remotely instead of via work item References: <20230303195841.310844446@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CEEB440029 X-Rspam-User: X-Stat-Signature: gzcs1qaaiem6n9w67so9ko47413wbprm X-HE-Tag: 1677873637-151580 X-HE-Meta: U2FsdGVkX18k8rAOXeqsCQIRtUszpGGpINA5pSd2CmIDacLtLKFPnHvgNWkDtTZke394ip80Sa8zqgHNa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UKNxex+KeEfCIHkARxtZ4/XSvMg6bkU= 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)); }