Re: Automatic memory management
Posted: Tue Nov 24, 2015 10:34 am
Hi,
If you've disabled pre-fetch; it should be fairly easy to estimate the performance difference it could make. For example, boot the computer and measure how long it takes to start eclipse (when none of eclipse's files are in the OS's file cache), and then close eclipse and start it a second time (when all of eclipse's files are in the OS's file cache). I'm not sure about eclipse (it's written in Java so there'd be a huge amount of bloat during application start-up that pre-fetching can't avoid); but I do know that things I use are noticeably slower after rebooting (e.g. starting a web brower, my own project's build utility, etc), mostly because Linux is extremely bad at pre-fetching.
Note that it's actually common for users to think "Hey, I've got plenty of RAM so I don't need swap space" because they don't understand the role swap plays in a well designed system (and this is made worse by some old and/or poorly designed OSs that don't use swap space and/or pre-fetching very well). We are supposed to be OS developers and not just normal users, so we should know better.
Cheers,
Brendan
I really think you don't understand the difference between "pre-fetching" (e.g. before any application is started) and plain old "fetching" (e.g. after a program is started).embryo2 wrote:Database, browser, game.Brendan wrote:What application?
And there are also the Notepad, Calculator or Minesweeper.
For the first list it is important to have tools an application can use to cache it's data or code. For the second list may be it is better if the OS takes care of the caching. If there are some common libraries (used by notepad and calculator and many other applications) then the library itself can optimize the caching better than OS can. But it requires some change in the way the libraries are created.
However, some common things are suitable for the OS. And the OS can improve the application's performance even better if it has additional information like the AOT or JIT can provide. It means the OS is destined to include the features that help it "manage" the application. Yes, in the end it's the managed environment.Prefetching "most of the files" is inefficient. The browser can help and tell the OS "I need this and this". But of course, there can be some cooperation.Brendan wrote:From past behaviour it should know only one user logs on, and it should know it's very likely that user is going to use a web browser sooner or later; so it should have pre-fetched most of the files that the web browser would want.
The only difference between free RAM and RAM that's being used to cache data (including pre-fetched data) is that free RAM contributes nothing to performance and is being pointlessly wasted. In both cases, if something more important needs the RAM it can be allocated.embryo2 wrote:The effect of such prefetch is negligible. And there also should be some service for frequent refresh of the prefetched data to detect it's changes. Such service requires some memory. Also the actually prefetched data requires some memory. The indexes and pattern usage statistics also require some memory. Final result will be less memory for 100ms gain in the page load speed.Brendan wrote:It should also pre-fetch the IP addresses for some frequently used domain names
IO priorities are standard practice (and are supported and used internally by every major OS). The only real problem is that most programming languages (and/or their standard libraries) are crippled jokes that don't let the programmer explicitly specify priority.embryo2 wrote:Hopefully, it starts the prefetching with some background priority. And also hopefully, I can tell the OS what I want and what I do not want to be prefetched (a bit of extra control over the situation).Brendan wrote:If I was playing a game that gobbles a lot of RAM and then exit the game; the OS should notice there's suddenly a lot of "under-used"/free RAM and start pre-fetching.
I have no idea what you're saying here. Are you talking about the scheduler (that schedules CPU time), or any of the many IO schedulers, or a "job scheduler" (like Cron)? Note that none of these run once per day.embryo2 wrote:There are such things as schedulers. User or scheduler's developer still know better what it is for and how to optimize it. And even more, because the scheduler runs not so often (once per day while I can run a browser many times a day) it can be in the state "poorly prefetched". But when it starts it's disk usage can break my uninterrupted work in browser. It's actually the case for some antivirus soft and it's scheduled updates on my PC (and it also wants to do all it can at the boot time when it seems the OS allows you to start working, but there's this ugly thing running...).Brendan wrote:If I happen to start the web browser while it's pre-fetching the browser's executable the OS just bumps that file up to "high priority".
Pre-fetching is the sort of thing that would take a fair bit of "trial and error" and tuning to get right; but I've never noticed anything periodically slowing down without an obvious cause (e.g. garbage collectors).embryo2 wrote:I know it. And the prefetch is not working "as expected". May be there are some other problems with Windows and it's actually not the prefetch's sin, but there's something that starts periodically and slows things in a very noticeable manner. In the end I just turned prefetching off. At least now I can control what happens and when. But the general direction of the prefetching elaboration in different OSes is good.Brendan wrote:Note that Windows has supported something roughly like this since Vista (they call it "SuperFetch")
The advantage could be anything from no speed-up to massive speed-ups; and the disadvantage (assuming it's implemented properly - e.g. low priority IO with the ability to cancel) is a little more power consumption (where power consumption is something the OS could/should take into account when deciding what/if to pre-fetch).embryo2 wrote:In fact I do not use a great mix of applications for development. It's just Eclipse and the most of the time there's nothing else. But yes, sometime an external watching entity can speed things. The only problem here is the actual value we can get from it. The speed increase of 100ms when start time takes 1 second is not visible. But if it's something like "from 15 seconds to 3 seconds", then yes, it's interesting. And again, if it buys the start time for the interruption of my work with other software, then I prefer not to have such trade.Brendan wrote:You start a text editor, and it notices you're editing a source code of some kind and (because it's been profiling user behaviour in the background when it's not even running) the text editor decides to start pre-fetching the compiler?
If you've disabled pre-fetch; it should be fairly easy to estimate the performance difference it could make. For example, boot the computer and measure how long it takes to start eclipse (when none of eclipse's files are in the OS's file cache), and then close eclipse and start it a second time (when all of eclipse's files are in the OS's file cache). I'm not sure about eclipse (it's written in Java so there'd be a huge amount of bloat during application start-up that pre-fetching can't avoid); but I do know that things I use are noticeably slower after rebooting (e.g. starting a web brower, my own project's build utility, etc), mostly because Linux is extremely bad at pre-fetching.
The initial statement was "The swap is a very ugly thing of the past. It ruins the uninterrupted flow of user's work. It just should be removed.".embryo2 wrote:Well, the initial question was about the swap use cases.Brendan wrote:It's about interactions between many pieces (where swap is just one of the pieces involved). If you only look at swap in isolation then you end up with naive misconceptions.
Note that it's actually common for users to think "Hey, I've got plenty of RAM so I don't need swap space" because they don't understand the role swap plays in a well designed system (and this is made worse by some old and/or poorly designed OSs that don't use swap space and/or pre-fetching very well). We are supposed to be OS developers and not just normal users, so we should know better.
The OS doesn't need to inspect the application's code. There's always something that can be hooked to gather statistics (the VFS's "open file" code, the OS's DNS service, etc).embryo2 wrote:But the cooperation of the applications and the OS is something I really support. And the management of an application life cycle can be performed optimally if the OS has more information about the application, would it be some annotations or AOT/JIT's output or whatever related to the ability of the OS to introspect the code and it's usage.
Cheers,
Brendan