Disk scheduling algorithms are crucial for optimizing the performance of disk drives. They determine the order in which disk I/O requests are processed, thereby reducing seek time and improving throughput.
FCFS is the simplest disk scheduling algorithm. Requests are processed in the order they arrive.
// Example of FCFS Disk Scheduling
import java.util.LinkedList;
import java.util.Queue;
class FCFSDiskScheduling {
public static void main(String[] args) {
int[] requests = {98, 183, 37, 122, 14, 124, 65, 67};
int headStart = 53;
fcfs(requests, headStart);
}
static void fcfs(int[] requests, int headStart) {
int totalSeekTime = 0;
int currentPosition = headStart;
for (int request : requests) {
totalSeekTime += Math.abs(request - currentPosition);
currentPosition = request;
}
System.out.println("Total Seek Time: " + totalSeekTime);
}
}
Simple to implement and understand, making it a good choice for small systems.
High variance in response time; not efficient for large workloads.
SSTF selects the request closest to the current head position, minimizing seek time.
// Example of SSTF Disk Scheduling
import java.util.*;
class SSTFDiskScheduling {
public static void main(String[] args) {
int[] requests = {98, 183, 37, 122, 14, 124, 65, 67};
int headStart = 53;
sstf(requests, headStart);
}
static void sstf(int[] requests, int headStart) {
List requestList = new ArrayList<>();
for (int request : requests) {
requestList.add(request);
}
int totalSeekTime = 0;
int currentPosition = headStart;
while (!requestList.isEmpty()) {
int closestRequest = findClosestRequest(requestList, currentPosition);
totalSeekTime += Math.abs(closestRequest - currentPosition);
currentPosition = closestRequest;
requestList.remove((Integer) closestRequest);
}
System.out.println("Total Seek Time: " + totalSeekTime);
}
static int findClosestRequest(List requests, int currentPosition) {
int minDistance = Integer.MAX_VALUE;
int closestRequest = -1;
for (int request : requests) {
int distance = Math.abs(request - currentPosition);
if (distance < minDistance) {
minDistance = distance;
closestRequest = request;
}
}
return closestRequest;
}
}
Minimizes seek time effectively for most workloads.
Can lead to starvation of requests far from the current head position.
The SCAN algorithm moves the disk arm across the disk, servicing requests in one direction before reversing.
// Example of SCAN Disk Scheduling
import java.util.*;
class SCANDiskScheduling {
public static void main(String[] args) {
int[] requests = {98, 183, 37, 122, 14, 124, 65, 67};
int headStart = 53;
int diskSize = 200;
scan(requests, headStart, diskSize);
}
static void scan(int[] requests, int headStart, int diskSize) {
Arrays.sort(requests);
int totalSeekTime = 0;
int currentPosition = headStart;
boolean directionUp = true;
List requestList = new ArrayList<>();
for (int request : requests) {
requestList.add(request);
}
while (!requestList.isEmpty()) {
int nextRequest = findNextRequest(requestList, currentPosition, directionUp);
if (nextRequest == -1) {
directionUp = !directionUp;
continue;
}
totalSeekTime += Math.abs(nextRequest - currentPosition);
currentPosition = nextRequest;
requestList.remove((Integer) nextRequest);
}
System.out.println("Total Seek Time: " + totalSeekTime);
}
static int findNextRequest(List requests, int currentPosition, boolean directionUp) {
if (directionUp) {
for (int request : requests) {
if (request >= currentPosition) {
return request;
}
}
} else {
for (int i = requests.size() - 1; i >= 0; i--) {
if (requests.get(i) <= currentPosition) {
return requests.get(i);
}
}
}
return -1;
}
}
Reduces variance in response time and avoids starvation.
May still have higher seek time compared to more advanced algorithms.
C-SCAN treats the disk as a circular list that wraps around from the last cylinder to the first.
// Example of C-SCAN Disk Scheduling
import java.util.*;
class CSCANDiskScheduling {
public static void main(String[] args) {
int[] requests = {98, 183, 37, 122, 14, 124, 65, 67};
int headStart = 53;
int diskSize = 200;
cscan(requests, headStart, diskSize);
}
static void cscan(int[] requests, int headStart, int diskSize) {
Arrays.sort(requests);
int totalSeekTime = 0;
int currentPosition = headStart;
List requestList = new ArrayList<>();
for (int request : requests) {
requestList.add(request);
}
while (!requestList.isEmpty()) {
int nextRequest = findNextRequest(requestList, currentPosition);
if (nextRequest == -1) {
totalSeekTime += (diskSize - 1 - currentPosition);
currentPosition = 0;
continue;
}
totalSeekTime += Math.abs(nextRequest - currentPosition);
currentPosition = nextRequest;
requestList.remove((Integer) nextRequest);
}
System.out.println("Total Seek Time: " + totalSeekTime);
}
static int findNextRequest(List requests, int currentPosition) {
for (int request : requests) {
if (request >= currentPosition) {
return request;
}
}
return -1;
}
}
Provides a more uniform wait time for requests.
Can result in higher overall seek time compared to SCAN.
The LOOK algorithm is similar to SCAN but does not go to the end of the disk unless there is a request.
// Example of LOOK Disk Scheduling
import java.util.*;
class LOOKDiskScheduling {
public static void main(String[] args) {
int[] requests = {98, 183, 37, 122, 14, 124, 65, 67};
int headStart = 53;
look(requests, headStart);
}
static void look(int[] requests, int headStart) {
Arrays.sort(requests);
int totalSeekTime = 0;
int currentPosition = headStart;
boolean directionUp = true;
List requestList = new ArrayList<>();
for (int request : requests) {
requestList.add(request);
}
while (!requestList.isEmpty()) {
int nextRequest = findNextRequest(requestList, currentPosition, directionUp);
if (nextRequest == -1) {
directionUp = !directionUp;
continue;
}
totalSeekTime += Math.abs(nextRequest - currentPosition);
currentPosition = nextRequest;
requestList.remove((Integer) nextRequest);
}
System.out.println("Total Seek Time: " + totalSeekTime);
}
static int findNextRequest(List requests, int currentPosition, boolean directionUp) {
if (directionUp) {
for (int request : requests) {
if (request >= currentPosition) {
return request;
}
}
} else {
for (int i = requests.size() - 1; i >= 0; i--) {
if (requests.get(i) <= currentPosition) {
return requests.get(i);
}
}
}
return -1;
}
}
Reduces unnecessary head movement and improves efficiency.
Still can lead to starvation if not managed properly.
C-LOOK is a variant of the LOOK algorithm that wraps around the end of the disk to the beginning.
// Example of C-LOOK Disk Scheduling
import java.util.*;
class CLOOKDiskScheduling {
public static void main(String[] args) {
int[] requests = {98, 183, 37, 122, 14, 124, 65, 67};
int headStart = 53;
clook(requests, headStart);
}
static void clook(int[] requests, int headStart) {
Arrays.sort(requests);
int totalSeekTime = 0;
int currentPosition = headStart;
List requestList = new ArrayList<>();
for (int request : requests) {
requestList.add(request);
}
while (!requestList.isEmpty()) {
int nextRequest = findNextRequest(requestList, currentPosition);
if (nextRequest == -1) {
currentPosition = requestList.get(0);
continue;
}
totalSeekTime += Math.abs(nextRequest - currentPosition);
currentPosition = nextRequest;
requestList.remove((Integer) nextRequest);
}
System.out.println("Total Seek Time: " + totalSeekTime);
}
static int findNextRequest(List requests, int currentPosition) {
for (int request : requests) {
if (request >= currentPosition) {
return request;
}
}
return -1;
}
}
Efficient for large workloads with uniformly distributed requests.
Can still lead to starvation for requests at the far ends.
Newsletter
Subscribe to our newsletter for weekly updates and promotions.
Wiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterCompany
About usCareersPressCompany
About usCareersPressCompany
About usCareersPressLegal
TermsPrivacyContactAds PoliciesLegal
TermsPrivacyContactAds PoliciesLegal
TermsPrivacyContactAds PoliciesCompany
About usCareersPressCompany
About usCareersPressCompany
About usCareersPressLegal
TermsPrivacyContactAds PoliciesLegal
TermsPrivacyContactAds PoliciesLegal
TermsPrivacyContactAds PoliciesLegal
TermsPrivacyContactAds PoliciesAds Policies