[PATCH] checkpoint: conditionally schedule; check for fatal signals

Nathan Lynch ntl at pobox.com
Thu Nov 18 13:21:05 PST 2010


Long-running operations in the kernel should:

o  not monopolize the CPU
o  abort when asked

Put voluntary preemption points in ckpt_kread, ckpt_kwrite, and the
VMA-walking checkpoint code.  At the same points, return an error if a
fatal signal is pending; callers of these functions are supposed to be
checking return values.

Signed-off-by: Nathan Lynch <ntl at pobox.com>
---
 kernel/checkpoint/sys.c |   10 ++++++++++
 mm/checkpoint.c         |    7 +++++++
 2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/kernel/checkpoint/sys.c b/kernel/checkpoint/sys.c
index b761ec0..04e6277 100644
--- a/kernel/checkpoint/sys.c
+++ b/kernel/checkpoint/sys.c
@@ -72,6 +72,11 @@ int ckpt_kwrite(struct ckpt_ctx *ctx, void *addr, size_t count)
 	if (ckpt_test_error(ctx))
 		return ckpt_get_error(ctx);
 
+	if (fatal_signal_pending(current))
+		return -EINTR;
+
+	cond_resched();
+
 	ret = _ckpt_kwrite(ctx->file, addr, count);
 	if (ret < 0)
 		return ret;
@@ -103,6 +108,11 @@ int ckpt_kread(struct ckpt_ctx *ctx, void *addr, size_t count)
 	if (ckpt_test_error(ctx))
 		return ckpt_get_error(ctx);
 
+	if (fatal_signal_pending(current))
+		return -EINTR;
+
+	cond_resched();
+
 	ret = _ckpt_kread(ctx->file, addr, count);
 	if (ret < 0)
 		return ret;
diff --git a/mm/checkpoint.c b/mm/checkpoint.c
index 70300e8..6732a2e 100644
--- a/mm/checkpoint.c
+++ b/mm/checkpoint.c
@@ -310,6 +310,13 @@ static int vma_fill_pgarr(struct ckpt_ctx *ctx,
 		while (addr < end) {
 			struct page *page;
 
+			if (fatal_signal_pending(current)) {
+				cnt = -EINTR;
+				goto out;
+			}
+
+			cond_resched();
+
 			if (vma)
 				page = consider_private_page(vma, addr);
 			else
-- 
1.7.3.2



More information about the Containers mailing list