PDA

View Full Version : zram, anyone have an opinion on this?



utu
10-06-2011, 11:47 PM
.
See the brief article here

http://www.webupd8.org/2011/10/increased-performance-in-linux-with.html

utu
05-15-2012, 12:59 AM
.
Compressed swap in RAM, zram is an experimental linux innovation that
provides swap performance improvement in systems that might otherwise
swap to other media, such as hard drives or SDDs, for examples: older
computers, netbooks or any computer 'low on ram' considering the random
access memory demands of all its program(s) being used concurrently.

The following sites may be of some help in understanding zram as used
by several linux distributions. Warning, these may not be self-consistent:
http://www.webupd8.org/2011/10/increased-performance-in-linux-with.html
http://mystilleef.blogspot.com/2011/10/enable-zram-in-fedora.html
http://oprod.net/index.php/news/1-news/92-compress-ram-with-zram-in-slackware\ (http://oprod.net/index.php/news/1-news/92-compress-ram-with-zram-in-slackware%5C)
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=648249
http://weirdfellow.wordpress.com/2011/05/04/compressed-ram-with-zram/

Blacksimon
05-15-2012, 08:12 AM
Hi utu,
instead of swap disk, it uses a part of phisical RAM like swap file. It's right ?
I think you need to have more 1GB of RAM to really increase performance with zRAM

Blacksimon
05-17-2012, 08:30 AM
I read more about zram.
usually if you use swap, you have already a low ram system
there is no doubt that swap in RAM is faster then HDD, but with zram you make less memory available to applications
and finally how is the compressing memory on the fly using zram ?

The ramdisk in knoppix is not the same concept of zram ?

utu
05-17-2012, 03:35 PM
@ Blacksimon

In Knoppix 6.7.1, I note that a device has been defined,
that is /dev/zram0. I can find no other references to zram
in 6.7.1.

zram is a block device, and a lot of linux activity outside of
Knoppix as I have noted in post #2 concerns zram.
I was hoping this forum might have some interest or activity
on this subject.
I can see how this might help the netbook situation.
I can't yet grasp how this might help virtual systems.

I expect if one has a lot of ram and doesn't have lots of
high-powered apps going simultaneously that zram doesn't have
much to offer. Although it might be a nice feature to assure
that one almost never would crash because of running too
low on ram. If there's no significant overhead for this.

Blacksimon
05-18-2012, 03:03 PM
Hi Utu,
yes in knoppix 6.7.1 /dev/zram0 is defined but not inizialized, i think.
take a look at the value = 0 in file called disksize in /sys/devices/virtual/block/zram0
and then at the file Kconfig in /usr/src/linux-headers-3.0.4/drivers/staging/zram
and even at Kconfig in /usr/src/linux-headers-3.0.4/drivers/staging

i read again the user's comment in http://www.webupd8.org/2011/10/increased-performance-in-linux-with.html
I tried in terminal:


root@Black:~# modprobe zram disksize=524288 #probably do not need ad i've to modify directly file called disksize
root@Black:~# mkswap /dev/zram0
mkswap: error: swap area needs to be at least 40 KiB
Usage: mkswap [-c] [-pPAGESZ] [-L label] [-U UUID] /dev/name [blocks]
root@Black:~# swapon -p 100 /dev/zram0
swapon: /dev/zram0: read swap header failed: Argomento non valido
root@Black:~#

but nothing. Sure i'm wrong

and like you say it might be a nice feature for net-book with only 1GB Ram and low power CPU
for now I optimize knoppix moving the browser cache, log, tmp and spool in tmpfs
http://www.fewt.com/2010/07/move-your-logs-and-temp-files-to-ram.html

bye

utu
05-18-2012, 03:46 PM
@ Blacksimon

My experience has been chiefly with a LiveUSB built from
the CD-size Knoppix 6.7.1, and had seen only the /dev/zram0 there,
no src files. I expect you found these in a DVD version.
Still, you mention no documentation on how to use this material.

I've never used swap with Knoppix since I switched to LiveUSB.
My portable has 4 Gb of ram, and the most complicated apps I use
are IceWeasel, LibreOffice and Synaptic.

My expectations are
1. Finished products for driver and configuration in a CD-size
Knoppix seem useful for 512k-ram-or-less situations.
2. For such ram-limited computers, compiling the finished products
seems like a Catch22 situation: you'd need them to do their compilation;
3. I'd really like a roadmap on how to do an implementation, given
the infrastructure that's apparently provided in a DVD distribution; and
4. I would favor a hidden, standard implementation that's there to
provide 'more ram' in situations one doesn't anticipate but may
run into sometime. Standard, not an option, just there, part of the
infrastructure of a robust OS.

I think we are probably only bringing the Unix swap idea into the
current era of relative i/o device speeds & clever and fast algorithms
to compact and restore large blocks of data, and realizing how we might
better utilize what we have.

Hoping also to hear from the 'virtual' crowd to see if this offers
them anything useful.

