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 07D64D0C609 for ; Fri, 25 Oct 2024 13:22:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 97E706B008C; Fri, 25 Oct 2024 09:22:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 92E0F6B0092; Fri, 25 Oct 2024 09:22:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F6156B0095; Fri, 25 Oct 2024 09:22:25 -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 5E5096B008C for ; Fri, 25 Oct 2024 09:22:25 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7B6D140A95 for ; Fri, 25 Oct 2024 13:22:14 +0000 (UTC) X-FDA: 82712187642.07.49212E6 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by imf04.hostedemail.com (Postfix) with ESMTP id 3B7D840009 for ; Fri, 25 Oct 2024 13:21:57 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=eELR54Qs; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf04.hostedemail.com: domain of andriy.shevchenko@linux.intel.com has no SPF policy when checking 192.198.163.10) smtp.mailfrom=andriy.shevchenko@linux.intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729862502; a=rsa-sha256; cv=none; b=Oq/X9xHquZFhteKuFN1ysqJVXuuZkrrH2YJSjb+LdmBFZsHlLdIz+P5NJFmfQlCNW9Qguk gmCsJxNDoFcyirxgTEf6SwhX1m/76vdnWeBaH4Ad/OOoOTry79p59o1/qXitlynqtYpOft AreK/duzwJHTYQ4KtSntoWrPPfRQf0c= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=eELR54Qs; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf04.hostedemail.com: domain of andriy.shevchenko@linux.intel.com has no SPF policy when checking 192.198.163.10) smtp.mailfrom=andriy.shevchenko@linux.intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729862502; 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=nOHcnHrS3Lbov4n7GOVnMY5MXppFn+XIJKqkdlnjD9U=; b=oDnENqJTodYPTNi5LQRr2ZsD4BL8A2jjJTSY6NG0a8cFL6CF+OakKn6wRbQZyFzMHBMziL 9WpVKAsCBQ7rEDxUHOlbdp5FQT4TrOnKxVCiQ31fufc07ygB7YtzWCMUqk7J1QGEQjyOF0 l7s/dZrdhOQKywKXQiEJNL//O4ejKh8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729862542; x=1761398542; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=81WNh0s1O8ZXozmBExAYQXh9JrGJ8eiJSzANEkWiXFQ=; b=eELR54QszapGiYIQx5K5vKICNWX6RNSIsQ8PbAgKIAjLA9IRZqNqsTGo +GZ6xPGXPcbAwbb3sQCX39++xuhHS2Oh8rFXU8FTJoICmamPR/x2dRbZP DiE2sHZnu4DPRJWfPLdz9P4BB4kKmenfuB0v8+ZPD2udM4SO2sUBcujOc fFF97EZXrsEZGclWhrwas8Xe2IsMZ9jH7q0YKzW6h3wL3a6oP9LTmYLSy ZJ2E3KIsbog5aDJdKuhjA+eEHcPEMm5l18ZAn3Rw0Zg/AuVe8wn75LONn kdVvKb7GOewex0wD1H4PmoO7pqGZ5U7i706ixMYQaECmUw6nqc/Xj7ALq Q==; X-CSE-ConnectionGUID: LecqJto9QFuGsql1tQwJjw== X-CSE-MsgGUID: je3hGXdSTzq2jjsZzTJ9dw== X-IronPort-AV: E=McAfee;i="6700,10204,11236"; a="40906449" X-IronPort-AV: E=Sophos;i="6.11,231,1725346800"; d="scan'208";a="40906449" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2024 06:22:21 -0700 X-CSE-ConnectionGUID: k1uxzFdQS76ExSjTuzTOog== X-CSE-MsgGUID: vGv3hZq0Svq40xrst0dsxA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,231,1725346800"; d="scan'208";a="80514115" Received: from smile.fi.intel.com ([10.237.72.154]) by fmviesa006.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2024 06:22:17 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.98) (envelope-from ) id 1t4KGc-00000006vI8-3X11; Fri, 25 Oct 2024 16:22:14 +0300 Date: Fri, 25 Oct 2024 16:22:14 +0300 From: Andy Shevchenko To: Dan Williams Cc: "Huang, Ying" , 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() Message-ID: 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <671ac2d2b7bea_10e59294f2@dwillia2-xfh.jf.intel.com.notmuch> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Rspam-User: X-Stat-Signature: bcm5x49b7b5rne1rsy1d3ytkt93eh6pu X-Rspamd-Queue-Id: 3B7D840009 X-Rspamd-Server: rspam02 X-HE-Tag: 1729862517-678255 X-HE-Meta: U2FsdGVkX19m7oH95qskcn4ZpTvuV4GMhyv66E2KwsQ37T3XCvOLlgqhD2X5CAnUv3k4D0BSyr08JSYO6BbJVgtr5ga1M7gd2vBfKXm5D+XccGWzqmAMdPbG6Z3Np/3s9VXPuTzfCWLnioyxnc3VPV13F22zOpSf6TXclUSy2w2fjqnnYTxfb5Rgy2aYnMhKrl6erLkfEo025yzY3IszIJE4Hs2wYJgsQz/Dl3jZMdarW8w7VfOHcFe/oHyM5IJcAHYSjtJIOpIrVNVJuRaFSyClErFx6brXZ+F6/rrJHCGsErE9EumPHnX4raXPwMrhtIceZHYzaYwKKrxZSSzWjww7bQIHq5mGPz6ykVnl8beOqXSXEFXznawNrQtZZmIdyEPl6AniXEZ1cjBEuBl0LxinyfHDJPXQ3Hf4zLuFYg0u0YeFVFj521ofXyPVeFFDonQi9yukko8q5oZG7SkJBq9dfv+WD9/fmZeE0/5+byJ5rEyKH6rPIbdJhXbDpbSF4w4TmE3ugkmNbgN2zlESOhZsGsxzicwhEUqPu/SblO+ow/0pK5S8RmHf5rAqpsUqE3YUkPrMsRrTTyT3nEIuJ7S89Ma10FUIS1/b/KLPdCiXXTzu6jH8S621U6KDUv0hEzX51Y9XzbFdVmKXkw02TRnaH1ndGeSxOv6GMbexWVcxgjLc0C8BPHYbY/C8KyFLpWKjFyNjbaM5O6TJeOadMaMBH0RncwenQWyGG+35WF6FAEQrPRd516xrOt5aFBenlSQFkQ8cjZGbDJp0pJbaQ2HX2MD4kr9/8vuQKz4BQDSJPTHjgewkMvZiIaNtXWCqe8318Ll2flnNsBNvHQ/nnr+V3RwOq/am/LW7S6dTZ51GK9K6D1zM6Q808lQl4+nFpxwPozY0cac6v+ZIwZYL5u+pomkpniHvMYiIn6/hRg1geO5G0ipH9FMQBo9J4MTrqVKtIMYPBraSv5UgMxx jX3efQpF hogvWJ76vDng4XT/z5O+Qi4G9780UQcCZFedyUF9gaa0rmtCbnaU7m1W8tYaY98/9S9Gou8gqMxTJhnqK9Lp3ikvwdo8bf3yrSDLsrqTZQmHBxpSunRA7Wb6OzdCjg2U4jezAWry1Q4ovY56VNbS+PCTzDhXggHXiLJp51OoiFGSDexY5naTYB62+voDQELXS+GWPTDbPJ4c8nWJTqbLln0+dwvaW3AlLaRD+Vm/gwTwnWYPnE7aoLNL4ETD5KrsomkC66wkEKjuD3v6MF0FN4WouYpd7T3X3FBfQFWKMI/5v5ZFncx37vgKjYSl2YnnxaPme 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: On Thu, Oct 24, 2024 at 02:57:38PM -0700, Dan Williams wrote: > 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: ... > > > >> > > > 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. > > Oh, due to the comment expression, good catch. > > > 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.) > > Ah, my apologies, I thought the objection was to the macro altogether. No, no, I'm supporting the idea! > > but if you want to stick with your variant some improvements can be done: > > > > #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. > > Why not: > > #define for_each_resource_XXX(_root, _p) \ > for (typeof(_root) __root = (_root), __p = _p = __root->child; \ > _p; _p = 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. If people think this would be better than the existing patterns, okay. fine. -- With Best Regards, Andy Shevchenko