Skip to content

Commit 1b0f7ff

Browse files
oleg-nesterovtorvalds
authored andcommitted
pids: kill signal_struct-> __pgrp/__session and friends
We are wasting 2 words in signal_struct without any reason to implement task_pgrp_nr() and task_session_nr(). task_session_nr() has no callers since 2e2ba22, we can remove it. task_pgrp_nr() is still (I believe wrongly) used in fs/autofsX and fs/coda. This patch reimplements task_pgrp_nr() via task_pgrp_nr_ns(), and kills __pgrp/__session and the related helpers. The change in drivers/char/tty_io.c is cosmetic, but hopefully makes sense anyway. Signed-off-by: Oleg Nesterov <[email protected]> Acked-by: Alan Cox <[email protected]> [tty parts] Cc: Cedric Le Goater <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Eric Biederman <[email protected]> Cc: Pavel Emelyanov <[email protected]> Cc: Serge Hallyn <[email protected]> Cc: Sukadev Bhattiprolu <[email protected]> Cc: Roland McGrath <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 52ee2df commit 1b0f7ff

File tree

5 files changed

+12
-51
lines changed

5 files changed

+12
-51
lines changed

drivers/char/tty_io.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2681,7 +2681,7 @@ void __do_SAK(struct tty_struct *tty)
26812681
/* Kill the entire session */
26822682
do_each_pid_task(session, PIDTYPE_SID, p) {
26832683
printk(KERN_NOTICE "SAK: killed process %d"
2684-
" (%s): task_session_nr(p)==tty->session\n",
2684+
" (%s): task_session(p)==tty->session\n",
26852685
task_pid_nr(p), p->comm);
26862686
send_sig(SIGKILL, p, 1);
26872687
} while_each_pid_task(session, PIDTYPE_SID, p);
@@ -2691,7 +2691,7 @@ void __do_SAK(struct tty_struct *tty)
26912691
do_each_thread(g, p) {
26922692
if (p->signal->tty == tty) {
26932693
printk(KERN_NOTICE "SAK: killed process %d"
2694-
" (%s): task_session_nr(p)==tty->session\n",
2694+
" (%s): task_session(p)==tty->session\n",
26952695
task_pid_nr(p), p->comm);
26962696
send_sig(SIGKILL, p, 1);
26972697
continue;

include/linux/sched.h

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -547,25 +547,8 @@ struct signal_struct {
547547

548548
struct list_head cpu_timers[3];
549549

550-
/* job control IDs */
551-
552-
/*
553-
* pgrp and session fields are deprecated.
554-
* use the task_session_Xnr and task_pgrp_Xnr routines below
555-
*/
556-
557-
union {
558-
pid_t pgrp __deprecated;
559-
pid_t __pgrp;
560-
};
561-
562550
struct pid *tty_old_pgrp;
563551

564-
union {
565-
pid_t session __deprecated;
566-
pid_t __session;
567-
};
568-
569552
/* boolean value for session group leader */
570553
int leader;
571554

@@ -1469,16 +1452,6 @@ static inline int rt_task(struct task_struct *p)
14691452
return rt_prio(p->prio);
14701453
}
14711454

1472-
static inline void set_task_session(struct task_struct *tsk, pid_t session)
1473-
{
1474-
tsk->signal->__session = session;
1475-
}
1476-
1477-
static inline void set_task_pgrp(struct task_struct *tsk, pid_t pgrp)
1478-
{
1479-
tsk->signal->__pgrp = pgrp;
1480-
}
1481-
14821455
static inline struct pid *task_pid(struct task_struct *task)
14831456
{
14841457
return task->pids[PIDTYPE_PID].pid;
@@ -1552,11 +1525,6 @@ static inline pid_t task_tgid_vnr(struct task_struct *tsk)
15521525
}
15531526

15541527

1555-
static inline pid_t task_pgrp_nr(struct task_struct *tsk)
1556-
{
1557-
return tsk->signal->__pgrp;
1558-
}
1559-
15601528
static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk,
15611529
struct pid_namespace *ns)
15621530
{
@@ -1569,11 +1537,6 @@ static inline pid_t task_pgrp_vnr(struct task_struct *tsk)
15691537
}
15701538

15711539

1572-
static inline pid_t task_session_nr(struct task_struct *tsk)
1573-
{
1574-
return tsk->signal->__session;
1575-
}
1576-
15771540
static inline pid_t task_session_nr_ns(struct task_struct *tsk,
15781541
struct pid_namespace *ns)
15791542
{
@@ -1585,6 +1548,12 @@ static inline pid_t task_session_vnr(struct task_struct *tsk)
15851548
return __task_pid_nr_ns(tsk, PIDTYPE_SID, NULL);
15861549
}
15871550

1551+
/* obsolete, do not use */
1552+
static inline pid_t task_pgrp_nr(struct task_struct *tsk)
1553+
{
1554+
return task_pgrp_nr_ns(tsk, &init_pid_ns);
1555+
}
1556+
15881557
/**
15891558
* pid_alive - check that a task structure is not stale
15901559
* @p: Task structure to be checked.

kernel/exit.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -357,16 +357,12 @@ static void reparent_to_kthreadd(void)
357357
void __set_special_pids(struct pid *pid)
358358
{
359359
struct task_struct *curr = current->group_leader;
360-
pid_t nr = pid_nr(pid);
361360

362-
if (task_session(curr) != pid) {
361+
if (task_session(curr) != pid)
363362
change_pid(curr, PIDTYPE_SID, pid);
364-
set_task_session(curr, nr);
365-
}
366-
if (task_pgrp(curr) != pid) {
363+
364+
if (task_pgrp(curr) != pid)
367365
change_pid(curr, PIDTYPE_PGID, pid);
368-
set_task_pgrp(curr, nr);
369-
}
370366
}
371367

372368
static void set_special_pids(struct pid *pid)

kernel/fork.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,8 +1265,6 @@ static struct task_struct *copy_process(unsigned long clone_flags,
12651265
p->signal->leader_pid = pid;
12661266
tty_kref_put(p->signal->tty);
12671267
p->signal->tty = tty_kref_get(current->signal->tty);
1268-
set_task_pgrp(p, task_pgrp_nr(current));
1269-
set_task_session(p, task_session_nr(current));
12701268
attach_pid(p, PIDTYPE_PGID, task_pgrp(current));
12711269
attach_pid(p, PIDTYPE_SID, task_session(current));
12721270
list_add_tail_rcu(&p->tasks, &init_task.tasks);

kernel/sys.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,10 +1013,8 @@ SYSCALL_DEFINE2(setpgid, pid_t, pid, pid_t, pgid)
10131013
if (err)
10141014
goto out;
10151015

1016-
if (task_pgrp(p) != pgrp) {
1016+
if (task_pgrp(p) != pgrp)
10171017
change_pid(p, PIDTYPE_PGID, pgrp);
1018-
set_task_pgrp(p, pid_nr(pgrp));
1019-
}
10201018

10211019
err = 0;
10221020
out:

0 commit comments

Comments
 (0)