Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp386022pxb; Thu, 21 Apr 2022 01:37:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpeVub8+1GgknB8LuLEgmQ1KTdGd6vVKgXOaCG6qEbXRXs+lmlQXnIbzqK/0axNkheDwg0 X-Received: by 2002:a05:6a00:ad2:b0:4f1:2734:a3d9 with SMTP id c18-20020a056a000ad200b004f12734a3d9mr28103100pfl.61.1650530274352; Thu, 21 Apr 2022 01:37:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650530274; cv=none; d=google.com; s=arc-20160816; b=Wxj++ggsPXo7m9H8CAnX7rmtVgl6KzYLw2A0GXNIR2sAiQFqRUyt91AjkZ5AptCwlu erZmgb6sbRCnvIQoLqq2YhLlJxDQB1SOxQAL5A/m7FtT9Z0c1ck0mR7Z7fNnQ3IvcWLz onL8dixXrQTtzSdwzt3G4oDWBR63c9q+xLugpgVVoAzEDS7wkPkXXxKRsT6863Srhh3p tz0cq77eL3tU0oSNbshsdITFM/LLRhQzPLoiBwzzCQkB+Tz20bSFZl8SfDRx2sp+6lYV s5zQPxu+sERn0uid846i4qZNPNIBaRu9xn1FzEKqgQQs5++DInPk8dMQfNsyh5W9cM1q kI5w== 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:date:dkim-signature; bh=zeR3V0x/d5dS+XbGlGq1iYQwImzuhf524PVpciJ0wyA=; b=NF0C5fNcQEljWujgNKCKBPPfgOSojsZHW266A3C6Ftzp30P67HMb+JwApkEYyscLuq 8MbGNuPn1gJQZpvBqukbPZr7d6O8yp9KFsxtI1CNNiU+9Nr0+0ea8sntcCax8oiMX7Rv B82SXVftC2VfZPjFXFYadgVVWlK7Z5tpyHt4ikzV3ehcfGPvmXmfLuT52LQnBudN2JMO 9E0sBQrbTVVXU/LiYf7MQSnTB4kH90GkRyPgpyqiobWUUHmIxUnKKSTexjAI8XyUXsPP M/113ep6HDEMWheoTwfeeSz/060yIMp9lY88+CGplDjaduh72vAoefzM5j1NkIrl1r/y X/hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=f5MU9YQh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d21-20020a056a0024d500b004fa3a8e004csi4729656pfv.259.2022.04.21.01.37.39; Thu, 21 Apr 2022 01:37:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=f5MU9YQh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242773AbiDSSa7 (ORCPT + 99 others); Tue, 19 Apr 2022 14:30:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357445AbiDSS2I (ORCPT ); Tue, 19 Apr 2022 14:28:08 -0400 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD3A932ED4 for ; Tue, 19 Apr 2022 11:20:33 -0700 (PDT) Received: by mail-qt1-x836.google.com with SMTP id t26so4241372qtn.6 for ; Tue, 19 Apr 2022 11:20:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=zeR3V0x/d5dS+XbGlGq1iYQwImzuhf524PVpciJ0wyA=; b=f5MU9YQh2Eunm+v3zEufTrXY3X1K+ZReCWqTSryDhoUg5tqzZbCHuntywVLW4Nrj6T eS3a8FNZ7JhNWz/Mcwt2BdW20BCxmuxR4dA1Tx9M2lJpyDUpNkVwjmYYdjIQbexud61h NSY7ItILuCfFvzk42D8a9+0k9Wdh9pAlc4KDk8QjCQMjFOk7zNYPu35ohvTft8tkAPIm yl9Oxg7/5+HHzCfvXA9V8x6jH4RdwXF/30DxlSar4NPGGNqDzl3zU1NWAcS2oA8FbQ7d r/RdKJFFc3EgwU2+2jeXGdvgDEPMVrIdAZU/E8VpyzSw76zEcrsB8YCy9U4f+rtt1VLJ qq6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=zeR3V0x/d5dS+XbGlGq1iYQwImzuhf524PVpciJ0wyA=; b=vjPx0V/N3JwRI37p8CCA6w3XqHXHCefGBuxTd1N2uR06fBFg0xygG8orSlEUNSfIvg UsWIHJIOExr+BgYxvXpPKbmv9cqXkNcVrpMCTc16hFIhy9pwQM0tfIcjWIVcBCIumPDM pCZzWJxrFaf/kzPG2kT9CYH1rfg0tyDiVF0+pQ8JmgTPSjIhoH7L4aMgzamOPFl6hyJx jNyD8mJGstH+W9W00HHiC+VFFBlPhuvPHdrI66R71vJGq7nUnS8/MzGd92O/DPuauvy7 +Cn8xTomicJD+If8TCAFH9mSQ0kZ1vWnRw85A0mspuDpd64oemeFKCUoqLP3duhq2+r8 vXzA== X-Gm-Message-State: AOAM533BmEPKrhd9XJ8SA6/GbWDkQty3iaaaVCNiMBsZQU92jp0LEAqT 8n1K7azgw9Fyhh3pqa+4VQ== X-Received: by 2002:ac8:578b:0:b0:2e2:324a:7b6c with SMTP id v11-20020ac8578b000000b002e2324a7b6cmr11081009qta.267.1650392432986; Tue, 19 Apr 2022 11:20:32 -0700 (PDT) Received: from moria.home.lan (c-73-219-103-14.hsd1.vt.comcast.net. [73.219.103.14]) by smtp.gmail.com with ESMTPSA id s18-20020a05622a1a9200b002f335693f4bsm400640qtc.38.2022.04.19.11.20.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 11:20:32 -0700 (PDT) Date: Tue, 19 Apr 2022 14:20:30 -0400 From: Kent Overstreet To: Roman Gushchin 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: <20220419182030.idqqmtim4slhbked@moria.home.lan> References: <20220416002756.4087977-1-roman.gushchin@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220416002756.4087977-1-roman.gushchin@linux.dev> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 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. 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. 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. 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.