summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKirill Korotaev <kksx@mail.ru>2004-09-02 00:42:48 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2004-09-02 00:42:48 -0700
commit37cbd41da09cb39c9896c04ed8baac7526bb9547 (patch)
treec56359f143f02c3cf50996fb25a82fe896fae1ff /include
parent3345ee71e2303c7c3d70de11d812306adc648865 (diff)
[PATCH] fixed pidhashing patch
This patch fixes strange and obscure pid implementation in current kernels: - it removes calling of put_task_struct() from detach_pid() under tasklist_lock. This allows to use blocking calls in security_task_free() hooks (in __put_task_struct()). - it saves some space = 5*5 ints = 100 bytes in task_struct - it's smaller and tidy, more straigthforward and doesn't use any knowledge about pids using and assignment. - it removes pid_links and pid_struct doesn't hold reference counters on task_struct. instead, new pid_structs and linked altogether and only one of them is inserted in hash_list. Signed-off-by: Kirill Korotaev (kksx@mail.ru) Signed-off-by: William Irwin <wli@holomorphy.com> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/pid.h44
-rw-r--r--include/linux/sched.h9
2 files changed, 21 insertions, 32 deletions
diff --git a/include/linux/pid.h b/include/linux/pid.h
index 02fb2d216d2b..5f74c4ab0d11 100644
--- a/include/linux/pid.h
+++ b/include/linux/pid.h
@@ -12,35 +12,22 @@ enum pid_type
struct pid
{
- /* Try to keep hash_chain in the same cacheline as nr for find_pid */
- struct hlist_node hash_chain;
+ /* Try to keep pid_chain in the same cacheline as nr for find_pid */
int nr;
- atomic_t count;
- struct task_struct *task;
- struct list_head task_list;
-};
-
-struct pid_link
-{
- struct list_head pid_chain;
- struct pid *pidptr;
- struct pid pid;
+ struct hlist_node pid_chain;
+ /* list of pids with the same nr, only one of them is in the hash */
+ struct list_head pid_list;
};
#define pid_task(elem, type) \
- list_entry(elem, struct task_struct, pids[type].pid_chain)
+ list_entry(elem, struct task_struct, pids[type].pid_list)
/*
- * attach_pid() and link_pid() must be called with the tasklist_lock
+ * attach_pid() and detach_pid() must be called with the tasklist_lock
* write-held.
*/
extern int FASTCALL(attach_pid(struct task_struct *task, enum pid_type type, int nr));
-extern void FASTCALL(link_pid(struct task_struct *task, struct pid_link *link, struct pid *pid));
-
-/*
- * detach_pid() must be called with the tasklist_lock write-held.
- */
extern void FASTCALL(detach_pid(struct task_struct *task, enum pid_type));
/*
@@ -53,13 +40,16 @@ extern int alloc_pidmap(void);
extern void FASTCALL(free_pidmap(int));
extern void switch_exec_pids(struct task_struct *leader, struct task_struct *thread);
-#define for_each_task_pid(who, type, task, elem, pid) \
- if ((pid = find_pid(type, who))) \
- for (elem = pid->task_list.next, \
- prefetch(elem->next), \
- task = pid_task(elem, type); \
- elem != &pid->task_list; \
- elem = elem->next, prefetch(elem->next), \
- task = pid_task(elem, type))
+#define do_each_task_pid(who, type, task) \
+ if ((task = find_task_by_pid_type(type, who))) { \
+ prefetch((task)->pids[type].pid_list.next); \
+ do {
+
+#define while_each_task_pid(who, type, task) \
+ task = pid_task((task)->pids[type].pid_list.next,\
+ type); \
+ prefetch((task)->pids[type].pid_list.next); \
+ } while (hlist_unhashed(&(task)->pids[type].pid_chain));\
+ } \
#endif /* _LINUX_PID_H */
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 3aaf8e5f2216..5cf33f072140 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -494,7 +494,7 @@ struct task_struct {
struct task_struct *group_leader; /* threadgroup leader */
/* PID/PID hash table linkage. */
- struct pid_link pids[PIDTYPE_MAX];
+ struct pid pids[PIDTYPE_MAX];
wait_queue_head_t wait_chldexit; /* for wait4() */
struct completion *vfork_done; /* for vfork() */
@@ -673,7 +673,8 @@ extern struct task_struct init_task;
extern struct mm_struct init_mm;
-extern struct task_struct *find_task_by_pid(int pid);
+#define find_task_by_pid(nr) find_task_by_pid_type(PIDTYPE_PID, nr)
+extern struct task_struct *find_task_by_pid_type(int type, int pid);
extern void set_special_pids(pid_t session, pid_t pgrp);
extern void __set_special_pids(pid_t session, pid_t pgrp);
@@ -876,9 +877,7 @@ extern task_t * FASTCALL(next_thread(const task_t *p));
static inline int thread_group_empty(task_t *p)
{
- struct pid *pid = p->pids[PIDTYPE_TGID].pidptr;
-
- return pid->task_list.next->next == &pid->task_list;
+ return list_empty(&p->pids[PIDTYPE_TGID].pid_list);
}
#define delay_group_leader(p) \