LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This 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


Reply
  Search this Thread
Old 10-18-2015, 11:44 AM   #1
Duglas
Member
 
Registered: Mar 2009
Distribution: Debian
Posts: 69

Rep: Reputation: 2
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?
 
Old 10-18-2015, 06:56 PM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
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.
 
Old 10-18-2015, 07:09 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,140

Rep: Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123
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.
 
Old 10-18-2015, 09:28 PM   #4
blue_z
Member
 
Registered: Jul 2015
Location: USA
Distribution: Ubuntu, Lubuntu, Mint, custom embedded
Posts: 104

Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
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.

Regards

Last edited by blue_z; 10-18-2015 at 09:36 PM.
 
Old 10-18-2015, 09:33 PM   #5
blue_z
Member
 
Registered: Jul 2015
Location: USA
Distribution: Ubuntu, Lubuntu, Mint, custom embedded
Posts: 104

Rep: Reputation: Disabled
Quote:
Originally Posted by syg00 View Post
The OP asked whether the swap should be move off the SD card. The answer to that question is "probably yes".
Definitely "yes" if you don't want to wear out the SDcard.
The wear-leveling capabilities of SDcards are suspect, and reportedly not as good as SSD.

Regards
 
Old 10-20-2015, 12:36 PM   #6
LinuxUser42
Member
 
Registered: Nov 2010
Distribution: Lubuntu, Raspbian, Openelec, messing with others.
Posts: 143

Rep: Reputation: 19
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).
 
Old 10-21-2015, 08:12 AM   #7
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
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:
  1. 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
  2. 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.
 
Old 10-21-2015, 03:15 PM   #8
blue_z
Member
 
Registered: Jul 2015
Location: USA
Distribution: Ubuntu, Lubuntu, Mint, custom embedded
Posts: 104

Rep: Reputation: Disabled
Quote:
Originally Posted by LinuxUser42 View Post
What points to the swap file?
The file /etc/fstab.

Quote:
Originally Posted by LinuxUser42 View Post
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.

Regards
 
Old 10-21-2015, 03:37 PM   #9
blue_z
Member
 
Registered: Jul 2015
Location: USA
Distribution: Ubuntu, Lubuntu, Mint, custom embedded
Posts: 104

Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
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.

Regards
 
Old 10-23-2015, 03:58 AM   #10
blue_z
Member
 
Registered: Jul 2015
Location: USA
Distribution: Ubuntu, Lubuntu, Mint, custom embedded
Posts: 104

Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
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 View Post
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.

Regards

Last edited by blue_z; 10-23-2015 at 04:05 AM.
 
Old 10-24-2015, 08:23 AM   #11
Duglas
Member
 
Registered: Mar 2009
Distribution: Debian
Posts: 69

Original Poster
Rep: Reputation: 2
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".
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Swap partition against swap file: how much performance do I loose? stf92 Slackware - Installation 12 03-15-2014 05:48 PM
Would a Linux swap partition work as a FreeBSD swap partition? Froggy192 *BSD 11 07-27-2013 02:06 PM
Boot hangs at "activating swapfile swap" in Ubuntu 9.04 gray53 Linux - Software 6 08-24-2009 05:41 AM
Can swap file or a swap partition be mounted and read? Mr-Bisquit Linux - General 3 06-08-2009 02:16 PM
Hard Drive Partition Management - Mandriva Double Partition with Swap File partition moshebagelfresser Linux - Hardware 2 05-23-2008 10:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 12:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration