From patchwork Sat Mar 18 11:13:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13179744 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 DE95BC7618A for ; Sat, 18 Mar 2023 11:15:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 354E3900004; Sat, 18 Mar 2023 07:15:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2DE30900002; Sat, 18 Mar 2023 07:15:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 156B8900004; Sat, 18 Mar 2023 07:15:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 07DF0900002 for ; Sat, 18 Mar 2023 07:15:32 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id CA70E16067F for ; Sat, 18 Mar 2023 11:15:31 +0000 (UTC) X-FDA: 80581763262.15.3D643A6 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by imf18.hostedemail.com (Postfix) with ESMTP id E0A761C0013 for ; Sat, 18 Mar 2023 11:15:29 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=lcVvYIEW; spf=pass (imf18.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.48 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=1679138130; 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=rtTyPgAyyTCsuj6xg05jXpazWd4/Ojg4wA/2tNBdu1s=; b=jt9YpLf+uVrxJNdYtGq7pzDKOpHzUloVIt/Y/sEsMsdCuSrnxgf2GN30sUz6Mssavu1TYB i8FADXMZ64SfLcJS0XeOgsl78B8nYrjHCip8dLWNE52RdG7MeRVJZW1d1wdZ/kJqJ6U+lZ gziiBjnrT+zHbMTxOEPfq/7NZgn1CrY= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=lcVvYIEW; spf=pass (imf18.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.48 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=1679138130; a=rsa-sha256; cv=none; b=MoRr7En+u8xH4p2kh5Mt+iWcrqwoZrVxJze5X9BmrmVM0ijx7fU68eRusVIeSgOMmRIl7r zkn/YPLyvXa6uwmVKzsUXuDS4xl2MsXbOjiE9+ZKWpiLx5OjC+FU43t2BJaoAmTQY9Hy+2 CR4EfPj3Fp9o4ML6w7OISdWpruuqPYM= Received: by mail-wm1-f48.google.com with SMTP id ay8so4735627wmb.1 for ; Sat, 18 Mar 2023 04:15:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679138128; 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=rtTyPgAyyTCsuj6xg05jXpazWd4/Ojg4wA/2tNBdu1s=; b=lcVvYIEW8+t4NkKIqKPZkQ/jm/KlLLZlZl9jbndrlXKESJ5B22z2oeoab9fhvx+Ntt 7oS48C9g1A1M+KR2O9NE6h0VV/leh0sMEzsU91SdB19XsZv0mQtwCQ5PnhewtgTzI7La CKKKpaD768kZd9t/WlyMRlj7ZSYq7zOC+J/qwyYJkN8786JINt+DfcRYSDM43SLE1R3R o6aD7LoZPqYpDm/NP89CyAhno6pNBm0a+eVvURQrJQtmWM8jHN9fbZzESqPfc3nFObZl XuW3leBcK6d5ksDIinObI2+pj8l5wd4WKhTKcUMybeeIZyUBx9Qn5OwL4nFxK/TEwlAE b0Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679138128; 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=rtTyPgAyyTCsuj6xg05jXpazWd4/Ojg4wA/2tNBdu1s=; b=ReGjcpF+StrzwZ3RhOGC40Z1AbZ1/o96bBop5VpJ5T2ssX3iz3f5sG0xBo2eHLNBuQ RqrTHakjMXw2JZBQYgGqorrWtwn/irPEJTiG8aksn0qp1yqA5BAyV+nvhK9ohXETIyxo Ok6dg8DNdSJ/lez1SASGs/8AC0Il0bL3LQRiViKfOeEErmdOcgfJKydSknE+YWQV7g8L 2VG8i0+kaMAIx8ufTTIhvBZQFY6LCeTuEJrG6DwHY3c1vjlbOo0z8+vtsDD6bEeNRUNe L5vjQKWMnU2s6jyvGpBwAEVpkZRiWqWyvWvK1xv/FCYpElgQL/KoVTBs7O7AtRQZvANE SnKg== X-Gm-Message-State: AO0yUKWuB/BCzjk2/3bN54HpbIA+an+8hJGK/jR2G2upCKpqUE9GKnQ6 MANUHumk3MElFB2a9qlCT4w0K8B5aO4= X-Google-Smtp-Source: AK7set8PKRFrmahfYs9pbXZ+Lyy8xMiJQ1AWofunInVbiM9ckVRROOif+SqzAwtD9W2TAhn8L3LM3w== X-Received: by 2002:a05:600c:4f07:b0:3ed:3cec:d2ec with SMTP id l7-20020a05600c4f0700b003ed3cecd2ecmr10106468wmq.15.1679138128112; Sat, 18 Mar 2023 04:15:28 -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.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 04:15:27 -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 1/4] mm/mmap/vma_merge: further improve prev/next VMA naming Date: Sat, 18 Mar 2023 11:13:18 +0000 Message-Id: <6001e08fa7e119470cbb1d2b6275ad8d742ff9a7.1679137163.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: E0A761C0013 X-Rspam-User: X-Stat-Signature: h936mpqk6ncbh97u3oxxejj1atqrspg5 X-HE-Tag: 1679138129-334254 X-HE-Meta: U2FsdGVkX19JQesHL9KJrrelKjBDQnuFCGliRffURKkN7Z0YlWbraR/7/u+Vw1K66nQZKQ7XhEwAFVfg5ZjClcwOu+jV7YPyozlEmSAZQf54h+U6CBucJpnKtpBqxwgSRFF4KBMvn5b500rU4RnodbgsfcCjr5i5/5SsEVyJ3/kVrMJKTuKl395+1vtG4tpdQHUZmf1raVaK/f9K9XjjIOib17+nrz+UVFQIY1UqqclnkXwvq7gxPnGEQq8CdMCLLrFRutR6lyGFMU3vMIVlg6d1VQvY82v9WCHo6UI/mFSLRuV1mhTcxIm4+aUEq0+7ZWhjRLzzVXgE10D0NTRRZh1lmZR5JUxrP1w+32NCZCpw3y9lPdRLZVgedNFi69YrVlwCP77UO8sSxVkuDEpFoRZEXdJALr8Rcqy9alR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6VMkBOmV 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 a lot more natural and replacing what was 'N' with 'C' which stands for 'concurrent' VMA. No word quite describes a VMA that has coincident start as the input span, concurrent, abbreviated to 'curr' (and which can be thought of also as 'current') however 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); } } }