carlosfm
Posts: 132
Joined: Fri Oct 21, 2011 3:23 pm
Location: Lisbon, Portugal

Re: No swap space?

Fri Aug 17, 2012 7:47 pm

joe2act wrote:Thanks to all.

In summary, Raspbian still has a swap file in file system, but Raspbian has no swap partition in SD card. The reason is SD card has limited read/write cycles. No swap partition in SD card can increase SD card life span.
The reasons for not including a swap partition don't seem logical, as there is a swap file on the SD card, which has the same role.
I prefer to use a swap partition instead of a swap file - with the partition it does seem faster in practice (and it theory it should, IMHO).
I also have the logs in RAM (tmpfs), which also helps to reduce the writes to the SD card.

To put the logs in RAM, add this to /etc/fstab:

# logs in RAM
tmpfs /var/log tmpfs defaults,noatime,mode=1777 0 0
Do you Pi?

User avatar
jojopi
Posts: 3193
Joined: Tue Oct 11, 2011 8:38 pm

Re: No swap space?

Fri Aug 17, 2012 8:19 pm

carlosfm wrote:The reasons for not including a swap partition don't seem logical, as there is a swap file on the SD card, which has the same role.
I prefer to use a swap partition instead of a swap file - with the partition it does seem faster in practice (and it theory it should, IMHO).
I also have the logs in RAM (tmpfs), which also helps to reduce the writes to the SD card.
I think the reason for using a swap file is to make resizing easier.

Ignoring data locality, which could go either way, yes in theory a partition might have less overhead. But we are talking about clock cycles on an operation taking milliseconds, which is why you will not be able to measure it. Incidentally, it is the same code in both cases, and the code actually cares more about whether the swap is solid-state or spinning, than whether it is a file or partition.

tmpfs can make a big difference.

joe2act
Posts: 40
Joined: Tue Jul 24, 2012 4:21 am

Re: No swap space?

Fri Aug 17, 2012 9:37 pm

The reasons for not including a swap partition don't seem logical, as there is a swap file on the SD card, which has the same role.
I prefer to use a swap partition instead of a swap file - with the partition it does seem faster in practice (and it theory it should, IMHO).
I also have the logs in RAM (tmpfs), which also helps to reduce the writes to the SD card.

To put the logs in RAM, add this to /etc/fstab:

# logs in RAM
tmpfs /var/log tmpfs defaults,noatime,mode=1777 0 0
I agree. Swap file still exist in file system, and it stores at SD card. Swap file did not exist on other external memory such as HDD. In result, swap file do not reduce read/write cycle on SD card.

Compare to using swap partition, what is the real advantage Wheezy obtains by using swap file? Do Wheezy developers have a benchmark result of testing 'swap file vs swap partition' ?

The log file in RAM using tmpfs is a good SD card saving idea in normal condition.

joe2act
Posts: 40
Joined: Tue Jul 24, 2012 4:21 am

Re: No swap space?

Fri Aug 17, 2012 10:33 pm

Can users resize file swap file size? for example, free -h shows swap file szie is 99MB. Can user resize swap file size to smaller 50MB?

Code: Select all

[email protected] ~ $ free -h
             total       used       free     shared    buffers     cached
Mem:          183M        71M       112M         0B        10M        44M
-/+ buffers/cache:        16M       167M
Swap:          99M         0B        99M

joe2act
Posts: 40
Joined: Tue Jul 24, 2012 4:21 am

Re: No swap space?

Fri Aug 17, 2012 10:41 pm

jojopi wrote:
carlosfm wrote:The reasons for not including a swap partition don't seem logical, as there is a swap file on the SD card, which has the same role.
I prefer to use a swap partition instead of a swap file - with the partition it does seem faster in practice (and it theory it should, IMHO).
I also have the logs in RAM (tmpfs), which also helps to reduce the writes to the SD card.
I think the reason for using a swap file is to make resizing easier.

Ignoring data locality, which could go either way, yes in theory a partition might have less overhead. ...
Do you mean raspi-config.sh to resize or repartition SD card? raspi-config.sh do not need to deal with the extra swap partition?

That is a good reason if swap file makes raspi-config resize/repartition task easier.

User avatar
jojopi
Posts: 3193
Joined: Tue Oct 11, 2011 8:38 pm

Re: No swap space?

Fri Aug 17, 2012 10:45 pm

To resize:

Code: Select all

