LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how ext2/3/4 handles random writes. (https://www.linuxquestions.org/questions/linux-newbie-8/how-ext2-3-4-handles-random-writes-4175498585/)

vinayak099 03-18-2014 05:49 AM

how ext2/3/4 handles random writes.
 
Hi,

I am little curious to know and understand ext4 file system. But I am not able to understand how the ext4 handles random write.

ex : assume that I have file called
"f1.txt", initilally constains
"HI I am vinayak, trying to learn ext4 file system"

now I will insert "good morning," between "HI" and "I"
Now the file contents of f1.txt will be
"HI good morning, I am vinayak, trying to learn ext4 file system"

In this case file content is very small and I can easily read the contents of the file, can insert the string and other content can be moved by the length of the string.

But how it is handled in case of big file (1 GB etc), if I want to apply the patch to such a big file. Because applying patch requires changes in several places and each time data should be moved across the blocks.

Can anybody explain me how write to such big files will happen. I mean how the insertion of the string happens and blocks will be adjusted.

gengisdave 03-18-2014 06:33 AM

how ext2/3/4 handles random writes.
 
Fast explanation: to preserve file fragmentations, ext4 allocate a new file far after the end of the previous one, so it can grow without being fragmented.

vinayak099 03-18-2014 06:50 AM

But how ext4 handles the data integrity ?

ex : I will open the file 10 times and each time I will add some strings at different positions randomly ( assume that file is of 100 MB ).

Now, ext4 should handle the case by inserting the string at different offsets.

In this case, does ext4 will allocate new block for every addition of the string (it results in disk fragmentation.) or creates new file every time and writes the modified data again (time overhead is more in this case )?

How it handles data integrity and performance in this case ?

Can you please help me in understanding it.

gengisdave 03-18-2014 07:24 AM

how ext2/3/4 handles random writes.
 
https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout

long explanation :)

vinayak099 03-18-2014 08:00 AM

Thank you. Hope it will clear my doubts.


All times are GMT -5. The time now is 07:32 PM.