Reputation: 1452
Lets say I have a big file (or just raw storage if that is even possible in any popular operating systems) on disk that I am going to need to operate on. Is there a way to let the operating system know that I would like the entire chunk of data to be eagerly loaded into memory rather than having only a tiny chunk of it initially loaded into memory and page faulting every time I try to access a segment that hasn't been loaded into memory yet? I'm thinking this would be more for memory mapped files, since the operating system probably already does a good job of having things preloaded if you are doing sequential reads. I'm sure it's technically possible to write an operating system that provides the functionality I am looking for, but does it exist in any popular operating systems? Also, do most operating systems already preload the entire block into memory by default if there is extra RAM available? If operating systems provide this functionality, what programming language support exists for accessing this functionality?
Upvotes: 0
Views: 72
Reputation: 48682
As commentators have pointed out, for the case of sequential reading, modern operating systems already perform a read-ahead optimisation that does this for you.
For other kinds of input, you could make use of asynchronous I/O.
If your program knows it will need to some read data in the future, but does not need it immediately, it dispatches a request for asynchronous input of the data.
When the program advances to the point where it needs that data, it examines the state of the asynchronous request.
If the request has been satisfied, the optimisation worked, and the program can process the requested data without blocking.
If the request has not yet been satisfied, the program blocks until the data is ready. Although the program still has to block for this case, the length of time it is blocked will be less that for the case of synchronous I/O.
Upvotes: 0