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