mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-29 13:28:27 +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:
parent
b354a09cd7
commit
45cc85eea4
@ -73,6 +73,9 @@ int main(int argc, char *argv[])
|
||||
opts.final_state = TASK_DEAD;
|
||||
INIT_LIST_HEAD(&opts.veth_pairs);
|
||||
|
||||
if (init_service_fd())
|
||||
return -1;
|
||||
|
||||
while (1) {
|
||||
static struct option long_opts[] = {
|
||||
{ "tree", required_argument, 0, 't' },
|
||||
|
@ -100,16 +100,22 @@ struct cr_options {
|
||||
|
||||
extern struct cr_options opts;
|
||||
|
||||
enum {
|
||||
LOG_FD_OFF = 1,
|
||||
enum sfd_type {
|
||||
SERVICE_FD_MIN,
|
||||
|
||||
LOG_FD_OFF,
|
||||
LOG_DIR_FD_OFF,
|
||||
IMG_FD_OFF,
|
||||
SELF_EXE_FD_OFF,
|
||||
PROC_FD_OFF,
|
||||
CTL_TTY_OFF,
|
||||
|
||||
SERVICE_FD_MAX
|
||||
};
|
||||
|
||||
int get_service_fd(int type);
|
||||
extern int init_service_fd(void);
|
||||
extern int get_service_fd(enum sfd_type type);
|
||||
extern bool is_service_fd(int fd, enum sfd_type type);
|
||||
|
||||
/* file descriptors template */
|
||||
struct cr_fd_desc_tmpl {
|
||||
|
20
util.c
20
util.c
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user