LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-10-2010, 02:42 PM   #1
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 999

Rep: Reputation: 142Reputation: 142
Why not write to HDD when not busy?


Hi!

Well, this might be a very stupid question, but I have it "in my throat" since a long time - I finally decided to dare asking it :


When I write something to HDD Linux (and probably as well all other OSs) keeps it back in RAM and waits until a timeout has been reached or it waits that a specific event happens (e.g. the cached informations that haven't been written yet reaches a certain amount of the total RAM) before that it decides to flush the buffers and effectively write the informations to HDD.

Why?
Wouldn't it be better, when the HDD is idle, to write that stuff immediately instead of waiting e.g. 40 seconds risking that when that timeout is reached the HDD receives at the same time another command to read something different from HDD resulting in a congested HDD?

The logic that I think that Linux uses is more or less:
"Keep the informations in memory until 1) timeout is reached and/or 2) buffer limit is reached and/or 3) a sync command is given".

Wouldn't it be better this way?
"Write bits of informations to HDD whenever the HDD is idle and 1) write expired informations when timeout is reached and/or 2) buffer limit is reached and/or 3) a sync command is given.
When writing to HDD and a read command needs HDD access stop writing unless 1/2/3 occur".

Hope I was able to explain what I mean.
Thx!
 
Old 02-10-2010, 02:50 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Your logic is fine---all I can offer is that it seems to work fine the way it is. The real test is whether the user sees smooth operation.
 
1 members found this post helpful.
Old 02-10-2010, 03:02 PM   #3
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Linux 11 (Bullseye)
Posts: 3,407

Rep: Reputation: 141Reputation: 141
Hate to bust your bubble, but there is no low-hanging fruit in the kernel - mostly because the guys who write the drivers aren't high school kids doing it after school. Yes, they're volunteers, but yes (again) they are professionals in their real lives. If you have a question about how the various filesystem types work, then google is your friend. The kernel source is also available. There are also various kernel developer mailing lists.
 
0 members found this post helpful.
Old 02-10-2010, 04:57 PM   #4
CoderMan
Member
 
Registered: Jan 2009
Location: Gemini Capsule 25164
Distribution: Gentoo
Posts: 375
Blog Entries: 24

Rep: Reputation: 43
I won't pretend to be an expert on the subject, but I know that certain file systems like XFS make use of this buffering, in conjunction with delayed allocation, to decrease file system fragmentation and improve performance.

Keep in mind that writing data to your hard drive is one of the slowest operations routinely performed on your computer. If I recalled the statistics correctly, it can take 1000x longer or more to write data to a hard drive rather than other sources of memory on your computer. So don't knock the system too hard before you have a good understanding of the technical difficulties involved.
 
1 members found this post helpful.
Old 02-10-2010, 07:19 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
The general rule of thumb I was taught was that each step away from the cpu is (roughly) an order of magnitude slower to read/write ie x10, so:

cpu = 1
cache = x10 slower
RAM = x10 slower than cache
disk = x10 slower than RAM
 
Old 02-11-2010, 05:06 AM   #6
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
Quote:
Wouldn't it be better, when the HDD is idle,......
It is impossible to determine that the HDD is "idle", at the instant anything decides to write to it.

You can determine that the HDD has been idle (for the last 4 seconds perhaps), but by now you have missed the opportunity to use it whilst no other process was using it.

The very moment you do decide to write to it, some other process could start up and want to use the disk as well, so it is now no longer "idle".

See the problem?

I am happy to leave this stuff to the kernel maintainers.
 
2 members found this post helpful.
Old 02-11-2010, 06:14 AM   #7
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 999

Original Poster
Rep: Reputation: 142Reputation: 142
Well CoderMan, you're right about the issue with the fragmentation - that's a point I missed.
And tredegar you're right as well mentioning the problem of the current status which has actually already elapsed... .

We'll see!

Thank youuu!
 
Old 02-11-2010, 11:54 AM   #8
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Quote:
Originally Posted by CoderMan View Post
I won't pretend to be an expert on the subject, but I know that certain file systems like XFS make use of this buffering, in conjunction with delayed allocation, to decrease file system fragmentation and improve performance.
Yup, XFS can do this if you set the options right. I think recently ext4 does this by default (which is madness, IMO). If the power goes out before it writes it from RAM to HDD ... you can say goodbye to your data.
 
Old 02-11-2010, 12:00 PM   #9
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Linux 11 (Bullseye)
Posts: 3,407

Rep: Reputation: 141Reputation: 141
Quote:
Originally Posted by tredegar View Post
The very moment you do decide to write to it, some other process could start up and want to use the disk as well, so it is now no longer "idle".

See the problem?
Processes do not write directly to the disk, and haven't since DOS when there was only one process running at a time. Processes send read/write requests to the operating system. The operating system decides when and how to service those requests. In some cases, the data for a read is already in memory, so the kernel will supply that. In other cases, the disk has to read, and the kernel places the read request on a queue where it will be prioritized and ordered and eventually sent to the disk. There is also a write queue where write requests are ordered and prioritized to be sent to the disk. Some filesystems have a journal that is written to first, as it is faster, and then the journal is played into the disk when there is time.
 
0 members found this post helpful.
Old 02-11-2010, 12:03 PM   #10
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Linux 11 (Bullseye)
Posts: 3,407

Rep: Reputation: 141Reputation: 141
Quote:
Originally Posted by H_TeXMeX_H View Post
Yup, XFS can do this if you set the options right. I think recently ext4 does this by default (which is madness, IMO). If the power goes out before it writes it from RAM to HDD ... you can say goodbye to your data.
Let's not forget that memory buffers are flushed to disk every 5 seconds. Sure, you can lose 5 seconds worth of data, but as modern filesystems get trickier (more madness) the chance of losing filesystem integrity decreases. Which means less chance of losing data on a large scale.
 
Old 02-11-2010, 12:11 PM   #11
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Quote:
Originally Posted by Quakeboy02 View Post
Let's not forget that memory buffers are flushed to disk every 5 seconds. Sure, you can lose 5 seconds worth of data, but as modern filesystems get trickier (more madness) the chance of losing filesystem integrity decreases. Which means less chance of losing data on a large scale.
I think with XFS you can even change that option to be longer. Still 5 seconds is a long time ... you could lose at around 50 MB/s ... 250 MB of data.
 
Old 02-11-2010, 12:23 PM   #12
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Linux 11 (Bullseye)
Posts: 3,407

Rep: Reputation: 141Reputation: 141
Quote:
Originally Posted by H_TeXMeX_H View Post
I think with XFS you can even change that option to be longer. Still 5 seconds is a long time ... you could lose at around 50 MB/s ... 250 MB of data.
If your needs are really that critical, you might want to invest in a UPS.
 
Old 02-11-2010, 12:57 PM   #13
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Quote:
Originally Posted by Quakeboy02 View Post
If your needs are really that critical, you might want to invest in a UPS.
I got one ... it's great, especially here where the power is not at all stable.
 
Old 02-11-2010, 02:26 PM   #14
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 999

Original Poster
Rep: Reputation: 142Reputation: 142
Just for information: did you try btrfs? And if yes, did you have any bad experiences using it with a recent kernel?

I gave it a shot for the first time a few months ago and I really liked the "re-balance" & "re-sizing" it did to a raid5 when I added an additional HDD to the 3 HDDs I had initially.

A few weeks ago I therefore decided to use it as root fs for my netbook and until now I had no issues, apart from the fact that (only?) Gentoo does not have (yet?) a fsck that runs when the PC boots (and btrfs doesn't apparently support yet a fsck on mounted filesystems).

Performance seems to be ok, especially when running a non-cached "emerge" (the package manager of Gentoo) which reads a large amount of small files - I have the feeling that when doing that it's faster than xfs, reiserfs (for a long time my favourite, now with btrfs as candidate replacement) and jfs. But I don't have yet numbers available to validate my statement.
 
Old 02-11-2010, 02:51 PM   #15
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Linux 11 (Bullseye)
Posts: 3,407

Rep: Reputation: 141Reputation: 141
Looks very Oracle-ish. But, does it do anything to address the question you posed in your original post?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't write to HDD, really annoying baldurpet Linux - Newbie 4 10-01-2009 01:50 AM
How can I force tar to over-write busy files? KenShelby Linux - Newbie 12 06-17-2009 06:36 PM
help with fstab can't write to second hdd albertBeach Linux - Newbie 7 07-20-2006 08:34 AM
HDD write protection pingvina Linux - Software 17 02-11-2006 06:59 PM
cannot write on external HDD trutnev Red Hat 2 03-20-2004 03:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration