From 593cb59a6386bd6d5ca8975aa18d124e7ff9a4da Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Mon, 3 Feb 2014 00:30:02 +0400 Subject: [PATCH] pagemap: Use pread to read pagemap entries When reading pagemaps, we read it from specific position. To do it, we called lseek, then read. Fortunetely, there's a syscall that does both things in one call -- pread. Since we don't need to keep pagemap's position for further reads, it perfectly suits our needs. This removes 75% of lseek calls when dumping basic container. Signed-off-by: Pavel Emelyanov --- mem.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/mem.c b/mem.c index 81ebef411..62097a84e 100644 --- a/mem.c +++ b/mem.c @@ -105,17 +105,12 @@ static int generate_iovs(struct vma_area *vma, int pagemap, struct page_pipe *pp { unsigned long pfn, nr_to_scan; unsigned long pages[2] = {}; - u64 aux; - - aux = vma->vma.start / PAGE_SIZE * sizeof(*map); - if (lseek(pagemap, aux, SEEK_SET) != aux) { - pr_perror("Can't rewind pagemap file"); - return -1; - } + u64 from, len; nr_to_scan = vma_area_len(vma) / PAGE_SIZE; - aux = nr_to_scan * sizeof(*map); - if (read(pagemap, map, aux) != aux) { + from = vma->vma.start / PAGE_SIZE * sizeof(*map); + len = nr_to_scan * sizeof(*map); + if (pread(pagemap, map, len, from) != len) { pr_perror("Can't read pagemap file"); return -1; }