Skip to content

Commit

Permalink
memcgroup: move memory controller allocations to their own slabs
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Pavel Emelianov <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Sudhir Kumar <[email protected]>
Cc: YAMAMOTO Takashi <[email protected]>
Cc: Paul Menage <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: KAMEZAWA Hiroyuki <[email protected]>
Cc: Mel Gorman <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Balbir Singh authored and torvalds committed Apr 29, 2008
1 parent faebe9f commit b6ac57d
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <linux/backing-dev.h>
#include <linux/bit_spinlock.h>
#include <linux/rcupdate.h>
#include <linux/slab.h>
#include <linux/swap.h>
#include <linux/spinlock.h>
#include <linux/fs.h>
Expand All @@ -35,6 +36,7 @@

struct cgroup_subsys mem_cgroup_subsys;
static const int MEM_CGROUP_RECLAIM_RETRIES = 5;
static struct kmem_cache *page_cgroup_cache;

/*
* Statistics for memory cgroup.
Expand Down Expand Up @@ -547,7 +549,7 @@ static int mem_cgroup_charge_common(struct page *page, struct mm_struct *mm,
}
unlock_page_cgroup(page);

pc = kzalloc(sizeof(struct page_cgroup), gfp_mask);
pc = kmem_cache_zalloc(page_cgroup_cache, gfp_mask);
if (pc == NULL)
goto err;

Expand Down Expand Up @@ -609,7 +611,7 @@ static int mem_cgroup_charge_common(struct page *page, struct mm_struct *mm,
*/
res_counter_uncharge(&mem->res, PAGE_SIZE);
css_put(&mem->css);
kfree(pc);
kmem_cache_free(page_cgroup_cache, pc);
goto retry;
}
page_assign_page_cgroup(page, pc);
Expand All @@ -624,7 +626,7 @@ static int mem_cgroup_charge_common(struct page *page, struct mm_struct *mm,
return 0;
out:
css_put(&mem->css);
kfree(pc);
kmem_cache_free(page_cgroup_cache, pc);
err:
return -ENOMEM;
}
Expand Down Expand Up @@ -682,7 +684,7 @@ void mem_cgroup_uncharge_page(struct page *page)
res_counter_uncharge(&mem->res, PAGE_SIZE);
css_put(&mem->css);

kfree(pc);
kmem_cache_free(page_cgroup_cache, pc);
return;
}

Expand Down Expand Up @@ -989,10 +991,12 @@ mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont)
struct mem_cgroup *mem;
int node;

if (unlikely((cont->parent) == NULL))
if (unlikely((cont->parent) == NULL)) {
mem = &init_mem_cgroup;
else
page_cgroup_cache = KMEM_CACHE(page_cgroup, SLAB_PANIC);
} else {
mem = kzalloc(sizeof(struct mem_cgroup), GFP_KERNEL);
}

if (mem == NULL)
return ERR_PTR(-ENOMEM);
Expand Down

0 comments on commit b6ac57d

Please sign in to comment.