Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp3184253rwl; Tue, 27 Dec 2022 05:40:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXvEh/umYZF03BGCqdOa3ozIKCVBz9HT4E14rbh9RpD3NVRxA+HXU/aeAhjDgEAXpW3jYlFM X-Received: by 2002:a17:90a:1955:b0:21b:c9b3:e94b with SMTP id 21-20020a17090a195500b0021bc9b3e94bmr24914184pjh.16.1672148421249; Tue, 27 Dec 2022 05:40:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672148421; cv=none; d=google.com; s=arc-20160816; b=A9VHUX/tl+h+Zy8WpPAUTu46XLzUauFS4BkSGU2ld9w7BzReUce0YQVKwv4Vz62kKA BF3wNWB4xFeSjXnl3onfXxW4bcsjRgimJBwasQuDAmt122L59jmckGOK62AjM8AAx1ui EDowpCIIo2q+BWKV+6xYsaWPEKU8oR3iefnEpau7vvC5bY3N7OmrQkus0KdlnUdGEEv2 V2x+dzXFJ7THDuZFLRoulVKrNRTaIVPTDdemA1VH2yVoxs2U4FWbKLrmRIT49pDFyIZ2 oqNNn7k7QK7+QHsvRXbp+y0yA5g87rXlNPm1vF6X87ttYhlDqZ4ddi+q/yz5bdokWD/A oumw== 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=CqggzM+YtlNY8+VheXxfHye6fQtUBH0h9jBpeWHBdBQ=; b=nb7xtAnJtCzi7kXWON0LBYkE3b5Xg7VPqW1i7bz2O5VV37bkYsLu37/kNOpC9vbOtS 6Pl3GRpjvE43yLFd/n3kYN1aGCxGywJ7esj4drTnGAO8tVJbQzPEgSPBgQeKUebn8Ej2 ZXhfkXWEQo9MfFtdBRz2n6qWJkZuF5uv3S6XX1vWcCIbeVK602yX1o7Fd1vJ8olW5m6z ag92XvX0cRBx1wunAg7KiRxxfy8titWX/bUR9rJTiRVGwaYD8YxsKzpW8XiNGVkRPQ6k GvxnUVtNw2IaSOym/RqBfJ5UL2uYdsmgpG4PdUjP2tyNFw4y7QC+/TQRxM7HGXvndk5G 0Rmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FbqDj8yh; 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 l72-20020a63914b000000b00477fdec4e0fsi13040011pge.16.2022.12.27.05.40.09; Tue, 27 Dec 2022 05:40:21 -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=FbqDj8yh; 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 S229762AbiL0Mh0 (ORCPT + 66 others); Tue, 27 Dec 2022 07:37:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230043AbiL0MhX (ORCPT ); Tue, 27 Dec 2022 07:37:23 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 858651E5 for ; Tue, 27 Dec 2022 04:36:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1672144595; 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=CqggzM+YtlNY8+VheXxfHye6fQtUBH0h9jBpeWHBdBQ=; b=FbqDj8yh6sclRTk6faNzUlOC2GfIzRXgZqjXGufj+Whx3oPHBOJ69VkyaCDRx+S6/1Jlxi rP0iTcYd8AqunJoZbaVWHy7evYDu0VwW1Ox1ses+Oa++5GGpHGUryYzHAgENvC3rNQolsR TWta0zEt8sPkWhNXuGh5O1Nto3dLjc4= 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-434-bzfDgGI4OBe12qE5XtAC4g-1; Tue, 27 Dec 2022 07:36:32 -0500 X-MC-Unique: bzfDgGI4OBe12qE5XtAC4g-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ECCA9183B3C0; Tue, 27 Dec 2022 12:36:31 +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 7D40579A1; Tue, 27 Dec 2022 12:36:31 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id C96BF4257A831; Tue, 27 Dec 2022 09:14:52 -0300 (-03) Message-ID: <20221227121342.139017111@redhat.com> User-Agent: quilt/0.66 Date: Tue, 27 Dec 2022 09:11:43 -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 v12 6/6] mm/vmstat: avoid queueing work item if cpu stats are clean References: <20221227121137.102497574@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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 @@ -1924,6 +1924,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); @@ -1933,8 +1958,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 @@ -1948,9 +1977,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.