sudo nano /etc/dphys-swapfile
sudo dphys-swapfile setup
sudo dphys-swapfile swapon

joe2act
Posts: 40
Joined: Tue Jul 24, 2012 4:21 am

Re: No swap space?

Sat Aug 18, 2012 12:47 am

jojopi wrote:To resize:

Code: Select all

sudo nano /etc/dphys-swapfile
sudo dphys-swapfile setup
sudo dphys-swapfile swapon
Thank you for answering my resize question.

Can you clarify that Raspbian Wheezy's swap file is not stored in memory and it is stored at SD card? If answer is yes, swap file can not increase SD card's life span?

keith.b
Posts: 16
Joined: Tue Jul 03, 2012 6:09 pm

Re: No swap space?

Sun Aug 19, 2012 3:04 pm

bredman wrote on 14th Aug:
To check the current swap status
swapon -s

To turn off all swap
sudo swapoff -a

To turn on swap as defined in /etc/fstab
sudo swapon -a

To turn on swap, using a specified file
sudo swapon /var/swap
This works immediately, as also shown using the 'top' command.

HOWEVER, on rebooting with AutoLogin and AutoStarting with startx at the end of the /etc/profile file,
the swap file is re-instated!

As I have already burned out my first SD card with too many writes, I need to disable swap permanently in the Raspian OS.

Can anyone suggest how to achieve this?

User avatar
jojopi
Posts: 3193
Joined: Tue Oct 11, 2011 8:38 pm

Re: No swap space?

Sun Aug 19, 2012 3:38 pm

keith.b wrote:As I have already burned out my first SD card with too many writes, I need to disable swap permanently in the Raspian OS.
Can anyone suggest how to achieve this?
There are two methods to disable swap permanently in this thread alone: 1 2.

How many writes did you make to your first card, and what proportion of them were swap? It is just as effective not to try to use more memory than you have, as it is to disable swap. In fact, it is hard to make the foundation's raspbian image swap significantly in the default configuration, without it first going so slow that you should notice a problem.

keith.b
Posts: 16
Joined: Tue Jul 03, 2012 6:09 pm

Re: No swap space?

Mon Aug 20, 2012 1:46 pm

jojopi wrote:How many writes did you make to your first card, and what proportion of them were swap? It is just as effective not to try to use more memory than you have, as it is to disable swap.
I'd tried all the options I could find, but swap always came back on after a reboot.

I don't know how many times the swap file was used: the first SD card gave up the ghost on my project, which involved switching between two .html files at 30 second intervals whilst alternately fetching a twitter feed for display.

My card supplier, having never had a failed card before, suggested that the write limit of the SD card had been reached because this process would have been writing to the swap file on each cycle. The project had been running 24/7 for approx. 7 days.

I've now found that by editing /etc/init.d/dphys-swapfile, changing both options under case "$1" to swapoff, keeps the swap file off even after a reboot.

I'll be monitoring the project to see if that cures the problem!

User avatar
jojopi
Posts: 3193
Joined: Tue Oct 11, 2011 8:38 pm

Re: No swap space?

Mon Aug 20, 2012 2:19 pm

I am not sure what you mean by "switching between html files", but it sounds more likely to write to the filesystem than the swap. If you are going to run anything in a continuous loop then it would be wise to ensure that it writes as little as possible.

If your project was writing to swap on every cycle (which you do not seem to have any evidence of) then it must have been using more memory than is available on the Pi. If that is the case then now that you have disabled swap it will instead crash with a "Cannot allocate memory" error.

Changing the code for dphys-swapfile is not as good a solution as disabling or purging it as previously suggested. There is a possibility that a future package update will undo your modification.

User avatar
RaTTuS
Posts: 10549
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: No swap space?

Mon Aug 20, 2012 2:30 pm

if you are writing small files constantly then using a tmpfs [ram disk] will help,
even writing files to /tmp [as /tmp is mounted tmpfs]
would be better
saying it was swap what did it is a bit on the meh side as you have provided no evidence that the swap was even being used.
with no swap file/partition then you will get out of memory errors if you have a problem.
Raspbian swap is set ultra low - i.e. it will only swap if it really needs to .
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

keith.b
Posts: 16
Joined: Tue Jul 03, 2012 6:09 pm

Re: No swap space?

Mon Aug 20, 2012 6:30 pm

jojopi and RaTTuS both replied on Aug 20th
Apologies for the lack of info guys, and also for me being very new to the Linux OS.

