Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3103695rwb; Thu, 29 Sep 2022 21:18:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5EjfSftLEsNQNwXdnHhmq8HrMjs4dcHsl+5j2iDTqNVrn3uXLKndDKv7OQt+fSizOqYdn4 X-Received: by 2002:a17:906:9be4:b0:77a:a1c:a624 with SMTP id de36-20020a1709069be400b0077a0a1ca624mr5287902ejc.172.1664511513436; Thu, 29 Sep 2022 21:18:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664511513; cv=none; d=google.com; s=arc-20160816; b=Cn2GEYvrtkODlIv3Qe4ShmTFiLA6/WlO5We0fpqHcKWoid0wd2LHSqrrayxSQ25YuA 3KZFEUg0DNy/QIjPCEFr9MuDn4/3hoshb3yx7HKQNTC7ZyihG9OvAmoIIyNmfRLE8gCH or0QDVypDrHcDbSlGBN+RiN/R2sMwUMSS+dkT9byz/opo1ZfcKfZgBMzTFcZCZUrYtsc uoCEa47z8iz6wIDcZFFJDRoaR4zbenVHeaVYoO7t0F96hmyWvs1yzsK2aeUH4+41TDCj QicggOMOoYuy6/+9vUtILOotq1FR4zDlTK7TZV77Vtx1gJbvOKHIlGAzUD9gfZCSQK0K eLmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=5PW9yEJm2TZ4rvDYuk85itsZsQmvkbgTUynrv9k/4Ko=; b=ksmlRnDyw91xbXTenrT8zbBiwXbJfzDLEPNiRDsVjZifAPgJnKF68PY+pLszdmQOXH NkRYg8uP8HrJLuB03wPN6H9bFX/o0xtNzVMzGkfaJAKokYWlJU95gn3McwHafoZ/2Upo 7zSSzMS9JbVZSsOsUUU4qFPGYjo6+DqrQbd57WDFvCUqord/H6j9n2KGH7wvlvM73mCn ifSs8Re0+AuRjut/r5i+EhYDWfqTW3cPAj+MWQLCgy7fvqKoFYYBicfeVwG3YwAGH39D DJPCHDpUCp4mHMigSw1hYCivmjPEdtHz+nTjCckBfR9eUYo8P0fLhkOP6BDf2HR9vsOP PSkw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sc24-20020a1709078a1800b0078792b24218si846707ejc.841.2022.09.29.21.18.07; Thu, 29 Sep 2022 21:18:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230085AbiI3Dqh (ORCPT + 99 others); Thu, 29 Sep 2022 23:46:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229696AbiI3Dqf (ORCPT ); Thu, 29 Sep 2022 23:46:35 -0400 Received: from out30-42.freemail.mail.aliyun.com (out30-42.freemail.mail.aliyun.com [115.124.30.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4BB31D929B for ; Thu, 29 Sep 2022 20:46:33 -0700 (PDT) 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 X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > > [...]