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 E0001ECAAD8 for ; Wed, 21 Sep 2022 16:41:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 55DDC6B0071; Wed, 21 Sep 2022 12:41:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 50DEF940007; Wed, 21 Sep 2022 12:41:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D69A6B0073; Wed, 21 Sep 2022 12:41:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2E1356B0071 for ; Wed, 21 Sep 2022 12:41:49 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id F19241403D6 for ; Wed, 21 Sep 2022 16:41:48 +0000 (UTC) X-FDA: 79936659096.17.6A427B1 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf08.hostedemail.com (Postfix) with ESMTP id 7B5B0160012 for ; Wed, 21 Sep 2022 16:41:48 +0000 (UTC) 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 B644BB81AE4; 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663778508; a=rsa-sha256; cv=none; b=bVHUG3fOPErqu/PGMaE//CLKy/DxvTcbYP0oxX13MOcLmRZtdOYOh0h0eRENuEsk6dQyjn YdX7R8PZBjEWXTrXV/tL93D5J+txWJvx06L2QsH96kOSsLDos0X8OuUtGGPKrluWrLb5mx Tkl4uN6iYsUSmek7P9BrWfWFTphPSgk= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DssCK6+5; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf08.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663778508; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IqSHaiXYNIJcBn0bJXiCvP0AIK+HFAJCgvDLc0GbgPg=; b=TB2EfgWmRsDY8XKFKP4wJfMbeUHATtxGGRqUgNiaNx0alCyH0wNFajDgv5OGYmXny3K1iw O/LiB/Dv8YumlUDn0Isr1irxyhyT1ASdDFffB3Yr8YG+yh3yBH83QUY1CcmJKELs4ipYnD aj+BlWDqS/93u9si0KwAucmO3qzlCKQ= X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 7B5B0160012 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DssCK6+5; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf08.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org X-Stat-Signature: fhcufznatuo3n3f6ocime8kfytu5fmnq X-HE-Tag: 1663778508-791914 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 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 [...]