From patchwork Fri Mar 3 19:58:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13159447 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 509D1C64EC4 for ; Fri, 3 Mar 2023 20:00:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCC506B007E; Fri, 3 Mar 2023 15:00:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CF5E96B0072; Fri, 3 Mar 2023 15:00:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 937866B0080; Fri, 3 Mar 2023 15:00:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 726876B0074 for ; Fri, 3 Mar 2023 15:00:39 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5149D80A32 for ; Fri, 3 Mar 2023 20:00:39 +0000 (UTC) X-FDA: 80528654598.24.18DAA65 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf21.hostedemail.com (Postfix) with ESMTP id E864A1C002F for ; Fri, 3 Mar 2023 20:00:35 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Bbo3oW5k; spf=pass (imf21.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=1677873637; 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=gz8YmAWe77MPk6KLnyeDeBjg9daGz/JZkyszI8+E0yI=; b=IfmEZbI07ssv3V+KDjFdIQuKlrQcGRyABc4XWTDPLx0uzRnUMsmsi5CoWJobfhZt89BciC RAmaRnQQ5kFZB9X/SOqQEY+EAzfpNjJNb7yg2qMCwQvo9OFhkjlAtJ5QCP+1zzPz5pPeh4 2ov+dGH5rCvXCdqu3YWGxrhEsWLkpA8= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Bbo3oW5k; spf=pass (imf21.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=1677873637; a=rsa-sha256; cv=none; b=l5ubE0tU0iQlDLQn0wiH8lOLb/3jPGAjssDn9raaVS+tYNr2TWZ7IxQLxMUSSD0AZNEZxC SxDxnW7wQKVfrSgCJPRGKLR8LVhZDU0Chlbl/UYdWTkKPagy0AQn4tyJ5idRYBC8t7VzDF jfitSbj1rrU/20gAVZzyJDcmC388n0U= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677873635; 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=gz8YmAWe77MPk6KLnyeDeBjg9daGz/JZkyszI8+E0yI=; b=Bbo3oW5kwuKXovhqSTi01jPs4eqgWklMw9ijOd21qcthYzYk/FLLuOTMtvw9H+mGzvVq7Y csK7Hz81Iz0MJ4pi670S/S98Tn2R1+AGjFvHk1B0U6Tiqd72yem7kC66EmC0JUg4Yqqw/E 2r1wNkT2fdqrPIFxL+dqdf7evd4GeJo= 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-518-geIIwn8RNXmtnWL1QLi5hQ-1; Fri, 03 Mar 2023 15:00:32 -0500 X-MC-Unique: geIIwn8RNXmtnWL1QLi5hQ-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 97BA8280AA46; Fri, 3 Mar 2023 20:00: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 2AE3B440D8; Fri, 3 Mar 2023 20:00:30 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 8A25240E00366; Fri, 3 Mar 2023 17:00:12 -0300 (-03) Message-ID: <20230303195908.774798959@redhat.com> User-Agent: quilt/0.67 Date: Fri, 03 Mar 2023 16:58:42 -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, David Hildenbrand , Marcelo Tosatti Subject: [PATCH v3 01/11] mm/vmstat: remove remote node draining References: <20230303195841.310844446@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: E864A1C002F X-Stat-Signature: iweimikzcpjxpo4omou54ukxenqjnqju X-Rspam-User: X-HE-Tag: 1677873635-447673 X-HE-Meta: U2FsdGVkX19GCqjzNq+7FE3B1OrHNeqc3oizjvh0L4l9Xii4daLcYI/KMx13ZqwLWC2WLePwwqSd5cHACROE3TCM7iwa7Fbl/uNygrVRNIoAVVIg+UKw6DIpZpji0tXk/sGl7g605Ju9gNbrghgPUWXkZGLp58v4lv9AlzzFPpymadXIYbyrQj8DXNFduXPwC6mK8TzPWExJrc66rTxlLCHMh+KVFUipt/kxZDK7CCEi762clU+Zi1p4KcRIveuwOQMECJ7DINXHyqSZZsSWMT9Fs2krWFLKzjoA4G8/w2HG3iEqYFdSaPDSv0VfXULa7KUDpJwSaIoDnvOoG5QJTHBrc+nS06tTaT7ZIvu7pw3UsDX3TdSY2Xw9hmKIQo+k+dpFvu6Mgl6kpHxgl9Kuy1prDZzOgHMekpi3fNUjnIXuzBio14u+RUe4VpY//VU4GjgI8bEJummNx4kXklDkmfQYzhgN8d412ZimPvUuSjIDF6hchEzusyO6Q33u5pPZEiDEBeQyKxo+jHQl0+LeAcvJlgM9837ZIMw+g/GSEtGGghmd/ijJSTnxVDllfrmV5RaBZ7zapomNz0NgOckIHizAzKnMt+mLabHYCqs+2VQ2aFhpw6LypA5wA/0aUX6pEF9RGITgNWEwWvhMJcq76cSuo/A2J8Eq90buDGLqMziuPikdpQWIYi80I3j0dkEVJcdlCjI3eNPDV9l0b3jfT3W5cWO8FN1tVLzuf4TN62lbNHMoW0Nm9PpXWj0X2RCeB//SRrXAMmSN6ljDJiYbb7bGqwBMPBqkBt/V7j2vCR0wG61cDn8ERO8LKMKqnn08MDQGMktEkoUU7h+M7zCZB/s2Y0zIywdXPM/nwwhA3px6P4/gRXuUstjaAngc2BHM2ftxZv+hZKQLOSmiXGHkgvzNQK+3uQ1BSWlHbA3VZ/SOwzAJXbgHoTd+AJWPHUrpGrQUgHrCGD/o3QlMYEI Z4YSpvEf A46RtK76fDs1P+I0FQ2jCj+gRJIddsAGN5M5uL98gGsa6KasndCczu4QukgV01kiWTaKRtMhibqVRmwHH2jTkoPAtaaMyogoyUlAon2/sE1HU0zkK78tneHEjCMeCGG8P/ErYh43ytISsPEU0i1JEBdvpufQl4vksOezpGpd7sQUWERQ9mYeFeaO43oYo5alrU/sGw0ZoQSs0t9saDAuoV6FOg1TFJauYw8PMGwIvm4vsFTk= 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: Draining of pages from the local pcp for a remote zone should not be necessary, since once the system is low on memory (or compaction on a zone is in effect), drain_all_pages should be called freeing any unused pcps. For reference, the original commit which introduces remote node draining is 4037d452202e34214e8a939fa5621b2b3bbb45b7. Acked-by: David Hildenbrand Signed-off-by: Marcelo Tosatti Index: linux-vmstat-remote/include/linux/mmzone.h =================================================================== --- linux-vmstat-remote.orig/include/linux/mmzone.h +++ linux-vmstat-remote/include/linux/mmzone.h @@ -679,9 +679,6 @@ struct per_cpu_pages { int high; /* high watermark, emptying needed */ int batch; /* chunk size for buddy add/remove */ short free_factor; /* batch scaling factor during free */ -#ifdef CONFIG_NUMA - short expire; /* When 0, remote pagesets are drained */ -#endif /* Lists of pages, one per migrate type stored on the pcp-lists */ struct list_head lists[NR_PCP_LISTS]; Index: linux-vmstat-remote/mm/vmstat.c =================================================================== --- linux-vmstat-remote.orig/mm/vmstat.c +++ linux-vmstat-remote/mm/vmstat.c @@ -803,20 +803,16 @@ static int fold_diff(int *zone_diff, int * * The function returns the number of global counters updated. */ -static int refresh_cpu_vm_stats(bool do_pagesets) +static int refresh_cpu_vm_stats(void) { struct pglist_data *pgdat; struct zone *zone; int i; int global_zone_diff[NR_VM_ZONE_STAT_ITEMS] = { 0, }; int global_node_diff[NR_VM_NODE_STAT_ITEMS] = { 0, }; - int changes = 0; for_each_populated_zone(zone) { struct per_cpu_zonestat __percpu *pzstats = zone->per_cpu_zonestats; -#ifdef CONFIG_NUMA - struct per_cpu_pages __percpu *pcp = zone->per_cpu_pageset; -#endif for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) { int v; @@ -826,44 +822,8 @@ static int refresh_cpu_vm_stats(bool do_ atomic_long_add(v, &zone->vm_stat[i]); global_zone_diff[i] += v; -#ifdef CONFIG_NUMA - /* 3 seconds idle till flush */ - __this_cpu_write(pcp->expire, 3); -#endif } } -#ifdef CONFIG_NUMA - - if (do_pagesets) { - cond_resched(); - /* - * Deal with draining the remote pageset of this - * processor - * - * Check if there are pages remaining in this pageset - * if not then there is nothing to expire. - */ - if (!__this_cpu_read(pcp->expire) || - !__this_cpu_read(pcp->count)) - continue; - - /* - * We never drain zones local to this processor. - */ - if (zone_to_nid(zone) == numa_node_id()) { - __this_cpu_write(pcp->expire, 0); - continue; - } - - if (__this_cpu_dec_return(pcp->expire)) - continue; - - if (__this_cpu_read(pcp->count)) { - drain_zone_pages(zone, this_cpu_ptr(pcp)); - changes++; - } - } -#endif } for_each_online_pgdat(pgdat) { @@ -880,8 +840,7 @@ static int refresh_cpu_vm_stats(bool do_ } } - changes += fold_diff(global_zone_diff, global_node_diff); - return changes; + return fold_diff(global_zone_diff, global_node_diff); } /* @@ -1867,7 +1826,7 @@ int sysctl_stat_interval __read_mostly = #ifdef CONFIG_PROC_FS static void refresh_vm_stats(struct work_struct *work) { - refresh_cpu_vm_stats(true); + refresh_cpu_vm_stats(); } int vmstat_refresh(struct ctl_table *table, int write, @@ -1877,6 +1836,8 @@ int vmstat_refresh(struct ctl_table *tab int err; int i; + drain_all_pages(NULL); + /* * The regular update, every sysctl_stat_interval, may come later * than expected: leaving a significant amount in per_cpu buckets. @@ -1931,7 +1892,7 @@ int vmstat_refresh(struct ctl_table *tab static void vmstat_update(struct work_struct *w) { - if (refresh_cpu_vm_stats(true)) { + if (refresh_cpu_vm_stats()) { /* * Counters were updated so we expect more updates * to occur in the future. Keep on running the @@ -1994,7 +1955,7 @@ void quiet_vmstat(void) * it would be too expensive from this path. * vmstat_shepherd will take care about that for us. */ - refresh_cpu_vm_stats(false); + refresh_cpu_vm_stats(); } /* Index: linux-vmstat-remote/mm/page_alloc.c =================================================================== --- linux-vmstat-remote.orig/mm/page_alloc.c +++ linux-vmstat-remote/mm/page_alloc.c @@ -3176,26 +3176,6 @@ static int rmqueue_bulk(struct zone *zon return allocated; } -#ifdef CONFIG_NUMA -/* - * Called from the vmstat counter updater to drain pagesets of this - * currently executing processor on remote nodes after they have - * expired. - */ -void drain_zone_pages(struct zone *zone, struct per_cpu_pages *pcp) -{ - int to_drain, batch; - - batch = READ_ONCE(pcp->batch); - to_drain = min(pcp->count, batch); - if (to_drain > 0) { - spin_lock(&pcp->lock); - free_pcppages_bulk(zone, to_drain, pcp, 0); - spin_unlock(&pcp->lock); - } -} -#endif - /* * Drain pcplists of the indicated processor and zone. */ From patchwork Fri Mar 3 19:58:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13159455 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 679B9C7EE2F for ; Fri, 3 Mar 2023 20:00:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2517E6B0083; Fri, 3 Mar 2023 15:00:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 202576B0085; Fri, 3 Mar 2023 15:00:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0A2136B0087; Fri, 3 Mar 2023 15:00:50 -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 E84B66B0083 for ; Fri, 3 Mar 2023 15:00:49 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9E443A11F4 for ; Fri, 3 Mar 2023 20:00:49 +0000 (UTC) X-FDA: 80528655018.13.0082024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 960004002B for ; Fri, 3 Mar 2023 20:00:47 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=f62vylpe; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mtosatti@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677873647; 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=iUvNynje4NLXuVViJqGVXz34mfwfY1r+EmC29iXiBlQ=; b=gWbzos1L0Izl2KERZrEp6VjO/nGSOKZAjHGWQqyH+eoPDXE+xd47TU7JzwpfE3E90zzQdj agvKom8TmwwnIHVzrOo06kmbasEYUwNrYcmiMdGO9JWcvJmUsqeqMN3wY4WwMpM7nTfh18 maL+7QJunnCueOJq9rdUhUdVAR1yMmc= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=f62vylpe; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mtosatti@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677873647; a=rsa-sha256; cv=none; b=VtSqqcNCau1gAvFtlXK812ZIZgqpFMh+FnxxKf1sqZTnWHbRE6eivxJkT+igBVO8eR+hJj y+1DG/eBPh5rJ7fC+wVeqB0JixPYjxDPdN2ZIfTKL5Adq5SCVy7xhXEdvXHoqdNV2Ln+7t WVeP73ESgb0W055TMbjgbgfnt+m+Ksg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677873647; 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=iUvNynje4NLXuVViJqGVXz34mfwfY1r+EmC29iXiBlQ=; b=f62vylpeWNxgtjpTfSbiwr/3W/trGHqneILbNo6ilEB6KxSj8Saq89rkz11c/YKTxXl8zf grK75wTUkiOYZeVHW38i72bs55rRSVjnCALJ7/TXyvqvLBoi5oaLBVKUNIGTTGljVuAC3t aisU3E8okPFAczIVm07mPThWayQXPIo= 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-516-PxqYS3KjPXirwMt8cwawRQ-1; Fri, 03 Mar 2023 15:00:30 -0500 X-MC-Unique: PxqYS3KjPXirwMt8cwawRQ-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 53E9A85C70B; Fri, 3 Mar 2023 20:00: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 1E0FB40C6EC4; Fri, 3 Mar 2023 20:00:30 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 8C9F04291962B; Fri, 3 Mar 2023 17:00:12 -0300 (-03) Message-ID: <20230303195908.800742864@redhat.com> User-Agent: quilt/0.67 Date: Fri, 03 Mar 2023 16:58:43 -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 02/11] this_cpu_cmpxchg: ARM64: switch this_cpu_cmpxchg to locked, add _local function References: <20230303195841.310844446@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspamd-Queue-Id: 960004002B X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: gfq6m9ggunassz68u7irodstqd6umbb5 X-HE-Tag: 1677873647-316399 X-HE-Meta: U2FsdGVkX1+7eP6w8YFSuuaStbV0pCY/zQlATRwJ5rHInfhVuqKaVh3eVf5uqMJ6l0jAFhU1H7BPmFz2c6tsjnIl/KOy9UWOUULE5YrwoTh8MrjcjF2lSVo2exVdhzfBCyjXkdQDjE0YWyWc3bkRemTSQpRT4W+FppY4iJsfY4J2eRAAzPOrWO3R88Kvnu8YD7pMLayQ2KqJKd9SP0wxrXs7BlN4rGOSehxhwqqWM9yNBTjevFnshjrAVPX80rhUNMt4zrIy9oN+7KwtomYeMXWmbpCwbwfk4Ty93OO29Bq0cBiboekv7JhhrJ+lbuuMTCLMb4fBAcGIdl1aNSC4P/li9u4a70hWqNTZJCLQ7uYkmh5CqMcjs8zkxXhhowR5FRtSt8tm8/e9Pj+k/Km9efgVARNsNoT1O30bt6NQDFQAZRp/KqOJvpcyskU4SPBvY3gDZp4vHQ4bEdFwZDrgKy4bjaA8CsasoCqNZIMXPj8QIqwXCcwMvHXr0Cg9aBsV4wpJnUBZEFT+h/o3DLHWbOdneFyCwNqxdgw/zg0HgYlRuZXsGtkKa6pUYFL7w3tLgWXOy/rUb55Y5f6I11OERYPMPZiJUlw7HwQAyeMe6nAhVLMF6HKiL7C+BlklIBUJMICeC4TP2dAzSlF2Wq4zmrvggksYhmHd4oJRF1ZipAj8k0c9e7ClWedYudDyNKhOdFS9kAEnk0ZgmcFi5urXEFhgHprAjTUeHnQRXTYorzqMxDsazx4S2GXSRDwCkDcXt+mpgX0dwJSVp7/LxIObNbvlCT/q5U4roAY0e/jRmLrz7aPrGIhvOoDeojXBDYchQ8f3gC9fzbxKkrTnaJOYcRODhrdS00KeHF6nA9ROZ0iK/tykKMIF0cwZ8qfDqshakFrw+IDpw4HODMEJaBKogKjzJW9AND6WcvjZRWPQmxVhzwOwFaS0rDH/uayPoZ8P8QaKc6eDjrOOl2PpjEs 8K+kCgq0 LeWfxHOk84UssyyYU6KsE35rdE4AobFWsVs8dqBcVQEmpGTHIXLLFmFKSZk1lH6qc5bVRlyYxAk6qrBv3SH8tfRm4tflAQKkayUgqFw/Z5IU4n28Z/1kFoOow/E3S4VKGmurJNXyEqZqtBdCAXT1R7Lq499jlciDd3Yplg2WMrBy3N+g5U0G8Dg+Ke51MiDTNpODLQamd84yZEakAh1xJl4NFsyyXRu1LOBqrkYDtVCXPVZceUU/hS1pMbA== 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: Goal is to have vmstat_shepherd to transfer from per-CPU counters to global counters remotely. For this, an atomic this_cpu_cmpxchg is necessary. Following the kernel convention for cmpxchg/cmpxchg_local, change ARM's this_cpu_cmpxchg_ helpers to be atomic, and add this_cpu_cmpxchg_local_ helpers which are not atomic. Signed-off-by: Marcelo Tosatti Index: linux-vmstat-remote/arch/arm64/include/asm/percpu.h =================================================================== --- linux-vmstat-remote.orig/arch/arm64/include/asm/percpu.h +++ linux-vmstat-remote/arch/arm64/include/asm/percpu.h @@ -232,13 +232,23 @@ PERCPU_RET_OP(add, add, ldadd) _pcp_protect_return(xchg_relaxed, pcp, val) #define this_cpu_cmpxchg_1(pcp, o, n) \ - _pcp_protect_return(cmpxchg_relaxed, pcp, o, n) + _pcp_protect_return(cmpxchg, pcp, o, n) #define this_cpu_cmpxchg_2(pcp, o, n) \ - _pcp_protect_return(cmpxchg_relaxed, pcp, o, n) + _pcp_protect_return(cmpxchg, pcp, o, n) #define this_cpu_cmpxchg_4(pcp, o, n) \ - _pcp_protect_return(cmpxchg_relaxed, pcp, o, n) + _pcp_protect_return(cmpxchg, pcp, o, n) #define this_cpu_cmpxchg_8(pcp, o, n) \ + _pcp_protect_return(cmpxchg, pcp, o, n) + +#define this_cpu_cmpxchg_local_1(pcp, o, n) \ _pcp_protect_return(cmpxchg_relaxed, pcp, o, n) +#define this_cpu_cmpxchg_local_2(pcp, o, n) \ + _pcp_protect_return(cmpxchg_relaxed, pcp, o, n) +#define this_cpu_cmpxchg_local_4(pcp, o, n) \ + _pcp_protect_return(cmpxchg_relaxed, pcp, o, n) +#define this_cpu_cmpxchg_local_8(pcp, o, n) \ + _pcp_protect_return(cmpxchg_relaxed, pcp, o, n) + #ifdef __KVM_NVHE_HYPERVISOR__ extern unsigned long __hyp_per_cpu_offset(unsigned int cpu); From patchwork Fri Mar 3 19:58:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13159451 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 B018AC7EE2F for ; Fri, 3 Mar 2023 20:00:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 872DA6B007B; Fri, 3 Mar 2023 15:00:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 81B7A6B0082; Fri, 3 Mar 2023 15:00:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D3246B007B; Fri, 3 Mar 2023 15:00:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D0FC96B007B for ; Fri, 3 Mar 2023 15:00:39 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8901BC12A8 for ; Fri, 3 Mar 2023 20:00:39 +0000 (UTC) X-FDA: 80528654598.20.02DD558 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf05.hostedemail.com (Postfix) with ESMTP id B99DD10002B for ; Fri, 3 Mar 2023 20:00:36 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JRJYDTDa; spf=pass (imf05.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=1677873637; a=rsa-sha256; cv=none; b=H4cFtJK4OekFxihZlIgQto7l+t9leAZffdo7uronZLXYiBGYwEprEBKNgrd4+wpf0Ie4LD ebucdwSwg8Y9k3xr7IDRV6nVaGQgFAlEpNrxBCnAFpwnwzNL4uikEG4axqKC5UsizQz7Go 56muwA9aIUuXKXeuQd5755UOcEItALk= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JRJYDTDa; spf=pass (imf05.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=1677873637; 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=1qMXUw9dsgBVhjNMR0OfieQvkRg7GOetq5N/8/ayAmg=; b=gX5hNChkS573zya+ema6w5lj8atz1lXZKvoMIKl4CLH5BqFaHEF7cXUuE6k5bZLtB23uyI 6F/ErROq8T1FWZ15i9ApytpuMOkxF8ZnBX/f2kC86tSi1Md/NP1TuQcdez3qfHLMRNLF3e hP8xk5smWku6sxlgKPnUgTgbM5UkQs8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677873636; 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=1qMXUw9dsgBVhjNMR0OfieQvkRg7GOetq5N/8/ayAmg=; b=JRJYDTDa3RCA8Yo7cSfI7NrzApvtfgOpNrVnCUWVYVx0R62nty8K2TTubF5kSS6TiybrGD dl47EpALDeKfNkMtneDSljW/C2f4cMToeQ5hY2M+uUPZshjsepWDx+eB5rJfahUFsjsPgl TldGepQ9AoS2MSZoSmDx5YHiDxEZ7tU= 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-516-fgnJlgi-OousMj4BXlHHWQ-1; Fri, 03 Mar 2023 15:00:31 -0500 X-MC-Unique: fgnJlgi-OousMj4BXlHHWQ-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 6572338123AE; Fri, 3 Mar 2023 20:00: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 377734010E86; Fri, 3 Mar 2023 20:00:30 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 8FD6A4291962C; Fri, 3 Mar 2023 17:00:12 -0300 (-03) Message-ID: <20230303195908.826802488@redhat.com> User-Agent: quilt/0.67 Date: Fri, 03 Mar 2023 16:58:44 -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 03/11] this_cpu_cmpxchg: loongarch: switch this_cpu_cmpxchg to locked, add _local function References: <20230303195841.310844446@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspam-User: X-Rspamd-Queue-Id: B99DD10002B X-Rspamd-Server: rspam01 X-Stat-Signature: c4qox3nt9moc147rabu3wixkimahq4ny X-HE-Tag: 1677873636-257313 X-HE-Meta: U2FsdGVkX18PiT41fFGjynK+U2gIyEXHNRyy29RP3BnKSlf4JcS2znpelrFqx49fncjDplW2Cus32cVzA6EmkyiW/yGZYYlI50fze7qiH5vgXe7edMJs0jZ4y05FtpGjYUm005heoxirUC9shL1tVXRBszhd2j3kRAybGzLj+j30QJ9c9AXkL5Jb8P4x1+4ax0zcvAydeMJS1t0y65Yr50OqsF9asD0Gi+V945cuqPeBlp8DFeh1XfPpW5STX/gZ78BoS1qLv6MrJgo9TZdiJAIy3O8yITX5Adc4qUu8myFkQiNQD7+wvSO6IF1R7gDtQTiZXdAdbKv6rz1922v1z4e1tpNEq7A/0dWjOylI/ezz9SHmjaPqZmukiCbyDFAkrFm235BjIMG4u16i4Qy7LjE2e0c03TxM0mDakgKQ4Hijb1JcL0DQ4R0VocXqdVdupTuqswK6s0krE4kLUGxPJE42bgz1uQji3oQjTb+XQ7hMI2QMCnPB4VF7gZ/0WQCheB/K4IpIOI4S0yVvYz4JM8YfTDJ3f71MXm9Hm43tW8DY8I09v1+EusgwPFiDz1k+8uqwi4lgyeWMrVxY88GukukZ1aETN9SjX+dKGjxdQ0I+K48vfMdeyjutuLLROU9sYncqSn7pm5h2qSPg2CaB+AhRs3je2vnO4MNkzBN7iCiZvYzXlEMC5shtAeuOyKRMOo5alZQZ+yyNjSl10hEbpfwERzmCzz2slPpXtM4COQRe+Et2zrD07heu298QkCpeFIS6zF+FlRNaubQEsAj10eYvFppWDNcc2EAb4bESh/Nwcg+6dhFk3Eys27nA+qD3dkGwv50Iz7/ZMSh/MN9g7h4kAqFt5In25AGsSBS8X8fjcr2Z+3ntB5Bav+jWds84Rq6gBJdNcrjgV5yVaTuTK68TYJ2uXINf76X5HR1CWau+3R7SQJWpygkFqZ1Rmlxa41m0w6qZkid6NKod4zk anQFkDtP UuSlNi5ddVGSfvCqDV76qBM88I4o7hiwo9Blekj5yYflDVuFFSoPTJ2s1QW0wR01BYhr6r3msqN1+eai2MkQgb8yOOV1bnsve8dbLbyVwLN2OJoU7S9/o6XkWjmeICyBBjlA5aVgaW5pbHPVlwDJ7ZtOh2ND9Mn76ZlY9i7udzvK0G06MvjvoIx54eZ0TBAx4RuBS04KUx9ikEG9qeTcjqS7UD9ZoKnZ8zKdMeqxchUejjdOthJ5BnYKE8w== 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: Goal is to have vmstat_shepherd to transfer from per-CPU counters to global counters remotely. For this, an atomic this_cpu_cmpxchg is necessary. Following the kernel convention for cmpxchg/cmpxchg_local, add this_cpu_cmpxchg_local helpers to Loongarch. Signed-off-by: Marcelo Tosatti Index: linux-vmstat-remote/arch/loongarch/include/asm/percpu.h =================================================================== --- linux-vmstat-remote.orig/arch/loongarch/include/asm/percpu.h +++ linux-vmstat-remote/arch/loongarch/include/asm/percpu.h @@ -150,6 +150,16 @@ static inline unsigned long __percpu_xch } /* this_cpu_cmpxchg */ +#define _protect_cmpxchg(pcp, o, n) \ +({ \ + typeof(*raw_cpu_ptr(&(pcp))) __ret; \ + preempt_disable_notrace(); \ + __ret = cmpxchg(raw_cpu_ptr(&(pcp)), o, n); \ + preempt_enable_notrace(); \ + __ret; \ +}) + +/* this_cpu_cmpxchg_local */ #define _protect_cmpxchg_local(pcp, o, n) \ ({ \ typeof(*raw_cpu_ptr(&(pcp))) __ret; \ @@ -222,10 +232,15 @@ do { \ #define this_cpu_xchg_4(pcp, val) _percpu_xchg(pcp, val) #define this_cpu_xchg_8(pcp, val) _percpu_xchg(pcp, val) -#define this_cpu_cmpxchg_1(ptr, o, n) _protect_cmpxchg_local(ptr, o, n) -#define this_cpu_cmpxchg_2(ptr, o, n) _protect_cmpxchg_local(ptr, o, n) -#define this_cpu_cmpxchg_4(ptr, o, n) _protect_cmpxchg_local(ptr, o, n) -#define this_cpu_cmpxchg_8(ptr, o, n) _protect_cmpxchg_local(ptr, o, n) +#define this_cpu_cmpxchg_local_1(ptr, o, n) _protect_cmpxchg_local(ptr, o, n) +#define this_cpu_cmpxchg_local_2(ptr, o, n) _protect_cmpxchg_local(ptr, o, n) +#define this_cpu_cmpxchg_local_4(ptr, o, n) _protect_cmpxchg_local(ptr, o, n) +#define this_cpu_cmpxchg_local_8(ptr, o, n) _protect_cmpxchg_local(ptr, o, n) + +#define this_cpu_cmpxchg_1(ptr, o, n) _protect_cmpxchg(ptr, o, n) +#define this_cpu_cmpxchg_2(ptr, o, n) _protect_cmpxchg(ptr, o, n) +#define this_cpu_cmpxchg_4(ptr, o, n) _protect_cmpxchg(ptr, o, n) +#define this_cpu_cmpxchg_8(ptr, o, n) _protect_cmpxchg(ptr, o, n) #include From patchwork Fri Mar 3 19:58:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13159445 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 1B588C7EE2F for ; Fri, 3 Mar 2023 20:00:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6E3136B0073; Fri, 3 Mar 2023 15:00:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6466F6B0072; Fri, 3 Mar 2023 15:00:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 44B7A6B0074; Fri, 3 Mar 2023 15:00:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1F5026B0074 for ; Fri, 3 Mar 2023 15:00:39 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id ED5F9ABB93 for ; Fri, 3 Mar 2023 20:00:38 +0000 (UTC) X-FDA: 80528654556.29.1FD7DD5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf16.hostedemail.com (Postfix) with ESMTP id A23A9180016 for ; Fri, 3 Mar 2023 20:00:35 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eXp1RSew; spf=pass (imf16.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=1677873637; 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=FePX2+VFBr01iZwaVbBM1HjdLAtX/eNoAgkcl35m848=; b=weHbtOtsntT3h68TUmsV56PTG33gvmdtH9OQzG9fUc2T0maLD0e8Za6cmtJdFyMIA99q58 N/HDV7qIHJi17jy5fb1bU0s+9N0kF6I0WiDIbmvA1Te2vAny+TlnjVd4FEErB0ATlv1Qy2 G6rwSm9u0GOJl6CQqnnWYHmrlZH2f8s= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eXp1RSew; spf=pass (imf16.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=1677873637; a=rsa-sha256; cv=none; b=aUTNg7uR669ckUFYl9qC2kQCJemicjav1V5lsWCLrsg0KyHrqEP0HxeUALbEhr84pk/DMK LPppo0SXdZqVm/CszPt4AQcbNqTJ+lGE9wTfo+sbVNWYEpfvxyR1wLLBvppdSxgGljfkP+ ARhJJU8tdp40xLDjI/lkgiVOGJCra5Q= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677873634; 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=FePX2+VFBr01iZwaVbBM1HjdLAtX/eNoAgkcl35m848=; b=eXp1RSewFRwJASXTUvECihX3+jtcnez3oP4z/ruEPFeB6gADtqcq9vFn+IKK/zk9j9J88K 166XBUWW5d8QXOq5jeTQyMt0dlIvNUZWIWbo0SidFCLql2NDF8Ct9QsLXIbfxJdqf1sjRZ xEjNYornbRJQVpecBjb8I/aeehgGlRw= 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-212-OPuKcFE6ON6wpaC72tuhoQ-1; Fri, 03 Mar 2023 15:00:33 -0500 X-MC-Unique: OPuKcFE6ON6wpaC72tuhoQ-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 5A063185A7A4; 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 2D93D40CF8EF; Fri, 3 Mar 2023 20:00:32 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 94CB94291962D; Fri, 3 Mar 2023 17:00:12 -0300 (-03) Message-ID: <20230303195908.851997547@redhat.com> User-Agent: quilt/0.67 Date: Fri, 03 Mar 2023 16:58:45 -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 04/11] this_cpu_cmpxchg: S390: switch this_cpu_cmpxchg to locked, add _local function References: <20230303195841.310844446@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: id4pukm5t9fg6oxr11brwmehxbhr3ns8 X-Rspamd-Queue-Id: A23A9180016 X-HE-Tag: 1677873635-467687 X-HE-Meta: U2FsdGVkX192QMGgxiLDOpLThzvh1n/yEX8O8EUfBszpbMAKNlwDNa3L1gmcbjpIalzUdUJ3eNaRsET9vS2+ca/K4ncGTuWfFby4p9rauxifSl1qpidH7rdWDnY4VciJk+hxAoX7b3ivc9zm2fsa0sVTyscXOCt7wqC0SQ1XsA6tqS21OFtULOHirB4LIf5/g9BCgihTyF43ziHLBfhKiLCm38ONWB5j6wOlXGYIL5NHFmFkKFs4+UYe+b8e8Q9H3VKYqfIbyB9lrb/+ozWxB3q6w11MFyB6LZQvs5i+vH4QvmC0stJjwr93pDy+271FJe6/GJphG94sfswT+H66uF218e7tDKNWdEc/GaVd1LQE+dko2M+S1pjF97lM4lA7im6caNduiUFtLsTSpr35eZU2AXNZ8UiEuR5qLbAwU7WGiFGLvHrGZQZniKw2nO0cV8dYvBu3Ao7u5pamqyL6KRtBFuvkgEQ2cCbyaE7a5MEU4uiCskimQcC/Eg2tfqdzkSyj8Kw1y8wzSu4SpdkjeUbOFzef9LGvtKME6bZpcIgTq7J8/bCxUCzuduYyRA4gJXAgFED7Ae7qm69zXKCceBw+PwOZcjfAt26znxwu32PjPKQHw7pzrjb5DB8V73+F1XxktZbsUMq/YPnkltbwsML69lyet9V0j3EHHCk+O47cLZuJ2RPuk0BtfRjy0rEr/7aKpxlilPD6UTr2AiWZvgfIpCq8ZF2dX/j9P9GDh6SS6gw25ZbRjqAaC+fVEOOuKy8W5ZKcFaca2sPVoDQv92nxh2FkPb2Zn+0wuZHSUhu2gtfLaP448VThtQ7vMJ9qEdGJehwSXnGHB+QmZCiYIsBvQjx34WcyDcp9z0rL41o3f57Wj4ND6figKQQ+VkqjT3g87HvEZ2c6RWTURFesAkHAgtr7LrzmybbdFWwOWNisV/5G9nQGZQIFIqaeZzl2yMPHmeVbLE+dDiXiBO5 dbsqln9r FSwXW0+pMDN6jfGRcwQpqMdSqhtN9MfVqs7B/8Yy4nqV8QwJFStP8DnWfVVsDn9YY1HyO1Uv2sWvSHMdeSpp45ffXO9UCt0MsJi+0b7MPxDV7+Zdi88lNlgVVI4ZpPNTg36q8caeyc0ceEXOztPePmDL/EiPLD6d8AnCucA7NmJqfc4+o17BPByfYCUT6i4vD32B6AGL2IVgO3qcy+R8a9UxnzvPo+OzQLApcm8x7mIH2vhMtK+0ldNDoYQ== 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: Goal is to have vmstat_shepherd to transfer from per-CPU counters to global counters remotely. For this, an atomic this_cpu_cmpxchg is necessary. Following the kernel convention for cmpxchg/cmpxchg_local, add S390's this_cpu_cmpxchg_local. Signed-off-by: Marcelo Tosatti Index: linux-vmstat-remote/arch/s390/include/asm/percpu.h =================================================================== --- linux-vmstat-remote.orig/arch/s390/include/asm/percpu.h +++ linux-vmstat-remote/arch/s390/include/asm/percpu.h @@ -148,6 +148,11 @@ #define this_cpu_cmpxchg_4(pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval) #define this_cpu_cmpxchg_8(pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval) +#define this_cpu_cmpxchg_local_1(pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval) +#define this_cpu_cmpxchg_local_2(pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval) +#define this_cpu_cmpxchg_local_4(pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval) +#define this_cpu_cmpxchg_local_8(pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval) + #define arch_this_cpu_xchg(pcp, nval) \ ({ \ typeof(pcp) *ptr__; \ From patchwork Fri Mar 3 19:58:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13159446 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 87C35C7EE32 for ; Fri, 3 Mar 2023 20:00:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A18396B0074; Fri, 3 Mar 2023 15:00:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9CA496B0072; Fri, 3 Mar 2023 15:00:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 623C36B007D; Fri, 3 Mar 2023 15:00:39 -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 353656B0073 for ; Fri, 3 Mar 2023 15:00:39 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0C8E81A1400 for ; Fri, 3 Mar 2023 20:00:39 +0000 (UTC) X-FDA: 80528654598.04.76E21BD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 3998D20029 for ; Fri, 3 Mar 2023 20:00:35 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cAvn16sE; spf=pass (imf03.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=1677873637; 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=hjd5gtUB1FFqfcJWUv9qrW5kcd1bszAAtI+X6kwFBXk=; b=YtuzVbBVq+NqpfQbn8zNXYsWF449Izz63gXgrVCdyqCBbgrwySvIVbhBkXY2duh8bCi3Do e8ysRxPeBcpRE42NMvVoE4E94VmGfK2NSe01sFOZSRp4qvpNfv2rO2u/7NugekpaxwtLj+ uvlG2y71BLTc1pknYlzMo+dB2NrT1yE= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cAvn16sE; spf=pass (imf03.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=1677873637; a=rsa-sha256; cv=none; b=KAuwf1460Sn+H/RU8Ahcl7l5Z8cJqRroAd4VQY46s3u8RzwsAv2AIXsN5io3gLxl7lniX/ ONgU9mQFpJNpVJHlLdB9p+Naa66QE5E+d2a5YuAJOh8QXwHrJhBG7GyFa0bxlqxwbadir5 NHMrWiSmq2okAydB6jIU7HcJaXCsP2Y= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677873634; 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=hjd5gtUB1FFqfcJWUv9qrW5kcd1bszAAtI+X6kwFBXk=; b=cAvn16sElGPFdX0SLNylPmeTJcgnHJhVfE/SGqjZ4bydY4b5SMKbmEWvXbZP7v9T/jzr68 +8llNiX4R2Hl1Gx9ukKMG9IccI4BYogiDQBrowqwhpionfDn53HsWVtTT/DNU6n7YvpUQ5 452kXY51M1aBgez1VD4C+g7Kj65BpAs= 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-101-cMDpLZCKMwyZ6cNzNBnl9Q-1; Fri, 03 Mar 2023 15:00:33 -0500 X-MC-Unique: cMDpLZCKMwyZ6cNzNBnl9Q-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 5BD4F280AA49; 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 093FF40BC781; Fri, 3 Mar 2023 20:00:32 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 986474291962E; Fri, 3 Mar 2023 17:00:12 -0300 (-03) Message-ID: <20230303195908.877083312@redhat.com> User-Agent: quilt/0.67 Date: Fri, 03 Mar 2023 16:58:46 -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 05/11] this_cpu_cmpxchg: x86: switch this_cpu_cmpxchg to locked, add _local function References: <20230303195841.310844446@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 3998D20029 X-Stat-Signature: o314ix38e9hxpjqkusgg6y173aogo563 X-Rspam-User: X-HE-Tag: 1677873635-576673 X-HE-Meta: U2FsdGVkX1+dcVTE+dW2uhBMhXk823FzXec3SbcnMIYrpA5nYroZgOb0Q945UrKZUZi2tCyY1N99DZ9/gfRj8k9bG0EFoIWbKxCV/Y1lXYPyn4LTkWKxYWHdJJcTZZcxG/oAa/YMHmPRa7B26rl/rTy6lRcd4XVn86FgAcwl7nEkjbdVRurQehr+yx4RyHwmx/Oifn5xtytTUrmj7t1cc9NGTtPRHRZ5LxOWn3JACxrA6+9UFrROUE2Zpj+iogBECUa0Rn0s7v2qoSDdWuMFVHH5XHn9E4KAKSQjNRib1VXc1DauqoRK2LWMDvL4cvR7zTe4YkIXVmnYyv2TLoAgbatWMF5d1nKnkfXI7Rfs5PrsxB3R2ip33MWI6Dmqw5bS1OehNHwpC9rQElXBtAVu+58tyyqOOoEIfEU8ns2LmTNFHHxKeimB46yzoGqtElWkPv9zbQxe6bqLNog6T82s9zKZOOCqf81iTsMfA3yLT1e40/ewH9s1msbkEutSwADMtG8RBsWplbO3jFBWzpyLePp+6cVu6w/xAYq5nARTKbK90LXcmXVOSJnVVknxpldt3mDOWnVjU5V/VU80/EMmKGe9TbhN9UqExJOj31WQRLEw/eYIA0Yzm86RoDS70gJI3kuttprgeTv+gmR6mCU/sisNNSDN6nwSaWzRqd0V+T2CCX+dd3Znho7gPJw7Si2oSiu6/ZbER920w5syWICTHLiypl0rquJ5//+C3q4grSy8CDWJ/OMXlEWxIJEZ8PkmXUPALKCjwoamWxbtfkZAG/krFz5cBh8IsiJMHzBkywDHtIFYN5ENxjJ7+IzcA2hPpIOyw8otBnlcmwYJJv2+JtgdIsXhaxP4kUzrrX7o4qajd120U+OItaEAnEQDYjbb4b9zyof2pvECQ3WdQxCTdYguf2s+HU0o7QCrQyfRolLlHqePGoj4LjU/XsaYIvvQlNqOk1y8JQedKYTFi90 iG3Y8ePx pnJGGmUYaGF2WcIMPE/WE/ffmqpN5+r8idMZM0TQ/sFbxqHuSn9pCOMOlR2LZcWMfXAK+lvzIMf4dWlJ259QniaFwUsgzFWslq20+oWo40vrLwj0j3Oe+T1d+EiJGZD7DFQasnnKwkEmOhHzA8GH2vocFx+cjdihGvDttMZXcmFzxh3osw9f1aQFFS6W1fxpMajhRib95O4wFT4s3o7xAddzCsojTu9N/fiBGT19z50oyWLmC1NYMNxJViA== 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: Goal is to have vmstat_shepherd to transfer from per-CPU counters to global counters remotely. For this, an atomic this_cpu_cmpxchg is necessary. Following the kernel convention for cmpxchg/cmpxchg_local, change x86's this_cpu_cmpxchg_ helpers to be atomic. and add this_cpu_cmpxchg_local_ helpers which are not atomic. Signed-off-by: Marcelo Tosatti Index: linux-vmstat-remote/arch/x86/include/asm/percpu.h =================================================================== --- linux-vmstat-remote.orig/arch/x86/include/asm/percpu.h +++ linux-vmstat-remote/arch/x86/include/asm/percpu.h @@ -197,11 +197,11 @@ do { \ * cmpxchg has no such implied lock semantics as a result it is much * more efficient for cpu local operations. */ -#define percpu_cmpxchg_op(size, qual, _var, _oval, _nval) \ +#define percpu_cmpxchg_op(size, qual, _var, _oval, _nval, lockp) \ ({ \ __pcpu_type_##size pco_old__ = __pcpu_cast_##size(_oval); \ __pcpu_type_##size pco_new__ = __pcpu_cast_##size(_nval); \ - asm qual (__pcpu_op2_##size("cmpxchg", "%[nval]", \ + asm qual (__pcpu_op2_##size(lockp "cmpxchg", "%[nval]", \ __percpu_arg([var])) \ : [oval] "+a" (pco_old__), \ [var] "+m" (_var) \ @@ -279,16 +279,20 @@ do { \ #define raw_cpu_add_return_1(pcp, val) percpu_add_return_op(1, , pcp, val) #define raw_cpu_add_return_2(pcp, val) percpu_add_return_op(2, , pcp, val) #define raw_cpu_add_return_4(pcp, val) percpu_add_return_op(4, , pcp, val) -#define raw_cpu_cmpxchg_1(pcp, oval, nval) percpu_cmpxchg_op(1, , pcp, oval, nval) -#define raw_cpu_cmpxchg_2(pcp, oval, nval) percpu_cmpxchg_op(2, , pcp, oval, nval) -#define raw_cpu_cmpxchg_4(pcp, oval, nval) percpu_cmpxchg_op(4, , pcp, oval, nval) +#define raw_cpu_cmpxchg_1(pcp, oval, nval) percpu_cmpxchg_op(1, , pcp, oval, nval, "") +#define raw_cpu_cmpxchg_2(pcp, oval, nval) percpu_cmpxchg_op(2, , pcp, oval, nval, "") +#define raw_cpu_cmpxchg_4(pcp, oval, nval) percpu_cmpxchg_op(4, , pcp, oval, nval, "") #define this_cpu_add_return_1(pcp, val) percpu_add_return_op(1, volatile, pcp, val) #define this_cpu_add_return_2(pcp, val) percpu_add_return_op(2, volatile, pcp, val) #define this_cpu_add_return_4(pcp, val) percpu_add_return_op(4, volatile, pcp, val) -#define this_cpu_cmpxchg_1(pcp, oval, nval) percpu_cmpxchg_op(1, volatile, pcp, oval, nval) -#define this_cpu_cmpxchg_2(pcp, oval, nval) percpu_cmpxchg_op(2, volatile, pcp, oval, nval) -#define this_cpu_cmpxchg_4(pcp, oval, nval) percpu_cmpxchg_op(4, volatile, pcp, oval, nval) +#define this_cpu_cmpxchg_local_1(pcp, oval, nval) percpu_cmpxchg_op(1, volatile, pcp, oval, nval, "") +#define this_cpu_cmpxchg_local_2(pcp, oval, nval) percpu_cmpxchg_op(2, volatile, pcp, oval, nval, "") +#define this_cpu_cmpxchg_local_4(pcp, oval, nval) percpu_cmpxchg_op(4, volatile, pcp, oval, nval, "") + +#define this_cpu_cmpxchg_1(pcp, oval, nval) percpu_cmpxchg_op(1, volatile, pcp, oval, nval, LOCK_PREFIX) +#define this_cpu_cmpxchg_2(pcp, oval, nval) percpu_cmpxchg_op(2, volatile, pcp, oval, nval, LOCK_PREFIX) +#define this_cpu_cmpxchg_4(pcp, oval, nval) percpu_cmpxchg_op(4, volatile, pcp, oval, nval, LOCK_PREFIX) #ifdef CONFIG_X86_CMPXCHG64 #define percpu_cmpxchg8b_double(pcp1, pcp2, o1, o2, n1, n2) \ @@ -319,16 +323,17 @@ do { \ #define raw_cpu_or_8(pcp, val) percpu_to_op(8, , "or", (pcp), val) #define raw_cpu_add_return_8(pcp, val) percpu_add_return_op(8, , pcp, val) #define raw_cpu_xchg_8(pcp, nval) raw_percpu_xchg_op(pcp, nval) -#define raw_cpu_cmpxchg_8(pcp, oval, nval) percpu_cmpxchg_op(8, , pcp, oval, nval) +#define raw_cpu_cmpxchg_8(pcp, oval, nval) percpu_cmpxchg_op(8, , pcp, oval, nval, "") -#define this_cpu_read_8(pcp) percpu_from_op(8, volatile, "mov", pcp) -#define this_cpu_write_8(pcp, val) percpu_to_op(8, volatile, "mov", (pcp), val) -#define this_cpu_add_8(pcp, val) percpu_add_op(8, volatile, (pcp), val) -#define this_cpu_and_8(pcp, val) percpu_to_op(8, volatile, "and", (pcp), val) -#define this_cpu_or_8(pcp, val) percpu_to_op(8, volatile, "or", (pcp), val) -#define this_cpu_add_return_8(pcp, val) percpu_add_return_op(8, volatile, pcp, val) -#define this_cpu_xchg_8(pcp, nval) percpu_xchg_op(8, volatile, pcp, nval) -#define this_cpu_cmpxchg_8(pcp, oval, nval) percpu_cmpxchg_op(8, volatile, pcp, oval, nval) +#define this_cpu_read_8(pcp) percpu_from_op(8, volatile, "mov", pcp) +#define this_cpu_write_8(pcp, val) percpu_to_op(8, volatile, "mov", (pcp), val) +#define this_cpu_add_8(pcp, val) percpu_add_op(8, volatile, (pcp), val) +#define this_cpu_and_8(pcp, val) percpu_to_op(8, volatile, "and", (pcp), val) +#define this_cpu_or_8(pcp, val) percpu_to_op(8, volatile, "or", (pcp), val) +#define this_cpu_add_return_8(pcp, val) percpu_add_return_op(8, volatile, pcp, val) +#define this_cpu_xchg_8(pcp, nval) percpu_xchg_op(8, volatile, pcp, nval) +#define this_cpu_cmpxchg_local_8(pcp, oval, nval) percpu_cmpxchg_op(8, volatile, pcp, oval, nval, "") +#define this_cpu_cmpxchg_8(pcp, oval, nval) percpu_cmpxchg_op(8, volatile, pcp, oval, nval, LOCK_PREFIX) /* * Pretty complex macro to generate cmpxchg16 instruction. The instruction From patchwork Fri Mar 3 19:58:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13159453 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 45777C7EE2F for ; Fri, 3 Mar 2023 20:00:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B03CE6B0080; Fri, 3 Mar 2023 15:00:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AB4666B0082; Fri, 3 Mar 2023 15:00:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 905C76B0083; Fri, 3 Mar 2023 15:00:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6DE346B0080 for ; Fri, 3 Mar 2023 15:00:41 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 4A93B1C6C66 for ; Fri, 3 Mar 2023 20:00:41 +0000 (UTC) X-FDA: 80528654682.20.A96E671 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 744D5140007 for ; Fri, 3 Mar 2023 20:00:39 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LMARRIQ8; 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=1677873639; 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=X5A6sr5GdS/CRp9e0AjLg+A82o3GBDzuPA8yAWqGcJk=; b=XeZeU9HSpNnZRPWr3OAFVG3vkKT6WKtZwPuvE31kBuFC6Yka4NnOojWonOUWYaEWjcWqbT MDwsUsOTvsyjK5IVlNaQ7YtivjA7GqcI3FM+E+fDqBPkrcZf2HBalqOstXw/+4VuenKpq/ 1h7151v01T9DVSPb3rV7s29PhdLll8o= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LMARRIQ8; 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=1677873639; a=rsa-sha256; cv=none; b=PjwxWqnPwBu8DxkcBG7oQ6DnA7m1q47vDgFKu3FonMGX80FojupUwMNsqwSQtXkyAflust tPDmAcYb1mUkMH4Y7Q9I/cGRbSvPSstPn1lFICaZN8Gf/XHHSFAWyBx1Ytj7xQ6s1YsBn8 S7tXpgAsyLsaoNj0LaRNwqYGJDEFHkg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677873638; 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=X5A6sr5GdS/CRp9e0AjLg+A82o3GBDzuPA8yAWqGcJk=; b=LMARRIQ8uj1AOPDiyx48/ckW0bZGlyePCLJ/4F8LLm5XaqnEVVANrjsjvYUDwUH6kmslvn o/prMK9AyxM20c/VPfBjKdgPhPZy8grHUC/NvCKQIA7mYbjZAscRldEut9Gc2nyEIh/Z7F DNWpO4RM0KA/4rLFVA44W9QUuC1pLrI= 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-70-TL7B6PkrOIq9tqOikCZwhA-1; Fri, 03 Mar 2023 15:00:32 -0500 X-MC-Unique: TL7B6PkrOIq9tqOikCZwhA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 403DE803491; 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 14CB4492B00; Fri, 3 Mar 2023 20:00:32 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 9DD5C4291962F; Fri, 3 Mar 2023 17:00:12 -0300 (-03) Message-ID: <20230303195908.901973993@redhat.com> User-Agent: quilt/0.67 Date: Fri, 03 Mar 2023 16:58:47 -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 06/11] add this_cpu_cmpxchg_local and asm-generic definitions References: <20230303195841.310844446@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 744D5140007 X-Rspam-User: X-Stat-Signature: pyasjfh6we5nopjm1dxnz7a1jukwue4d X-HE-Tag: 1677873639-422783 X-HE-Meta: U2FsdGVkX189qeDJnD6zrEb2XxdQIfLchkiD1Y6nHD1WpY260Cw5hPcINDhSAUnPLybVU5msfDpMLzMmIGgrCCnIW0gDjbUrM6gTXCEcs02RgLNxBEhaDhwvKxwYaIijQ6smr8qpiAeDeQ3b9+5kCXRzEoUlJGA8qLaQg3Z/qSpeWAXBn/uFLi0w5PhvoESoyspUr4VT0cpxcL0Mck5T1hpVhOT6lNdS6BPXGPMUjnff4g+v8w9FFsBiebD9jTAIwJSIprKpQ89PNVEuiLQB9gNIb8N242W9Pjy/QOD0i9j4FeV2UZ0VVxBBkrb7aqhHVml9Mr0lw48y6jMFBCirJiKW9DwWa/abn6dwfa9B6aB8s5DEmbz6+Gl9wDArGf60X9E4VYYpKG5iPLh4iJhla5doO/Mu1yKz1zZb6qC4X3cbdFWKYl/lIEGGZI8J0hIEmxsdDTA9iMVjsQz1YOcyilGx6cXu3d4R0ERcl+PDTsbgtjJSELBgCqIj2MtfjdeqKobG0PHLcfCStfDQwyC8DBDOa/gHept7jEpgC/UXzYyrofuAMDyBWKyi4paE7GRnoFASQyH6anKCvTllnOI0NVsSR1EoR5D3ujEcjaXJDArpzbASagrPzFTcsUx/0z7ne8saehOpKw4XP7ydKicWAHL85Q4kk0ZzlEmJYGZtd7jrzty9sq3kNClgE3rpDasu8zq+aODmeykSw8GIX7MXIdRABwed/2ZQxsBFdMccdBuRgf+rA9cV2RC0FgbLEfPVjTma8u9wHAX52pnz9jAtqhg3oulqMR5j8DxMrc5sATqx4kDCMMC5C1Myar/9/LaiF6JFziW1w7CyHi/IW9gOzsSu6PQEbepNCqPJYrv45rWz9s0erSj3b2BAIDO+aIp4HwcXVynjHuolwIey4rlfQ2eZRMjH54mbAIhuWll6H9ZBA5IJzuQiSQFGNvBwyW8RKYJvcF6ejynVbPSZHjx RpRXm/5q SmAH+lbRx/u3E/6388k66qCoDhqx5c/ELaFvvf03pSRWr3GQ7kUwpf5YLnePWI3t6z2GOUi7pGF48UbvdLAx1GvFYpxKe8ZWud40HYyKN3WWkUF/hSUsooIC7cuZeuWRz4BIfQZ77ydWFSM8gPG2o208ruZW9OB9Vaq02nOanJwmpGud1wRYByrXhdvIsbnY85zojwz+fG2GyBbEn9EawnGu1w70NnW/AcXkc7eIVy3K+1rva1yoTzd2bcg== 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: Goal is to have vmstat_shepherd to transfer from per-CPU counters to global counters remotely. For this, an atomic this_cpu_cmpxchg is necessary. Add this_cpu_cmpxchg_local_ helpers to asm-generic/percpu.h. Signed-off-by: Marcelo Tosatti Index: linux-vmstat-remote/include/asm-generic/percpu.h =================================================================== --- linux-vmstat-remote.orig/include/asm-generic/percpu.h +++ linux-vmstat-remote/include/asm-generic/percpu.h @@ -424,6 +424,23 @@ do { \ this_cpu_generic_cmpxchg(pcp, oval, nval) #endif +#ifndef this_cpu_cmpxchg_local_1 +#define this_cpu_cmpxchg_local_1(pcp, oval, nval) \ + this_cpu_generic_cmpxchg(pcp, oval, nval) +#endif +#ifndef this_cpu_cmpxchg_local_2 +#define this_cpu_cmpxchg_local_2(pcp, oval, nval) \ + this_cpu_generic_cmpxchg(pcp, oval, nval) +#endif +#ifndef this_cpu_cmpxchg_local_4 +#define this_cpu_cmpxchg_local_4(pcp, oval, nval) \ + this_cpu_generic_cmpxchg(pcp, oval, nval) +#endif +#ifndef this_cpu_cmpxchg_local_8 +#define this_cpu_cmpxchg_local_8(pcp, oval, nval) \ + this_cpu_generic_cmpxchg(pcp, oval, nval) +#endif + #ifndef this_cpu_cmpxchg_double_1 #define this_cpu_cmpxchg_double_1(pcp1, pcp2, oval1, oval2, nval1, nval2) \ this_cpu_generic_cmpxchg_double(pcp1, pcp2, oval1, oval2, nval1, nval2) Index: linux-vmstat-remote/include/linux/percpu-defs.h =================================================================== --- linux-vmstat-remote.orig/include/linux/percpu-defs.h +++ linux-vmstat-remote/include/linux/percpu-defs.h @@ -513,6 +513,8 @@ do { \ #define this_cpu_xchg(pcp, nval) __pcpu_size_call_return2(this_cpu_xchg_, pcp, nval) #define this_cpu_cmpxchg(pcp, oval, nval) \ __pcpu_size_call_return2(this_cpu_cmpxchg_, pcp, oval, nval) +#define this_cpu_cmpxchg_local(pcp, oval, nval) \ + __pcpu_size_call_return2(this_cpu_cmpxchg_local_, pcp, oval, nval) #define this_cpu_cmpxchg_double(pcp1, pcp2, oval1, oval2, nval1, nval2) \ __pcpu_double_call_return_bool(this_cpu_cmpxchg_double_, pcp1, pcp2, oval1, oval2, nval1, nval2) From patchwork Fri Mar 3 19:58:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13159449 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 4B40BC7EE32 for ; Fri, 3 Mar 2023 20:00:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 33BB96B0081; Fri, 3 Mar 2023 15:00:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E9B36B0078; Fri, 3 Mar 2023 15:00:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 093246B0083; Fri, 3 Mar 2023 15:00:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C309A6B0080 for ; Fri, 3 Mar 2023 15:00:39 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8FEFB14142A for ; Fri, 3 Mar 2023 20:00:39 +0000 (UTC) X-FDA: 80528654598.23.CD0E907 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id A519640023 for ; Fri, 3 Mar 2023 20:00:36 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=F5g96e2w; spf=pass (imf07.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=1677873637; a=rsa-sha256; cv=none; b=ATxeuIq4/V8kTR0obanu4RUTBdPgeeTSa76GxnU3X7wcotil3KLCleTW6dN9y0p2GFyRq5 7eJXT3iocC62D/nHGJiz+r1H435gOSVwwhYJ7gX8F1dJSXcRQzTn8veqeFGGd08aXPDMDZ GjywtIpWrUL3LyX4CWvD05I6o4AjmI0= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=F5g96e2w; spf=pass (imf07.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=1677873637; 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=4jas7+kZOWWtovsxw7rARjyOL6nO08FiGsNhXOwYk0U=; b=Tn4tuY6ATvkuWSA0VPMMU185WosRail9oX0rePgqe/CvNqG/wPiN6BJRvLHXEpoSGEVumj gsACplCX+rbZWPxdFRi9d/ZYMkfWnz82Wb6Nsx4x0M3hoj0CPb/LaTz7STaq0WukxSCt9Y 56zExahUmR3MWncborW94DUV4rHM3B4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677873636; 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=4jas7+kZOWWtovsxw7rARjyOL6nO08FiGsNhXOwYk0U=; b=F5g96e2wznCSan//sgQ3LR0YBN1wsPKkjOYww1NA9ZZBD/Lol6YWCJxYgUBkEubFEJFNeY yY6l73FwTm2xB+U3lXeakHIeD2pwrRKgTYe5nTGZ/W7GUEe4no7KYHSpK8lVoTvgSVWr4s mY1NZyRhY3cJezibppZxa/NUfdB/tnY= 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-70-XHhHsPN-OM-HKLtx0grcWA-1; Fri, 03 Mar 2023 15:00:32 -0500 X-MC-Unique: XHhHsPN-OM-HKLtx0grcWA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3AA4F80D0F1; 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 0612A492C14; Fri, 3 Mar 2023 20:00:32 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id A344242919630; Fri, 3 Mar 2023 17:00:12 -0300 (-03) Message-ID: <20230303195908.926950608@redhat.com> User-Agent: quilt/0.67 Date: Fri, 03 Mar 2023 16:58:48 -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, Peter Xu , Marcelo Tosatti Subject: [PATCH v3 07/11] convert this_cpu_cmpxchg users to this_cpu_cmpxchg_local References: <20230303195841.310844446@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspam-User: X-Rspamd-Queue-Id: A519640023 X-Rspamd-Server: rspam01 X-Stat-Signature: necbjn4kmqdjq5p6atzjqdfp3i3j1a4i X-HE-Tag: 1677873636-434849 X-HE-Meta: U2FsdGVkX1905xX0O66moTvh8C2dJN/Q3ZV6W582HyjP3b5y7vp4YGYVrLhzBiv7rJ81b73QDznWUKLEOm8DPV3E1OpIp+0tatc8GTYzNO7vAqLmQ+CQGS24mct1jyPulYo7s6jRZ/aQ3xAFuvhnUHYXtyOAsY4Sw+hePt6beGQv7KG1qs/QbNmEz3gEkaUGuQPVfKwvFHck7empFN/zz+qwe1uvNZdMwLptKd48FUHB/GZnkZh/OI/+ltCnr0TiLpts3MOkK5g6gWlNllDxHMHQ1TE01IvaeD29dLraDjD+xEdKKlRjtXYV3X+E9QUIq11CktrkDHpjLzZTy3E0YjVNlZvZleKDxP3UM/NuUvefMNkLtuk5bpxP0aLK4eUnWnP+A9SE+/+9yF2fuv5qtfdHeuKXPU4zXwS8fmVwhs+vo1xykPR5rbdrBNT7hEFQCtzOTX6wE5cmNl+H6uTdz+y9uYulFpmm6km54/N+qMpMoROVzZMNLAp8w0nZ7Zze+lKIP3Pc0f2lN8b7NlXUl4R+RI4IL5ZWfoTlweTlxDKlSYDQN92//TcypGMw+0/qdzbtgUHoFi+c9+UDs9ais51akLegIUgzywqJw1VZ9T5tXiiP0yO24L1kcPnXJxnZDJxtkDY4sCftB09LBto8bDZ1L+b3Pmetm0DNZ4PuG1mMzU+0rNupcS1NTjBaXPKQnW6zgo4/Ev7rc7HcIoA8U+kgtJcNNpRKasLUimWHKFS+CuK/a0JS0v0aF/FOsF+bVAMJgaRgBzw0jT9PusEj5Zj7qwzxftKb1r54As2YUW5bGngpUjSOAbANucfhNK3DkaGDDbrThtqf9KcPX/Ffi5bt/I6l8VKH7SlEG8Jyc69AZufPVUaZKDgHZzkw/X9vRg07oiEPVf0SVS75H5GUnfIL8Yd8R8I6wQURlOcE+Byg8Sq+QFUj7WMQanHm31L0XWFkxzxpeHGEDi4JZlL SSYDTwBL bG/Y3CDtteUHAB3Bcy4xMP8JEhtnkvrkDpatREj08M50d+fS54+/BNrP9Y8q2g3qhpKDUWwLYo8SHQdIi2awpLGpZskMm9EJR7QpGaPubmIyjUsQ6edD0GMz+czvPS64NBfDIJ0gDYcWfnFP9/ATNAbr7vhgktbMTJLl8QhuDO+d6n2pbJAcI0C1HhXiaVZ3KaD5gbFTSJY2wMctTzlz2BntYtwTwfcfwxCHXlnTMoRuBELIGd5ygFZdVTw== 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: this_cpu_cmpxchg was modified to atomic version, which can be more costly than non-atomic version. Switch users of this_cpu_cmpxchg to this_cpu_cmpxchg_local (which preserves pre-non-atomic this_cpu_cmpxchg behaviour). Acked-by: Peter Xu Signed-off-by: Marcelo Tosatti Index: linux-vmstat-remote/kernel/fork.c =================================================================== --- linux-vmstat-remote.orig/kernel/fork.c +++ linux-vmstat-remote/kernel/fork.c @@ -203,7 +203,7 @@ static bool try_release_thread_stack_to_ unsigned int i; for (i = 0; i < NR_CACHED_STACKS; i++) { - if (this_cpu_cmpxchg(cached_stacks[i], NULL, vm) != NULL) + if (this_cpu_cmpxchg_local(cached_stacks[i], NULL, vm) != NULL) continue; return true; } Index: linux-vmstat-remote/kernel/scs.c =================================================================== --- linux-vmstat-remote.orig/kernel/scs.c +++ linux-vmstat-remote/kernel/scs.c @@ -83,7 +83,7 @@ void scs_free(void *s) */ for (i = 0; i < NR_CACHED_SCS; i++) - if (this_cpu_cmpxchg(scs_cache[i], 0, s) == NULL) + if (this_cpu_cmpxchg_local(scs_cache[i], 0, s) == NULL) return; kasan_unpoison_vmalloc(s, SCS_SIZE, KASAN_VMALLOC_PROT_NORMAL); From patchwork Fri Mar 3 19:58:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13159448 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 1E314C7EE2F for ; Fri, 3 Mar 2023 20:00:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1147F6B0072; Fri, 3 Mar 2023 15:00:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0CC626B0082; Fri, 3 Mar 2023 15:00:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A3D156B007D; Fri, 3 Mar 2023 15:00:39 -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 798036B0078 for ; Fri, 3 Mar 2023 15:00:39 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 47EDFA123D for ; Fri, 3 Mar 2023 20:00:39 +0000 (UTC) X-FDA: 80528654598.28.E71C5A3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 46BDE4000F for ; Fri, 3 Mar 2023 20:00:37 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="IBjJ/fBZ"; spf=pass (imf01.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=1677873637; 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=kck/KScqtu56KKjBhC7jhwkN1m2f1dyAwfBXk4OMNDU=; b=Ply/X7WIxqncmNZkXsFEPI6GI5asE4RaWMLj1MnRLGGl2aoMPUW05y5m4gPuV4rogUDtlB NvUKfX+FveTvMue5w810EqCaOlZ2aqlt0Alc/4G9h/XDOv/6n6Ndu3o/IFXDqz9mguRkbi D0iQCBjpdshew35HftJMWMtBoAZHguM= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="IBjJ/fBZ"; spf=pass (imf01.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=1677873637; a=rsa-sha256; cv=none; b=CYK8Xy2ZtNx59nb3ML4vt2yYhXV5wkWwcbDBvIPB9Uy49mLUbyu3GW2MpmkiAjhskn/63n Nm9Sucd/PN2c5AHmENNyixsPaiTAI3kxSPJuUMEHStj4xQQ988+SxXBHOTSJoKTTPInRAX gfnw+F7UNPZppM8Pf4HVbI394xmuNUI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677873636; 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=kck/KScqtu56KKjBhC7jhwkN1m2f1dyAwfBXk4OMNDU=; b=IBjJ/fBZKe5B7YF6KGfCUuzpgdjpRWBZhAvr1aPe8U3YAPkindQre8PWtJ5VTN2M+cOYfd 8RTDso7bFt6MXs4kLRP0l7SnO62o2ntK5roLbkrG4kuFsXucWvCg0wtxboCVhUsFQdhXx2 JpoujeL/mVrvyDX2bwYasOI+22VPm2M= 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-634-3UIEbQqAPI-iF1Ofjgcasg-1; Fri, 03 Mar 2023 15:00:33 -0500 X-MC-Unique: 3UIEbQqAPI-iF1Ofjgcasg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 82FB2858F09; 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 31152492C18; Fri, 3 Mar 2023 20:00:32 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id A7AFB42919631; Fri, 3 Mar 2023 17:00:12 -0300 (-03) Message-ID: <20230303195908.952010050@redhat.com> User-Agent: quilt/0.67 Date: Fri, 03 Mar 2023 16:58:49 -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 08/11] mm/vmstat: switch counter modification to cmpxchg References: <20230303195841.310844446@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspamd-Queue-Id: 46BDE4000F X-Stat-Signature: yctdtzunx5ysaw8k73a6ffznf661n8ys X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1677873637-524111 X-HE-Meta: U2FsdGVkX1/XHG/U9Xvu1zb03DW93nrKz3yWwXGWr0wdsa+Q9GYW3qZRkR1PZRoUbU0H2rBlXXz5UA79seoNrEIUjPkzhx+h+QYDuKRJfZUbT2zdOfVUg1AQLXhAkWsYEK6DMZlt9/qS9llQFEOeafkiyB/ADRVUpEgsJuxm/Vohj0Bk3/JfDtHwMhXMVDlWr7Ob18UKP78kdjIEmwzPr4SsY69VhtvuAVBUiRr5pdyWplnhwxyXkQ/6g+LuSXi3JgLw2U+bSACG10Vnw6HlXkoXw1+f+gxv9h3t+zLaZib2EffmKvklTIgQTrYiRSs5O274hDjqcX6duVPcEKMSiJWnTknZtG9l7VaQYrgQ0zG8yRSCv9Nlf9ggqYmrqX8/aQB2WndsbeyhURFI8qP27hWC4RnCH/SfhiRxE4OHdl207aAdJnjDmq5wY9VR/EpBaq+ZEETru/urbRvSfpaIsVTfrwEI8Iy3EL8FPekkn71I5LHpHUmUv/5p+B++01GDcnXXhwXqTsqZaGKEaDug5pFmBFf3E0wzg7258OrH94Vid05tlTnlOvYJLXWx9N3rurwdHKcKjvmgoAKJ/cpNOEjcitENIAUjXQKksAO3rt4TNZFOHGZW0PvH08xyhmC9mk4LfBHZBSXdElZOoKAegrzcLZWGlQuxpHJlDoS8OsMTmuxawmeZllyUqbvhS6CyMKyB6VcFnplWP5Cki0dam0YxkD1XyCMz68QFAdi+hvhkylEpyIMIiePhpRmrKEs5MaFAhLEmX5U0SPVXt9OoPYMsrtNldDy3t6cGuSP7z+vK7Zw4EGOMmHMzHNQGeRzUi5eEs5TfPa083PQGKHxJeHmqMxK9PwcDNZeXQgUdlxGbJa27mZU9TiYp4EkXwhFZZ7abNQ4DIpI8LL5KCAGeKCjDmUc6F0pQwXQox+SFcUeumohCgq/zOL1Efer2h1+tI512SK/fu16dswNofBo 1FSDzBW6 UvW4eRMNmoN30xCu0sLsazFKYqmwT+xdr30eMxBpewVIwKlstJfG5HhnDXo16O/b5NSrzsKnyTpbe+J7oDUDzCPwRO4mwNCwwSJakIUxnWhjVZBGToaSlkHbtksllzDdWsZJr3P/Q85MYzqrAx7F3CBMZXrK682pRqypR9SZXtedsp3mgd1qCosnSpECGbaOygkFDnILY1uGBsS+EQAGDh2yeD2AcCjFyM5BP 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 for switching vmstat shepherd to flush per-CPU counters remotely, switch the __{mod,inc,dec} functions that modify the counters to use cmpxchg. To facilitate reviewing, functions are ordered in the text file, as: __{mod,inc,dec}_{zone,node}_page_state #ifdef CONFIG_HAVE_CMPXCHG_LOCAL {mod,inc,dec}_{zone,node}_page_state #else {mod,inc,dec}_{zone,node}_page_state #endif This patch defines the __ versions for the CONFIG_HAVE_CMPXCHG_LOCAL case to be their non-"__" counterparts: #ifdef CONFIG_HAVE_CMPXCHG_LOCAL {mod,inc,dec}_{zone,node}_page_state __{mod,inc,dec}_{zone,node}_page_state = {mod,inc,dec}_{zone,node}_page_state #else {mod,inc,dec}_{zone,node}_page_state __{mod,inc,dec}_{zone,node}_page_state #endif To test the performance difference, a page allocator microbenchmark: https://github.com/netoptimizer/prototype-kernel/blob/master/kernel/mm/bench/page_bench01.c with loops=1000000 was used, on Intel Core i7-11850H @ 2.50GHz. For the single_page_alloc_free test, which does /** Loop to measure **/ for (i = 0; i < rec->loops; i++) { my_page = alloc_page(gfp_mask); if (unlikely(my_page == NULL)) return 0; __free_page(my_page); } Unit is cycles. Vanilla Patched Diff 115.25 117 1.4% 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 @@ -334,6 +334,188 @@ void set_pgdat_percpu_threshold(pg_data_ } } +#ifdef CONFIG_HAVE_CMPXCHG_LOCAL +/* + * If we have cmpxchg_local support then we do not need to incur the overhead + * that comes with local_irq_save/restore if we use this_cpu_cmpxchg. + * + * mod_state() modifies the zone counter state through atomic per cpu + * operations. + * + * Overstep mode specifies how overstep should handled: + * 0 No overstepping + * 1 Overstepping half of threshold + * -1 Overstepping minus half of threshold + */ +static inline void mod_zone_state(struct zone *zone, enum zone_stat_item item, + long delta, int overstep_mode) +{ + struct per_cpu_zonestat __percpu *pcp = zone->per_cpu_zonestats; + s8 __percpu *p = pcp->vm_stat_diff + item; + long o, n, t, z; + + do { + z = 0; /* overflow to zone counters */ + + /* + * The fetching of the stat_threshold is racy. We may apply + * a counter threshold to the wrong the cpu if we get + * rescheduled while executing here. However, the next + * counter update will apply the threshold again and + * therefore bring the counter under the threshold again. + * + * Most of the time the thresholds are the same anyways + * for all cpus in a zone. + */ + t = this_cpu_read(pcp->stat_threshold); + + o = this_cpu_read(*p); + n = delta + o; + + if (abs(n) > t) { + int os = overstep_mode * (t >> 1); + + /* Overflow must be added to zone counters */ + z = n + os; + n = -os; + } + } while (this_cpu_cmpxchg(*p, o, n) != o); + + if (z) + zone_page_state_add(z, zone, item); +} + +void mod_zone_page_state(struct zone *zone, enum zone_stat_item item, + long delta) +{ + mod_zone_state(zone, item, delta, 0); +} +EXPORT_SYMBOL(mod_zone_page_state); + +void __mod_zone_page_state(struct zone *zone, enum zone_stat_item item, + long delta) +{ + mod_zone_state(zone, item, delta, 0); +} +EXPORT_SYMBOL(__mod_zone_page_state); + +void inc_zone_page_state(struct page *page, enum zone_stat_item item) +{ + mod_zone_state(page_zone(page), item, 1, 1); +} +EXPORT_SYMBOL(inc_zone_page_state); + +void __inc_zone_page_state(struct page *page, enum zone_stat_item item) +{ + mod_zone_state(page_zone(page), item, 1, 1); +} +EXPORT_SYMBOL(__inc_zone_page_state); + +void dec_zone_page_state(struct page *page, enum zone_stat_item item) +{ + mod_zone_state(page_zone(page), item, -1, -1); +} +EXPORT_SYMBOL(dec_zone_page_state); + +void __dec_zone_page_state(struct page *page, enum zone_stat_item item) +{ + mod_zone_state(page_zone(page), item, -1, -1); +} +EXPORT_SYMBOL(__dec_zone_page_state); + +static inline void mod_node_state(struct pglist_data *pgdat, + enum node_stat_item item, + int delta, int overstep_mode) +{ + struct per_cpu_nodestat __percpu *pcp = pgdat->per_cpu_nodestats; + s8 __percpu *p = pcp->vm_node_stat_diff + item; + long o, n, t, z; + + if (vmstat_item_in_bytes(item)) { + /* + * Only cgroups use subpage accounting right now; at + * the global level, these items still change in + * multiples of whole pages. Store them as pages + * internally to keep the per-cpu counters compact. + */ + VM_WARN_ON_ONCE(delta & (PAGE_SIZE - 1)); + delta >>= PAGE_SHIFT; + } + + do { + z = 0; /* overflow to node counters */ + + /* + * The fetching of the stat_threshold is racy. We may apply + * a counter threshold to the wrong the cpu if we get + * rescheduled while executing here. However, the next + * counter update will apply the threshold again and + * therefore bring the counter under the threshold again. + * + * Most of the time the thresholds are the same anyways + * for all cpus in a node. + */ + t = this_cpu_read(pcp->stat_threshold); + + o = this_cpu_read(*p); + n = delta + o; + + if (abs(n) > t) { + int os = overstep_mode * (t >> 1); + + /* Overflow must be added to node counters */ + z = n + os; + n = -os; + } + } while (this_cpu_cmpxchg(*p, o, n) != o); + + if (z) + node_page_state_add(z, pgdat, item); +} + +void mod_node_page_state(struct pglist_data *pgdat, enum node_stat_item item, + long delta) +{ + mod_node_state(pgdat, item, delta, 0); +} +EXPORT_SYMBOL(mod_node_page_state); + +void __mod_node_page_state(struct pglist_data *pgdat, enum node_stat_item item, + long delta) +{ + mod_node_state(pgdat, item, delta, 0); +} +EXPORT_SYMBOL(__mod_node_page_state); + +void inc_node_state(struct pglist_data *pgdat, enum node_stat_item item) +{ + mod_node_state(pgdat, item, 1, 1); +} + +void inc_node_page_state(struct page *page, enum node_stat_item item) +{ + mod_node_state(page_pgdat(page), item, 1, 1); +} +EXPORT_SYMBOL(inc_node_page_state); + +void __inc_node_page_state(struct page *page, enum node_stat_item item) +{ + mod_node_state(page_pgdat(page), item, 1, 1); +} +EXPORT_SYMBOL(__inc_node_page_state); + +void dec_node_page_state(struct page *page, enum node_stat_item item) +{ + mod_node_state(page_pgdat(page), item, -1, -1); +} +EXPORT_SYMBOL(dec_node_page_state); + +void __dec_node_page_state(struct page *page, enum node_stat_item item) +{ + mod_node_state(page_pgdat(page), item, -1, -1); +} +EXPORT_SYMBOL(__dec_node_page_state); +#else /* * For use when we know that interrupts are disabled, * or when we know that preemption is disabled and that @@ -541,149 +723,6 @@ void __dec_node_page_state(struct page * } EXPORT_SYMBOL(__dec_node_page_state); -#ifdef CONFIG_HAVE_CMPXCHG_LOCAL -/* - * If we have cmpxchg_local support then we do not need to incur the overhead - * that comes with local_irq_save/restore if we use this_cpu_cmpxchg. - * - * mod_state() modifies the zone counter state through atomic per cpu - * operations. - * - * Overstep mode specifies how overstep should handled: - * 0 No overstepping - * 1 Overstepping half of threshold - * -1 Overstepping minus half of threshold -*/ -static inline void mod_zone_state(struct zone *zone, - enum zone_stat_item item, long delta, int overstep_mode) -{ - struct per_cpu_zonestat __percpu *pcp = zone->per_cpu_zonestats; - s8 __percpu *p = pcp->vm_stat_diff + item; - long o, n, t, z; - - do { - z = 0; /* overflow to zone counters */ - - /* - * The fetching of the stat_threshold is racy. We may apply - * a counter threshold to the wrong the cpu if we get - * rescheduled while executing here. However, the next - * counter update will apply the threshold again and - * therefore bring the counter under the threshold again. - * - * Most of the time the thresholds are the same anyways - * for all cpus in a zone. - */ - t = this_cpu_read(pcp->stat_threshold); - - o = this_cpu_read(*p); - n = delta + o; - - if (abs(n) > t) { - int os = overstep_mode * (t >> 1) ; - - /* Overflow must be added to zone counters */ - z = n + os; - n = -os; - } - } while (this_cpu_cmpxchg(*p, o, n) != o); - - if (z) - zone_page_state_add(z, zone, item); -} - -void mod_zone_page_state(struct zone *zone, enum zone_stat_item item, - long delta) -{ - mod_zone_state(zone, item, delta, 0); -} -EXPORT_SYMBOL(mod_zone_page_state); - -void inc_zone_page_state(struct page *page, enum zone_stat_item item) -{ - mod_zone_state(page_zone(page), item, 1, 1); -} -EXPORT_SYMBOL(inc_zone_page_state); - -void dec_zone_page_state(struct page *page, enum zone_stat_item item) -{ - mod_zone_state(page_zone(page), item, -1, -1); -} -EXPORT_SYMBOL(dec_zone_page_state); - -static inline void mod_node_state(struct pglist_data *pgdat, - enum node_stat_item item, int delta, int overstep_mode) -{ - struct per_cpu_nodestat __percpu *pcp = pgdat->per_cpu_nodestats; - s8 __percpu *p = pcp->vm_node_stat_diff + item; - long o, n, t, z; - - if (vmstat_item_in_bytes(item)) { - /* - * Only cgroups use subpage accounting right now; at - * the global level, these items still change in - * multiples of whole pages. Store them as pages - * internally to keep the per-cpu counters compact. - */ - VM_WARN_ON_ONCE(delta & (PAGE_SIZE - 1)); - delta >>= PAGE_SHIFT; - } - - do { - z = 0; /* overflow to node counters */ - - /* - * The fetching of the stat_threshold is racy. We may apply - * a counter threshold to the wrong the cpu if we get - * rescheduled while executing here. However, the next - * counter update will apply the threshold again and - * therefore bring the counter under the threshold again. - * - * Most of the time the thresholds are the same anyways - * for all cpus in a node. - */ - t = this_cpu_read(pcp->stat_threshold); - - o = this_cpu_read(*p); - n = delta + o; - - if (abs(n) > t) { - int os = overstep_mode * (t >> 1) ; - - /* Overflow must be added to node counters */ - z = n + os; - n = -os; - } - } while (this_cpu_cmpxchg(*p, o, n) != o); - - if (z) - node_page_state_add(z, pgdat, item); -} - -void mod_node_page_state(struct pglist_data *pgdat, enum node_stat_item item, - long delta) -{ - mod_node_state(pgdat, item, delta, 0); -} -EXPORT_SYMBOL(mod_node_page_state); - -void inc_node_state(struct pglist_data *pgdat, enum node_stat_item item) -{ - mod_node_state(pgdat, item, 1, 1); -} - -void inc_node_page_state(struct page *page, enum node_stat_item item) -{ - mod_node_state(page_pgdat(page), item, 1, 1); -} -EXPORT_SYMBOL(inc_node_page_state); - -void dec_node_page_state(struct page *page, enum node_stat_item item) -{ - mod_node_state(page_pgdat(page), item, -1, -1); -} -EXPORT_SYMBOL(dec_node_page_state); -#else /* * Use interrupt disable to serialize counter updates */ Index: linux-vmstat-remote/mm/page_alloc.c =================================================================== --- linux-vmstat-remote.orig/mm/page_alloc.c +++ linux-vmstat-remote/mm/page_alloc.c @@ -8608,9 +8608,6 @@ static int page_alloc_cpu_dead(unsigned /* * Zero the differential counters of the dead processor * so that the vm statistics are consistent. - * - * This is only okay since the processor is dead and cannot - * race with what we are doing. */ cpu_vm_stats_fold(cpu); 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: 13159454 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 BB582C64EC4 for ; Fri, 3 Mar 2023 20:00:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 07C096B0082; Fri, 3 Mar 2023 15:00:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 02B7F6B0083; Fri, 3 Mar 2023 15:00:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E11E86B0085; Fri, 3 Mar 2023 15:00:41 -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 B8E5C6B0083 for ; Fri, 3 Mar 2023 15:00:41 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8BED181331 for ; Fri, 3 Mar 2023 20:00:41 +0000 (UTC) X-FDA: 80528654682.14.FF6F322 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf05.hostedemail.com (Postfix) with ESMTP id CECE8100016 for ; Fri, 3 Mar 2023 20:00:39 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LHQZ8E0q; spf=pass (imf05.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=1677873639; 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=YjZzxvwbzUGJAOWGom5FEayhMjnpZ78I4D4VtdieNs8=; b=27WclZtc89zgJ5b+/4oYMSvnltgUxhnun+2P8LTC3/kjrJCFeR+YEjoccmQ9qBeqgVOg+n jz3ibbCj4o7yaHYwINhjnkB1d+JB1KiwgVFapgbS4Q/nt5z/FMeBI8CZKcCT5Z6cJNhSIt 9EPqc2+uhKvgkrAd9UJPM2v239p5CbY= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LHQZ8E0q; spf=pass (imf05.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=1677873639; a=rsa-sha256; cv=none; b=VdtHe/6R9lTwk2dPCarXBVKIOO0iLjgZejQvZv+832el6P+3/Zuwr5q5MtxmvWz+dgHSEM hCTRR2NuYiagpwnuH/TS+MS36zyprxv3MKXPniu4pARsIOhJj5lLNFXXs0pibRNx/Y+yOF z50G10meKMilAUXxxlzCkLPmMELqyIw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677873639; 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=LHQZ8E0qRTdKgK+K9SgZ5gx5RZNHgpAPj4JjIlWxflC7Q9k2SL4Umr/Y36ml2Hq2o+7zeI Y5CInG2DXpe9BfqdsamGqARaG605UyZ4b4UU/LFYP0lRtG1NT9GoyHYzPsLyJvqkAYpSsi 0oEkLKgfgb9czoFe426NPwUPBUtwErE= 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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: CECE8100016 X-Stat-Signature: gyp8hshum18fcupiy9wyo63ujjedt8nc X-Rspam-User: X-HE-Tag: 1677873639-387474 X-HE-Meta: U2FsdGVkX1/I/TjzXRC4BErPy1COqp+z0l7JjZTKZfSJ+YTUdNY34s4nBxGWf8e1skXoMe8k0Sp9AQ/fnZ8EaS8xIM0vi/LwtrdtXgEpC58ms2/NX8xsAlqbFPGcaCq6EiCwxpFysqNOo/SSXlHMcTKNcIWyxkEutrL34z3bQIhhMb3J5JoJ3FeS7Lsk+5CNbQYeUpcZi0x7VF7+20SeHZT61n+3J105Y2BxUZP+7pOijWfC5jU3xy5qmVD6eLYBrDHDcRBAY+q8IZlYCkZ0Bnu2yHv7uaE3tnGAsSmCXPTFEH5AjcieBnqXl3X2e+PzG86HFzrLqWEmZ/AXi+JyXDqyaEyjqbNd8QJvmEfyHpAMVsEapPGXUTP1izxkqRRHB33wcdrtjvKDRQUI7si7ZnCSGHB8ZUDCTmyvz4SPP3mcJLSvgQ+kruVk55FvCLN5/UEGEmTS/C0bQ+uJhuXOiUo5404/KFPGOqM6b4qCClu6uz7oK4RxxPMc/JEd166HyaAygMa4nJCoHwpF6SW3wMcOgfioieojJRlh73x+Z00ZmQef3nbFxo5EK/NJJpjcOV4kEwcCLVL1MdfvtJBi4JGUaQqgmyk8X3kgUBFpoc8VZJjGL8WycIEmwlBrJGTH4RTEsLhIo7YLk9rvouA52M5gelEEszCYKH+FS1dx3UKcvd6SOaUbMHG/fIMKyntjRoi1zv2v0SVOT0Mj3uCj3jAzUXDFO1EK6Cryz992iVdSTvSkDSSKAS87gci5hDB/tEzwm/YlRYU8xksf71XpCojAvnAmLykKNCjSqLqyYr7dOUV2ZTyvG65bJEku5vZ/3MrGTPLeNRG/tmOAQ/mHfQTtOCCbqxVlouY4Q2WGS3SiEmfo+0lxAP+CS6XvfWLkhnZAduhvswYtoa/leC3NW2N+dfs/BAWXrl7NKMkzRmj9O8aNvdbNwoiD6SiXP9lUdPUAcL4GqCd57ZztRG5 RT9vFxDd 2j4n3MeOcAAn1VIBQIVf5SDEpo02/s3OnvaiSNtgEmAxHx7B3tnzTaSMtdxhBtN3dbDSEV16d0lytjD2sPfAbpoDVoMhXFRKehVtf5S2A4lWyH1ZsyYRwOH4kG9Ze1t3OPwuefE0p7xluTccZUXN5Sf6nVrCXplkZtOrFqgGidihnDzltuqugXrEdwiQOhI49zc9RetCnb5MIT+LnBbCin+UPEUoLxJmwIOEg6e0M0v+kTWbMu7fojrin2qMCHE9btkOjKAcFTDZiOu0= 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 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; } From patchwork Fri Mar 3 19:58:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13159452 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 A7AE4C64EC4 for ; Fri, 3 Mar 2023 20:00:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8A696B007D; Fri, 3 Mar 2023 15:00:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BEB8F6B0080; Fri, 3 Mar 2023 15:00:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB35B6B0082; Fri, 3 Mar 2023 15:00:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 977C66B007D for ; Fri, 3 Mar 2023 15:00:40 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6689D1A13E9 for ; Fri, 3 Mar 2023 20:00:40 +0000 (UTC) X-FDA: 80528654640.06.98213F2 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 4A3611C0027 for ; Fri, 3 Mar 2023 20:00:38 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=C+SMje5g; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=C+SMje5g; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf20.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mtosatti@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677873638; 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=tHAQYo4aXRrl160KH7pJqqqPegg14fiAPRCJhIKS8fE=; b=2aovifAI7Zk0m8WtK8e8YT37uQNl+xjx0yLUMfmgiSlxa64XYlBgwFdj2MEUtelm7Z0Xvh xQ0v8oUK+UnDTCKgrikFEyeY+W3b7pJpqBgzgRdIM302hl2Kflrt4ltaH15s5AZ4Iai/hy Oeki/3HG7dPMI/02OAsCAMs/rBkJ7Wk= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=C+SMje5g; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=C+SMje5g; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf20.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mtosatti@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677873638; a=rsa-sha256; cv=none; b=FiVs7bft5VXmKpynaECOz/HcsUM0oFEXPv0yg5gHcOofbOScy7Y/j2/FRTt7l1F+xXIzCV +HYUDr8ujab71S2UNAVydRzm+DZv/DNAbFp9kgnVb3f/rnP2NGBa/Qb0oPEJNeHwYXkJSD GPUz7KanpDKhkPqkEtQb9/bZ5F1NxVk= 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=tHAQYo4aXRrl160KH7pJqqqPegg14fiAPRCJhIKS8fE=; b=C+SMje5gYEckt1DDg+VAbZ4kji2VGss2AxngIGm0PVUznX4w0ZJWiw6wznDXoga+Nb0aap kCJ7eW2j0oRtWnNTGr4QfpiJde/OFZXHJEA+Puqlw1m2lezcRGtJ8QFnCuh8v5/S7rdLnC 1n6cuAMJuO7pYtd9+kEJ/8QOC1oA9b4= 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=tHAQYo4aXRrl160KH7pJqqqPegg14fiAPRCJhIKS8fE=; b=C+SMje5gYEckt1DDg+VAbZ4kji2VGss2AxngIGm0PVUznX4w0ZJWiw6wznDXoga+Nb0aap kCJ7eW2j0oRtWnNTGr4QfpiJde/OFZXHJEA+Puqlw1m2lezcRGtJ8QFnCuh8v5/S7rdLnC 1n6cuAMJuO7pYtd9+kEJ/8QOC1oA9b4= 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-294-29M75UO_NkSSiK0Vpi9pvg-1; Fri, 03 Mar 2023 15:00:31 -0500 X-MC-Unique: 29M75UO_NkSSiK0Vpi9pvg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 55C1A803491; Fri, 3 Mar 2023 20:00: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 2861A492B00; Fri, 3 Mar 2023 20:00:30 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id AFB1442919633; Fri, 3 Mar 2023 17:00:12 -0300 (-03) Message-ID: <20230303195909.003776725@redhat.com> User-Agent: quilt/0.67 Date: Fri, 03 Mar 2023 16:58:51 -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 10/11] mm/vmstat: switch vmstat shepherd to flush per-CPU counters remotely References: <20230303195841.310844446@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 4A3611C0027 X-Stat-Signature: ar6b8ycisn66xwp38iyrt79ufudu3n4s X-HE-Tag: 1677873638-794624 X-HE-Meta: U2FsdGVkX1/oJb9pUxKsHer94XWc9whqf4kM/D/0KJW2mNksYiNwKOHFpB34dj4YpGtH/mBNak6vwnwmBURMxT2AN8EcjxovwtKYP8yjfKfUOLoEqTEZb3bIcFq9pJlSQCpCOZ0R8ZIHcrsPp3IcYQXRq9ts/DKgs9J7GsWtYfPdMDCRRDzPxiAv4Owqc7YTwVy/Oa55KIlJrCW/77NOlc0EGYQpMjfxiplC/bSk5VTx8qpZmrDOa1Ik6lhYGW0OUR2jxbi2ICefG8887xNSCZp6LpbsAJjJxtflMjuv3Wv3ZrFVUeQ8PHCOJNW1FO5zC3BPyJG5F9kychru2sesHJDfpqEh6p279FBjtQQ+JzgPswNyjN6wfei9LwStYbyF+JYsrpPqJ1Bs3V0xYqa7UDObXbrBFzVpQvzhkOEFPYpmCuiWdX03Arbd5QrO1uZP5D3ENntwrigADU1zJwkI5E9IPReHeT6YAEHE4qg+cxntmQGNJnQrIAv+I0onkt3ILhsJdPrKJHXRBybopMT1YSl/vWBbgvaGOT5qspZO2uN5eCmmBHkAUkZWWtrEl8vibLNaxk5FP8wCID6fwW+w0mDbYzy2ZUcF4sEa65KrV7JizWrCSRPoTjF+4AysitX+DSX7utxkrHM7X43ML5NRzMyaOEPP3Qq+IEAXUXZPPjc3TQr5I9XsGxbCGG7ccEXD8r1nO+NRoc74r/RfEU16F2A9H+uzqvgmnUGx/042RKqa0xKPkZ9QMxi/BC6Q3Lv8AfeRNpKsqk813kMlRvbw5B7DJ6voRRPocjBcdGzvhn4ZlmYs8vAaQFhCVV0/ly2ipd9BETVVQfPej0lc7/Q/tE3MPf7anyT9JolsiwadRWMppOfpdaHCGHXT4FpxR5BwxnkBKNtavRHVcbUuJBuxgJe5qzqpQsFhIAwBl/2/R0ONMaj0vGSeBm58f0SyWcJErvOtaCete1agDDCOVEW 2/DeORwY rsxJB6Oz1jvx0M+mqKL2IjJnruPtJIAtA4DDK7E9PxTgXftHncqfV4tBMWFQxjGS+6DX9L0nsaaY7N3YXsU98EeDJ7Mr8EeK1EqhbcHINK9KmJJHfrEOVVCKCUmpFMK8snYIwpzP1WshUkAoaNH6LE2pY682fwHhvfNxw1/YVzxIhQq9hZVqWqU6UT0HSBJX/EdFdGVqV7OCIHnM= 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: Now that the counters are modified via cmpxchg both CPU locally (via the account functions), and remotely (via cpu_vm_stats_fold), its possible to switch vmstat_shepherd to perform the per-CPU vmstats folding remotely. This fixes the following two problems: 1. A customer provided some evidence which indicates that the idle tick was stopped; albeit, CPU-specific vmstat counters still remained populated. Thus one can only assume quiet_vmstat() was not invoked on return to the idle loop. If I understand correctly, I suspect this divergence might erroneously prevent a reclaim attempt by kswapd. If the number of zone specific free pages are below their per-cpu drift value then zone_page_state_snapshot() is used to compute a more accurate view of the aforementioned statistic. Thus any task blocked on the NUMA node specific pfmemalloc_wait queue will be unable to make significant progress via direct reclaim unless it is killed after being woken up by kswapd (see throttle_direct_reclaim()) 2. With a SCHED_FIFO task that busy loops on a given CPU, and kworker for that CPU at SCHED_OTHER priority, queuing work to sync per-vmstats will either cause that work to never execute, or stalld (i.e. stall daemon) boosts kworker priority which causes a latency violation 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 @@ -2004,6 +2004,23 @@ static void vmstat_shepherd(struct work_ static DECLARE_DEFERRABLE_WORK(shepherd, vmstat_shepherd); +#ifdef CONFIG_HAVE_CMPXCHG_LOCAL +/* Flush counters remotely if CPU uses cmpxchg to update its per-CPU counters */ +static void vmstat_shepherd(struct work_struct *w) +{ + int cpu; + + cpus_read_lock(); + for_each_online_cpu(cpu) { + cpu_vm_stats_fold(cpu); + cond_resched(); + } + cpus_read_unlock(); + + schedule_delayed_work(&shepherd, + round_jiffies_relative(sysctl_stat_interval)); +} +#else static void vmstat_shepherd(struct work_struct *w) { int cpu; @@ -2023,6 +2040,7 @@ static void vmstat_shepherd(struct work_ schedule_delayed_work(&shepherd, round_jiffies_relative(sysctl_stat_interval)); } +#endif static void __init start_shepherd_timer(void) { From patchwork Fri Mar 3 19:58:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13159450 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 18C31C64EC4 for ; Fri, 3 Mar 2023 20:00:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 64EE66B0078; Fri, 3 Mar 2023 15:00:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 56CCE6B007D; Fri, 3 Mar 2023 15:00:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36CD66B0080; Fri, 3 Mar 2023 15:00:40 -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 C0AF36B0078 for ; Fri, 3 Mar 2023 15:00:39 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 940858134F for ; Fri, 3 Mar 2023 20:00:39 +0000 (UTC) X-FDA: 80528654598.18.7CBD49D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id CEEB440029 for ; Fri, 3 Mar 2023 20:00:37 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HlHhTNWF; spf=pass (imf01.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=1677873637; 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=HEd4Z20qHewy4816S06cVIYXHbFUi/GbntWDJMKAj40=; b=lzFiK75TsopniVCkp3ZjpE3jGOC4MVbCs3+2E+rU9QJlu8iUlveXrpzlw6neV5er7DHggJ vCeVTCUHmB4ZSZh9XBeFY4foAj/4XU28U3/MlIMPkwMME6MLk8anT9r3cqG9olTreLg5O9 tU26uYIEveB5NyaVA04gL89ELiIvS9Q= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HlHhTNWF; spf=pass (imf01.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=1677873637; a=rsa-sha256; cv=none; b=NdBBligIn3bbSmlQm9m0bIaVIW6SyEI43kJR4GDhozzKkohbj9RWCT5sw5Xe1eqiqxohsX dNoH+UTBdR6TMOENJp2i6PZTurIyMyBBrop/74hAPG52NaZuQyJ43PaNRWdWJsUKylAPBX CpQFR9Gk9Uh/G0H80z5rMwBkWr6/Qj8= 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=HEd4Z20qHewy4816S06cVIYXHbFUi/GbntWDJMKAj40=; b=HlHhTNWFB/lIB4oewSYfnJNqQi9uzsmYXovDUQCFYQsbLdHWD4U1IoUS4nHfMe2Uv2VFGc mZnWFFW7ou3q+zYdUFUJOWmSK2808Ov/NS1YbTNykho3dpOuXWUvvJlsu06jERKDZuhO7G eHekWoykK3h2Idepu8UoDLFKcUjleGk= 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-643-joKSBS7lOOC_ZiriZUzjGQ-1; Fri, 03 Mar 2023 15:00:33 -0500 X-MC-Unique: joKSBS7lOOC_ZiriZUzjGQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 42FA480D0F3; 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 17CA02026D4B; Fri, 3 Mar 2023 20:00:32 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id B4B3642919634; Fri, 3 Mar 2023 17:00:12 -0300 (-03) Message-ID: <20230303195909.029065935@redhat.com> User-Agent: quilt/0.67 Date: Fri, 03 Mar 2023 16:58:52 -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 11/11] mm/vmstat: refresh stats remotely instead of via work item References: <20230303195841.310844446@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CEEB440029 X-Rspam-User: X-Stat-Signature: gzcs1qaaiem6n9w67so9ko47413wbprm X-HE-Tag: 1677873637-151580 X-HE-Meta: U2FsdGVkX18k8rAOXeqsCQIRtUszpGGpINA5pSd2CmIDacLtLKFPnHvgNWkDtTZke394ip80Sa8zqgHNaIIiatf1/igUEiI+BaSk8V27ZJDX+mkQaOSm1CE1K0kYjLhln7ni4G+BwJmY6QiDd8Kd4Y/01l51UEEW6cUY/zTKb1KaFTHle5KB6dmPEQRHAYZzAoTGhb7D5YO/WjG9gR/Acr+/AyRvOpM2vvmRseEr17YiKzXtF1843KSVq+DdUQKMXPnEYallO9XdfQjdG5ENN9811MJ6m9RRLuce1pMNKX8ozYU/oFgtWF6r4+Rsu73+Ii218pEy/MaL8TGx+T6J5EsLKFzqUQs/ybwufNY7q+jn4aCZhz+QVUUIEN9WxLbfdNpg638Lo+nO3PoPSwZ44quWxr8vAZKhQQxC09g58GF18jzicnkNdSa7ojrfVFP5/VZsrQIwEJLQ9zwUzMBduAnBMOOemji7oqavJmdW0MESoduE4djnRu2N6qhOPODQWkABBg1ziZQ+F0KAfE4fVg1LvaEdtc4exqMTf7Efk2KRfvaW2VFnHwzcRWCcGbIyctsaTtF62y+IwjcSwqF2Fq8UaM6doNowNrmLA6dDDNr233Ly4HCizlH3OSBXuVp3v1iI/bigsoX3JM/qQWhnr/TtQOGX1Wms6if4r6ozZSF8Ixd8d5NUFKnJQu7FfA6n26ZrA2QoLc9pjqbF9IdBk59z0XdRejDwGiOv1wCuiijTancGoSk3ad+QZshnaSv8Ig8ROtzWD64bDN9QU6tDGmU3wsoWwPkHNJzWuonePtoPda95BVBSj5KtEmd9VTEdM+c+YP5QOZeHQ7On9qGskWIEvJvUVF3TV++TgF7cy/Y4JhfN2S5rkxuUd4P84KpwYHYt4u8wYF5DXHJAQTfGU3MIG85lmJW9WyFfH1yCwh2CNlzjJsypHBCwBIqLUSJhGUVvNhPN7nG8DdoD7nM p0ntSyS6 krt+K1Hl/43DwI1YOPqtgeHCS4994yoLpvw+jvF4yXfWeQO4N+juChReuqmZ7WoGEST+vgew5G8u9DL1H6eyp3u0wM1zeArio4Y61WgxevinjCpSWHA4BIHQuopj14MjR6gv1Bq6/vxf1WlgvkdVlE5x4lPsUpafX1sn7Z2lsNh/N0JXQUKNxex+KeEfCIHkARxtZ4/XSvMg6bkU= 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: Refresh per-CPU stats remotely, instead of queueing work items, for the stat_refresh procfs method. This fixes sosreport hang (which uses vmstat_refresh) with spinning SCHED_FIFO process. 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 @@ -1860,11 +1860,21 @@ static DEFINE_PER_CPU(struct delayed_wor int sysctl_stat_interval __read_mostly = HZ; #ifdef CONFIG_PROC_FS + +#ifdef CONFIG_HAVE_CMPXCHG_LOCAL +static int refresh_all_vm_stats(void); +#else static void refresh_vm_stats(struct work_struct *work) { refresh_cpu_vm_stats(); } +static int refresh_all_vm_stats(void) +{ + return schedule_on_each_cpu(refresh_vm_stats); +} +#endif + int vmstat_refresh(struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos) { @@ -1886,7 +1896,7 @@ 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); + err = refresh_all_vm_stats(); if (err) return err; for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) { @@ -2006,7 +2016,7 @@ static DECLARE_DEFERRABLE_WORK(shepherd, #ifdef CONFIG_HAVE_CMPXCHG_LOCAL /* Flush counters remotely if CPU uses cmpxchg to update its per-CPU counters */ -static void vmstat_shepherd(struct work_struct *w) +static int refresh_all_vm_stats(void) { int cpu; @@ -2016,7 +2026,12 @@ static void vmstat_shepherd(struct work_ cond_resched(); } cpus_read_unlock(); + return 0; +} +static void vmstat_shepherd(struct work_struct *w) +{ + refresh_all_vm_stats(); schedule_delayed_work(&shepherd, round_jiffies_relative(sysctl_stat_interval)); }