]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: fd: Add a counter of used fds.
authorOlivier Houchard <ohouchard@haproxy.com>
Tue, 16 Apr 2019 16:37:05 +0000 (18:37 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 18 Apr 2019 17:19:59 +0000 (19:19 +0200)
Add a new counter, ha_used_fds, that let us know how many file descriptors
we're currently using.

include/proto/fd.h
src/fd.c

index 07bb20a05ca18cd3107ef8b8303a716b2e257122..745c4fe458a7ea4aa981280bb13a623e9256b92b 100644 (file)
@@ -49,6 +49,8 @@ extern THREAD_LOCAL int fd_nbupdt; // number of updates in the list
 
 extern int poller_wr_pipe[MAX_THREADS];
 
+extern volatile int ha_used_fds; // Number of FDs we're currently using
+
 __decl_hathreads(extern HA_RWLOCK_T   __attribute__((aligned(64))) fdcache_lock);    /* global lock to protect fd_cache array */
 
 /* Deletes an FD from the fdsets.
@@ -555,6 +557,7 @@ static inline void fd_insert(int fd, void *owner, void (*iocb)(int fd), unsigned
         */
        if (locked)
                HA_SPIN_UNLOCK(FD_LOCK, &fdtab[fd].lock);
+       _HA_ATOMIC_ADD(&ha_used_fds, 1);
 }
 
 /* Computes the bounded poll() timeout based on the next expiration timer <next>
index ab0df33aedcfb68029fb43edb1ae815fc3edd724..fef44571e58c48087d70008b2fd41926e48970bc 100644 (file)
--- a/src/fd.c
+++ b/src/fd.c
@@ -186,6 +186,8 @@ THREAD_LOCAL int  fd_nbupdt = 0;   // number of updates in the list
 THREAD_LOCAL int poller_rd_pipe = -1; // Pipe to wake the thread
 int poller_wr_pipe[MAX_THREADS]; // Pipe to wake the threads
 
+volatile int ha_used_fds = 0; // Number of FD we're currently using
+
 #define _GET_NEXT(fd, off) ((struct fdlist_entry *)(void *)((char *)(&fdtab[fd]) + off))->next
 #define _GET_PREV(fd, off) ((struct fdlist_entry *)(void *)((char *)(&fdtab[fd]) + off))->prev
 /* adds fd <fd> to fd list <list> if it was not yet in it */
@@ -387,6 +389,7 @@ static void fd_dodelete(int fd, int do_close)
        if (do_close) {
                polled_mask[fd] = 0;
                close(fd);
+               _HA_ATOMIC_SUB(&ha_used_fds, 1);
        }
        if (locked)
                HA_SPIN_UNLOCK(FD_LOCK, &fdtab[fd].lock);