Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp559205rdb; Sun, 18 Feb 2024 00:50:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVYcaCWwCMdf8HCnZESCSqsE4eHgFp4wd1oUK64oNkTpznOBmhHbLnod22Z6P/1tGqGRPVE1vsWrivsEsTed1YkiY48VIbGD5z1WmcDdA== X-Google-Smtp-Source: AGHT+IHkqUhziUf9vdxF13u+QzZJvfexpfu+5IvJTI2vJxWfuZNFrYxVsjryf+ijKaTMfK73CtAK X-Received: by 2002:a05:6870:4706:b0:21e:b50c:3e90 with SMTP id b6-20020a056870470600b0021eb50c3e90mr1996129oaq.37.1708246254943; Sun, 18 Feb 2024 00:50:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708246254; cv=pass; d=google.com; s=arc-20160816; b=gbu7V5M1mC/POmrRYgs98+rizTur6HAS0/i7+wqvalVRBm68IEs9+2VxP4XYRgdPt8 QOxLObtqO42K/WQz9RspL006CYos2lrGhjZBF7/E8QKOGzHej5PfwdvKohJ6/J9uSTVV z9su3YH+5KZ653AyGCtBywdkwYr+Ej2XTZpJJYpbhHGQupnLUY9n/x7Ti62I6zCnF/N7 oQJssZixNW3JQteF4NbL56JFpMY2Yij4xZKyjkq/e6t8DoUj+ZZFe9kWVGR89EZDXjgl WEW+PDxDn2NgwIiESBBnKZH3kKhpLeUdz8jYsLDqSsrWTf/LjeVB1HUkslP2l+FAUZ6d TqCA== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70303-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 y124-20020a636482000000b005d8505c96e1si2584234pgb.423.2024.02.18.00.50.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 00:50:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70303-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=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-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70303-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 9E13928198A for ; Sun, 18 Feb 2024 08:50:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 00CF2107A0; Sun, 18 Feb 2024 08:50:49 +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 ; 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 To: akpm@linux-foundation.org Cc: Liam.Howlett@Oracle.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yajun Deng 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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 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 --- 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 * 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); -- 2.25.1