Commit 878ff729 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by James Toy

The exiting sub-thread flushes /proc/pid only, but this doesn't buy too

much: ps and friends mostly use /proc/tid/task/pid.

Remove "if (thread_group_leader())" checks from proc_flush_task() path,
this means we always remove /proc/tid/task/pid dentry on exit, and this
actually matches the comment above proc_flush_task().

The test-case:

	static void* tfunc(void *arg)
	{
		char name[256];

		sprintf(name, "/proc/%d/task/%ld/status", getpid(), gettid());
		close(open(name, O_RDONLY));

		return NULL;
	}

	int main(void)
	{
		pthread_t t;

		for (;;) {
			if (!pthread_create(&t, NULL, &tfunc, NULL))
				pthread_join(t, NULL);
		}
	}

slabtop shows that pid/proc_inode_cache/etc grow quickly and
"indefinitely" until the task is killed or shrink_slab() is called, not
good.  And the main thread needs a lot of time to exit.

The same can happen if something like "ps -efL" runs continuously, while
some application spawns short-living threads.
Reported-by: default avatar"James M. Leddy" <jleddy@redhat.com>
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Dominic Duval <dduval@redhat.com>
Cc: Frank Hirtz <fhirtz@redhat.com>
Cc: "Fuller, Johnray" <Johnray.Fuller@gs.com>
Cc: Larry Woodman <lwoodman@redhat.com>
Cc: Paul Batkowski <pbatkowski@redhat.com>
Cc: Roland McGrath <roland@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent f1635a2c
...@@ -2586,9 +2586,6 @@ static void proc_flush_task_mnt(struct vfsmount *mnt, pid_t pid, pid_t tgid) ...@@ -2586,9 +2586,6 @@ static void proc_flush_task_mnt(struct vfsmount *mnt, pid_t pid, pid_t tgid)
dput(dentry); dput(dentry);
} }
if (tgid == 0)
goto out;
name.name = buf; name.name = buf;
name.len = snprintf(buf, sizeof(buf), "%d", tgid); name.len = snprintf(buf, sizeof(buf), "%d", tgid);
leader = d_hash_and_lookup(mnt->mnt_root, &name); leader = d_hash_and_lookup(mnt->mnt_root, &name);
...@@ -2645,17 +2642,16 @@ out: ...@@ -2645,17 +2642,16 @@ out:
void proc_flush_task(struct task_struct *task) void proc_flush_task(struct task_struct *task)
{ {
int i; int i;
struct pid *pid, *tgid = NULL; struct pid *pid, *tgid;
struct upid *upid; struct upid *upid;
pid = task_pid(task); pid = task_pid(task);
if (thread_group_leader(task)) tgid = task_tgid(task);
tgid = task_tgid(task);
for (i = 0; i <= pid->level; i++) { for (i = 0; i <= pid->level; i++) {
upid = &pid->numbers[i]; upid = &pid->numbers[i];
proc_flush_task_mnt(upid->ns->proc_mnt, upid->nr, proc_flush_task_mnt(upid->ns->proc_mnt, upid->nr,
tgid ? tgid->numbers[i].nr : 0); tgid->numbers[i].nr);
} }
upid = &pid->numbers[pid->level]; upid = &pid->numbers[pid->level];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment