From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 147FAC433EF for ; Sat, 16 Apr 2022 01:35:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A3E086B0072; Fri, 15 Apr 2022 21:35:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9ED676B0073; Fri, 15 Apr 2022 21:35:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B73E6B0074; Fri, 15 Apr 2022 21:35:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0122.hostedemail.com [216.40.44.122]) by kanga.kvack.org (Postfix) with ESMTP id 7C19A6B0072 for ; Fri, 15 Apr 2022 21:35:47 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 308B48249980 for ; Sat, 16 Apr 2022 01:35:47 +0000 (UTC) X-FDA: 79361025534.28.DD99EA2 Received: from mail3-165.sinamail.sina.com.cn (mail3-165.sinamail.sina.com.cn [202.108.3.165]) by imf26.hostedemail.com (Postfix) with SMTP id 64710140002 for ; Sat, 16 Apr 2022 01:35:44 +0000 (UTC) Received: from unknown (HELO localhost.localdomain)([114.249.57.134]) by sina.com (172.16.97.32) with ESMTP id 625A1D6000025FE3; Sat, 16 Apr 2022 09:35:30 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com X-SMAIL-MID: 143835628878 From: Hillf Danton To: Roman Gushchin Cc: linux-mm@kvack.org, Andrew Morton , Dave Chinner , linux-kernel@vger.kernel.org, Michal Hocko Subject: Re: [PATCH rfc 1/5] mm: introduce sysfs interface for debugging kernel shrinker Date: Sat, 16 Apr 2022 09:35:31 +0800 Message-Id: <20220416013531.1582-1-hdanton@sina.com> In-Reply-To: <20220416002756.4087977-2-roman.gushchin@linux.dev> References: <20220416002756.4087977-1-roman.gushchin@linux.dev> MIME-Version: 1.0 X-Stat-Signature: bn8gin16pt4cyzfxaqnj9dej1o8ct4x8 X-Rspam-User: Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf26.hostedemail.com: domain of hdanton@sina.com designates 202.108.3.165 as permitted sender) smtp.mailfrom=hdanton@sina.com X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 64710140002 X-HE-Tag: 1650072944-78407 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, 15 Apr 2022 17:27:52 -0700 Roman Gushchin wrote: > This commit introduces the /sys/kernel/shrinker sysfs interface > which provides an ability to observe the state and interact with > individual kernel memory shrinkers. >=20 > Because the feature is oriented on kernel developers and adds some > memory overhead (which shouldn't be large unless there is a huge > amount of registered shrinkers), it's guarded by a config option > (disabled by default). >=20 > To simplify the code, kobjects are not embedded into shrinkers > objects, but are created, linked and unlinked dynamically. >=20 > This commit introduces basic "count" and "scan" interfaces. > Basic usage: > $ cat count : get the number of objects > $ echo "500" > scan : try to reclaim 500 objects > $ cat scan : get the number of objects reclaimed What is nice in design is the window opened for scanning individual shrin= ker without bothering wakeup of kswapd, thus this is good work from the drawi= ng board. > + > +static ssize_t scan_store(struct shrinker_kobj *skobj, > + struct shrinker_attribute *attr, > + const char *buf, size_t size) > +{ > + unsigned long nr, total =3D 0, nr_to_scan =3D 0, freed =3D 0; > + unsigned long *count_per_node =3D NULL; > + struct shrinker *shrinker; > + ssize_t ret =3D size; > + int nid; > + > + if (kstrtoul(buf, 10, &nr_to_scan)) > + return -EINVAL; > + > + down_read(&shrinker_rwsem); Nit, use down_read_killable instead to allow the CAP_SYS_ADMIN guy to change mind on cmdline. Hillf