From mboxrd@z Thu Jan 1 00:00:00 1970 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 CD94DC001B2 for ; Fri, 16 Dec 2022 19:52:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C6458E0009; Fri, 16 Dec 2022 14:52:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3785E8E0007; Fri, 16 Dec 2022 14:52:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F0528E0009; Fri, 16 Dec 2022 14:52:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0BA8D8E0007 for ; Fri, 16 Dec 2022 14:52:45 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BDDE2AAB73 for ; Fri, 16 Dec 2022 19:52:44 +0000 (UTC) X-FDA: 80249217048.10.C85D03D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 3F5E420004 for ; Fri, 16 Dec 2022 19:52:43 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XRl4Lomw; spf=pass (imf03.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=1671220363; a=rsa-sha256; cv=none; b=3GTZSLpttxknn2SGOzOQI/VoCNkStHsvM5ktcFCeWA9hZN8pSk+TSiNQVkOyBBDDf1A7zV ywtoFJfUDiiTfJQfQS0L5oIt7tusZ40leNV/TWwpNAkJjQVBqDtaIxN2iDmgMSxegxjaH7 N5Ig/ArOBPHN9x/1FDLL1Pyd5xiOKKU= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XRl4Lomw; spf=pass (imf03.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=1671220363; 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=8S7mt7lE8e/IJlnGX6npC3VGrMTwvxTRAvd6yzbBL9I=; b=XSHavczBhR5jLgKyOvxTqUHX+wdZINJfq/oFDRyOeGmDEQr09fQBtwQcfgQ4AutTxXpeu+ cK4tFXOyE28spwCIpuS+9/8BHEzVT02ag8mN1OSnHOaHU/uqlG/BmAz0jQ6DrNRDz/Pv8A sxzMdigwNsukTY9dPAs5J//pbjBXZSQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671220362; 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=8S7mt7lE8e/IJlnGX6npC3VGrMTwvxTRAvd6yzbBL9I=; b=XRl4Lomw6mJ/Kz/oPV7licJtKs30SU3weGJGVPyP7QFuZYQxI5jROcM+x0jtc8/7sE6uWY xBkxAegQEVmGFbOi9vkJugpNuLEuEJhJj4GhDUmPXozf18sQ+/fbFMMQRKltsu4tLz/O4Q o1EzMsQHrHfHpZuEGlkDycbA1fTHb2c= 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-322-VaFJA5p6PziY1me1vqiQcQ-1; Fri, 16 Dec 2022 14:52:38 -0500 X-MC-Unique: VaFJA5p6PziY1me1vqiQcQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 05030183B3C0; Fri, 16 Dec 2022 19:52:38 +0000 (UTC) Received: from tpad.localdomain (ovpn-112-3.gru2.redhat.com [10.97.112.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C2F491121314; Fri, 16 Dec 2022 19:52:37 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id D7C7C4269CA84; Fri, 16 Dec 2022 16:52:10 -0300 (-03) Message-ID: <20221216194904.272106293@redhat.com> User-Agent: quilt/0.66 Date: Fri, 16 Dec 2022 16:45:46 -0300 From: Marcelo Tosatti To: atomlin@redhat.com, frederic@kernel.org Cc: cl@linux.com, tglx@linutronix.de, mingo@kernel.org, peterz@infradead.org, pauld@redhat.com, neelx@redhat.com, oleksandr@natalenko.name, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Marcelo Tosatti Subject: [PATCH v10 6/6] mm/vmstat: avoid queueing work item if cpu stats are clean References: <20221216194540.202752779@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspam-User: X-Rspamd-Queue-Id: 3F5E420004 X-Rspamd-Server: rspam01 X-Stat-Signature: a7ntb1ypb1u5swo73rdo5ywoia47in3w X-HE-Tag: 1671220363-748800 X-HE-Meta: U2FsdGVkX189GVPuXuNhWL8y4YYDFW9cMVke7dlLE66mbV2tANuWx+60LDYffWWpGuj5GcMXejB8mCJ9dTr/GFdKUsGXzr2TerHYZeJ3vAxiT8po6vxMLSRysJoPNvbEjCPqYVGX4MqSlLA7GQdJgaybQ/J1J6Y3mtxXn6pGZmbhLNe0UWStAn3L/8PjF6Zsriq5bdpZ65S00tSdnqiJFSvN92jSgxR4V0KawZXPzDAU3qRfci+sYkqL/is9nTz0FdL2GDCiZAz7kqq9unWFu9kie9nthJNRUZu4+Lm+HyPCYI695NnCBFY/j9L7a2HRmfU9iwjJgq3aE3n9Y8y4YSkb2p9ZPj01+FNYMWzg9Fe7cOXz907QW17ziwtYb2hMAU3SE4V3xgKxAAJxtwipNgUX+2OxNjlvxY8p3U/Xm+rwQ6iAwdkvU0/0bwA84EeLlscAa8/yq2DBwDaFFeIG9LOUi+kithO8+Ik/uCQrQkRotdsaSKHDqZdtZ4HQrJabZzW54EIPqzTGPEHtWNf8MQERoSe8xvSRHvBIy/dfj/Xo5iTHwAlSs+BzoJ4rLlXnwFyLtxGw0v9XUCmSVx59Y8C7YIuCu8znF5Hq6413bghKKUp3MrcCFKoT3qnB6zis7Y9ppKdeZvQFn+9s9MjrqU/wqPZ2oncupsKrMREGXQ9svY5uwTY65/iBTbxtM4MD1F09LUxWUfjXiUAYsDdEx7YA9Cf2ZDJpMi9puR8TdsqETZmCpQcYnX1X2YMoCk79K5xR8Cwi4H1U0u2PZI59UJlifLXNOpcbCcWaelTavl1bKBhoDqtyys0KiXFzJYgVDLCYCwuT0rPanC5qibbWyjT7hEFq2zn5tSoMXAGBBvdCN9B/fTlxzlRUjyx6wqvt 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: It is not necessary to queue work item to run refresh_vm_stats on a remote CPU if that CPU has no dirty stats and no per-CPU allocations for remote nodes. This fixes sosreport hang (which uses vmstat_refresh) with spinning SCHED_FIFO process. Signed-off-by: Marcelo Tosatti Index: linux-2.6/mm/vmstat.c =================================================================== --- linux-2.6.orig/mm/vmstat.c +++ linux-2.6/mm/vmstat.c @@ -1905,6 +1905,31 @@ static const struct seq_operations vmsta #ifdef CONFIG_SMP #ifdef CONFIG_PROC_FS +static bool need_drain_remote_zones(int cpu) +{ +#ifdef CONFIG_NUMA + struct zone *zone; + + for_each_populated_zone(zone) { + struct per_cpu_pages *pcp; + + pcp = per_cpu_ptr(zone->per_cpu_pageset, cpu); + if (!pcp->count) + continue; + + if (!pcp->expire) + continue; + + if (zone_to_nid(zone) == cpu_to_node(cpu)) + continue; + + return true; + } +#endif + + return false; +} + static void refresh_vm_stats(struct work_struct *work) { refresh_cpu_vm_stats(true); @@ -1914,8 +1939,12 @@ int vmstat_refresh(struct ctl_table *tab void *buffer, size_t *lenp, loff_t *ppos) { long val; - int err; - int i; + int i, cpu; + struct work_struct __percpu *works; + + works = alloc_percpu(struct work_struct); + if (!works) + return -ENOMEM; /* * The regular update, every sysctl_stat_interval, may come later @@ -1929,9 +1958,19 @@ 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); - if (err) - return err; + cpus_read_lock(); + for_each_online_cpu(cpu) { + struct work_struct *work = per_cpu_ptr(works, cpu); + + INIT_WORK(work, refresh_vm_stats); + if (per_cpu(vmstat_dirty, cpu) || need_drain_remote_zones(cpu)) + schedule_work_on(cpu, work); + } + for_each_online_cpu(cpu) + flush_work(per_cpu_ptr(works, cpu)); + cpus_read_unlock(); + free_percpu(works); + for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) { /* * Skip checking stats known to go negative occasionally.