My project is for a (shop) window display, and uses chromium-browser to loop between two sites, both internal .html files. Both pages load jQuery.js from a resident file; the first file displays a simple static page and uses the delayer function to switch to the second .html file after a delay of 20 seconds.

The second file then loads a twitter feed (code contains error traps in case of internet or twitter response failures), which it displays on screen. After a delay of 40 seconds, it then loops back to the first, and so on.

Nowhere do I purposely write to any files, just write the twitter feed to the browser screen. Obviously there are multiple file reads from the SD card at each switch.

Therefore you may well be right, that the swap file is not frequently (if ever) invoked, and the problem may reside elsewhere. The first SD card crashed after 7 days continuous looping, and would not boot to the command prompt, instead displaying 'mmcblk0: error - 110 transferring data, sector 158760, nr 264, cnd response 0x200900, card status 0x0'; then 'end_request: I/O error, dev mmcblk0, sector 158760'. This repeats some 260 odd times until nr counts down to zero. That was using a Debian 6 'Squeeze' OS.

Now running Raspbian Wheezy build 20_7_2012.

The project has now been running for 24 hrs. with Wheezy, and has displayed an error message from Chromium 'Aw Snap' in the centre of a blank screen. However, in this case a reboot restored the status quo.

Your advice against modifying the dphys-swapfile is noted, and I have now found your references to the other alternatives - thanks.

If I continue to have problems, I should probably start a new thread.

stisi
Posts: 2
Joined: Tue Jul 31, 2012 10:35 am

Re: No swap space?

Wed Aug 22, 2012 3:34 am

I need much swap space to stitch pictures (yes, the raspberry has time for this :) ) - about 1GB

How to use a USB Drive as swapfile/Swappartition with raspbian?


Thx

User avatar
Ray_GTI-R
Posts: 96
Joined: Fri Mar 09, 2012 1:21 am
Contact: Website

Re: No swap space?

Tue Aug 28, 2012 2:07 am

/etc/fstab is depricated (read:- superceeded although it might work if you can figger it out) in the latest Raspbian.

Simple answer, step-by-step

Change the size of the swapfile from 100MB to 512MB
---------------------------------------------------
In the "startx" GUI

Open a Root terminal then type:-

sudo echo "CONF_SWAPSIZE=512" > /etc/dphys-swapfile

Initialize the swapfile
-----------------------
sudo dphys-swapfile setup

Enable the swapfile
-------------------
sudo dphys-swapfile swapon

I cold-rebooted just to make sure all was as expected, I looked at the pre-logon messages just to check.

A swap partition might be better, dunno.
Better yet, use a swap disk ... that's a physical disk used purely as a swap ... erm ... a place for swappiness happening that won't impact on the system disk (uh-ho windowness returning) ahem - I mean preventing swapping of any kind on the Raspbian operating system (OS) SD card.
No I haven't figgered that out yet but I'm a noob. :lol:
Yes, all highly repetetive physical data changes should be done off-Raspbian operating system SD card because that will prolong the life of the Raspbian operating system SD card , e.g., a(nother) physical disk used purely for non-Raspbian OS.
FWIW a good 2nd micro/SD card beckons for swappiness & frequent data changes and if it's cheap I can just junk it if things get ... erm ... unswappy.
(Please don't ask me what frequent data changes mean in your context - I can't quantify frequent inside my own context :!: )
PPS A good, non-swapped, non-frequent data changes physical data disk is a(nother) decent idea :mrgreen: Then there's external backup stored in a firesafe/Cloud repository to ...umm ... schedule, think on. I do :ugeek:

zinit
Posts: 2
Joined: Sun Sep 16, 2012 5:19 am

Re: No swap space?

Sun Sep 16, 2012 5:28 am

swap on another media than the SD card is easy to set up.
I use a 500MB usb2 stick I had laying around. comes up as /dev/sda1
so just make a partition with type swap.
mkswap /dev/sda1
swapon /dev/sda1
add /dev/sda1 as swap in /etc/fstab to start it during boot.
swapon -s to show your swap partition/file.

zinit
Posts: 2
Joined: Sun Sep 16, 2012 5:19 am

Re: No swap space?

Sun Sep 16, 2012 6:03 am

I have my swap on an old 500MB usb2 stick I had laying around. so the swap file was no point to keep as the usb is alot faster than the SD card.
still keeping the swapfile program installed in case I dont have the usb with me somewhere so I can just switch the swapfile on if needed.

if you go in /etc/rc.local and put this in above the "exit 0"

Code: Select all

dphys-swapfile swapoff
then the swapfile will be switched off during boot when you are booting into multiuser. (honestly.. how often do you use singleuser...)

and can be switched on in case you would need some more swap for some reason. (or go somewhere and forget the usb at home)

mcgyver83
Posts: 361
Joined: Fri Oct 05, 2012 11:49 am

Re: No swap space?

Wed Oct 24, 2012 12:48 pm

zinit wrote:I have my swap on an old 500MB usb2 stick I had laying around. so the swap file was no point to keep as the usb is alot faster than the SD card.
still keeping the swapfile program installed in case I dont have the usb with me somewhere so I can just switch the swapfile on if needed.

if you go in /etc/rc.local and put this in above the "exit 0"

Code: Select all

dphys-swapfile swapoff
then the swapfile will be switched off during boot when you are booting into multiuser. (honestly.. how often do you use singleuser...)

and can be switched on in case you would need some more swap for some reason. (or go somewhere and forget the usb at home)
Hi, I also have an old 256Mb pendrive, why don't find a new life for it :mrgreen:
I followed Zinit "guide"

Code: Select all

mkswap /dev/sda1
swapon /dev/sda1 
add /dev/sda1 as swap in /etc/fstab to start it during boot. 
swapon -s to show your swap partition/file.
and now I have my usb that is a swap partition. Ok, but what will happen if I boot the rasp without pendrive plugged?I have a working system without swap but working, right?
I can have an error regarding the fstab line but the system will boot, I hope..
After that, why don't give higher priority to swap partition than the swap file to maintain both?
This "double" swap will nullify the advantages (write-cycles number save) of moving the swap far from the sd?

hallonman
Posts: 1
Joined: Thu Nov 29, 2012 11:08 am

Re: No swap space?

Thu Nov 29, 2012 11:43 am

Using a USB pendrive as swap won't make you more happy I'm afraid.
It is just another application of the same flash memory technology having the problem of a finite number of program-erase cycles as SD cards have. Avoid swapping altogether and send frequent writes to ram or use hard disks of the old mechanical magnetic type if you can't.
Regards,
Sven

mcgyver83
Posts: 361
Joined: Fri Oct 05, 2012 11:49 am

Re: No swap space?

Thu Nov 29, 2012 2:46 pm

Yes, I know. but i prefer to consume this old 256MB usb stick instead of the new sdhc class10 :D

zinit wrote:I have my swap on an old 500MB usb2 stick I had laying around. so the swap file was no point to keep as the usb is alot faster than the SD card.
still keeping the swapfile program installed in case I dont have the usb with me somewhere so I can just switch the swapfile on if needed.

if you go in /etc/rc.local and put this in above the "exit 0"

Code: Select all

dphys-swapfile swapoff
then the swapfile will be switched off during boot when you are booting into multiuser. (honestly.. how often do you use singleuser...)

and can be switched on in case you would need some more swap for some reason. (or go somewhere and forget the usb at home)
But in this way, if the usb stick is removed you don't have any swap due the line added?Is it right?
And something that check for swap partition and if it is found disable the swap file?

mcgyver83
Posts: 361
Joined: Fri Oct 05, 2012 11:49 am

Re: No swap space?

Fri Dec 07, 2012 9:51 am

As I said I'm using a swap partition on an external usb pendrive, I added to /etc/rc.local

Code: Select all

dphys-swapfile swapoff
but when I reboot I read on the screen:
"Starting dphys-swapfile swapfile setup...
want /var/swapfile=100MByte, checking existing: keeping it"
and with swapon -s I found the swap partition but also the swap file...
If I run manually

Code: Select all

dphys-swapfile swapoff
the swap file disappears.
why?

User avatar
kbailey
Posts: 40
Joined: Fri Feb 08, 2013 6:22 am
Location: Largo Florida USA
Contact: ICQ Website

swappiiness

Thu Apr 11, 2013 4:29 pm

OK, I accept there are good reasons for raspian using a swap file , and I re sized it in accordance with general good practices in Linux. Now I want to alter the swappiness so the system operates more efficiently and therefore faster. How do I alter swappiness?
:?:
-Cheers!
-_-=-_-=-_-=-_-=-_-=-_-=-_-=-_-=-
Computers are the new Logos.
Does this compute?

Return to “General discussion”