Message ID | 20240218085028.3294332-1-yajun.deng@linux.dev |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-70303-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp691727dyc; Sun, 18 Feb 2024 00:51:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVcwxgEplgN7ah5GgkX95xCaZ4KoaifNwfNqgqi4DTdYA2muzQAV7JtrBWjpXV3VXggrWo1ysEyHcKWqRg3PDqUPur1dQ== X-Google-Smtp-Source: AGHT+IGG+7k41mksoILlfXGXw4uEjB/NYUYeuoJvCyKvyMAabP8lRAXrXRxMspwYfyz5Ou4gVGPp X-Received: by 2002:a05:6402:40c4:b0:563:b7b4:a30e with SMTP id z4-20020a05640240c400b00563b7b4a30emr7017485edb.3.1708246263642; Sun, 18 Feb 2024 00:51:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708246263; cv=pass; d=google.com; s=arc-20160816; b=Qt+ZNPJ6jDO42Aw8ogZxH/wgTNKLUKbWMD3kqdxDzh5JMWiQLGIqvN46GE+I1mKWy3 tSUuX7FplHnwbDejTJ/LkuEfD0KhMF4tdYIjU5/5u/0T1jkt4qMEPAjmKR02ZVsN3y9L Uj1NoJHS0KuKd7scQ9O5Gq4XSKDsZNSwQM9z/8t2M8opFuy0QFD2ChtVmqdYHGtrv/ro fHskJFgogkVBqveBKxxYIW2Tk8HoixA6SeY8m4AJkfiaj6YmkeeJVcXv+jfdgcDAaB3P A8hJNQmJ1FS72U/6FMPirw9b9TsWeKHmZf5Cywq+xgamKkikOZkCunKKDVna7OriaH+2 qBSg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=AEljPih4VKEaedgdPxkR+QTAZVEHkgRl9SR5WXdN/js=; fh=9dbTP+8qiE15iWU0P8jOF7HnY3DYTAEp9+Z7q4CVW+M=; b=kpP8IB/JOThkE23hxD9+GCvJrkLPfLL45Y48IMDiJlnVcZ5S7g3TcKIDcnkUSWS+Mp 6M/k9YdapO78GQAMUeol2OzoWm3384KMmJW3SrkfdW8qjHgzewbpKcpOItI8zKrmimHy u/inZOMSB7lhgouOTYOBd+llo18RLLwslWuIqfwikF8pBc4ndjUyQeT0SQ4ACpuUsHIh lpQVKskc14SxQ3FYV2Fz9FWaxbE+tvidiM4TdBTiaYt1cXLqxLTtae6Xc50jVYbw64fh tCg3cenqcj2VKLT/3+m90wJMgqji1SnkFWoB2GueUX2mf9mPBInkCChKjiIKtdsctzpt tCaw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Njlk1OD0; 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-70303-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70303-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id r21-20020aa7d155000000b00563cc313c70si1502733edo.214.2024.02.18.00.51.03 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 00:51:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70303-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Njlk1OD0; 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-70303-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70303-ouuuleilei=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 43AC31F21AE8 for <ouuuleilei@gmail.com>; Sun, 18 Feb 2024 08:51:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B0A2E12E4C; Sun, 18 Feb 2024 08:50:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Njlk1OD0" Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (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 E545D1078D for <linux-kernel@vger.kernel.org>; Sun, 18 Feb 2024 08:50:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708246247; cv=none; b=YAmxivRZG1IEHB8f+tJbCdhq5NAMAMJtnyUd1cKUOpaZU/ELZPzSZW2Mh8kafCshdFC8RGJpZ+PZFMtqdvjCh1paetTiXMBPXdRUsR3hid0DwV7U0dUdJk1XDBOH2Pll6or/XX1uHZxv1qUnIP/PM1t3DDf5z4k7SB6CQ/PWEzY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708246247; c=relaxed/simple; bh=da1qu/r9stegXEm7ynAOlKBK2eKOnZ0EjDNsWTT4L0I=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=nqKjWeMY8G1zpfnncisEcf56o1DkGOZnO2JSzTsK6kFnXt/NFlDHxJlbJG0QMZ1E3tSEAqpV8HDtVrXImqELxvWG4BcIMoimFajaf0oL4Zs0nxvYI0jp4dEz5+d9A975CJRAcLXWZmAvIFMhjnJh4FEUePU1yKLIA5loh21ejZ4= 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=Njlk1OD0; arc=none smtp.client-ip=91.218.175.170 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 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708246243; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=AEljPih4VKEaedgdPxkR+QTAZVEHkgRl9SR5WXdN/js=; b=Njlk1OD0qYqxPkPOtxILtH6gC5FBCH55YfGbAwkVLzJv8DOR3Afi5Gl7doigiVCmVeWQ3i N92VXe+rl6TPn+I812AtuNGuFjL7llLIT/VEShOm7xQflwemEO3qeOwjGLdYTZV+AvmslC uYlKLV/sbWIRfdvhSWn6dX2snC8m69c= From: Yajun Deng <yajun.deng@linux.dev> To: akpm@linux-foundation.org Cc: Liam.Howlett@Oracle.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yajun Deng <yajun.deng@linux.dev> Subject: [PATCH] mm/mmap: Add case 9 in vma_merge() Date: Sun, 18 Feb 2024 16:50:28 +0800 Message-Id: <20240218085028.3294332-1-yajun.deng@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791226034009066690 X-GMAIL-MSGID: 1791226034009066690 |
Series |
mm/mmap: Add case 9 in vma_merge()
|
|
Commit Message
Yajun Deng
Feb. 18, 2024, 8:50 a.m. UTC
If the prev vma exists and the end is less than the end of prev, we
can return NULL immediately. This reduces unnecessary operations.
Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
---
mm/mmap.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Comments
* Yajun Deng <yajun.deng@linux.dev> [240219 22:00]: > > On 2024/2/19 07:03, Lorenzo Stoakes wrote: > > On Sun, Feb 18, 2024 at 04:50:28PM +0800, Yajun Deng wrote: > > > If the prev vma exists and the end is less than the end of prev, we > > > can return NULL immediately. This reduces unnecessary operations. > > > > > > Signed-off-by: Yajun Deng <yajun.deng@linux.dev> > > Adding Vlastimil, while get_maintainers.pl might not show it very clearly, > > myself, Vlastimil and Liam often work with vma_merge() so it's handy to cc > > us on these if you can! > Okay. > > > --- > > > mm/mmap.c | 5 ++++- > > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > > > diff --git a/mm/mmap.c b/mm/mmap.c > > > index 8f176027583c..b738849321c0 100644 > > > --- a/mm/mmap.c > > > +++ b/mm/mmap.c > > > @@ -827,7 +827,7 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags, > > > * > > > * **** **** **** > > > * PPPPPPNNNNNN PPPPPPNNNNNN PPPPPPCCCCCC > > > - * cannot merge might become might become > > > + * cannot merge 9 might become might become > > While I welcome your interest here :) I am not a fan of the 'case' approach > > to this function as-is and plan to heavily refactor this when I get a chance. > > > > But at any rate, an early-exit situation is not a merge case, merge cases > > describe cases where we _can_ merge, so we can drop this case 9 stuff (this > > is not your fault, it's understandable why you would label this, this > > function is just generally unclear). > > Yes, it's not a merge case. I label this to make it easier to understand. But it isn't. It's not a case at all, it's a failure to merge. > > > > * PPNNNNNNNNNN PPPPPPPPPPCC > > > * mmap, brk or case 4 below case 5 below > > > * mremap move: > > > @@ -890,6 +890,9 @@ static struct vm_area_struct > > > if (vm_flags & VM_SPECIAL) > > > return NULL; > > > > > > + if (prev && end < prev->vm_end) /* case 9 */ > > > + return NULL; > > > + > > I need to get back into vma_merge() head space, but I don't actually think > > a caller that's behaving correctly should ever do this. I know the ASCII > > diagram above lists it as a thing that can happen, but I think we > > implicitly avoid this from the way we invoke callers. Either prev == vma as > > per vma_merge_extend(), or the loops that invoke vma_merge_new_vma() > > wouldn't permit this to occur. > No, it will actually happen. That's why I submitted this patch. Can you elaborate on where it happens? I mean, you seem to have already looked into it but haven't shared what you found of where it reduces the unnecessary operations. Such a detail should also be added to the commit log so that, when the call sites change, this check could be dropped - or be seen as necessary.
diff --git a/mm/mmap.c b/mm/mmap.c index 8f176027583c..b738849321c0 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -827,7 +827,7 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags, * * **** **** **** * PPPPPPNNNNNN PPPPPPNNNNNN PPPPPPCCCCCC - * cannot merge might become might become + * cannot merge 9 might become might become * PPNNNNNNNNNN PPPPPPPPPPCC * mmap, brk or case 4 below case 5 below * mremap move: @@ -890,6 +890,9 @@ static struct vm_area_struct if (vm_flags & VM_SPECIAL) return NULL; + if (prev && end < prev->vm_end) /* case 9 */ + return NULL; + /* Does the input range span an existing VMA? (cases 5 - 8) */ curr = find_vma_intersection(mm, prev ? prev->vm_end : 0, end);