LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-20-2010, 12:16 AM   #1
harit agarwal
LQ Newbie
 
Registered: Aug 2008
Location: allahabad
Posts: 21

Rep: Reputation: 15
block read ahead algorithm


algorithm:breada
input:file system block number for immediate read
file system block number for asynchronous read
output:buffer containing data for immediate read
{
if(first block not in cache)
{
get buffer for first block
if(buffer data not valid)
initiate disk read
}
if(second block not in cache)
{
get buffer for second block)
if(buffer data valid) //line 1
release buffer
else
initiate disk read //line 2
}
if(first block was originally in cache) //line 3
{
read first block
return buffer
}
sleep(event first buffer contains valid data)
return buffer
}

here is an algorithm for block read algorithm. i have problem in
line 1: if buffer data is valid why is it releasing the buffer?
line 2: if buffer data valid why is it initiating disk read. it should have read directly from buffer?
line 3:it should be the first condition as if it is there in cache then it should return it without delay?

so please clear my doubts in these statements.....
 
Old 05-20-2010, 12:43 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by harit agarwal View Post
algorithm:breada
input:file system block number for immediate read
file system block number for asynchronous read
output:buffer containing data for immediate read
{
if(first block not in cache)
{
get buffer for first block
if(buffer data not valid)
initiate disk read
}
if(second block not in cache)
{
get buffer for second block)
if(buffer data valid) //line 1
release buffer
else
initiate disk read //line 2
}
if(first block was originally in cache) //line 3
{
read first block
return buffer
}
sleep(event first buffer contains valid data)
return buffer
}

here is an algorithm for block read algorithm. i have problem in
line 1: if buffer data is valid why is it releasing the buffer?
line 2: if buffer data valid why is it initiating disk read. it should have read directly from buffer?
line 3:it should be the first condition as if it is there in cache then it should return it without delay?

so please clear my doubts in these statements.....
Please copy-paste screen output of

Code:
cat -n your_file.c
Please use code tags - for that go to "Advance" menu, select your with mouse and press '#' button.
 
0 members found this post helpful.
Old 05-20-2010, 01:31 AM   #3
murugesan
Member
 
Registered: May 2003
Location: Bangalore ,Karnataka, India, Asia, Earth, Solar system, milky way galaxy, black hole
Distribution: murugesan openssl
Posts: 181

Rep: Reputation: 29
Kindly read the book:
Bach M.J. The design of the Unix operating system related to chapter 3:
Links given here for each chapter:
or available at beginning of each chapter.
Quote:
Top / Software manuals / [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]

I prefer to use the book instead of using the url mentioned here as it does not contain the diagrams mentioned in each chapter.


Refer "4.7 ALLOCATION OF DISK BLOCKS"
Refer how OS uses buffer cache.

Last edited by murugesan; 05-20-2010 at 01:36 AM. Reason: Edited this for error while accessing the urls mentioned here.
 
Old 05-20-2010, 03:18 AM   #4
harit agarwal
LQ Newbie
 
Registered: Aug 2008
Location: allahabad
Posts: 21

Original Poster
Rep: Reputation: 15
i read this algorithm from the same book but still i have some issues after reading it (as i already posted in my first post).....so please clarify those doubts....
 
Old 05-20-2010, 04:32 AM   #5
murugesan
Member
 
Registered: May 2003
Location: Bangalore ,Karnataka, India, Asia, Earth, Solar system, milky way galaxy, black hole
Distribution: murugesan openssl
Posts: 181

Rep: Reputation: 29
Quote:
Originally Posted by harit agarwal View Post
line 1: if buffer data is valid why is it releasing the buffer?
This requires information to read on "brelse" algorithm (provided you have gone through 5 steps mentioned in "the kernel may follow in getblk".)

Quote:
Originally Posted by harit agarwal View Post
line 2: if buffer data valid why is it initiating disk read. it should have read directly from buffer?
Kernel will go to initiate disk read when the buffer data is invalid.

Quote:
Originally Posted by harit agarwal View Post
line 3:it should be the first condition as if it is there in cache then it should return it without delay?
This is because the following statement is given in the book:
"If the second block is not in the buffer cache, the kernel instructs the disk driver to read it ASYNCHRONOUSLY."
 
Old 05-20-2010, 05:34 AM   #6
harit agarwal
LQ Newbie
 
Registered: Aug 2008
Location: allahabad
Posts: 21

Original Poster
Rep: Reputation: 15
thanks i got it.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
silo read error on block <number>... results in a short read peterlowrie Linux - Hardware 0 02-07-2010 07:39 PM
what is the Linux iso-9660 filesystem read ahead bug ? electronpusher Linux - General 2 08-31-2008 03:54 PM
Raid disk problem : Attempt to read block from filesystem resulted in short read ElmPie Linux - General 5 08-26-2008 05:21 AM
Error reading block "x" (Attempt to read block from....... pvandyk2005 Slackware 6 07-06-2008 05:25 AM
CDROM read ahead questions!! wrapster Solaris / OpenSolaris 3 06-29-2008 11:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:06 AM.

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