Elevator algorithm (1)

Source: Internet
Author: User

Elevator algorithm (1)

Hedgehog @ http://blog.csdn.net/littlehedgehog

 

The elevator algorithm is mainly used for disk seek optimization.

The first is our most primitiveFirst come first served)Algorithm. This is suitable for us to get a meal out of the restaurant first. Otherwise, our customers may have opinions. However, it is not suitable for disk searching. For example:

Note that this figure does not explain the first-come-first-served algorithm. We just borrowed it.

Suppose we are currently reading 11th data records, and there are other processes that require us to provide them with disk content. Here we will read the cylinder (if you are not studying disk seek, then you can understand this word as a data block, that is, the small block above) 1, 36, 16, 34, 9, and 12 are recorded in the order required by the process. in strict accordance with the first-come-first-served principle, the next cylinder we want to go to is 1, there will be 10 cylinders in the middle, and then 36 ....... after reading all the data, we will calculate that we have to "run" A total of 111 cylinders.

Obviously, this algorithm is too inefficient. We need to improve it.

The second type isShortest seek first)

This algorithm is a bit greedy, that is, every time we choose a point (cylindrical) closest to our current point ). For example, if we have finished reading Block 11 and the next block is the last block 12, we can read the data of Block 12, then read Block 16 ...... we can see that if this algorithm is used, the number of blocks we pass through is 12, 9, 16, 1, 34, and 36. In this way, we have a total of 61 cylinders, in this way, we greatly save the tracing time.

 

This algorithm is already good, but we have to face the following problem: we are reading Block 16 and are about to read Block 1, this is a process breaking in and asking us to provide him with information on block 20. The distance between the 20 and the 16 is relatively close. Let's go to the 20th, then we receive a message requesting data on the 23rd ..... keep doing this. Er, what about information on the 1st? When does Dawn wait to read its content!

So here we need an algorithm to balance efficiency and fairness (we do not want to discriminate against small square 1 ). So we introducedElevator Algorithm. We need to make a mark to mark whether to read in the big direction or small direction. If the read is forward (the number is big), we need to keep reading until the last one. Similarly, backward read. Shows the algorithm:

 

For details, refer to operating system design and implementation.

 

The first time I wrote a blog, I wrote it all by myself.

Pray for the suffering people in the earthquake in their hometown

Foreign customers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.