Andrea Fontana

Results 64 comments of Andrea Fontana

1 - I think that `/dev/fd` exists in many unix-based os. Maybe `/proc/this/fd` is linux specific. 2 - That's the reason why I first check `/dev/fd` Please notice that this...

Some related examples: - python that counts open fd: https://github.com/python/cpython/blob/main/Lib/test/support/os_helper.py#L612 - python that closes fd of subprocess (!) https://github.com/python/cpython/blob/main/Modules/_posixsubprocess.c#L496 - swift to check max fd used: https://github.com/apple/swift-corelibs-foundation/blob/master/Sources/Foundation/Process.swift#L70 - libreoffice: https://github.com/LibreOffice/online/blob/d0edfeabbdc969a9a66cf90976a63c2f4403a6d3/common/Util.cpp#L204...

Even docker and podman use this way to close fd: https://github.com/docker/docker-ce/blob/master/components/engine/daemon/graphdriver/devmapper/deviceset.go#L1265 https://github.com/containers/podman/blob/main/libpod/container_top_linux.go#L141

https://en.wikibooks.org/wiki/C_Programming/POSIX_Reference/dirent.h Here they say it's a "pseudo-standard": I'm not sure that every C library implements that function. Is there a way to understand when these functions were added to posix...

I wonder if I should still leave the old method in the case of low limits. At that point it's probably faster to iterate and close all the fds and...

> Hm... I was rather thinking the getrlimit would be the test, and then only if it's over a certain limit would it make sense to use the /proc/fd read....

I have done some tests with a ulimit starting from 1_000_000 and going down to 100_000, in 10 steps. For each step, I tested the performance with 0, 1000, …,...

> > Having said that, it is necessary to find a balance between the two methods, deciding when to use one or the other based on the ulimit. Any ideas?...

With few FD it wins. That probably it is the common case. How many software did you write with more than a dozen of FDs open at the same time?...

Watching the stats above, I think: - maxfds/(1+estimated_open) > 120 => /dev/fd - maxfds > N => /dev/fd - else : old way (it allocates 8bytes*maxfds) So, how much ram...