[PATCH] [RFC] Throttle swappiness for interactive tasks

अभिजित भोपटकर (Abhijit Bhopatkar)
2007-04-18T12:10:55Z

The mm structures of interactive tasks are marked and
the pages belonging to them are never shifted to inactive
list in lru algorithm. Thus keeping interactive tasks in
memory as long as possible.
The interactivity is already determined by schedular so
we reuse that knowledge to mark the mm structures.

Signed-off-by: Abhijit Bhopatkar <bainonline@gmail.com>
---
include/linux/init_task.h | 1 +
include/linux/sched.h | 4 ++++
kernel/sched.c | 4 ++++
mm/rmap.c | 5 +++++
4 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/include/linux/init_task.h b/include/linux/init_task.h
index a2d95ff..12ba3c1 100644
--- a/include/linux/init_task.h
+++ b/include/linux/init_task.h
@@ -54,6 +54,7 @@
.page_table_lock = __SPIN_LOCK_UNLOCKED(name.page_table_lock), \
.mmlist = LIST_HEAD_INIT(name.mmlist), \
.cpu_vm_mask = CPU_MASK_ALL, \
+ .interactive = 0, \
}

#define INIT_SIGNALS(sig) { \
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 49fe299..1f233e7 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -373,6 +373,10 @@ struct mm_struct {
/* aio bits */
rwlock_t ioctx_list_lock;
struct kioctx *ioctx_list;
+
+ /* interactivity flag */
+ unsigned char interactive;
+
};

struct sighand_struct {
diff --git a/kernel/sched.c b/kernel/sched.c
index b9a6837..72caf94 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -746,6 +746,10 @@ static inline int __normal_prio(struct task_struct *p)
prio = MAX_RT_PRIO;
if (prio > MAX_PRIO-1)
prio = MAX_PRIO-1;
+
+ /* Update interactivity flag in mm if interactive. */
+ if(p->mm && TASK_INTERACTIVE(p))
+ p->mm->interactive = 1;
return prio;
}

diff --git a/mm/rmap.c b/mm/rmap.c
index b82146e..0735168 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -317,6 +317,11 @@ static int page_referenced_one(struct page *page,
rwsem_is_locked(&mm->mmap_sem))
referenced++;

+ /* Pretend the page is referenced if the task is
+ interactive. */
+ if (mm != current->mm && mm->interactive)
+ referenced++;
+
(*mapcount)--;
pte_unmap_unlock(pte, ptl);
out:
--
1.4.4.2