View Single Post
Posts: 1,808 | Thanked: 4,272 times | Joined on Feb 2011 @ Germany
#17
(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.
This is not necessarily true. If you've understood what @pichlo is trying to say from the very beginning of this thread, you'd know that swap is the same as ram, only that it uses disk

The kernel may well decide to use swap during boot, but this is not likely.

(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.
*MEMORY* is used. Whether it's DRAM or swap is only the kernel's business. Obviously, the more memory is used the less memory is available. If your free swap reaches zero there is a very high probability that your physical ram is also zero, meaning you can't do anything.

(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.
When a program exits its memory (both ram and swap) is freed. Now most programs are not self contained but use libraries and other "middleware" which is basically constantly allocating memory. Most programs written after 2000 basically don't care about memory and except that someone else will take care of deallocating it. The problem is that that someone else doesn't exist.

Imagine (just hypothetically) a music player tells pulseaudio to allocate a chunk of 4MB to buffer music (this is clearly false, but only a made-up example) and then exists without telling pulseaudio that it doesn't need the buffer anymore. The memory used by the player is freed, but those 4MB are still there, allocated (reserved) and basically orphaned forever.

(4) I have noticed that slowdown both within apps like Fenix and while switching between the three homescreens, and in general other usage, is noticeable and irritating. The slowdown I experience is directly proportional to the degree that swap memory is utilized. Performance slows early on, though it is hardly noticeable, but then gets progressively worse until it absolutely cripples the device.
This is the usual effect or having almost no memory availblle (if you have a VM at hand try running Windows NT 4.0 with 12MB of RAM and 16MB of swap. You'll see how I lived for about 3 years).

(5) MY QUESTION. Yes, we all know that rebooting the device will get us back to a snappy 255MB out of 255MB of swap available. BUT, how can this exact result be obtained without rebooting the device??? Something like a swap memory refresh script is what I'm looking for. Can you dig it?
There's no way to achieve what you want. The only way would be if all programs that are running would be closed so as to free the memory they were using and then start again, which is not going to happen (at least in general).

You could try reducing the swappiness, but this will just make your N9 use more RAM. You could also try reducing the block/inode cache. This will get you more free memory at the expense of everything being slower.

Basically, the only way to not leak memory is by using programs that don't leak memory. Given the unfortunately "common wisdom" that you are supposed to reboot every couple of hours/days, most programmers don't feel the need to do things properly, thus reinforcing that common wisdom.
 

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