2

I have 128 MB of Ram in one of my products, which was sufficient when we released first version of the product. But now we added some extra features in it, So this much Ram may cause a problem of OOM.

I have 64 MB of Flash memory out of which more than 50% is unused So can I use the remaining memory as a Swap memory?

We are using Linux kernel version 3.4.56 in this product.

Thanks in advance for your suggestions.

2 Answers 2

2

If the flash supports wear-levelling (will depend) then swap might be viable, it depends on how long you want these devices to last. There are other factors - what the flash memory is rated for in terms of writes, how long it has been in use up until now, how active it has been in terms of writes.

Wear-levelling is a process where the controller keeps a constant count on how many times every cell has been written to, and tries to keep things so that all cells have equal writes to them.

With that working perfectly and a device rated for 100,000 writes (for example) some very rough math tells us that you could expect a life of a little over 2.5 years with perfect wear and 10MB/s. Realistically you are probably not going to see perfect wear but you are also probably not going to see that level of constant writing either.

Without wear-levelling then all bets are off, you will have no idea how often a piece of data might be overwritten and without something to spread it around the flash cells, you could start killing cells in hours/days/weeks depending on your usage.

So, you can use your flash device for swap, but whether you should or not will depend on the factors above and how long you want the devices to be viable.

One other note: the speed will generally be SLOW for random writes on this device, so you will see a huge performance penalty when hitting the flash swap when you configure it. You will avoid OOM situations, but it may be just as bad if everything slows to a crawl, so definitely some testing required to see if it is even worth it.

1

Linux does not care what block device the swap lives on. Using the swapon command from a shell, you can put it wherever you want.

It can be a hard drive partition sda1, sda2, etc., an iSCSI device, an encrypted or LVM'ed device in /dev/mapper, or an mtdblock device.

If your flash is already formatted, you may want to use a swap file instead of a block device.

1
  • Thanks Adam and ultrasawblade for your quick reply. I later went through the limitations of using flash as a swap memory and also found an interesting parameter in /proc/meminfo, i.e inactive memory. My current system status shows the 8 Mb of free memory but when I manually frees up the inactive memory it shows around 50 Mb of free memory. So now I am looking for the way by which system can clear the inactive memory by itself. So my memory problem will be solved easily.
    – nyk_mat
    Feb 26, 2014 at 5:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .