Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp930777pxb; Fri, 22 Apr 2022 14:38:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZUAj7Iiwzon4kP5YDs75p5zD0j1JvLnwqyWTsvLzBqyR9RXodC/wnwbdstiPIxtYIF/Yt X-Received: by 2002:a17:90a:d3d3:b0:1bf:2e8d:3175 with SMTP id d19-20020a17090ad3d300b001bf2e8d3175mr7725701pjw.2.1650663505805; Fri, 22 Apr 2022 14:38:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650663505; cv=none; d=google.com; s=arc-20160816; b=bzvQ7nJVYJyHfuNXnVwyNhwinSgjYBC6mBFurednJP3WVSn/qo3aWZobB2b/ZS99Ba 29BNfUWmHuoeDy9zoVMj300O5aLA1zAAVqMmLCsizvzqCU64rmibxJKxcdoatkX45ilB yGnFimjCJuxosIAOLd7MfbrnvWXAgc0htNs0C9XZzMhuRQSydCNHvtAnZyrcUUSQdXC9 1c8YI2xNNkF9S/oXsbc6hAUBv+ZyxHlr3ZVjnss0vnEXFOb8QtVBfZVhZ/6wKxaAE1Dv ZTJIni9+OvcQIkxb6eI8PRu2TC958ZFnnvYqvDMnwMFFCXT7t3YF5fKFgryaofcEFQEi BlsA== 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=aHP1fr3pFCglhUt6wslEJqCTPQEvCI12BCqK6uc3qpE=; b=GelYR65LknQhMJRFYuhUiCoxj0OHK3cWZFx+24hmV9DygDj++uRwYQE3fJ1goUn8Fj nPrq8PpTPIe4SV35bMVr8l1pjWYitKl1gutKK0sOYWXgyBRitvHR1EqRtIziS1RSgAou q0jeoW9EI1g2JrQfb9pWQuLHld1P07BECKbU2OD84GsORJIGkoCDCeQs55DrUFTqCdqw fFrMWLSc9jQtkXFQdZxFIN4KPDbtkV4qlAxeFZuACqRItOQ0uv2VImJGNENC1v9nOewy Aiv2sq/V6nbyvVFRl5lGaaGHfpjJPwNFAsFa2yJAsPcKTqiAnSamw722uq6Teev3sMII Ibcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=gnhLIOha; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id c9-20020a637249000000b003aa45e32c20si9392463pgn.860.2022.04.22.14.38.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 14:38:25 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=gnhLIOha; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4C34C221767; Fri, 22 Apr 2022 12:45:52 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352847AbiDSTAy (ORCPT + 99 others); Tue, 19 Apr 2022 15:00:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349562AbiDSTAw (ORCPT ); Tue, 19 Apr 2022 15:00:52 -0400 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB4CF3EF08 for ; Tue, 19 Apr 2022 11:58:07 -0700 (PDT) Date: Tue, 19 Apr 2022 11:58:00 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1650394686; 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=aHP1fr3pFCglhUt6wslEJqCTPQEvCI12BCqK6uc3qpE=; b=gnhLIOha4Zr8ErfXIK162pTJfscSXT9fDJM6MJH7Df5HlbvUDZ2PwsBxD8idBgSHTR6Yi+ PuheUtLEu2Xge91pGBxcIz4PW4NnBj8sDVUFnKGYlJ0Sml0iP33rIdgScf0G5KNVQICfuD ckx16d5O1MfYiOOoQPTCVk5QCrZD5dg= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Kent Overstreet Cc: linux-mm@kvack.org, Andrew Morton , Dave Chinner , linux-kernel@vger.kernel.org, Johannes Weiner , Michal Hocko , Shakeel Butt , Yang Shi Subject: Re: [PATCH rfc 0/5] mm: introduce shrinker sysfs interface Message-ID: References: <20220416002756.4087977-1-roman.gushchin@linux.dev> <20220419182030.idqqmtim4slhbked@moria.home.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220419182030.idqqmtim4slhbked@moria.home.lan> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=no 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 On Tue, Apr 19, 2022 at 02:20:30PM -0400, Kent Overstreet wrote: > On Fri, Apr 15, 2022 at 05:27:51PM -0700, Roman Gushchin wrote: > > There are 50+ different shrinkers in the kernel, many with their own bells and > > whistles. Under the memory pressure the kernel applies some pressure on each of > > them in the order of which they were created/registered in the system. Some > > of them can contain only few objects, some can be quite large. Some can be > > effective at reclaiming memory, some not. > > > > The only existing debugging mechanism is a couple of tracepoints in > > do_shrink_slab(): mm_shrink_slab_start and mm_shrink_slab_end. They aren't > > covering everything though: shrinkers which report 0 objects will never show up, > > there is no support for memcg-aware shrinkers. Shrinkers are identified by their > > scan function, which is not always enough (e.g. hard to guess which super > > block's shrinker it is having only "super_cache_scan"). They are a passive > > mechanism: there is no way to call into counting and scanning of an individual > > shrinker and profile it. > > > > To provide a better visibility and debug options for memory shrinkers > > this patchset introduces a /sys/kernel/shrinker interface, to some extent > > similar to /sys/kernel/slab. > > > > For each shrinker registered in the system a folder is created. The folder > > contains "count" and "scan" files, which allow to trigger count_objects() > > and scan_objects() callbacks. For memcg-aware and numa-aware shrinkers > > count_memcg, scan_memcg, count_node, scan_node, count_memcg_node > > and scan_memcg_node are additionally provided. They allow to get per-memcg > > and/or per-node object count and shrink only a specific memcg/node. > > Cool! > > I've been starting to sketch out some shrinker improvements of my own, perhaps > we could combine efforts. Thanks! Absolutely! > The issue I've been targeting is that when we hit an > OOM, we currently don't get a lot of useful information - shrinkers ought to be > included, and we really want information on shrinker's internal state (e.g. > object dirtyness) if we're to have a chance at understanding why memory isn't > getting reclaimed. > > https://evilpiepirate.org/git/bcachefs.git/log/?h=shrinker_to_text > > This adds a .to_text() method - a pretty-printer - that shrinkers can > implement, and then on OOM we report on the top 10 shrinkers by memory usage, in > sorted order. We must be really careful with describing what's allowed and not allowed by these callbacks. In-kernel OOM is the last-resort mechanism and it should be able to make forward progress in really nasty circumstances. So there are significant (and not very well described) limitations on what can be done from the oom context. > > Another thing I'd like to do is have shrinkers report usage not just in object > counts but in bytes; I think it should be obvious why that's desirable. I totally agree, it's actually on my short-term todo list. > > Maybe we could have a memory-reporting-and-shrinker-improvements session at LSF? > I'd love to do some collective brainstorming and get some real momementum going > in this area. Would be really nice! I'm planning to work on improving shrinkers and gather ideas and problems, so having a discussion would be really great. Thanks!