From patchwork Thu Feb 9 15:01:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13134750 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 79F50C61DA4 for ; Thu, 9 Feb 2023 15:33:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CAA126B0071; Thu, 9 Feb 2023 10:33:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C59C96B0072; Thu, 9 Feb 2023 10:33:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B48BE6B0074; Thu, 9 Feb 2023 10:33:23 -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 A153D6B0071 for ; Thu, 9 Feb 2023 10:33:23 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6F6A740F19 for ; Thu, 9 Feb 2023 15:33:23 +0000 (UTC) X-FDA: 80448147486.29.37FA271 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 9693940009 for ; Thu, 9 Feb 2023 15:33:21 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="f/RbsuIs"; spf=pass (imf11.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.129.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=1675956801; 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=LGWVlVnJpdpZsY64OC4/IsULi3iGJlzsOgwi06Ffb5I=; b=R9Ek4T/5nqH2pb+RlnBi1x7OQ7xfkG1tJv22Z4lNGLK2b4O8Z6f+AYQ0owVwi0LmuoBgXQ FOw7tDcAfLeLOi/YUPyDTkmY0Vn08C9o4oiQW2VmQeY8LA4mf59Zc6Q6HOgHKStfcWh+35 PCoTqNCKVeTGRURLDQtG+dV5aMp45tg= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="f/RbsuIs"; spf=pass (imf11.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.129.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=1675956801; a=rsa-sha256; cv=none; b=lOXelw2iLwf3jmDUXVCk3rdbR/2voyW/ok9qo3tqli3qN+rZvM2Im6Fa6lKQsLL3vU+5P+ VpuoOMzGqbuAF3ZDeHVRIILKKTVb4AbKXnU2gD1ZMVCd0G4lFG17nSK12/mLwfqZY7e1/K mSmJ7q+LqXJ5hgycRd4co0lMRntTOkQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675956800; 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=LGWVlVnJpdpZsY64OC4/IsULi3iGJlzsOgwi06Ffb5I=; b=f/RbsuIs488HKP153mWQOox/Q8210pglPiRKZcqEhL5IjoLU9Bzb9Srz9pmgJEty4mC6Gx jkqvux6LKSSuw/acmtosR/vmbRKmTRP5tmTJ3gY3nL36/eF1PKXOakXyO0K3XQbtt6u2fq EiExcC2ELDyi3mwZomXhTfkOFWA2Onw= 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-205-LPxsHX8gOi6p7L8Li5eumw-1; Thu, 09 Feb 2023 10:33:18 -0500 X-MC-Unique: LPxsHX8gOi6p7L8Li5eumw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 902DD1C29D4F; Thu, 9 Feb 2023 15:33:16 +0000 (UTC) Received: from tpad.localdomain (ovpn-112-3.gru2.redhat.com [10.97.112.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 625EB40C83B6; Thu, 9 Feb 2023 15:33:16 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 86BD4400E5701; Thu, 9 Feb 2023 12:32:51 -0300 (-03) Message-ID: <20230209153204.873999366@redhat.com> User-Agent: quilt/0.67 Date: Thu, 09 Feb 2023 12:01:59 -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 v2 09/11] mm/vmstat: use cmpxchg loop in cpu_vm_stats_fold References: <20230209150150.380060673@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9693940009 X-Rspam-User: X-Stat-Signature: q6n9o88ggo9bfez5fiypqrbfq49hwoif X-HE-Tag: 1675956801-674984 X-HE-Meta: U2FsdGVkX19yUjb76McjvSqPUbbgo02hMs+atEinCrTLWfQmR52+hE1g0xCvrEvLW6cIlMaoOz+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ZN/E23DoYprpWu1w0tjlrwfoPXCuJCNf/lod8sEsc9kagxuDl4F7FMZ0d01BCg2l0+1AciIgKg4Z8bFd+S185CXzIW+EMdRshZFjWMIKcFk= 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-2.6/mm/vmstat.c =================================================================== --- linux-2.6.orig/mm/vmstat.c +++ linux-2.6/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 (!try_cmpxchg(&pzstats->vm_stat_diff[i], &v, 0)); 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 (!try_cmpxchg(&pzstats->vm_numa_event[i], &v, 0)); 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 (!try_cmpxchg(&p->vm_node_stat_diff[i], &v, 0)); atomic_long_add(v, &pgdat->vm_stat[i]); global_node_diff[i] += v; }