Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp253048rdb; Thu, 22 Feb 2024 02:36:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXn0sgvUEaZxWY3QJAUA/sclXvc6Qde3nUDA1CRGQFGVms+ryh97U5q1ZsTX7z2GjMd6VVlKl+rNpjWsx0f6otc/zLd/mc/LLWFxqZSSw== X-Google-Smtp-Source: AGHT+IGXStKqkrx5lUzc8DsWwFeA0K2uNqa5pvmC7oIPKCHX1bITNfSOYvFLBOtD+nrapn6w4GoL X-Received: by 2002:a17:906:d85:b0:a3f:9de3:59a8 with SMTP id m5-20020a1709060d8500b00a3f9de359a8mr313817eji.1.1708598211469; Thu, 22 Feb 2024 02:36:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708598211; cv=pass; d=google.com; s=arc-20160816; b=r8T/mBpvA2RfEJJJCSshq+laudAxvkJ+8eWKkw7f1zScsPxvn1mg8ctyZKQ+w2FL48 pE6WuahOm+Vj1HbNAdYctDDXPljQV1iQbnf26kTMm0v0+wyLnPWOI5kLJDf7jCANFd/3 deHQQiTzZNsdxW50Wx3swXvlMcxteW1TSih045KEhHrwj0PpwL83FjmNhOocO6gxDRd6 da+dq6S2Ig2syDW4gBLLzsst5SNKYBugEG1U3DVvhiJ6O33uK1fyHs5nsfIu4G/qT1PA 1JSC1gsH2zdwvPu+JWf/RHsYkbAyKqGb18VJTfmn6BmOv+cuCuuENBFoKVyozo42J51D x12g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:cc:references:to :content-language:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature:message-id; bh=+7spRFbh2J4ww37DpVZh+dxZFQJF6WKI0aJByND9M2M=; fh=w7qQBzbunk1AYSxYoj8p+PgMOj9CpOBkn0uWx6vrs7A=; b=ggJ//BXdTULaWqqy4tmJ3VbB/2oNF3vv6dN3SOiH41pQpxfkz2f+cZd4rJCvTyxDpe p4goBpTipFm+6rNlGTMOW8O/wYpuTpoD4I7eV4lMMGp/RnbpDJtrYNW+rZDtvY4vl1ag eiFhMPL3HsNzFcnaTYfuXCSgQAWa/Lqb4NrzYG6wdL21VF7J6NM75/pdmaguh/lPcmqu kaI9lv+0BVaWTPx2l2pc88h5rsGk+S9hASIkTF1fMEnFc0z8bqEDJosfqnABnW0ehlZv p52FuIssi+ajNPWYFNs+mpn2HyenYi6AXRmMZPsxAwzGS1fsPp6OpZdC11vf0g/6yxO8 fISQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=uBIsCIa1; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-76323-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76323-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id qu22-20020a170907111600b00a3f4c3f0d19si1111710ejb.607.2024.02.22.02.36.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 02:36:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76323-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=uBIsCIa1; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-76323-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76323-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 81C711F27320 for ; Thu, 22 Feb 2024 10:26:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 80A743F8F0; Thu, 22 Feb 2024 10:26:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="uBIsCIa1" Received: from out-184.mta1.migadu.com (out-184.mta1.migadu.com [95.215.58.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F4013E493 for ; Thu, 22 Feb 2024 10:26:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.184 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708597591; cv=none; b=I6rMfzc9+hagxvOJCx/5cwVl4NG9+qDZpj5kpMimxyE1pPvSSjG+pzQGAdsk8PLAS8DMs7FqBl1BOMmqxMtOl2SyDyHDE1XNs3keG2jjRdcey99W242UtMABUQxnOi2e9O33z5ge8g3u2QMIPSw8c7nlFcuvwmcK50a0XxsneVQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708597591; c=relaxed/simple; bh=UEj9sHztDU8qj7jBQBTqaSJ97zq+jU8sjx+z8b97n9w=; h=Message-ID:Date:MIME-Version:Subject:To:References:Cc:From: In-Reply-To:Content-Type; b=SpFM/iHIO+CO+w+wteWKQb6VQr5M7UXx+W+qkuGQQWd23UBRTAQlo4aNnvA24bO6sSK0XloG/+tERU91QlM8y77ZriM6RxxJmV0Jp/rrMHIO2hb+8WFwywU/uwGiV0cndBwX+CV2zEvy5gmYCpv5aQZO8zZ2NBphtW8pGbX6eJQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=uBIsCIa1; arc=none smtp.client-ip=95.215.58.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Message-ID: <7229eb6e-bf3e-fa97-6709-6c92bc72443b@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708597586; h=from:from: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; bh=+7spRFbh2J4ww37DpVZh+dxZFQJF6WKI0aJByND9M2M=; b=uBIsCIa13A/Fs89WWjKMTg//DsS1q1bl0lRGY8fIonQKfUYADQPrsYRucSSGgCr1k7komW ABm8yceiEl3msvXaPyDirssN/rn0BImI/8NeKLNmo6VaDzgB3DKaQIiUomdRMsc8c5yg09 dEHQK2kIhgLQCC+P3JZ/XAFLRCgO/FA= Date: Thu, 22 Feb 2024 18:26:18 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH] mm/mmap: remove the mm parameter in vma_complete() Content-Language: en-US To: "Liam R. Howlett" References: <20240129075305.3512138-1-yajun.deng@linux.dev> <20240129150417.3m6jyj3ftdh6ka7x@revolver> Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, vbabka@suse.cz, lstoakes@gmail.com X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yajun Deng In-Reply-To: <20240129150417.3m6jyj3ftdh6ka7x@revolver> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 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. >> 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 >> >>