View Single Post
pichlo's Avatar
Posts: 6,450 | Thanked: 20,983 times | Joined on Sep 2012 @ UK
#13
(1) We all agree that when you reboot the N9, there is 255 MB of swap available out of a total swap size of 255 MB. In short, 100% of the swap memory is available immediately after reboot.
Actually, there is 100% out of the total virtual memory (RAM + swap) available. I am not sure on exact figures; is it 1 GB RAM + 256 MB swap or 1 GB altogether?

(2) I think we all agree that after using the device, the swap memory begins to be consumed, so after a bunch of multitasking, use of heavy apps, etc., the swap memory will drop to something like 200MB out of 255MB total. After more use, it may drop to 130 MB out of 255MB total. And ultimately can reach 0MB out of 255MB total.
Again, we are talking about the total virtual memory (RAM + swap) that gets consumed. Swap is just an extension of the RAM, nothing more, nothing less. Memory gets allocated by the OS and applications. When there is not enough memory in the RAM, some pages are swapped out (moved to swap). When the application frees the memory (which happens naturally during its operation and always upon terminating it), it does not matter where the memory block actually is. Swap or RAM, it is made available again.

(3) On my device, shutting down the heavy apps, multitasking windows, etc. does NOT restore the swap capacity, so the available swap memory tends only to go down.
That is very strange. Applications and most OS components have no way of telling which memory to use. They just go, "give me some memory" and "here is your memory back, I no longer need it". Only the kernel decides whether a certain memory page should be in RAM or in swap, using a sophisticated algorithm, based mostly the frequency of the access to a particular page. More used pages stay in the RAM, the less used ones go to the slower part of the virtual memory, a.k.a. swap.

If what you say is this indeed the case then I would expect the available RAM to go drastically down as well. Yes, it is theoretically possible that the swap apace is completely full while the RAM is not. I would expect that to happen if a memory hungry background task has not been used for a long time. Let's call it task X. Other tasks have started, allocated some memory, the kernel had to resort to pushing some memory blocks already in RAM to swap. If task X has not used its memory for a while (and forgot to free it), then after a while it might find all its memory swapped out. When other tasks terminate, they release their memory but task X's memory is not moved from swap back to RAM as it is not needed (yet). This is however a very hypothetical situation that is very easily verified.

To give us a better picture, could you please post the result of:
Code:
free
followed by
Code:
top
Ideally when you experience your swap problems as described.
(After starting top, press 'm' to sort the processes by memory usage.)
 

The Following 2 Users Say Thank You to pichlo For This Useful Post: