Skip to content

Commit

Permalink
shm: optimize exit_shm()
Browse files Browse the repository at this point in the history
We may optimistically check .in_use == 0 without holding the rw_mutex:
it's the common case, and if it's zero, there certainly won't be any
segments associated with us.

After taking the lock, the idr_for_each() will do the right thing, so we
could now drop the re-check inside the lock without any real cost.  But
it won't hurt.

Signed-off-by: Vasiliy Kulikov <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
segoon authored and torvalds committed Aug 4, 2011
1 parent 33a30ed commit 298507d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ipc/shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ void exit_shm(struct task_struct *task)
{
struct ipc_namespace *ns = task->nsproxy->ipc_ns;

if (shm_ids(ns).in_use == 0)
return;

/* Destroy all already created segments, but not mapped yet */
down_write(&shm_ids(ns).rw_mutex);
if (shm_ids(ns).in_use)
Expand Down

0 comments on commit 298507d

Please sign in to comment.