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 66D47C47DD9 for ; Fri, 23 Feb 2024 02:36:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF3926B00C7; Thu, 22 Feb 2024 21:36:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CA39C6B00C8; Thu, 22 Feb 2024 21:36:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B92766B00CB; Thu, 22 Feb 2024 21:36:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A96466B00C7 for ; Thu, 22 Feb 2024 21:36:32 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4B007A0579 for ; Fri, 23 Feb 2024 02:36:31 +0000 (UTC) X-FDA: 81821504982.28.B63F66F Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) by imf12.hostedemail.com (Postfix) with ESMTP id 5029540009 for ; Fri, 23 Feb 2024 02:36:29 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=PZgfnbj1; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf12.hostedemail.com: domain of yajun.deng@linux.dev designates 91.218.175.178 as permitted sender) smtp.mailfrom=yajun.deng@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708655789; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=xHqdu3spwmkF6oWZOtRqdMOZaCL8AWKGggIeQiYpA+s=; b=YiGsq5f4kTWTuuP7YbLAtDLfimqSfd/1LYvzF3vAAoeAnCBRbomqFqUHmQ213MlcMTxVC6 f9X/S3xe2NgqxYU9WAYw/RzIsnMHSi/h8a4BunEG9kVZRU9wns020cDjVLneAsQ06r2It/ 8CylSId4GDl9MEFz3JoxdY9+2lml3xA= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=PZgfnbj1; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf12.hostedemail.com: domain of yajun.deng@linux.dev designates 91.218.175.178 as permitted sender) smtp.mailfrom=yajun.deng@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708655789; a=rsa-sha256; cv=none; b=jFpJFEX5k+R80xvH1SNtCJWPQ97qnjvy2oRMwgwhIoSDKjG+UObqDwKvlbKYdb+VT5BjHp OttS4v7e0HmH1IpKq4prvR+W4MGrVMV8wgdIi2IygdHhLL6G8pB9hsZyjMgpcwZklejtXf 2FhHGEX0a3BTp+JsaFl0MSjEawiqp0c= Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708655787; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xHqdu3spwmkF6oWZOtRqdMOZaCL8AWKGggIeQiYpA+s=; b=PZgfnbj1wz3UlFSGeyz9yQxBmfYAVpF35gls8d+bGNxqRGt19k39nJXtYyb5A4YzkPGS4Q 9A6Ly+iB1q0ebPEw0mzGmN33PDSPFbOkJEiv97taml+aJwrKPoqCmp0JI7TSnGTJ3KRXr6 C1u7tNmVUE8+YJ/0OV5WXzhKg54qG5w= Date: Fri, 23 Feb 2024 10:36:09 +0800 MIME-Version: 1.0 Subject: Re: [PATCH] mm/mmap: remove the mm parameter in vma_complete() Content-Language: en-US To: "Liam R. Howlett" , akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, vbabka@suse.cz, lstoakes@gmail.com References: <20240129075305.3512138-1-yajun.deng@linux.dev> <20240129150417.3m6jyj3ftdh6ka7x@revolver> <7229eb6e-bf3e-fa97-6709-6c92bc72443b@linux.dev> <20240222162222.d7imwzuqpreilr6u@revolver> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yajun Deng In-Reply-To: <20240222162222.d7imwzuqpreilr6u@revolver> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 5029540009 X-Stat-Signature: ezoswe1cdfkix8mg1t5cfi3o65rz3ood X-HE-Tag: 1708655789-540666 X-HE-Meta: U2FsdGVkX194dS+vhY9LSkQZPmYi8ZqxSdGIbGzNn1EA00mSr4IlAs2SAvyeCeHmcUkNet5LqxCYNPv9M5V1Vp5bQDqi6RNd2eoAHgLHG080/y3XbNsquN2piWdUI1PalLWLA4j0QZY/9Cxmnl+8oxvkZJuOvJjvpNq3FLL/dC78jsfW99bJTF/zyo4h+B95D4ZyoiuWXaO3qQbsPbYWqRVUoaqBtU3IuCrHSSiHoG6lKb6VtFSHgfvP6nf8i6qW2jB3z34GXTl3cvPGXUM/GryXnxQRg32gmfyEz/gN7XIuJvwcKBPOBcLjZpQ0c87YFajKVTgKxSb1IYqyN8P5ltceH/wf0pNrApaUIlGGfdoxhCgRWAV1bezKxPJC6W/0CIgm7NrRyo6vZYAlQz0EhLFI4gwFbOFudICGEryIungkNwYFiJicOuMoEyUIZ6JBRS9ETtnxCbSVSskleyt4wJ4R+1HpliWWQjO++HUhFHf23NX+C2s5Qg/HseW/Lg275yxu4DG4pSDr/NEjVGjGR8+Ena3JM0UvBMb4ZFwujqdEL7t22nUy2vAH7FdknSCT09tYrN18e/0sR0K8PvV1IIT3Z9JQd/gJDf4cKPRV7YlP7asZVtgvnyTrjBqwbXuAcJiXjiZC5RzcC6oHxJRv4InsVrrJBrNRIiX1EleW7viejKnXcB1vxF0WdgPEtDuO+33R6ZB2EnpGoKSqEzljAaVNabZruYmZiexHZ16EgjjppnxmslE0WPeVBHUb2WvzFfNX9eiZv+sNZartm29haGgyOF7vGPfC/r1MYE8wxgwfMn9Zxv+TSzj1GrOYONNFIT8AKK6+/Y844Z2JwSvIyBIez2f/5cI02nBDo/d34HBKbLO+yGZhpQqzFMaPXN9kApimG5006tZjB/RR9vWMq/dI1glzT/W7S5w21z7v7NBL+DNuCMiINz7GdZwxfdt/PoJN+lEcVYViOTnwiDl EyTIxTJV wBqhdg090JU4FH7K6rANgK6XKtNIufyzFSHLhVEO6YqPMwEOHWBX8CN6VKEFuCV8sFysMnT3khXSjjG1h6e17bfUrcuWbGqkN44dd60F4UDEdhJ0meFMRs8gnG2OBOyQfb21tEoJgbburBTgLs5WPyD9xLCROFyNCD7EE 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 2024/2/23 00:22, Liam R. Howlett wrote: > * Yajun Deng [240222 05:26]: >> Adding Vlastimil and Lorenzo to discuss this patch. >> >> >> On 2024/1/29 23:04, Liam R. Howlett wrote: >>> * Yajun Deng [240129 02:53]: >>>> There are vma_merge() and do_brk_flags() pass mm to vma_complete(), others >>>> would pass the vma->vm_mm. The following explains that the mm is the >>>> vma->vm_mm in vma_merge() and do_brk_flags(). >>>> >>>> All vma will point to the same mm struct if the vma_merge() is successful. >>>> So the mm and the vma->mm are the same. >>> Absolutely, they must be the same. I don't think vma_merge() checks >>> this, but it is true. >>> >>>> vm_brk_flags() and brk syscall will initialize vmi with current->mm, >>>> so the vma->vm_mm and the current->mm are the same if vma exists in >>>> do_brk_flags(). >>>> >>>> Remove the mm parameter in vma_complete() and get mm from the vma in vp. >>> You have added a dereference to the two paths that don't need it to >>> reduce the argument list from 3 to 2. It's the same number of lines as >>> well. vma_shrink() is only used on process creation, but brk is more >>> common. Note that this function is marked as inline. >>> >>> I'm not sure this change is worth making. >> If we can make sure the mm isĀ  vma->vm_mm, I don't think we need to pass the >> mm. >> >> If we can't make sure that, this change is not worth it. > We can be quite confident the mm struct is the same. The point is that > you are causing more instructions for zero gain. There isn't a lot of > arguments and this is marked inline. For most of the cases, we are > already causing 1/2 the dereferences you are moving - except > brk_flags(), which already has the pointer available. But instead of > using the pointer already in a register, you are adding two new > dereferences inside an inline function. > > This is like writing: > > struct mm_struct *mm = current->mm; > struct vm_area_stuuct *vma = find_vma(mm, 0); > > ... > > use_the_mm(vma->vm_mm); > > .. only it's worse than that because the compiler will replace > use_the_mm() with the actual code in use_the_mm(), so we have > effectively told the compiler to set another register up by > dereferencing twice instead of using the value already available. > > It's a change for the sake of changing. > > You are not reducing the code size, you are not increasing the > readability. You are adding two dereferences to brk() and one to all > other callers. Why do this change? Thank you for your explanation. >>>> Signed-off-by: Yajun Deng >>>> --- >>>> mm/mmap.c | 16 ++++++++-------- >>>> 1 file changed, 8 insertions(+), 8 deletions(-) >>>> >>>> diff --git a/mm/mmap.c b/mm/mmap.c >>>> index e97b9144c61a..9b968d1edf55 100644 >>>> --- a/mm/mmap.c >>>> +++ b/mm/mmap.c >>>> @@ -509,11 +509,11 @@ static inline void vma_prepare(struct vma_prepare *vp) >>>> * >>>> * @vp: The vma_prepare struct >>>> * @vmi: The vma iterator >>>> - * @mm: The mm_struct >>>> */ >>>> -static inline void vma_complete(struct vma_prepare *vp, >>>> - struct vma_iterator *vmi, struct mm_struct *mm) >>>> +static inline void vma_complete(struct vma_prepare *vp, struct vma_iterator *vmi) >>>> { >>>> + struct mm_struct *mm = vp->vma->vm_mm; >>>> + >>>> if (vp->file) { >>>> if (vp->adj_next) >>>> vma_interval_tree_insert(vp->adj_next, >>>> @@ -666,7 +666,7 @@ int vma_expand(struct vma_iterator *vmi, struct vm_area_struct *vma, >>>> vma_set_range(vma, start, end, pgoff); >>>> vma_iter_store(vmi, vma); >>>> - vma_complete(&vp, vmi, vma->vm_mm); >>>> + vma_complete(&vp, vmi); >>>> return 0; >>>> nomem: >>>> @@ -707,7 +707,7 @@ int vma_shrink(struct vma_iterator *vmi, struct vm_area_struct *vma, >>>> vma_iter_clear(vmi); >>>> vma_set_range(vma, start, end, pgoff); >>>> - vma_complete(&vp, vmi, vma->vm_mm); >>>> + vma_complete(&vp, vmi); >>>> return 0; >>>> } >>>> @@ -1030,7 +1030,7 @@ static struct vm_area_struct >>>> } >>>> } >>>> - vma_complete(&vp, vmi, mm); >>>> + vma_complete(&vp, vmi); >>>> khugepaged_enter_vma(res, vm_flags); >>>> return res; >>>> @@ -2377,7 +2377,7 @@ static int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, >>>> } >>>> /* vma_complete stores the new vma */ >>>> - vma_complete(&vp, vmi, vma->vm_mm); >>>> + vma_complete(&vp, vmi); >>>> /* Success. */ >>>> if (new_below) >>>> @@ -3145,7 +3145,7 @@ static int do_brk_flags(struct vma_iterator *vmi, struct vm_area_struct *vma, >>>> vm_flags_set(vma, VM_SOFTDIRTY); >>>> vma_iter_store(vmi, vma); >>>> - vma_complete(&vp, vmi, mm); >>>> + vma_complete(&vp, vmi); >>>> khugepaged_enter_vma(vma, flags); >>>> goto out; >>>> } >>>> -- >>>> 2.25.1 >>>> >>>>