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 59B5DC433FE for ; Fri, 30 Sep 2022 03:46:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B75EA8D0003; Thu, 29 Sep 2022 23:46:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B25738D0001; Thu, 29 Sep 2022 23:46:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A14028D0003; Thu, 29 Sep 2022 23:46:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 934848D0001 for ; Thu, 29 Sep 2022 23:46:37 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5037B141458 for ; Fri, 30 Sep 2022 03:46:37 +0000 (UTC) X-FDA: 79967364834.22.1979C04 Received: from out30-42.freemail.mail.aliyun.com (out30-42.freemail.mail.aliyun.com [115.124.30.42]) by imf13.hostedemail.com (Postfix) with ESMTP id 9D7D020007 for ; Fri, 30 Sep 2022 03:46:35 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R321e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046051;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VR0KQ4u_1664509589; Received: from 30.240.98.80(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VR0KQ4u_1664509589) by smtp.aliyun-inc.com; Fri, 30 Sep 2022 11:46:31 +0800 Message-ID: <61df199f-5579-933e-3f11-35f204f93bf4@linux.alibaba.com> Date: Fri, 30 Sep 2022 11:46:26 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH v1] mm/damon: add DAMON_OBJ macro To: SeongJae Park Cc: akpm@linux-foundation.org, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20220921164143.59971-1-sj@kernel.org> From: haoxin In-Reply-To: <20220921164143.59971-1-sj@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664509596; a=rsa-sha256; cv=none; b=pemq0X7qF+QF6y+Vbm2VDN/EV8bcy6rqSUcmNlYd9DFbsm6lwJKYHLCGUxTRO/tTLHazBL 6XaRjKb2/Zd3llKXbfRYCZUfXtqvwaf9YWCQuVkjNkw42Q1q1jt1ot9kBqPA+2LgpQjoSz j0/mf3lBjCcNdT+p6CVBdW3oUW9kONw= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf13.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.42 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664509596; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5PW9yEJm2TZ4rvDYuk85itsZsQmvkbgTUynrv9k/4Ko=; b=e+M+vvv5+oGVp8WTvTKOYcrQfaFT30q0sHsJUD9ray2TQQWoyawlzIJ8f2+7hXYOtHJggV AuoRp8+6goVhs1xokO58GrDuDTzISAGlA/PDRr6upa//hGpk7QWirQDGSeTMNqwfecyXJn aVk9LRr0M5n9eh6WLONNk2EVw4lGWp8= X-Stat-Signature: tg38uujbuonpok4fizriryfykmj48ckx X-Rspamd-Queue-Id: 9D7D020007 X-Rspamd-Server: rspam04 Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf13.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.42 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com X-Rspam-User: X-HE-Tag: 1664509595-308256 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: Hi SJ, 在 2022/9/22 上午12:41, SeongJae Park 写道: > Hi Xin, > > On Wed, 21 Sep 2022 11:49:42 +0800 Xin Hao 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 >> --- >> 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 > > [...]