Blocking and Buffering
Blocking and Buffering
CS 102
File Structures & File Organizations
Accessing secondary storage takes longer than accessing main memory Usually, processing a file component by the CPU is much less than reading or writing the component in the file. Block smallest amount of data that can be read from or written to secondary storage at a time.
Chapter 02
CJD
Blocking
Blocking grouping several file components : usually records. If a record is too long to fit a block, it will span several blocks. Blocking improves execution times of programs that access files fewer accesses retrieve the entire file by block instead of by record. less physical accesses means less total execution time
a record
CJD
Blocking Factor
Blocking factor is configurable Blocking Factor = number of components (or records) per block Many points must be considered in deciding the size of a block.
a block of 3 records
CJD
Blocking Examples
10,000 components must be added to a new file. One component to a block requires 10,000 accesses If a blocking factor of 10 is used, there will be 10,000 components / 10 components per block = 1,000 blocks requiring only 1,000 accesses. If a blocking factor of 100 is used, there will be 10,000 components / 100 components per block = 1,00 blocks requiring only 100 accesses. If a blocking factor of 10,000 is used, there will only be 1 block requiring only 1 physical access.
CJD
Single Buffering
Buffer a location in main memory used to store a block of data. It has the same size as a block of data. The CPU directs the I/O channel to access a particular device to read or write data. The I/O channel directs a device controller to input or output data for the device. Blocking and Deblocking is executed by the I/O channel of a computer.
Physical I/O Storage Buffer Logical I/O CPU
CJD
CJD
There are more records per block in File B. File B has less blocks per file. Because of the overhead per physical I/O, accessing file B is faster.
CJD CJD
Double Buffering
Single Buffering : The CPU waits until each physical I/O operation is completed. The I/O channel is idle while the CPU is executing the non I/O parts of a program. Double Buffering : providing two buffers per file improves program execution when I/O operations and CPU processing overlap in time.
CJD
Single Buffering Total File (50 ms to read + 25 Processing ms to process) per time block x 1000 blocks per file = 75,000 ms = 75 seconds
Double Buffering (50 ms to read each block x 1000 blocks per file) + 25 ms to process first block = 50,025ms 50 seconds
CJD
CJD
Double buffering savings is 75 50 = 25 seconds or about ((75 50) / 75 ) * 100% = 33% of single buffering time.
75 50
75 50
75 50
50
CJD
Single Buffering Total File (50 ms to write + 75 Processing ms to process) per time block x 1000 blocks per file = 125,000 ms = 125 seconds
Double Buffering (75 ms to process each block x 1000 blocks per file) + 50 ms to write last block = 75,050ms 75 seconds
CJD
Double buffering savings is 125 75 = 50 seconds or about ((125 75) / 125 ) * 100% = 40% of single buffering time.
CJD
Exercise
Question : When a certain job is executed in a computer system, 40 percent of the total processing time of the job is used for CPU and the rest is spent waiting for I/O to complete. If a newer CPU whose speed is two times faster than the current one is installed, approximately how many times faster is the new system than the current system? Here, the system environment except for the CPU remains unchanged. Solution : 40 + 60 ------------- = 100/80 = 1.25 40/2 + 60
End
CJD
CJD