From nobody Tue Dec 16 16:31:11 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2308FC6FD1F for ; Wed, 22 Mar 2023 20:43:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231435AbjCVUnu (ORCPT ); Wed, 22 Mar 2023 16:43:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231781AbjCVUnM (ORCPT ); Wed, 22 Mar 2023 16:43:12 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC41693137 for ; Wed, 22 Mar 2023 13:35:50 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id ew6so15074011edb.7 for ; Wed, 22 Mar 2023 13:35:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679517349; 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=K8Aesu5vvORZ6WL09YL+5IVo5FSwXDwhTdstOAf0sjY=; b=Gg5ZcObAHlJvGaCbpLwUzetA5+NHQs6BycCsLMoBZl6joElfip0bipdpM2WgW2LkxS IhP76tzkKx7vU3pM4Hz6vbbL8H21u6Hd23aLFQLSElsiIK/YzU2ALEtLz+sunfDfHBZq a52EP+1ZO5ujrwHZj5VyzTmELogEYXJkBt/q+GPJ0eRztuLGKaheji40U2xud6DS9pwx C+QT+/ua9HaTWCf+/m9AxOBaq42Ot8I/Gqt2Yuba0K9bEdTp1G6ubNhn7OqFX3sU8k7/ URA668qFTEe92JlfvL10X37VUNPl5XfHhGs1IAzFa0xU/ITrrVFlk2WnKvofFIRUv2BT PmdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679517349; 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=K8Aesu5vvORZ6WL09YL+5IVo5FSwXDwhTdstOAf0sjY=; b=YNr8Xl6gQYGtnPMxcKvBNGI24JgagY5YQ6PRSQftOnbSbr9hpTejGTR7voN+RPa8e/ zyLgok66CTqWlTkVgfs2FO3ECvrjWQy/aEZn9QKvxM20TvC+JU3rxwgfkI6W2tAFRvjS SyKDYKy9IpWXLztxFXc82wn/SvNGZF6ROldfuaWjib92Sa2MD4MOkaezPFxPGLoRRU0R Gi3gyVeO1kaQPKQoD5SmGhgE1rp5WjajOKhACxjclJU96HyuUMj5QiLNLaS8KTLMcqbS QSRyuiB7rC/u0m2Jnjd+0+nMK/d6o3QZ5x7YPFdVSq8mysKLMg/ftfd6De6XRfkmw+Z2 uxQw== X-Gm-Message-State: AO0yUKUfeXdMgdux+4qqqKvBEmIxOyL7EKRu28I6gFOTnmQlL80lHtvC /DGhUovMN5SswMULb7InunM0HOVguW8= X-Google-Smtp-Source: AKy350b6/PNGrU1z3zYstiHHWJmoHdwvwf1iQoFh6VemNDWFUaJZcr26zbVOFOfyXdBIoZKtBW1zTA== X-Received: by 2002:adf:ee02:0:b0:2cf:f279:378f with SMTP id y2-20020adfee02000000b002cff279378fmr727274wrn.44.1679516344797; Wed, 22 Mar 2023 13:19:04 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id e4-20020a5d4e84000000b002ceac2ccc4asm14570690wru.23.2023.03.22.13.19.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 13:19:04 -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 v5 1/4] mm/mmap/vma_merge: further improve prev/next VMA naming Date: Wed, 22 Mar 2023 20:18:57 +0000 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 'A' with '*' as it is clearer, 'X' with 'N', which feels more natural as this represents the _next_ VMA and finally '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 Reviewed-by: Vlastimil Babka Reviewed-by: Liam R. Howlett --- 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, unsig= ned 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_struc= t *mm, @@ -911,7 +911,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *v= mi, struct mm_struct *mm, { pgoff_t pglen =3D (end - addr) >> PAGE_SHIFT; pgoff_t vma_pgoff; - struct vm_area_struct *mid, *next, *res =3D NULL; + struct vm_area_struct *curr, *next, *res =3D NULL; struct vm_area_struct *vma, *adjust, *remove, *remove2; int err =3D -1; bool merge_prev =3D 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; =20 - mid =3D find_vma(mm, prev ? prev->vm_end : 0); - if (mid && mid->vm_end =3D=3D end) /* cases 6, 7, 8 */ - next =3D find_vma(mm, mid->vm_end); + curr =3D find_vma(mm, prev ? prev->vm_end : 0); + if (curr && curr->vm_end =3D=3D end) /* cases 6, 7, 8 */ + next =3D find_vma(mm, curr->vm_end); else - next =3D mid; + next =3D curr; =20 - /* In cases 1 - 4 there's no NNNN vma */ - if (mid && end <=3D mid->vm_start) - mid =3D NULL; + /* In cases 1 - 4 there's no CCCC vma */ + if (curr && end <=3D curr->vm_start) + curr =3D NULL; =20 /* verify some invariant that must be enforced by the caller */ VM_WARN_ON(prev && addr <=3D prev->vm_start); - VM_WARN_ON(mid && end > mid->vm_end); + VM_WARN_ON(curr && end > curr->vm_end); VM_WARN_ON(addr >=3D end); =20 if (prev) { @@ -974,21 +974,21 @@ struct vm_area_struct *vma_merge(struct vma_iterator = *vmi, struct mm_struct *mm, remove =3D next; /* case 1 */ vma_end =3D next->vm_end; err =3D dup_anon_vma(prev, next); - if (mid) { /* case 6 */ - remove =3D mid; + if (curr) { /* case 6 */ + remove =3D curr; remove2 =3D next; if (!next->anon_vma) - err =3D dup_anon_vma(prev, mid); + err =3D dup_anon_vma(prev, curr); } } else if (merge_prev) { err =3D 0; /* case 2 */ - if (mid) { - err =3D dup_anon_vma(prev, mid); - if (end =3D=3D mid->vm_end) { /* case 7 */ - remove =3D mid; + if (curr) { + err =3D dup_anon_vma(prev, curr); + if (end =3D=3D curr->vm_end) { /* case 7 */ + remove =3D curr; } else { /* case 5 */ - adjust =3D mid; - adj_start =3D (end - mid->vm_start); + adjust =3D curr; + adj_start =3D (end - curr->vm_start); } } } else if (merge_next) { @@ -1004,10 +1004,10 @@ struct vm_area_struct *vma_merge(struct vma_iterato= r *vmi, struct mm_struct *mm, vma_end =3D next->vm_end; vma_pgoff =3D next->vm_pgoff; err =3D 0; - if (mid) { /* case 8 */ - vma_pgoff =3D mid->vm_pgoff; - remove =3D mid; - err =3D dup_anon_vma(next, mid); + if (curr) { /* case 8 */ + vma_pgoff =3D curr->vm_pgoff; + remove =3D curr; + err =3D dup_anon_vma(next, curr); } } } --=20 2.39.2