Home » Mailing lists » Devel » [RFC][PATCH 0/7] Resource controllers based on process containers
[RFC][PATCH 5/7] Per-container OOM killer and page reclamation [message #10893 is a reply to message #10888] |
Tue, 06 March 2007 15:01 |
xemul
Messages: 248 Registered: November 2005
|
Senior Member |
|
|
* container_try_to_free_pages() walks containers
page list and tries to shrink pages. This is based
on try_to_free_pages() and Co code.
Called from core code when no resource left at the
moment of page touching.
* container_out_of_memory() selects a process to be
killed which mm_struct belongs to container in question.
Called from core code when no resources left and no
pages were reclaimed.
diff -upr linux-2.6.20.orig/mm/oom_kill.c linux-2.6.20-0/mm/oom_kill.c
--- linux-2.6.20.orig/mm/oom_kill.c 2007-03-06 13:33:28.000000000 +0300
+++ linux-2.6.20-0/mm/oom_kill.c 2007-03-06 13:33:28.000000000 +0300
@@ -24,6 +24,7 @@
#include <linux/cpuset.h>
#include <linux/module.h>
#include <linux/notifier.h>
+#include <linux/rss_container.h>
int sysctl_panic_on_oom;
/* #define DEBUG */
@@ -47,7 +48,8 @@ int sysctl_panic_on_oom;
* of least surprise ... (be careful when you change it)
*/
-unsigned long badness(struct task_struct *p, unsigned long uptime)
+unsigned long badness(struct task_struct *p, unsigned long uptime,
+ struct rss_container *rss)
{
unsigned long points, cpu_time, run_time, s;
struct mm_struct *mm;
@@ -60,6 +62,13 @@ unsigned long badness(struct task_struct
return 0;
}
+#ifdef CONFIG_RSS_CONTAINER
+ if (rss != NULL && mm->rss_container != rss) {
+ task_unlock(p);
+ return 0;
+ }
+#endif
+
/*
* The memory size of the process is the basis for the badness.
*/
@@ -200,7 +209,8 @@ static inline int constrained_alloc(stru
*
* (not docbooked, we don't want this one cluttering up the manual)
*/
-static struct task_struct *select_bad_process(unsigned long *ppoints)
+static struct task_struct *select_bad_process(unsigned long *ppoints,
+ struct rss_container *rss)
{
struct task_struct *g, *p;
struct task_struct *chosen = NULL;
@@ -254,7 +264,7 @@ static struct task_struct *select_bad_pr
if (p->oomkilladj == OOM_DISABLE)
continue;
- points = badness(p, uptime.tv_sec);
+ points = badness(p, uptime.tv_sec, rss);
if (points > *ppoints || !chosen) {
chosen = p;
*ppoints = points;
@@ -435,7 +445,7 @@ retry:
* Rambo mode: Shoot down a process and hope it solves whatever
* issues we may have.
*/
- p = select_bad_process(&points);
+ p = select_bad_process(&points, NULL);
if (PTR_ERR(p) == -1UL)
goto out;
@@ -464,3 +474,27 @@ out:
if (!test_thread_flag(TIF_MEMDIE))
schedule_timeout_uninterruptible(1);
}
+
+#ifdef CONFIG_RSS_CONTAINER
+void container_out_of_memory(struct rss_container *rss)
+{
+ unsigned long points = 0;
+ struct task_struct *p;
+
+ container_lock();
+ read_lock(&tasklist_lock);
+retry:
+ p = select_bad_process(&points, rss);
+ if (PTR_ERR(p) == -1UL)
+ goto out;
+
+ if (!p)
+ p = current;
+
+ if (oom_kill_process(p, points, "Container out of memory"))
+ goto retry;
+out:
+ read_unlock(&tasklist_lock);
+ container_unlock();
+}
+#endif
diff -upr linux-2.6.20.orig/mm/vmscan.c linux-2.6.20-0/mm/vmscan.c
--- linux-2.6.20.orig/mm/vmscan.c 2007-02-04 21:44:54.000000000 +0300
+++ linux-2.6.20-0/mm/vmscan.c 2007-03-06 13:33:28.000000000 +0300
@@ -45,6 +45,8 @@
#include "internal.h"
+#include <linux/rss_container.h>
+
struct scan_control {
/* Incremented by the number of inactive pages that were scanned */
unsigned long nr_scanned;
@@ -1097,6 +1099,194 @@ out:
return ret;
}
+#ifdef CONFIG_RSS_CONTAINER
+/*
+ * These are containers' inactive and active pages shrinkers.
+ * Thes works like shrink_inactive_list() and shrink_active_list()
+ *
+ * Two main differences is that container_isolate_pages() is used to isolate
+ * pages, and that reclaim_mapped is considered to be 1 as hitting BC
+ * limit implies we have to shrink _mapped_ pages
+ */
+static unsigned long container_shrink_pages_inactive(unsigned long max_scan,
+ struct rss_container *rss, struct scan_control *sc)
+{
+ LIST_HEAD(page_list);
+ unsigned long nr_scanned = 0;
+ unsigned long nr_reclaimed = 0;
+
+ do {
+ struct page *page;
+ unsigned long nr_taken;
+ unsigned long nr_scan;
+ struct zone *z;
+
+ nr_taken = container_isolate_pages(sc->swap_cluster_max, rss,
+ &page_list, 0, &nr_scan);
+
+ nr_scanned += nr_scan;
+ nr_reclaimed += shrink_page_list(&page_list, sc);
+ if (nr_taken == 0)
+ goto done;
+
+ while (!list_empty(&page_list)) {
+ page = lru_to_page(&page_list);
+ z = page_zone(page);
+
+ spin_lock_irq(&z->lru_lock);
+ VM_BUG_ON(PageLRU(page));
+ SetPageLRU(page);
+ list_del(&page->lru);
+ if (PageActive(page))
+ add_page_to_active_list(z, page);
+ else
+ add_page_to_inactive_list(z, page);
+ spin_unlock_irq(&z->lru_lock);
+
+ put_page(page);
+ }
+ } while (nr_scanned < max_scan);
+done:
+ return nr_reclaimed;
+}
+
+static void container_shrink_pages_active(unsigned long nr_pages,
+ struct rss_container *rss, struct scan_control *sc)
+{
+ LIST_HEAD(l_hold);
+ LIST_HEAD(l_inactive);
+ LIST_HEAD(l_active);
+ struct page *page;
+ unsigned long nr_scanned;
+ unsigned long nr_deactivated = 0;
+ struct zone *z;
+
+ container_isolate_pages(nr_pages, rss, &l_hold, 1, &nr_scanned);
+
+ while (!list_empty(&l_hold)) {
+ cond_resched();
+ page = lru_to_page(&l_hold);
+ list_del(&page->lru);
+ if (page_mapped(page)) {
+ if ((total_swap_pages == 0 && PageAnon(page)) ||
+ page_referenced(page, 0)) {
+ list_add(&page->lru, &l_active);
+ continue;
+ }
+ }
+ nr_deactivated++;
+ list_add(&page->lru, &l_inactive);
+ }
+
+ while (!list_empty(&l_inactive)) {
+ page = lru_to_page(&l_inactive);
+ z = page_zone(page);
+
+ spin_lock_irq(&z->lru_lock);
+ VM_BUG_ON(PageLRU(page));
+ SetPageLRU(page);
+ VM_BUG_ON(!PageActive(page));
+ ClearPageActive(page);
+
+ list_move(&page->lru, &z->inactive_list);
+ z->nr_inactive++;
+ spin_unlock_irq(&z->lru_lock);
+
+ put_page(page);
+ }
+
+ while (!list_empty(&l_active)) {
+ page = lru_to_page(&l_active);
+ z = page_zone(page);
+
+ spin_lock_irq(&z->lru_lock);
+ VM_BUG_ON(PageLRU(page));
+ SetPageLRU(page);
+ VM_BUG_ON(!PageActive(page));
+ list_move(&page->lru, &z->active_list);
+ z->nr_active++;
+ spin_unlock_irq(&z->lru_lock);
+
+ put_page(page);
+ }
+}
+
+/*
+ * This is a reworked shrink_zone() routine - it scans active pages firts,
+ * then inactive and returns the number of pages reclaimed
+ */
+static unsigned long container_shrink_pages(int priority,
+ struct rss_container *rss, struct scan_control *sc)
+{
+ unsigned long nr_pages;
+ unsigned long nr_to_scan;
+ unsigned long nr_reclaimed = 0;
+
+ nr_pages = (container_nr_physpages(rss) >> priority) + 1;
+ if (nr_pages < sc->swap_cluster_max)
+ nr_pages = 0;
+
+ while (nr_pages) {
+ nr_to_scan = min(nr_pages, (unsigned long)sc->swap_cluster_max);
+ nr_pages -= nr_to_scan;
+ container_shrink_pages_active(nr_to_scan, rss, sc);
+ }
+
+ nr_pages = (container_nr_physpages(rss) >> priority) + 1;
+ if (nr_pages < sc->swap_cluster_max)
+ nr_pages = 0;
+
+ while (nr_pages) {
+ nr_to_scan = min(nr_pages, (unsigned long)sc->swap_cluster_max);
+ nr_pages -= nr_to_scan;
+ nr_reclaimed += container_shrink_pages_inactive(nr_to_scan, rss, sc);
+ }
+
+ throttle_vm_writeout();
+ return nr_reclaimed;
+}
+
+/*
+ * This functions works like try_to_free_pages() - it tries
+ * to shrink bc's pages with increasing priority
+ */
+unsigned long container_try_to_free_pages(struct rss_container *rss)
+{
+ int priority;
+ int ret = 0;
+ unsigned long total_scanned = 0;
+ unsigned long nr_reclaimed = 0;
+ struct scan_control sc = {
+ .gfp_mask = GFP_KERNEL,
+ .may_writepage = !laptop_mode,
+ .swap_cluster_max = SWAP_CLUSTER_MAX,
+ .may_swap = 1,
+ .swappiness = vm_swappiness,
+ };
+
+ for (priority = DEF_PRIORITY; priority >= 0; priority--) {
+ sc.nr_scanned = 0;
+ nr_reclaimed += container_shrink_pages(priority, rss, &sc);
+ total_scanned += sc.nr_scanned;
+ if (nr_reclaimed > 1) {
+ ret = 1;
+ goto out;
+ }
+
+ if (total_scanned > sc.swap_cluster_max +
+ sc.swap_cluster_max / 2) {
+ wakeup_pdflush(laptop_mode ? 0 : total_scanned);
+ sc.may_writepage = 1;
+ }
+
+ if (sc.nr_scanned && priority < DEF_PRIORITY - 2)
+ congestion_wait(WRITE, HZ/10);
+ }
+out:
+ return ret;
+}
+#endif
+
/*
* For kswapd, balance_pgdat() will work across all this node's zones until
* they are all at pages_high.
...
|
|
|
|
|
[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 01:02:19 GMT 2024
Total time taken to generate the page: 0.02742 seconds
|