Raspberry Pi swapfile or swap partition
I have connected a large harddrive to my Raspberry Pi as a file server.
Should I now allocate some space as a swapfile or swap partition, to use instead of the swapfile on the SD card? If so, how to go about this? |
You only need swap space if your virtual memory is not sufficient, that is, programs can't run because of the lack of virtual memory.
If this is what happens on your system, create some swap space on a disk partition or a normal file using the mkswap command. Then, tell the system to use that swap space by adding it to the /etc/fstab file. Most likely, you don't need swap space though. Just adding a disk drive doesn't change your memory needs. |
The OP asked whether the swap should be move off the SD card. The answer to that question is "probably yes".
Swap extent must be contiguous - having a partition makes this trivial. For a swap file use dd to create a file of the requisite size then issue the mkswap. Then use swapon to ensure it is ok, and swapoff the swap on the SD card. When all that works, add it to fstab and remove the entry for the SD swap. Check your bootloader parms - especially the "resume" parameter (if any). Also the init{ramfs,rd} may reference the swap if you use one. If all that seems too much work, and you aren't using the swap, you could just leave everything as-is. Your choice. |
Quote:
To be a correct comment, you need to replace both instances of "virtual" with "physical". A Linux process can acquire (i.e. malloc()) all the virtual memory it wants up to the system limit (e.g. typically 3GB in a 32-bit system), but it's when the process tries to use it that physical memory has to be mapped and swapping might occur. Regards |
Quote:
The wear-leveling capabilities of SDcards are suspect, and reportedly not as good as SSD. Regards |
What points to the swap file?
I am thinking, it might be better to add another swap file to the hard drive and point to it, but save the prior, in case you don't have the hard drive on or hooked up (either redirect or if/then type statement). |
My understanding is that ARM has no memory controller and hence all ARM based distributions have to employ a non-memory controller distribution. What this has to do with swap is that I believe the memory controller is what uses swap.
My take on this is that you absolutely do not want to put swap on a flash disk, for a couple of reasons:
|
Quote:
Quote:
But not easily implemented (i.e. fstab is a text file, and AFAIK there are no conditional operators for the mount program to recognize when it processes this file). In the init script, after populating /dev and before mount processes fstab), a check for the drive and installing an appropriate version of fstab file would have to be added. But if swapoff and swapon commands are installed, then the move can be performed by a shell script at root's descretion. Regards |
Quote:
Besides RAM disks have been deprecated in favor of ramfs and tmpfs. Regards |
Quote:
A memory controller is the hardware whose primary function is to arbitrate access to memory and maintain it (e.g. refresh DRAM). Since the typical Linux system uses (some type of) dynamic RAM, a memory controller is an essential HW component. Perhaps you are thinking of a memory management unit, MMU, which provides virtual memory and paging capabilities. Since Linux requires virtual memory, ARM systems running Linux will have a MMU. SoCs incorporating ARM9, ARM11 and ARM Cortex-A typically have MMUs. Note that Linux has been available on ARM for about 20 years. There is a non-MMU version of Linux called the uClinux project. The mainline Linux kernel can be built as a MMU-less version, but since the typical ARM MPU SoC (I'm excluding all ARM MCUs) does have a MMU, ARM Linux does use virtual memory (just like x86). Quote:
Your statements are also contradictory. If ARM doesn't have a "memory controller", and "the memory controller is what uses swap", it would follow the ARM can't use swap. Yet you proceed to discuss swapping on ARM. Regards |
Thanks Guys,
This thread is Solved, and will be marked as such, as soon as I figure out how to do it. sygOO said "probably yes" blue_z said "definitly yes if you don't want to wear out the SDcard", and that has to be the correct answer. Searching thru the system I found a file "/etc/dphys-swapfile", and a script "/sbin/dphys-swapfile". I repartitioned the harddisk to add a swap partition. Enabled it in /etc/fstab. That was all, the script /etc/dphys-swapfile is smart enough to not start a swapfile when it finds a swap partition. I had tried to add a swapfile on the disk, but came up with "permission errors". |
All times are GMT -5. The time now is 08:50 PM. |