From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 383A238BF71 for ; Tue, 13 Jan 2026 09:24:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768296293; cv=none; b=kixpb3PMRUCQ+H3Xg5Hfd/cbIKDU98P4rCiFNxYc+cYQmaTLPDkRJ6gMhPIqGZ0CQGxG11W9EseO63WQoE9Tav4Y0moa+IMGD1o3uHVnJh3/7E9gzJlAG7QvaESslLsWNgfXoQ/U/1CTzhgmA3f9XlvZAvzQceLe5IdC9aYsKQM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768296293; c=relaxed/simple; bh=0jn24JEKWb0/9Saq/hawmriPzmuV9BAKK4nMxc5tsuI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=umcubPgJa3dh4wGnJYIbG+a9ytmhK/EKkBdnzdb4Zv+dZTnFhogFqfuqk0fJ49UomtflVF14wrNKTUlP9K149jB/FoCUteu4WdUpyLwdwXq9Z5n9uzir/UvGP3W9FpJ2UO2grvoBgDBcT0d9opjf2PW0WhaZrwrPwZ0AA+Cfrvg= 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=QXeaHx2i; arc=none smtp.client-ip=209.85.128.50 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="QXeaHx2i" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-47d3ffa5f33so32879665e9.2 for ; Tue, 13 Jan 2026 01:24:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1768296282; x=1768901082; 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=sZyF9oSCiMio2wmOHsADV3M+vA6ApPBpXUawJoezOv4=; b=QXeaHx2iQddPnvlJUTny7x9XCHlJt32YcUK3wvyddOSl5Z2lKA4VWlkUJGYXP1z8ZC SmQDiggrVPjm/ThsU27KydqrF5lvKQwGqbw0K6Dg9mDkGWg5UVz878qmczRHSAYoV0qb cFEZ4W0HpDos5sHxwAKoV198zmF/JtUzrbK/DiDwA/ajk/zPwMQgTYkK6BkrcBhWM30s i642TSzb+Qy/rNx4VfIVWtRSn4pOAMyzk+41Xf5D1VoUA4NexH4uZxDBtYZJKJHv5UHk x/V/Fxrx7xxDOVUg/jOohpBznRm7izEKIndAxhDJTo63e8uY5DbYpsrsjTlI2pE7p742 J4Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768296282; x=1768901082; 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=sZyF9oSCiMio2wmOHsADV3M+vA6ApPBpXUawJoezOv4=; b=I+ZP4Ab6DxlCHQzSr1sPqhpZvTjPHmTvzRJUAwJ1swdf+xFL4LRUQ3QZZjXEqgI64g uFCXWVgrDkxm+/2TAudCT0aH06pQ++qIdqIK7rGhwruCJz6YYZwtFEo4flx7JVVZqaba k9C9aUmaO65v5OQPLgnIPzDM6EVLBrN528y1aP2imdlWL6vUbcyXV4iXWMTGZz3k2Mz/ D5UldDO/eszBzhO+IBxmucr0Y/GiGSZcZjlIr4OYNUqhV2dL/HGY9vSMEB4t7rq6Nyw9 hDQFPMVniRweq2EVu/FM3armamAz5xL2FdFc3ouj88gTZ6WQrnweQtK0/aDla5mrPAdn ljpA== X-Forwarded-Encrypted: i=1; AJvYcCWoK07LmKC7N51aq66DEzBaRfl2sqra242WJUbAEii4+clt7qYzJjMagelmjhII7Ag9Q+Gd09j4pRS/Kes=@vger.kernel.org X-Gm-Message-State: AOJu0Yzn1Hi6870gr/SEGh4PQfikFpLJUU2NbBVisAGjEQxFOmJ6lari gS6ol5KapXVyGviEUXlq1l9pPMMaWU8UbV771fy6gnJng8mElFBdJUYSTI2jvX3/wmg= X-Gm-Gg: AY/fxX5lsOFHvzYnPqrX0213otWf67hgt/42gmQFdlyaEeFXD1F2x6uzdAc0Bw8S+Kc ivF/cUq8h3/d7sUFya9Pr3F7rshDrmV6y9SZtHTPU1uqQKc9gyXMdptYjFmnay3e9OW/qvpMyFR ioszZfSVDKf5cKE/tIdl4/OF7vufsyacR86LWGlWJIhM/Edn5QYcYtL53MlEKIhEFybsAIIlRzO P51x9vZSpp4UuSaiebUF+ywWvB8IVb2yFhbkf4ZBk9gVUrswYZNGdbpp8OaOzEWDcSwze2M2NmF q066dPeg1acvs4/18ZD0HB9w4sY9/MfEZxPTzxYQdxrC37hOOoXGAKqyFygUcr6vznXAjByERnJ LI7dX05tr8lPBUPIT1O4Y+1j5zv0d8LtjFzF2dc6tuc+8oxIY8RBUMqPxUz6C5tchH+bsZnOLEZ CYnwdyowLcQiyS8954oMciTpNd X-Google-Smtp-Source: AGHT+IHxVARX0CcBthdCu6T5JJaZCa1h1WP2ZhQZH2siQrl0JD5UEBh8+2HwINiFB9HE7IPyLrLj0w== X-Received: by 2002:a05:600c:a314:b0:479:3876:22a8 with SMTP id 5b1f17b1804b1-47d84b2d285mr218894715e9.16.1768296282317; Tue, 13 Jan 2026 01:24:42 -0800 (PST) Received: from localhost (109-81-19-111.rct.o2.cz. [109.81.19.111]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47d7f68f4ddsm405518135e9.2.2026.01.13.01.24.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jan 2026 01:24:41 -0800 (PST) Date: Tue, 13 Jan 2026 10:24:40 +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 v13 2/3] mm: Fix OOM killer inaccuracy on large many-core systems Message-ID: References: <20260111194958.1231477-1-mathieu.desnoyers@efficios.com> <20260111194958.1231477-3-mathieu.desnoyers@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: On Mon 12-01-26 19:47:54, Mathieu Desnoyers wrote: > On 2026-01-12 14:48, Michal Hocko wrote: > > On Mon 12-01-26 14:37:49, Mathieu Desnoyers wrote: > > > On 2026-01-12 03:42, Michal Hocko wrote: > > > > Hi, > > > > sorry to jump in this late but the timing of previous versions didn't > > > > really work well for me. > > > > > > > > On Sun 11-01-26 14:49:57, Mathieu Desnoyers wrote: > > > > [...] > > > > > Here is a (possibly incomplete) list of the prior approaches that were > > > > > used or proposed, along with their downside: > > > > > > > > > > 1) Per-thread rss tracking: large error on many-thread processes. > > > > > > > > > > 2) Per-CPU counters: up to 12% slower for short-lived processes and 9% > > > > > increased system time in make test workloads [1]. Moreover, the > > > > > inaccuracy increases with O(n^2) with the number of CPUs. > > > > > > > > > > 3) Per-NUMA-node counters: requires atomics on fast-path (overhead), > > > > > error is high with systems that have lots of NUMA nodes (32 times > > > > > the number of NUMA nodes). > > > > > > > > > > The approach proposed here is to replace this by the hierarchical > > > > > per-cpu counters, which bounds the inaccuracy based on the system > > > > > topology with O(N*logN). > > > > > > > > The concept of hierarchical pcp counter is interesting and I am > > > > definitely not opposed if there are more users that would benefit. > > > > > > > > From the OOM POV, IIUC the primary problem is that get_mm_counter > > > > (percpu_counter_read_positive) is too imprecise on systems when the task > > > > is moving around a large number of cpus. In the list of alternative > > > > solutions I do not see percpu_counter_sum_positive to be mentioned. > > > > oom_badness() is a really slow path and taking the slow path to > > > > calculate a much more precise value seems acceptable. Have you > > > > considered that option? > > > I must admit I assumed that since there was already a mechanism in place > > > to ensure it's not necessary to sum per-cpu counters when the oom killer > > > is trying to select tasks, it must be because this > > > > > > O(nr_possible_cpus * nr_processes) > > > > > > operation must be too slow for the oom killer requirements. > > > > > > AFAIU, the oom killer is executed when the memory allocator fails to > > > allocate memory, which can be within code paths which need to progress > > > eventually. So even though it's a slow path compared to the allocator > > > fast path, there must be at least _some_ expectations about it > > > completing within a decent amount of time. What would that ballpark be ? > > > > I do not think we have ever promissed more than the oom killer will try > > to unlock the system blocked on memory shortage. > > > > > To give an order of magnitude, I've tried modifying the upstream > > > oom killer to use percpu_counter_sum_positive and compared it to > > > the hierarchical approach: > > > > > > AMD EPYC 9654 96-Core (2 sockets) > > > Within a KVM, configured with 256 logical cpus. > > > > > > nr_processes=40 nr_processes=10000 > > > Counter sum: 0.4 ms 81.0 ms > > > HPCC with 2-pass: 0.3 ms 9.3 ms > > > > These are peanuts for the global oom situations. We have had situations > > when soft lockup detector triggered because of the process tree > > traversal so adding 100ms is not really critical. > > > > > So as we scale up the number of processes on large SMP systems, > > > the latency caused by the oom killer task selection greatly > > > increases with the counter sums compared with the hierarchical > > > approach. > > > > Yes, I am not really questioning the hierarchical approach will perform > > much better but I am thinking of a good enough solution and calculating > > the number might be just that stop gap solution (that would be also > > suitable for stable tree backports). I am not ruling out improving on > > top of that by a more clever solution like your hierarchical counters > > approach. Especially if there are more benefits from that elsewhere. > > > > Would you be OK with introducing changes in the following order ? > > 1) Fix the OOM killer inaccuracy by using counter sum (iteration on all > cpu counters) in task selection. This may slow down the oom killer, > but would at least fix its current inaccuracy issues. This could be > backported to stable kernels. > > 2) Introduce the hierarchical percpu counters on top, as a oom killer > task selection performance optimization (reduce latency of oom kill). > > This way, (2) becomes purely a performance optimization, so it's easy > to bissect and revert if it causes issues. Yes, this makes more sense. > I agree that bringing a fix along with a performance optimization within > a single commit makes it hard to backport to stable, and tricky to > revert if it causes problems. > > As for finding other users of the hpcc, I have ideas, but not so much > time available to try them out, as I'm pretty much doing this in my > spare time. I do understand this constrain and motivation to have OOM situation addressed with a priority. I am pretty sure that if you see issues in OOM path then other consumers of get_mm_counter would be affected as well. Namely /proc//stat. There might be others but I can imagine that some of them are more performance than precision sensitive. All that being said it seems that we need slow-and-precise and fast-approximate interfaces to have incremental path for other users as well. Looking at patch 1 it seems there are interfaces available for that. I think it would be great to call those out explicitly in the highlevel doc to give some guidance what to use when with what kind of expectations. Thanks! -- Michal Hocko SUSE Labs