In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
Three kinds of Multiplexing IO implementation: the difference of select,poll,epoll
Look directly at the watch:
The following is reproduced at: http://watter1985.iteye.com/blog/1614039
There is a specific implementation of select/poll/epoll in the above article.
Summary of kernel calls:
The implementation of poll/select/epoll is based on the poll method provided by the file (fanciopp-> poll).
This method uses the _ qproc method provided by poll_table to add a node (wait_queue_t) containing a wake-up function (wait_queue_t.func) to one or more waiting queues (wait_queue_head_t) corresponding to the file internal event mask _ key, and checks that the current ready state of the file is returned to the caller of poll (depending on the implementation of the file).
When the state of the file changes (for example, when the network packet arrives), the file traverses the waiting queue corresponding to the event and calls the callback function (wait_queue_t.func) to wake up the waiting thread.
Poll and select
The implementation of poll and select is basically the same, except that the parameters passed are different. Their basic flow is as follows:
1. Copy user data to kernel space
two。 Estimated timeout
3. Iterate through each file and call fuploop-> poll to get the current ready state of the file. If none of the previously traversed files are ready, insert a wait_queue node into the file
4. Check the status after traversal:
a)。 If you already have a ready file to go to 5
b)。 If a signal is generated, restart poll or select (go to 1 or 3)
c)。 Otherwise, the suspended process waits for timeout or wake up, or after being awakened, traverse all files again to get the ready state of each file.
5. Copy the ready state of all files to user space
6. Clean up the requested resources
Common function
Here are some functions common to poll/select that implement the core functions of poll and select.
Poll_initwait is used to initialize poll_wqueues
_ _ pollwait implements the logic of adding callback nodes to the file
Pollwake is called by the file to wake up the thread when the state of the file changes.
Poll_get_entry,free_poll_entry,poll_freewait is used to request the release of memory occupied by poll_table_entry and is responsible for releasing the wait_queue node on the file.
Among them, the application and release of poll_table_entry by poll,select adopts the management mode similar to the memory pool, first using the pre-allocated space, when the pre-allocated space is insufficient, allocate a memory page and use the space on the memory page.
Flow chart:
For epoll:
Recursive depth Detection (ep_call_nested) cyclic Detection (ep_loop_check) Wake up Storm Detection (reverse_path_check)
Flow chart:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.