Error in Wikipedia article about memory leaks

At the end of this article on Wikipedia, the section β€œA Simple Example in C” states that β€œthe operating system delays the actual allocation of memory until it is written to it.” In my experience, this is impossible or better, "impossible." OS / Processor does not track every memory entry. Is the wikipedia article incorrect, as I suspect? If you don’t enlighten me.

change

I assume that when you accept page errors than this makes sense in some respects. However, page errors and virtual memory are poorly suited for discussing memory leaks. I mean, if a process distributes 2 pages, writes to one (page one), and then both pages flow, which are still a leak, regardless of the weather, the second page loses physical memory or not. Perhaps the partition should distinguish between physical memory and virtual memory ?: D

+6
source share
4 answers

Depends on the operating system. For example, on Linux, this really works. See "optimistic memory allocation."

In addition to this, there is a difference between virtual memory and physical memory. On most operating systems, you use virtual memory, so even if you allocate a lot of megabytes of memory, the actual physical memory will only be used after you write it (at this point, what was in this place before can be unloaded back to disk).

There is a "virtual address space", which is basically a "logical" memory, which is then mapped to physical RAM (or to your hard disk if the memory is unloaded).

+10
source

You are wrong.

All OS should allocate virtual memory. You call, say, mmap or break . It creates a virtual address space and sets page table entries to cause page errors. You go to the memory link, a page error occurs, and the system goes to the actual memory allocation. Not earlier.

+4
source

I would say that the comment at least is not related to memory leaks, even if it is not erroneous. There are at least 3 dimensions of memory usage:

  • consumed virtual address space
  • make an order
  • physical memory occupied

Even if the allocated memory was not physically created due to a page error, it still takes up valuable virtual address space and captures the charge.

+2
source

Suppose you have allocated 1 GB of virtual memory and are actually only referring and using 0.5 GB, you are still leaked to 0.5 GB of your allocated address space. Even if it is not busy with real real RAM, it still requires resources from the memory allocator to manage your allocations (especially when you have allocated many small objects). So this is still a memory leak, because (at least on 32-bit) you can only allocate 1 GB max. instead of 1.5 GB and you cannot let it go from your application.

0
source

Source: https://habr.com/ru/post/886067/


All Articles