From patchwork Sat Mar 18 11:13:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13179747 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 138C0C76196 for ; Sat, 18 Mar 2023 11:15:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B1DA8280002; Sat, 18 Mar 2023 07:15:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ACD0B280001; Sat, 18 Mar 2023 07:15:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D130280002; Sat, 18 Mar 2023 07:15:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 7F293280001 for ; Sat, 18 Mar 2023 07:15:36 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5A9C112053F for ; Sat, 18 Mar 2023 11:15:36 +0000 (UTC) X-FDA: 80581763472.27.D4D01F6 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by imf14.hostedemail.com (Postfix) with ESMTP id 7FEA4100012 for ; Sat, 18 Mar 2023 11:15:34 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=TNBn6zG1; spf=pass (imf14.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.53 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679138134; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zGH+7XD9CZf7riiQs7tokzcrN5LQH5VfpFAGRw9yBzQ=; b=GNDmu4ByzloqtyUJGJo6ZAEeJp6zjQXdopDzZQGZeTxEwBJkS4afTSXbANSk9Z7es/3mc+ 4L+BFo+BBB4Z/r7bRyeTwKF9ltlDz3PxRwELirsYTli8YsDtYQ9/ZTviziWYSB/YCnODnZ VdOpaqi774QNH1GRUe1zMfH1EbiERQU= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=TNBn6zG1; spf=pass (imf14.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.53 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679138134; a=rsa-sha256; cv=none; b=miBL/+3Jft9efvNx1UM5UPqSCOdSluodpnl/1Wem0haPK73EOIbaX2a8KSX99mf4KQsmdO 06wge3iLWK4B4Q8n1XAur1nC2VEmoHJLttD/O5SCzoHjwRTD63GsLvl0tbDwozLjjHNodO mS0fAYkI6KLHgFQLompp07SZ18AiNLU= Received: by mail-wm1-f53.google.com with SMTP id l15-20020a05600c4f0f00b003ed58a9a15eso4764486wmq.5 for ; Sat, 18 Mar 2023 04:15:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679138133; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zGH+7XD9CZf7riiQs7tokzcrN5LQH5VfpFAGRw9yBzQ=; b=TNBn6zG1hdBUOTzqqLTQiTtEN0JRMCO/ZKWzRMNFgj98uLt+q4k8ghjew+1pvNNue0 WwuBPWByIjGO6uz6yW0hfU/p/UBnFVzOKoUSjnAJjKSqgICoaJmKntHF+CK5laaQom3b 1s/U5zrnWwkkTUXUeSuRY3AQEcLUewaUMMA+mlEsxedaVkkwOotRV04GT9Lo+B5HTSnS WEHauh80WAubtJWn7pTBHLj2ioyNwyVm3yLeSNxz7YYMVYY3uIoL9rZGI8ai495/0CVU jNKdhGVgyJ0bjR8u3rwu4aVVaVpzSZg9TPbaRJ2RZbZ2iRsUekHAW24kpm90Ip/zFoXW ubfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679138133; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zGH+7XD9CZf7riiQs7tokzcrN5LQH5VfpFAGRw9yBzQ=; b=3RnA9xZOaE5XP/esO+mv09BIorQa/9hBmYYTUfCQe6cS+Oyo6XW7AmLkOguDqd/qWW sVgo+xmiB19IC957XnzYoixCQVZ8ukcHredzb8iFZ4uwJmLnmiKLxqjjC/MLR8+rhyK1 lQIa93Nluz73BzbAB0k3npsmkNEah3uRRXU5h6TxJaeg5hHEuk43VIJgTrlR/H6i0Us0 epBCEi++omr88sPxOiBBV0EBAomVkA6nCHwXN8JjBKtfjEUkaVp3awql5X9uVOzrOLXm E14iUECo0iguK0hkXleMsSMdqqK08IAi8A8OvKpooXQUG4MQPhkLBRkyfxJgLdiIwJOH U3ZA== X-Gm-Message-State: AO0yUKUV9GY8Q9VJpZlwO25c15F64S+++x3xAZr/L/ASChqPpNTmx5IO gNolHSJNLet9lnobjx8Md4N3TOv6ACQ= X-Google-Smtp-Source: AK7set8EFNhOT1+VWTHfriGxmv6FTPoHw/mhcihpxX6H7XQbmsH1Imd3c4T2RUMnWGoOhIvwMJ06xw== X-Received: by 2002:a1c:ed16:0:b0:3ed:a45d:aee9 with SMTP id l22-20020a1ced16000000b003eda45daee9mr1705649wmh.39.1679138132644; Sat, 18 Mar 2023 04:15:32 -0700 (PDT) Received: from lucifer.home (host86-146-209-214.range86-146.btcentralplus.com. [86.146.209.214]) by smtp.googlemail.com with ESMTPSA id n23-20020a1c7217000000b003eb68bb61c8sm4849965wmc.3.2023.03.18.04.15.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 04:15:31 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: David Hildenbrand , Matthew Wilcox , Vlastimil Babka , "Liam R . Howlett" , maple-tree@lists.infradead.org, Lorenzo Stoakes Subject: [PATCH 4/4] mm/mmap/vma_merge: be explicit about the non-mergeable case Date: Sat, 18 Mar 2023 11:13:21 +0000 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 7FEA4100012 X-Rspam-User: X-Stat-Signature: n6f495cz3rq5brnnzjgm1bx63dccuj1c X-HE-Tag: 1679138134-525763 X-HE-Meta: U2FsdGVkX1/BFGMSF/KNdVyp/J2DG7RMyc4FQtdqNe54bxQDNnPZxW0A/5s3q61j4kk9TMUjm71nuGfhomrmtE0Zr9W6VAmjwhgedIxw/wJSI4Op0IQfU53J4uMjSWTgAHr9x0idQjqRZAPUBHEh41E9zfp1wIp8Vu6cIxAzF6uZxp6Ta8+nUpYanSJsontKGlPAY9xjibSaZsV2YIfnMFa8PZJkhi9zvfVzR0HWSC7MAPuaXyyJT3npVws7emWd8cfcaCzzyZqJP7PdMNZdRTBvtM3Q0pLbzuSe1F86CbNW1y3HDDfQwgcYZ3kOuQxxaNMEOGbcKnKFiuX6GJZdJMDqbLKaptVzq4kEFYTo6yk9kGpuw5Zu2jRG5Dtu8Zv7o4zNdTf19IZizynakUKkjpI+XvcCY9vwm/oqFWD4ycDy+QG0iFVf6H5NNDO6ckbk0ovoBuVbzKEovFW67owl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.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Rather than setting err = -1 and only resetting if we hit merge cases, explicitly check the non-mergeable case to make it abundantly clear that we only proceed with the rest if something is mergeable, default err to 0 and only update if an error might occur. Additionally set merge_next directly as there is no need for an if() {} statement assigning a boolean. This has no functional impact. Signed-off-by: Lorenzo Stoakes --- mm/mmap.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index e60c637f4e49..2ac43b2b9a00 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -913,7 +913,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, pgoff_t vma_pgoff; struct vm_area_struct *curr, *next, *res; struct vm_area_struct *vma, *adjust, *remove, *remove2; - int err = -1; + int err = 0; bool merge_prev = false; bool merge_next = false; bool vma_expanded = false; @@ -1002,12 +1002,15 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, } /* Can we merge the successor? */ - if (next && mpol_equal(policy, vma_policy(next)) && - can_vma_merge_before(next, vm_flags, - anon_vma, file, pgoff+pglen, - vm_userfaultfd_ctx, anon_name)) { - merge_next = true; - } + merge_next = next && + mpol_equal(policy, vma_policy(next)) && + can_vma_merge_before(next, vm_flags, + anon_vma, file, pgoff+pglen, + vm_userfaultfd_ctx, anon_name); + + /* Not mergeable. */ + if (!merge_prev && !merge_next) + return NULL; remove = remove2 = adjust = NULL; /* Can we merge both the predecessor and the successor? */ @@ -1023,7 +1026,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, err = dup_anon_vma(prev, curr); } } else if (merge_prev) { - err = 0; /* case 2 */ + /* case 2 */ if (curr) { err = dup_anon_vma(prev, curr); if (end == curr->vm_end) { /* case 7 */ @@ -1033,7 +1036,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, adj_start = (end - curr->vm_start); } } - } else if (merge_next) { + } else { /* merge_next */ res = next; if (prev && addr < prev->vm_end) { /* case 4 */ vma_end = addr; @@ -1049,7 +1052,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, vma_start = addr; vma_end = next->vm_end; vma_pgoff = next->vm_pgoff; - err = 0; + if (curr) { /* case 8 */ vma_pgoff = curr->vm_pgoff; remove = curr; @@ -1058,7 +1061,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, } } - /* Cannot merge or error in anon_vma clone */ + /* Error in anon_vma clone. */ if (err) return NULL;