Jump to content

RAM Disk with Zram


Lucil

Recommended Posts

I have an OrangePi Prime with 2 GB RAM. I'm running a server-like node.js app that does constant writes to .json files and text log files. Let's call it "database storage". The app is not otherwise RAM intensive, can run fine on 512 MB boards. I'm thinking of putting all my RAM to use and move the database storage to a RAM disk made with Zram.

 

Do you see any potential problems and interference with the way Zram is configured for this board?

Link to comment
Share on other sites

Zram maybe was not intended for creating ram drives. But it's fit to the task and it has the benefit it does not swap the contents of the ramdrive. So I'm not talking about system swap or system logs. Simply if using it in the above scenario (fast db storage) would crap the other components of it already running.

Link to comment
Share on other sites

Tido is right as its an example of zram creating a ram drive that in that uses a zram drive for log files.
It would take minimal change for it to be dbstorage instead and you could use the same mechanisms on start and stop to transfer to media to make it persistent.

With Lz4 you would get minimal and near ram speed with large compression gains or use pure tmpfs ram.
I don't like how log2ram writes out full files every hour and did my own version https://github.com/StuartIanNaylor/log2zram but its all based on azlux's work which is all based on https://debian-administration.org/article/661/A_transient_/var/log

With log2ram or log2zram you could just change the bind directory which basically moves the directory somewhere else so you can mount a ram drive inplace.
That is it create bind directory to move your directory.
Mount you ram drive in the location that was moved.
Copy the data to ram and go.
On stop you just do the reverse and copy data back to the moved directory.
Then unmount ram and bind and it is then persistent.

With azlux and log2ram each hour it copies out to the moved directory, but that can still leave up to an hours gap and something IMHO is probably pointless.
If you have lost the last hour via usage of volatile memory storage I am not really sure of the benefit of the hours preceding.
Thats only if you get a complete crash and no orderly shutdown which you can prob trigger with a watchdog, but if you lose up to the last hour its lost.
Prob worse with logs as the info of the crash is very likely to be lost and what you do have is of little interest.
For most usages the complete crash is the exception and not likely to occur, apart from pulling the plug.

zram is a hotplug system and a simple check is...
 

if [ ! -d "/sys/class/zram-control" ]; then

modprobe --verbose zram

RAM_DEV='0'

else

RAM_DEV=$(cat /sys/class/zram-control/hot_add)

Have the same routine in log2zram and zram-swap-config and should be able to run and be first with the modprobe of zram0 or just hot_add another.
https://github.com/StuartIanNaylor/zram-swap-config does the same as https://github.com/StuartIanNaylor/log2zram and you just have to be aware of other zram services that don't check previous existence, or be sure you run after.
 

Link to comment
Share on other sites

PS thought that was a good idea and a zram drive for any purpose might be a good idea.

Need to tidy the conf info and readme.md

 

But in zramdrive.conf there are 2 options.
HDD_DIR is the dir you are going to create 'any name' to be the temp persistent dir that we will move to via bind

ZRAM_DIR is the dir you want to hold in zram
 

HDD_DIR=/opt/moved

ZRAM_DIR=/var/backups

https://github.com/StuartIanNaylor/zramdrive

Link to comment
Share on other sites

I have done an all-in-one based on a /etc/ztab that lets you create any number of swaps / zram backed dirs and also /var/log with log shipping to persistant.
https://github.com/StuartIanNaylor/zram-config
Should be great for block wear and near ram speed file performance. or extending memory via compression.
If any of the Armbian guys want to grab hack or rename then please do so.
Its a bit fresh so needs some input and use as sure there will be something.

 

sudo apt-get install git 

git clone https://github.com/StuartIanNaylor/zram-config 

cd zram-config 

sudo sh install.sh

Any issues please post on github and as said grab, hack or comment on improvements. 

Link to comment
Share on other sites

On 3/20/2019 at 2:11 AM, Lucil said:

have an OrangePi Prime with 2 GB RAM. I'm running a server-like node.js app that does constant writes to .json files and text log files. Let's call it "database storage". The app is not otherwise RAM intensive, can run fine on 512 MB boards. I'm thinking of putting all my RAM to use and move the database storage to a RAM disk made with Zram.

 

Do you see any potential problems and interference with the way Zram is configured for this board?

 

It's do-able - as long as your data is real-time/epherimal - if the board crashes, any data that needs to be retained will go "poof - software magic smoke"

 

I normally keep /tmp in tmpfs, and yes I do run ZRAM, but not for data that is expected to persist across reboots - this would also be /var/tmp...

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines