From patchwork Wed Feb 1 19:50:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13124917 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 89E4FC63797 for ; Wed, 1 Feb 2023 19:52:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 539586B0075; Wed, 1 Feb 2023 14:52:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4727C6B0078; Wed, 1 Feb 2023 14:52:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 29CEA6B007B; Wed, 1 Feb 2023 14:52:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 19BF36B0075 for ; Wed, 1 Feb 2023 14:52:37 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E34A11C660D for ; Wed, 1 Feb 2023 19:52:36 +0000 (UTC) X-FDA: 80419770312.19.D1B2449 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 0FA081C0024 for ; Wed, 1 Feb 2023 19:52:34 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RKO5+FUx; spf=pass (imf20.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=1675281155; 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=UNuyx8K2ySiAV6ZnRT9lDE7gCUj8cZTtuvFWAoUAsDg=; b=1jbxl8/GAMoJt5/loLa0QZMkvsqZ/o38ohfvLBxh+Fz2DZfgvSTy5/W+CFy1R7Lc8ekAXt gPYZpRlw9SnBEn9rVLW96IiqS/0jf1sxU0Vr3LQTobrIQaVar3FR0GIkYktU2ytQiz0fTh KeVBd7eslA4EL2Bi89cnbahpWWryUnY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RKO5+FUx; spf=pass (imf20.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=1675281155; a=rsa-sha256; cv=none; b=LT46uzV1lJStWRsDz4XW5FxFJ0t0CNJSfJhVt6o1GBrbMXMYZgjvxl+oFgb9IJOXX7BZCD nYHKSylwiW+YFC6eGG6HjugTzd5O2T84DBnzNcpcUmfN0ao+yNfLES5gJLcBhxvojLt9TV ky2YlrQSdBASqQfcwqzZndMv8E7S2lw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675281154; 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=UNuyx8K2ySiAV6ZnRT9lDE7gCUj8cZTtuvFWAoUAsDg=; b=RKO5+FUxGjB7l5FKxsawSkRLLD7XswLK4FN1C001CjfG+H+VyP5Stg8YxEgg5eLgN9HLlv kDYd2A+ezn60ZsNQV/xDZAKLkm4McsjsNnDKBYRn+rWvowV8UUq3YI8Mp42diXNHo/or+3 xswSnsFS96BP0KgUOpUnHfWV8ZnKunA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-594--FZ7uIvhM-eLBBPBAMydmw-1; Wed, 01 Feb 2023 14:52:30 -0500 X-MC-Unique: -FZ7uIvhM-eLBBPBAMydmw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 497DE386B751; Wed, 1 Feb 2023 19:52:30 +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 E39C42166B34; Wed, 1 Feb 2023 19:52:29 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 12F5E403C47C6; Wed, 1 Feb 2023 16:51:49 -0300 (-03) Message-ID: <20230201195104.460373427@redhat.com> User-Agent: quilt/0.67 Date: Wed, 01 Feb 2023 16:50:16 -0300 From: Marcelo Tosatti To: Christoph Lameter Cc: Aaron Tomlin , Frederic Weisbecker , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Marcelo Tosatti Subject: [PATCH 3/5] mm/vmstat: use cmpxchg loop in cpu_vm_stats_fold References: <20230201195013.881721887@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: yrwuky981cq18z8mnk1pbayfg6r5t4hq X-Rspamd-Queue-Id: 0FA081C0024 X-HE-Tag: 1675281154-120087 X-HE-Meta: U2FsdGVkX184aEQMVTxDuy77+Al6esDxLim4htCV1FNs3VZKhLldc4Hw8LEjda/9ijkNND0f3c5uGHUs0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6+mObbPFiseCGOJzp6WCEQVr6DetDQFfx9zcnGPOeGtjtFFsu5Odn31xudW4f66CDXameK/YkhqNOgH6kIBr4zOHTE= 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: In preparation to switch vmstat shepherd to flush per-CPU counters remotely, use a cmpxchg loop instead of a pair of read/write instructions. Signed-off-by: Marcelo Tosatti Index: linux-vmstat-remote/mm/vmstat.c =================================================================== --- linux-vmstat-remote.orig/mm/vmstat.c +++ linux-vmstat-remote/mm/vmstat.c @@ -885,7 +885,7 @@ static int refresh_cpu_vm_stats(void) } /* - * Fold the data for an offline cpu into the global array. + * Fold the data for a cpu into the global array. * There cannot be any access by the offline cpu and therefore * synchronization is simplified. */ @@ -906,8 +906,9 @@ void cpu_vm_stats_fold(int cpu) if (pzstats->vm_stat_diff[i]) { int v; - v = pzstats->vm_stat_diff[i]; - pzstats->vm_stat_diff[i] = 0; + do { + v = pzstats->vm_stat_diff[i]; + } while (cmpxchg(&pzstats->vm_stat_diff[i], v, 0) != v); atomic_long_add(v, &zone->vm_stat[i]); global_zone_diff[i] += v; } @@ -917,8 +918,9 @@ void cpu_vm_stats_fold(int cpu) if (pzstats->vm_numa_event[i]) { unsigned long v; - v = pzstats->vm_numa_event[i]; - pzstats->vm_numa_event[i] = 0; + do { + v = pzstats->vm_numa_event[i]; + } while (cmpxchg(&pzstats->vm_numa_event[i], v, 0) != v); zone_numa_event_add(v, zone, i); } } @@ -934,8 +936,9 @@ void cpu_vm_stats_fold(int cpu) if (p->vm_node_stat_diff[i]) { int v; - v = p->vm_node_stat_diff[i]; - p->vm_node_stat_diff[i] = 0; + do { + v = p->vm_node_stat_diff[i]; + } while (cmpxchg(&p->vm_node_stat_diff[i], v, 0) != v); atomic_long_add(v, &pgdat->vm_stat[i]); global_node_diff[i] += v; }