Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1294999rdb; Fri, 1 Dec 2023 12:02:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGy0dgoKjkGjp/emCn18Yc6HR7uJ5zzW4hCsoCwd0ZWtJyBGgDMHpVMCsG1oDZ3aJZKvKqW X-Received: by 2002:a17:902:fc4c:b0:1d0:220a:f00c with SMTP id me12-20020a170902fc4c00b001d0220af00cmr120453plb.54.1701460941194; Fri, 01 Dec 2023 12:02:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701460941; cv=none; d=google.com; s=arc-20160816; b=EuVYQQ7Fnew6JMXHQcpExi5foMuR/O3WdcAkZ+AXXKUTgFb8KHLUUDUTAq6eXxk/RB PF+OSGWF+tUtGB7kSEkjzOz7OKBJQLzZrD2NstldjZ7S8ARwS5igBpSKvUfe0ctYkt9U AgmOSAYAX8cQMMODrLnenolsu3HqbHHuXZDGjlfqmCWvBQUM8w5YpbP8yjQp3x+qptk8 56tYvWC/ZvwOedxbKD8MAZKjZbrQslaU+rckCGeKSOpSzhyOORd++AZ2J9ShK2UYXp1w BJ7G22XJY5/Gk8iUmF+/36NlswI2e7rUh6xEQr9RiNh1Qhn8hY4RN7R322k/FjZ8mvZA Sc/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=L4EsUjCpDqR5ukRbUrdGLVdW+brLvnqNkoJINxDTUj4=; fh=RtAAvgmNuTCS1tRSx/Jw549/0Fu3lbmJMJDbJ76dDa4=; b=N97yk6BNWgjTrk0QjiOJoPt0qToRe6I/6OVUaM/usEqujg+lI7XDfEAKfvfy79lklC gRDCyeU6xiJq8cpwfvcTpQiGT6vwEZ8z1LFwmmcKOS1TSxQLSxuNyQAU7QHgrIQdM32Y Fwz+QfE8TR/BiCNq0c+aGWQFHLigvYfYrIFuf8hagisSJkf717hYpFBLkAPb6p1au9Zg 1+urnikDddgXa7bjQBFxX4dQEGP4/SGoPsXX+K4lB0/iGYHjKHTA8AMZ5IXpqgConjrc omH6001fryDz7ZYcBb9/xE0cODYXau1Q0+iih2EGxBHgqzrmTnz9YeMSqODwZE9hbfTE hUCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=imM9s+0U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id jb20-20020a170903259400b001b8922e82e3si1630808plb.297.2023.12.01.12.02.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 12:02:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=imM9s+0U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 2E85980A7E7D; Fri, 1 Dec 2023 12:01:59 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379578AbjLAUBj (ORCPT + 99 others); Fri, 1 Dec 2023 15:01:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379550AbjLAUBi (ORCPT ); Fri, 1 Dec 2023 15:01:38 -0500 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [IPv6:2001:41d0:1004:224b::b7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 429E695 for ; Fri, 1 Dec 2023 12:01:41 -0800 (PST) Date: Fri, 1 Dec 2023 12:01:33 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1701460898; 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: in-reply-to:in-reply-to:references:references; bh=L4EsUjCpDqR5ukRbUrdGLVdW+brLvnqNkoJINxDTUj4=; b=imM9s+0UUfzimqJ8u6k96q03kHMIRBQOgk5f45b7nxNLxLWwGy/XhsfjLsd4SIikXhSdPg Mx7ovIdRCZz9QgY6LMils28s6R6uBRdlmfUCTISH4vw315Z0la9owPgNYDmBqfpGn9GpKc 5KZwnG40OoqDZPcOv/k5NWqbO9oSEOA= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Dave Chinner Cc: Kent Overstreet , Qi Zheng , Michal Hocko , Muchun Song , Linux-MM , linux-kernel@vger.kernel.org, Andrew Morton Subject: Re: [PATCH 2/7] mm: shrinker: Add a .to_text() method for shrinkers Message-ID: References: <76A1EE85-B62C-49B3-889C-80F9A2A88040@linux.dev> <20231128035345.5c7yc7jnautjpfoc@moria.home.lan> <20231129231147.7msiocerq7phxnyu@moria.home.lan> <04f63966-af72-43ef-a65c-ff927064a3e4@bytedance.com> <20231130032149.ynap4ai47dj62fy3@moria.home.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 01 Dec 2023 12:01:59 -0800 (PST) On Fri, Dec 01, 2023 at 12:18:44PM +1100, Dave Chinner wrote: > On Thu, Nov 30, 2023 at 11:01:23AM -0800, Roman Gushchin wrote: > > On Wed, Nov 29, 2023 at 10:21:49PM -0500, Kent Overstreet wrote: > > > On Thu, Nov 30, 2023 at 11:09:42AM +0800, Qi Zheng wrote: > > > > For non-bcachefs developers, who knows what those statistics mean? > > > Ok, a simple question then: > > why can't you dump /proc/slabinfo after the OOM? > > Taken to it's logical conclusion, we arrive at: > > OOM-kill doesn't need to output anything at all except for > what it killed because we can dump > /proc/{mem,zone,vmalloc,buddy,slab}info after the OOM.... > > As it is, even asking such a question shows that you haven't looked > at the OOM kill output for a long time - it already reports the slab > cache usage information for caches that are reclaimable. > > That is, if too much accounted slab cache based memory consumption > is detected at OOM-kill, it will calldump_unreclaimable_slab() to > dump all the SLAB_RECLAIM_ACCOUNT caches (i.e. those with shrinkers) > to the console as part of the OOM-kill output. You are right, I missed that, partially because most of OOM's I had to deal with recently were memcg OOM's. This changes my perspective at Kent's patches, if we dump this information already, it might be not a bad idea to do it nicer. So I take my words back here. > > The problem Kent is trying to address is that this output *isn't > sufficient to debug shrinker based memory reclaim issues*. It hasn't > been for a long time, and so we've all got our own special debug > patches and methods for checking that shrinkers are doing what they > are supposed to. Kent is trying to formalise one of the more useful > general methods for exposing that internal information when OOM > occurs... > > Indeed, I can think of several uses for a shrinker->to_text() output > that we simply cannot do right now. > > Any shrinker that does garbage collection on something that is not a > pure slab cache (e.g. xfs buffer cache, xfs inode gc subsystem, > graphics memory allocators, binder, etc) has no visibility of the > actuall memory being used by the subsystem in the OOM-kill output. > This information isn't in /proc/slabinfo, it's not accounted by a > SLAB_RECLAIM_ACCOUNT cache, and it's not accounted by anything in > the core mm statistics. > > e.g. How does anyone other than a XFS expert know that the 500k of > active xfs_buf handles in the slab cache actually pins 15GB of > cached metadata allocated directly from the page allocator, not just > the 150MB of slab cache the handles take up? > > Another example is that an inode can pin lots of heap memory (e.g. > for in-memory extent lists) and that may not be freeable until the > inode is reclaimed. So while the slab cache might not be excesively > large, we might have an a million inodes with a billion cumulative > extents cached in memory and it is the heap memory consumed by the > cached extents that is consuming the 30GB of "missing" kernel memory > that is causing OOM-kills to occur. > > How is a user or developer supposed to know when one of these > situations has occurred given the current lack of memory usage > introspection into subsystems? What would be the proper solution to this problem from your point of view? What functionality/API mm can provide to make the life of fs developers better here? > > These are the sorts of situations that shrinker->to_text() would > allow us to enumerate when it is necessary (i.e. at OOM-kill). At > any other time, it just doesn't matter, but when we're at OOM having > a mechanism to report somewhat accurate subsystem memory consumption > would be very useful indeed. > > > Unlike anon memory, slab memory (fs caches in particular) should not be heavily > > affected by killing some userspace task. > > Whether tasks get killed or not is completely irrelevant. The issue > is that not all memory that is reclaimed by shrinkers is either pure > slab cache memory or directly accounted as reclaimable to the mm > subsystem.... My problem with the current OOM reporting infrastructure (and it's a bit an offtopic here) - it's good for manually looking into these reports, but not particularly great for automatic collection and analysis at scale. So this is where I was coming from. Thanks!