Commit b6ac57d50a375aa2f267e1b2b56c46564a936d00

Authored by Balbir Singh
Committed by Linus Torvalds
1 parent faebe9fdf3

memcgroup: move memory controller allocations to their own slabs

Move the memory controller data structure page_cgroup to its own slab cache.
It saves space on the system, allocations are not necessarily pushed to order
of 2 and should provide performance benefits.  Users who disable the memory
controller can also double check that the memory controller is not allocating
page_cgroup's.

NOTE: Hugh Dickins brought up the issue of whether we want to mark page_cgroup
as __GFP_MOVABLE or __GFP_RECLAIMABLE.  I don't think there is an easy answer
at the moment.  page_cgroup's are associated with user pages, they can be
reclaimed once the user page has been reclaimed, so it might make sense to
mark them as __GFP_RECLAIMABLE.  For now, I am leaving the marking to default
values that the slab allocator uses.

Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com>
Cc: Pavel Emelianov <xemul@openvz.org>
Cc: Hugh Dickins <hugh@veritas.com>
Cc: Sudhir Kumar <skumar@linux.vnet.ibm.com>
Cc: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Cc: Paul Menage <menage@google.com>
Cc: David Rientjes <rientjes@google.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Mel Gorman <mel@csn.ul.ie>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 10 additions and 6 deletions Side-by-side Diff

... ... @@ -26,6 +26,7 @@
26 26 #include <linux/backing-dev.h>
27 27 #include <linux/bit_spinlock.h>
28 28 #include <linux/rcupdate.h>
  29 +#include <linux/slab.h>
29 30 #include <linux/swap.h>
30 31 #include <linux/spinlock.h>
31 32 #include <linux/fs.h>
... ... @@ -35,6 +36,7 @@
35 36  
36 37 struct cgroup_subsys mem_cgroup_subsys;
37 38 static const int MEM_CGROUP_RECLAIM_RETRIES = 5;
  39 +static struct kmem_cache *page_cgroup_cache;
38 40  
39 41 /*
40 42 * Statistics for memory cgroup.
... ... @@ -547,7 +549,7 @@
547 549 }
548 550 unlock_page_cgroup(page);
549 551  
550   - pc = kzalloc(sizeof(struct page_cgroup), gfp_mask);
  552 + pc = kmem_cache_zalloc(page_cgroup_cache, gfp_mask);
551 553 if (pc == NULL)
552 554 goto err;
553 555  
... ... @@ -609,7 +611,7 @@
609 611 */
610 612 res_counter_uncharge(&mem->res, PAGE_SIZE);
611 613 css_put(&mem->css);
612   - kfree(pc);
  614 + kmem_cache_free(page_cgroup_cache, pc);
613 615 goto retry;
614 616 }
615 617 page_assign_page_cgroup(page, pc);
... ... @@ -624,7 +626,7 @@
624 626 return 0;
625 627 out:
626 628 css_put(&mem->css);
627   - kfree(pc);
  629 + kmem_cache_free(page_cgroup_cache, pc);
628 630 err:
629 631 return -ENOMEM;
630 632 }
... ... @@ -682,7 +684,7 @@
682 684 res_counter_uncharge(&mem->res, PAGE_SIZE);
683 685 css_put(&mem->css);
684 686  
685   - kfree(pc);
  687 + kmem_cache_free(page_cgroup_cache, pc);
686 688 return;
687 689 }
688 690  
689 691  
690 692  
... ... @@ -989,10 +991,12 @@
989 991 struct mem_cgroup *mem;
990 992 int node;
991 993  
992   - if (unlikely((cont->parent) == NULL))
  994 + if (unlikely((cont->parent) == NULL)) {
993 995 mem = &init_mem_cgroup;
994   - else
  996 + page_cgroup_cache = KMEM_CACHE(page_cgroup, SLAB_PANIC);
  997 + } else {
995 998 mem = kzalloc(sizeof(struct mem_cgroup), GFP_KERNEL);
  999 + }
996 1000  
997 1001 if (mem == NULL)
998 1002 return ERR_PTR(-ENOMEM);