Skip to contentSkip to conversation

checkpoint: don't checkpoint a task with aio requests

PATCH In review Serge E. Hallyn 2 participants 2 messages Dec 30, 2009 – Jan 20, 2010 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpoint: don't checkpoint a task with aio requests

Not sure this is the best way, or entirely foolproof, but at least make an attempt to not checkpoint a task which is using aio.

A checkpoint-aware application using aio can have the checkpointer signal all tasks to complete aio and wait for the checkpoint to complete.

(Note I still have a queue of the patches at
http://git.kernel.org/gitweb.cgi?p=linux/kernel/git/sergeh/linux-cr.git;a=shortlog;h=refs/heads/cr-next
so you should be able to

git fetch git://git.kernel.org/pub/scm/linux/kernel/git/sergeh/linux-cr.git cr-next:serge

and cherrypick patches from that branch instead
of wrangling all the patches from mbox...)

---
 checkpoint/memory.c |    6 ++++++
 fs/aio.c            |   17 +++++++++++++++++
 include/linux/aio.h |    2 ++
 3 files changed, 25 insertions(+), 0 deletions(-)
checkpoint/memory.c +6 -0
index 0108dbe..49e16c5 100644
@@ -25,6 +25,7 @@
 #include <linux/swap.h>
 #include <linux/checkpoint.h>
 #include <linux/checkpoint_hdr.h>
+#include <linux/aio.h>
 
 /*
  * page-array chains: each ckpt_pgarr describes a set of <struct page *,vaddr>
@@ -666,6 +667,11 @@ static int do_checkpoint_mm(struct ckpt_ctx *ctx, struct mm_struct *mm)
 	struct file *exe_file = NULL;
 	int ret;
 
+	ret = check_for_outstanding_aio(mm);
+	if (ret < 0) {
+		ckpt_err(ctx, ret, "(%T)Outstanding aio\n");
+		return ret;
+	}
 	h = ckpt_hdr_get_type(ctx, sizeof(*h), CKPT_HDR_MM);
 	if (!h)
 		return -ENOMEM;
fs/aio.c +17 -0
index 02a2c93..7eb764c 100644
@@ -1784,3 +1784,20 @@ SYSCALL_DEFINE5(io_getevents, aio_context_t, ctx_id,
 	asmlinkage_protect(5, ret, ctx_id, min_nr, nr, events, timeout);
 	return ret;
 }
+
+int check_for_outstanding_aio(struct mm_struct *mm)
+{
+	int ret = -EBUSY;
+	struct kioctx *ctx;
+	struct hlist_node *n;
+
+	rcu_read_lock();
+	hlist_for_each_entry_rcu(ctx, n, &mm->ioctx_list, list)
+		if (!ctx->dead)
+			goto found;
+	ret = 0;
+found:
+	rcu_read_unlock();
+
+	return ret;
+}
include/linux/aio.h +2 -0
index aea219d..462f22e 100644
@@ -214,6 +214,7 @@ extern void kick_iocb(struct kiocb *iocb);
 extern int aio_complete(struct kiocb *iocb, long res, long res2);
 struct mm_struct;
 extern void exit_aio(struct mm_struct *mm);
+extern int check_for_outstanding_aio(struct mm_struct *mm);
 #else
 static inline ssize_t wait_on_sync_kiocb(struct kiocb *iocb) { return 0; }
 static inline int aio_put_req(struct kiocb *iocb) { return 0; }
@@ -221,6 +222,7 @@ static inline void kick_iocb(struct kiocb *iocb) { }
 static inline int aio_complete(struct kiocb *iocb, long res, long res2) { return 0; }
 struct mm_struct;
 static inline void exit_aio(struct mm_struct *mm) { }
+static inline int check_for_outstanding_aio(struct mm_struct *mm) { return 0; }
 #endif /* CONFIG_AIO */
 
 #define io_wait_to_kiocb(wait) container_of(wait, struct kiocb, ki_wait)
Signature · 1 line
1.6.0.4

