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 12408D0D78F for ; Fri, 11 Oct 2024 13:24:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 929206B00A7; Fri, 11 Oct 2024 09:24:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D8D66B00A9; Fri, 11 Oct 2024 09:24:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A0366B00AA; Fri, 11 Oct 2024 09:24:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5D0256B00A7 for ; Fri, 11 Oct 2024 09:24:49 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id F2BDF41078 for ; Fri, 11 Oct 2024 13:24:45 +0000 (UTC) X-FDA: 82661391414.03.3083DB5 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) by imf15.hostedemail.com (Postfix) with ESMTP id A0699A000D for ; Fri, 11 Oct 2024 13:24:43 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=YBFvuGBC; spf=pass (imf15.hostedemail.com: domain of ying.huang@intel.com designates 192.198.163.19 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=1728652903; 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=Sh6npOE+hctNOwt5bLCtUaPzauyQQ9mQ26SWtQbOO9c=; b=77rrfCoinLsD+GLTgtNep9Fo+PJP+Sb2s7LD/foxC52wxlmqdyHj8hR0tHWQP3g3E4fcqF xOYPUSxQZDhtu9Oa4bid1aphWS+0SgJIk31mqiRaFiHetqwzm0XamwQx16fDfV6dJB9Kep aZK6U7KZrwdw2rx8G1ekNYylnsITyUo= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=YBFvuGBC; spf=pass (imf15.hostedemail.com: domain of ying.huang@intel.com designates 192.198.163.19 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=1728652903; a=rsa-sha256; cv=none; b=aOI8I4nB53832zMMJpKSVSZPnlcG5+agOByBLkeNtRNaCcjbV0nKMy5zODoaZOJpEJbxU+ fjFjbwAzbI/QgyjV2Gxg3wjhUDdquhZSbAM6DFZacWlJ1y9Y1sTpPDiEH2dA5q8kotcx1r Oy1j/KfGrTXZnr4SCIqGkzFoB0lk+dk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1728653086; x=1760189086; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=iIufuyOteBXsvMYuxWsNVz1UkSne8TnyU6hpEqh44yI=; b=YBFvuGBCB1zmX1UEEcMwEsnMSOqqV28qPzwYCMAyb0Nv6q25FU/ObfD8 N4SvU7NR0x3vVkyFwUtIi6NpPeZn3l/CDuA83KFISYvQU4bMIboTOepjK NpNxly+G9ufPc9X9vkMjApweBzqOBto3xaDj0yROKeN0wW5f/hEmefZpE 0j//lUZOuD1KmtE0Ygb/ocJ3XnYh3a9+wVrVOFO2gnYlBED/wPnlRNgbi 5tgLtiiBfIge/bEAngvRL7oXeovftal9hg/C4W6kizDiN/MR6ABb/XqEN 68N6XZxQN1TJmPHjHZDRuFiT8/ISSc0SOcJ6f70/UkYsysCv8FLJjQYhn Q==; X-CSE-ConnectionGUID: +POc0dXTQRW1FSF292IZCw== X-CSE-MsgGUID: irN3utVBSW6GS0uQSaWAaQ== X-IronPort-AV: E=McAfee;i="6700,10204,11221"; a="27523129" X-IronPort-AV: E=Sophos;i="6.11,196,1725346800"; d="scan'208";a="27523129" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2024 06:24:43 -0700 X-CSE-ConnectionGUID: 9HFN1MVJREGnXwoFJGKiNg== X-CSE-MsgGUID: lLrqMJBrQo+K8cdGK7CVbw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,196,1725346800"; d="scan'208";a="107640626" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2024 06:24:38 -0700 From: "Huang, Ying" To: David Hildenbrand Cc: Andy Shevchenko , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-cxl@vger.kernel.org, Dan Williams , 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: <12c0a19e-784d-4ac0-8d3c-d5242bcd3723@redhat.com> (David Hildenbrand's message of "Fri, 11 Oct 2024 13:30:15 +0200") References: <20241010065558.1347018-1-ying.huang@intel.com> <87set3a1nm.fsf@yhuang6-desk2.ccr.corp.intel.com> <12c0a19e-784d-4ac0-8d3c-d5242bcd3723@redhat.com> Date: Fri, 11 Oct 2024 21:21:05 +0800 Message-ID: <87msja93ni.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: A0699A000D X-Stat-Signature: 1s7x9bi1jxd656yut4q35bqtwdoaas7z X-Rspam-User: X-HE-Tag: 1728653083-287424 X-HE-Meta: U2FsdGVkX1/9S7Q3GqJkorwginALWPm8LI3UYprzxl9fEGEJzEqrnomHBI0Dd5z2+70W6RIvdtt4x6jKAez2vtuDGOjkdB/IommXndCEQR6TP060Fgntn2lVf8oBqstmo2i6amO5aBeKOCkbN1D0fScf6R74QTyO+UBWbTYrk9/X6dNrGRXX4nj8kr4fUUsu+NOqLQZtMzF5A9FtU/CceplIBwkaZJNaqwMW0yS/01VEIAcuwdWY5nsOGJtG75ndiL4fP/86MEZWgyG7p6xFN0z6jesHEFObdgPNcVUSx3t9HNyO4ucOI/NCGWCBcGZYrnt+HjO7cufvIJ1ahKFMP22nh5+laFySLYAktH76l4Zfx01fOp+yZW73rtW1E6A5haoshoUIFQ6c8fIyOSuFNx8Y3f19lP3J9vM0pGz/KjHJd/9T8VJjGnojXQptzf4pUlwwJLcq8ajxl0NCkKMxeoUWITeXRDyOsDvcoJ5KaW7qMGwFoPFbQgNexnRs7enTlQCozv566JUX7CQLe6iatYmhRHOph1Br6zWA/zAhYKCAfA8Ngft1aPpK696arnEYkBwKW08LmlVj4Ndtotl3dS4SF5Gn5PmXE/p8RzM82kFRzqzzvz6bLQwoVARUOMGcIUIvIlD0BAfjR3syAB5brc0m18IGcVg6h0WsBQkzT+OnkMDXLx9OOjBG21QG1U+zF1X6M+z/lfnQCvmkV1mVF9RKhn8A1dxMCFnZx+ctxQqGBA95Qy0gRXA0SYaO8Rz0PepL0lKGPwOEaOLHnrT6ojimDuh6jLcXhoF1i1raXHkUIJyqCg2YKqHYxiPeL0QUmURwMKgBL5hyO7eQWqC+G/CkSgpyvpwICTQe2RchuVpsT07/BxYbfc8926O+DLSLiu5XuD72jBVnJvSdcAVMuxChwjQ/IwzSQON5wjyfpBC+AH37qgm8JQuAt0K9byS49igqEWDSDh40vk9arx8 BM+epryR 1qKlzpd1R7JB9/Jxw5PumFo/xYEwgWcWrY6746j+JdLrkqHwUW8X9unVRV/Bs4RHaTBzHAqTxQQFiYV0988EEbTdkqYmsi2SzAGMiLHpnIW/AC61eW+HXbh8w7PACNY7YrFRBhnBWPYWh79GUUl+lTcOlvaOCw3pM4EYQe1/jAUuPwSNnHNBoS0EXLRD9ExxX/QDV0Ohqg8I4SjDVsNASdfdeBojsjDBkWBmleEFizmowqdnr2Bc3L15S2A== 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: David Hildenbrand writes: > On 11.10.24 13:19, Andy Shevchenko wrote: >> On Fri, Oct 11, 2024 at 02:15:55PM +0300, Andy Shevchenko wrote: >>> On Fri, Oct 11, 2024 at 12:51:09PM +0200, David Hildenbrand wrote: >>>> On 11.10.24 12:49, 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). >>>> >>>> Fully agreed, I didn't quite understand the concern about "evaluation" at >>>> first. >>> >>> It's a basic concept for macros and a good mine field even for the simple >>> cases. >>> >>>> If it's just reading a variable twice, it doesn't matter at all right >>>> now. >>> >>> The problem (even if it's a variable) is that the content of variable can be >>> changed when run in non-atomic context, i.e. two evaluations will give two >>> different results. Most "simple" for_each macros leave this exercise to the >>> caller. That's what I also suggest for now. >> For any context as Ying provided an example with calls, they have to >> be >> idempotent, or you definitely get two different pointers for these, which is >> bigger issue that what I described above. > > Ah, now I understood what Ying meant: if the root pointer is modified > within the loop body we'd be in trouble. Given we cannot provide a good macro implementation to traverse only the descendant tree of _root, I suggest to just keep current for_each_resource() implementation. There is only one user of the proposed new macro to traverse the descendant tree. So, I suggest to open coded the for loop instead. More comments can be added to make it clear. -- Best Regards, Huang, Ying