Linux - Embedded & Single-board computerThis forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
Not quite.
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.
Distribution: Lubuntu, Raspbian, Openelec, messing with others.
Posts: 143
Rep:
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:
Swap will look to read/write a lot because it assumes all data is volatile (not intended to be retained across a boot or power cycle), and it will do this a lot to a finite life storage disk
You'll want to designate a certain partition, and thus location on disk for this, and you'll not want to make it very large, thus you'll be reading and writing a lot to a very particular range in disk, not allowing write leveling algorithms to work effectively on a flash media. So just a poor idea.
If you really feel you need swap space, I'd try using a RAM disk for that.
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).
That'a a good idea when swap is on a removable drive.
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.
If you really feel you need swap space, I'd try using a RAM disk for that.
Bad advice if all you're doing is re-purposing a portion of main memory to a RAM disk.
Besides RAM disks have been deprecated in favor of ramfs and tmpfs.
My understanding is that ARM has no memory controller and hence all ARM based distributions have to employ a non-memory controller distribution.
Your understanding is incorrect.
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:
Originally Posted by rtmistler
What this has to do with swap is that I believe the memory controller is what uses swap.
Swapping is managed by the OS, not by any memory controller or MMU. Swapping is optional, and can be disabled in the kernel (e.g. in embedded systems).
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.
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".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.