[CRIU] [PATCH v2 3/4] aio: Refactor nr_req calculation

Kirill Tkhai ktkhai at virtuozzo.com
Thu May 19 06:12:31 PDT 2016


nr_req always depends on ring size and we even check for that.

Kill parasite_aio::max_reqs,vma_nr_reqs and vma_area::aio_nr_req,
because they are not need and excess.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/aio.c              |   25 ++++++++++++-------------
 criu/include/aio.h      |    1 +
 criu/include/parasite.h |    2 --
 criu/include/vma.h      |    1 -
 criu/pie/parasite.c     |    2 --
 criu/proc_parse.c       |    1 -
 6 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/criu/aio.c b/criu/aio.c
index 26bca30..4d2fbeb 100644
--- a/criu/aio.c
+++ b/criu/aio.c
@@ -8,6 +8,8 @@
 #include "parasite-syscall.h"
 #include "images/mm.pb-c.h"
 
+#define NR_IOEVENTS_IN_NPAGES(npages) ((PAGE_SIZE * npages - sizeof(struct aio_ring)) / sizeof(struct io_event))
+
 int dump_aio_ring(MmEntry *mme, struct vma_area *vma)
 {
 	int nr = mme->n_aios;
@@ -23,8 +25,10 @@ int dump_aio_ring(MmEntry *mme, struct vma_area *vma)
 
 	aio_ring_entry__init(re);
 	re->id = vma->e->start;
-	re->nr_req = vma->aio_nr_req;
 	re->ring_len = vma->e->end - vma->e->start;
+	re->nr_req = aio_estimate_nr_reqs(re->ring_len);
+	if (!re->nr_req)
+		return -1;
 	mme->aios[nr] = re;
 	mme->n_aios = nr + 1;
 	pr_info("Dumping AIO ring @%"PRIx64"-%"PRIx64"\n",
@@ -43,8 +47,14 @@ void free_aios(MmEntry *mme)
 	}
 }
 
-static unsigned int aio_estimate_nr_reqs(unsigned int k_max_reqs)
+unsigned int aio_estimate_nr_reqs(unsigned int size)
 {
+	unsigned int k_max_reqs = NR_IOEVENTS_IN_NPAGES(size/PAGE_SIZE);
+
+	if (size & ~PAGE_MASK) {
+		pr_err("Ring size is not aligned\n");
+		return 0;
+	}
 	/*
 	 * Kernel does
 	 *
@@ -74,7 +84,6 @@ int parasite_collect_aios(struct parasite_ctl *ctl, struct vm_area_list *vmas)
 	struct vma_area *vma;
 	struct parasite_check_aios_args *aa;
 	struct parasite_aio *pa;
-	int i;
 
 	if (!vmas->nr_aios)
 		return 0;
@@ -99,8 +108,6 @@ int parasite_collect_aios(struct parasite_ctl *ctl, struct vm_area_list *vmas)
 				(long)(pa - &aa->ring[0]), vma->e->start);
 		pa->ctx = vma->e->start;
 		pa->size = vma->e->end - vma->e->start;
-		pa->max_reqs = 0;
-		pa->vma_nr_reqs = &vma->aio_nr_req;
 		pa++;
 	}
 	aa->nr_rings = vmas->nr_aios;
@@ -108,13 +115,5 @@ int parasite_collect_aios(struct parasite_ctl *ctl, struct vm_area_list *vmas)
 	if (parasite_execute_daemon(PARASITE_CMD_CHECK_AIOS, ctl))
 		return -1;
 
-	pa = &aa->ring[0];
-	for (i = 0; i < vmas->nr_aios; i++) {
-		pa = &aa->ring[i];
-		*pa->vma_nr_reqs = aio_estimate_nr_reqs(pa->max_reqs);
-		pr_debug(" `- Ring #%d has %u reqs, estimated to %u\n", i,
-				pa->max_reqs, *pa->vma_nr_reqs);
-	}
-
 	return 0;
 }
diff --git a/criu/include/aio.h b/criu/include/aio.h
index 1e08775..c72122c 100644
--- a/criu/include/aio.h
+++ b/criu/include/aio.h
@@ -3,6 +3,7 @@
 
 #include <linux/aio_abi.h>
 #include "images/mm.pb-c.h"
+unsigned int aio_estimate_nr_reqs(unsigned int size);
 int dump_aio_ring(MmEntry *mme, struct vma_area *vma);
 void free_aios(MmEntry *mme);
 struct parasite_ctl;
diff --git a/criu/include/parasite.h b/criu/include/parasite.h
index c2bd0c3..a4228b8 100644
--- a/criu/include/parasite.h
+++ b/criu/include/parasite.h
@@ -140,8 +140,6 @@ struct parasite_dump_posix_timers_args {
 struct parasite_aio {
 	unsigned long ctx;
 	unsigned int size;
-	unsigned int max_reqs;
-	unsigned int *vma_nr_reqs;
 };
 
 struct parasite_check_aios_args {
diff --git a/criu/include/vma.h b/criu/include/vma.h
index d69f5f0..82f725f 100644
--- a/criu/include/vma.h
+++ b/criu/include/vma.h
@@ -46,7 +46,6 @@ struct vma_area {
 				 */
 				int	vm_file_fd;
 				int	vm_socket_id;
-				unsigned int aio_nr_req;
 			};
 
 			char		*aufs_rpath;	/* path from aufs root */
diff --git a/criu/pie/parasite.c b/criu/pie/parasite.c
index f45f7f4..4e8683d 100644
--- a/criu/pie/parasite.c
+++ b/criu/pie/parasite.c
@@ -418,8 +418,6 @@ static int parasite_check_aios(struct parasite_check_aios_args *args)
 		}
 
 		/* XXX: wait aio completion */
-
-		args->ring[i].max_reqs = ring->nr;
 	}
 
 	return 0;
diff --git a/criu/proc_parse.c b/criu/proc_parse.c
index cebf21c..5f6b47b 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -251,7 +251,6 @@ static int vma_get_mapfile(char *fname, struct vma_area *vma, DIR *mfd,
 			if ((buf.st_mode & S_IFMT) == 0 && !strncmp(fname, AIO_FNAME, sizeof(AIO_FNAME) - 1)) {
 				/* AIO ring, let's try */
 				close(vma->vm_file_fd);
-				vma->aio_nr_req = -1;
 				vma->e->status = VMA_AREA_AIORING;
 				return 0;
 			}



More information about the CRIU mailing list