From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5839033BBAB for ; Fri, 16 Jan 2026 15:51:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768578685; cv=none; b=rYyzwCTIgRhqjT4qwyRFO2WMhF+JyRP1n/31YHGGNIf7ek5KcKX1bdyLOTtjXOKrjPDiykPwaPvkvgeXoDVpwEE1xSNs2cSULkLM3kUkzyLs90RIcJN/gixBGFxiSBY5Z7MbvPtvUjroRrpmOVyEEvBcmqR4FXZuEip8UGEurxg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768578685; c=relaxed/simple; bh=sWsFXuclsCQHF1wp24NKR1BJW2Va0NelV/xUk3GRd+c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=F4czgeKll2XyKZx5HnS3KJTQDnsR9kHQu+77se+UlnUL03cOH/kQr28XYViUp+zQUtX7iI/QajL7XI9t0/oEP4qTKeT/X3C0zOyPkLERuNVHnXcK4x8WCtsI4wCnv/KQYdacrfkfJ5guppjOe6p3Ey+Tfl4go5bEvEKW0Wh0T9k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=FcdsOP3M; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="FcdsOP3M" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4801c314c84so11577705e9.0 for ; Fri, 16 Jan 2026 07:51:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1768578681; x=1769183481; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Yxikc1y77Ls9+KOGiahB2sX17dgvn1C4IYfzeZk12RM=; b=FcdsOP3MR4AEmQ4rmKuDfT3DYfQ++lQvmNZ0fM2IJgj+GNzEw1EEpJiJZDwkSzYRh8 4L5PTc2/9gvJlUTY/BY7AC7bilte4mIAUjGXWdpK3iM1pW5PbQ4selN8wMa3PK2Oo/CW eEN2kyWMUOID0muh11EHFIQA7GfF2yuxqr3M3Kfb8nAVBAoxqRwh5aehDdvD7mRSs/dr GRr5jijSzAeZIv2IK8HZbV+t4IOUfWIPBpFUxmVDexQW9/ivDOLXxrAkkCUoRellTBSd HIb9tVVMbIWJfHy7rfRf0GjWkOc3oza5kuEFsAa6T2dOh82vbcPLBS0P0Db0RnUdEp9h YqZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768578681; x=1769183481; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Yxikc1y77Ls9+KOGiahB2sX17dgvn1C4IYfzeZk12RM=; b=JnD6Iv8Ia4sHUcYYb5FG56GDN0YlKzIfQwOl0sjCnOs25BMOkSWvhsbjuWfpIV5bwm 4nM89u68+YyEuMsxss3bbTV1G/2ztEfT1TJGb3sLeZYLYe7eTkv6Ys6iTzE94MCfNXFP Z2/tD40vZA7ML+Su89cD1IvsAVNS39PJ4gJe460LCJ3x6KxBHlvHodTpSYndMlKWij09 216ux7tTtGHSMl8hrkc+WsLvnWBEQu49WZ38R9etG9I1iKjVe9u4vQ6Xp2ObkWFmbI+h 23z2VLMftuBkN51YSvIXyvTsCTvd/qEhxw2tVR8LWFspn05Lu8dp60dsGlZAhso3gmYk LhlA== X-Forwarded-Encrypted: i=1; AJvYcCWvIsfNLIMcCwkCYZByOsZoXgWEsrRutiNdn1tWVfHFA+V5Fhoz0z6ufb7BuD4hh9WlMpWubK/i8hSW26w=@vger.kernel.org X-Gm-Message-State: AOJu0YzyDp+HpOvAWj02uQ1gFFw86B5Ep8MwlJyYE8/UU9fjM1phoXMH VkVOfyc8Cv5K1oSQ0hfet3kCnUHvSnIe15CazqsOqxfe3cm6UtXhenf5Fu+KLoNcjLMXWrTnrGq mAv1E X-Gm-Gg: AY/fxX64oN4drs+/GI0L5+Up9YW46Z2Ge34FZUyXXiJw3acXL2axlTIWAB+YVL7Xjrk HkBQXmiv6Xx5c/B5VcspOXh+H7Ox5acdas4M3Kn1SlN6XUtifqaKPlMIvfWdvXVuMPsbNZd3zY1 ZRSXKMUE714aSWBK/9r5tcpKcOmtlg9l5hqwo+0V/CQNua7xx/ELN82ktYjSqBy2r65aoskk/u9 VAibUSxCxJhglUhFWP/3Q6TLzyAUhHvDY6pgmexveU1BhY1IyGn+s21gAqM5xskBsd822SNcRYJ 1wTrH/4Y3j0sRrC28YSiDG07mxZ88nTYAwZ0bKoFJhpeJYDYdo3/q9HCVEiWn+2kjW4imNF88yY AW5C5v8iIKlhyba0yKPZKdVb1e3sF4Sw4v/OeYUybabaaiHg1yybqGqAgkI11M2HKVhZLX1aNrA FbWTpqrMdHV0+itRmcroAv/HM+ X-Received: by 2002:a05:600c:3b9e:b0:477:9a28:b09a with SMTP id 5b1f17b1804b1-4801e2a5861mr49417745e9.0.1768578681507; Fri, 16 Jan 2026 07:51:21 -0800 (PST) Received: from localhost (109-81-19-111.rct.o2.cz. [109.81.19.111]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4801fe65883sm18036695e9.15.2026.01.16.07.51.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jan 2026 07:51:20 -0800 (PST) Date: Fri, 16 Jan 2026 16:51:19 +0100 From: Michal Hocko To: Mathieu Desnoyers Cc: Andrew Morton , linux-kernel@vger.kernel.org, "Paul E. McKenney" , Steven Rostedt , Masami Hiramatsu , Dennis Zhou , Tejun Heo , Christoph Lameter , Martin Liu , David Rientjes , christian.koenig@amd.com, Shakeel Butt , SeongJae Park , Johannes Weiner , Sweet Tea Dorminy , Lorenzo Stoakes , "Liam R . Howlett" , Mike Rapoport , Suren Baghdasaryan , Vlastimil Babka , Christian Brauner , Wei Yang , David Hildenbrand , Miaohe Lin , Al Viro , linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, Yu Zhao , Roman Gushchin , Mateusz Guzik , Matthew Wilcox , Baolin Wang , Aboorva Devarajan Subject: Re: [PATCH v16 1/3] lib: Introduce hierarchical per-cpu counters Message-ID: References: <20260114145915.49926-1-mathieu.desnoyers@efficios.com> <20260114145915.49926-2-mathieu.desnoyers@efficios.com> <67bdfd38-1acf-4b90-9e34-ce752632ddb1@efficios.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <67bdfd38-1acf-4b90-9e34-ce752632ddb1@efficios.com> On Wed 14-01-26 14:19:38, Mathieu Desnoyers wrote: > On 2026-01-14 11:41, Michal Hocko wrote: > > > > One thing you should probably mention here is the memory consumption of > > the structure. > Good point. > > The most important parts are the per-cpu counters and the tree items > which propagate the carry. > > In the proposed implementation, the per-cpu counters are allocated > within per-cpu data structures, so they end up using: > > nr_possible_cpus * sizeof(unsigned long) > > In addition, the tree items are appended at the end of the mm_struct. > The size of those items is defined by the per_nr_cpu_order_config > table "nr_items" field. > > Each item is aligned on cacheline size (typically 64 bytes) to minimize > false sharing. > > Here is the footprint for a few nr_cpus on a 64-bit arch: > > nr_cpus percpu counters (bytes) nr_items items size (bytes) total (bytes) > 2 16 1 64 80 > 4 32 3 192 224 > 8 64 7 448 512 > 64 512 21 1344 1856 > 128 1024 21 1344 2368 > 256 2048 37 2368 4416 > 512 4096 73 4672 8768 I assume this is nr_possible_cpus not NR_CPUS, right? > There are of course various trade offs we can make here. We can: > > * Increase the n-arity of the intermediate items to shrink the nr_items > required for a given nr_cpus. This will increase contention of carry > propagation across more cores. > > * Remove cacheline alignment of intermediate tree items. This will > shrink the memory needed for tree items, but will increase false > sharing. > > * Represent intermediate tree items on a byte rather than long. > This further reduces the memory required for intermediate tree > items, but further increases false sharing. > > * Represent per-cpu counters on bytes rather than long. This makes > the "sum" operation trickier, because it needs to iterate on the > intermediate carry propagation nodes as well and synchronize with > ongoing "tree add" operations. It further reduces memory use. > > * Implement a custom strided allocator for intermediate items carry > propagation bytes. This shares cachelines across different tree > instances, keeping good locality. This ensures that all accesses > from a given location in the machine topology touch the same > cacheline for the various tree instances. This adds complexity, > but provides compactness as well as minimal false-sharing. > > Compared to this, the upstream percpu counters use a 32-bit integer per-cpu > (4 bytes), and accumulate within a 64-bit global value. > > So yes, there is an extra memory footprint added by the current hpcc > implementation, but if it's an issue we have various options to consider > to reduce its footprint. > > Is it OK if I add this discussion to the commit message, or should it > be also added into the high level design doc within > Documentation/core-api/percpu-counter-tree.rst ? I would mention them in both changelog and the documentation. -- Michal Hocko SUSE Labs