Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp5992197rwj; Wed, 21 Dec 2022 09:25:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXuf2dJnQx5bTMwRDs4Jd3JOrK8eEe0Tk4j2rlLSptLgKC0TJUcdSu9XJIJEOlCmWL2erzYf X-Received: by 2002:a17:90a:cf0f:b0:223:f0c3:172b with SMTP id h15-20020a17090acf0f00b00223f0c3172bmr2953893pju.17.1671643536329; Wed, 21 Dec 2022 09:25:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671643536; cv=none; d=google.com; s=arc-20160816; b=RYZ2JHPFXKBAimxXmYRoslG6buhJZBOU+dEe65lYSLhLjIW6koi5Y9Y0/07aeXR9Ex FmkwrYQGVxKRYp7vfsBO8skoWCk5dgxkfnjrE4N46+5EhqzsyVTVX7LJkZMOP8y62H9l KWa/dX95lYKdOCgYUM0/LvBeXZ7xSsqpQb5m4/HaTeIJJP10U2jxLlHhyVhJXK8NhTzV t8Jw+Mxdi0uA7OX0cuc5OZM53t1xMptrxo1S/yMONNjnwUiBvhfdDgoVs87x9skcs9Z8 ai43r4X9y6W1RutIVwvPuozyrF0DkCKh6OZXffKY0VqIUABpyTXIMueCRzwr56TqRqfa S1xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id:dkim-signature; bh=TlUBF+2Ovi4fw5cA3chagzYiWYAEFxQHjy6HVV9843g=; b=H+G5cIJefBHi1dF03qp1FLge2h5Exy6dp2Qv1QiMk+q15JxPUCrETPLT102CaJmhX4 A6Qqm9q7FzOy3lQr+m8xlBDju6CmQVsmGtVbPGjr2Dw6sumZW0bEqvrlKsglIjJZDNig d5JGyMECVeKF4ynv/Ga1JlUhTQtvzY1NOB+kttOS/JcrpFm1VJ0jgP+AbkbVenqOPgI7 T0iOWFQYDno9MP/f/+cdNqBlbzv6lE1CvcSLfXGGFJXC/M6rbOD7LnNk5uoQPK+lD5D8 nb/JFyA04Jey4XCdWYzhluhiq0fiFZFMSsm3zWKis8rJt5eYsUSWvEG6iyoPKxNZjpfl mRqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TrqpULD3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i64-20020a638743000000b004772ea50c14si17675079pge.171.2022.12.21.09.25.26; Wed, 21 Dec 2022 09:25:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TrqpULD3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234714AbiLURMA (ORCPT + 67 others); Wed, 21 Dec 2022 12:12:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234740AbiLURLc (ORCPT ); Wed, 21 Dec 2022 12:11:32 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3983279 for ; Wed, 21 Dec 2022 09:10:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671642650; 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=TlUBF+2Ovi4fw5cA3chagzYiWYAEFxQHjy6HVV9843g=; b=TrqpULD3gTwTepHiCA/N1HKRNLPzyubuRizwl7OHJrJVm6YRci7g9JTGpK3YApuCH7+CGa JE77GBn0jzg3the4L5YDKckJvSfpnAVesGsHSRsmiFSPmYUQvHkPijLSqQ+l2zubPhSCvr FL3/Dm49TCZeA0x3A7SJI/PcVjLcxQU= 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-483-4PpJoZByPimihLmmqWBpNQ-1; Wed, 21 Dec 2022 12:10:46 -0500 X-MC-Unique: 4PpJoZByPimihLmmqWBpNQ-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 20631882827; Wed, 21 Dec 2022 17:10:46 +0000 (UTC) Received: from tpad.localdomain (ovpn-112-4.gru2.redhat.com [10.97.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DA5E92026D4B; Wed, 21 Dec 2022 17:10:44 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id B17E640408D5F; Wed, 21 Dec 2022 14:09:34 -0300 (-03) Message-ID: <20221221170436.449941687@redhat.com> User-Agent: quilt/0.66 Date: Wed, 21 Dec 2022 13:58:07 -0300 From: Marcelo Tosatti To: atomlin@atomlin.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 v11 6/6] mm/vmstat: avoid queueing work item if cpu stats are clean References: <20221221165801.362118576@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 @@ -1917,6 +1917,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); @@ -1926,8 +1951,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 @@ -1941,9 +1970,21 @@ 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); + struct vmstat_dirty *vms = per_cpu_ptr(&vmstat_dirty_pcpu, cpu); + + INIT_WORK(work, refresh_vm_stats); + + if (vms->dirty || 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.