From patchwork Sun Feb 18 08:50:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yajun Deng X-Patchwork-Id: 202756 Return-Path: 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 (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 ; 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 ; 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 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791226034009066690 X-GMAIL-MSGID: 1791226034009066690 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);