
On 12/01/2020 04:15, Andrei Borzenkov wrote:
12.01.2020 11:57, jdd@dodin.org пишет:
If you are short of memory but there is swap available, swap will be used instead.
That is wrong.
It's not that he's "wrong" per se but that he'd worded it badly. You go on to more accurately describe what is happening.
sure, but do the kernel care that it's swap, not physical memory?
in an other way, is 5 Gb of physical memory and 5 Gb of swap identical of 10Gb of physical memory?
No. If there is no free memory to satisfy allocation request, kernel will look for cold data in memory and will try to reclaim it.
All memory is either statically allocated for the kernel and/or it's threads or is available to the VM system. The latter is ALL on one of a number of linked lists. Not all memory has a corresponding swap location, so there is no need for the size(swap) = size(RAM) Why is this? You never need to swap out code! Late model VM has memory mapped files. This is wonderful for the VM's "load on demand" capability if the CPU can do instruction restart. Most can these days but it was a problem with some of the original set of 16-bit CPUs and unavailable with the 8-it. SUN pulled a trick with a pair of 68000 chips, one a step behind the other, the fudge the restart capability on a chip that didn't have it. Fantastic engineering kludge! You never need to swap out code, you just have to mark that page as one that can be put on the 'dirty' queue and as it fails to be accessed it 'ages' along to the end, where it can, if necessary, be reclaimed. How fast that happens, how aggressively the pages are plucked from that queue for re-use are tunable parameters. Note I said "as it fails to be accessed". If it is accessed, that pages code gets accessed -- i.e. executed -- then it is brought back to the tail of the queue. Suppose that code page ages out and gets re-used 'cos the application isn't needing it ... for a while, but then the application gets round and needs that code fragment again. The page isn't there, there is a page-fault triggered, execution is suspended and the page needs to be brought back in. It is a page of a memory mapped file, so it is NOT in swap. It never was; it never will be.
Swap is used to preserve content of anonymous memory that is reclaimed.
I don't know that I'd call it 'anonymous'. This is the volatile memory that belongs to processes. "Volatile memory"? Consider: at startup a processes reads one or more config files. It opens them in read-only mode. The VM opens them as memory mapped files; the process digested them then closes them. They may be in the data space, but they are not volatile, they are read-only. When closed, their mapping tables entries and their mapped virtual memory are freed. But while they are, strictly speaking, in the data space of the application, they are like code pages. if the demand of multi-tasking necessitates suspending that process it may be that those pages get released so something else can run. (I agree, context and circumstances make it unlikely that a startup config read gets this treatment. But the logic does apply.) Like the code pages mentioned above the contents of the read-only file can be re-mapped 'on demand'. They don't need to go to swap. I think the term 'cold' is an interesting one. "Hot' pages are the ones that see the traffic, the access.
To actually *use* swapped out data kernel must read it back into memory, which requires free memory so we are back to square one. If no memory is available or can be reclaimed at this moment, data cannot be read back and so cannot be used.
And of course not all memory content can actually be swapped out in the first place.
Damn right! Obviously you don't want to swap out essential kernel code, least of all the code that implements the VM[1].
So no, swap is not memory extension.
I'm not going to give this an expletive agreement. I insist that many people mis-use swap. Linux lets you swap out pages on a 'precautionary' basis even when there is a lot of memory still available. This is the 'swapiness' setting. Turning it down but not off means that I'm not hitting my rotating rust gratuitously. Swapping ALWAYS means delay and usually means a configuration problems if there is still free memory available. A lot of your ideas about VM are contaminated by the days when you still had to pre-allocate resources. I use LVM and dynamic provisioning 'cos I don't want to tie things down. We often see people asking how they can grow a partition. OUCH! I avoid the whole issue with LVM. Strictly speaking you don't even need to configure you disk for a swap partition. As in "don't do that". The VM system will accept a file on a file system as swap. This makes things even more 'dynamic' and 'deferred design'. This gives you the opportunity to play with the allocation of swap even more than using LVM does! You can experiment with different types of file system and file allocation policies.
Oh, and not every reclaimed memory needs swap (which is why I said "anonymous" above). So even without swap it is possible to have more virtual memory in use than is physically available.
that is what the 'working set' is all about. [1] File under "You really don't want to know about this". The ICL 29000 series machine allowed for language-specific microcode. (You don't want to know about the compilers that did that, either). As such, the microcode also had to be pageable. That machine was nightmare. -- A: Yes. > Q: Are you sure? >> A: Because it reverses the logical flow of conversation. >>> Q: Why is top posting frowned upon? -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org