In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "Linux kernel patch example analysis". In daily operation, I believe many people have doubts about Linux kernel patch example analysis. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "Linux kernel patch example analysis". Next, please follow the editor to study!
If a file is read in the system, it will be called
Generic_file_buffered_read
The function of this function is to read the data from the disk to the page, or directly get the page in the cache, and then call copy_page_to_iter to copy the page to the buffer in the user layer.
One quiet afternoon, when I was free, I turned on the computer and was ready to study the function carefully. I found that the comment on the function was written on it:
* This is really ugly. But the goto's actually try to clarify some * of the logic when it comes to error handling etc.
After taking a closer look at the code, I found that ugly was outrageous, full of jumps and judgments, and the whole function reached about 300 lines (forgive me for reading the comments before saying: -), and found that if I looked at this function, I would not be in a good mood all day (I was looking at Linux5.10 code at that time).
Ssize_t generic_file_buffered_read (struct kiocb * iocb, struct iov_iter * iter, ssize_t written) {find_page: if (fatal_signal_pending (current)) {error =-EINTR; goto out } error = wait_on_page_locked_killable (page); if (unlikely (error)) goto readpage_error; if (PageUptodate (page)) goto page_ok If (inode- > i_blkbits = = PAGE_SHIFT | |! mapping- > astatops-> is_partially_uptodate) goto page_not_up_to_date / * pipes can't handle partially uptodate pages * / if (unlikely (iov_iter_is_pipe (iter) goto page_not_up_to_date; if (! trylock_page (page)) goto page_not_up_to_date / * Did it get truncated before we got the lock? * / if (! page- > mapping) goto page_not_up_to_date_locked If (! mapping- > astatops-> is_partially_uptodate (page, offset, iter- > count) goto page_not_up_to_date_locked; unlock_page (page);}
So I think there are so many awesome people in the kernel community who stare at this code all day long. I'm sure many people have already noticed it, so they want to see if anyone has submitted this function for patch refactoring:
. / scripts/get_maintainer.pl mm/filemap.c linux-kernel@vger.kernel.org (open list)
Then I searched for generic_file_buffered_read in the following URL, and sure enough, on October 25th (I see the code that day was around November 1st), someone posted the relevant patch:
Https://lore.kernel.org/lkml/
Then I can't wait to check out the patch and download the entire patch:
A tool is recommended here, using the b4 tool
Https://git.kernel.org/pub/scm/utils/b4/b4.git
Can be obtained directly from the
Https://lore.kernel.org
Get the patch in the original format so that you can test it after git am.
# b4 am https://lore.kernel.org/lkml/20201025212949.602194-1-kent.overstreet@gmail.com v2_20201025_kent_overstreet_generic_file_buffered_read_improvements.cover v2_20201025_kent_overstreet_generic_file_buffered_read_improvements.mbx
Then git am directly, which is very convenient, so you can type the patch submitted on lore.kernel.org.
Git am v2_20201025_kent_overstreet_generic_file_buffered_read_improvements.mbx hint: before git am You can git apply-check in advance # gitlogdate-3 fc5608fc9917 2020-10-25 Kent Overstreet fs: generic_file_buffered_read () now uses find_get_pages_contig 3bcadc3306be 2020-10-25 Kent Overstreet fs: Break generic_file_buffered_read up into multiple functions 3650b228f83a 2020-10-25 Linus Torvalds Linux 5.10-rc1 alias gitlogdate='git log-- pretty=format: "% h%x09%ad%x09%an%x09%s"-- date=short'
After typing this patch, generic_file_buffered_read looks like this:
Ssize_t generic_file_buffered_read (struct kiocb * iocb, struct iov_iter * iter, ssize_t written) {.. Pg_nr = generic_file_buffered_read_get_pages (iocb, iter, pages, nr_pages); For (I = 0; I)
< pg_nr; i++) { copied = copy_page_to_iter(pages[i], offset, bytes, iter); } 而且 generic_file_buffered_read_get_pages 也非常之清晰: static int generic_file_buffered_read_get_pages(struct kiocb *iocb, struct iov_iter *iter, struct page **pages, unsigned int nr) nr_got = find_get_pages_contig(mapping, index, nr, pages); if (nr_got) goto got_pages; if (iocb->Ki_flags & IOCB_NOIO) return-EAGAIN; page_cache_sync_readahead (mapping, ra, filp, index, last_index-index); nr_got = find_get_pages_contig (mapping, index, nr, pages); if (nr_got) goto got_pages .} at this point, the study on "Linux kernel patch example analysis" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.