mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Q: kernel/pids.c code
       [not found] ` <1310277139.20040415001215@7ka.mipt.ru>
@ 2004-04-14 20:13   ` Kirill Korotaev
  0 siblings, 0 replies; only message in thread
From: Kirill Korotaev @ 2004-04-14 20:13 UTC (permalink / raw)
  To: linux-kernel

Hello all,

I have two questions both concerning code located in kernel/pids.c:

1. why do we hold task.struct pid_link pids[].pid in task_struct?
I looked through the code and found that such solution is ugly at
least because:
- it occupies at least 7*4=28 more integers in task_struct then could
be. Note that this memory is not used everytime.
- pids can held reference to task_struct thus making it's lifetime longer
and less predictable. Memory consumption is unpredictable.
- the code is really unreadable and messy
Why struct pid is not allocated in kmem_cache instead?

2. function switch_exec_pids() calls _detach_pid() 6 times
and attach_pid() 8 times, i.e. we put 6 references and take 8.
is it bug? if so, then it looks like
pids (SID and PGID) can leak (with corresponding task_structs)?

void switch_exec_pids(task_t *leader, task_t *thread)
{
         _detach_pid(leader, PIDTYPE_PID);
         _detach_pid(leader, PIDTYPE_TGID);
         _detach_pid(leader, PIDTYPE_PGID);
         _detach_pid(leader, PIDTYPE_SID);

         _detach_pid(thread, PIDTYPE_PID);
         _detach_pid(thread, PIDTYPE_TGID);

         leader->pid = leader->tgid = thread->pid;
         thread->pid = thread->tgid;

         attach_pid(thread, PIDTYPE_PID, thread->pid);
         attach_pid(thread, PIDTYPE_TGID, thread->tgid);
         attach_pid(thread, PIDTYPE_PGID, thread->pgrp);
         attach_pid(thread, PIDTYPE_SID, thread->session);

         attach_pid(leader, PIDTYPE_PID, leader->pid);
         attach_pid(leader, PIDTYPE_TGID, leader->tgid);
         attach_pid(leader, PIDTYPE_PGID, leader->pgrp);
         attach_pid(leader, PIDTYPE_SID, leader->session);
}

Kirill



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-04-14 20:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <407D57F4.7090409@sw.ru>
     [not found] ` <1310277139.20040415001215@7ka.mipt.ru>
2004-04-14 20:13   ` Q: kernel/pids.c code Kirill Korotaev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®