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: use helper functions for allocating and freeing vm_area structs

The vm_area_struct is one of the most fundamental memory management
objects, but the management of it is entirely open-coded evertwhere,
ranging from allocation and freeing (using kmem_cache_[z]alloc and
kmem_cache_free) to initializing all the fields.

We want to unify this in order to end up having some unified
initialization of the vmas, and the first step to this is to at least
have basic allocation functions.

Right now those functions are literally just wrappers around the
kmem_cache_*() calls. This is a purely mechanical conversion:

# new vma:
kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL) -> vm_area_alloc()

# copy old vma
kmem_cache_alloc(vm_area_cachep, GFP_KERNEL) -> vm_area_dup(old)

# free vma
kmem_cache_free(vm_area_cachep, vma) -> vm_area_free(vma)

to the point where the old vma passed in to the vm_area_dup() function
isn't even used yet (because I've left all the old manual initialization
alone).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

+44 -27
+2 -2
arch/ia64/kernel/perfmon.c
··· 2278 2278 DPRINT(("smpl_buf @%p\n", smpl_buf)); 2279 2279 2280 2280 /* allocate vma */ 2281 - vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); 2281 + vma = vm_area_alloc(); 2282 2282 if (!vma) { 2283 2283 DPRINT(("Cannot allocate vma\n")); 2284 2284 goto error_kmem; ··· 2346 2346 return 0; 2347 2347 2348 2348 error: 2349 - kmem_cache_free(vm_area_cachep, vma); 2349 + vm_area_free(vma); 2350 2350 error_kmem: 2351 2351 pfm_rvfree(smpl_buf, size); 2352 2352
+4 -4
arch/ia64/mm/init.c
··· 114 114 * the problem. When the process attempts to write to the register backing store 115 115 * for the first time, it will get a SEGFAULT in this case. 116 116 */ 117 - vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); 117 + vma = vm_area_alloc(); 118 118 if (vma) { 119 119 INIT_LIST_HEAD(&vma->anon_vma_chain); 120 120 vma->vm_mm = current->mm; ··· 125 125 down_write(&current->mm->mmap_sem); 126 126 if (insert_vm_struct(current->mm, vma)) { 127 127 up_write(&current->mm->mmap_sem); 128 - kmem_cache_free(vm_area_cachep, vma); 128 + vm_area_free(vma); 129 129 return; 130 130 } 131 131 up_write(&current->mm->mmap_sem); ··· 133 133 134 134 /* map NaT-page at address zero to speed up speculative dereferencing of NULL: */ 135 135 if (!(current->personality & MMAP_PAGE_ZERO)) { 136 - vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); 136 + vma = vm_area_alloc(); 137 137 if (vma) { 138 138 INIT_LIST_HEAD(&vma->anon_vma_chain); 139 139 vma->vm_mm = current->mm; ··· 144 144 down_write(&current->mm->mmap_sem); 145 145 if (insert_vm_struct(current->mm, vma)) { 146 146 up_write(&current->mm->mmap_sem); 147 - kmem_cache_free(vm_area_cachep, vma); 147 + vm_area_free(vma); 148 148 return; 149 149 } 150 150 up_write(&current->mm->mmap_sem);
+2 -2
fs/exec.c
··· 290 290 struct vm_area_struct *vma = NULL; 291 291 struct mm_struct *mm = bprm->mm; 292 292 293 - bprm->vma = vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); 293 + bprm->vma = vma = vm_area_alloc(); 294 294 if (!vma) 295 295 return -ENOMEM; 296 296 ··· 326 326 up_write(&mm->mmap_sem); 327 327 err_free: 328 328 bprm->vma = NULL; 329 - kmem_cache_free(vm_area_cachep, vma); 329 + vm_area_free(vma); 330 330 return err; 331 331 } 332 332
+3 -1
include/linux/mm.h
··· 155 155 * mmap() functions). 156 156 */ 157 157 158 - extern struct kmem_cache *vm_area_cachep; 158 + struct vm_area_struct *vm_area_alloc(void); 159 + struct vm_area_struct *vm_area_dup(struct vm_area_struct *); 160 + void vm_area_free(struct vm_area_struct *); 159 161 160 162 #ifndef CONFIG_MMU 161 163 extern struct rb_root nommu_region_tree;
+18 -3
kernel/fork.c
··· 303 303 struct kmem_cache *fs_cachep; 304 304 305 305 /* SLAB cache for vm_area_struct structures */ 306 - struct kmem_cache *vm_area_cachep; 306 + static struct kmem_cache *vm_area_cachep; 307 307 308 308 /* SLAB cache for mm_struct structures (tsk->mm) */ 309 309 static struct kmem_cache *mm_cachep; 310 + 311 + struct vm_area_struct *vm_area_alloc(void) 312 + { 313 + return kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); 314 + } 315 + 316 + struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) 317 + { 318 + return kmem_cache_alloc(vm_area_cachep, GFP_KERNEL); 319 + } 320 + 321 + void vm_area_free(struct vm_area_struct *vma) 322 + { 323 + kmem_cache_free(vm_area_cachep, vma); 324 + } 310 325 311 326 static void account_kernel_stack(struct task_struct *tsk, int account) 312 327 { ··· 470 455 goto fail_nomem; 471 456 charge = len; 472 457 } 473 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL); 458 + tmp = vm_area_dup(mpnt); 474 459 if (!tmp) 475 460 goto fail_nomem; 476 461 *tmp = *mpnt; ··· 554 539 fail_nomem_anon_vma_fork: 555 540 mpol_put(vma_policy(tmp)); 556 541 fail_nomem_policy: 557 - kmem_cache_free(vm_area_cachep, tmp); 542 + vm_area_free(tmp); 558 543 fail_nomem: 559 544 retval = -ENOMEM; 560 545 vm_unacct_memory(charge);
+11 -11
mm/mmap.c
··· 182 182 if (vma->vm_file) 183 183 fput(vma->vm_file); 184 184 mpol_put(vma_policy(vma)); 185 - kmem_cache_free(vm_area_cachep, vma); 185 + vm_area_free(vma); 186 186 return next; 187 187 } 188 188 ··· 911 911 anon_vma_merge(vma, next); 912 912 mm->map_count--; 913 913 mpol_put(vma_policy(next)); 914 - kmem_cache_free(vm_area_cachep, next); 914 + vm_area_free(next); 915 915 /* 916 916 * In mprotect's case 6 (see comments on vma_merge), 917 917 * we must remove another next too. It would clutter ··· 1729 1729 * specific mapper. the address has already been validated, but 1730 1730 * not unmapped, but the maps are removed from the list. 1731 1731 */ 1732 - vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); 1732 + vma = vm_area_alloc(); 1733 1733 if (!vma) { 1734 1734 error = -ENOMEM; 1735 1735 goto unacct_error; ··· 1832 1832 if (vm_flags & VM_DENYWRITE) 1833 1833 allow_write_access(file); 1834 1834 free_vma: 1835 - kmem_cache_free(vm_area_cachep, vma); 1835 + vm_area_free(vma); 1836 1836 unacct_error: 1837 1837 if (charged) 1838 1838 vm_unacct_memory(charged); ··· 2620 2620 return err; 2621 2621 } 2622 2622 2623 - new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL); 2623 + new = vm_area_dup(vma); 2624 2624 if (!new) 2625 2625 return -ENOMEM; 2626 2626 ··· 2669 2669 out_free_mpol: 2670 2670 mpol_put(vma_policy(new)); 2671 2671 out_free_vma: 2672 - kmem_cache_free(vm_area_cachep, new); 2672 + vm_area_free(new); 2673 2673 return err; 2674 2674 } 2675 2675 ··· 2984 2984 /* 2985 2985 * create a vma struct for an anonymous mapping 2986 2986 */ 2987 - vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); 2987 + vma = vm_area_alloc(); 2988 2988 if (!vma) { 2989 2989 vm_unacct_memory(len >> PAGE_SHIFT); 2990 2990 return -ENOMEM; ··· 3202 3202 } 3203 3203 *need_rmap_locks = (new_vma->vm_pgoff <= vma->vm_pgoff); 3204 3204 } else { 3205 - new_vma = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL); 3205 + new_vma = vm_area_dup(vma); 3206 3206 if (!new_vma) 3207 3207 goto out; 3208 3208 *new_vma = *vma; ··· 3226 3226 out_free_mempol: 3227 3227 mpol_put(vma_policy(new_vma)); 3228 3228 out_free_vma: 3229 - kmem_cache_free(vm_area_cachep, new_vma); 3229 + vm_area_free(new_vma); 3230 3230 out: 3231 3231 return NULL; 3232 3232 } ··· 3350 3350 int ret; 3351 3351 struct vm_area_struct *vma; 3352 3352 3353 - vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); 3353 + vma = vm_area_alloc(); 3354 3354 if (unlikely(vma == NULL)) 3355 3355 return ERR_PTR(-ENOMEM); 3356 3356 ··· 3376 3376 return vma; 3377 3377 3378 3378 out: 3379 - kmem_cache_free(vm_area_cachep, vma); 3379 + vm_area_free(vma); 3380 3380 return ERR_PTR(ret); 3381 3381 } 3382 3382
+4 -4
mm/nommu.c
··· 769 769 if (vma->vm_file) 770 770 fput(vma->vm_file); 771 771 put_nommu_region(vma->vm_region); 772 - kmem_cache_free(vm_area_cachep, vma); 772 + vm_area_free(vma); 773 773 } 774 774 775 775 /* ··· 1204 1204 if (!region) 1205 1205 goto error_getting_region; 1206 1206 1207 - vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); 1207 + vma = vm_area_alloc(); 1208 1208 if (!vma) 1209 1209 goto error_getting_vma; 1210 1210 ··· 1368 1368 kmem_cache_free(vm_region_jar, region); 1369 1369 if (vma->vm_file) 1370 1370 fput(vma->vm_file); 1371 - kmem_cache_free(vm_area_cachep, vma); 1371 + vm_area_free(vma); 1372 1372 return ret; 1373 1373 1374 1374 sharing_violation: ··· 1469 1469 if (!region) 1470 1470 return -ENOMEM; 1471 1471 1472 - new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL); 1472 + new = vm_area_dup(vma); 1473 1473 if (!new) { 1474 1474 kmem_cache_free(vm_region_jar, region); 1475 1475 return -ENOMEM;