Commit 45cc85ee authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

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: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent b354a09c
...@@ -73,6 +73,9 @@ int main(int argc, char *argv[]) ...@@ -73,6 +73,9 @@ int main(int argc, char *argv[])
opts.final_state = TASK_DEAD; opts.final_state = TASK_DEAD;
INIT_LIST_HEAD(&opts.veth_pairs); INIT_LIST_HEAD(&opts.veth_pairs);
if (init_service_fd())
return -1;
while (1) { while (1) {
static struct option long_opts[] = { static struct option long_opts[] = {
{ "tree", required_argument, 0, 't' }, { "tree", required_argument, 0, 't' },
......
...@@ -100,16 +100,22 @@ struct cr_options { ...@@ -100,16 +100,22 @@ struct cr_options {
extern struct cr_options opts; extern struct cr_options opts;
enum { enum sfd_type {
LOG_FD_OFF = 1, SERVICE_FD_MIN,
LOG_FD_OFF,
LOG_DIR_FD_OFF, LOG_DIR_FD_OFF,
IMG_FD_OFF, IMG_FD_OFF,
SELF_EXE_FD_OFF, SELF_EXE_FD_OFF,
PROC_FD_OFF, PROC_FD_OFF,
CTL_TTY_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 */ /* file descriptors template */
struct cr_fd_desc_tmpl { struct cr_fd_desc_tmpl {
......
...@@ -259,7 +259,9 @@ int do_open_proc(pid_t pid, int flags, const char *fmt, ...) ...@@ -259,7 +259,9 @@ int do_open_proc(pid_t pid, int flags, const char *fmt, ...)
return openat(dirfd, path, flags); 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; struct rlimit rlimit;
...@@ -273,7 +275,21 @@ int get_service_fd(int type) ...@@ -273,7 +275,21 @@ int get_service_fd(int type)
return -1; 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) int copy_file(int fd_in, int fd_out, size_t bytes)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment