From: Dan Smith <danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org
Subject: [PATCH 1/2] Adjust socket reference count during leak detection phase
Date: Mon, 21 Sep 2009 13:44:36 -0700 [thread overview]
Message-ID: <1253565877-7303-2-git-send-email-danms@us.ibm.com> (raw)
In-Reply-To: <1253565877-7303-1-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
Sockets that have been disconnected from their struct file have
a reference count one less than normal sockets (potentially zero if the
socket is only in the system because of an outstanding skb). Since the
objhash assumes a minimum reference count of 2, skb's in such a situation
will always be counted as a leak.
This (probably contentious) patch adds a fixup function during the leak
detection phase to adjust SOCK_DEAD sockets' reference counts down by
one to match reality.
Signed-off-by: Dan Smith <danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
---
checkpoint/objhash.c | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/checkpoint/objhash.c b/checkpoint/objhash.c
index b85aa77..ee9dbfd 100644
--- a/checkpoint/objhash.c
+++ b/checkpoint/objhash.c
@@ -816,6 +816,26 @@ static void ckpt_obj_users_inc(struct ckpt_ctx *ctx, void *ptr, int increment)
*/
/**
+ * obj_sock_adjust_users - remove implicit reference on DEAD sockets
+ * @obj: CKPT_OBJ_SOCK object to adjust
+ *
+ * Sockets that have been disconnected from their struct file have
+ * a reference count one less than normal sockets. The objhash's
+ * assumption of such a reference is therefore incorrect, so we correct
+ * it here.
+ */
+static inline void obj_sock_adjust_users(struct ckpt_obj *obj)
+{
+ struct sock *sk = (struct sock *)obj->ptr;
+
+ if (sock_flag(sk, SOCK_DEAD)) {
+ obj->users--;
+ ckpt_debug("Adjusting SOCK %i count to %i\n",
+ obj->objref, obj->users);
+ }
+}
+
+/**
* ckpt_obj_contained - test if shared objects are contained in checkpoint
* @ctx: checkpoint context
*
@@ -838,6 +858,10 @@ int ckpt_obj_contained(struct ckpt_ctx *ctx)
hlist_for_each_entry(obj, node, &ctx->obj_hash->list, next) {
if (!obj->ops->ref_users)
continue;
+
+ if (obj->ops->obj_type == CKPT_OBJ_SOCK)
+ obj_sock_adjust_users(obj);
+
if (obj->ops->ref_users(obj->ptr) != obj->users) {
ckpt_debug("usage leak: %s\n", obj->ops->obj_name);
ckpt_write_err(ctx, "OP", "leak: usage (%d != %d (%s)",
--
1.6.2.5
next prev parent reply other threads:[~2009-09-21 20:44 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-21 20:44 Collect sockets for leak detection Dan Smith
[not found] ` <1253565877-7303-1-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-09-21 20:44 ` Dan Smith [this message]
[not found] ` <1253565877-7303-2-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-09-21 20:55 ` [PATCH 1/2] Adjust socket reference count during leak detection phase Serge E. Hallyn
[not found] ` <20090921205549.GB22363-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-09-22 19:31 ` Oren Laadan
2009-09-21 20:44 ` [PATCH 2/2] Collect sockets Dan Smith
[not found] ` <1253565877-7303-3-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-09-21 21:08 ` Serge E. Hallyn
2009-09-22 19:30 ` Oren Laadan
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=1253565877-7303-2-git-send-email-danms@us.ibm.com \
--to=danms-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
--cc=containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org \
/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