How to set up properly zram and swap
I'm configuring & compiling new 3.0 kernel. One of the goodies I planned to use for some time (by patching) that was merged into 3.0 is zram.
Is it possible to set both hdd swap and zram swap so the zram is used first and only spilled pages are put into actual swap?
linux swap zram virtual-memory
add a comment |
I'm configuring & compiling new 3.0 kernel. One of the goodies I planned to use for some time (by patching) that was merged into 3.0 is zram.
Is it possible to set both hdd swap and zram swap so the zram is used first and only spilled pages are put into actual swap?
linux swap zram virtual-memory
add a comment |
I'm configuring & compiling new 3.0 kernel. One of the goodies I planned to use for some time (by patching) that was merged into 3.0 is zram.
Is it possible to set both hdd swap and zram swap so the zram is used first and only spilled pages are put into actual swap?
linux swap zram virtual-memory
I'm configuring & compiling new 3.0 kernel. One of the goodies I planned to use for some time (by patching) that was merged into 3.0 is zram.
Is it possible to set both hdd swap and zram swap so the zram is used first and only spilled pages are put into actual swap?
linux swap zram virtual-memory
linux swap zram virtual-memory
asked Jul 22 '11 at 21:45
Maciej PiechotkaMaciej Piechotka
11.3k74278
11.3k74278
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
Sidenote: because of per-cpu locking, it is important to have as many zram-swaps as CPUs (modprobe zram_num_devices=n zram) instead of a single big one. RTFM!
1
[citation needed]? I cannot find the recomendation in Linux documentation or Google.
– Maciej Piechotka
Nov 28 '11 at 23:28
By defaultmax_comp_streams
seems to be1
according to documentation. I haven't checked if that parameter existed in 2011 but it seems to be a better option then multiple swap files.
– Maciej Piechotka
May 21 '15 at 19:27
Testing with the packagezram-config
under Ubuntu (and likely debian) I noted that the configuration defaults to 1 per core or thread (2 on an old E2140 dual core and 4 on an i3-3220)
– Elder Geek
Feb 29 '16 at 4:03
interesting, and this also seems quite clear to understand by reading /etc/init/zram-config.conf
– Aquarius Power
Nov 18 '16 at 19:44
add a comment |
swapon
have -p
switch which sets the priority. I can set up:
swapon -p 32767 /dev/zram0
swapon -p 0 /dev/my-lvm-volume/swap
Or in /etc/fstab:
/dev/zram0 none swap sw,pri=32767 0 0
/dev/my-lvm-volume/swap none swap sw,pri=0 0 0
EDIT: Just for a full solution - such line may be helpful as udev rule:
KERNEL=="zram0", ACTION=="add", ATTR{disksize}="1073741824", RUN="/sbin/mkswap /$root/$name"
add a comment |
Select how many zram devices do you want by passing
zram.num_devices=4
to kernel parameters or directly to module (without zram.) . Default value is 1. zram will be able utilize as many cpus as number of devices you create.
Prepare zram0 device, set size to 1GB.
echo 1000000000 > /sys/block/zram0/disksize
Alternatively you can do it by udev rule.
Create swap on zram0
mkswap /dev/zram0
and enable it with higher priority than other swap devices
swapon -p 32767 /dev/zram0
What kernel and distro versions are you writing for here ?
– Cbhihe
Aug 29 '16 at 15:23
For the record, proceeding as you advise on a 14.04.5 desktop Ubuntu, fails. In particular, when I try to set the priorities ofzram0
andzram1
to value 10 on a 2 nuclei Intel T9300 box, it throws me with:swapon: /dev/zram0 or 1: swapon failed: Device or resource busy
.
– Cbhihe
Aug 29 '16 at 15:26
add a comment |
When you enable zram, it will automatically have priority.
For ubuntu 16.04: /usr/bin/init-zram-swapping
You can edit that file (make a backup 1st), to lower the used real ram, I changed the mem line to this:
mem=$(((totalmem / 4 / ${NRDEVICES}) * 1024))
add a comment |
For some reason there seems to be a lot of misinterpretation of https://www.kernel.org/doc/Documentation/blockdev/zram.txt
It clearly states
"2) Set max number of compression streams
Regardless the value passed to this attribute, ZRAM will always
allocate multiple compression streams - one per online CPUs - thus
allowing several concurrent compression operations. The number of
allocated compression streams goes down when some of the CPUs
become offline. There is no single-compression-stream mode anymore,
unless you are running a UP system or has only 1 CPU online.
To find out how many streams are currently available:
cat /sys/block/zram0/max_comp_streams"
But repetitively there is a common urban myth max streams is 1.
Its plainly not true.
The two OS where zram has proven effective Chrome OS & Android you a single device.
Also they tweak page-cluster
page-cluster controls the number of pages up to which consecutive pages
are read in from swap in a single attempt. This is the swap counterpart
to page cache readahead.
The mentioned consecutivity is not in terms of virtual/physical addresses,
but consecutive on swap space - that means they were swapped out together.
It is a logarithmic value - setting it to zero means "1 page", setting
it to 1 means "2 pages", setting it to 2 means "4 pages", etc.
Zero disables swap readahead completely.
The default value is three (eight pages at a time). There may be some
small benefits in tuning this to a different value if your workload is
swap-intensive.
Lower values mean lower latencies for initial faults, but at the same time
extra faults and I/O delays for following faults if they would have been part of
that consecutive pages readahead would have brought in.
echo "0" > /proc/sys/vm/page-cluster to force single page
Much seems to originate from zram_config the debian/ubuntu package that for some reason seems to have very little correlation with the kernel documents for zram and has bred a series of Chinese whispers that in essence could be completely wrong.
With file swap do you create a swap drive for each core? Maybe that might answer your questions.
Also to back this up Googles Chrome OS & Android which successfully with the above page-cluster as its not matching a disk so latency can be improved.
Also "num_devices parameter is optional and tells zram how many devices should be pre-created. Default: 1"
All you need to do is check if the zram sys class exists
ZRAM_SYS_DIR='/sys/class/zram-control'
if [ ! -d "${ZRAM_SYS_DIR}" ]; then
modprobe zram
# create /dev/zram0
# as /sys/class/zram-control/hot_add = 1
fi
Next zram device = /dev/zram${hot_add}
Add/remove zram devices
zram provides a control interface, which enables dynamic (on-demand) device
addition and removal.
In order to add a new /dev/zramX device, perform read operation on hot_add
attribute. This will return either new device's device id (meaning that you
can use /dev/zram) or error code.
Example:
cat /sys/class/zram-control/hot_add
1
To remove the existing /dev/zramX device (where X is a device id)
execute
echo X > /sys/class/zram-control/hot_remove
New contributor
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f17254%2fhow-to-set-up-properly-zram-and-swap%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sidenote: because of per-cpu locking, it is important to have as many zram-swaps as CPUs (modprobe zram_num_devices=n zram) instead of a single big one. RTFM!
1
[citation needed]? I cannot find the recomendation in Linux documentation or Google.
– Maciej Piechotka
Nov 28 '11 at 23:28
By defaultmax_comp_streams
seems to be1
according to documentation. I haven't checked if that parameter existed in 2011 but it seems to be a better option then multiple swap files.
– Maciej Piechotka
May 21 '15 at 19:27
Testing with the packagezram-config
under Ubuntu (and likely debian) I noted that the configuration defaults to 1 per core or thread (2 on an old E2140 dual core and 4 on an i3-3220)
– Elder Geek
Feb 29 '16 at 4:03
interesting, and this also seems quite clear to understand by reading /etc/init/zram-config.conf
– Aquarius Power
Nov 18 '16 at 19:44
add a comment |
Sidenote: because of per-cpu locking, it is important to have as many zram-swaps as CPUs (modprobe zram_num_devices=n zram) instead of a single big one. RTFM!
1
[citation needed]? I cannot find the recomendation in Linux documentation or Google.
– Maciej Piechotka
Nov 28 '11 at 23:28
By defaultmax_comp_streams
seems to be1
according to documentation. I haven't checked if that parameter existed in 2011 but it seems to be a better option then multiple swap files.
– Maciej Piechotka
May 21 '15 at 19:27
Testing with the packagezram-config
under Ubuntu (and likely debian) I noted that the configuration defaults to 1 per core or thread (2 on an old E2140 dual core and 4 on an i3-3220)
– Elder Geek
Feb 29 '16 at 4:03
interesting, and this also seems quite clear to understand by reading /etc/init/zram-config.conf
– Aquarius Power
Nov 18 '16 at 19:44
add a comment |
Sidenote: because of per-cpu locking, it is important to have as many zram-swaps as CPUs (modprobe zram_num_devices=n zram) instead of a single big one. RTFM!
Sidenote: because of per-cpu locking, it is important to have as many zram-swaps as CPUs (modprobe zram_num_devices=n zram) instead of a single big one. RTFM!
answered Nov 27 '11 at 17:59
eMPee584eMPee584
7111
7111
1
[citation needed]? I cannot find the recomendation in Linux documentation or Google.
– Maciej Piechotka
Nov 28 '11 at 23:28
By defaultmax_comp_streams
seems to be1
according to documentation. I haven't checked if that parameter existed in 2011 but it seems to be a better option then multiple swap files.
– Maciej Piechotka
May 21 '15 at 19:27
Testing with the packagezram-config
under Ubuntu (and likely debian) I noted that the configuration defaults to 1 per core or thread (2 on an old E2140 dual core and 4 on an i3-3220)
– Elder Geek
Feb 29 '16 at 4:03
interesting, and this also seems quite clear to understand by reading /etc/init/zram-config.conf
– Aquarius Power
Nov 18 '16 at 19:44
add a comment |
1
[citation needed]? I cannot find the recomendation in Linux documentation or Google.
– Maciej Piechotka
Nov 28 '11 at 23:28
By defaultmax_comp_streams
seems to be1
according to documentation. I haven't checked if that parameter existed in 2011 but it seems to be a better option then multiple swap files.
– Maciej Piechotka
May 21 '15 at 19:27
Testing with the packagezram-config
under Ubuntu (and likely debian) I noted that the configuration defaults to 1 per core or thread (2 on an old E2140 dual core and 4 on an i3-3220)
– Elder Geek
Feb 29 '16 at 4:03
interesting, and this also seems quite clear to understand by reading /etc/init/zram-config.conf
– Aquarius Power
Nov 18 '16 at 19:44
1
1
[citation needed]? I cannot find the recomendation in Linux documentation or Google.
– Maciej Piechotka
Nov 28 '11 at 23:28
[citation needed]? I cannot find the recomendation in Linux documentation or Google.
– Maciej Piechotka
Nov 28 '11 at 23:28
By default
max_comp_streams
seems to be 1
according to documentation. I haven't checked if that parameter existed in 2011 but it seems to be a better option then multiple swap files.– Maciej Piechotka
May 21 '15 at 19:27
By default
max_comp_streams
seems to be 1
according to documentation. I haven't checked if that parameter existed in 2011 but it seems to be a better option then multiple swap files.– Maciej Piechotka
May 21 '15 at 19:27
Testing with the package
zram-config
under Ubuntu (and likely debian) I noted that the configuration defaults to 1 per core or thread (2 on an old E2140 dual core and 4 on an i3-3220)– Elder Geek
Feb 29 '16 at 4:03
Testing with the package
zram-config
under Ubuntu (and likely debian) I noted that the configuration defaults to 1 per core or thread (2 on an old E2140 dual core and 4 on an i3-3220)– Elder Geek
Feb 29 '16 at 4:03
interesting, and this also seems quite clear to understand by reading /etc/init/zram-config.conf
– Aquarius Power
Nov 18 '16 at 19:44
interesting, and this also seems quite clear to understand by reading /etc/init/zram-config.conf
– Aquarius Power
Nov 18 '16 at 19:44
add a comment |
swapon
have -p
switch which sets the priority. I can set up:
swapon -p 32767 /dev/zram0
swapon -p 0 /dev/my-lvm-volume/swap
Or in /etc/fstab:
/dev/zram0 none swap sw,pri=32767 0 0
/dev/my-lvm-volume/swap none swap sw,pri=0 0 0
EDIT: Just for a full solution - such line may be helpful as udev rule:
KERNEL=="zram0", ACTION=="add", ATTR{disksize}="1073741824", RUN="/sbin/mkswap /$root/$name"
add a comment |
swapon
have -p
switch which sets the priority. I can set up:
swapon -p 32767 /dev/zram0
swapon -p 0 /dev/my-lvm-volume/swap
Or in /etc/fstab:
/dev/zram0 none swap sw,pri=32767 0 0
/dev/my-lvm-volume/swap none swap sw,pri=0 0 0
EDIT: Just for a full solution - such line may be helpful as udev rule:
KERNEL=="zram0", ACTION=="add", ATTR{disksize}="1073741824", RUN="/sbin/mkswap /$root/$name"
add a comment |
swapon
have -p
switch which sets the priority. I can set up:
swapon -p 32767 /dev/zram0
swapon -p 0 /dev/my-lvm-volume/swap
Or in /etc/fstab:
/dev/zram0 none swap sw,pri=32767 0 0
/dev/my-lvm-volume/swap none swap sw,pri=0 0 0
EDIT: Just for a full solution - such line may be helpful as udev rule:
KERNEL=="zram0", ACTION=="add", ATTR{disksize}="1073741824", RUN="/sbin/mkswap /$root/$name"
swapon
have -p
switch which sets the priority. I can set up:
swapon -p 32767 /dev/zram0
swapon -p 0 /dev/my-lvm-volume/swap
Or in /etc/fstab:
/dev/zram0 none swap sw,pri=32767 0 0
/dev/my-lvm-volume/swap none swap sw,pri=0 0 0
EDIT: Just for a full solution - such line may be helpful as udev rule:
KERNEL=="zram0", ACTION=="add", ATTR{disksize}="1073741824", RUN="/sbin/mkswap /$root/$name"
edited Jul 26 '11 at 1:33
answered Jul 23 '11 at 13:26
Maciej PiechotkaMaciej Piechotka
11.3k74278
11.3k74278
add a comment |
add a comment |
Select how many zram devices do you want by passing
zram.num_devices=4
to kernel parameters or directly to module (without zram.) . Default value is 1. zram will be able utilize as many cpus as number of devices you create.
Prepare zram0 device, set size to 1GB.
echo 1000000000 > /sys/block/zram0/disksize
Alternatively you can do it by udev rule.
Create swap on zram0
mkswap /dev/zram0
and enable it with higher priority than other swap devices
swapon -p 32767 /dev/zram0
What kernel and distro versions are you writing for here ?
– Cbhihe
Aug 29 '16 at 15:23
For the record, proceeding as you advise on a 14.04.5 desktop Ubuntu, fails. In particular, when I try to set the priorities ofzram0
andzram1
to value 10 on a 2 nuclei Intel T9300 box, it throws me with:swapon: /dev/zram0 or 1: swapon failed: Device or resource busy
.
– Cbhihe
Aug 29 '16 at 15:26
add a comment |
Select how many zram devices do you want by passing
zram.num_devices=4
to kernel parameters or directly to module (without zram.) . Default value is 1. zram will be able utilize as many cpus as number of devices you create.
Prepare zram0 device, set size to 1GB.
echo 1000000000 > /sys/block/zram0/disksize
Alternatively you can do it by udev rule.
Create swap on zram0
mkswap /dev/zram0
and enable it with higher priority than other swap devices
swapon -p 32767 /dev/zram0
What kernel and distro versions are you writing for here ?
– Cbhihe
Aug 29 '16 at 15:23
For the record, proceeding as you advise on a 14.04.5 desktop Ubuntu, fails. In particular, when I try to set the priorities ofzram0
andzram1
to value 10 on a 2 nuclei Intel T9300 box, it throws me with:swapon: /dev/zram0 or 1: swapon failed: Device or resource busy
.
– Cbhihe
Aug 29 '16 at 15:26
add a comment |
Select how many zram devices do you want by passing
zram.num_devices=4
to kernel parameters or directly to module (without zram.) . Default value is 1. zram will be able utilize as many cpus as number of devices you create.
Prepare zram0 device, set size to 1GB.
echo 1000000000 > /sys/block/zram0/disksize
Alternatively you can do it by udev rule.
Create swap on zram0
mkswap /dev/zram0
and enable it with higher priority than other swap devices
swapon -p 32767 /dev/zram0
Select how many zram devices do you want by passing
zram.num_devices=4
to kernel parameters or directly to module (without zram.) . Default value is 1. zram will be able utilize as many cpus as number of devices you create.
Prepare zram0 device, set size to 1GB.
echo 1000000000 > /sys/block/zram0/disksize
Alternatively you can do it by udev rule.
Create swap on zram0
mkswap /dev/zram0
and enable it with higher priority than other swap devices
swapon -p 32767 /dev/zram0
answered Jun 3 '14 at 16:25
okiasokias
111
111
What kernel and distro versions are you writing for here ?
– Cbhihe
Aug 29 '16 at 15:23
For the record, proceeding as you advise on a 14.04.5 desktop Ubuntu, fails. In particular, when I try to set the priorities ofzram0
andzram1
to value 10 on a 2 nuclei Intel T9300 box, it throws me with:swapon: /dev/zram0 or 1: swapon failed: Device or resource busy
.
– Cbhihe
Aug 29 '16 at 15:26
add a comment |
What kernel and distro versions are you writing for here ?
– Cbhihe
Aug 29 '16 at 15:23
For the record, proceeding as you advise on a 14.04.5 desktop Ubuntu, fails. In particular, when I try to set the priorities ofzram0
andzram1
to value 10 on a 2 nuclei Intel T9300 box, it throws me with:swapon: /dev/zram0 or 1: swapon failed: Device or resource busy
.
– Cbhihe
Aug 29 '16 at 15:26
What kernel and distro versions are you writing for here ?
– Cbhihe
Aug 29 '16 at 15:23
What kernel and distro versions are you writing for here ?
– Cbhihe
Aug 29 '16 at 15:23
For the record, proceeding as you advise on a 14.04.5 desktop Ubuntu, fails. In particular, when I try to set the priorities of
zram0
and zram1
to value 10 on a 2 nuclei Intel T9300 box, it throws me with: swapon: /dev/zram0 or 1: swapon failed: Device or resource busy
.– Cbhihe
Aug 29 '16 at 15:26
For the record, proceeding as you advise on a 14.04.5 desktop Ubuntu, fails. In particular, when I try to set the priorities of
zram0
and zram1
to value 10 on a 2 nuclei Intel T9300 box, it throws me with: swapon: /dev/zram0 or 1: swapon failed: Device or resource busy
.– Cbhihe
Aug 29 '16 at 15:26
add a comment |
When you enable zram, it will automatically have priority.
For ubuntu 16.04: /usr/bin/init-zram-swapping
You can edit that file (make a backup 1st), to lower the used real ram, I changed the mem line to this:
mem=$(((totalmem / 4 / ${NRDEVICES}) * 1024))
add a comment |
When you enable zram, it will automatically have priority.
For ubuntu 16.04: /usr/bin/init-zram-swapping
You can edit that file (make a backup 1st), to lower the used real ram, I changed the mem line to this:
mem=$(((totalmem / 4 / ${NRDEVICES}) * 1024))
add a comment |
When you enable zram, it will automatically have priority.
For ubuntu 16.04: /usr/bin/init-zram-swapping
You can edit that file (make a backup 1st), to lower the used real ram, I changed the mem line to this:
mem=$(((totalmem / 4 / ${NRDEVICES}) * 1024))
When you enable zram, it will automatically have priority.
For ubuntu 16.04: /usr/bin/init-zram-swapping
You can edit that file (make a backup 1st), to lower the used real ram, I changed the mem line to this:
mem=$(((totalmem / 4 / ${NRDEVICES}) * 1024))
edited Jun 19 '17 at 15:21
Stephen Rauch
3,346101428
3,346101428
answered Jun 19 '17 at 14:59
VeganEyeVeganEye
1
1
add a comment |
add a comment |
For some reason there seems to be a lot of misinterpretation of https://www.kernel.org/doc/Documentation/blockdev/zram.txt
It clearly states
"2) Set max number of compression streams
Regardless the value passed to this attribute, ZRAM will always
allocate multiple compression streams - one per online CPUs - thus
allowing several concurrent compression operations. The number of
allocated compression streams goes down when some of the CPUs
become offline. There is no single-compression-stream mode anymore,
unless you are running a UP system or has only 1 CPU online.
To find out how many streams are currently available:
cat /sys/block/zram0/max_comp_streams"
But repetitively there is a common urban myth max streams is 1.
Its plainly not true.
The two OS where zram has proven effective Chrome OS & Android you a single device.
Also they tweak page-cluster
page-cluster controls the number of pages up to which consecutive pages
are read in from swap in a single attempt. This is the swap counterpart
to page cache readahead.
The mentioned consecutivity is not in terms of virtual/physical addresses,
but consecutive on swap space - that means they were swapped out together.
It is a logarithmic value - setting it to zero means "1 page", setting
it to 1 means "2 pages", setting it to 2 means "4 pages", etc.
Zero disables swap readahead completely.
The default value is three (eight pages at a time). There may be some
small benefits in tuning this to a different value if your workload is
swap-intensive.
Lower values mean lower latencies for initial faults, but at the same time
extra faults and I/O delays for following faults if they would have been part of
that consecutive pages readahead would have brought in.
echo "0" > /proc/sys/vm/page-cluster to force single page
Much seems to originate from zram_config the debian/ubuntu package that for some reason seems to have very little correlation with the kernel documents for zram and has bred a series of Chinese whispers that in essence could be completely wrong.
With file swap do you create a swap drive for each core? Maybe that might answer your questions.
Also to back this up Googles Chrome OS & Android which successfully with the above page-cluster as its not matching a disk so latency can be improved.
Also "num_devices parameter is optional and tells zram how many devices should be pre-created. Default: 1"
All you need to do is check if the zram sys class exists
ZRAM_SYS_DIR='/sys/class/zram-control'
if [ ! -d "${ZRAM_SYS_DIR}" ]; then
modprobe zram
# create /dev/zram0
# as /sys/class/zram-control/hot_add = 1
fi
Next zram device = /dev/zram${hot_add}
Add/remove zram devices
zram provides a control interface, which enables dynamic (on-demand) device
addition and removal.
In order to add a new /dev/zramX device, perform read operation on hot_add
attribute. This will return either new device's device id (meaning that you
can use /dev/zram) or error code.
Example:
cat /sys/class/zram-control/hot_add
1
To remove the existing /dev/zramX device (where X is a device id)
execute
echo X > /sys/class/zram-control/hot_remove
New contributor
add a comment |
For some reason there seems to be a lot of misinterpretation of https://www.kernel.org/doc/Documentation/blockdev/zram.txt
It clearly states
"2) Set max number of compression streams
Regardless the value passed to this attribute, ZRAM will always
allocate multiple compression streams - one per online CPUs - thus
allowing several concurrent compression operations. The number of
allocated compression streams goes down when some of the CPUs
become offline. There is no single-compression-stream mode anymore,
unless you are running a UP system or has only 1 CPU online.
To find out how many streams are currently available:
cat /sys/block/zram0/max_comp_streams"
But repetitively there is a common urban myth max streams is 1.
Its plainly not true.
The two OS where zram has proven effective Chrome OS & Android you a single device.
Also they tweak page-cluster
page-cluster controls the number of pages up to which consecutive pages
are read in from swap in a single attempt. This is the swap counterpart
to page cache readahead.
The mentioned consecutivity is not in terms of virtual/physical addresses,
but consecutive on swap space - that means they were swapped out together.
It is a logarithmic value - setting it to zero means "1 page", setting
it to 1 means "2 pages", setting it to 2 means "4 pages", etc.
Zero disables swap readahead completely.
The default value is three (eight pages at a time). There may be some
small benefits in tuning this to a different value if your workload is
swap-intensive.
Lower values mean lower latencies for initial faults, but at the same time
extra faults and I/O delays for following faults if they would have been part of
that consecutive pages readahead would have brought in.
echo "0" > /proc/sys/vm/page-cluster to force single page
Much seems to originate from zram_config the debian/ubuntu package that for some reason seems to have very little correlation with the kernel documents for zram and has bred a series of Chinese whispers that in essence could be completely wrong.
With file swap do you create a swap drive for each core? Maybe that might answer your questions.
Also to back this up Googles Chrome OS & Android which successfully with the above page-cluster as its not matching a disk so latency can be improved.
Also "num_devices parameter is optional and tells zram how many devices should be pre-created. Default: 1"
All you need to do is check if the zram sys class exists
ZRAM_SYS_DIR='/sys/class/zram-control'
if [ ! -d "${ZRAM_SYS_DIR}" ]; then
modprobe zram
# create /dev/zram0
# as /sys/class/zram-control/hot_add = 1
fi
Next zram device = /dev/zram${hot_add}
Add/remove zram devices
zram provides a control interface, which enables dynamic (on-demand) device
addition and removal.
In order to add a new /dev/zramX device, perform read operation on hot_add
attribute. This will return either new device's device id (meaning that you
can use /dev/zram) or error code.
Example:
cat /sys/class/zram-control/hot_add
1
To remove the existing /dev/zramX device (where X is a device id)
execute
echo X > /sys/class/zram-control/hot_remove
New contributor
add a comment |
For some reason there seems to be a lot of misinterpretation of https://www.kernel.org/doc/Documentation/blockdev/zram.txt
It clearly states
"2) Set max number of compression streams
Regardless the value passed to this attribute, ZRAM will always
allocate multiple compression streams - one per online CPUs - thus
allowing several concurrent compression operations. The number of
allocated compression streams goes down when some of the CPUs
become offline. There is no single-compression-stream mode anymore,
unless you are running a UP system or has only 1 CPU online.
To find out how many streams are currently available:
cat /sys/block/zram0/max_comp_streams"
But repetitively there is a common urban myth max streams is 1.
Its plainly not true.
The two OS where zram has proven effective Chrome OS & Android you a single device.
Also they tweak page-cluster
page-cluster controls the number of pages up to which consecutive pages
are read in from swap in a single attempt. This is the swap counterpart
to page cache readahead.
The mentioned consecutivity is not in terms of virtual/physical addresses,
but consecutive on swap space - that means they were swapped out together.
It is a logarithmic value - setting it to zero means "1 page", setting
it to 1 means "2 pages", setting it to 2 means "4 pages", etc.
Zero disables swap readahead completely.
The default value is three (eight pages at a time). There may be some
small benefits in tuning this to a different value if your workload is
swap-intensive.
Lower values mean lower latencies for initial faults, but at the same time
extra faults and I/O delays for following faults if they would have been part of
that consecutive pages readahead would have brought in.
echo "0" > /proc/sys/vm/page-cluster to force single page
Much seems to originate from zram_config the debian/ubuntu package that for some reason seems to have very little correlation with the kernel documents for zram and has bred a series of Chinese whispers that in essence could be completely wrong.
With file swap do you create a swap drive for each core? Maybe that might answer your questions.
Also to back this up Googles Chrome OS & Android which successfully with the above page-cluster as its not matching a disk so latency can be improved.
Also "num_devices parameter is optional and tells zram how many devices should be pre-created. Default: 1"
All you need to do is check if the zram sys class exists
ZRAM_SYS_DIR='/sys/class/zram-control'
if [ ! -d "${ZRAM_SYS_DIR}" ]; then
modprobe zram
# create /dev/zram0
# as /sys/class/zram-control/hot_add = 1
fi
Next zram device = /dev/zram${hot_add}
Add/remove zram devices
zram provides a control interface, which enables dynamic (on-demand) device
addition and removal.
In order to add a new /dev/zramX device, perform read operation on hot_add
attribute. This will return either new device's device id (meaning that you
can use /dev/zram) or error code.
Example:
cat /sys/class/zram-control/hot_add
1
To remove the existing /dev/zramX device (where X is a device id)
execute
echo X > /sys/class/zram-control/hot_remove
New contributor
For some reason there seems to be a lot of misinterpretation of https://www.kernel.org/doc/Documentation/blockdev/zram.txt
It clearly states
"2) Set max number of compression streams
Regardless the value passed to this attribute, ZRAM will always
allocate multiple compression streams - one per online CPUs - thus
allowing several concurrent compression operations. The number of
allocated compression streams goes down when some of the CPUs
become offline. There is no single-compression-stream mode anymore,
unless you are running a UP system or has only 1 CPU online.
To find out how many streams are currently available:
cat /sys/block/zram0/max_comp_streams"
But repetitively there is a common urban myth max streams is 1.
Its plainly not true.
The two OS where zram has proven effective Chrome OS & Android you a single device.
Also they tweak page-cluster
page-cluster controls the number of pages up to which consecutive pages
are read in from swap in a single attempt. This is the swap counterpart
to page cache readahead.
The mentioned consecutivity is not in terms of virtual/physical addresses,
but consecutive on swap space - that means they were swapped out together.
It is a logarithmic value - setting it to zero means "1 page", setting
it to 1 means "2 pages", setting it to 2 means "4 pages", etc.
Zero disables swap readahead completely.
The default value is three (eight pages at a time). There may be some
small benefits in tuning this to a different value if your workload is
swap-intensive.
Lower values mean lower latencies for initial faults, but at the same time
extra faults and I/O delays for following faults if they would have been part of
that consecutive pages readahead would have brought in.
echo "0" > /proc/sys/vm/page-cluster to force single page
Much seems to originate from zram_config the debian/ubuntu package that for some reason seems to have very little correlation with the kernel documents for zram and has bred a series of Chinese whispers that in essence could be completely wrong.
With file swap do you create a swap drive for each core? Maybe that might answer your questions.
Also to back this up Googles Chrome OS & Android which successfully with the above page-cluster as its not matching a disk so latency can be improved.
Also "num_devices parameter is optional and tells zram how many devices should be pre-created. Default: 1"
All you need to do is check if the zram sys class exists
ZRAM_SYS_DIR='/sys/class/zram-control'
if [ ! -d "${ZRAM_SYS_DIR}" ]; then
modprobe zram
# create /dev/zram0
# as /sys/class/zram-control/hot_add = 1
fi
Next zram device = /dev/zram${hot_add}
Add/remove zram devices
zram provides a control interface, which enables dynamic (on-demand) device
addition and removal.
In order to add a new /dev/zramX device, perform read operation on hot_add
attribute. This will return either new device's device id (meaning that you
can use /dev/zram) or error code.
Example:
cat /sys/class/zram-control/hot_add
1
To remove the existing /dev/zramX device (where X is a device id)
execute
echo X > /sys/class/zram-control/hot_remove
New contributor
edited 1 hour ago
New contributor
answered 1 hour ago
Stuart NaylorStuart Naylor
11
11
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f17254%2fhow-to-set-up-properly-zram-and-swap%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown