From patchwork Tue Dec 27 12:11:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 36887 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1369642wrt; Tue, 27 Dec 2022 04:38:56 -0800 (PST) X-Google-Smtp-Source: AMrXdXsoaV993x93Rq6yx8j0dn9qGQEAYXaJhsT9/fp/cMgZ8tfvt/24KhCa59Bv3E3MdG+Zh4PS X-Received: by 2002:a17:906:6896:b0:7c1:4c46:30a0 with SMTP id n22-20020a170906689600b007c14c4630a0mr20373045ejr.65.1672144735770; Tue, 27 Dec 2022 04:38:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672144735; cv=none; d=google.com; s=arc-20160816; b=gdcKi0t0YovN4i5d7CZLjfhD58py02Zck+BzasJtejVhsgimSevJhoE5a/npnVX5S+ IYNf50KA/z4mypG3DDUmNzCnwnpeide2uEUJgCUsfWfByuI5ZPUcOvkDKeIX9nC7nihu klVmVm6hsMa5lxveohTdvAbSn3bCJJo5Cb6DmuI2DUjUEG/CkEjd+1pg36xXXIgF/3L5 4X1VLfpYoXsFdDxtJlGEueufTu/iloJsSOvcvFvqrqghUEPtAQp+XHhu/xW5JzbQSuOi TIjL+WRaLOss9FBbndnHt+IAG88VIaJKk9HW/qM9G86gpw6bMvwcTJ616tL7MtyjvGP5 vqWg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qa38-20020a17090786a600b0073d9f16e5b3si11851568ejc.258.2022.12.27.04.38.30; Tue, 27 Dec 2022 04:38:55 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753370838714554377?= X-GMAIL-MSGID: =?utf-8?q?1753370838714554377?= 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.