From mboxrd@z Thu Jan 1 00:00:00 1970 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 EED88C761A6 for ; Wed, 22 Mar 2023 07:13:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8AF236B0078; Wed, 22 Mar 2023 03:13:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 860076B007B; Wed, 22 Mar 2023 03:13:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70005900002; Wed, 22 Mar 2023 03:13:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 643816B0078 for ; Wed, 22 Mar 2023 03:13:14 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 25E9980385 for ; Wed, 22 Mar 2023 07:13:14 +0000 (UTC) X-FDA: 80595667908.29.D356520 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by imf25.hostedemail.com (Postfix) with ESMTP id 4A758A0002 for ; Wed, 22 Mar 2023 07:13:11 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=iztqSobc; spf=pass (imf25.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.41 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=1679469191; 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=TzbyGhvLZi9NdvR9qLzRGr9CkBr431wgVaStXlIqo9A=; b=O/uS89d59m6BkejqaZFznBcWrosqtLvL/yVvhblYLem6GbpgmmsthaLpiN8fAHEKOUwOSX jmtr5kHbiu0ffPDj6ck6pb+kKt2rr7P+Bq2OjKmws2OUV/V3p6WW5ImT7cbDadyKlvlBHD 9vEplxWMep6b0cbvWMDlmNcqVKD2kDg= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=iztqSobc; spf=pass (imf25.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.41 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=1679469191; a=rsa-sha256; cv=none; b=AuC7dPgAYLp7v7H1HHs4QMXEksSozq11SI6iF50SA+j0kzftyDZ8tgZqmwglewbd9QkeS2 0tmi/YTsU8mdFtouNHX71cqTNeh5TR6k0Rpk/bHVrehV3I4RZ7m5puo6Um6n4iQ0VeTI4H UTsbHbo6hqgQYv7vZUcd6ScbiHT1CGk= Received: by mail-wm1-f41.google.com with SMTP id bg16-20020a05600c3c9000b003eb34e21bdfso12389344wmb.0 for ; Wed, 22 Mar 2023 00:13:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679469189; 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=TzbyGhvLZi9NdvR9qLzRGr9CkBr431wgVaStXlIqo9A=; b=iztqSobcddwbnuUtBHhFE9WjYOulPGHfY2DbngPzSP8ELao2sG7kXGWD4oTEaMVGxw J3TEIypuIQkDidGDCmKMHo7mLEqz9eIf97TUEkPbzrGSd9ZtZJ7PBbjFgJ4/gpXDv1hR 85GHppxR57d+bBqJQRAmvms4vGqrLeUCgckhv9sW/s6r/NIh7QCQsrrGCzCiVptZz1tS bcJUGH/TbdL+vYLJm+MzaG3uYb3pJs6MgJpIGhMoZjw+bxvJyzEiZelTUYNjYehNq1oJ 5WIv/1H67N7bucq4y6KjIlyNRlnyp8E8pZYbHs0rNWbn1McyKBCkB88UyGnoWuKRe1og Ac5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679469189; 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=TzbyGhvLZi9NdvR9qLzRGr9CkBr431wgVaStXlIqo9A=; b=4ZpbhxRJiCPbK3PosJhnACs9rSSjbyX3RBxzhanBp48g6EdT9YmDZomBPnrhfMfn7W pkANUwn93iFjPmegd4aICBCwTM1qIw2UeUTOXSUoQ5midPw7bAfrTuvnyoJPQ+/oplhM 24UmYn6rhAnJqerDMLsM8FvFQFg9UVD7l9mDiZ7cI6W2y+NkO/eJ6HM3kzEPtSa7Ngiw 82rOdElidiw0a7wVrl4gWz7WwNH2rMRxwzjUNV5YcUFSXRe4dN/9NOgxIwJ7zK/8Neq+ KcYB2L9iOSRS4IepQzA3FaS6WX/z8wzWZozm2A5oDcxiVfJB05SWlfr2uxDf8erNjMs6 fcLA== X-Gm-Message-State: AO0yUKX7UT85kHj3LPtvAAH+LpoJOpx0FbRXeQd55C3+PQDa5wVr5KAx Tydrs2mD6pofpX/rk/HbNhu0ljfIi1Q= X-Google-Smtp-Source: AK7set8wLvBkCl/46e1zzwcPlr72JTjzxGtGYyojohBR7ImjPCisXXFah/R8nrkwC/f3egE0wbe6Cw== X-Received: by 2002:a1c:740b:0:b0:3ee:126b:4a11 with SMTP id p11-20020a1c740b000000b003ee126b4a11mr4145903wmc.6.1679469189479; Wed, 22 Mar 2023 00:13:09 -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 u4-20020a5d4344000000b002c5526234d2sm13290279wrr.8.2023.03.22.00.13.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 00:13:08 -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, Vernon Yang , Lorenzo Stoakes Subject: [PATCH v3 1/4] mm/mmap/vma_merge: further improve prev/next VMA naming Date: Wed, 22 Mar 2023 07:13:01 +0000 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 4A758A0002 X-Rspam-User: X-Stat-Signature: 9usduk3xw4j47nqr7xfyyqw8pgjfrbuo X-HE-Tag: 1679469191-919122 X-HE-Meta: U2FsdGVkX1/sH5/UqSXhi54ji9IWRTTrFw0ZewAFiggvE0kDR3QiY2u3ealtOT+UcFfSWopbQshziTk/it0NbJUlG+vfrKYEVPDvkuf7pmcL0s8I81ep6sMqZEjgB1E08Xxy2+t/UQoHDwtI2fLfhuGmOoK1GeeAShaNFrJNlfSkU/6tvcurQDBlUu9fJ094jlfTFNrrgCTpY+LRGhwBLBf6rzRKBgXcgJK8tdbVzV6yKjv/BDSBH6cJP9HqCjo3CNMOlVuoga7/rbydh2xH8NGeK/5tfc3WXoqVnBL6qbls1imVL+umpXxhfy3iO7gdEGPw8iS7mbkd7GYOMlcBY+Pet/JpFMxAVKryI1RPGi+8ig7BaQF8q0vDFKk5FTzpnjsKDpaITEw3FeexO/pRq7xXz8ZFfFDIIJZm+PpMj04A6j2ILm45UezO9ZHO2Ry2VQ/QzT5IXiAuBGAa/MqRBNcxPiMbbTmS3Z+RRBoDJM9BHg8xLJayIwwFW0lVDSLHpvamUhZGB2m/ov6vOvwLMepLTgqvbDOzwTfnbgxZtroNWoXhBtScqC3nxi2q8SyudVS3w7BnZpC7ORanLfjNcaUZPs633H/RHNmlFsG4qGT6/qHi3OGzTmiH8uVImx10IfAnoAxvE6aJprlZj0jVTMJrUvx14aCcX6GeXn8jh4y+RFtudfma8PBZqjtkcDqIcyQ5Nn+2Q7j5ivw8/9D77DIP5s74OdzxwcjdAp12fjM+0/rLpWFADTcYA9uf8MPRDthBjN4x6Psy02m+rCYG8VGbvDzZcaDOuYjHuLtfxyS7imeJ+tcG97p0E6uWKgA1wrtoWSkEc9pQZ/oK+XEtGiyGHE2fMLKhxaH1sgjnHJRgLj6ZPegq0ig12mNlIGrTSROiwgr4YewAKNK5+K4C8IinU9TNgJpZpOSbaaMTx7dyRHFL5hg+oRd66RdlBy94UoOYW0r3rvcuiDfIl4F tskVPd4Q olMHzKsWeVpHnCgrYNjWWEuFm0LjaC9d+cZupA1CDYQTXAOOn4p71IqVIUkwN0mxnzHVBJfCg57Ne/W2FQ89PCZYJHfVuX97RdCkf+2zio2xeVOXNPInXX7pq63iTkAXs1GFXZ7JMKigeLy4Xm18zxzLnO+YqXqe1jIJhj5uG1PThZGfpri333e6hcG9LmXWp3+4E8fK5rs/lOaBVfd9n7yVzLt31yZhNf73VscvpCC0hmsdImmL68nk1pN2ZnNQgS25yazDGa0cj10dD8RvNjSKAH9WZSLcNH4jRaoOfmC21yqA5mLE5bjFWrpTyP3l43DMs0NiOn8od33TRnTTGoD93WPcV9rYplew6C0zbNT2/W4duCiHOC2KcotcRmJHURKM5IJKgW13AMiG1tDJ//9HkeaEgY3zqRb3V X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Previously the ASCII diagram above vma_merge() and the accompanying variable naming was rather confusing, however recent efforts by Liam Howlett and Vlastimil Babka have significantly improved matters. This patch goes a little further - replacing 'X' with 'N', which feels more natural as this represents the _next_ VMA and replacing what was 'N' with 'C' which represents the current VMA. No word quite describes a VMA that has coincident start as the input span, however 'concurrent' (or more simply 'current') abbreviated to 'curr' fits intuitions well alongside prev and next. This has no functional impact. Signed-off-by: Lorenzo Stoakes --- mm/mmap.c | 86 +++++++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 042d22e63528..c9834364ac98 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -861,44 +861,44 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags, * this area are about to be changed to vm_flags - and the no-change * case has already been eliminated. * - * The following mprotect cases have to be considered, where AAAA is + * The following mprotect cases have to be considered, where **** is * the area passed down from mprotect_fixup, never extending beyond one - * vma, PPPP is the previous vma, NNNN is a vma that starts at the same - * address as AAAA and is of the same or larger span, and XXXX the next - * vma after AAAA: + * vma, PPPP is the previous vma, CCCC is a concurrent vma that starts + * at the same address as **** and is of the same or larger span, and + * NNNN the next vma after ****: * - * AAAA AAAA AAAA - * PPPPPPXXXXXX PPPPPPXXXXXX PPPPPPNNNNNN + * **** **** **** + * PPPPPPNNNNNN PPPPPPNNNNNN PPPPPPCCCCCC * cannot merge might become might become - * PPXXXXXXXXXX PPPPPPPPPPNN + * PPNNNNNNNNNN PPPPPPPPPPCC * mmap, brk or case 4 below case 5 below * mremap move: - * AAAA AAAA - * PPPP XXXX PPPPNNNNXXXX + * **** **** + * PPPP NNNN PPPPCCCCNNNN * might become might become * PPPPPPPPPPPP 1 or PPPPPPPPPPPP 6 or - * PPPPPPPPXXXX 2 or PPPPPPPPXXXX 7 or - * PPPPXXXXXXXX 3 PPPPXXXXXXXX 8 + * PPPPPPPPNNNN 2 or PPPPPPPPNNNN 7 or + * PPPPNNNNNNNN 3 PPPPNNNNNNNN 8 * - * It is important for case 8 that the vma NNNN overlapping the - * region AAAA is never going to extended over XXXX. Instead XXXX must - * be extended in region AAAA and NNNN must be removed. This way in + * It is important for case 8 that the vma CCCC overlapping the + * region **** is never going to extended over NNNN. Instead NNNN must + * be extended in region **** and CCCC must be removed. This way in * all cases where vma_merge succeeds, the moment vma_merge drops the * rmap_locks, the properties of the merged vma will be already * correct for the whole merged range. Some of those properties like * vm_page_prot/vm_flags may be accessed by rmap_walks and they must * be correct for the whole merged range immediately after the - * rmap_locks are released. Otherwise if XXXX would be removed and - * NNNN would be extended over the XXXX range, remove_migration_ptes + * rmap_locks are released. Otherwise if NNNN would be removed and + * CCCC would be extended over the NNNN range, remove_migration_ptes * or other rmap walkers (if working on addresses beyond the "end" - * parameter) may establish ptes with the wrong permissions of NNNN - * instead of the right permissions of XXXX. + * parameter) may establish ptes with the wrong permissions of CCCC + * instead of the right permissions of NNNN. * * In the code below: * PPPP is represented by *prev - * NNNN is represented by *mid or not represented at all (NULL) - * XXXX is represented by *next or not represented at all (NULL) - * AAAA is not represented - it will be merged and the vma containing the + * CCCC is represented by *curr or not represented at all (NULL) + * NNNN is represented by *next or not represented at all (NULL) + * **** is not represented - it will be merged and the vma containing the * area is returned, or the function will return NULL */ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, @@ -911,7 +911,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, { pgoff_t pglen = (end - addr) >> PAGE_SHIFT; pgoff_t vma_pgoff; - struct vm_area_struct *mid, *next, *res = NULL; + struct vm_area_struct *curr, *next, *res = NULL; struct vm_area_struct *vma, *adjust, *remove, *remove2; int err = -1; bool merge_prev = false; @@ -930,19 +930,19 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, if (vm_flags & VM_SPECIAL) return NULL; - mid = find_vma(mm, prev ? prev->vm_end : 0); - if (mid && mid->vm_end == end) /* cases 6, 7, 8 */ - next = find_vma(mm, mid->vm_end); + curr = find_vma(mm, prev ? prev->vm_end : 0); + if (curr && curr->vm_end == end) /* cases 6, 7, 8 */ + next = find_vma(mm, curr->vm_end); else - next = mid; + next = curr; - /* In cases 1 - 4 there's no NNNN vma */ - if (mid && end <= mid->vm_start) - mid = NULL; + /* In cases 1 - 4 there's no CCCC vma */ + if (curr && end <= curr->vm_start) + curr = NULL; /* verify some invariant that must be enforced by the caller */ VM_WARN_ON(prev && addr <= prev->vm_start); - VM_WARN_ON(mid && end > mid->vm_end); + VM_WARN_ON(curr && end > curr->vm_end); VM_WARN_ON(addr >= end); if (prev) { @@ -974,21 +974,21 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, remove = next; /* case 1 */ vma_end = next->vm_end; err = dup_anon_vma(prev, next); - if (mid) { /* case 6 */ - remove = mid; + if (curr) { /* case 6 */ + remove = curr; remove2 = next; if (!next->anon_vma) - err = dup_anon_vma(prev, mid); + err = dup_anon_vma(prev, curr); } } else if (merge_prev) { err = 0; /* case 2 */ - if (mid) { - err = dup_anon_vma(prev, mid); - if (end == mid->vm_end) { /* case 7 */ - remove = mid; + if (curr) { + err = dup_anon_vma(prev, curr); + if (end == curr->vm_end) { /* case 7 */ + remove = curr; } else { /* case 5 */ - adjust = mid; - adj_start = (end - mid->vm_start); + adjust = curr; + adj_start = (end - curr->vm_start); } } } else if (merge_next) { @@ -1004,10 +1004,10 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, vma_end = next->vm_end; vma_pgoff = next->vm_pgoff; err = 0; - if (mid) { /* case 8 */ - vma_pgoff = mid->vm_pgoff; - remove = mid; - err = dup_anon_vma(next, mid); + if (curr) { /* case 8 */ + vma_pgoff = curr->vm_pgoff; + remove = curr; + err = dup_anon_vma(next, curr); } } } -- 2.39.2