Skip to contentSkip to conversation

Memory leak in 2.5.64

Linux-ia64 Peter Chubb 2 participants 2 messages Mar 11, 2003 – Mar 12, 2003

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

Hi David,
The way that tasks need to be freed has changed since 2.5.61 --- I
think we need to do something like the attached patch (keep __put_task_struct() in kernel/fork.c; have ia64-specific free_task_struct() in arch/ia64/kernel/process.c) otherwise the user_struct will never have its reference count deleted and so will not be freed.

arch/ia64/kernel/process.c +2 -2
diff -Nur --exclude=RCS --exclude=CVS --exclude=SCCS --exclude=BitKeeper --exclude=ChangeSet linux-2.5.64-davidm/arch/ia64/kernel/process.c linux-2.5-EXPORT/arch/ia64/kernel/process.c
@@ -751,7 +751,7 @@
 }
 
 void
-__put_task_struct (struct task_struct *tsk)
+free_task_struct(struct task_struct *tsk)
 {
-	free_pages((unsigned long) tsk, KERNEL_STACK_SIZE_ORDER);
+	free_pages((unsigned long)tsk, KERNEL_STACK_SIZE_ORDER);
 }
kernel/fork.c +16 -12
diff -Nur --exclude=RCS --exclude=CVS --exclude=SCCS --exclude=BitKeeper --exclude=ChangeSet linux-2.5.64-davidm/kernel/fork.c linux-2.5-EXPORT/kernel/fork.c
@@ -38,7 +38,9 @@
 #include <asm/cacheflush.h>
 #include <asm/tlbflush.h>
 
+#ifndef CONFIG_IA64
 static kmem_cache_t *task_struct_cachep;
+#endif
 
 extern int copy_semundo(unsigned long clone_flags, struct task_struct *tsk);
 extern void exit_semundo(struct task_struct *tsk);
@@ -53,13 +55,6 @@
 
 rwlock_t tasklist_lock __cacheline_aligned = RW_LOCK_UNLOCKED;  /* outer */
 
-/*
- * A per-CPU task cache - this relies on the fact that
- * the very last portion of sys_exit() is executed with
- * preemption turned off.
- */
-static task_t *task_cache[NR_CPUS] __cacheline_aligned;
-
 int nr_processes(void)
 {
 	int cpu;
@@ -72,6 +67,14 @@
 	return total;
 }
 
+#ifndef CONFIG_IA64
+/*
+ * A per-CPU task cache - this relies on the fact that
+ * the very last portion of sys_exit() is executed with
+ * preemption turned off.
+ */
+task_t *task_cache[NR_CPUS] __cacheline_aligned;
+
 static void free_task_struct(struct task_struct *tsk)
 {
 	/*
@@ -95,8 +98,10 @@
 		put_cpu();
 	}
 }
+#else
+extern void free_task_struct(struct task_struct *tsk);
+#endif
 
-#if 0
 void __put_task_struct(struct task_struct *tsk)
 {
 	WARN_ON(!(tsk->state & (TASK_DEAD | TASK_ZOMBIE)));
@@ -107,7 +112,6 @@
 	free_uid(tsk->user);
 	free_task_struct(tsk);
 }
-#endif
 
 void add_wait_queue(wait_queue_head_t *q, wait_queue_t * wait)
 {
@@ -187,13 +191,14 @@
 void __init fork_init(unsigned long mempages)
 {
 	/* create a slab on which task_structs can be allocated */
+#ifndef CONFIG_IA64
 	task_struct_cachep  		kmem_cache_create("task_struct",
 				  sizeof(struct task_struct),0,
 				  SLAB_HWCACHE_ALIGN, NULL, NULL);
 	if (!task_struct_cachep)
 		panic("fork_init(): cannot create task_struct SLAB cache");
-
+#endif
 	/*
 	 * The default maximum number of threads is set to a safe
 	 * value: the thread structures can take up at most half
@@ -210,7 +215,7 @@
 	init_task.rlim[RLIMIT_NPROC].rlim_max = max_threads/2;
 }
 
-#if 1
+#ifdef CONFIG_IA64
 extern struct task_struct *dup_task_struct (struct task_struct *orig);
 #else
 
@@ -247,7 +252,6 @@
 }
 
 #endif
-
 #ifdef CONFIG_MMU
 static inline int dup_mmap(struct mm_struct * mm, struct mm_struct * oldmm)
 {
#1 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · William Lee Irwin III

William> On Tue, Mar 11, 2003 at 02:44:14PM +1100, Peter Chubb

Quoted 6 lines · William> wrote:
Quoted 6 lines

The way that tasks need to be freed has changed since 2.5.61 --- I think we need to do something like the attached patch (keep __put_task_struct() in kernel/fork.c; have ia64-specific free_task_struct() in arch/ia64/kernel/process.c) otherwise the user_struct will never have its reference count deleted and so will not be freed.

William> I think you might be in trouble. From entry.S:

William> /* * Invoke schedule_tail(task) while preserving
William> in0-in7, which may be nee ded * in case a system call gets William> restarted. */ GLOBAL_ENTRY(ia64_invoke_schedule_tail)

William> Well, you're going to need to pass a parameter to William> schedule_tail() namely, the previous task, and find some William> other way to save in0-in7. schedule_tail() now relies on William> the task getting passed to it to free it.

That's why ia64_invoke_schedule_tail() exists in the first place: the previously running task is passed in r8. In other words: no problem.

	--david