summaryrefslogtreecommitdiffstats
path: root/kernel/fork.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-07-21 16:48:51 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-07-21 16:48:51 -0400
commit3928d4f5ee37cdc523894f6e549e6aae521d8980 (patch)
treec328fd919e48fc8442db04d13c2ba1fe2c0f88e4 /kernel/fork.c
parent191a3afa98b857faf5231981ddbab66698034273 (diff)
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>
Diffstat (limited to 'kernel/fork.c')
-rw-r--r--kernel/fork.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/kernel/fork.c b/kernel/fork.c
index 9440d61b925c..0e23deb5acfc 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -303,11 +303,26 @@ struct kmem_cache *files_cachep;
303struct kmem_cache *fs_cachep; 303struct kmem_cache *fs_cachep;
304 304
305/* SLAB cache for vm_area_struct structures */ 305/* SLAB cache for vm_area_struct structures */
306struct kmem_cache *vm_area_cachep; 306static struct kmem_cache *vm_area_cachep;
307 307
308/* SLAB cache for mm_struct structures (tsk->mm) */ 308/* SLAB cache for mm_struct structures (tsk->mm) */
309static struct kmem_cache *mm_cachep; 309static struct kmem_cache *mm_cachep;
310 310
311struct vm_area_struct *vm_area_alloc(void)
312{
313 return kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
314}
315
316struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig)
317{
318 return kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
319}
320
321void vm_area_free(struct vm_area_struct *vma)
322{
323 kmem_cache_free(vm_area_cachep, vma);
324}
325
311static void account_kernel_stack(struct task_struct *tsk, int account) 326static void account_kernel_stack(struct task_struct *tsk, int account)
312{ 327{
313 void *stack = task_stack_page(tsk); 328 void *stack = task_stack_page(tsk);
@@ -455,7 +470,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
455 goto fail_nomem; 470 goto fail_nomem;
456 charge = len; 471 charge = len;
457 } 472 }
458 tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL); 473 tmp = vm_area_dup(mpnt);
459 if (!tmp) 474 if (!tmp)
460 goto fail_nomem; 475 goto fail_nomem;
461 *tmp = *mpnt; 476 *tmp = *mpnt;
@@ -539,7 +554,7 @@ fail_uprobe_end:
539fail_nomem_anon_vma_fork: 554fail_nomem_anon_vma_fork:
540 mpol_put(vma_policy(tmp)); 555 mpol_put(vma_policy(tmp));
541fail_nomem_policy: 556fail_nomem_policy:
542 kmem_cache_free(vm_area_cachep, tmp); 557 vm_area_free(tmp);
543fail_nomem: 558fail_nomem:
544 retval = -ENOMEM; 559 retval = -ENOMEM;
545 vm_unacct_memory(charge); 560 vm_unacct_memory(charge);