I was diving into the kernel source code and I noticed this function set_bh_page()
. However, I could not understand clearly what it does.
I could only find this comment in the fs/buffer.c
file:
/* Link the buffer to its page */
set_bh_page(bh, page, offset);
But it is still not clear to me what it does.
So, to make it clear, I want to understand what is the relationship of this function call to the buffer and physical page, as well as if it has anything to do with the page cache itself.
UPDATE 1:
The function alloc_page_buffers()
calls this set_bh_page()
, and there is some comment about that, as follows:
Create the appropriate buffers when a given a page for data area and the size of each buffer.. User the bh->b_this_page linked list to follow the buffers created. Return NULL if unable to create more buffers.
And I checked who calls the alloc_page_buffers()
, which one of them is the read_page()
, that has this description:
Read a page from a file.
We both read the page, and attach buffers to the page to record the address of each block (using bmap). These addresses will be used to write the block later, completely bypassing the filesystem. This usage is similar to how swap files are handled, and allows us to write to a file with no concerns of memory allocation failing.
So, by looking through the source code of read_page()
, my understanding is that the buffer_head
allocated must be associated to its physical page address, like a direct mapping.
Is that correct?