linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Suren Baghdasaryan <surenb@google.com>
To: "Liam R. Howlett" <Liam.Howlett@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	maple-tree@lists.infradead.org,  linux-mm@kvack.org,
	linux-kernel@vger.kernel.org,
	 David Hildenbrand <david@redhat.com>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	 Vlastimil Babka <vbabka@suse.cz>, Michal Hocko <mhocko@suse.com>,
	Jann Horn <jannh@google.com>,  Pedro Falcato <pfalcato@suse.de>,
	Charan Teja Kalla <quic_charante@quicinc.com>,
	shikemeng@huaweicloud.com,  kasong@tencent.com,
	nphamcs@gmail.com, bhe@redhat.com, baohua@kernel.org,
	 chrisl@kernel.org, Matthew Wilcox <willy@infradead.org>
Subject: Re: [PATCH v1 7/9] mm: Introduce unmap_desc struct to reduce function arguments
Date: Tue, 9 Sep 2025 14:44:05 -0700	[thread overview]
Message-ID: <CAJuCfpG4D4ikZO1c8zN7HNgLTAco1ggk21rg9AUFwoztA95qSA@mail.gmail.com> (raw)
In-Reply-To: <20250909190945.1030905-8-Liam.Howlett@oracle.com>

On Tue, Sep 9, 2025 at 12:11 PM Liam R. Howlett <Liam.Howlett@oracle.com> wrote:
>
> The unmap_region code uses a number of arguments that could use better
> documentation.  With the addition of a descriptor for unmap (called
> unmap_desc), the arguments can be more self-documenting and increase the
> descriptions within the declaration.
>
> No functional change intended
>
> Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
> ---
>  mm/mmap.c | 12 ++++++++----
>  mm/vma.c  | 27 ++++++++++++---------------
>  mm/vma.h  | 35 ++++++++++++++++++++++++++++++++---
>  3 files changed, 52 insertions(+), 22 deletions(-)
>
> diff --git a/mm/mmap.c b/mm/mmap.c
> index aa4770b8d7f1e..5c9bd3f20e53f 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -1883,11 +1883,15 @@ __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
>                 if (max) {
>                         vma_iter_set(&vmi, 0);
>                         tmp = vma_next(&vmi);
> +                       UNMAP_REGION(unmap, &vmi, /* first vma = */ tmp,
> +                                    /* min vma addr = */ 0,
> +                                    /* max vma addr = */ max,
> +                                    /* prev = */ NULL, /* next = */ NULL);
> +
> +                       /* Don't free the pgtables higher than the failure */
> +                       unmap.tree_max = max;

Sorry, the naming still feels confusing... tree_max is described as /*
Maximum for the vma tree search */ and here we set it to /* Don't free
the pgtables higher than the failure */.

>                         flush_cache_mm(mm);
> -                       unmap_region(&vmi.mas, /* vma = */ tmp,
> -                                    /*vma_min = */ 0, /* vma_max = */ max,
> -                                    /* pg_max = */ max, /* prev = */ NULL,
> -                                    /* next = */ NULL);
> +                       unmap_region(&unmap);
>                         charge = tear_down_vmas(mm, &vmi, tmp, max);
>                         vm_unacct_memory(charge);
>                 }
> diff --git a/mm/vma.c b/mm/vma.c
> index 4c850ffd83a4b..c92384975cbb2 100644
> --- a/mm/vma.c
> +++ b/mm/vma.c
> @@ -473,22 +473,20 @@ void remove_vma(struct vm_area_struct *vma)
>   *
>   * Called with the mm semaphore held.
>   */
> -void unmap_region(struct ma_state *mas, struct vm_area_struct *vma,
> -               unsigned long vma_min, unsigned long vma_max, unsigned long pg_max,
> -               struct vm_area_struct *prev, struct vm_area_struct *next)
> +void unmap_region(struct unmap_desc *desc)
>  {
> -       struct mm_struct *mm = vma->vm_mm;
> +       struct mm_struct *mm = desc->first->vm_mm;
> +       struct ma_state *mas = desc->mas;
>         struct mmu_gather tlb;
>
>         tlb_gather_mmu(&tlb, mm);
>         update_hiwater_rss(mm);
> -       unmap_vmas(&tlb, mas, vma, vma_min, vma_max, vma_max,
> -                  /* mm_wr_locked = */ true);
> -       mas_set(mas, vma->vm_end);
> -       free_pgtables(&tlb, mas, vma, prev ? prev->vm_end : FIRST_USER_ADDRESS,
> -                     next ? next->vm_start : USER_PGTABLES_CEILING,
> -                     pg_max,
> -                     /* mm_wr_locked = */ true);
> +       unmap_vmas(&tlb, mas, desc->first, desc->vma_min, desc->vma_max,
> +                  desc->vma_max, desc->mm_wr_locked);
> +       mas_set(mas, desc->tree_reset);
> +       free_pgtables(&tlb, mas, desc->first, desc->first_pgaddr,
> +                     desc->last_pgaddr, desc->tree_max,
> +                     desc->mm_wr_locked);
>         tlb_finish_mmu(&tlb);
>  }
>
> @@ -2414,15 +2412,14 @@ static int __mmap_new_file_vma(struct mmap_state *map,
>
>         error = mmap_file(vma->vm_file, vma);
>         if (error) {
> +               UNMAP_REGION(unmap, vmi, vma, vma->vm_start, vma->vm_end,
> +                            map->prev, map->next);
>                 fput(vma->vm_file);
>                 vma->vm_file = NULL;
>
>                 vma_iter_set(vmi, vma->vm_end);
>                 /* Undo any partial mapping done by a device driver. */
> -               unmap_region(&vmi->mas, vma, vma->vm_start, vma->vm_end,
> -                            map->next ? map->next->vm_start : USER_PGTABLES_CEILING,
> -                            map->prev, map->next);
> -
> +               unmap_region(&unmap);
>                 return error;
>         }
>
> diff --git a/mm/vma.h b/mm/vma.h
> index b0ebc81d5862e..4edd5d26ffcfc 100644
> --- a/mm/vma.h
> +++ b/mm/vma.h
> @@ -152,6 +152,37 @@ struct vma_merge_struct {
>
>  };
>
> +struct unmap_desc {
> +       struct  ma_state *mas;        /* the maple state point to the first vma */
> +       struct vm_area_struct *first; /* The first vma */
> +       unsigned long first_pgaddr;   /* The first pagetable address to free */
> +       unsigned long last_pgaddr;    /* The last pagetable address to free */
> +       unsigned long vma_min;        /* The min vma address */
> +       unsigned long vma_max;        /* The max vma address */
> +       unsigned long tree_max;       /* Maximum for the vma tree search */
> +       unsigned long tree_reset;     /* Where to reset the vma tree walk */
> +       bool mm_wr_locked;            /* If the mmap write lock is held */
> +};
> +
> +#define UNMAP_REGION(name, _vmi, _vma, _vma_min, _vma_max, _prev, _next)      \

Maybe DEFINE_UNMAP_REGION() similar to DEFINE_PER_CPU() or DEFINE_SPINLOCK()?

> +       struct unmap_desc name = {                                          \
> +               .mas = &(_vmi)->mas,                                          \
> +               .first = _vma,                                                \
> +               .first_pgaddr = _prev ?                                       \
> +                       ((struct vm_area_struct *)_prev)->vm_end :            \
> +                       FIRST_USER_ADDRESS,                                   \
> +               .last_pgaddr = _next ?                                        \
> +                       ((struct vm_area_struct *)_next)->vm_start :          \
> +                       USER_PGTABLES_CEILING,                                \
> +               .vma_min = _vma_min,                                          \
> +               .vma_max = _vma_max,                                          \
> +               .tree_max = _next ?                                           \
> +                       ((struct vm_area_struct *)_next)->vm_start :          \
> +                       USER_PGTABLES_CEILING,                                \
> +               .tree_reset = _vma->vm_end,                                   \
> +               .mm_wr_locked = true,                                         \
> +       }
> +
>  static inline bool vmg_nomem(struct vma_merge_struct *vmg)
>  {
>         return vmg->state == VMA_MERGE_ERROR_NOMEM;
> @@ -260,9 +291,7 @@ int do_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm,
>
>  void remove_vma(struct vm_area_struct *vma);
>
> -void unmap_region(struct ma_state *mas, struct vm_area_struct *vma,
> -               unsigned long min, unsigned long max, unsigned long pg_max,
> -               struct vm_area_struct *prev, struct vm_area_struct *next);
> +void unmap_region(struct unmap_desc *desc);
>
>  /* We are about to modify the VMA's flags. */
>  __must_check struct vm_area_struct
> --
> 2.47.2
>


  reply	other threads:[~2025-09-09 21:44 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-09 19:09 [PATCH v1 0/9] Remove XA_ZERO from error recovery of dup_mmap() Liam R. Howlett
2025-09-09 19:09 ` [PATCH v1 1/9] mm/mmap: Move exit_mmap() trace point Liam R. Howlett
2025-09-09 20:07   ` Suren Baghdasaryan
2025-09-10 12:51   ` Pedro Falcato
2025-09-11  9:19   ` David Hildenbrand
2025-09-09 19:09 ` [PATCH v1 2/9] mm/mmap: Abstract vma clean up from exit_mmap() Liam R. Howlett
2025-09-09 20:09   ` Suren Baghdasaryan
2025-09-10 12:54   ` Pedro Falcato
2025-09-11  9:21   ` David Hildenbrand
2025-09-09 19:09 ` [PATCH v1 3/9] mm/vma: Add limits to unmap_region() for vmas Liam R. Howlett
2025-09-09 20:09   ` Suren Baghdasaryan
2025-09-10 12:56   ` Pedro Falcato
2025-09-11  8:56   ` Lorenzo Stoakes
2025-09-11  9:22   ` David Hildenbrand
2025-09-09 19:09 ` [PATCH v1 4/9] mm/memory: Add tree limit to free_pgtables() Liam R. Howlett
2025-09-09 21:05   ` Suren Baghdasaryan
2025-09-10 13:08   ` Pedro Falcato
2025-09-11  9:08   ` Lorenzo Stoakes
2025-09-11  9:24   ` David Hildenbrand
2025-09-09 19:09 ` [PATCH v1 5/9] mm/vma: Add page table limit to unmap_region() Liam R. Howlett
2025-09-09 21:29   ` Suren Baghdasaryan
2025-09-10 13:08   ` Pedro Falcato
2025-09-09 19:09 ` [PATCH v1 6/9] mm: Change dup_mmap() recovery Liam R. Howlett
2025-09-09 22:03   ` Suren Baghdasaryan
2025-09-10 13:23   ` Pedro Falcato
2025-09-11  9:13   ` Lorenzo Stoakes
2025-09-11  9:31   ` David Hildenbrand
2025-09-09 19:09 ` [PATCH v1 7/9] mm: Introduce unmap_desc struct to reduce function arguments Liam R. Howlett
2025-09-09 21:44   ` Suren Baghdasaryan [this message]
2025-09-11  9:22     ` Lorenzo Stoakes
2025-09-11 16:51       ` Suren Baghdasaryan
2025-09-11 16:56         ` Liam R. Howlett
2025-09-11 17:03           ` Suren Baghdasaryan
2025-09-10 13:10   ` Pedro Falcato
2025-09-11  9:20   ` Lorenzo Stoakes
2025-09-09 19:09 ` [PATCH v1 8/9] mm/vma: Use unmap_desc in vms_clear_ptes() and exit_mmap() Liam R. Howlett
2025-09-09 22:16   ` Suren Baghdasaryan
2025-09-11 16:59     ` Liam R. Howlett
2025-09-11  9:53   ` Lorenzo Stoakes
2025-09-12  5:08   ` kernel test robot
2025-09-09 19:09 ` [PATCH v1 9/9] mm: Use unmap_desc struct for freeing page tables Liam R. Howlett
2025-09-09 22:27   ` Suren Baghdasaryan
2025-09-11 10:06   ` Lorenzo Stoakes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJuCfpG4D4ikZO1c8zN7HNgLTAco1ggk21rg9AUFwoztA95qSA@mail.gmail.com \
    --to=surenb@google.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=bhe@redhat.com \
    --cc=chrisl@kernel.org \
    --cc=david@redhat.com \
    --cc=jannh@google.com \
    --cc=kasong@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=maple-tree@lists.infradead.org \
    --cc=mhocko@suse.com \
    --cc=nphamcs@gmail.com \
    --cc=pfalcato@suse.de \
    --cc=quic_charante@quicinc.com \
    --cc=shikemeng@huaweicloud.com \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox