Why does the JDK NIO use so many anon_inode file descriptors?

I use Sun JDK 1.6.0_26 and NIO (with Netty), and I see hundreds of file descriptors that anon_inode :

 $ lsof -np 11225 | fgrep -w anon_inode java 11225 nobody 57u 0000 0,9 0 1386 anon_inode java 11225 nobody 61u 0000 0,9 0 1386 anon_inode java 11225 nobody 65u 0000 0,9 0 1386 anon_inode java 11225 nobody 69u 0000 0,9 0 1386 anon_inode java 11225 nobody 73u 0000 0,9 0 1386 anon_inode java 11225 nobody 77u 0000 0,9 0 1386 anon_inode java 11225 nobody 81u 0000 0,9 0 1386 anon_inode java 11225 nobody 86u 0000 0,9 0 1386 anon_inode java 11225 nobody 89u 0000 0,9 0 1386 anon_inode java 11225 nobody 93u 0000 0,9 0 1386 anon_inode java 11225 nobody 97u 0000 0,9 0 1386 anon_inode [...] 

I could not find a clear explanation of what an anonymous index is, I looked at fs/anon_inodes.c in the source tree of the Linux kernel, and it seems that maybe epoll using it, but I'm not sure why I would have so much. I have several "epoll loops" and timer threads, but not as many as my anon_inode number.

+4
source share
2 answers

This is most likely an epic. Selectors use epoll by default, starting with one of the earlier releases of JDK 1.6.x, and this impl selector uses more file descriptors than the old one, in addition to the descriptors used by the sockets themselves. You will also use more file descriptors if you register multiple selectors with one SocketChannel, for example, separate selectors for reading and writing. If Netty uses NIO, it almost certainly uses selectors. In one application, the ratio of file descriptors to sockets ranged from 4 to 1 due to the use of epoll based selectors. You can return to the old implementation of the selector by changing the java.nio.channels.spi.SelectorProvider property, and this will reduce the number of descriptors, but probably due to performance (YMMV).

+5
source

Perhaps these inodes are associated with mapped “files” that translate to Java Direct ByteBuffers. The mmap(2) system call usually works with files (using file descriptors). But it also supports the MAP_ANONYMOUS option to manipulate the memory mapping without having the actual file descriptor. It sounds like something that might require an “anonymous index” inside.

0
source

Source: https://habr.com/ru/post/1381747/


All Articles