Skip to contentSkip to conversation

2.4.23 *_task_struct() observations ...

DISCUSSION Herbert Poetzl 2 participants 2 messages Dec 1, 2003

lore
Share & tools
lore
#0 lore raw

Hi All!

just wanted to get an opinion on the following ...

include/asm-i386/processor.h defines ...

  #define alloc_task_struct() ((struct task_struct *) \
				__get_free_pages(GFP_KERNEL,1))

#define free_task_struct(p) free_pages((unsigned long) (p), 1) #define get_task_struct(tsk) atomic_inc(&virt_to_page(tsk)->count)

now there seems to be no put_task_struct(), but there are some examples where get/free is used where I would expect a put_* ...

fs/proc/base.c for example does:

        read_lock(&tasklist_lock);
        task = find_task_by_pid(pid);
        if (task)
                get_task_struct(task);
        read_unlock(&tasklist_lock);
        if (!task)
                goto out;

        inode = proc_pid_make_inode(dir->i_sb, task, PROC_PID_INO);

        free_task_struct(task);

which is a little suspicious ...

please could anybody explain the logic behind that? (if it isn't a widespread bug(tm))

TIA,
Herbert

#1 lore raw
Quoted 4 lines · Herbert Poetzl

just wanted to get an opinion on the following ...

include/asm-i386/processor.h defines ...

Quoted 8 lines
  #define alloc_task_struct() ((struct task_struct *) \
				__get_free_pages(GFP_KERNEL,1))

#define free_task_struct(p) free_pages((unsigned long) (p), 1) #define get_task_struct(tsk) atomic_inc(&virt_to_page(tsk)->count)

now there seems to be no put_task_struct(), but
there are some examples where get/free is used
where I would expect a put_* ...

put_* is free_*. The reference count for the task struct is the page count (virt_to_page(tsk)->count).

Signature · 4 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 PCMCIA      - http://pcmcia.arm.linux.org.uk/
                 2.6 Serial core