From: Jack Miller <millerjo@us.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: mikey@au1.ibm.com, anton@au1.ibm.com, miltonm@us.ibm.com
Subject: [PATCH 2/3] shm: Allow exit_shm in parallel if only marking orphans
Date: Wed, 4 Jun 2014 14:07:47 -0500 [thread overview]
Message-ID: <1401908868-14554-3-git-send-email-millerjo@us.ibm.com> (raw)
In-Reply-To: <1401908868-14554-1-git-send-email-millerjo@us.ibm.com>
If shm_rmid_force is not set then we only mark the shmids as orphaned and
do not lock, add, or delete any entries into the tree. This is also the
default state.
Seperate the sysctl on and off case, and only obtain the read lock. The
newly aded list head can be deleted uner the read lock because we are only
called with current and will only change the semids allocated by this task
and not manipulate the list.
This commit assumes that up_read includes a sufficent memory barrier for
the writes to be seen my others that later obtain a write lock.
Signed-off-by: Milton Miller <miltonm@bga.com>
Signed-off-by: Jack Miller <millerjo@us.ibm.com>
---
ipc/shm.c | 67 +++++++++++++++++++++++++++++++++------------------------------
1 file changed, 35 insertions(+), 32 deletions(-)
diff --git a/ipc/shm.c b/ipc/shm.c
index 9790a0e..0dde176 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -269,32 +269,6 @@ static void shm_close(struct vm_area_struct *vma)
}
/* Called with ns->shm_ids(ns).rwsem locked */
-static void shm_mark_orphan(struct shmid_kernel *shp, struct ipc_namespace *ns)
-{
- if (WARN_ON(shp->shm_creator != current)) /* Remove me when it works */
- return;
-
- /*
- * Mark it as orphaned to destroy the segment when
- * kernel.shm_rmid_forced is changed.
- * It is noop if the following shm_may_destroy() returns true.
- */
- shp->shm_creator = NULL;
-
- /*
- * Don't even try to destroy it. If shm_rmid_forced=0 and IPC_RMID
- * is not set, it shouldn't be deleted here.
- */
- if (!ns->shm_rmid_forced)
- return;
-
- if (shm_may_destroy(ns, shp)) {
- shm_lock_by_ptr(shp);
- shm_destroy(ns, shp);
- }
-}
-
-/* Called with ns->shm_ids(ns).rwsem locked */
static int shm_try_destroy_orphaned(int id, void *p, void *data)
{
struct ipc_namespace *ns = data;
@@ -325,20 +299,49 @@ void shm_destroy_orphaned(struct ipc_namespace *ns)
up_write(&shm_ids(ns).rwsem);
}
-
+/* Locking assumes this will only be called with task == current */
void exit_shm(struct task_struct *task)
{
struct ipc_namespace *ns = task->nsproxy->ipc_ns;
struct shmid_kernel *shp, *n;
- if (shm_ids(ns).in_use == 0)
+ if (list_empty(&task->sysvshm.shm_clist))
+ return;
+
+ /*
+ * If kernel.shm_rmid_forced is not set then only keep track of
+ * which shmids are orphaned, so that a later set of the sysctl
+ * can clean them up.
+ */
+ if (!ns->shm_rmid_forced) {
+ down_read(&shm_ids(ns).rwsem);
+ list_for_each_entry(shp, &task->sysvshm.shm_clist, shm_clist)
+ shp->shm_creator = NULL;
+ /*
+ * Only under read lock but we are only called on current
+ * so no entry on the list will be shared.
+ */
+ list_del(&task->sysvshm.shm_clist);
+ up_read(&shm_ids(ns).rwsem);
return;
+ }
- /* Destroy all already created segments, but not mapped yet */
+ /*
+ * Destroy all already created segments, that were not yet mapped,
+ * and mark any mapped as orphan to cover the sysctl toggling.
+ * Destroy is skipped if shm_may_destroy() returns false.
+ */
down_write(&shm_ids(ns).rwsem);
- list_for_each_entry_safe(shp, n, &task->sysvshm.shm_clist, shm_clist)
- shm_mark_orphan(shp, ns);
- /* remove the list head from any segments still attached */
+ list_for_each_entry_safe(shp, n, &task->sysvshm.shm_clist, shm_clist) {
+ shp->shm_creator = NULL;
+
+ if (shm_may_destroy(ns, shp)) {
+ shm_lock_by_ptr(shp);
+ shm_destroy(ns, shp);
+ }
+ }
+
+ /* Remove the list head from any segments still attached. */
list_del(&task->sysvshm.shm_clist);
up_write(&shm_ids(ns).rwsem);
}
--
1.9.1
next prev parent reply other threads:[~2014-06-04 19:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-04 19:07 shm: shm_exit scalability fixes Jack Miller
2014-06-04 19:07 ` [PATCH 1/3] shm: Make exit_shm work proportional to task activity Jack Miller
2014-06-04 19:07 ` Jack Miller [this message]
2014-06-04 19:07 ` [PATCH 3/3] shm: Remove unneeded extern for function Jack Miller
2014-06-17 17:27 [RESEND] shm: shm exit scalability fixes Jack Miller
2014-06-17 17:27 ` [PATCH 2/3] shm: Allow exit_shm in parallel if only marking orphans Jack Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1401908868-14554-3-git-send-email-millerjo@us.ibm.com \
--to=millerjo@us.ibm.com \
--cc=anton@au1.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mikey@au1.ibm.com \
--cc=miltonm@us.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®