Skip to contentSkip to conversation

Move memory controller allocations to their own slabs (v3)

PATCH In review Balbir Singh 4 participants 4 messages Mar 13, 2008 – Mar 17, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Move memory controller allocations to their own slabs (v3)

Changelog v3

1. Remove HWCACHE_ALIGN

Changelog v2

1. Remove extra slab for mem_cgroup_per_zone

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.

Comments?

---

 mm/memcontrol.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
mm/memcontrol.c renamed from mm/memcontrol.c~memory-controller-move-to-own-slab +7 -4
diff -puN mm/memcontrol.c~memory-controller-move-to-own-slab mm/memcontrol.c
@@ -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>
@@ -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.
@@ -560,7 +562,7 @@ retry:
 	}
 	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;
 
@@ -622,7 +624,7 @@ retry:
 		 */
 		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);
@@ -637,7 +639,7 @@ done:
 	return 0;
 out:
 	css_put(&mem->css);
-	kfree(pc);
+	kmem_cache_free(page_cgroup_cache, pc);
 err:
 	return -ENOMEM;
 }
@@ -695,7 +697,7 @@ void mem_cgroup_uncharge_page(struct pag
 		res_counter_uncharge(&mem->res, PAGE_SIZE);
 		css_put(&mem->css);
 
-		kfree(pc);
+		kmem_cache_free(page_cgroup_cache, pc);
 		return;
 	}
 
@@ -989,6 +991,7 @@ mem_cgroup_create(struct cgroup_subsys *
 	if (unlikely((cont->parent) == NULL)) {
 		mem = &init_mem_cgroup;
 		init_mm.mem_cgroup = mem;
+		page_cgroup_cache = KMEM_CACHE(page_cgroup, SLAB_PANIC);
 	} else
 		mem = kzalloc(sizeof(struct mem_cgroup), GFP_KERNEL);
 

_

Signature · 10 lines
	Warm Regards,
	Balbir Singh
	Linux Technology Center
	IBM, ISTL

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 16 lines · On Thu, 13 Mar 2008 19:33:07 +0530 Balbir Singh <[email protected]>…

Changelog v3

1. Remove HWCACHE_ALIGN

Changelog v2

1. Remove extra slab for mem_cgroup_per_zone

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.

Quoted 9 lines

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.

Comments?

At first, in my understanding,
- MOVABLE is for migratable pages. (so, not for kernel objects.)
- RECLAIMABLE is for reclaimable kernel objects. (for slab etc..)

All reclaimable objects are not necessary to be always reclaimable but some amount of RECLAIMABLE objects (not all) should be recraimable easily. For example, some of dentry-cache, inode-cache is reclaimable because *unused* objects are cached.

When it comes to page_cgroup, *all* objects has dependency to pages which are assigned to. And user pages are reclaimable.
There is a similar object....the radix tree. radix-tree's node is allocated as RECLAIMABLE object.

So I think it makes sense to changing page_cgroup to be reclaimable.

But final decision should be done by how fragmentation avoidance works. It's good to test "how many hugepages can be allocated dynamically" when we make page_cgroup to be GFP_RECAIMABLE

Thanks,
-Kame

#2 lore raw
Quoted 14 lines · KAMEZAWA Hiroyuki

At first, in my understanding,
- MOVABLE is for migratable pages. (so, not for kernel objects.)
- RECLAIMABLE is for reclaimable kernel objects. (for slab etc..)

All reclaimable objects are not necessary to be always reclaimable but some amount of RECLAIMABLE objects (not all) should be recraimable easily. For example, some of dentry-cache, inode-cache is reclaimable because *unused* objects are cached.

When it comes to page_cgroup, *all* objects has dependency to pages which are assigned to. And user pages are reclaimable.
There is a similar object....the radix tree. radix-tree's node is allocated as RECLAIMABLE object.

Quoted 5 lines

So I think it makes sense to changing page_cgroup to be reclaimable.

But final decision should be done by how fragmentation avoidance works. It's good to test "how many hugepages can be allocated dynamically" when we make page_cgroup to be GFP_RECAIMABLE

I agree with you on all points. No need for it to be done in the same patch as Balbir's, but yes, __GFP_RECLAIMABLE appears to be appropriate for the page_cgroup kmem_cache.

(I think it's a better fit than for the radix_tree_node cache: though the common pagecache usage of the radix_tree implies that its nodes are reclaimable, I can't see why radix_tree nodes would intrinsically be reclaimable. If a significant non-reclaimable user of radix-tree comes on the scene, I'd expect us to change that assumption.)

Hugh

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw
In reply to KAMEZAWA Hiroyuki
Quoted 26 lines · KAMEZAWA Hiroyuki
Quoted 23 lines · On Thu, 13 Mar 2008 19:33:07 +0530 Balbir Singh <[email protected]>…

Changelog v3

1. Remove HWCACHE_ALIGN

Changelog v2

1. Remove extra slab for mem_cgroup_per_zone

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.

Quoted 5 lines
Quoted 2 lines

Comments?

At first, in my understanding,
- MOVABLE is for migratable pages. (so, not for kernel objects.)
- RECLAIMABLE is for reclaimable kernel objects. (for slab etc..)

Yes, MOVABLE is for things which are very easily moved out, whether that is migrated to another page, or paged out to swap, or trivially freed as it can be re-read from somewhere such as text from a binary; generally this is things on the LRU.

RECLAIMABLE, is things which are harder to get rid of, but for which there is some hope of evicting their contents; as you say things like those slab caches with shrinkers.

Quoted 11 lines

All reclaimable objects are not necessary to be always reclaimable but some amount of RECLAIMABLE objects (not all) should be recraimable easily. For example, some of dentry-cache, inode-cache is reclaimable because *unused* objects are cached.

When it comes to page_cgroup, *all* objects has dependency to pages which are assigned to. And user pages are reclaimable.
There is a similar object....the radix tree. radix-tree's node is allocated as RECLAIMABLE object.

So I think it makes sense to changing page_cgroup to be reclaimable.

That sounds correct to me.

Quoted 3 lines

But final decision should be done by how fragmentation avoidance works. It's good to test "how many hugepages can be allocated dynamically" when we make page_cgroup to be GFP_RECAIMABLE

-apw

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>