Blacksimon
05-18-2012, 04:55 PM
Hi Utu,
yes I use LiveUSB DVD version and I've not found any further documentation about how to use it.
I've never used swap too and even with only 1gb of ram on my netbook, knoppix 6.7.1 works well, only when I work with high-resolution photos in Gimp I see some slowdown.
For everything else, I fully agree with you.

while waiting for suggestions from the community there is to read this article: http://www.thegeekstuff.com/2008/11/overview-of-ramfs-and-tmpfs-on-linux/

I do not know if there is a difference between zram, tmpfs and ramfs

utu
05-21-2012, 04:26 PM
.
From a usually reliable source in Germany, I received the following
response in regard to where I might find some roadmap to using zram in Knoppix:



The delay between your question and my answer means that I did a lot of
updates, zram ist working now,

A good description on how to test zram can be found at:
http://www.webupd8.org/2011/10/increased-performance-in-linux-with.html
and an overview at Wikipedia at
http://en.wikipedia.org/wiki/ZRam

Knoppix 7.0.1 will use 75% of the available RAM, but at maximum 4GB, for
compressed swapspace in ram. In the best case, you can double or triple
your "virtual working RAM" with zram without swapping to disk. In the
worst case, you lose a few header bytes due to incompressible data, or
get "out of memory" kills (like before, without zram) when even
compressed swap runs out of space.

75% seems to be a decent number for me. I don't trust a "fully
compressed" RAM like recommended in the URL given above, since you
always need some extra MB as immediately available "emergency RAM"
without having to negotiate with the swap area. In my tests, I got
strange effects when using 100% of the available Ram as zram space, like
ramdisks suddenly being "full" with no data inside.

Blacksimon
05-21-2012, 10:56 PM
Hi utu,
finally I find the way...


modprobe zram #I do not think is necessary if your system has / dev/zram0
echo $((100*1024*1204)) > /sys/block/zram0/disksize #Allocate 100MB to zram. (Check if the file disksize is present in CD version)
mkswap /dev/zram0 #create swap in Ram
swapon -p 100 /dev/zram0 #activate swap. You can specify the priority of the swap device


root@Black:~# free
total used free shared buffers cached
Mem: 1018724 943440 75284 0 58860 599440
-/+ buffers/cache: 285140 733584
Swap: 102396 0 102396

Now it's time to test performance...

Best Regards

utu
05-22-2012, 12:26 AM
@ Blacksimon

I can confirm your experience -so far- with Knoppix 6.7.1 & CeBIT 7.
And I'm flabbergasted.

However, I can't seem to get any combination of my apps to create any 'used' swap values.
I'm using your commands but asking for 3.1 Gb swap, having 3.6 Gb total and apps amounting to 1+ Gb.
Perhaps there's yet one more magic word necessary to enable the magic.

Also, in my case, I have 2 cpus, and probably should enable 2 swap files.
Let me know how you make out.

________________
Werner: we'd not be disturbed if you moved this thread out of this category.

utu
05-22-2012, 01:21 AM
.
@ Blacksimon

Although I am surprised at how much infrastructure you have uncovered that is applicable to zram,
this may be more due to my absence of experience with any form of swap.

In this instance, I think we are at least missing a driver called zram, and/or perhaps a clue like zram.ko
indicating some source material.
Also, I can't see any evidence on /etc/fstab that speaks to swapping of any kind.

I expect we may have to wait for 7.0.1 for the rest of the material to appear.
I'd be pleased to have you show otherwise.

Blacksimon
05-22-2012, 03:06 PM
Hello Utu,
thanks for your words but my experience comes from the fact that I like to understand how to improve system performance by using hardware and software available without having to invest any more money... :-)
I like to fully understand how things work...

