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 73E13D1038E for ; Fri, 25 Oct 2024 00:35:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D9CA56B0092; Thu, 24 Oct 2024 20:35:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D25596B0093; Thu, 24 Oct 2024 20:35:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B9F0C6B0095; Thu, 24 Oct 2024 20:35:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 98C1B6B0092 for ; Thu, 24 Oct 2024 20:35:01 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9FBA5A0240 for ; Fri, 25 Oct 2024 00:34:26 +0000 (UTC) X-FDA: 82710254592.28.814892A Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by imf02.hostedemail.com (Postfix) with ESMTP id 05FC18000C for ; Fri, 25 Oct 2024 00:34:21 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=jeWXkcHm; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf02.hostedemail.com: domain of ying.huang@intel.com designates 192.198.163.11 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729816459; a=rsa-sha256; cv=none; b=uo0lmY9O5UyI2CKbRL7OXVgL6YS2erJmCZOsREqqEmILIOymMokGSo366Qk3HFn58l/Yw/ U9hwi2JiY5TATddVVNTEFQYo36+clAalYcc8p3KE23++FIsJDCxWQTKnprglHtZbRgRoHS r8iTHUhJVrFvUbbT1yoEObo90feyZtE= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=jeWXkcHm; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf02.hostedemail.com: domain of ying.huang@intel.com designates 192.198.163.11 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729816459; 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:dkim-signature; bh=LGJ43pTyMc/FDMsBUvEBoiDrjFqecumJCd96GvsFfss=; b=UbW5UrrMvcA9um5Tmw2wIepfMeQkT5vV7ShlIzu2Vvjk+Cjzkf0giZeLSIc/4w/fF8ywR/ h9Wjn1foIAg8vpOuR9h3+t7J2htFfeM1BE05pjJIudG4ZmhDPV4hLP1d475DAUMUebkVS3 ADo8/MjKhr1+FrXZ5JaKhTrhxE4j/2o= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729816498; x=1761352498; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version:content-transfer-encoding; bh=WZLcB/JIp9eAIRtXS44KhQy+6u4FTbvIx6i23GslbnM=; b=jeWXkcHm5Y73p7VWCxlGv8xCR/mvHVe6I+44/eRYrA9I4lNTloAmfb2/ 6a9FGtJqDvs/UqMXiWEy3qMr5vF9AoL93lqD7PlV5tNeI9aDjv5g/hm7Y EHRl8Vm/FCSieKviimz4eRcJC51IusOnDYSr+X/ktmbWomnkxFqbPsBYe G1KCzBz3AmgNxF/Vy5lCPlnzUAhsLiczK+bkzrbP0bfuM14W+nIo2Dj/m 41enf5y+SmV8/VphyOR6vD7wcC0dMgQd1x0aHQSRGs6vpeNdHTYNXd3iP dRSClYXpLzGWlbXxD0LWKwMZCJNNoUllp36to9usESpKPZpPoCtdYGwFO Q==; X-CSE-ConnectionGUID: i80vi3+mRya6Iy8jObJETQ== X-CSE-MsgGUID: nyyXoYqHQ+OF0nf30u7HHg== X-IronPort-AV: E=McAfee;i="6700,10204,11235"; a="40065031" X-IronPort-AV: E=Sophos;i="6.11,230,1725346800"; d="scan'208";a="40065031" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2024 17:34:57 -0700 X-CSE-ConnectionGUID: ZUpTV2XERfSb8sYEZNtsng== X-CSE-MsgGUID: lMDrP+CLSxGFFav1q8Ue3w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,230,1725346800"; d="scan'208";a="81580938" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2024 17:34:54 -0700 From: "Huang, Ying" To: Dan Williams Cc: Andy Shevchenko , David Hildenbrand , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-cxl@vger.kernel.org, Davidlohr Bueso , Jonathan Cameron , Alistair Popple , Bjorn Helgaas , Baoquan He , Dave Jiang , Alison Schofield Subject: Re: [RFC] resource: Avoid unnecessary resource tree walking in __region_intersects() In-Reply-To: <671ac2d2b7bea_10e59294f2@dwillia2-xfh.jf.intel.com.notmuch> (Dan Williams's message of "Thu, 24 Oct 2024 14:57:38 -0700") References: <20241010065558.1347018-1-ying.huang@intel.com> <87set3a1nm.fsf@yhuang6-desk2.ccr.corp.intel.com> <671965a8b37a2_1bbc629489@dwillia2-xfh.jf.intel.com.notmuch> <87wmhx3cpc.fsf@yhuang6-desk2.ccr.corp.intel.com> <671ac2d2b7bea_10e59294f2@dwillia2-xfh.jf.intel.com.notmuch> Date: Fri, 25 Oct 2024 08:31:21 +0800 Message-ID: <87sesl2fc6.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Stat-Signature: 4df9fowqkce3ukowngu1gagpbnd3cuif X-Rspamd-Queue-Id: 05FC18000C X-Rspamd-Server: rspam02 X-HE-Tag: 1729816461-3201 X-HE-Meta: U2FsdGVkX18EMipfQhGMHUzeYEFfCk535ioaTYVTHwXf0tEy58nAWFMusP4r8OQJu9Z5JHpumFCDc8DYEGmyqY6QrvB4v7sGxmVO6bEdYwpbTbucMbBu8+Q9uEl3ZXKzY+mgTiRkQp5rKhtflmuyGN2AdTkYX0VA7D2s8Ky3DYQ+000sxyaGNuJBxxIF1WrlEQY/aahKCzgWXkFEtT76gOOCVevuYER3lYbrQoWdipSaaScWHF/t5UWYqS2/XzWp+t8FG6yojLVDWf7lucMHN2KZ/vnYDHFT9dzmNLBvL1l2fGmjWF5uqDZklSQPKgK9F4P7Fm52PaL086qUXEp0njXhINV7cxG821z/NG6IKG4okYGwKmUqWA72qc5Zhv8z18SqQartRH15gdH8k4URhICAGQcAyKz9mkFCsy98S0D7n0qSjo8Jbs45KTcNcPF0SG/NSkycTFNKMYzuHPkAxPn3XV6X+XBdh0WZXbY0ulqb+ml8qvOx3WTr58BbLRmLay4TghrCb++1RO8syVSSBT96WwEXYJdCBQztJfoyGOI3ii2hZCUmR2sN1N612fHz0wyVBh5V+y0WcOgd4xJjv8PZ61VO/rKwpffZtfvL5TCwCyoBuHPJJcIEfp4hNbT3BsYy3LoOS9mNd+265FoPjhFNuum+1A3Z+e/O89pIcWh/CjIAwWdkeGYZR+zb0p13D9xN8WIF63OL/Kk1TCD8gsuvGKMPQPGOBpXPsP9uuU8SlG66DaUlkfUWvFQAbpwgkLeUAl483u7MdAV/uhTstmI/N8LZytZU8rdEDIDpW2i3OP63y+7+rfPwcCSqROp5z+IHIp/Qylj57cKnMOOvrM9XbbEBM6clkzz6qrVyVzxHbfvdNE5/IxVq/Vn8Ukr6W8B+BhxlURh3xGa8z2UowRlmsxVzXuX9mJ8BNLaAQkLIwFKZg/pPadAsads3f8HF9axCHVCubUBiz8ryFqK lvi/OEop 0x+NWGbhE5KjT2t+v9bOh+jU0BbaRZgtn5eHP1SZF/7US8/TYl7G+um3m3H2UZsdzvT9fnVBo9BAkQjypD0ro5zIn3T99pe7RWHGu+aq3Wtx9p4UTasEYNMSD8jXqDFMY7lew2Zk+majj97rCwjnKElfeROACySkiD0dp615N42yyozuAymv6TKIcCMpmU7iUjk7EFC1TSqEnCnzNlgHcoLSpQ1s6X+m8HX2p86T8hE1H3+mK1UfcEoi5BF/X3yITaa9GRNaekUwfalE= 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: List-Subscribe: List-Unsubscribe: Dan Williams writes: > Andy Shevchenko wrote: >> On Thu, Oct 24, 2024 at 08:30:39PM +0800, Huang, Ying wrote: >> > Andy Shevchenko writes: >> > > On Wed, Oct 23, 2024 at 02:07:52PM -0700, Dan Williams wrote: >> > >> Andy Shevchenko wrote: >> > >> > On Fri, Oct 11, 2024 at 09:06:37AM +0800, Huang, Ying wrote: >> > >> > > David Hildenbrand writes: >> > >> > > > On 10.10.24 08:55, Huang Ying wrote: >>=20 >> ... >>=20 >> > >> > > > for ((_p) =3D (_root)->child; (_p); (_p) =3D next_resource_X= XX(_root, _p)) >> > >> > >=20 >> > >> > > Yes. This can improve code readability. >> > >> > >=20 >> > >> > > A possible issue is that "_root" will be evaluated twice in abo= ve macro >> > >> > > definition. IMO, this should be avoided. >> > >> >=20 >> > >> > Ideally, yes. But how many for_each type of macros you see that r= eally try hard >> > >> > to achieve that? I believe we shouldn't worry right now about thi= s and rely on >> > >> > the fact that root is the given variable. Or do you have an examp= le of what you >> > >> > suggested in the other reply, i.e. where it's an evaluation of th= e heavy call? >> > >> >=20 >> > >> > > Do you have some idea about >> > >> > > how to do that? Something like below? >> > >> > >=20 >> > >> > > #define for_each_resource_XXX(_root, _p) = \ >> > >> > > for (typeof(_root) __root =3D (_root), __p =3D (_p) =3D (__roo= t)->child; \ >> > >> > > __p && (_p); (_p) =3D next_resource_XXX(__root, _p)) >> > >> >=20 >> > >> > This is a bit ugly :-( I would avoid ugliness as long as we have = no problem to >> > >> > solve (see above). >> > >>=20 >> > >> Using a local defined variable to avoid double evaluation is standa= rd >> > >> practice. I do not understand "avoid ugliness as long as we have no= problem to >> > >> solve", the problem to solve will be if someone accidentally does >> > >> something like "for_each_resource_descendant(root++, res)". *That* = will >> > >> be a problem when someone finally realizes that the macro is hiding= a >> > >> double evaluation. >> > > >> > > Can you explain, why do we need __p and how can we get rid of that? >> > > I understand the part of the local variable for root. >> >=20 >> > If don't use '__p', the macro becomes >> >=20 >> > #define for_each_resource_XXX(_root, _p) = \ >> > for (typeof(_root) __root =3D (_root), (_p) =3D (__root)->child; \ >> > (_p); (_p) =3D next_resource_XXX(__root, _p)) >> >=20 >> > Where, '_p' must be a variable name, and it will be a new variable >> > inside for loop and mask the variable with same name outside of macro. >> > IIUC, this breaks the macro convention in kernel and has subtle variab= le >> > masking semantics. >>=20 >> Yep. > > Oh, due to the comment expression, good catch. > >>=20 >> In property.h nobody cares about evaluation which makes the macro as sim= ple as >>=20 >> #define for_each_resource_XXX(_root, _p) \ >> for (_p =3D next_resource_XXX(__root, NULL); _p; \ >> _p =3D next_resource_XXX(__root, _p)) >>=20 >> (Dan, >> that's what I called to avoid solving issues we don't have and most lik= ely >> will never have.) > > Ah, my apologies, I thought the objection was to the macro altogether.=20 > >> but if you want to stick with your variant some improvements can be done: >>=20 >> #define for_each_resource_XXX(_root, _p) \ >> for (typeof(_root) __root =3D (_root), __p =3D _p =3D __root->child; \ >> __p && _p; _p =3D next_resource_XXX(__root, _p)) >>=20 >>=20 >> 1) no need to have local variable in parentheses; >> 2) no need to have iterator in parentheses, otherwise it would be crazy = code >> that has put something really wrong there and still expect the thing to = work. > > Why not: > > #define for_each_resource_XXX(_root, _p) \ > for (typeof(_root) __root =3D (_root), __p =3D _p =3D __root->child; \ > _p; _p =3D next_resource_XXX(__root, _p)) > > The __p is only to allow for _p to be initialized in the first statement > without causing a new "_p" shadow to be declared. I have tries this before. Compiler will complain with warning: unused variable =E2=80=98__p=E2=80=99 [-Wunused-variable] -- Best Regards, Huang, Ying