2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 06:15:24 +00:00

Speed up service-fd retrieval

We're using get_service_fd in file engine,
better to make it fast. This patch caches
the limits system provides us, instead of
calling getrlimit() every time.

This patch introduces is_service_fd helper
which will be used instead of get_service_fd
where it make sense.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Cyrill Gorcunov
2012-09-13 14:45:06 +04:00
committed by Pavel Emelyanov
parent b354a09cd7
commit 45cc85eea4
3 changed files with 30 additions and 5 deletions

20
util.c
View File

@@ -259,7 +259,9 @@ int do_open_proc(pid_t pid, int flags, const char *fmt, ...)
return openat(dirfd, path, flags);
}
int get_service_fd(int type)
static int service_fd_rlim_cur;
int init_service_fd(void)
{
struct rlimit rlimit;
@@ -273,7 +275,21 @@ int get_service_fd(int type)
return -1;
}
return rlimit.rlim_cur - type;
service_fd_rlim_cur = (int)rlimit.rlim_cur;
BUG_ON(service_fd_rlim_cur < SERVICE_FD_MAX);
return 0;
}
int get_service_fd(enum sfd_type type)
{
BUG_ON((int)type <= SERVICE_FD_MIN || (int)type >= SERVICE_FD_MAX);
return service_fd_rlim_cur - type;
}
bool is_service_fd(int fd, enum sfd_type type)
{
return fd == get_service_fd(type);
}
int copy_file(int fd_in, int fd_out, size_t bytes)