I am newbie to Linux kernel and just started to know how zram
works. Initial testing, I am seeing that READ
is issued before WRITE
just after the zram
is being initialized. But I am just eager to know, why this is so ?
As an activity I took the dump_stack()
and followed the path form where to how this zram
read is being performed.
zram
get to know this info whether it has to do READ
or WRITE
operation on issued bio->bi_rw
. Code flow is like that zram_make_request
API is being called from create_device
in zram
driver. And zram_make_request
internally called __zram_make_request
which called the zram_bvec_rw
API.
In zram_bvec_rw
API check the available info of bio->bi_rw
and correspondingly issued the READ
and WRITE
call.
Now, in this case what is happening: READ
is being encapsulated inside bio
struct itself. As triage I found that submit_bh
fills all the entry of bio
and issued the submit_bio
.
I was wondering who is actually sets the bio->bi_rw
as READ
. By enabling the few prints I found that ll_rw_block
API is being called by __block_write_begin
with READ
, later ll_rw_block
calls the submit_bh
API where rest of bio
struct entries are filled.
But I am still not getting the answer why READ
is issued for ll_rw_block
from __block_write_begin
?
- zram driver:
if (!buffer_uptodate(bh) && !buffer_delay(bh) &&
!buffer_unwritten(bh) &&
(block_start < from || block_end > to)) {
ll_rw_block(READ, 1, &bh);
*wait_bh++=bh;
}
buffer_uptodate(bh), /* Contains valid data */
buffer_delay(bh), /* Buffer is not yet allocated on disk */
buffer_unwritten(bh), /* Buffer is allocated on disk but not written */
Please can someone give an explaination/answer to my question ?
How I am concluding that read is perfomed before write ??
I just check the num_reads
and num_writes
count. And num_reads
count is set to 1
while num_writes
is found 0
when we do mkswap /dev/block/zram0
and after calling the swapon /dev/block/zram0
the final counts are num_reads = 2 and num_writes=1
.
NOTE: This is the case when we don't performing any additional zram
activity. We got this behavior in case as explained above.