Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp5697077rwb; Wed, 21 Sep 2022 11:04:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM78iJg1x6B8HUQZpAQchncAkyaaYCfWpUMBiww8uAtdu0GdXjkM4o38S459wy9/UGtIs66j X-Received: by 2002:a17:902:9006:b0:178:b494:c15a with SMTP id a6-20020a170902900600b00178b494c15amr6075889plp.37.1663783466546; Wed, 21 Sep 2022 11:04:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663783466; cv=none; d=google.com; s=arc-20160816; b=uAsg0Gs/iZdNE94VD3MnfxQS5bozxeQ6WOGkpIHQj8+WZN8XeI3GdAYPsSv9BZ0y2q HcHYm8lpIY+0mnf3MYPmNcsiQJajNaZUV40l9vdE66nLlD9J2Nsf4jNHV7HJIbfMEzoz AJGa87Za/BULXN1f1ZinaBEXBubJX38o2FQg6tpnT2KdqQXrhFh6XC46HXZlfHo/RZUb 12sZtDukH+Rk1SRSSpSnvkqi4XNtkoG+CUQJuUpJxZc6tf/kEjMM8NL5LDOzS7Fbv0ns LpYIpvSgcRpg+d/r1LfxiRWwLBwXVXIX18fEv2Mo+qwhytE+FXO2o1De8sd8WLhADTSp gM4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IqSHaiXYNIJcBn0bJXiCvP0AIK+HFAJCgvDLc0GbgPg=; b=OXcDf10Sk54XCY0A7UwWR0gPiAZ0wUsXYgddqjbNPQ9dTQfziGhJWZtAe/M7hfbt2T 4RGHXsbEH7xT6M0nYbeQwt3kLaCT8us38irMOvS9++SUQX4eyUky5vCI/TIudaCAKbO6 5f3Hw5/h3i+9qNYVX9lNXAxw5jEPtrwoNpJR108JoaNy2M5rDJ8qVxxqZC4ykihAO9oW zk91yGqc2lEqIznGwEbf5VticM6t55jW0IvIRxng3StI2oSSQynTYKOOVb8tmdOeAjT7 Y0ljM1R85JrMsVzLs8ijZB+foApFcmznXmTc5b8gm1D2pJ6oldzvMqQMsCTQSOiFKRek onpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DssCK6+5; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z10-20020a63330a000000b0043978ae48a7si3651852pgz.177.2022.09.21.11.04.13; Wed, 21 Sep 2022 11:04:26 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DssCK6+5; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230447AbiIUQtH (ORCPT + 99 others); Wed, 21 Sep 2022 12:49:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231633AbiIUQsl (ORCPT ); Wed, 21 Sep 2022 12:48:41 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E5DF2F012 for ; Wed, 21 Sep 2022 09:41:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B8299B8273B for ; Wed, 21 Sep 2022 16:41:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06198C433D6; Wed, 21 Sep 2022 16:41:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663778505; bh=TPnWwHt82eNripHM/TYcNEM4j+W6BPqrNNPqcMZfY2Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DssCK6+5FXzjyCL6XPkfhP19N3vuzZwpdHEi9FoT3tAIJLv4uLcPmDkU3/ASW5rqJ +LpEimYm461rx6A8qD2Gg/miof6u/D2og2ABIlZkE159gh9yUHyxmZ0h+PCBkEBzOw UkfkGOGijvBa2Y/vGW2GzS41KcT8hN5+t7NKgTFP7ypazxp0b8LLV3elnNvEFV6lC6 D+1vcgOVV4v2l0I5E1UEy9pb5Nr+nx1HCzMr/mn8wN2bSir3g+Qu7uk5qYSLlRIHEl mI4Fb40bAXyiaJOce//FWlBxNhlvoM26mBRpn2932H7dIKNyDNklrmpSvAPueagsvZ atpk3RPMiQqjQ== From: SeongJae Park To: Xin Hao Cc: sj@kernel.org, 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: Wed, 21 Sep 2022 16:41:43 +0000 Message-Id: <20220921164143.59971-1-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220921034942.88568-1-xhao@linux.alibaba.com> References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 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. Thanks, SJ [...]