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 724A8D10399 for ; Fri, 25 Oct 2024 00:38:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7ABF96B0095; Thu, 24 Oct 2024 20:38:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 75C256B0096; Thu, 24 Oct 2024 20:38:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 623CA6B0098; Thu, 24 Oct 2024 20:38:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 423FC6B0095 for ; Thu, 24 Oct 2024 20:38:01 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id EFF7914023D for ; Fri, 25 Oct 2024 00:37:40 +0000 (UTC) X-FDA: 82710261648.06.A895A21 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by imf11.hostedemail.com (Postfix) with ESMTP id A4F154000E for ; Fri, 25 Oct 2024 00:37:35 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=lSumJNdw; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 192.198.163.14 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729816474; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FFun/2zd/LDNtD7IRT35ounFZUrF3a5dGYJEJbSGiAI=; b=iys61MVGqAo8hgwVStoQUYvOcFQIocopeBPsVN1f11CwM8sq7MNccwJuKtNc4iwzIMQmON rFI9B1506jHRLksMUclMDJHPAgBdfKGlF9nWGmVSod9fhFVk0WMinm6nRbCwwWghy8/91v DyH/0BBHMpkb62AjqNaHPbR7ZkiS8w0= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=lSumJNdw; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 192.198.163.14 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729816474; a=rsa-sha256; cv=none; b=CifzUS1FgIO4suoDnuPqKWsZCwE0FBfYUdEmlL7CAm94piJbQeFRa8f39lSUF7gA8lnfBu SfXkwmMaULWs0cJHhfwQXPv0Vi1NqZ2+rXVP4PxTamXgc+OcvJSAanH49obwHHsLu++/Vp mUbNCNkEWJJHQ7oNHwkvjR4LfB53iz0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729816679; x=1761352679; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=eHPZAfwG8NkGljBkafKoc9M7hBYTkNOCs1lnbwpvDSo=; b=lSumJNdwIxSkg4mYWfntP8zLj59pbvwqhBa5zehmSSg1DOlXN6kDfpdP HK1v3kvvj4Vq5VM1uCKNIAHrvQXFPieGGsVTC4F5hRfW4xgze9MLn6Wi5 ieIIDVtI432uLE7C45nruVAFcExRsbuROmBtVJ2MuhAmUCst7ZLl2r66h Mj2IukraOvWhyLfNlT88bOzjBYcV5EhlEAb3EIl+1nKuvuiL3ikaRwlQC QFq5r1rvu/itzWPHh+grCMuAnW48iz9q5yAmU/Yg//nIpR91ZYywswRD/ OUZQE1AcKBtR8v3Z8+M3McAAEb1nVALVpWqHoHEk0cjAWaKcB3HN2kAUG A==; X-CSE-ConnectionGUID: XOIlR4YXTYCMeTrLIqVmuQ== X-CSE-MsgGUID: DrrCX1BuT0Gpq1C7Wr30fw== X-IronPort-AV: E=McAfee;i="6700,10204,11235"; a="29694224" X-IronPort-AV: E=Sophos;i="6.11,230,1725346800"; d="scan'208";a="29694224" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2024 17:37:57 -0700 X-CSE-ConnectionGUID: JbPqYJVuTpOpdktP1jboRw== X-CSE-MsgGUID: jnqhm2zkRJW9JS5rYDxAtA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,230,1725346800"; d="scan'208";a="81066461" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2024 17:37:54 -0700 From: "Huang, Ying" To: Andy Shevchenko Cc: Dan Williams , David Hildenbrand , Andrew Morton , , , , 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: (Andy Shevchenko's message of "Thu, 24 Oct 2024 16:01:52 +0300") 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> Date: Fri, 25 Oct 2024 08:34:21 +0800 Message-ID: <87o7392f76.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: A4F154000E X-Stat-Signature: h9iwxzrh8o4dmmucxcx1gqztswcpqxj5 X-Rspam-User: X-HE-Tag: 1729816655-340849 X-HE-Meta: U2FsdGVkX18IJcC4cgwaXndeKlTy1NtQPQ0geAx5Y0iFN2XBx2uqB+I9AtjhzfmHDH9CcAIxCYJhu+N5LcRasga5WT87SVrXN9iMGKLrncPlZjfijlB9oNs932an4F8BARhTIxskDVlvCFbrvKMIv4UxDFMddlC/cKPAljPk+rCdFx+Zkb/8mVp7rfSEogkAJBEttAQCJExg2W/HYtOcdHi0p+1skLTd4HNbOyDvyRK74NWeH0hbT3WqfD3RAoTvf6cpixX2jP+rUCR+EgcmWUok+P1hW+a1k7xBFxFe7NhlBm3YXbSjnRy4Nc4aRFCGQzMcLXFWLP2FwG6xRi4a90GQBz/ULj1FqtJlzaGThaS+SYV+PZ9bgEU7sTjr+8AHSveVMwHkpPn2HrqiYQfHW4+fC1NSFhcHoUldxlT+pq8Xfjwh6I0z3OmJzpA0nywjRpKgizQ47hzTZeV5I+ya6cItFCUlJRm692inxK1CsajFkWwPyAF1CdNU9ZQHMU385gd04vNFd49lLcJAcS166iYrB6bPUO2178IDCinH9hsHXi6hD2QQJ0C9AekpivnxGihKrL9AIjriMg0KiSbK/FsM32gXyg/jUSEphv+BofH1kY+JGQ6dk+Oi08u2l8BdDTpVXPbtQDPOknbMv6/+GqH6ROo6bcheNoQMhv1I9HH/XxYE17GnjkqKXcMVjpw6AoQSiwScYBtD8Wk/H8WJojaSoZTAUTkPWbzOGxwNdZs5s1fO1cKqiSAR4aaJHRqLZ9sag8hy2770pEGarQJ/4Tn95BBrxMHDNTTmTB/0zdyWxTfp+M2GI2Z2vXYZHaesZzq8y4kqoFf70PjPEoaBQe+YTg/Kv/qVzIdrs3hWvJasKSLUnqiYyejsepy4IuOEl1itiPRxZzGpASYi7NVgWifikoIXYbYfYym4YihCjo5G0tKxgJwRYqE+R+y2DO827YKc1xbMPv/at0ima8P qXiCEiMj khrAkBw0lyfsdI4QID0j+94v+RDQD5jsHPTT7ddO6wLDKFv0/IAqCNk0KVzW5Ts8m6EUPcy1zUZ90gGRAW0ki+bBQ9zDo+gkgTPZotTQUxkUFSjz7uM6Exfi5mUZOs81/YPoJQgjG8aQcIo+hcGf5MlKKjU/li/o+6wg1L6xfsMdWZhpWKNxgajW77/Dv78jGlxChSiK/4GfZk47DPrz3dhWPBZ1pMjiWbQ7KTQaqDv5hJIsWxlLcYU/l+cxMKfT5Xl63ulprzBmCp9Q= 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: Andy Shevchenko writes: > 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: > > ... > >> >> > > > for ((_p) = (_root)->child; (_p); (_p) = next_resource_XXX(_root, _p)) >> >> > > >> >> > > Yes. This can improve code readability. >> >> > > >> >> > > A possible issue is that "_root" will be evaluated twice in above macro >> >> > > definition. IMO, this should be avoided. >> >> > >> >> > Ideally, yes. But how many for_each type of macros you see that really try hard >> >> > to achieve that? I believe we shouldn't worry right now about this and rely on >> >> > the fact that root is the given variable. Or do you have an example of what you >> >> > suggested in the other reply, i.e. where it's an evaluation of the heavy call? >> >> > >> >> > > Do you have some idea about >> >> > > how to do that? Something like below? >> >> > > >> >> > > #define for_each_resource_XXX(_root, _p) \ >> >> > > for (typeof(_root) __root = (_root), __p = (_p) = (__root)->child; \ >> >> > > __p && (_p); (_p) = next_resource_XXX(__root, _p)) >> >> > >> >> > This is a bit ugly :-( I would avoid ugliness as long as we have no problem to >> >> > solve (see above). >> >> >> >> Using a local defined variable to avoid double evaluation is standard >> >> 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. >> >> If don't use '__p', the macro becomes >> >> #define for_each_resource_XXX(_root, _p) \ >> for (typeof(_root) __root = (_root), (_p) = (__root)->child; \ >> (_p); (_p) = next_resource_XXX(__root, _p)) >> >> 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 variable >> masking semantics. > > Yep. > > In property.h nobody cares about evaluation which makes the macro as simple as > > #define for_each_resource_XXX(_root, _p) \ > for (_p = next_resource_XXX(__root, NULL); _p; \ > _p = next_resource_XXX(__root, _p)) > > (Dan, > that's what I called to avoid solving issues we don't have and most likely > will never have.) > > but if you want to stick with your variant some improvements can be done: I still prefer to solve possible issues if the solution isn't too complex. > #define for_each_resource_XXX(_root, _p) \ > for (typeof(_root) __root = (_root), __p = _p = __root->child; \ > __p && _p; _p = next_resource_XXX(__root, _p)) > > > 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. Thanks! You are right. Will use this in the future versions. >> >> So no, this proposal is not "ugly", it is a best practice. See the >> >> definition of min_not_zero() for example. >> > >> > I know that there are a lot of macros that look uglier that this one. -- Best Regards, Huang, Ying