A message that is not in the archive (sent off-list or not yet received): 20091230203722.GA25170-r/[email protected]

#2 lore raw

Seems sufficient for now - until we get to address AIO. Added, thanks.

Oren.

Quoted 93 lines · Serge E. Hallyn

Not sure this is the best way, or entirely foolproof, but at least make an attempt to not checkpoint a task which is using aio.

A checkpoint-aware application using aio can have the checkpointer signal all tasks to complete aio and wait for the checkpoint to complete.

(Note I still have a queue of the patches at
http://git.kernel.org/gitweb.cgi?p=linux/kernel/git/sergeh/linux-cr.git;a=shortlog;h=refs/heads/cr-next
so you should be able to

git fetch git://git.kernel.org/pub/scm/linux/kernel/git/sergeh/linux-cr.git cr-next:serge

and cherrypick patches from that branch instead
of wrangling all the patches from mbox...)

---
 checkpoint/memory.c |    6 ++++++
 fs/aio.c            |   17 +++++++++++++++++
 include/linux/aio.h |    2 ++
 3 files changed, 25 insertions(+), 0 deletions(-)
checkpoint/memory.c +6 -0
index 0108dbe..49e16c5 100644
@@ -25,6 +25,7 @@
 #include <linux/swap.h>
 #include <linux/checkpoint.h>
 #include <linux/checkpoint_hdr.h>
+#include <linux/aio.h>
 
 /*
  * page-array chains: each ckpt_pgarr describes a set of <struct page *,vaddr>
@@ -666,6 +667,11 @@ static int do_checkpoint_mm(struct ckpt_ctx *ctx, struct mm_struct *mm)
 	struct file *exe_file = NULL;
 	int ret;
 
+	ret = check_for_outstanding_aio(mm);
+	if (ret < 0) {
+		ckpt_err(ctx, ret, "(%T)Outstanding aio\n");
+		return ret;
+	}
 	h = ckpt_hdr_get_type(ctx, sizeof(*h), CKPT_HDR_MM);
 	if (!h)
 		return -ENOMEM;
fs/aio.c +17 -0
index 02a2c93..7eb764c 100644
@@ -1784,3 +1784,20 @@ SYSCALL_DEFINE5(io_getevents, aio_context_t, ctx_id,
 	asmlinkage_protect(5, ret, ctx_id, min_nr, nr, events, timeout);
 	return ret;
 }
+
+int check_for_outstanding_aio(struct mm_struct *mm)
+{
+	int ret = -EBUSY;
+	struct kioctx *ctx;
+	struct hlist_node *n;
+
+	rcu_read_lock();
+	hlist_for_each_entry_rcu(ctx, n, &mm->ioctx_list, list)
+		if (!ctx->dead)
+			goto found;
+	ret = 0;
+found:
+	rcu_read_unlock();
+
+	return ret;
+}
include/linux/aio.h +2 -0
index aea219d..462f22e 100644
@@ -214,6 +214,7 @@ extern void kick_iocb(struct kiocb *iocb);
 extern int aio_complete(struct kiocb *iocb, long res, long res2);
 struct mm_struct;
 extern void exit_aio(struct mm_struct *mm);
+extern int check_for_outstanding_aio(struct mm_struct *mm);
 #else
 static inline ssize_t wait_on_sync_kiocb(struct kiocb *iocb) { return 0; }
 static inline int aio_put_req(struct kiocb *iocb) { return 0; }
@@ -221,6 +222,7 @@ static inline void kick_iocb(struct kiocb *iocb) { }
 static inline int aio_complete(struct kiocb *iocb, long res, long res2) { return 0; }
 struct mm_struct;
 static inline void exit_aio(struct mm_struct *mm) { }
+static inline int check_for_outstanding_aio(struct mm_struct *mm) { return 0; }
 #endif /* CONFIG_AIO */
 
 #define io_wait_to_kiocb(wait) container_of(wait, struct kiocb, ki_wait)