Re: [PATCH v2 2/2] alloc_tag: keep codetag iterator active between read() calls

From: David Wang
Date: Fri May 09 2025 - 23:26:36 EST




At 2025-05-10 02:33:48, "Tim Chen" <tim.c.chen@xxxxxxxxxxxxxxx> wrote:
>On Sat, 2025-05-10 at 01:39 +0800, David Wang wrote:
>>
>>
>> Signed-off-by: David Wang <00107082@xxxxxxx>
>> ---
>> lib/alloc_tag.c | 29 ++++++++++-------------------
>> 1 file changed, 10 insertions(+), 19 deletions(-)
>>
>> diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c
>> index 25ecc1334b67..fdd5887769a6 100644
>> --- a/lib/alloc_tag.c
>> +++ b/lib/alloc_tag.c
>> @@ -45,21 +45,16 @@ struct allocinfo_private {
>> static void *allocinfo_start(struct seq_file *m, loff_t *pos)
>> {
>> struct allocinfo_private *priv;
>> - struct codetag *ct;
>> loff_t node = *pos;
>>
>> - priv = kzalloc(sizeof(*priv), GFP_KERNEL);
>> - m->private = priv;
>> - if (!priv)
>> - return NULL;
>> -
>> - priv->print_header = (node == 0);
>> + priv = (struct allocinfo_private *)m->private;
>> codetag_lock_module_list(alloc_tag_cttype, true);
>> - priv->iter = codetag_get_ct_iter(alloc_tag_cttype);
>> - while ((ct = codetag_next_ct(&priv->iter)) != NULL && node)
>> - node--;
>> -
>> - return ct ? priv : NULL;
>> + if (node == 0) {
>> + priv->print_header = true;
>> + priv->iter = codetag_get_ct_iter(alloc_tag_cttype);
>> + codetag_next_ct(&priv->iter);
>> + }
>
>Do you need to skip print header when *pos != 0? i.e add
>
> } else {
> priv->print_header = false;
> }
>
>Tim

print_header flag will be set to false once header is printed, in allocinfo_show():
114 if (priv->print_header) {
115 print_allocinfo_header(&buf);
116 priv->print_header = false;
117 }

once priv->print_header) is set to true, the header will be printed once and only once until it is
set to true next time.

Thanks
David

>
>> + return priv->iter.ct ? priv : NULL;
>> }
>>