Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1490994rdb; Mon, 19 Feb 2024 19:01:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUfnYV/xdVB2liWTDofAdFbyoOsovoOdBqcIsYnvuusa6dy9cXBCN02cqC/wm4fVtFUSs1racpnVZ16ibYaydjcN2pLprz0v30lc2krUQ== X-Google-Smtp-Source: AGHT+IEWl4i7sWdo8/0O9EWB4YKZrb8rZ3028uSeqeScQYyDEPgI9o+jezSPVK05c4UqFdWWYWKX X-Received: by 2002:a05:6a00:1ca3:b0:6e0:f975:e920 with SMTP id y35-20020a056a001ca300b006e0f975e920mr14492655pfw.22.1708398107899; Mon, 19 Feb 2024 19:01:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708398107; cv=pass; d=google.com; s=arc-20160816; b=aOhUIhdziyeHA/UJ1eWLbHh1rQC591MBNk9uWK7ewSsHZ8+Te9+IoxYtcJEH9n+yMx 0Iu+e/8I8O2wta4wbMv0BzY1dkY6wYosZz/EAvwODA8PQP5UMw5Nc/tmffgRuwsXgWle X8qi5u/9wjdWqkG+ilPq44jyezQmXUV5wsG4ah7GCmQclk6E92JwoLyyzCdlk890juC8 kWzI6olnZ39A6hKC3VjXP/S6nrbsvZmAnjZf/KpPN0v+XftUwsqebLT7O37NK6zI5hTU 26LnAuYfyc46VLCHb8aHB3ULdF5tNzK5VHX+RsVFN43EvWACfs15XfAcAH2RGuVHRXx6 0SeA== 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:references:cc:to :content-language:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature:message-id; bh=62UrT3cpno7hjOTET/L8V6znazoo6gcdnhOZELLpvOg=; fh=YGfo9CEGowuBJLN8Hwrg3jop2AFn1x+NyY3piAbbzY0=; b=v1fzaqePRspcZS3LD26sEsvCshl2yFieViVIYjtHmuEYSz31RCXr6efoBr1Ki/CLEs /OVOZeWHrgS3zF0Q1HMLOYUVKMitfL77oq3sjuWRxUopOfk1KsrcG06JxS/GuSbQ64zH r0iJA81RYm48df4CZsuCPYDp0ZViUHZP5Du9HKhcBhwJMXxq7v3GPmBatcWizSBfs1eb q6FpIB+03f/GygOXKwy0U1g9tC1ADcmHTap5schXNo3LN+/d1Ru+yTyhjnpbXT1cLjnb cSur5uMVDd+PMY30P1NiI3LqLVvLDeABp/YK0c9vuzsOD6UmTLntWhzS7FfbWOd/B4+s yXJw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=nsT3mVFg; 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-72237-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72237-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id t9-20020a056a00138900b006e0d76bc291si5467893pfg.111.2024.02.19.19.01.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 19:01:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72237-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=nsT3mVFg; 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-72237-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72237-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A7C9C284234 for ; Tue, 20 Feb 2024 03:00:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F193D4596C; Tue, 20 Feb 2024 03:00:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="nsT3mVFg" Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (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 C3C93433B3 for ; Tue, 20 Feb 2024 03:00:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708398043; cv=none; b=cPB82l+86NPi/hvBstcZkc3mLAA/T/oJhgpriF5wWo2qfuGdvOnN5InyiZxMHocncGGrPIQ80GnZtFDf/52e+eoUSRIwsWN15LT/f7aX98fNaojhKX2fhHQhtxCC01lZheIKjDaQaVmW3FjwIDlK4egWotnpqFwr3C0REnlNLok= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708398043; c=relaxed/simple; bh=/IeaaKyllnXBtJJ48HMH5+0WGzXBm4XIBwUop+B3gFY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=B7ZV6/aL7f0O+/ZBqaSW7a37IatQJWhsPEuir1ktnNKC5L0fyRhaDWRPBj19AJ3GqnFgqCzSIfMch8DVSi25V5VhkkPjmeG1vVNztDe1DJVsJjSRJSfetXCOaYd0yapCdF0MhYN03M6HQqIsvcb60Q5UOg+I53AAMnGj5akM0eA= 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=nsT3mVFg; arc=none smtp.client-ip=91.218.175.172 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: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708398038; 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=62UrT3cpno7hjOTET/L8V6znazoo6gcdnhOZELLpvOg=; b=nsT3mVFgyVJ0bpvazA4AAzDjc6tKuQNkUFJ3C0+h2znZUJLLt9m74fQfduAIyqsvPqC6TN sZJEicTasuFWRdnh5ChoMlRLb4rPd5XexpsclW+/i0b0uL/P0tgKJ9DxHzdoQ/I5QC8FcV 7tujUbBsrxw3+9vrGzBKScL+pL9VGgE= Date: Tue, 20 Feb 2024 11:00:30 +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: Add case 9 in vma_merge() Content-Language: en-US To: Lorenzo Stoakes Cc: akpm@linux-foundation.org, Liam.Howlett@oracle.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, vbabka@suse.cz References: <20240218085028.3294332-1-yajun.deng@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yajun Deng In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT 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 > 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. >> * 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. > Let me look into it more deeply + reply again a bit later, I mean we could > perhaps do with asserting this somehow, but I don't think it's useful to do > an early exit for something that ostensibly _shouldn't_ happen. > >> /* Does the input range span an existing VMA? (cases 5 - 8) */ >> curr = find_vma_intersection(mm, prev ? prev->vm_end : 0, end); >> >> -- >> 2.25.1 >>