From mboxrd@z Thu Jan 1 00:00:00 1970 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 6FBF3C4345F for ; Fri, 3 May 2024 14:15:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D3BD56B0083; Fri, 3 May 2024 10:14:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CEBEC6B0088; Fri, 3 May 2024 10:14:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDA696B0089; Fri, 3 May 2024 10:14:59 -0400 (EDT) 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 A01EB6B0083 for ; Fri, 3 May 2024 10:14:59 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 18D6CA1EC3 for ; Fri, 3 May 2024 14:14:59 +0000 (UTC) X-FDA: 82077281118.08.FDCD213 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf30.hostedemail.com (Postfix) with ESMTP id 2E60D80078 for ; Fri, 3 May 2024 14:14:52 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf30.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714745693; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Rs9fMUDcko0mYTl/DxgToWuArkhphaNAoaV6J1pibBU=; b=1xuNA8SV5CfnOweWYq1IHn9XdarkeH65SBUt9DWmU723a9A/XaOWsR0xf/IlrPpwD3NkKr cfdIgkxvCZIA2UsYwRgYyWXoRZsnmjvGJ1pfXlFugiKbSo05X2hKEKAbPWEc1Nc6jQxoj1 07WM1m9A1aEWZL4D8o5rHgLJV3LxIRo= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf30.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714745693; a=rsa-sha256; cv=none; b=1SA48ZxddoLPQoDMMVU6AP4x+P5CYmvoAjFbG+8fi9Iu52ACBs30Cezmyo8mWItu+iHfY7 OBS8NQ9ujtbaeaBppny0FdtKPdQNVxHrtZv4fVIsK6tN+8DuMon4HiCxBWnW6DgrEQqCBS BRUYIPcmNBtVK1Cs5fVkZlZ/ip1IS18= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 45C7513D5; Fri, 3 May 2024 07:15:17 -0700 (PDT) Received: from [10.57.67.51] (unknown [10.57.67.51]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B180F3F73F; Fri, 3 May 2024 07:14:50 -0700 (PDT) Message-ID: <9d390017-f1c4-44db-864f-cb95b8fd3a9b@arm.com> Date: Fri, 3 May 2024 15:14:49 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] mm/vmstat: sum up all possible CPUs instead of using vm_events_fold_cpu Content-Language: en-GB To: Vlastimil Babka , Barry Song <21cnbao@gmail.com>, akpm@linux-foundation.org, linux-mm@kvack.org Cc: hannes@cmpxchg.org, linux-kernel@vger.kernel.org, david@redhat.com, v-songbaohua@oppo.com, willy@infradead.org References: <20240503020924.208431-1-21cnbao@gmail.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Stat-Signature: jqupcop9dxs6486xa36fxsjtuypdy481 X-Rspamd-Queue-Id: 2E60D80078 X-Rspamd-Server: rspam10 X-Rspam-User: X-HE-Tag: 1714745692-636733 X-HE-Meta: U2FsdGVkX18n+HFX/9JNgwwZX0O9xliIQdItdLe8nWhz3kwc+YFrHZfL+V3qmYBnWhmDF8RpWgbCtbpPYaRddmCfZQx1K42Hbuqcl+6RTi6YXnelvpJPTxOwDEkEy9UeVuCkkoptJC+SfHeIH820lAASLm0Jl8E+N8iYsxy6NvWLgcbl2Yb1gAyKKhigqdHpHUm0I5WbHHgSvElNY+W+JrIwJ5e0YT8+UEH7oYIbdndL1OL4hYa1KT9TG4cYgi1M4krZP2GssS6udYjpFpgBdDthjLn1bTjJ9lfj7bxq49ksSjq8aLuiUCfzdLlIsjhM2Nxz1q3SJSi0jfKx10RPU3Q5k/3lwWM7CoVVpM1YTP3WSTzwJyiUpkSq4o/JfQq1joo6coMeDRGZyQftdmnRCtxjw0CWeCh7VfFzj1fGIJCV0jyaWj7q6SAYdWJxR9AH7u0K+W6D93DOwW+UMDTJkLWrVgv27fzt2M7GRGco9jeZpUXVTlImTi68FcGfILuUxrsrKj/aop4mZPXJLCVoq5zZ5w4itmws6AwJUe9+wkoF8hcIJ3P0+gzujGcZcanPV8Fl0vH/L6XoD+LQZtA9QjkuwdQWp6Vigv8tUsqsL2TETONqQ/ZPovbSpXNSpZAI4gkrHSg6HsWwlWtRHi1O8+vtSV+OwNgMaNOMjOcUl0ml89Wht3h3qODVG3XnTuBl+svW36fHuXT+flPRwWmrW1Jiu0G56kb/B0N0b1Ie69O19CSm658d+MiWVlqUnUAMEq8HluOKxHgz/KuvzYmlpDfwrGusIyjD/EIGyfZ8J5ktGTVHW+V44MgsaN6xF6BlJftZSxG+E1cMp/tglBm9VqsCoj+Goc6R/JjmJx/bSA1CRSyeCsn2OEoHI7cR8uhW1UqzymlgDftOaQzRFBUMnuCMhBZJn0/qpwBaMSNDh5nEaSZUaX6xtOsJkJ0PUD2ul2tUnSCDwM8UlRNi1Uc NOAxVd5d L8rHQaOyGnsC0Gmyhey3OV6ja5cL0LelXRISqrUgnSoq3Hey+/Z0iggyCxFnbpPlojYxVbhgjse730SbpHHOCXGA+a1AqUtwGkiaEvaUuHmMXFJ7n4Y7GEYqHCNFMrP0aJKWdwStAsirP7eFfXOJq82pagx1PlhOTOIwBuVNBQKZJosH+v4XAv1R2C2+RI/dTyNF+ 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: List-Subscribe: List-Unsubscribe: On 03/05/2024 14:45, Vlastimil Babka wrote: > On 5/3/24 11:16 AM, Ryan Roberts wrote: >> On 03/05/2024 03:09, Barry Song wrote: >>> @@ -83,8 +83,6 @@ static inline void count_vm_events(enum vm_event_item item, long delta) >>> >>> extern void all_vm_events(unsigned long *); >>> >>> -extern void vm_events_fold_cpu(int cpu); >>> - >>> #else >>> >>> /* Disable counters */ >>> @@ -103,9 +101,6 @@ static inline void __count_vm_events(enum vm_event_item item, long delta) >>> static inline void all_vm_events(unsigned long *ret) >>> { >>> } >>> -static inline void vm_events_fold_cpu(int cpu) >>> -{ >>> -} >>> >>> #endif /* CONFIG_VM_EVENT_COUNTERS */ >>> >>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c >>> index cd584aace6bf..8b56d785d587 100644 >>> --- a/mm/page_alloc.c >>> +++ b/mm/page_alloc.c >>> @@ -5826,14 +5826,6 @@ static int page_alloc_cpu_dead(unsigned int cpu) >>> mlock_drain_remote(cpu); >>> drain_pages(cpu); >>> >>> - /* >>> - * Spill the event counters of the dead processor >>> - * into the current processors event counters. >>> - * This artificially elevates the count of the current >>> - * processor. >>> - */ >>> - vm_events_fold_cpu(cpu); >>> - >>> /* >>> * Zero the differential counters of the dead processor >>> * so that the vm statistics are consistent. >>> diff --git a/mm/vmstat.c b/mm/vmstat.c >>> index db79935e4a54..aaa32418652e 100644 >>> --- a/mm/vmstat.c >>> +++ b/mm/vmstat.c >>> @@ -114,7 +114,7 @@ static void sum_vm_events(unsigned long *ret) >>> >>> memset(ret, 0, NR_VM_EVENT_ITEMS * sizeof(unsigned long)); >>> >>> - for_each_online_cpu(cpu) { >>> + for_each_possible_cpu(cpu) { >> >> One thought comes to mind (due to my lack of understanding exactly what >> "possible" means): Linux is compiled with a max number of cpus - NR_CPUS - 512 >> for arm64's defconfig. Does all possible cpus include all 512? On an 8 CPU >> system that would be increasing the number of loops by 64 times. >> >> Or perhaps possible just means CPUs that have ever been online? > > IIRC on x86 it comes from some BIOS tables, and some bioses might be not > providing very realistic numbers, so it can be unnecessary large. OK thanks for the info. > >> Either way, I guess it's not considered a performance bottleneck because, from >> memory, the scheduler and many other places are iterating over all possible cpus. > > I doubt anything does it in a fastpath. But this affects only reading > /proc/vmstat, right? Which is not a fastpath. Also update_balloon_stats() > which is probably ok as well? Yep agreed. > > Either way I don't see a clear advantage nor disadvantage of this. The advantage is just that it deletes 32 lines of code and makes it easier to understand. > >>> struct vm_event_state *this = &per_cpu(vm_event_states, cpu); >>> >>> for (i = 0; i < NR_VM_EVENT_ITEMS; i++) >>> @@ -129,29 +129,10 @@ static void sum_vm_events(unsigned long *ret) >>> */ >>> void all_vm_events(unsigned long *ret) >>> { >>> - cpus_read_lock(); >>> sum_vm_events(ret); >>> - cpus_read_unlock(); >>> } >>> EXPORT_SYMBOL_GPL(all_vm_events); >>> >>> -/* >>> - * Fold the foreign cpu events into our own. >>> - * >>> - * This is adding to the events on one processor >>> - * but keeps the global counts constant. >>> - */ >>> -void vm_events_fold_cpu(int cpu) >>> -{ >>> - struct vm_event_state *fold_state = &per_cpu(vm_event_states, cpu); >>> - int i; >>> - >>> - for (i = 0; i < NR_VM_EVENT_ITEMS; i++) { >>> - count_vm_events(i, fold_state->event[i]); >>> - fold_state->event[i] = 0; >>> - } >>> -} >>> - >>> #endif /* CONFIG_VM_EVENT_COUNTERS */ >>> >>> /* >> >