Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp855899rwl; Thu, 5 Jan 2023 05:38:49 -0800 (PST) X-Google-Smtp-Source: AMrXdXuunhMVqoQ3Ol7W+kwvnNUbmDCiwEP11hym9XspMkNpTE9opobMoe/oVeT2+DKmEtPxYQCU X-Received: by 2002:a17:903:228a:b0:191:271f:4789 with SMTP id b10-20020a170903228a00b00191271f4789mr69998745plh.27.1672925929441; Thu, 05 Jan 2023 05:38:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672925929; cv=none; d=google.com; s=arc-20160816; b=wkHY+oDR05/DKTDtanAHVZGlJLZvmVlo6iznrfILFboSK1dIAAyozL6EI5tWDxQw5/ lnapVpakD3Lst3zSAexASmlAQm7p2isI5x/kqYh+rZfHKMC6QGMkEY6iQsqBnxg5ev0v pwXv1YLyNS6Q+3KNKC00HCcBT9TbzAw3mFazheYcc8EQvYucgXUUz3LNsAlwDCbqzQHx cnsTu3pnuNkRZCTXNY+14IPKHNyp4Hebwt9yTQEihNFh4apFJ2z7QeqDFLbNo5Yscv8V 74G5tKA5nvDY010AcoWlN8QyoYqDjjPMR2aQTgQI0EZGmjeKoyZ+4jMB6SBLhR3EPzYv oD4A== 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=C8n9DE0ruCcCCK7cY6ZY83QBYvGpdJ8qqUIL+bP6IWU=; b=NCQ7sHE8QKyR+eLc3PkuZaoYUU091HHv+9Xco10R8hLXKYVrpCVTsJd3M9jnnBWjPA 89wDb4Cm+LdIrBGcWscbCEgyUkXZIkl4g8qEXtWUadiCncGbsD5OjFlOEu2Ls7QHRi+Y o6j/dlzeGCpZNE1P1AH5rKerhHIHh3It9OyjtBS/wG7BF4/Q0EE0CrEcpI75Cz1clKp4 dqoSl9lRSm+5rS83Ns6Ru/GCh865gFdm4pAwvLGnYEz4r06E5aTVYverJRCXRQ3nEbAV sUSCTiDC1qZegc7COaHrphcc7wZWk2JCAHK4iF7Gdg3SoB8Pyn27UcAiRNXpI+B4EFpN 2g5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="gb/ZNANV"; 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 q14-20020a170902dace00b001897390a9fdsi40061836plx.541.2023.01.05.05.38.41; Thu, 05 Jan 2023 05:38:49 -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="gb/ZNANV"; 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 S232952AbjAEM51 (ORCPT + 58 others); Thu, 5 Jan 2023 07:57:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232958AbjAEM5Y (ORCPT ); Thu, 5 Jan 2023 07:57:24 -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 672B51081 for ; Thu, 5 Jan 2023 04:56:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1672923403; 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=C8n9DE0ruCcCCK7cY6ZY83QBYvGpdJ8qqUIL+bP6IWU=; b=gb/ZNANVaX//SnP38qcHV9CxNSKD1LwWgAx3xjgkLUe4DALRnhpUvZJKNEQVUv1RTFNHMs bbyfGGIVstryDsNhXirltawYbqhVjdJJw/EUNPXoVzGsz+lhiU6jYcJHuOJrKxTgVP1kiv eDrPi2xDmTK899hM10zOmpqjeNL4wUw= 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-120-zOn_0ctvMduyru0HaogF3g-1; Thu, 05 Jan 2023 07:56:41 -0500 X-MC-Unique: zOn_0ctvMduyru0HaogF3g-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 A49B8802C1C; Thu, 5 Jan 2023 12:56:40 +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 3529E53A0; Thu, 5 Jan 2023 12:56:40 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id A7E8340502F46; Thu, 5 Jan 2023 09:54:47 -0300 (-03) Message-ID: <20230105125248.971432211@redhat.com> User-Agent: quilt/0.66 Date: Thu, 05 Jan 2023 09:52:24 -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 v13 6/6] mm/vmstat: avoid queueing work item if cpu stats are clean References: <20230105125218.031928326@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 @@ -1931,6 +1931,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); @@ -1940,8 +1965,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 @@ -1955,9 +1984,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.