From patchwork Fri Mar 3 19:58:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 64075 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp608253wrd; Fri, 3 Mar 2023 12:16:21 -0800 (PST) X-Google-Smtp-Source: AK7set+P4gcwhLAJgG2lCzwg/HppkC/FDsnFe01XnQgkd+QSE1Rx0g53r4YmJD/QKyDGwMtStNhQ X-Received: by 2002:a17:90b:4a8e:b0:234:156:dda7 with SMTP id lp14-20020a17090b4a8e00b002340156dda7mr2967486pjb.28.1677874581583; Fri, 03 Mar 2023 12:16:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677874581; cv=none; d=google.com; s=arc-20160816; b=oPqGaCEVmeJdHqHLjWth/HNqgsdOAQ6yVCinjiJwt1Ki9vGoXKcGlMNUVRc0/493XD HcjGSnNyyokEKeQtb5FXbIsnkfcJjYrYnLvn8ueL+PRARjofhmurZV+8/2TrvB4wpJrT /xF6Cm8JgfHyd35O+nI0H6TSZFbJoKivs8Ni7IBts0neuir3FKjSo2Fxx99mhrL99A6O cVr/hKnmwuE5xYAGCm5bFA6Po21FY4BnSEecRXfTf/5u+b0K4gJrops7AGugLMhmDrLz 984XR2tBcDGVb8TB+iC3R3o6Wftl0bmlsqIVddWBTUdkkry+Hi0Tt2Z+faiLTeM7dZcz awhA== 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=YjZzxvwbzUGJAOWGom5FEayhMjnpZ78I4D4VtdieNs8=; b=Py+NC3Fjc23ecgJJIRSuNYMNB+NCeRUWeP1PpzF/iZEvoWSexjCIA6JoV+tePJNBn3 LTEypPxFQEblHvW+FWdNOyXnsYbl+OtoGYXt9D+qCQolopicTPuErYlAScfql5JLgnUz AVmB7uCCjrLzTd1IzuG6gQvuMmhTy28epxsVOZ+3qi6p/eFc1AvsfOshk3nRg5T1KfVM 5VOhKCr44cgm1RU6Pdfg/hxoTVd8oP02bsGnbnZSl510h4AamKZD9woUWB5ckOV9Rq/m HfUQBQlQM23mhf8bjLuyO6qAl1hGs1IYgqgkPHQzNli/upiew272xCL8WgB2itb5x9eV E5NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hG15rrNB; 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 j24-20020a17090aeb1800b0023037066be7si5479582pjz.56.2023.03.03.12.16.04; Fri, 03 Mar 2023 12:16: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=hG15rrNB; 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 S231644AbjCCUCF (ORCPT + 99 others); Fri, 3 Mar 2023 15:02:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231539AbjCCUBf (ORCPT ); Fri, 3 Mar 2023 15:01:35 -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 EB543618A1 for ; Fri, 3 Mar 2023 12:00:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677873637; 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=YjZzxvwbzUGJAOWGom5FEayhMjnpZ78I4D4VtdieNs8=; b=hG15rrNB4QDk+bbjylSVqLEqW76YTZWhkpPv5cAsJWtm1dIGcYTNMeI9iHBMRvKfTWpaNk dxETyLILqoJ/ZNxWT5YWQjOdosTiVr+/mlgZ3ljrc19wqkAszdbmz4XQ5D6TiI5JCJrEVN +KyeLm+XpVZG0jj4z62f8mFYGj9FnDA= 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-600-0hR5pFVRPFKmnp7Mr7Vb7w-1; Fri, 03 Mar 2023 15:00:33 -0500 X-MC-Unique: 0hR5pFVRPFKmnp7Mr7Vb7w-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5C821101B44E; Fri, 3 Mar 2023 20:00:32 +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 2D92C4014EB9; Fri, 3 Mar 2023 20:00:32 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id ABA1542919632; Fri, 3 Mar 2023 17:00:12 -0300 (-03) Message-ID: <20230303195908.977788434@redhat.com> User-Agent: quilt/0.67 Date: Fri, 03 Mar 2023 16:58:50 -0300 From: Marcelo Tosatti To: Christoph Lameter Cc: Aaron Tomlin , Frederic Weisbecker , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Russell King , Huacai Chen , Heiko Carstens , x86@kernel.org, Marcelo Tosatti Subject: [PATCH v3 09/11] mm/vmstat: use xchg in cpu_vm_stats_fold References: <20230303195841.310844446@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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?1759379017358539140?= X-GMAIL-MSGID: =?utf-8?q?1759379017358539140?= In preparation to switch vmstat shepherd to flush per-CPU counters remotely, use xchg 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 @@ -883,7 +883,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. */ @@ -904,8 +904,7 @@ 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; + v = xchg(&pzstats->vm_stat_diff[i], 0); atomic_long_add(v, &zone->vm_stat[i]); global_zone_diff[i] += v; } @@ -915,8 +914,7 @@ 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; + v = xchg(&pzstats->vm_numa_event[i], 0); zone_numa_event_add(v, zone, i); } } @@ -932,8 +930,7 @@ 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; + v = xchg(&p->vm_node_stat_diff[i], 0); atomic_long_add(v, &pgdat->vm_stat[i]); global_node_diff[i] += v; }