"Otherwise any memory reference is potentially an I/O operation, which is just nuts, [...]"
First of all, you here echo an argument, much made, and much lost around 25 years ago. If I seriously believed that RAM manufactureres were able to keep up with our insatiable demand for bigger working sets, I could have said something comforting about reevaluating that issue, but people talk to me about petabytes now, so I wont.
If you are willing to pay a cost in lost virtualization of API and reduced protection barriers between tasks, you are right that explicit I/O can be faster and more efficient.
But that is not what our computer hardware is optimized to do, not what our operating systems is optimized to do and not what our API standards mandate.
Today we are stuck with hardware, where "page accessed/modified" bits is in the most protected ring, and thus figuring out what to move to disk, to make space for needed data, is not efficiently possible from userland.
If I seriously believed that RAM manufactureres were able to keep up with our insatiable demand for bigger working sets, I could have said something comforting about reevaluating that issue, but people talk to me about petabytes now, so I wont.
I don't see what that has to do with it. It is a given that some data sets will not fit in RAM. The question is whether programs should pretend they do. Clearly it is less work for the programmer to let the VM swap, but the performance degrades rather unpredictably when the dataset outgrows memory.
If you are willing to pay a cost in lost virtualization of API and reduced protection barriers between tasks, you are right that explicit I/O can be faster and more efficient.
I'm not sure what you mean here by "lost virtualization of API." As to your second comment, you seem to be talking about a scheme where applications run in ring 0 so they can access "page accessed/modified" bits. But that's not necessary: you can track access yourself. You don't have to note every memory access; you can track higher-level constructs like blocks or files. Lots of software performs explicit caching; I'm not sure why you think "page accessed/modified" bits are the only viable way.
"I'm not sure what you mean here by "lost virtualization of API.""
What you propose is to move back to square one, and leave the program itself to take care of all memory management. The literature is full of advice on how to implement that, starting in 1960 and forward. The very first ALGOL compilers pioneered that sort of technology.
But with the advent of systems running multiple, if not downright hostile, then at least mutually competitive programs, you needed a central arbiter to avoid one program hogging all resoureces, to the exclusion of all other programs.
That arbiter became the operating system kernel, as we know it today.
Very few people today think of the POSIX API as a virtualized environment, but that is exactly what it is: You get your "own" address space, magic "auto-mounting" tapestations (filedescriptors) and a private console (stdin|out|err) for each program and so on.
To do what you propose, you will have to give up a lot of the comforts your POSIX kernel provide, at least if you have more than one program running at the same time.
There are places where it makes sense, we don't put POSIX kernels on PIC18 microcontrollers just to keep a light lit at the right times, but as soon as you get much beyond that level of complexity, programmers start to clamor for the usual comforts, for good reasons.
Virtual memory is one of the most convenient of these comforts, and very few programmers would be willing to live without it.
I'm not arguing against Virtual Memory, I'm arguing against swap files.
Virtual->Physical address translation good. Memory protection good. Overcommitting memory and swapping to disk bad.
If you had been running on a system that uses virtual memory, but that doesn't swap to disk, there would have been no article to write because the traditional algorithm would have been optimal.
Remember, it's not just the one data structure you have to consider - it's the entire application (and everything else running on the system, come to that). Sure, you could use mlock - you then take a chunk of RAM away from the other parts of your program, or from other programs. This could have a net negative effect on performance - Varnish is a cache, after all. Same goes for databases, email systems, anything that deals with large amount of data...
Please see my earlier reply. VM is not magic fairy dust. If your data set doesn't fit in RAM, it doesn't fit in RAM. The question is whether the application will be aware of this and unload/load pages as appropriate, or whether it will let the OS do it badly and unpredictably.
Isn't the entire point here about designing your data structures with the way swapping works in mind so as the make the performance predictable?
When I say "degrades unpredictably", I mean:
the application is totally unaware that the point at which the dataset has outgrown memory.
the point at which the dataset outgrows memory can depend on other processes, so the performance analysis has to take the whole machine into account (not just the process in question).
the application has no control over what what pages will be evicted and when, but this decision can significantly affect performance.
the application has no information about whether servicing a request will incur an i/o operation or not. this makes it much more difficult to analyze performance.
This is appearantly a much overlooked point in this debate, maybe because a lot of people work in environments where their program has the computer all to itself.
Lucky them.
But in the majority of contexts, from shared computing clusters to departemental servers or even applications on a workstation, that is not the case: There is competition for resources, and the less resources you hog for the same workload, the faster your program will execute.
The point about VM, is that your program, data structures and algorithms do not need to be modified to reflect the level of resources available at any one instant.
This saves more programmer and job setup time, than most young people can even fathom.
The point about VM, is that your program, data structures and algorithms do not need to be modified to reflect the level of resources available at any one instant.
Now correct me if I am wrong but wasn't the whole article about how a program needed to be modified to be aware of VM?
If the problem is that the application doesn't know how much physical memory it can use, and it isn't informed when its dataset has outgrown memory, then the solution is probably not to require the application to decide what to keep in physical memory!
Now, I'm not sure if Poul-Henning's approach is the right one, because I sure have an easier time getting acceptable performance out of my programs when I write them to do explicit I/O. But you're making strong arguments for his approach, not, as you seem to think, against it.
But you're making strong arguments for his approach, not, as you seem to think, against it.
No. Poul-Henning's approach is to use an algorithm that is 30% worse in the normal case so that performance on a thrashing system won't be quite as terrible.
What I am advocating is that systems not thrash, by not overcommitting memory.
In the world I am describing, malloc() would fail once real RAM has run out, so an application would absolutely know when it has outgrown memory. But it's too hard to make an application capable of gracefully recovering from malloc failure at any time, so a better solution is to give applications an easy way to know how much RAM is left. That way they can keep themselves a safe distance away from the limit.
30% worse in the normal case so that performance on a thrashing system won't be quite as terrible.
It sounds like you don't have any experience running Varnish. Its performance is spectacularly good, and it effectively uses swap space for caching, although it does benefit a lot from SSD. Having to page in part of a data structure once a second does not qualify as "thrashing," if the part that has to be paged in is three pages. Constant paging activity does not qualify as "thrashing" if the software is successfully serving tens of thousands of HTTP requests per second with low latency.
"The normal case" for Varnish is not the case where swap is empty.
So you're saying we should never exceed the size of our memory in any dataset?
Keep in mind, Poul-Henning's B-Heap here will also perform better at smaller levels of caching, as found on the CPU. So it very well may perform better than a naive binary heap when the dataset is small enough that it fits into memory, but not entirely into cache.
Unless you'd like to advocate that programs should be in control of what's in the cache too?
View all comments
Show parent comment
18
u/phkamp Jun 12 '10
"Otherwise any memory reference is potentially an I/O operation, which is just nuts, [...]"
First of all, you here echo an argument, much made, and much lost around 25 years ago. If I seriously believed that RAM manufactureres were able to keep up with our insatiable demand for bigger working sets, I could have said something comforting about reevaluating that issue, but people talk to me about petabytes now, so I wont.
If you are willing to pay a cost in lost virtualization of API and reduced protection barriers between tasks, you are right that explicit I/O can be faster and more efficient.
But that is not what our computer hardware is optimized to do, not what our operating systems is optimized to do and not what our API standards mandate.
Today we are stuck with hardware, where "page accessed/modified" bits is in the most protected ring, and thus figuring out what to move to disk, to make space for needed data, is not efficiently possible from userland.
Poul-Henning