Anyway in your case if you have multiple cores (2 cpus), then using a single zram can be a bottleneck, so you need zram0 e zram1 (it's present in your /dev/ ??)

modprobe zram num_devices=2 #On July 20th 2011, the zram driver in the linux 3.1 staging area was modified to use zram_num_devices as modprobe parameter
echo $((512*1024*1204)) > /sys/block/zram0/disksize #Allocate 512MB to zram0
echo $((512*1024*1204)) > /sys/block/zram1/disksize #Allocate 512MB to zram1
mkswap /dev/zram0
mkswap /dev/zram1
swapon -p 100 /dev/zram0
swapon -p 100 /dev/zram1

But beware, I have not tested anything right now, I just created a swap in ram. Now we need to see if it actually works. It 's likely to miss the module zram.ko as you have highlighted. I'm waiting 7.0.1 too.

Regards.

utu
05-25-2012, 11:19 PM
.
@ Blacksimon

Surprise: zram capability is already in 6.7.1; it just
hasn't been advertized or automated. As you were beginning to suspect.

Here's how to simulate what's coming in Knoppix 7.0+:

1. Boot up Knoppix 6.7.1 with the cheatcode knoppix mem=512M
This simulates a 'small' amount of ram these days.

2. Establish a zram set-up using 3/4 the ram as zram:
echo $((384*1024*1024))>/sys/block/zram0/disksize
mkswap /dev/zram0
swapon -p 100 /dev/zram0

3. Bring in LibreOffice and IceWeasel
(without zram, my mem used would be about 807M with
just these two and lxterminal)

4. Switch from one to the other of these; when you switch,
give each something new to do.

5. Examine free from time to time.

6. Bring in some more programs, check free again.

Blacksimon
05-26-2012, 04:29 PM
Hi Utu,
this makes me very pleased.
Now, all that remains is to check the effectiveness of zram to judge whether you have a real performance increase.
I'll try to test the system, making him work hard with Gimp, maybe applying some filters to high resolution images.
I will tell you.

utu
05-26-2012, 05:04 PM
Since this new capability will be applicable to any amount of ram,
it would be handy to have some simple, generic test that would
demonstrate significant usage of zram in any given situation.

For example, I've got 4 Gb of ram, and my normal needs are met by
less than 1.5 Gb having everything available all the time.

Dumbing things down to make-believe I have 512M proves a point,
but not convincingly, to my mind.

Some algorithmic scheme of dd manipulation and Fibonacci series has
an elegant flavor to it, although dd can be dangerous.

Another scheme might be based on spawning several simultaneous virtual systems.

Blacksimon
05-27-2012, 10:30 AM
I used a Netbook Acer Aspire One with 1GB RAM, 768MB of zram setting.
I stressed the system by opening a dozen pictures and move large files from one hard disk to another, while surfing the internet watching videos on Youtube.

Well I have not noticed any significant performance increase.

Perhaps it is wiser to let the system use the full 1GB of Ram automatically, and perhaps this is not the appropriate test.
I do not know ...

utu
05-27-2012, 12:52 PM
@ Blacksimon

Performance 'increase' should be a measure of the difference between
swapping to hdd and swapping to zram.

If your Knoppix can handle everything you need with 1 Gb, then
zram in Knoppix 7 will stay out of the way and not affect performance
at all.

If you need more than 1 Gb, presumably your system will hang up
without zram, unless you have some other swap to save you.
This is where Knoppix's zram comes to the rescue. Not crashing
is the performance increase in this case.

Just trying to clarify things, hope this helps.

Blacksimon
05-27-2012, 09:03 PM
Everything you say is correct
Taking the test again with 512MB of zram, I noticed the effective use of zram, and in my case not crashing is a really performance increase
:-)



root@Black:~# free
total used free shared buffers cached
Mem: 1018724 1006984 11740 0 65772 128280
-/+ buffers/cache: 812932 205792
Swap: 616444 321768 294676

cvevans
08-22-2012, 05:19 AM
.
@ Blacksimon

... 2. Establish a zram set-up using 3/4 the ram as zram:
echo $((384*1024*1024))>/sys/block/zram0/disksize
mkswap /dev/zram0
swapon -p 100 /dev/zram0

3. Bring in LibreOffice and IceWeasel
(without zram, my mem used would be about 807M with
just these two and lxterminal)

4. Switch from one to the other of these; when you switch,
give each something new to do.

5. Examine free from time to time.

6. Bring in some more programs, check free again.

Can I use this to shrink the existing zram0 on K703?
Can I modprobe to add a second, smaller zram0? How?
I am concerned about running out of memory; I already see long pauses, especially when the system suddenly decided to put 1G into the empty zram swap.
What happens if I put 1G of .debs into the ramdisk? They are compressed; will I lose that 1G of RAM? Do I get it back if I swapoff /dev/zram0?
I have searched the web, so far with no details found.
Thanks

utu
08-22-2012, 03:42 PM
@ cvevans

I recognize my own material, but I can't grasp how it applies to the
several questions you ask. My quote speaks to simulating a small ram
situation. My rig has 4 Gb and it is my understanding that without
some cheatcode or other, I'd never see zram's effect. Hence the
simulation.

IIRC, above 2 Gb real ram, zram is never employed.
There is a cheatcode which may be used to keep zram from being used
for any value of real ram. That about exhausts what I know about zram.

For some of the more experienced forum members, I think you should
spell out in some detail what you are trying to do and what the
particulars of your Knoppix install is. Maybe they can help you.

Keep in mind that some of us use LiveUSBs,
some have an hd install, poor-man's or 0wn, some use a virtual setup.

utu
08-22-2012, 06:42 PM
@cvevans

In considering this topic anew I have the following thoughts.

1. The general topic of swapping seems to apply here, it is only
that a new device has been added to the list.
There's lots of material on swapping; see apropos swap for example.

1.5 Whatever your situation is, it would seem you might emulate
whatever your swap questions are first using hard drive partitions
to iron out the kinks. Once that is working, switch only the device
designations for hard drive to zram.

2. Knoppix has only one device, zram0. defined to use ram as a swap device.
It may be necessary to re-compile the kernel fo provide additional such devices.
I now recall another developer likes to split the 'zram' load among cpus
if there are more than one available. Klaus K prefers not to do so.

3. Klaus K has an interest in netbook applications of Knoppix, so
his focus, sometimes, is in 'really small' values of ram (less, or much
less, than a gigabyte). My situation is one of never needing swap, of
any kind, since my apps never outrun my available ram.

Let us know how things go for you.