linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* d_add and dentry leak
@ 2019-02-21  7:45 Fam Zheng
  2019-02-21  8:30 ` Al Viro
  0 siblings, 1 reply; 3+ messages in thread
From: Fam Zheng @ 2019-02-21  7:45 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: Fam Zheng, Alexander Viro, Fam Zheng, 段熊春,
	Shine Liu

We’ve noticed an issue that frequent open,close,open,close... of /dev/ptmx eventually causes soft lockup.

Here is a summary of what happened.

Upon user opening /dev/ptmx, devpts_pty_new calls d_alloc_name and d_add, the new dentry is inserted into dcache_hashtable.

Later when closing, devpts_pty_kill calls d_delete and dput, but per the conditionals in them, neither calls __d_drop:

- d_delete sees “dentry->d_lockref.count == 1” and takes the “dentry_unlink_inode” branch, avoiding __d_drop.
- dput takes the “likely(fast_dput(dentry))” branch and skips dentry_kill() altogether (which would have called __d_drop).

The problem is that each devpts_pty_new creates a new dentry, which as a result stays in the hashtable forever. Reuse cannot happen because the devpts always uses d_add instead of d_alloc_parallel.

This can be a problem if a user has a loop to open/close /dev/ptmx, because a specific link in the hash is hit, making it ever grow longer.

In a system that has an unfortunate application that spawns a lot of short living processes and allocates ttys for each, such stale dentries accumulate, which are hashed the same, making a million elem long hash chain. In this case, d_alloc_parallel will more often than not need a few retries due to seq change because one __d_lookup_rcu call can take a second or so.

Reproducer:

	while echo >/dev/ptmx; :; done

Overtime, one of your unlucky path lookups (that hits the same hash bucket as affected by above) will slow down significantly.

Should devpts clean up differently? Or should d_delete be fixed?

Thanks,
Fam

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-02-21  9:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-21  7:45 d_add and dentry leak Fam Zheng
2019-02-21  8:30 ` Al Viro
2019-02-21  9:13   ` Fam Zheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).