Containers: Pagecache accounting and control subsystem (v1)
Subsystems (5)
RFC PATCH 1/1 Containers: Pagecache accounting and control subsystem (v1)
This patch adds pagecache accounting and control on top of Paul's container subsystem v7 posted at
http://lkml.org/lkml/2007/2/12/88
Comments, suggestions and criticisms are welcome.
Features:
--------
* New subsystem called 'pagecache_acct' is registered with containers
* Container pointer is added to struct address_space to keep track of associated container
* In filemap.c and swap_state.c, the corresponding container's pagecache_acct subsystem is charged and uncharged whenever a new page is added or removed from pagecache
* The accounting number include pages in swap cache and filesystem buffer pages apart from pagecache, basically everything under NR_FILE_PAGES is counted as pagecache. However this excluded mapped and anonymous pages
* Limits on pagecache can be set by echo 100000 > pagecache_limit on the /container file system. The unit is in kilobytes
* If the pagecache utilisation limit is exceeded, pagecache reclaim code is invoked to recover dirty and clean pagecache pages only.
Advantages:
-----------
* Does not add container pointers in struct page
Limitations:
-----------
* Code is not safe for container deletion/task migration
* Pagecache page reclaim needs performance improvements
* Global LRU is churned in search of pagecache pages
Usage:
-----
* Add patch on top of Paul container (v7) at kernel version 2.6.20
* Enable CONFIG_CONTAINER_PAGECACHE_ACCT in 'General Setup'
* Boot new kernel
* Mount container filesystem
mount -t container /container
cd /container
* Create new container
mkdir mybox
cd /container/mybox
* Add current shell to container
echo $$ > tasks
* There are two files pagecache_usage and pagecache_limit
* In order to set limit, echo value in kilobytes to pagecache_limit
echo 100000 > pagecache_limit #This would set 100MB limit on pagecache usage
* Trash the system from current shell using scp/cp/dd/tar etc
* Watch pagecache_usage and /proc/meminfo to verify behavior
* Only unmapped pagecache data will be accounted and controlled. These are memory used by cp, scp, tar etc. While file mmap will be controlled by Balbir's RSS controller.
ToDo:
----
* Merge with container RSS controller and eliminate redundant code
* Support and test task migration and container deletion
* Review reclaim performance
* Optimise page reclaim
--- include/linux/fs.h | 6 include/linux/pagecache_acct.h | 52 +++++ init/Kconfig | 7 kernel/Makefile | 1 kernel/pagecache_acct.c | 376 +++++++++++++++++++++++++++++++++++++++++ mm/filemap.c | 8 mm/vmscan.c | 76 ++++++++ 7 files changed, 524 insertions(+), 2 deletions(-)
include/linux/fs.h +6 -0
@@ -447,6 +447,12 @@ struct address_space {spinlock_t private_lock;/* for use by the address_space */ struct list_head private_list;/* ditto */ struct address_space *assoc_mapping;/* ditto */ + +#ifdef CONFIG_CONTAINER_PAGECACHE_ACCT +struct container *container;/* Charge page to the right container +using page->mapping */ +#endif + } __attribute__((aligned(sizeof(long))));/* * On most architectures that alignment is already the case; but
include/linux/pagecache_acct.h new file +52 -0
52 lines not on this page · raw message
init/Kconfig +7 -0
@@ -306,6 +306,13 @@ config CONTAINER_NS for instance virtual servers and checkpoint/restart jobs. +config CONTAINER_PAGECACHE_ACCT + bool "Simple PageCache accounting container subsystem" + select CONTAINERS + help + Provides a simple Resource Controller for monitoring the + total pagecache consumed by the tasks in a container + config RELAY bool "Kernel->user space relay support (formerly relayfs)" help
kernel/Makefile +1 -0
@@ -40,6 +40,7 @@ obj-$(CONFIG_CONTAINERS) += container.o obj-$(CONFIG_CPUSETS) += cpuset.o obj-$(CONFIG_CONTAINER_CPUACCT) += cpu_acct.o obj-$(CONFIG_CONTAINER_NS) += ns_container.o +obj-$(CONFIG_CONTAINER_PAGECACHE_ACCT) += pagecache_acct.o obj-$(CONFIG_IKCONFIG) += configs.o obj-$(CONFIG_STOP_MACHINE) += stop_machine.o obj-$(CONFIG_AUDIT) += audit.o auditfilter.o
kernel/pagecache_acct.c new file +376 -0
376 lines not on this page · raw message
mm/filemap.c +8 -0
@@ -30,6 +30,7 @@#include <linux/security.h> #include <linux/syscalls.h> #include <linux/cpuset.h> +#include <linux/pagecache_acct.h> #include "filemap.h" #include "internal.h"
@@ -117,6 +118,8 @@ void __remove_from_page_cache(struct pagstruct address_space *mapping = page->mapping;radix_tree_delete (&mapping->page_tree, page->index); +/* Uncharge before the mapping is gone */ +pagecache_acct_uncharge (page); page->mapping =NULL ; mapping->nrpages--;__dec_zone_page_state (page,NR_FILE_PAGES );
@@ -451,6 +454,11 @@ int add_to_page_cache(struct page *page,__inc_zone_page_state (page,NR_FILE_PAGES ); }write_unlock_irq (&mapping->tree_lock); +/* Unlock before charge, because we may reclaim this inline */ +if (!error) { +pagecache_acct_init_page_ptr (page); +pagecache_acct_charge (page); + }radix_tree_preload_end (); }return error;
mm/vmscan.c +74 -2
136 lines not on this page · raw message
--
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>