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: 13082273 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 EF935C10F1B for ; Tue, 27 Dec 2022 12:36:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2956C8E0005; Tue, 27 Dec 2022 07:36:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 21D788E0003; Tue, 27 Dec 2022 07:36:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 096D48E0005; Tue, 27 Dec 2022 07:36:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E970A8E0001 for ; Tue, 27 Dec 2022 07:36:37 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B7FCDAB0AA for ; Tue, 27 Dec 2022 12:36:37 +0000 (UTC) X-FDA: 80288034834.10.84B6E8B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 30AA4140008 for ; Tue, 27 Dec 2022 12:36:36 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FbqDj8yh; spf=pass (imf23.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=1672144596; 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=CqggzM+YtlNY8+VheXxfHye6fQtUBH0h9jBpeWHBdBQ=; b=sWrjEfA4wY0fkTL9w7PG2AJtGb8zlzo+zECI8oWMUCLJtTRkyFQ9NgkllWeX0jCNIq0q+L MVkAW+bNB2zva74Uj5qO6tjFWe1hrOTjFxsAG0/Fg3wPVYJTBcdOr+2uJ+HFKyOG8iZv++ nuSwKOMZJrPxA/Dhg9B8p0QPAnokwks= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FbqDj8yh; spf=pass (imf23.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=1672144596; a=rsa-sha256; cv=none; b=2coWOiNtHHas1IdGR1Q6vCzmsOK7Bbmjl3sh9jCEEhjTD1YC7YptSCAdmxDODJyHXXO9M4 b/jIAlCIKwfYvgTR4A3SAy+QW34udSsmHx5V9lcCBxNPwJiy/AgwSR8icKFj30yrqZ2evZ iBcT+bV+hnViy1dXgJJ5zpZ50RucHOo= 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-Rspamd-Queue-Id: 30AA4140008 X-Stat-Signature: p74z39dt7519pykuucs3uz1996cqdpsu X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1672144596-926598 X-HE-Meta: U2FsdGVkX182YLa3Op+m8m+4hUmLTJrVzn/GdGn/go5CU08/ZM8I4eCZ5pNXsTDZ3IufHjedP4uo/wSe5IcZ3zTUqSLnWMUGoyQmSsp5nJIugseQLf2Ub+RFCoG3D3mAWyZ8om+VsBym0j6sOhjQdGu8diCWprYoT5QTAMEmdfivj5HdRdhTvIYjKyQdT8Ppy8b8L6qRc2I665fPmIZDFUgMd0T8GFr4Vai5uNU1UcdMhTbF/hKVb4mYc7E39wyYMg1CO5TJOpm+tpGtmKq97vySIgRoTtE4apoRV/WNdzLeRI1F70oHBIm23gy1gaWuOn+VVxIwuEyFzQVKOM5RqqTmgiZg2j8lRh6yc868m4POKXA5Qu9E8xpZZQt7c0TMw2ASBYkR17mBmoq/8UNgInqwFZBb078e14lrunLCynNrNrHXuk1Bcx40AqoZ/XeFrszjCAy3z9KOpWDbcpBRHOXfRiJA99oQY9XDTab0ig+3kBht2ebM/JWc3asNlfTA/CBXa9GEXK3P0iEo5UIn6RFN4/RMMFWWqwdKDOpSBf3ylanPnIY18zJzGeAGOGh2mUlJwTBaQfHvP8ejKtHocEuK9GI1JwwZjAycr2lo+tLxNLsqrj1H1mN/wiOZ75pehsddObADfSnMXzUGK6VyTsIv3UhP8kkDSIJh2qhaCmscPD34VoJK28ki40slkcTyNaGKRjJT/BxlawqusAOfLUiwy6pwbBV/CWzqyj4AAohcVzzlvfh1y7My1+N5CMc/tz+bvK3iPt2IvBNd6LzZeQshyq/JTGh1zPtxqx9aIoz9MBCbVbbOfDF2ODVCotXZ5XZmX9vXQI0zx8j4QWrfKRO519S1/eMKPz2q9iZEL50Y8uYmgXeddD9EElp9ZT+H 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 @@ -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.