Linux内核如何从epoll兴趣列表中移除一个关闭的fd?

How does the Linux kernel remove a closed fd from the epoll interest list?

我正在尝试 epoll 玩一下,有一部分让我有点困惑。所以,从 epoll 的手册页:

 6.  Will closing a file descriptor cause it to be removed from
           all epoll interest lists?

           Yes, but be aware of the following point.  A file descriptor
           is a reference to an open file description (see open(2)).
           Whenever a file descriptor is duplicated via dup(2), dup2(2),
           fcntl(2) F_DUPFD, or fork(2), a new file descriptor referring
           to the same open file description is created.  An open file
           description continues to exist until all file descriptors
           referring to it have been closed.

           A file descriptor is removed from an interest list only after
           all the file descriptors referring to the underlying open
           file description have been closed.
           ...

根据我的理解,这些例子是可能的:

Example1:

fd1 added to the interest list
dup(fd1) -> fd2
close(fd1) - not removed from interest list because the underlying file is still open
event for the file -> epoll signals fd1

Example2:
fd1 added to the interest list
dup(fd1) -> fd2
close(fd1) - not removed from interest list because the underlying file is still open
another file open -> this gets fd1
event for the first file -> epoll signals fd1 (for me this looks like it should not happen)

我的第一个问题是我的理解是否正确。

我问题的第二部分是指 Linux 管理从 epoll 兴趣列表中静默删除的方式。那么,当你调用 close(fd) 并且 fd 在 epoll 的一个或多个兴趣列表中时,内核如何知道该 fd 在哪个兴趣列表中?这些数据是否存储在底层文件结构中?我想我的问题是从 epoll 兴趣列表中静默删除 fds 是如何一步步发生的。

当 fd1 被删除并复制到 fd2 时,内核不会删除打开的文件描述,但会从文件描述符中删除条目 table 即内核中的内部数据结构仍然完好无损,但与 fd1 索引无关再

epoll fd 在内部将兴趣列表保存在内核数据结构中,它了解在调用兴趣列表之一的关闭时需要清理所有打开的文件描述。以下 link 确实有更多信息。 https://unix.stackexchange.com/questions/195057/what-is-an-open-file-description