ae63ccc06ad7c5b6bff887da22c13b44fe0a3cc0
2 * Copyright (C) 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
9 #include "fd-limit.hpp"
11 #include <common/compat/errno.hpp>
12 #include <common/error.hpp>
15 #include <sys/resource.h>
17 #include <urcu/uatomic.h>
19 /* total count of fd. */
23 * threshold in % of number of fd allowed.
25 static long fd_threshold
[LTTNG_FD_NR_TYPES
] = {
26 75, /* LTTNG_FD_APPS */
29 static rlim_t max_nr_fd
;
31 int lttng_fd_get(enum lttng_fd_type type
, unsigned int nr
)
35 if (type
>= LTTNG_FD_NR_TYPES
) {
39 newval
= uatomic_add_return(&fd_count
, (long) nr
);
40 if ((long) (newval
* 100) - (long) (max_nr_fd
* fd_threshold
[type
]) > 0) {
41 uatomic_sub(&fd_count
, (long) nr
);
47 void lttng_fd_put(enum lttng_fd_type type
__attribute__((unused
)), unsigned int nr
)
49 uatomic_sub(&fd_count
, (long) nr
);
57 ret
= getrlimit(RLIMIT_NOFILE
, &rlim
);
61 max_nr_fd
= rlim
.rlim_cur
;
This page took 0.032583 seconds and 5 git commands to generate.