Home » Mailing lists » Devel » [RFC][PATCH 0/7] Resource controllers based on process containers
[RFC][PATCH 7/7] Account for the number of files opened within container [message #10895 is a reply to message #10888] |
Tue, 06 March 2007 15:05 |
xemul
Messages: 248 Registered: November 2005
|
Senior Member |
|
|
Simple again - increment usage counter at file open and
decrement at file close. Reject opening if limit is hit.
diff -upr linux-2.6.20.orig/fs/Makefile linux-2.6.20-0/fs/Makefile
--- linux-2.6.20.orig/fs/Makefile 2007-02-04 21:44:54.000000000 +0300
+++ linux-2.6.20-0/fs/Makefile 2007-03-06 13:33:28.000000000 +0300
@@ -19,6 +19,8 @@ else
obj-y += no-block.o
endif
+obj-$(CONFIG_FILES_CONTAINER) += numfiles_container.o
+
obj-$(CONFIG_INOTIFY) += inotify.o
obj-$(CONFIG_INOTIFY_USER) += inotify_user.o
obj-$(CONFIG_EPOLL) += eventpoll.o
diff -upr linux-2.6.20.orig/fs/file_table.c linux-2.6.20-0/fs/file_table.c
--- linux-2.6.20.orig/fs/file_table.c 2007-02-04 21:44:54.000000000 +0300
+++ linux-2.6.20-0/fs/file_table.c 2007-03-06 13:33:28.000000000 +0300
@@ -21,6 +21,7 @@
#include <linux/fsnotify.h>
#include <linux/sysctl.h>
#include <linux/percpu_counter.h>
+#include <linux/numfiles_container.h>
#include <asm/atomic.h>
@@ -42,6 +43,7 @@ static inline void file_free_rcu(struct
static inline void file_free(struct file *f)
{
+ container_file_uncharge(f);
percpu_counter_dec(&nr_files);
call_rcu(&f->f_u.fu_rcuhead, file_free_rcu);
}
@@ -109,6 +111,10 @@ struct file *get_empty_filp(void)
percpu_counter_inc(&nr_files);
memset(f, 0, sizeof(*f));
+
+ if (container_file_charge(f))
+ goto fail_charge;
+
if (security_file_alloc(f))
goto fail_sec;
@@ -132,7 +138,10 @@ over:
goto fail;
fail_sec:
- file_free(f);
+ container_file_uncharge(f);
+fail_charge:
+ percpu_counter_dec(&nr_files);
+ kmem_cache_free(filp_cachep, f);
fail:
return NULL;
}
diff -upr linux-2.6.20.orig/fs/numfiles_container.c linux-2.6.20-0/fs/numfiles_container.c
--- linux-2.6.20.orig/fs/numfiles_container.c 2007-03-06 13:39:17.000000000 +0300
+++ linux-2.6.20-0/fs/numfiles_container.c 2007-03-06 13:33:28.000000000 +0300
@@ -0,0 +1,152 @@
+/*
+ * Numfiles accounting container
+ *
+ * Copyright 2007 OpenVZ SWsoft Inc
+ *
+ * Author: Pavel Emelianov <xemul@openvz.org>
+ *
+ */
+
+#include <linux/list.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/res_counter.h>
+#include <linux/numfiles_container.h>
+
+static struct container_subsys numfiles_subsys;
+
+struct files_container {
+ struct res_counter res;
+ struct container_subsys_state css;
+};
+
+static inline struct files_container *numfiles_from_cont(struct container *cnt)
+{
+ return container_of(container_subsys_state(cnt, &numfiles_subsys),
+ struct files_container, css);
+}
+
+int container_file_charge(struct file *file)
+{
+ struct files_container *fc;
+
+ rcu_read_lock();
+ fc = numfiles_from_cont(task_container(current, &numfiles_subsys));
+ css_get_current(&fc->css);
+ rcu_read_unlock();
+
+ if (res_counter_charge(&fc->res, 1)) {
+ css_put(&fc->css);
+ return -ENOMEM;
+ }
+
+ file->f_cont = fc;
+ return 0;
+}
+
+void container_file_uncharge(struct file *file)
+{
+ struct files_container *fc;
+
+ fc = file->f_cont;
+ res_counter_uncharge(&fc->res, 1);
+ css_put(&fc->css);
+}
+
+static int numfiles_create(struct container_subsys *ss, struct container *cont)
+{
+ struct files_container *fc;
+
+ fc = kzalloc(sizeof(struct files_container), GFP_KERNEL);
+ if (fc == NULL)
+ return -ENOMEM;
+
+ res_counter_init(&fc->res);
+ cont->subsys[numfiles_subsys.subsys_id] = &fc->css;
+ return 0;
+}
+
+static void numfiles_destroy(struct container_subsys *ss,
+ struct container *cont)
+{
+ kfree(numfiles_from_cont(cont));
+}
+
+
+static ssize_t numfiles_read(struct container *cont, struct cftype *cft,
+ struct file *file, char __user *userbuf,
+ size_t nbytes, loff_t *ppos)
+{
+ return res_counter_read(&numfiles_from_cont(cont)->res, cft->private,
+ userbuf, nbytes, ppos);
+}
+
+static ssize_t numfiles_write(struct container *cont, struct cftype *cft,
+ struct file *file, const char __user *userbuf,
+ size_t nbytes, loff_t *ppos)
+{
+ return res_counter_write(&numfiles_from_cont(cont)->res, cft->private,
+ userbuf, nbytes, ppos);
+}
+
+
+static struct cftype numfiles_usage = {
+ .name = "numfiles_usage",
+ .private = RES_USAGE,
+ .read = numfiles_read,
+};
+
+static struct cftype numfiles_limit = {
+ .name = "numfiles_limit",
+ .private = RES_LIMIT,
+ .read = numfiles_read,
+ .write = numfiles_write,
+};
+
+static struct cftype numfiles_failcnt = {
+ .name = "numfiles_failcnt",
+ .private = RES_FAILCNT,
+ .read = numfiles_read,
+};
+
+static int numfiles_populate(struct container_subsys *ss,
+ struct container *cont)
+{
+ int rc;
+
+ if ((rc = container_add_file(cont, &numfiles_usage)) < 0)
+ return rc;
+ if ((rc = container_add_file(cont, &numfiles_failcnt)) < 0)
+ return rc;
+ if ((rc = container_add_file(cont, &numfiles_limit)) < 0)
+ return rc;
+
+ return 0;
+}
+
+static struct files_container init_files_container;
+
+static __init int numfiles_create_early(struct container_subsys *ss,
+ struct container *cont)
+{
+ struct files_container *np;
+
+ np = &init_files_container;
+ res_counter_init(&np->res);
+ cont->subsys[numfiles_subsys.subsys_id] = &np->css;
+ ss->create = numfiles_create;
+ return 0;
+}
+
+static struct container_subsys numfiles_subsys = {
+ .name = "numfiles",
+ .create = numfiles_create_early,
+ .destroy = numfiles_destroy,
+ .populate = numfiles_populate,
+};
+
+void __init container_numfiles_init_early(void)
+{
+ container_register_subsys(&numfiles_subsys);
+}
+
diff -upr linux-2.6.20.orig/include/linux/fs.h linux-2.6.20-0/include/linux/fs.h
--- linux-2.6.20.orig/include/linux/fs.h 2007-03-06 13:33:28.000000000 +0300
+++ linux-2.6.20-0/include/linux/fs.h 2007-03-06 13:33:28.000000000 +0300
@@ -739,6 +739,9 @@ struct file {
spinlock_t f_ep_lock;
#endif /* #ifdef CONFIG_EPOLL */
struct address_space *f_mapping;
+#ifdef CONFIG_FILES_CONTAINER
+ struct files_container *f_cont;
+#endif
};
extern spinlock_t files_lock;
#define file_list_lock() spin_lock(&files_lock);
diff -upr linux-2.6.20.orig/include/linux/numfiles_container.h linux-2.6.20-0/include/linux/numfiles_container.h
--- linux-2.6.20.orig/include/linux/numfiles_container.h 2007-03-06 13:39:17.000000000 +0300
+++ linux-2.6.20-0/include/linux/numfiles_container.h 2007-03-06 13:33:28.000000000 +0300
@@ -0,0 +1,33 @@
+#ifndef __NUMFILES_CONTAINER_H__
+#define __NUMFILES_CONTAINER_H__
+/*
+ * Numfiles container
+ *
+ * Copyright 2007 OpenVZ SWsoft Inc
+ *
+ * Author: Pavel Emelianov <xemul@openvz.org>
+ *
+ */
+
+#ifdef CONFIG_FILES_CONTAINER
+int container_file_charge(struct file *file);
+void container_file_uncharge(struct file *file);
+
+void container_numfiles_init_early(void);
+#else
+static inline int container_file_charge(struct file *file)
+{
+ return 0;
+}
+
+static inline void container_file_uncharge(struct file *file)
+{
+}
+
+static inline void container_numfiles_init_early(void)
+{
+}
+#endif
+
+#endif
+
diff -upr linux-2.6.20.orig/init/Kconfig linux-2.6.20-0/init/Kconfig
--- linux-2.6.20.orig/init/Kconfig 2007-03-06 13:33:28.000000000 +0300
+++ linux-2.6.20-0/init/Kconfig 2007-03-06 13:33:28.000000000 +0300
@@ -265,6 +265,12 @@ config CPUSETS
help
Provides the-number-of-tasks accounting container
+config FILES_CONTAINER
+ bool "Numfiles accounting container"
+ select RESOURCE_COUNTERS
+ help
+ Provides the-number-of-files accounting container
+
config SYSFS_DEPRECATED
bool "Create deprecated sysfs files"
default y
diff -upr linux-2.6.20.orig/kernel/container.c linux-2.6.20-0/kernel/container.c
--- linux-2.6.20.orig/kernel/container.c 2007-03-06 13:33:28.000000000 +0300
+++ linux-2.6.20-0/kernel/container.c 2007-03-06 13:35:48.000000000 +0300
@@ -60,6 +60,7 @@
#include <linux/rss_container.h>
#include <linux/numproc_container.h>
+#include <linux/numfiles_container.h>
#define CONTAINER_SUPER_MAGIC 0x27e0eb
@@ -1721,6 +1725,7 @@ int __init container_init_early(void)
container_rss_init_early();
container_numproc_init_early();
+ container_numfiles_init_early();
return 0;
}
...
|
|
|
|
|
[RFC][PATCH 0/7] Resource controllers based on process containers
By: xemul on Tue, 06 March 2007 14:42
|
|
|
[RFC][PATCH 1/7] Resource counters
By: xemul on Tue, 06 March 2007 14:47
|
|
|
Re: [RFC][PATCH 1/7] Resource counters
|
|
|
Re: [RFC][PATCH 1/7] Resource counters
By: xemul on Wed, 07 March 2007 07:17
|
|
|
Re: [RFC][PATCH 1/7] Resource counters
|
|
|
Re: [RFC][PATCH 1/7] Resource counters
By: xemul on Sun, 11 March 2007 09:01
|
|
|
Re: [RFC][PATCH 1/7] Resource counters
By: ebiederm on Sun, 11 March 2007 19:00
|
|
|
Re: [RFC][PATCH 1/7] Resource counters
|
|
|
Re: [RFC][PATCH 1/7] Resource counters
By: ebiederm on Tue, 13 March 2007 09:09
|
|
|
Re: [RFC][PATCH 1/7] Resource counters
By: xemul on Tue, 13 March 2007 09:27
|
|
|
Re: [RFC][PATCH 1/7] Resource counters
|
|
|
Re: [RFC][PATCH 1/7] Resource counters
By: xemul on Tue, 13 March 2007 15:41
|
|
|
Re: [RFC][PATCH 1/7] Resource counters
|
|
|
Re: [RFC][PATCH 1/7] Resource counters
By: xemul on Wed, 14 March 2007 07:12
|
|
|
Re: [RFC][PATCH 1/7] Resource counters
By: ebiederm on Thu, 15 March 2007 16:51
|
|
|
Re: Re: [RFC][PATCH 1/7] Resource counters
By: dev on Tue, 13 March 2007 09:36
|
|
|
Re: [RFC][PATCH 1/7] Resource counters
|
|
|
[RFC][PATCH 2/7] RSS controller core
By: xemul on Tue, 06 March 2007 14:53
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
By: dev on Sun, 11 March 2007 12:13
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
By: ebiederm on Sun, 11 March 2007 19:34
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
By: xemul on Mon, 12 March 2007 09:02
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
By: xemul on Tue, 13 March 2007 07:17
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
By: xemul on Tue, 13 March 2007 15:32
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
By: dev on Tue, 13 March 2007 15:10
|
|
|
Re: Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: Re: [RFC][PATCH 2/7] RSS controller core
By: ebiederm on Tue, 13 March 2007 09:26
|
|
|
Re: Re: [RFC][PATCH 2/7] RSS controller core
By: dev on Tue, 13 March 2007 15:30
|
|
|
Re: Re: [RFC][PATCH 2/7] RSS controller core
By: dev on Tue, 13 March 2007 10:06
|
|
|
Re: Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
By: mel on Wed, 14 March 2007 15:38
|
|
|
Re: Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: Re: [RFC][PATCH 2/7] RSS controller core
By: ebiederm on Mon, 19 March 2007 17:41
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
By: xemul on Sun, 11 March 2007 09:08
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
By: xemul on Sun, 11 March 2007 15:04
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
By: xemul on Mon, 12 March 2007 08:31
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
By: xemul on Wed, 07 March 2007 07:25
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
By: ebiederm on Sun, 18 March 2007 16:58
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
By: akpm on Tue, 13 March 2007 06:04
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
By: Alan Cox on Tue, 13 March 2007 19:09
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
By: ebiederm on Fri, 16 March 2007 00:55
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
By: ebiederm on Fri, 16 March 2007 18:54
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
By: mel on Wed, 14 March 2007 16:47
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
By: dev on Tue, 13 March 2007 15:54
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
By: mel on Tue, 20 March 2007 18:57
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
By: ebiederm on Sun, 18 March 2007 17:42
|
|
|
Re: [RFC][PATCH 2/7] RSS controller core
|
|
|
controlling mmap()'d vs read/write() pages
|
|
|
Re: controlling mmap()'d vs read/write() pages
By: ebiederm on Tue, 20 March 2007 21:19
|
|
|
Re: controlling mmap()'d vs read/write() pages
|
|
|
Re: controlling mmap()'d vs read/write() pages
|
|
|
Re: controlling mmap()'d vs read/write() pages
By: ebiederm on Fri, 23 March 2007 10:12
|
|
|
Re: controlling mmap()'d vs read/write() pages
|
|
|
Re: controlling mmap()'d vs read/write() pages
|
|
|
Re: controlling mmap()'d vs read/write() pages
|
|
|
Re: controlling mmap()'d vs read/write() pages
|
|
|
Re: controlling mmap()'d vs read/write() pages
By: ebiederm on Fri, 23 March 2007 12:21
|
|
|
Re: controlling mmap()'d vs read/write() pages
|
|
|
[RFC][PATCH 3/7] Data structures changes for RSS accounting
By: xemul on Tue, 06 March 2007 14:55
|
|
|
Re: [RFC][PATCH 3/7] Data structures changes for RSS accounting
By: ebiederm on Sun, 11 March 2007 19:13
|
|
|
Re: [RFC][PATCH 3/7] Data structures changes for RSS accounting
By: dev on Mon, 12 March 2007 16:16
|
|
|
Re: [RFC][PATCH 3/7] Data structures changes for RSS accounting
|
|
|
Re: [RFC][PATCH 3/7] Data structures changes for RSS accounting
By: xemul on Mon, 12 March 2007 17:19
|
|
|
Re: [RFC][PATCH 3/7] Data structures changes for RSS accounting
|
|
|
Re: [RFC][PATCH 3/7] Data structures changes for RSS accounting
|
|
|
Re: [RFC][PATCH 3/7] Data structures changes for RSS accounting
By: xemul on Tue, 13 March 2007 07:10
|
|
|
[RFC][PATCH 4/7] RSS accounting hooks over the code
By: xemul on Tue, 06 March 2007 14:57
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
By: xemul on Wed, 14 March 2007 15:43
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
By: ebiederm on Sun, 11 March 2007 19:14
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
By: dev on Mon, 12 March 2007 16:23
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
By: dev on Mon, 12 March 2007 17:07
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
By: ebiederm on Tue, 13 March 2007 09:58
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
By: ebiederm on Tue, 13 March 2007 09:43
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
By: ebiederm on Tue, 13 March 2007 16:01
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
By: dev on Wed, 14 March 2007 16:16
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
|
|
|
Re: [RFC][PATCH 4/7] RSS accounting hooks over the code
|
|
|
[RFC][PATCH 5/7] Per-container OOM killer and page reclamation
By: xemul on Tue, 06 March 2007 15:01
|
|
|
Re: [RFC][PATCH 5/7] Per-container OOM killer and page reclamation
|
|
|
Re: [RFC][PATCH 5/7] Per-container OOM killer and page reclamation
By: xemul on Sun, 11 March 2007 08:39
|
|
|
[RFC][PATCH 6/7] Account for the number of tasks within container
By: xemul on Tue, 06 March 2007 15:02
|
|
|
Re: [RFC][PATCH 6/7] Account for the number of tasks within container
|
|
|
Re: [RFC][PATCH 6/7] Account for the number of tasks within container
By: xemul on Wed, 07 March 2007 07:10
|
|
|
Re: [RFC][PATCH 6/7] Account for the number of tasks within container
|
|
|
Re: [RFC][PATCH 6/7] Account for the number of tasks within container
By: xemul on Sun, 11 March 2007 08:34
|
|
|
[RFC][PATCH 7/7] Account for the number of files opened within container
By: xemul on Tue, 06 March 2007 15:05
|
|
|
Re: [RFC][PATCH 0/7] Resource controllers based on process containers
|
|
|
Re: [RFC][PATCH 0/7] Resource controllers based on process containers
By: xemul on Wed, 07 March 2007 07:27
|
|
|
Re: [RFC][PATCH 0/7] Resource controllers based on process containers
|
|
|
Re: [RFC][PATCH 0/7] Resource controllers based on process containers
By: xemul on Wed, 07 March 2007 07:30
|
|
|
Re: [RFC][PATCH 0/7] Resource controllers based on process containers
By: dev on Wed, 07 March 2007 09:30
|
Goto Forum:
Current Time: Sun Dec 08 10:28:18 GMT 2024
Total time taken to generate the page: 0.02830 seconds
|