From: haoxin <xhao@linux.alibaba.com>
To: SeongJae Park <sj@kernel.org>
Cc: akpm@linux-foundation.org, damon@lists.linux.dev,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] mm/damon: add DAMON_OBJ macro
Date: Fri, 30 Sep 2022 11:46:26 +0800 [thread overview]
Message-ID: <61df199f-5579-933e-3f11-35f204f93bf4@linux.alibaba.com> (raw)
In-Reply-To: <20220921164143.59971-1-sj@kernel.org>
Hi SJ,
在 2022/9/22 上午12:41, SeongJae Park 写道:
> Hi Xin,
>
> On Wed, 21 Sep 2022 11:49:42 +0800 Xin Hao <xhao@linux.alibaba.com> wrote:
>
>> In damon/sysfs.c file, we use 'container_of' macro to get
>> damon_sysfs_xxx struct instances, but i think it has a little
>> inconvenience, because we have to pass three arguments to
>> 'container_of', and the codes also look a bit long, so there i add a
>> 'DAMON_OBJ' macro, you just need to pass one arguments, then you can get
>> the right damon_sysfs_xxx struct instance.
> Thank you always for your helps and efforts, but I have some comments below.
>
>> Signed-off-by: Xin Hao <xhao@linux.alibaba.com>
>> ---
>> include/linux/damon.h | 7 ++
>> mm/damon/sysfs.c | 230 +++++++++++++++++-------------------------
>> 2 files changed, 102 insertions(+), 135 deletions(-)
>>
>> diff --git a/include/linux/damon.h b/include/linux/damon.h
>> index e7808a84675f..a3b577677caa 100644
>> --- a/include/linux/damon.h
>> +++ b/include/linux/damon.h
>> @@ -24,6 +24,13 @@ static inline unsigned long damon_rand(unsigned long l, unsigned long r)
>> return l + prandom_u32_max(r - l);
>> }
>>
>> +/*
>> + * Get damon_sysfs_xxx relative struct instance.
>> + */
>> +#define DAMON_OBJ(_type) ({ \
>> + const typeof(((struct _type *)0)->kobj)*__mptr = (kobj); \
>> + (struct _type *)((char *)__mptr - offsetof(struct _type, kobj)); })
>> +
> So, this macro assumes two implicit rules.
> 1. The caller would have a relevant 'struct kobject *' variable called 'kobj',
> and
> 2. The '_type' would have the field 'kobj'.
>
> I think the implicit rules could make some people confused, so would be better
> to be well documented. Even though those are well documented, I think it
> cannot intuitively read by everyone. Making the name better self-explaining
> might help, but then the length of the code would be not so different.
>
> So IMHO, this change makes the code a little bit shorter but unclear to
> understand what it does. And at least to my humble eyes, use of
> 'container_of()' makes the code a little bit more verbose, but clear to
> understand. I have no idea how we can make this code shorter while keeping it
> still easily understandable, and I think the level of verboseness is acceptable
> for the readability. So Nack at the moment, sorry.
I really feel the need to do that, how about keep it in the sysfs.c
file, and change it like this:
#define DAMON_OBJ(_struct) container_of(kobj, struct _struct, kobj)
it will feel easy to understand and made sense.
>
>
> Thanks,
> SJ
>
> [...]
next prev parent reply other threads:[~2022-09-30 3:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-21 3:49 Xin Hao
2022-09-21 16:41 ` SeongJae Park
2022-09-30 3:46 ` haoxin [this message]
2022-09-30 18:04 ` SeongJae Park
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=61df199f-5579-933e-3f11-35f204f93bf4@linux.alibaba.com \
--to=xhao@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=sj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox