How could I ever get by without a swapfile?


Well... I *only* enable swap on a 1Gb dedicated SD card when I need it... Do you really want to shorten the life of a good higher capacity SD with all those writes?

its a non-issue.


the number of write needed before an SD card fails is quite large, much larger than anyone's patience when running something that would hit a swap file on an SD card non-stop.


you'll get fed up of waiting long before the SD dies.


take the usual 100,000 erase cycles, multiplied by wear-leveling, you'll have to wait a looooooooooooong time before the SD card dies.


chances are very good you'd kill the SD card by wearing out its connector thru repeated insertions way before its erase cycles run out.


all my SD cards that died, died of connector wear.
 
What you can do is to put the swap always at the same physical place of the SD, ie, 256M at the end.


So in case this part gets damaged, you just have to reduce (-256M or more) the size of the first partition, and recreate the 256M swap.


Anyway, i also think none of us will ever damage a good card with a standard usage. Only a few app make the OP to swap.


One really clever option of zram is the priority. With the right parameter, the compressed ram is used before the drive swap.
 
^


Hmm.. So in my desire to preserve my cards, I'm actually accelerating their demise.. Hmm. So what do you suggest? - create a swap file on my primary 32gb card?

yeah, I wouldn't put a swap on the NAND, but I really have no fear of putting one on the SD card.


its so slow that once it start swapping you'll really notice and want close some browser tabs to free up memory anyway.


still beats having the browser or other random programs just suddenly die on you.


a good SD card controller's firmware (its inside the SD card) will spread the wear over the card (wear leveling) so not one single part of the card gets overwritten over and over,


if it does not do proper wear leveling then, swap or no swap, the card wont last long even with normal use but I've never had one fail due to repetitive writes so I'm guessing they're all pretty good, or the 100,000 minimum erase cycles without even wear leveling are more than enough.


also, way before your SD card dies of regular use you should be able to afford a new one, 256GB or larger SD cards will probably be out already, with 32GB cards around 8$ in bundles of 3 per pack :p


just look at how cheap 4GB cards are today.


there's some info on formatting an SD card "properly" on the olpc forums altho its a bit of a pain and haven't bothered to but might for a large card:


http://www.olpcnews.com/forum/index.php?topic=4993.0
 
Do you think the wear leveling function acts at the partition level or above all ?
 
Well, I like having the ability to have 5 or 6 tabs open at once... Seeing as the Pandora is my only computing device when I'm in Coffee Bay it needs to do the job.


I'll keep using my 1gb card for swap for the time being (the swap file is about 950mb), and when I get around to buying another card 32gb or higher I'll look into changing how I do things... It's really neither here nor there if the 1gb card fails from repeated inserts.


The other concern I have: If you have swap on an unpartitioned card that also contains valuable data... if you take out the card and forget to disable swap before you do, don't you risk corrupting the whole card - requiring a format?
 
"If you have swap on an unpartitioned card that also contains valuable data..."


I'm not sure to understand.


"if you take out the card and forget to disable swap before you do, don't you risk corrupting the whole card"


Swap is like Ram, so it's more like to unplug the power cord. You can lose data, but there will be no needed format.
 
"If you have swap on an unpartitioned card that also contains valuable data..."


I'm not sure to understand.

I just meant that if I use a card that hasn't been partitioned into smaller drives with one of them dedicated to swap.

Swap is like Ram, so it's more like to unplug the power cord. You can lose data, but there will be no needed format.

Good to hear. So no reason why I shouldn't create a swapfile on my primary card. :)
 
MLC NAND Flash memory (which is what's used in most, if not all, sd-cards) typically has ±10.000 erase-cycles. 100.000 is what the more expensive SLC does.


Assuming perfect wear-leveling, a 8GByte-card with 20MByte/s sequential write-speed can be killed in 8GByte*10000/(20MByte/s) = 4000000s = 46days, so yeah, continously writing to such a card can kill it in 1.5 months, and a 1GByte-card with 20MByte/s write-speed will last 6 days...


Bigger cards will last longer, cards with faster sequential write-speeds will last shorter, but will write just as much data in that time.


Swap is primarily a lot of random-write activity, which is far slower, but the SD-card will still be writing its NAND at near-full-speed (which is what makes random writes so slow: it copies all of the data in the erase-block, makes your modifications, and writes it in one of the spare erase-blocks), so when calculating how long your card'll last, you must use the sequential write-speed.


Also, cards with high random-write-speeds will have better wear-leveling, causing less erase-block-copies, so will last longer.


Of course, you'll never be writing to your card continously, so I doubt anyone ever managed to kill a 8+GB-card in less than a year...


If you have a swap-file, and that file happens to share an erase-cluster with another file, the sd-card can copy over that other file as well during an erase-block-copy. That might corrupt that other file if you eject the card during the write, depending on the specific implementation of the wear-leveling. But a properly-formatted (partitions and files start at erase-blocks) sd-card should minimize the chance of that happening. But using a swap-partition is still safer.
 
MLC NAND Flash memory (which is what's used in most, if not all, sd-cards) typically has ±10.000 erase-cycles. 100.000 is what the more expensive SLC does.
Mmmm... Is that backwards?


http://en.wikipedia.org/wiki/Flash_memory


SLC = single level cell has been around a long time.


MLC = multi level cell is a relatively new tech.


I don't know that SLC vs MLC has a direct bearing on write cycles or wear either. The Wikipedia article has some insights to this. It makes good reading if you're really curious around the topic.


Does anyone make a MLC based SD form factor card yet?
 
MLC = higher data density for way less money. It was invented to make large flash chips cheaper, most mobile storage devices don't see a lot of write cycles so nobody cares about the fewer cycles.


It basically means that multiple bits are grouped together -> less space needed but you always have to erase/write all bits of such a group at once, making proper wear leveling more difficult and a loss of bits more likely as one failing bit renders its whole group useless.
 
The other concern I have: If you have swap on an unpartitioned card that also contains valuable data... if you take out the card and forget to disable swap before you do, don't you risk corrupting the whole card - requiring a format?

it shouldn't corrupt the card, it will however crash everything that was using the swap and there's a good possibility the kernel will panic and halt the system.


because from the kernel's point of view you just yanked RAM out of the machine (in a way, swap is very slow ram)


laurencevde got a point that it might corrupt something if the swap shares an erase block and the FTL isn't journalled properly and interrupted mid-process while its copying data over to a newly erased block.


just don't unplug the SD with swap on :p


the more the reason to have it on the SD card you never remove :)

MLC NAND Flash memory (which is what's used in most, if not all, sd-cards) typically has ±10.000 erase-cycles. 100.000 is what the more expensive SLC does.


Assuming perfect wear-leveling, a 8GByte-card with 20MByte/s sequential write-speed can be killed in 8GByte*10000/(20MByte/s) = 4000000s = 46days, so yeah, continously writing to such a card can kill it in 1.5 months, and a 1GByte-card with 20MByte/s write-speed will last 6 days...


[...]


Of course, you'll never be writing to your card continously, so I doubt anyone ever managed to kill a 8+GB-card in less than a year...

yup, and SLC would take 15months of continuous 24/7 abuse.


to kill and MLC in 1.5 months with swap while using your Pandora means you'd have to sit in front of your pandora non-stop 24/7 waiting after firefox to be done swapping to start it on something else and making sure it doesn't stop accessing the swap, and that's only if that's all the app is doing (not spending time drawing, waiting on the internet connection, etc).


you might as well watch paint dry :D


me and my wife have two digital video cameras that save to SD, we use them as dashboard cameras, one for the car, and one for the van. we completely fill and reformat the cards at least once or twice a week, one card has been at it for 2 years and the other for a year now, they're both still working fine.


I think that's way more abuse than normal web browsing + swap would cause :)


as always, your mileage may vary.


and make backups of your important stuff (and you really shouldn't use your very small, very easily lost or stolen Pandora to hold the only copy of whatever you hold dear :p )
 
What I did was created a 256MB swap file in the Firefox appdata directory and added "swapon" to the pre script. And swapoff to the post script, of course. That way, when I start Firefox I get swapfile, when I kill it the swapfile is closed, and I don't have to worry about whether I remembered to disable the swap manually before yanking the card. You could quite easily do the same for any other program (like Wesnoth) that you want or need to have a bit of a memory buffer for.
 
Ok, I just made a 256MB SWAP file on my main SD just for testing. I had a swap tool on my Pandora for quite a while but I never was brave enough to activate it. (It create and activate or disable a swap file)


And now Firefox loads the websites really fast, no much lag anymore. I


really thought it was because of the Browser(s) but now I see that the lack of a swap file really has a big impact on the performance of certain programms.


Of course I don't want to kill my beloved Pandora SD card so I guess I can't keep the swap file enabled. However, it works and now I know that browsing on the Pandora can be quite fast, even with an actual PC Browser. :)


I hope this promising ZRAM thingy is rady soon, because I plan longer Wesnoth sessions and this game reaaly needs a swap in newer game versions (1.8 branch played fine without)
 
Last edited by a moderator:
strange, my swapfile is disabled it seems, everytime I restart the Pandora. I use the litle tool from the Repo and it really works, but even with Admin PW it doesn't seems to be a permanent solution. Swap file still exists on the SD but using of it is disabled after reboot. So I guess I have to setup the swapfile everytime I need it.


Why is this always so complicated in Linux? :(
 
^^.


Actually it's pretty simple when you begin to know how to set up all automatically.
 
The tool that you are talking about is very very primitive. It doesn't touch a sinlge file on your rootfs. When you enable a swapfile, all it does is running gksudo swapon <path to the file you selected>. I could modify it to live on your NAND and save the swapfiles that you activate, if such functionality is wanted by anyone.
 
Back
Top