Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp342995pxb; Fri, 22 Apr 2022 02:02:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJyn7e6AGuYKsSztZnihLonDFlTf57mjUwhj/y2mduS18zh7UIg/1PfJXV/owY05Rvr3Vl X-Received: by 2002:a63:6401:0:b0:3aa:5639:1884 with SMTP id y1-20020a636401000000b003aa56391884mr3009758pgb.71.1650618146314; Fri, 22 Apr 2022 02:02:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650618146; cv=none; d=google.com; s=arc-20160816; b=oi78lNyk8/eP8XUJXU+GO9Lcbw0YR+6dPgU3L3NH76hmGHxRiZfuNJXvM8Npk81GHJ +YGJvF/Vgubb2nPIzH5gc9T6ha7e85hrc55lV1jS3tMGOcyz6O5VL3kvvraFdQSwhlho aX56hCXEbAgySx0OVJL3F0OwbWuljC0I+wPapUte9s/rfNoxo3Dy/WeRpF578yHQdFmm elEw/F90ZsXRWCGZFStvUMENO4uFpRhczLflwdQgt+Duv7sPilIfMCbJAQdhftUxHX11 JeYx3o9B8lQng1S44G0Ti8MDCRw89p8zWNmm83AKV191M0zwWoLj/7uXHMiRxLmfdyBk cNhw== 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=jy2W+tJC4EgncPCr4pDQKFAbzSZdFCIXIUs8dOXozQY=; b=sXLWzGLipa8Puq1apku1o0PTGjUmevAeahjWNqlIaR675BlgA3Q2In+cyhr8R/2j85 Qu7UxPzhi5YR3Xqrt5S0bfWH1Pw2UVNYKztJbtvGQA/8G77PC0Zdm8LGxpxcUbvqrqJm i6zFVOqgAeimfWPvONqpw0FCBq7Hqs603lyvsyfcll2haxxpRO8JbutwpQkveMErkdXs keIwRYDUM16oEVhSUCmppZhb0m3jVspwRWoortWIL2OP1XCTC6B5sFJGU+CaGeqBPcCL +r/00614jxF3cJhY8WhHDmFgzTY/xM6gguLy+1KN7UjI2FgDudMv7J8ptdMxr/M9TcS2 2fPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=slSbIION; 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=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s204-20020a632cd5000000b003aa3698e98csi7363289pgs.15.2022.04.22.02.02.11; Fri, 22 Apr 2022 02:02:26 -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=@linux.dev header.s=key1 header.b=slSbIION; 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=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383174AbiDTX0J (ORCPT + 99 others); Wed, 20 Apr 2022 19:26:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348970AbiDTX0H (ORCPT ); Wed, 20 Apr 2022 19:26:07 -0400 Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 454821B7B4 for ; Wed, 20 Apr 2022 16:23:19 -0700 (PDT) Date: Wed, 20 Apr 2022 16:23:10 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1650496997; 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=jy2W+tJC4EgncPCr4pDQKFAbzSZdFCIXIUs8dOXozQY=; b=slSbIIONuIW5IsYAUO6/Ak9/Uy2xDxxzAglPdGlVUyne4pMkM/92eOlfHPViy6tlnZK58z fq9TeH04R6WXGgidq4F/lr/VQTY65o2Js/Sj+Ac7Qph0h4M8U5Gb7DstJ/CVptYaY068v8 5QJy8+uz8fysOl5azONnmvQ5kYC2EIk= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Yang Shi Cc: Linux MM , Andrew Morton , Dave Chinner , Linux Kernel Mailing List , Johannes Weiner , Michal Hocko , Shakeel Butt Subject: Re: [PATCH rfc 0/5] mm: introduce shrinker sysfs interface Message-ID: 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: X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS 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 Wed, Apr 20, 2022 at 03:24:49PM -0700, Yang Shi wrote: > On Fri, Apr 15, 2022 at 5:28 PM 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. > > > > To make debugging more pleasant, the patchset also names all shrinkers, > > so that sysfs entries can have more meaningful names. > > > > Usage examples: > > Thanks, Roman. A follow-up question, why do we have to implement this > in kernel if we just count the objects? It seems userspace tools could > achieve it too, for example, drgn :-). Actually I did write a drgn > script for debugging a problem a few months ago, which iterates > specific memcg's lru_list to count the objects by their state. Good question! It's because not all shrinkers are lru_list-based and even some lru_list-based are implementing a custom logic on top of it, e.g. shadow nodes. So there is no simple way to get the count from a generic shrinker. Also I want to be able to reclaim individual shrinkers from userspace (e.g. to profile how effective the shrinking is). Thanks!