[3/4] page-pipe: move code to resize a pipe in a separate function

Submitted by Andrei Vagin on Nov. 7, 2017, 12:02 a.m.

Details

Message ID 20171107000237.27668-4-avagin@openvz.org
State New
Series "Optimize a number of pipes to splice memory"
Headers show

Commit Message

Andrei Vagin Nov. 7, 2017, 12:02 a.m.
From: Andrei Vagin <avagin@virtuozzo.com>

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
---
 criu/page-pipe.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/page-pipe.c b/criu/page-pipe.c
index 4eabb5ed5..adad1819d 100644
--- a/criu/page-pipe.c
+++ b/criu/page-pipe.c
@@ -189,23 +189,32 @@  void page_pipe_reinit(struct page_pipe *pp)
 		BUG(); /* It can't fail, because ppb is in free_bufs */
 }
 
+static inline int resize_pipe(struct page_pipe_buf *ppb)
+{
+	unsigned long new_size = ppb->pipe_size << 1;
+	int ret;
+
+	if (ppb->pages_in < ppb->pipe_size)
+		return 0;
+
+	if (new_size > PIPE_MAX_SIZE)
+		return 1;
+
+	ret = ppb_resize_pipe(ppb, new_size);
+	if (ret < 0)
+		return 1; /* need to add another buf */
+
+	return 0;
+}
+
 static inline int try_add_page_to(struct page_pipe *pp, struct page_pipe_buf *ppb,
 		unsigned long addr, unsigned int flags)
 {
 	if (ppb->flags != flags)
 		return 1;
 
-	if (ppb->pages_in == ppb->pipe_size) {
-		unsigned long new_size = ppb->pipe_size << 1;
-		int ret;
-
-		if (new_size > PIPE_MAX_SIZE)
-			return 1;
-
-		ret = ppb_resize_pipe(ppb, new_size);
-		if (ret < 0)
-			return 1; /* need to add another buf */
-	}
+	if (resize_pipe(ppb) == 1)
+		return 1;
 
 	if (ppb->nr_segs && iov_grow_page(&ppb->iov[ppb->nr_segs - 1], addr))
 			goto out;