#7742 closed bug (fixed)
SWAP file constantly recreated, takes up alot of space
Reported by: | Cypress | Owned by: | axeld |
---|---|---|---|
Priority: | normal | Milestone: | R1/alpha4 |
Component: | Preferences/VirtualMemory | Version: | R1/Development |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
The SWAP file is constantly being recreated at /boot/common/var/swap, regardless if VirtualMemory has the "Enable virtual memory" box checked or not. I have 1,5GB of RAM on my machine (Dell Latitude D820) and a partition of 4.3GB dedicated to Haiku. The SWAP file at /boot/common/var/swap takes up pprox. 3GB of that space. I keep enabling and disabling VirtualMemory, even deleting the file, but the SWAP file keeps reappearing there after a reboot.
If I enable a virtual memory of 257MB, the SWAP file decreases in size:
~> ls -l /boot/common/var/swap
-rw------- 1 user root 269484032 Jun 24 16:05 /boot/common/var/swap
Attachments (3)
Change History (22)
comment:1 by , 13 years ago
comment:2 by , 12 years ago
Version: | R1/alpha3 → R1/Development |
---|
same issue seen here:
hrevr1alpha4-44576
- Installed Haiku to a 8GB partition
- Reboot to find 400MB free
- Disk usage shows /boot/common/var/swap is 6.9 GB
- Machine has a little over 3GB ram... so this makes sense as ram * 2
- Swap preference panel was already disabled.
- Erased swap file
- Emptied trash
- Space still used
- Rebooted
- Space still used
- No swap file present now
- Ran checkfs on Haiku partition
- No errors reported, but space drops to a correct level.
comment:3 by , 12 years ago
Confirmed...
http://cgit.haiku-os.org/haiku/tree/src/system/kernel/vm/VMAnonymousCache.cpp#n1343
Is there a swap setting?
Init it.
Does the swap setting not exist?
size = (off_t)vm_page_num_pages() * B_PAGE_SIZE * 2;
There are several issues with this:
- The swap space can be very large without taking into account the filesystem size
- The automatically chosen size is never written anywhere so the swap preference panel isn't aware of it.
I'm seeing if there is a logical way to fix this without breaking anything :)
comment:4 by , 12 years ago
I have several of these VM bugs in my ticket list, I should have worked on them before we started working on the alpha4 release. Because it seems like they might need to be fixed. With the amount of RAM some people can have (such as myself) it is insane to have 16 GB of swap when you have 8 GB of RAM. For one thing it will probably never be used on Haiku, and in general that is way too much swap.
I think the sizing heuristic needs to be just a tad bit smarter ;)
It should have a reasonable maximum, like 2 GB, and it should take into account both the total size of the disk and the available space on that disk. When it has calculated a reasonable size, it should check for the settings file and create it if it doesn't exist and put in the chosen size.
And the initialization code should check the VM settings and delete the swap file if the settings exist and a current swap file exists, but the virtual memory is turned off. That should be inside the if statement on line 1345.
I think if all the above is done most of these bugs will be taken care of.
comment:5 by , 12 years ago
It should have a reasonable maximum, like 2 GB, and it should take into account both the total size of the disk and the available space on that disk. When it has calculated a reasonable size, it should check for the settings file and create it if it doesn't exist and put in the chosen size.
Yeah, this is definitely a good way to go... however how fast can we do this + testing? I'd like to see this fixed prior to R1A4 as it could impact a large number of users.
Attached is my test patch.. pretty much does what I originally listed and is the "most simple / reliable" solution. Although if you think you could have some smarter checking done before me... i'd say go for it :)
by , 12 years ago
comment:6 by , 12 years ago
patch: | 0 → 1 |
---|
comment:7 by , 12 years ago
I'm not fond of the suggested solution. First of all, the swap file should be enabled by default as Ryan pointed out when there is no settings file.
Second of all, it makes no sense to have a settings file by default, as the size of RAM, and available HD space are not constants. Also, the kernel should not create a settings file for the same reason: move the installation to a new system, and the same heuristic should determine the best swap file size, instead of using whatever else was good at some other point in time (unless the user changes the setting, that is).
The best solution is to have a syscall that returns the current swap file configuration (if there isn't already), and have VirtualMemory always show this. When you change the settings, it will create a settings file that is then honoured by the kernel on the next boot. VirtualMemory should probably have a setting "automatic" which is the default in which case it would delete the settings file.
comment:8 by , 12 years ago
This way, it could even determine differences between the settings file, and the current settings (if any), and directly show the "The settings will take effect on next boot".
comment:9 by , 12 years ago
I'm not fond of the suggested solution.
One thing to consider here is non-iso based (usb stick, hdd) installations... the Haiku boot partition generally has very little space available, so a small (ex. 64-128MB) swap file may result in a near 0 free space situation.
First of all, the swap file should be enabled by default as Ryan pointed out when there is no settings file.
How likely is it that a user will need the swap file on first boot? I can only see edge cases where users would need a swap file on first boot if they had less than 512MB ram.
With SSD's and other flash memory becoming more common, swap space is generally frowned upon. (not that it's a bad thing at all, an in-use system should have swap "just-in case")
Second of all, it makes no sense to have a settings file by default.
This was to give users an example swap file size (ex, the preflet shows the swap set to 128MB, and the swap file disabled)
To be honest, it really doesn't matter to me how it's implemented... I was just trying to get a solution to a problem that in was R1A3 complete before R1A4. We can take into account a ton of different metrics here, however the more metrics we check the more likely bugs will be :)
This doesn't have to be the final solution, just a solution in the short term.
Either way, I won't commit anything like this without some level of agreeance :P
comment:10 by , 12 years ago
Ok... here are some ideas for a more long-term fix:
- If swap is undefined (we can call this "automatic" the future)
- Swap size defaults to (ram * 2)
- If (ram * 2) is > 25% of the freespace, use the 25% of the free space as swap
- If 100MB free, largest swap is 25MB
- If 1GB free, largest swap is 250MB
- If 10GB free, largest swap is 2.5GB (this is however limited by the (ram * 2))
- If swap is defined:
- If swap larger then free space
- Log this event
- Set swap to 98% of free space for this boot only.
- We could have a low disk space notification that would give an overall alert that freespace is low.
- If swap larger then free space
comment:11 by , 12 years ago
It should be also said that the "ReadOnly disk? No swap at all" should still apply :)
comment:12 by , 12 years ago
actually... xyzzy pointed me to a pre-existing solution in #3723 I'm working on a patch using a cleaned up version of hamish's work
comment:13 by , 12 years ago
cleaned up kernel work is complete. See attached.
Kernel VM: Improve swap file selection * Heavily based on Hamish Morrison's GCI work with some modified logic and cleanup. #3723 * Adds automatic swap as well as user specified swap * Limits: Automatic: (ram * 2) up to 25% of the disk User: user specified up to 90% of the disk * Supports changing the swap disk location
by , 12 years ago
Attachment: | swap-kernel-v1.diff added |
---|
comment:14 by , 12 years ago
Milestone: | R1 → R1/alpha4 |
---|---|
Resolution: | → fixed |
Status: | new → closed |
comment:15 by , 12 years ago
A few comments:
+ if (swapAutomatic) { + swapEnabled = true; + swapSize = (off_t)vm_page_num_pages() * B_PAGE_SIZE * 2; + }
I would make the default size dependent on the size of memory: if < 1GB *2 is fine, above that, I would think that the same amount as the amount of memory is sufficient.
+ off_t maxSwap = freeSpace; + if (swapAutomatic) { + // Adjust automatic swap to a maximum of 25% of the free space + maxSwap = (off_t)(0.25 * freeSpace); } else { - size = (off_t)vm_page_num_pages() * B_PAGE_SIZE * 2; + // If user specified, leave 10% of the disk free + maxSwap = freeSpace - (off_t)(0.10 * freeSpace); + dprintf("%s: Warning: User specified swap file consumes over 90%% of " + "the available free space, limiting to 90%%\n", __func__); }
If you don't absolutely need floating point computation, don't use it in the kernel. In this case /4 respectively /10 should do the trick here.
comment:16 by , 12 years ago
Besides, why the differentiation between automatic mode and the other one? If the user sets a certain size, it should be respected, no matter if it needs more than 10%. BTW the warning is printed unconditionally which makes no sense.
comment:17 by , 12 years ago
Axel:
I would make the default size dependent on the size of memory: if < 1GB *2 is fine, above that, I would think that the same amount as the amount of memory is sufficient.
Mostly I was trying to avoid having any "set" numbers. But yeah.. 16GB * 2 seems a little silly. Making the change now
If you don't absolutely need floating point computation, don't use it in the kernel. In this case /4 respectively /10 should do the trick here.
Good point. Re-factoring now
comment:18 by , 12 years ago
Besides, why the differentiation between automatic mode and the other one? If the user sets a certain size, it should be respected, no matter if it needs more than 10%.
The difference is mostly to try and quell any free space shortage situations. For having a swap file set that is larger then the free space available. Instead of just failing, pull the swap space set back leaving a little free space on the disk.
Although you're right one I think through that... getting into that situation would be rough.
BTW the warning is printed unconditionally which makes no sense.
Sigh... good catch. Will remove that bit.
by , 12 years ago
Attachment: | swap-kernel-v2.diff added |
---|
Also see #7550. It appears that the disable option isn't honored at all. If it is the same issue this should be closed as a duplicate.