Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm: introduce unmap_desc struct to reduce function arguments

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

Link: https://lkml.kernel.org/r/20260121164946.2093480-9-Liam.Howlett@oracle.com
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: Pedro Falcato <pfalcato@suse.de>
Cc: Baoquan He <bhe@redhat.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Chris Li <chrisl@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: Jann Horn <jannh@google.com>
Cc: Kairui Song <kasong@tencent.com>
Cc: Kemeng Shi <shikemeng@huaweicloud.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: SeongJae Park <sj@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Liam R. Howlett and committed by
Andrew Morton
5b6626a7 43873af7

+51 -23
+10 -4
mm/mmap.c
··· 1876 1876 if (end) { 1877 1877 vma_iter_set(&vmi, 0); 1878 1878 tmp = vma_next(&vmi); 1879 + UNMAP_STATE(unmap, &vmi, /* first = */ tmp, 1880 + /* vma_start = */ 0, /* vma_end = */ end, 1881 + /* prev = */ NULL, /* next = */ NULL); 1882 + 1883 + /* 1884 + * Don't iterate over vmas beyond the failure point for 1885 + * both unmap_vma() and free_pgtables(). 1886 + */ 1887 + unmap.tree_end = end; 1879 1888 flush_cache_mm(mm); 1880 - unmap_region(&vmi.mas, /* vma = */ tmp, 1881 - /* vma_start = */ 0, /* vma_end = */ end, 1882 - /* pg_end = */ end, /* prev = */ NULL, 1883 - /* next = */ NULL); 1889 + unmap_region(&unmap); 1884 1890 charge = tear_down_vmas(mm, &vmi, tmp, end); 1885 1891 vm_unacct_memory(charge); 1886 1892 }
+11 -14
mm/vma.c
··· 472 472 * 473 473 * Called with the mm semaphore held. 474 474 */ 475 - void unmap_region(struct ma_state *mas, struct vm_area_struct *vma, 476 - unsigned long vma_start, unsigned long vma_end, 477 - unsigned long pg_max, struct vm_area_struct *prev, 478 - struct vm_area_struct *next) 475 + void unmap_region(struct unmap_desc *unmap) 479 476 { 480 - struct mm_struct *mm = vma->vm_mm; 477 + struct mm_struct *mm = unmap->first->vm_mm; 478 + struct ma_state *mas = unmap->mas; 481 479 struct mmu_gather tlb; 482 480 483 481 tlb_gather_mmu(&tlb, mm); 484 482 update_hiwater_rss(mm); 485 - unmap_vmas(&tlb, mas, vma, vma_start, vma_end, vma_end); 486 - mas_set(mas, vma->vm_end); 487 - free_pgtables(&tlb, mas, vma, prev ? prev->vm_end : FIRST_USER_ADDRESS, 488 - pg_max, next ? next->vm_start : USER_PGTABLES_CEILING, 489 - /* mm_wr_locked = */ true); 483 + unmap_vmas(&tlb, mas, unmap->first, unmap->vma_start, unmap->vma_end, 484 + unmap->vma_end); 485 + mas_set(mas, unmap->tree_reset); 486 + free_pgtables(&tlb, mas, unmap->first, unmap->pg_start, unmap->pg_end, 487 + unmap->tree_end, unmap->mm_wr_locked); 490 488 tlb_finish_mmu(&tlb); 491 489 } 492 490 ··· 2461 2463 2462 2464 error = mmap_file(vma->vm_file, vma); 2463 2465 if (error) { 2466 + UNMAP_STATE(unmap, vmi, vma, vma->vm_start, vma->vm_end, 2467 + map->prev, map->next); 2464 2468 fput(vma->vm_file); 2465 2469 vma->vm_file = NULL; 2466 2470 2467 2471 vma_iter_set(vmi, vma->vm_end); 2468 2472 /* Undo any partial mapping done by a device driver. */ 2469 - unmap_region(&vmi->mas, vma, vma->vm_start, vma->vm_end, 2470 - map->next ? map->next->vm_start : USER_PGTABLES_CEILING, 2471 - map->prev, map->next); 2472 - 2473 + unmap_region(&unmap); 2473 2474 return error; 2474 2475 } 2475 2476
+30 -5
mm/vma.h
··· 155 155 156 156 }; 157 157 158 + struct unmap_desc { 159 + struct ma_state *mas; /* the maple state point to the first vma */ 160 + struct vm_area_struct *first; /* The first vma */ 161 + unsigned long pg_start; /* The first pagetable address to free (floor) */ 162 + unsigned long pg_end; /* The last pagetable address to free (ceiling) */ 163 + unsigned long vma_start; /* The min vma address */ 164 + unsigned long vma_end; /* The max vma address */ 165 + unsigned long tree_end; /* Maximum for the vma tree search */ 166 + unsigned long tree_reset; /* Where to reset the vma tree walk */ 167 + bool mm_wr_locked; /* If the mmap write lock is held */ 168 + }; 169 + 170 + #define UNMAP_STATE(name, _vmi, _vma, _vma_start, _vma_end, _prev, _next) \ 171 + struct unmap_desc name = { \ 172 + .mas = &(_vmi)->mas, \ 173 + .first = _vma, \ 174 + .pg_start = _prev ? ((struct vm_area_struct *)_prev)->vm_end : \ 175 + FIRST_USER_ADDRESS, \ 176 + .pg_end = _next ? ((struct vm_area_struct *)_next)->vm_start : \ 177 + USER_PGTABLES_CEILING, \ 178 + .vma_start = _vma_start, \ 179 + .vma_end = _vma_end, \ 180 + .tree_end = _next ? \ 181 + ((struct vm_area_struct *)_next)->vm_start : \ 182 + USER_PGTABLES_CEILING, \ 183 + .tree_reset = _vma->vm_end, \ 184 + .mm_wr_locked = true, \ 185 + } 186 + 158 187 static inline bool vmg_nomem(struct vma_merge_struct *vmg) 159 188 { 160 189 return vmg->state == VMA_MERGE_ERROR_NOMEM; ··· 291 262 bool unlock); 292 263 293 264 void remove_vma(struct vm_area_struct *vma); 294 - 295 - void unmap_region(struct ma_state *mas, struct vm_area_struct *vma, 296 - unsigned long vma_start, unsigned long vma_end, 297 - unsigned long pg_max, struct vm_area_struct *prev, 298 - struct vm_area_struct *next); 265 + void unmap_region(struct unmap_desc *unmap); 299 266 300 267 /** 301 268 * vma_modify_flags() - Perform any necessary split/merge in preparation for