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 X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C169C43381 for ; Wed, 13 Jan 2021 16:06:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4D98023435 for ; Wed, 13 Jan 2021 16:06:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4D98023435 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 86C928D0063; Wed, 13 Jan 2021 11:06:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F4708D0061; Wed, 13 Jan 2021 11:06:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 709B88D0063; Wed, 13 Jan 2021 11:06:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0135.hostedemail.com [216.40.44.135]) by kanga.kvack.org (Postfix) with ESMTP id 5C3AC8D0061 for ; Wed, 13 Jan 2021 11:06:09 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 1A3451EE6 for ; Wed, 13 Jan 2021 16:06:09 +0000 (UTC) X-FDA: 77701228458.28.ants97_3f141e42751f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 74C0E6D80 for ; Wed, 13 Jan 2021 16:05:51 +0000 (UTC) X-HE-Tag: ants97_3f141e42751f X-Filterd-Recvd-Size: 7255 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 Jan 2021 16:05:50 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 51EC8AB9F; Wed, 13 Jan 2021 16:05:49 +0000 (UTC) To: Faiyaz Mohammed , cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: vinmenon@codeaurora.org References: <1610443287-23933-1-git-send-email-faiyazm@codeaurora.org> From: Vlastimil Babka Subject: Re: [PATCH] mm: slub: Convert sys slab alloc_calls, free_calls to bin attribute Message-ID: Date: Wed, 13 Jan 2021 17:05:48 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <1610443287-23933-1-git-send-email-faiyazm@codeaurora.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US 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 1/12/21 10:21 AM, Faiyaz Mohammed wrote: > Reading the sys slab alloc_calls, free_calls returns the available obje= ct > owners, but the size of this file is limited to PAGE_SIZE > because of the limitation of sysfs attributes, it is returning the > partial owner info, which is not sufficient to debug/account the slab > memory and alloc_calls output is not matching with /proc/slabinfo. >=20 > To remove the PAGE_SIZE limitation converted the sys slab > alloc_calls, free_calls to bin attribute. >=20 > Signed-off-by: Faiyaz Mohammed > --- > mm/slub.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++--------= ------ > 1 file changed, 47 insertions(+), 14 deletions(-) >=20 > diff --git a/mm/slub.c b/mm/slub.c > index b52384e..8744e5ec 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -4710,13 +4710,14 @@ static void process_slab(struct loc_track *t, s= truct kmem_cache *s, > } > =20 > static int list_locations(struct kmem_cache *s, char *buf, > - enum track_item alloc) > + loff_t offset, enum track_item alloc) > { > int len =3D 0; > unsigned long i; > struct loc_track t =3D { 0, 0, NULL }; > int node; > struct kmem_cache_node *n; > + static unsigned int previous_read_count; Hmm static? What about parallel reads from different files? I guess you'l= l have to somehow employ the offset parameter here and it won't be pretty, becau= se you are still printing free text and not some fixed-size binary chunks where = seeking is simple. Also it's wasteful to to repeat the data gathering for each pritned page,= you'd need a mechanism that allows holding private data between printing out th= e pages. If bin_attribute doesn't have that, you'd need e.g. seq_file which= we use for /proc/pid/(s)maps etc. > unsigned long *map =3D bitmap_alloc(oo_objects(s->max), GFP_KERNEL); This line doesn't exist since 90e9f6a66c78f in v5.6-rc1, is the patch bas= ed on an old kernel? > if (!map || !alloc_loc_track(&t, PAGE_SIZE / sizeof(struct location), > @@ -4742,11 +4743,9 @@ static int list_locations(struct kmem_cache *s, = char *buf, > spin_unlock_irqrestore(&n->list_lock, flags); > } > =20 > - for (i =3D 0; i < t.count; i++) { > + for (i =3D previous_read_count; i < t.count; i++) { > struct location *l =3D &t.loc[i]; > =20 > - if (len > PAGE_SIZE - KSYM_SYMBOL_LEN - 100) > - break; > len +=3D sprintf(buf + len, "%7ld ", l->count); > =20 > if (l->addr) > @@ -4784,12 +4783,20 @@ static int list_locations(struct kmem_cache *s,= char *buf, > nodemask_pr_args(&l->nodes)); > =20 > len +=3D sprintf(buf + len, "\n"); > + > + if (len > PAGE_SIZE - KSYM_SYMBOL_LEN - 100) { > + previous_read_count =3D i + 1; > + break; > + } > } > =20 > + if ((offset !=3D 0) && ((i >=3D t.count) || (previous_read_count > t.= count))) { > + previous_read_count =3D 0; > + len =3D 0; > + } else if (!t.count) > + len +=3D sprintf(buf, "No data\n"); > free_loc_track(&t); > bitmap_free(map); > - if (!t.count) > - len +=3D sprintf(buf, "No data\n"); > return len; > } > =20 > @@ -5180,6 +5187,7 @@ static int any_slab_objects(struct kmem_cache *s) > =20 > struct slab_attribute { > struct attribute attr; > + struct bin_attribute bin_attr; > ssize_t (*show)(struct kmem_cache *s, char *buf); > ssize_t (*store)(struct kmem_cache *s, const char *x, size_t count); > }; > @@ -5192,6 +5200,12 @@ struct slab_attribute { > static struct slab_attribute _name##_attr =3D \ > __ATTR(_name, 0600, _name##_show, _name##_store) > =20 > +#define SLAB_BIN_ATTR_RO(_name) \ > + static struct slab_attribute _name##_attr =3D { \ > + .bin_attr =3D \ > + __BIN_ATTR_RO(_name, 0) \ > + } \ > + > static ssize_t slab_size_show(struct kmem_cache *s, char *buf) > { > return sprintf(buf, "%u\n", s->size); > @@ -5535,21 +5549,33 @@ static ssize_t validate_store(struct kmem_cache= *s, > } > SLAB_ATTR(validate); > =20 > -static ssize_t alloc_calls_show(struct kmem_cache *s, char *buf) > +static ssize_t alloc_calls_read(struct file *filp, struct kobject *kob= j, > + struct bin_attribute *bin_attr, char *buf, > + loff_t offset, size_t count) > { > + struct kmem_cache *s; > + > + s =3D to_slab(kobj); > if (!(s->flags & SLAB_STORE_USER)) > return -ENOSYS; > - return list_locations(s, buf, TRACK_ALLOC); > + > + return list_locations(s, buf, offset, TRACK_ALLOC); > } > -SLAB_ATTR_RO(alloc_calls); > +SLAB_BIN_ATTR_RO(alloc_calls); > =20 > -static ssize_t free_calls_show(struct kmem_cache *s, char *buf) > +static ssize_t free_calls_read(struct file *filp, struct kobject *kobj= , > + struct bin_attribute *bin_attr, char *buf, > + loff_t offset, size_t count) > { > + struct kmem_cache *s; > + > + s =3D to_slab(kobj); > if (!(s->flags & SLAB_STORE_USER)) > return -ENOSYS; > - return list_locations(s, buf, TRACK_FREE); > + > + return list_locations(s, buf, offset, TRACK_FREE); > } > -SLAB_ATTR_RO(free_calls); > +SLAB_BIN_ATTR_RO(free_calls); > #endif /* CONFIG_SLUB_DEBUG */ > =20 > #ifdef CONFIG_FAILSLAB > @@ -5694,6 +5720,14 @@ STAT_ATTR(CPU_PARTIAL_NODE, cpu_partial_node); > STAT_ATTR(CPU_PARTIAL_DRAIN, cpu_partial_drain); > #endif /* CONFIG_SLUB_STATS */ > =20 > + > +static struct bin_attribute *slab_bin_attrs[] =3D { > +#ifdef CONFIG_SLUB_DEBUG > + &alloc_calls_attr.bin_attr, > + &free_calls_attr.bin_attr, > +#endif > +}; > + > static struct attribute *slab_attrs[] =3D { > &slab_size_attr.attr, > &object_size_attr.attr, > @@ -5722,8 +5756,6 @@ static struct attribute *slab_attrs[] =3D { > &poison_attr.attr, > &store_user_attr.attr, > &validate_attr.attr, > - &alloc_calls_attr.attr, > - &free_calls_attr.attr, > #endif > #ifdef CONFIG_ZONE_DMA > &cache_dma_attr.attr, > @@ -5769,6 +5801,7 @@ static struct attribute *slab_attrs[] =3D { > =20 > static const struct attribute_group slab_attr_group =3D { > .attrs =3D slab_attrs, > + .bin_attrs =3D slab_bin_attrs, > }; > =20 > static ssize_t slab_attr_show(struct kobject *kobj, >=20