sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget-/translations/zh_CN/admin-guide/blockdev/zrammodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget-/translations/zh_TW/admin-guide/blockdev/zrammodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget-/translations/it_IT/admin-guide/blockdev/zrammodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget-/translations/ja_JP/admin-guide/blockdev/zrammodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget-/translations/ko_KR/admin-guide/blockdev/zrammodnameN classnameN refexplicituh1hhh ubh)}(hhh]hPortuguese (Brazilian)}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget-/translations/pt_BR/admin-guide/blockdev/zrammodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget-/translations/sp_SP/admin-guide/blockdev/zrammodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhsection)}(hhh](htitle)}(h(zram: Compressed RAM-based block devicesh]h(zram: Compressed RAM-based block devices}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhG/var/lib/git/docbuild/linux/Documentation/admin-guide/blockdev/zram.rsthKubh)}(hhh](h)}(h Introductionh]h Introduction}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh paragraph)}(hXjThe zram module creates RAM-based block devices named /dev/zram ( = 0, 1, ...). Pages written to these disks are compressed and stored in memory itself. These disks allow very fast I/O and compression provides good amounts of memory savings. Some of the use cases include /tmp storage, use as swap disks, various caches under /var and maybe many more. :)h]hXjThe zram module creates RAM-based block devices named /dev/zram ( = 0, 1, ...). Pages written to these disks are compressed and stored in memory itself. These disks allow very fast I/O and compression provides good amounts of memory savings. Some of the use cases include /tmp storage, use as swap disks, various caches under /var and maybe many more. :)}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(h_Statistics for individual zram devices are exported through sysfs nodes at /sys/block/zram/h]h_Statistics for individual zram devices are exported through sysfs nodes at /sys/block/zram/}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubeh}(h] introductionah ]h"] introductionah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hUsageh]hUsage}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(h?There are several ways to configure and manage zram device(-s):h]h?There are several ways to configure and manage zram device(-s):}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubhenumerated_list)}(hhh](h list_item)}(h,using zram and zram_control sysfs attributesh]h)}(hj*h]h,using zram and zram_control sysfs attributes}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj(ubah}(h]h ]h"]h$]h&]uh1j&hj#hhhhhNubj')}(hLusing zramctl utility, provided by util-linux (util-linux@vger.kernel.org). h]h)}(hKusing zramctl utility, provided by util-linux (util-linux@vger.kernel.org).h](h/using zramctl utility, provided by util-linux (}(hjChhhNhNubh reference)}(hutil-linux@vger.kernel.orgh]hutil-linux@vger.kernel.org}(hjMhhhNhNubah}(h]h ]h"]h$]h&]refuri!mailto:util-linux@vger.kernel.orguh1jKhjCubh).}(hjChhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj?ubah}(h]h ]h"]h$]h&]uh1j&hj#hhhhhNubeh}(h]h ]h"]h$]h&]enumtype loweralphaprefixhsuffix)uh1j!hjhhhhhKubh)}(hvIn this document we will describe only 'manual' zram configuration steps, IOW, zram and zram_control sysfs attributes.h]hzIn this document we will describe only ‘manual’ zram configuration steps, IOW, zram and zram_control sysfs attributes.}(hjxhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hXIn order to get a better idea about zramctl please consult util-linux documentation, zramctl man-page or `zramctl --help`. Please be informed that zram maintainers do not develop/maintain util-linux or zramctl, should you have any questions please contact util-linux@vger.kernel.orgh](hiIn order to get a better idea about zramctl please consult util-linux documentation, zramctl man-page or }(hjhhhNhNubhtitle_reference)}(h`zramctl --help`h]hzramctl --help}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh. Please be informed that zram maintainers do not develop/maintain util-linux or zramctl, should you have any questions please contact }(hjhhhNhNubjL)}(hutil-linux@vger.kernel.orgh]hutil-linux@vger.kernel.org}(hjhhhNhNubah}(h]h ]h"]h$]h&]refuri!mailto:util-linux@vger.kernel.orguh1jKhjubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(h;Following shows a typical sequence of steps for using zram.h]h;Following shows a typical sequence of steps for using zram.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK!hjhhubeh}(h]usageah ]h"]usageah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hWARNINGh]hWARNING}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK$ubh)}(hFor the sake of simplicity we skip error checking parts in most of the examples below. However, it is your sole responsibility to handle errors.h]hFor the sake of simplicity we skip error checking parts in most of the examples below. However, it is your sole responsibility to handle errors.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK&hjhhubh)}(hizram sysfs attributes always return negative values in case of errors. The list of possible return codes:h]hizram sysfs attributes always return negative values in case of errors. The list of possible return codes:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK)hjhhubhtable)}(hhh]htgroup)}(hhh](hcolspec)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jhjubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthK>uh1jhjubhtbody)}(hhh](hrow)}(hhh](hentry)}(hhh]h)}(h-EBUSYh]h-EBUSY}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK-hj'ubah}(h]h ]h"]h$]h&]uh1j%hj"ubj&)}(hhh]h)}(hyan attempt to modify an attribute that cannot be changed once the device has been initialised. Please reset device first.h]hyan attempt to modify an attribute that cannot be changed once the device has been initialised. Please reset device first.}(hjAhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK-hj>ubah}(h]h ]h"]h$]h&]uh1j%hj"ubeh}(h]h ]h"]h$]h&]uh1j hjubj!)}(hhh](j&)}(hhh]h)}(h-ENOMEMh]h-ENOMEM}(hjahhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK/hj^ubah}(h]h ]h"]h$]h&]uh1j%hj[ubj&)}(hhh]h)}(hAzram was not able to allocate enough memory to fulfil your needs.h]hAzram was not able to allocate enough memory to fulfil your needs.}(hjxhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK/hjuubah}(h]h ]h"]h$]h&]uh1j%hj[ubeh}(h]h ]h"]h$]h&]uh1j hjubj!)}(hhh](j&)}(hhh]h)}(h-EINVALh]h-EINVAL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK1hjubah}(h]h ]h"]h$]h&]uh1j%hjubj&)}(hhh]h)}(h invalid input has been provided.h]h invalid input has been provided.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK1hjubah}(h]h ]h"]h$]h&]uh1j%hjubeh}(h]h ]h"]h$]h&]uh1j hjubj!)}(hhh](j&)}(hhh]h)}(h-EAGAINh]h-EAGAIN}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK2hjubah}(h]h ]h"]h$]h&]uh1j%hjubj&)}(hhh]h)}(h]re-try operation later (e.g. when attempting to run recompress and writeback simultaneously).h]h]re-try operation later (e.g. when attempting to run recompress and writeback simultaneously).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK2hjubah}(h]h ]h"]h$]h&]uh1j%hjubeh}(h]h ]h"]h$]h&]uh1j hjubeh}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]colsKuh1jhjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubh)}(hjIf you use 'echo', the returned value is set by the 'echo' utility, and, in general case, something like::h]hqIf you use ‘echo’, the returned value is set by the ‘echo’ utility, and, in general case, something like:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK6hjhhubh literal_block)}(hXecho foo > /sys/block/zram0/comp_algorithm if [ $? -ne 0 ]; then handle_error fih]hXecho foo > /sys/block/zram0/comp_algorithm if [ $? -ne 0 ]; then handle_error fi}hj#sbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1j!hhhK9hjhhubh)}(hshould suffice.h]hshould suffice.}(hj3hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK>hjhhubeh}(h]warningah ]h"]warningah$]h&]uh1hhhhhhhhK$ubh)}(hhh](h)}(h Load Moduleh]h Load Module}(hjLhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjIhhhhhKAubj")}(hmodprobe zram num_devices=4h]hmodprobe zram num_devices=4}hjZsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhKEhjIhhubh)}(h*This creates 4 devices: /dev/zram{0,1,2,3}h]h*This creates 4 devices: /dev/zram{0,1,2,3}}(hjhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKGhjIhhubh)}(hdnum_devices parameter is optional and tells zram how many devices should be pre-created. Default: 1.h]hdnum_devices parameter is optional and tells zram how many devices should be pre-created. Default: 1.}(hjvhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKIhjIhhubeh}(h] load-moduleah ]h"] load moduleah$]h&]uh1hhhhhhhhKAubh)}(hhh](h)}(hSelect compression algorithmh]hSelect compression algorithm}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKMubh)}(hXUsing comp_algorithm device attribute one can see available and currently selected (shown in square brackets) compression algorithms, or change the selected compression algorithm (once the device is initialised there is no way to change compression algorithm).h]hXUsing comp_algorithm device attribute one can see available and currently selected (shown in square brackets) compression algorithms, or change the selected compression algorithm (once the device is initialised there is no way to change compression algorithm).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKOhjhhubh)}(h Examples::h]h Examples:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKThjhhubj")}(h#show supported compression algorithms cat /sys/block/zram0/comp_algorithm lzo [lz4] #select lzo compression algorithm echo lzo > /sys/block/zram0/comp_algorithmh]h#show supported compression algorithms cat /sys/block/zram0/comp_algorithm lzo [lz4] #select lzo compression algorithm echo lzo > /sys/block/zram0/comp_algorithm}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhKVhjhhubh)}(hnFor the time being, the `comp_algorithm` content shows only compression algorithms that are supported by zram.h](hFor the time being, the }(hjhhhNhNubj)}(h`comp_algorithm`h]hcomp_algorithm}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhF content shows only compression algorithms that are supported by zram.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK]hjhhubeh}(h]select-compression-algorithmah ]h"]select compression algorithmah$]h&]uh1hhhhhhhhKMubh)}(hhh](h)}(h.Set compression algorithm parameters: Optionalh]h.Set compression algorithm parameters: Optional}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKaubh)}(hCompression algorithms may support specific parameters which can be tweaked for particular dataset. ZRAM has an `algorithm_params` device attribute which provides a per-algorithm params configuration.h](hpCompression algorithms may support specific parameters which can be tweaked for particular dataset. ZRAM has an }(hjhhhNhNubj)}(h`algorithm_params`h]halgorithm_params}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhF device attribute which provides a per-algorithm params configuration.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKchjhhubh)}(hX[For example, several compression algorithms support `level` parameter. In addition, certain compression algorithms support pre-trained dictionaries, which significantly change algorithms' characteristics. In order to configure compression algorithm to use external pre-trained dictionary, pass full path to the `dict` along with other parameters::h](h4For example, several compression algorithms support }(hj hhhNhNubj)}(h`level`h]hlevel}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubh parameter. In addition, certain compression algorithms support pre-trained dictionaries, which significantly change algorithms’ characteristics. In order to configure compression algorithm to use external pre-trained dictionary, pass full path to the }(hj hhhNhNubj)}(h`dict`h]hdict}(hj:hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubh along with other parameters:}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKghjhhubj")}(hX#pass path to pre-trained zstd dictionary echo "algo=zstd dict=/etc/dictionary" > /sys/block/zram0/algorithm_params #pass path to pre-trained zstd dictionary and compression level echo "algo=zstd level=8 dict=/etc/dictionary" > \ /sys/block/zram0/algorithm_params #same, but using algorithm priority echo "algo=zstd priority=1" > /sys/block/zram0/recomp_algorithm echo "priority=1 dict=/etc/dictionary" > \ /sys/block/zram0/algorithm_paramsh]hX#pass path to pre-trained zstd dictionary echo "algo=zstd dict=/etc/dictionary" > /sys/block/zram0/algorithm_params #pass path to pre-trained zstd dictionary and compression level echo "algo=zstd level=8 dict=/etc/dictionary" > \ /sys/block/zram0/algorithm_params #same, but using algorithm priority echo "algo=zstd priority=1" > /sys/block/zram0/recomp_algorithm echo "priority=1 dict=/etc/dictionary" > \ /sys/block/zram0/algorithm_params}hjRsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhKmhjhhubh)}(hEach write to `algorithm_params` replaces the entire set of parameters of the corresponding algorithm, parameters that are not listed in the write are reset to their default values. Configure all of the parameters of an algorithm in one write::h](hEach write to }(hj`hhhNhNubj)}(h`algorithm_params`h]halgorithm_params}(hjhhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj`ubh replaces the entire set of parameters of the corresponding algorithm, parameters that are not listed in the write are reset to their default values. Configure all of the parameters of an algorithm in one write:}(hj`hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKyhjhhubj")}(hX*#WRONG: the second write resets level back to its default value echo "algo=zstd level=8" > /sys/block/zram0/algorithm_params echo "algo=zstd dict=/etc/dictionary" > /sys/block/zram0/algorithm_params #RIGHT echo "algo=zstd level=8 dict=/etc/dictionary" > \ /sys/block/zram0/algorithm_paramsh]hX*#WRONG: the second write resets level back to its default value echo "algo=zstd level=8" > /sys/block/zram0/algorithm_params echo "algo=zstd dict=/etc/dictionary" > /sys/block/zram0/algorithm_params #RIGHT echo "algo=zstd level=8 dict=/etc/dictionary" > \ /sys/block/zram0/algorithm_params}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhK~hjhhubh)}(hSelect the compression algorithm before configuring its parameters. The parameters of one algorithm are not necessarily valid for another one, so changing the algorithm of a particular priority resets that priority's parameters::h]hSelect the compression algorithm before configuring its parameters. The parameters of one algorithm are not necessarily valid for another one, so changing the algorithm of a particular priority resets that priority’s parameters:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj")}(hX#WRONG: comp_algorithm write resets the previously configured level echo "level=8" > /sys/block/zram0/algorithm_params echo zstd > /sys/block/zram0/comp_algorithm #RIGHT echo zstd > /sys/block/zram0/comp_algorithm echo "algo=zstd level=8" > /sys/block/zram0/algorithm_paramsh]hX#WRONG: comp_algorithm write resets the previously configured level echo "level=8" > /sys/block/zram0/algorithm_params echo zstd > /sys/block/zram0/comp_algorithm #RIGHT echo zstd > /sys/block/zram0/comp_algorithm echo "algo=zstd level=8" > /sys/block/zram0/algorithm_params}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhKhjhhubh)}(hXParameters are algorithm specific: not all algorithms support pre-trained dictionaries, not all algorithms support `level`. Furthermore, for certain algorithms `level` controls the compression level (the higher the value the better the compression ratio, it even can take negatives values for some algorithms), for other algorithms `level` is acceleration level (the higher the value the lower the compression ratio).h](hsParameters are algorithm specific: not all algorithms support pre-trained dictionaries, not all algorithms support }(hjhhhNhNubj)}(h`level`h]hlevel}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh&. Furthermore, for certain algorithms }(hjhhhNhNubj)}(h`level`h]hlevel}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh controls the compression level (the higher the value the better the compression ratio, it even can take negatives values for some algorithms), for other algorithms }(hjhhhNhNubj)}(h`level`h]hlevel}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhN is acceleration level (the higher the value the lower the compression ratio).}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hXParameters are handed over to the compression algorithm when the device is initialised, hence invalid parameters (or parameters that the selected algorithm does not support) are reported by the `disksize` write, and not by the `algorithm_params` write that has configured them.h](hParameters are handed over to the compression algorithm when the device is initialised, hence invalid parameters (or parameters that the selected algorithm does not support) are reported by the }(hjhhhNhNubj)}(h `disksize`h]hdisksize}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh write, and not by the }(hjhhhNhNubj)}(h`algorithm_params`h]halgorithm_params}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh write that has configured them.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]-set-compression-algorithm-parameters-optionalah ]h"].set compression algorithm parameters: optionalah$]h&]uh1hhhhhhhhKaubh)}(hhh](h)}(h Set Disksizeh]h Set Disksize}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj(hhhhhKubh)}(hSet disk size by writing the value to sysfs node 'disksize'. The value can be either in bytes or you can use mem suffixes. Examples::h]hSet disk size by writing the value to sysfs node ‘disksize’. The value can be either in bytes or you can use mem suffixes. Examples:}(hj9hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj(hhubj")}(h# Initialize /dev/zram0 with 50MB disksize echo $((50*1024*1024)) > /sys/block/zram0/disksize # Using mem suffixes echo 256K > /sys/block/zram0/disksize echo 512M > /sys/block/zram0/disksize echo 1G > /sys/block/zram0/disksizeh]h# Initialize /dev/zram0 with 50MB disksize echo $((50*1024*1024)) > /sys/block/zram0/disksize # Using mem suffixes echo 256K > /sys/block/zram0/disksize echo 512M > /sys/block/zram0/disksize echo 1G > /sys/block/zram0/disksize}hjGsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhKhj(hhubh)}(hNote: There is little point creating a zram of greater than twice the size of memory since we expect a 2:1 compression ratio. Note that zram uses about 0.1% of the size of the disk when not in use so a huge zram is wasteful.h]hNote: There is little point creating a zram of greater than twice the size of memory since we expect a 2:1 compression ratio. Note that zram uses about 0.1% of the size of the disk when not in use so a huge zram is wasteful.}(hjUhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj(hhubeh}(h] set-disksizeah ]h"] set disksizeah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hSet memory limit: Optionalh]hSet memory limit: Optional}(hjnhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjkhhhhhKubh)}(hSet memory limit by writing the value to sysfs node 'mem_limit'. The value can be either in bytes or you can use mem suffixes. In addition, you could change the value in runtime. Examples::h]hSet memory limit by writing the value to sysfs node ‘mem_limit’. The value can be either in bytes or you can use mem suffixes. In addition, you could change the value in runtime. Examples:}(hj|hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjkhhubj")}(hX# limit /dev/zram0 with 50MB memory echo $((50*1024*1024)) > /sys/block/zram0/mem_limit # Using mem suffixes echo 256K > /sys/block/zram0/mem_limit echo 512M > /sys/block/zram0/mem_limit echo 1G > /sys/block/zram0/mem_limit # To disable memory limit echo 0 > /sys/block/zram0/mem_limith]hX# limit /dev/zram0 with 50MB memory echo $((50*1024*1024)) > /sys/block/zram0/mem_limit # Using mem suffixes echo 256K > /sys/block/zram0/mem_limit echo 512M > /sys/block/zram0/mem_limit echo 1G > /sys/block/zram0/mem_limit # To disable memory limit echo 0 > /sys/block/zram0/mem_limit}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhKhjkhhubeh}(h]set-memory-limit-optionalah ]h"]set memory limit: optionalah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hActivateh]hActivate}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubj")}(hOmkswap /dev/zram0 swapon /dev/zram0 mkfs.ext4 /dev/zram1 mount /dev/zram1 /tmph]hOmkswap /dev/zram0 swapon /dev/zram0 mkfs.ext4 /dev/zram1 mount /dev/zram1 /tmp}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhKhjhhubeh}(h]activateah ]h"]activateah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hAdd/remove zram devicesh]hAdd/remove zram devices}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hazram provides a control interface, which enables dynamic (on-demand) device addition and removal.h]hazram provides a control interface, which enables dynamic (on-demand) device addition and removal.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hIn order to add a new /dev/zramX device, perform a read operation on the hot_add attribute. This will return either the new device's device id (meaning that you can use /dev/zram) or an error code.h]hIn order to add a new /dev/zramX device, perform a read operation on the hot_add attribute. This will return either the new device’s device id (meaning that you can use /dev/zram) or an error code.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(h Example::h]hExample:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj")}(h%cat /sys/class/zram-control/hot_add 1h]h%cat /sys/class/zram-control/hot_add 1}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhKhjhhubh)}(hKTo remove the existing /dev/zramX device (where X is a device id) execute::h]hJTo remove the existing /dev/zramX device (where X is a device id) execute:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj")}(h+echo X > /sys/class/zram-control/hot_removeh]h+echo X > /sys/class/zram-control/hot_remove}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhKhjhhubeh}(h]add-remove-zram-devicesah ]h"]add/remove zram devicesah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hStatsh]hStats}(hj7hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj4hhhhhKubh)}(hNPer-device statistics are exported as various nodes under /sys/block/zram/h]hNPer-device statistics are exported as various nodes under /sys/block/zram/}(hjEhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj4hhubh)}(hA brief description of exported device attributes follows. For more details please read Documentation/ABI/testing/sysfs-block-zram.h]hA brief description of exported device attributes follows. For more details please read Documentation/ABI/testing/sysfs-block-zram.}(hjShhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj4hhubj)}(hhh]j)}(hhh](j)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jhjdubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jhjdubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthK/uh1jhjdubhthead)}(hhh]j!)}(hhh](j&)}(hhh]h)}(hNameh]hName}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j%hjubj&)}(hhh]h)}(haccessh]haccess}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j%hjubj&)}(hhh]h)}(h descriptionh]h description}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j%hjubeh}(h]h ]h"]h$]h&]uh1j hjubah}(h]h ]h"]h$]h&]uh1jhjdubj)}(hhh](j!)}(hhh](j&)}(hhh]h)}(hdisksizeh]hdisksize}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j%hjubj&)}(hhh]h)}(hRWh]hRW}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j%hjubj&)}(hhh]h)}(h#show and set the device's disk sizeh]h%show and set the device’s disk size}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j%hjubeh}(h]h ]h"]h$]h&]uh1j hjubj!)}(hhh](j&)}(hhh]h)}(h initstateh]h initstate}(hj5hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj2ubah}(h]h ]h"]h$]h&]uh1j%hj/ubj&)}(hhh]h)}(hROh]hRO}(hjLhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjIubah}(h]h ]h"]h$]h&]uh1j%hj/ubj&)}(hhh]h)}(h,shows the initialization state of the deviceh]h,shows the initialization state of the device}(hjchhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj`ubah}(h]h ]h"]h$]h&]uh1j%hj/ubeh}(h]h ]h"]h$]h&]uh1j hjubj!)}(hhh](j&)}(hhh]h)}(hreseth]hreset}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j%hj}ubj&)}(hhh]h)}(hWOh]hWO}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j%hj}ubj&)}(hhh]h)}(htrigger device reseth]htrigger device reset}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j%hj}ubeh}(h]h ]h"]h$]h&]uh1j hjubj!)}(hhh](j&)}(hhh]h)}(h mem_used_maxh]h mem_used_max}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j%hjubj&)}(hhh]h)}(hWOh]hWO}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j%hjubj&)}(hhh]h)}(h,reset the `mem_used_max` counter (see later)h](h reset the }(hjhhhNhNubj)}(h`mem_used_max`h]h mem_used_max}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh counter (see later)}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j%hjubeh}(h]h ]h"]h$]h&]uh1j hjubj!)}(hhh](j&)}(hhh]h)}(h mem_limith]h mem_limit}(hj1hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj.ubah}(h]h ]h"]h$]h&]uh1j%hj+ubj&)}(hhh]h)}(hWOh]hWO}(hjHhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjEubah}(h]h ]h"]h$]h&]uh1j%hj+ubj&)}(hhh]h)}(hPspecifies the maximum amount of memory ZRAM can use to store the compressed datah]hPspecifies the maximum amount of memory ZRAM can use to store the compressed data}(hj_hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj\ubah}(h]h ]h"]h$]h&]uh1j%hj+ubeh}(h]h ]h"]h$]h&]uh1j hjubj!)}(hhh](j&)}(hhh]h)}(hwriteback_limith]hwriteback_limit}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj|ubah}(h]h ]h"]h$]h&]uh1j%hjyubj&)}(hhh]h)}(hWOh]hWO}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j%hjyubj&)}(hhh]h)}(hYspecifies the maximum amount of write IO zram can write out to backing device as 4KB unith]hYspecifies the maximum amount of write IO zram can write out to backing device as 4KB unit}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j%hjyubeh}(h]h ]h"]h$]h&]uh1j hjubj!)}(hhh](j&)}(hhh]h)}(hwriteback_limit_enableh]hwriteback_limit_enable}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j%hjubj&)}(hhh]h)}(hRWh]hRW}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j%hjubj&)}(hhh]h)}(h$show and set writeback_limit featureh]h$show and set writeback_limit feature}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j%hjubeh}(h]h ]h"]h$]h&]uh1j hjubj!)}(hhh](j&)}(hhh]h)}(hwriteback_batch_sizeh]hwriteback_batch_size}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1j%hj ubj&)}(hhh]h)}(hRWh]hRW}(hj2 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj/ ubah}(h]h ]h"]h$]h&]uh1j%hj ubj&)}(hhh]h)}(h=show and set maximum number of in-flight writeback operationsh]h=show and set maximum number of in-flight writeback operations}(hjI hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjF ubah}(h]h ]h"]h$]h&]uh1j%hj ubeh}(h]h ]h"]h$]h&]uh1j hjubj!)}(hhh](j&)}(hhh]h)}(hcompressed_writebackh]hcompressed_writeback}(hji hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjf ubah}(h]h ]h"]h$]h&]uh1j%hjc ubj&)}(hhh]h)}(hRWh]hRW}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj} ubah}(h]h ]h"]h$]h&]uh1j%hjc ubj&)}(hhh]h)}(h)show and set compressed writeback featureh]h)show and set compressed writeback feature}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1j%hjc ubeh}(h]h ]h"]h$]h&]uh1j hjubj!)}(hhh](j&)}(hhh]h)}(hcomp_algorithmh]hcomp_algorithm}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1j%hj ubj&)}(hhh]h)}(hRWh]hRW}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1j%hj ubj&)}(hhh]h)}(h)show and change the compression algorithmh]h)show and change the compression algorithm}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1j%hj ubeh}(h]h ]h"]h$]h&]uh1j hjubj!)}(hhh](j&)}(hhh]h)}(halgorithm_paramsh]halgorithm_params}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1j%hj ubj&)}(hhh]h)}(hWOh]hWO}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1j%hj ubj&)}(hhh]h)}(h&setup compression algorithm parametersh]h&setup compression algorithm parameters}(hj3 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj0 ubah}(h]h ]h"]h$]h&]uh1j%hj ubeh}(h]h ]h"]h$]h&]uh1j hjubj!)}(hhh](j&)}(hhh]h)}(hcompacth]hcompact}(hjS hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjP ubah}(h]h ]h"]h$]h&]uh1j%hjM ubj&)}(hhh]h)}(hWOh]hWO}(hjj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjg ubah}(h]h ]h"]h$]h&]uh1j%hjM ubj&)}(hhh]h)}(htrigger memory compactionh]htrigger memory compaction}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj~ ubah}(h]h ]h"]h$]h&]uh1j%hjM ubeh}(h]h ]h"]h$]h&]uh1j hjubj!)}(hhh](j&)}(hhh]h)}(h debug_stath]h debug_stat}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1j%hj ubj&)}(hhh]h)}(hROh]hRO}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1j%hj ubj&)}(hhh]h)}(h-this file is used for zram debugging purposesh]h-this file is used for zram debugging purposes}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1j%hj ubeh}(h]h ]h"]h$]h&]uh1j hjubj!)}(hhh](j&)}(hhh]h)}(h backing_devh]h backing_dev}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1j%hj ubj&)}(hhh]h)}(hRWh]hRW}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1j%hj ubj&)}(hhh]h)}(h,set up backend storage for zram to write outh]h,set up backend storage for zram to write out}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1j%hj ubeh}(h]h ]h"]h$]h&]uh1j hjubj!)}(hhh](j&)}(hhh]h)}(hidleh]hidle}(hj= hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj: ubah}(h]h ]h"]h$]h&]uh1j%hj7 ubj&)}(hhh]h)}(hWOh]hWO}(hjT hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjQ ubah}(h]h ]h"]h$]h&]uh1j%hj7 ubj&)}(hhh]h)}(hmark allocated slot as idleh]hmark allocated slot as idle}(hjk hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjh ubah}(h]h ]h"]h$]h&]uh1j%hj7 ubeh}(h]h ]h"]h$]h&]uh1j hjubeh}(h]h ]h"]h$]h&]uh1jhjdubeh}(h]h ]h"]h$]h&]colsKuh1jhjaubah}(h]h ]h"]h$]h&]uh1jhj4hhhhhNubh)}(hOUser space is advised to use the following files to read the device statistics.h]hOUser space is advised to use the following files to read the device statistics.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj4hhubh)}(hFile /sys/block/zram/stath]hFile /sys/block/zram/stat}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj4hhubh)}(hQRepresents block layer statistics. Read Documentation/block/stat.rst for details.h]hQRepresents block layer statistics. Read Documentation/block/stat.rst for details.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj4hhubh)}(h File /sys/block/zram/io_stath]h File /sys/block/zram/io_stat}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hj4hhubh)}(hThe stat file represents device's I/O statistics not accounted by block layer and, thus, not available in zram/stat file. It consists of a single line of text and contains the following stats separated by whitespace:h]hThe stat file represents device’s I/O statistics not accounted by block layer and, thus, not available in zram/stat file. It consists of a single line of text and contains the following stats separated by whitespace:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hj4hhubh block_quote)}(hX============= ============================================================= failed_reads The number of failed reads failed_writes The number of failed writes invalid_io The number of non-page-size-aligned I/O requests notify_free Depending on device usage scenario it may account a) the number of pages freed because of swap slot free notifications b) the number of pages freed because of REQ_OP_DISCARD requests sent by bio. The former ones are sent to a swap block device when a swap slot is freed, which implies that this disk is being used as a swap disk. The latter ones are sent by filesystem mounted with discard option, whenever some data blocks are getting discarded. ============= ============================================================= h]j)}(hhh]j)}(hhh](j)}(hhh]h}(h]h ]h"]h$]h&]colwidthK uh1jhj ubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthK=uh1jhj ubj)}(hhh](j!)}(hhh](j&)}(hhh]h)}(h failed_readsh]h failed_reads}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1j%hj ubj&)}(hhh]h)}(hThe number of failed readsh]hThe number of failed reads}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1j%hj ubeh}(h]h ]h"]h$]h&]uh1j hj ubj!)}(hhh](j&)}(hhh]h)}(h failed_writesh]h failed_writes}(hj> hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj; ubah}(h]h ]h"]h$]h&]uh1j%hj8 ubj&)}(hhh]h)}(hThe number of failed writesh]hThe number of failed writes}(hjU hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjR ubah}(h]h ]h"]h$]h&]uh1j%hj8 ubeh}(h]h ]h"]h$]h&]uh1j hj ubj!)}(hhh](j&)}(hhh]h)}(h invalid_ioh]h invalid_io}(hju hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjr ubah}(h]h ]h"]h$]h&]uh1j%hjo ubj&)}(hhh]h)}(h0The number of non-page-size-aligned I/O requestsh]h0The number of non-page-size-aligned I/O requests}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1j%hjo ubeh}(h]h ]h"]h$]h&]uh1j hj ubj!)}(hhh](j&)}(hhh]h)}(h notify_freeh]h notify_free}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1j%hj ubj&)}(hhh](h)}(h1Depending on device usage scenario it may accounth]h1Depending on device usage scenario it may account}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubj")}(hhh](j')}(hAthe number of pages freed because of swap slot free notificationsh]h)}(hAthe number of pages freed because of swap slot free notificationsh]hAthe number of pages freed because of swap slot free notifications}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1j&hj ubj')}(hthe number of pages freed because of REQ_OP_DISCARD requests sent by bio. The former ones are sent to a swap block device when a swap slot is freed, which implies that this disk is being used as a swap disk. h]h)}(hthe number of pages freed because of REQ_OP_DISCARD requests sent by bio. The former ones are sent to a swap block device when a swap slot is freed, which implies that this disk is being used as a swap disk.h]hthe number of pages freed because of REQ_OP_DISCARD requests sent by bio. The former ones are sent to a swap block device when a swap slot is freed, which implies that this disk is being used as a swap disk.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1j&hj ubeh}(h]h ]h"]h$]h&]jsjtjuhjvjwuh1j!hj ubh)}(htThe latter ones are sent by filesystem mounted with discard option, whenever some data blocks are getting discarded.h]htThe latter ones are sent by filesystem mounted with discard option, whenever some data blocks are getting discarded.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubeh}(h]h ]h"]h$]h&]uh1j%hj ubeh}(h]h ]h"]h$]h&]uh1j hj ubeh}(h]h ]h"]h$]h&]uh1jhj ubeh}(h]h ]h"]h$]h&]colsKuh1jhj ubah}(h]h ]h"]h$]h&]uh1jhj ubah}(h]h ]h"]h$]h&]uh1j hhhMhj4hhubh)}(h File /sys/block/zram/mm_stath]h File /sys/block/zram/mm_stat}(hj= hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM$hj4hhubh)}(hThe mm_stat file represents the device's mm statistics. It consists of a single line of text and contains the following stats separated by whitespace:h]hThe mm_stat file represents the device’s mm statistics. It consists of a single line of text and contains the following stats separated by whitespace:}(hjK hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM&hj4hhubj )}(hX================ ============================================================= orig_data_size uncompressed size of data stored in this disk. Unit: bytes compr_data_size compressed size of data stored in this disk mem_used_total the amount of memory allocated for this disk. This includes allocator fragmentation and metadata overhead, allocated for this disk. So, allocator space efficiency can be calculated using compr_data_size and this statistic. Unit: bytes mem_limit the maximum amount of memory ZRAM can use to store the compressed data mem_used_max the maximum amount of memory zram has consumed to store the data same_pages the number of same element filled pages written to this disk. No memory is allocated for such pages. pages_compacted the number of pages freed during compaction huge_pages the number of incompressible pages huge_pages_since the number of incompressible pages since zram set up ================ ============================================================= h]j)}(hhh]j)}(hhh](j)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jhj` ubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthK=uh1jhj` ubj)}(hhh](j!)}(hhh](j&)}(hhh]h)}(horig_data_sizeh]horig_data_size}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM*hj} ubah}(h]h ]h"]h$]h&]uh1j%hjz ubj&)}(hhh]h)}(h:uncompressed size of data stored in this disk. Unit: bytesh]h:uncompressed size of data stored in this disk. Unit: bytes}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM*hj ubah}(h]h ]h"]h$]h&]uh1j%hjz ubeh}(h]h ]h"]h$]h&]uh1j hjw ubj!)}(hhh](j&)}(hhh]h)}(hcompr_data_sizeh]hcompr_data_size}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM,hj ubah}(h]h ]h"]h$]h&]uh1j%hj ubj&)}(hhh]h)}(h+compressed size of data stored in this diskh]h+compressed size of data stored in this disk}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM,hj ubah}(h]h ]h"]h$]h&]uh1j%hj ubeh}(h]h ]h"]h$]h&]uh1j hjw ubj!)}(hhh](j&)}(hhh]h)}(hmem_used_totalh]hmem_used_total}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM-hj ubah}(h]h ]h"]h$]h&]uh1j%hj ubj&)}(hhh]h)}(hthe amount of memory allocated for this disk. This includes allocator fragmentation and metadata overhead, allocated for this disk. So, allocator space efficiency can be calculated using compr_data_size and this statistic. Unit: bytesh]hthe amount of memory allocated for this disk. This includes allocator fragmentation and metadata overhead, allocated for this disk. So, allocator space efficiency can be calculated using compr_data_size and this statistic. Unit: bytes}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM-hjubah}(h]h ]h"]h$]h&]uh1j%hj ubeh}(h]h ]h"]h$]h&]uh1j hjw ubj!)}(hhh](j&)}(hhh]h)}(h mem_limith]h mem_limit}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM2hj"ubah}(h]h ]h"]h$]h&]uh1j%hjubj&)}(hhh]h)}(hFthe maximum amount of memory ZRAM can use to store the compressed datah]hFthe maximum amount of memory ZRAM can use to store the compressed data}(hj<hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM2hj9ubah}(h]h ]h"]h$]h&]uh1j%hjubeh}(h]h ]h"]h$]h&]uh1j hjw ubj!)}(hhh](j&)}(hhh]h)}(h mem_used_maxh]h mem_used_max}(hj\hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM4hjYubah}(h]h ]h"]h$]h&]uh1j%hjVubj&)}(hhh]h)}(h@the maximum amount of memory zram has consumed to store the datah]h@the maximum amount of memory zram has consumed to store the data}(hjshhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM4hjpubah}(h]h ]h"]h$]h&]uh1j%hjVubeh}(h]h ]h"]h$]h&]uh1j hjw ubj!)}(hhh](j&)}(hhh]h)}(h same_pagesh]h same_pages}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM6hjubah}(h]h ]h"]h$]h&]uh1j%hjubj&)}(hhh]h)}(hdthe number of same element filled pages written to this disk. No memory is allocated for such pages.h]hdthe number of same element filled pages written to this disk. No memory is allocated for such pages.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM6hjubah}(h]h ]h"]h$]h&]uh1j%hjubeh}(h]h ]h"]h$]h&]uh1j hjw ubj!)}(hhh](j&)}(hhh]h)}(hpages_compactedh]hpages_compacted}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM8hjubah}(h]h ]h"]h$]h&]uh1j%hjubj&)}(hhh]h)}(h+the number of pages freed during compactionh]h+the number of pages freed during compaction}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM8hjubah}(h]h ]h"]h$]h&]uh1j%hjubeh}(h]h ]h"]h$]h&]uh1j hjw ubj!)}(hhh](j&)}(hhh]h)}(h huge_pagesh]h huge_pages}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM9hjubah}(h]h ]h"]h$]h&]uh1j%hjubj&)}(hhh]h)}(h"the number of incompressible pagesh]h"the number of incompressible pages}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM9hjubah}(h]h ]h"]h$]h&]uh1j%hjubeh}(h]h ]h"]h$]h&]uh1j hjw ubj!)}(hhh](j&)}(hhh]h)}(hhuge_pages_sinceh]hhuge_pages_since}(hj8hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM:hj5ubah}(h]h ]h"]h$]h&]uh1j%hj2ubj&)}(hhh]h)}(h4the number of incompressible pages since zram set uph]h4the number of incompressible pages since zram set up}(hjOhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM:hjLubah}(h]h ]h"]h$]h&]uh1j%hj2ubeh}(h]h ]h"]h$]h&]uh1j hjw ubeh}(h]h ]h"]h$]h&]uh1jhj` ubeh}(h]h ]h"]h$]h&]colsKuh1jhj] ubah}(h]h ]h"]h$]h&]uh1jhjY ubah}(h]h ]h"]h$]h&]uh1j hhhM)hj4hhubh)}(h File /sys/block/zram/bd_stath]h File /sys/block/zram/bd_stat}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM=hj4hhubh)}(hThe bd_stat file represents a device's backing device statistics. It consists of a single line of text and contains the following stats separated by whitespace:h]hThe bd_stat file represents a device’s backing device statistics. It consists of a single line of text and contains the following stats separated by whitespace:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM?hj4hhubj )}(hX============== ============================================================= bd_count size of data written in backing device. Unit: 4K bytes bd_reads the number of reads from backing device Unit: 4K bytes bd_writes the number of writes to backing device Unit: 4K bytes ============== ============================================================= h]j)}(hhh]j)}(hhh](j)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jhjubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthK=uh1jhjubj)}(hhh](j!)}(hhh](j&)}(hhh]h)}(hbd_counth]hbd_count}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMChjubah}(h]h ]h"]h$]h&]uh1j%hjubj&)}(hhh]h)}(h6size of data written in backing device. Unit: 4K bytesh]h6size of data written in backing device. Unit: 4K bytes}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMChjubah}(h]h ]h"]h$]h&]uh1j%hjubeh}(h]h ]h"]h$]h&]uh1j hjubj!)}(hhh](j&)}(hhh]h)}(hbd_readsh]hbd_reads}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMEhjubah}(h]h ]h"]h$]h&]uh1j%hjubj&)}(hhh]h)}(h6the number of reads from backing device Unit: 4K bytesh]h6the number of reads from backing device Unit: 4K bytes}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMEhjubah}(h]h ]h"]h$]h&]uh1j%hjubeh}(h]h ]h"]h$]h&]uh1j hjubj!)}(hhh](j&)}(hhh]h)}(h bd_writesh]h bd_writes}(hj3hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMGhj0ubah}(h]h ]h"]h$]h&]uh1j%hj-ubj&)}(hhh]h)}(h5the number of writes to backing device Unit: 4K bytesh]h5the number of writes to backing device Unit: 4K bytes}(hjJhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMGhjGubah}(h]h ]h"]h$]h&]uh1j%hj-ubeh}(h]h ]h"]h$]h&]uh1j hjubeh}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]colsKuh1jhjubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1j hhhMBhj4hhubeh}(h]statsah ]h"]statsah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h Deactivateh]h Deactivate}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMLubj")}(h$swapoff /dev/zram0 umount /dev/zram1h]h$swapoff /dev/zram0 umount /dev/zram1}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhMPhjhhubeh}(h] deactivateah ]h"] deactivateah$]h&]uh1hhhhhhhhMLubh)}(hhh](h)}(hReseth]hReset}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMTubj )}(hXWrite any positive value to 'reset' sysfs node:: echo 1 > /sys/block/zram0/reset echo 1 > /sys/block/zram1/reset This frees all the memory allocated for the given device and resets the disksize to zero. You must set the disksize again before reusing the device. h](h)}(h0Write any positive value to 'reset' sysfs node::h]h3Write any positive value to ‘reset’ sysfs node:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMVhjubj")}(h?echo 1 > /sys/block/zram0/reset echo 1 > /sys/block/zram1/reseth]h?echo 1 > /sys/block/zram0/reset echo 1 > /sys/block/zram1/reset}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhMXhjubh)}(hThis frees all the memory allocated for the given device and resets the disksize to zero. You must set the disksize again before reusing the device.h]hThis frees all the memory allocated for the given device and resets the disksize to zero. You must set the disksize again before reusing the device.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM[hjubeh}(h]h ]h"]h$]h&]uh1j hhhMVhjhhubeh}(h]resetah ]h"]resetah$]h&]uh1hhhhhhhhMTubh)}(hhh](h)}(hOptional Featureh]hOptional Feature}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhM`ubh)}(hhh](h)}(hIDLE pages trackingh]hIDLE pages tracking}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhMcubh)}(hzram has built-in support for idle pages tracking (that is, allocated but not used pages). This feature is useful for e.g. zram writeback and recompression. In order to mark pages as idle, execute the following command::h]hzram has built-in support for idle pages tracking (that is, allocated but not used pages). This feature is useful for e.g. zram writeback and recompression. In order to mark pages as idle, execute the following command:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMehj hhubj")}(h echo all > /sys/block/zramX/idleh]h echo all > /sys/block/zramX/idle}hj)sbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhMihj hhubh)}(hXDThis will mark all allocated zram pages as idle. The idle mark will be removed only when the page (block) is accessed (e.g. overwritten or freed). Additionally, when CONFIG_ZRAM_TRACK_ENTRY_ACTIME is enabled, pages can be marked as idle based on how many seconds have passed since the last access to a particular zram page::h]hXCThis will mark all allocated zram pages as idle. The idle mark will be removed only when the page (block) is accessed (e.g. overwritten or freed). Additionally, when CONFIG_ZRAM_TRACK_ENTRY_ACTIME is enabled, pages can be marked as idle based on how many seconds have passed since the last access to a particular zram page:}(hj7hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMkhj hhubj")}(h"echo 86400 > /sys/block/zramX/idleh]h"echo 86400 > /sys/block/zramX/idle}hjEsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhMqhj hhubh)}(hpIn this example, all pages which haven't been accessed in more than 86400 seconds (one day) will be marked idle.h]hrIn this example, all pages which haven’t been accessed in more than 86400 seconds (one day) will be marked idle.}(hjShhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMshj hhubeh}(h]idle-pages-trackingah ]h"]idle pages trackingah$]h&]uh1hhjhhhhhMcubh)}(hhh](h)}(h writebackh]h writeback}(hjlhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjihhhhhMwubh)}(hWith CONFIG_ZRAM_WRITEBACK, zram can write idle/incompressible page to backing storage rather than keeping it in memory. To use the feature, admin should set up backing device via::h]hWith CONFIG_ZRAM_WRITEBACK, zram can write idle/incompressible page to backing storage rather than keeping it in memory. To use the feature, admin should set up backing device via:}(hjzhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMyhjihhubj")}(h-echo /dev/sda5 > /sys/block/zramX/backing_devh]h-echo /dev/sda5 > /sys/block/zramX/backing_dev}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhM}hjihhubh)}(hbefore disksize setting. It supports only partitions at this moment. If admin wants to use incompressible page writeback, they could do it via::h]hbefore disksize setting. It supports only partitions at this moment. If admin wants to use incompressible page writeback, they could do it via:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjihhubj")}(h&echo huge > /sys/block/zramX/writebackh]h&echo huge > /sys/block/zramX/writeback}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhMhjihhubh)}(h?Admin can request writeback of idle pages at right timing via::h]h>Admin can request writeback of idle pages at right timing via:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjihhubj")}(h&echo idle > /sys/block/zramX/writebackh]h&echo idle > /sys/block/zramX/writeback}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhMhjihhubh)}(hLWith the command, zram will writeback idle pages from memory to the storage.h]hLWith the command, zram will writeback idle pages from memory to the storage.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjihhubh)}(hdAdditionally, if a user choose to writeback only huge and idle pages this can be accomplished with::h]hcAdditionally, if a user choose to writeback only huge and idle pages this can be accomplished with:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjihhubj")}(h+echo huge_idle > /sys/block/zramX/writebackh]h+echo huge_idle > /sys/block/zramX/writeback}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhMhjihhubh)}(hIf a user chooses to writeback only incompressible pages (pages that none of algorithms can compress) this can be accomplished with::h]hIf a user chooses to writeback only incompressible pages (pages that none of algorithms can compress) this can be accomplished with:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjihhubj")}(h0echo incompressible > /sys/block/zramX/writebackh]h0echo incompressible > /sys/block/zramX/writeback}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhMhjihhubh)}(hIf an admin wants to write a specific page in zram device to the backing device, they could write a page index into the interface::h]hIf an admin wants to write a specific page in zram device to the backing device, they could write a page index into the interface:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjihhubj")}(h3echo "page_index=1251" > /sys/block/zramX/writebackh]h3echo "page_index=1251" > /sys/block/zramX/writeback}hj"sbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhMhjihhubh)}(hXIn Linux 6.16 this interface underwent some rework. First, the interface now supports `key=value` format for all of its parameters (`type=huge_idle`, etc.) Second, the support for `page_indexes` was introduced, which specify `LOW-HIGH` range (or ranges) of pages to be written-back. This reduces the number of syscalls, but more importantly this enables optimal post-processing target selection strategy. Usage example::h](hWIn Linux 6.16 this interface underwent some rework. First, the interface now supports }(hj0hhhNhNubj)}(h `key=value`h]h key=value}(hj8hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj0ubh# format for all of its parameters (}(hj0hhhNhNubj)}(h`type=huge_idle`h]htype=huge_idle}(hjJhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj0ubh!, etc.) Second, the support for }(hj0hhhNhNubj)}(h`page_indexes`h]h page_indexes}(hj\hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj0ubh was introduced, which specify }(hj0hhhNhNubj)}(h `LOW-HIGH`h]hLOW-HIGH}(hjnhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj0ubh range (or ranges) of pages to be written-back. This reduces the number of syscalls, but more importantly this enables optimal post-processing target selection strategy. Usage example:}(hj0hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjihhubj")}(hecho "type=idle" > /sys/block/zramX/writeback echo "page_indexes=1-100 page_indexes=200-300" > \ /sys/block/zramX/writebackh]hecho "type=idle" > /sys/block/zramX/writeback echo "page_indexes=1-100 page_indexes=200-300" > \ /sys/block/zramX/writeback}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhMhjihhubh)}(hbWe also now permit multiple page_index params per call and a mix of single pages and page ranges::h]haWe also now permit multiple page_index params per call and a mix of single pages and page ranges:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjihhubj")}(hqecho page_index=42 page_index=99 page_indexes=100-200 \ page_indexes=500-700 > /sys/block/zramX/writebackh]hqecho page_index=42 page_index=99 page_indexes=100-200 \ page_indexes=500-700 > /sys/block/zramX/writeback}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhMhjihhubh)}(hIf there are lots of write IO with flash device, potentially, it has flash wearout problem so that admin needs to design write limitation to guarantee storage health for entire product life.dh]hIf there are lots of write IO with flash device, potentially, it has flash wearout problem so that admin needs to design write limitation to guarantee storage health for entire product life.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjihhubh)}(hTo overcome the concern, zram supports "writeback_limit" feature. The "writeback_limit_enable"'s default value is 0 so that it doesn't limit any writeback. IOW, if admin wants to apply writeback budget, they should enable writeback_limit_enable via::h]hXTo overcome the concern, zram supports “writeback_limit” feature. The “writeback_limit_enable“‘s default value is 0 so that it doesn’t limit any writeback. IOW, if admin wants to apply writeback budget, they should enable writeback_limit_enable via:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjihhubj")}(h2$ echo 1 > /sys/block/zramX/writeback_limit_enableh]h2$ echo 1 > /sys/block/zramX/writeback_limit_enable}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhMhjihhubh)}(hOnce writeback_limit_enable is set, zram doesn't allow any writeback until admin sets the budget via /sys/block/zramX/writeback_limit.h]hOnce writeback_limit_enable is set, zram doesn’t allow any writeback until admin sets the budget via /sys/block/zramX/writeback_limit.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjihhubh)}(h(If admin doesn't enable writeback_limit_enable, writeback_limit's value assigned via /sys/block/zramX/writeback_limit is meaningless.)h]h(If admin doesn’t enable writeback_limit_enable, writeback_limit’s value assigned via /sys/block/zramX/writeback_limit is meaningless.)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjihhubh)}(hPIf admin wants to limit writeback as per-day 400M, they could do it like below::h]hOIf admin wants to limit writeback as per-day 400M, they could do it like below:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjihhubj")}(h$ MB_SHIFT=20 $ 4K_SHIFT=12 $ echo $((400<>4K_SHIFT)) > \ /sys/block/zram0/writeback_limit. $ echo 1 > /sys/block/zram0/writeback_limit_enableh]h$ MB_SHIFT=20 $ 4K_SHIFT=12 $ echo $((400<>4K_SHIFT)) > \ /sys/block/zram0/writeback_limit. $ echo 1 > /sys/block/zram0/writeback_limit_enable}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhMhjihhubh)}(hgIf admins want to allow further write again once the budget is exhausted, they could do it like below::h]hfIf admins want to allow further write again once the budget is exhausted, they could do it like below:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjihhubj")}(hP$ echo $((400<>4K_SHIFT)) > \ /sys/block/zram0/writeback_limith]hP$ echo $((400<>4K_SHIFT)) > \ /sys/block/zram0/writeback_limit}hj sbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhMhjihhubh)}(hHIf an admin wants to see the remaining writeback budget since last set::h]hGIf an admin wants to see the remaining writeback budget since last set:}(hj.hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjihhubj")}(h&$ cat /sys/block/zramX/writeback_limith]h&$ cat /sys/block/zramX/writeback_limit}hj<sbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhMhjihhubh)}(h=If an admin wants to disable writeback limit, they could do::h]h /sys/block/zramX/writeback_limit_enableh]h2$ echo 0 > /sys/block/zramX/writeback_limit_enable}hjXsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhMhjihhubh)}(hThe writeback_limit count will reset whenever you reset zram (e.g., system reboot, echo 1 > /sys/block/zramX/reset) so keeping how many of writeback happened until you reset the zram to allocate extra writeback budget in next setting is user's job.h]hThe writeback_limit count will reset whenever you reset zram (e.g., system reboot, echo 1 > /sys/block/zramX/reset) so keeping how many of writeback happened until you reset the zram to allocate extra writeback budget in next setting is user’s job.}(hjfhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjihhubh)}(hXBy default zram stores written back pages in decompressed (raw) form, which means that writeback operation involves decompression of the page before writing it to the backing device. This behavior can be changed by enabling `compressed_writeback` feature, which causes zram to write compressed pages to the backing device, thus avoiding decompression overhead. To enable this feature, execute::h](hBy default zram stores written back pages in decompressed (raw) form, which means that writeback operation involves decompression of the page before writing it to the backing device. This behavior can be changed by enabling }(hjthhhNhNubj)}(h`compressed_writeback`h]hcompressed_writeback}(hj|hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjtubh feature, which causes zram to write compressed pages to the backing device, thus avoiding decompression overhead. To enable this feature, execute:}(hjthhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjihhubj")}(h2$ echo yes > /sys/block/zramX/compressed_writebackh]h2$ echo yes > /sys/block/zramX/compressed_writeback}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhMhjihhubh)}(hUNote that this feature should be configured before the `zramX` device is initialized.h](h7Note that this feature should be configured before the }(hjhhhNhNubj)}(h`zramX`h]hzramX}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh device is initialized.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjihhubh)}(hX0Depending on backing device storage type, writeback operation may benefit from a higher number of in-flight write requests (batched writes). The number of maximum in-flight writeback operations can be configured via `writeback_batch_size` attribute. To change the default value (which is 32), execute::h](hDepending on backing device storage type, writeback operation may benefit from a higher number of in-flight write requests (batched writes). The number of maximum in-flight writeback operations can be configured via }(hjhhhNhNubj)}(h`writeback_batch_size`h]hwriteback_batch_size}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh@ attribute. To change the default value (which is 32), execute:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjihhubj")}(h1$ echo 64 > /sys/block/zramX/writeback_batch_sizeh]h1$ echo 64 > /sys/block/zramX/writeback_batch_size}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhMhjihhubh)}(h|If admin wants to measure writeback count in a certain period, they could know it via /sys/block/zram0/bd_stat's 3rd column.h]h~If admin wants to measure writeback count in a certain period, they could know it via /sys/block/zram0/bd_stat’s 3rd column.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjihhubeh}(h] writebackah ]h"] writebackah$]h&]uh1hhjhhhhhMwubh)}(hhh](h)}(h recompressionh]h recompression}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hX[With `CONFIG_ZRAM_MULTI_COMP`, zram can recompress pages using alternative (secondary) compression algorithms. The basic idea is that alternative compression algorithm can provide better compression ratio at a price of (potentially) slower compression/decompression speeds. Alternative compression algorithm can, for example, be more successful compressing huge pages (those that default algorithm failed to compress). Another application is idle pages recompression - pages that are cold and sit in the memory can be recompressed using more effective algorithm and, hence, reduce zsmalloc memory usage.h](hWith }(hjhhhNhNubj)}(h`CONFIG_ZRAM_MULTI_COMP`h]hCONFIG_ZRAM_MULTI_COMP}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhX>, zram can recompress pages using alternative (secondary) compression algorithms. The basic idea is that alternative compression algorithm can provide better compression ratio at a price of (potentially) slower compression/decompression speeds. Alternative compression algorithm can, for example, be more successful compressing huge pages (those that default algorithm failed to compress). Another application is idle pages recompression - pages that are cold and sit in the memory can be recompressed using more effective algorithm and, hence, reduce zsmalloc memory usage.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hX With `CONFIG_ZRAM_MULTI_COMP`, zram supports up to 4 compression algorithms: one primary and up to 3 secondary ones. Primary zram compressor is explained in "3) Select compression algorithm", secondary algorithms are configured using recomp_algorithm device attribute.h](hWith }(hj7hhhNhNubj)}(h`CONFIG_ZRAM_MULTI_COMP`h]hCONFIG_ZRAM_MULTI_COMP}(hj?hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj7ubh, zram supports up to 4 compression algorithms: one primary and up to 3 secondary ones. Primary zram compressor is explained in “3) Select compression algorithm”, secondary algorithms are configured using recomp_algorithm device attribute.}(hj7hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(h Example:::h]h Example::}(hjWhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj")}(h#show supported recompression algorithms cat /sys/block/zramX/recomp_algorithm #1: lzo lzo-rle lz4 lz4hc [zstd] #2: lzo lzo-rle lz4 [lz4hc] zstdh]h#show supported recompression algorithms cat /sys/block/zramX/recomp_algorithm #1: lzo lzo-rle lz4 lz4hc [zstd] #2: lzo lzo-rle lz4 [lz4hc] zstd}hjesbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhMhjhhubh)}(hX<Alternative compression algorithms are sorted by priority. In the example above, zstd is used as the first alternative algorithm, which has priority of 1, while lz4hc is configured as a compression algorithm with priority 2. Alternative compression algorithm's priority is provided during algorithms configuration:::h]hX=Alternative compression algorithms are sorted by priority. In the example above, zstd is used as the first alternative algorithm, which has priority of 1, while lz4hc is configured as a compression algorithm with priority 2. Alternative compression algorithm’s priority is provided during algorithms configuration::}(hjshhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj")}(h#select zstd recompression algorithm, priority 1 echo "algo=zstd priority=1" > /sys/block/zramX/recomp_algorithm #select deflate recompression algorithm, priority 2 echo "algo=deflate priority=2" > /sys/block/zramX/recomp_algorithmh]h#select zstd recompression algorithm, priority 1 echo "algo=zstd priority=1" > /sys/block/zramX/recomp_algorithm #select deflate recompression algorithm, priority 2 echo "algo=deflate priority=2" > /sys/block/zramX/recomp_algorithm}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhM hjhhubh)}(hmAnother device attribute that `CONFIG_ZRAM_MULTI_COMP` enables is `recompress`, which controls recompression.h](hAnother device attribute that }(hjhhhNhNubj)}(h`CONFIG_ZRAM_MULTI_COMP`h]hCONFIG_ZRAM_MULTI_COMP}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh enables is }(hjhhhNhNubj)}(h `recompress`h]h recompress}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh, which controls recompression.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(h Examples:::h]h Examples::}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj")}(hX`#IDLE pages recompression is activated by `idle` mode echo "type=idle priority=1" > /sys/block/zramX/recompress #HUGE pages recompression is activated by `huge` mode echo "type=huge priority=2" > /sys/block/zram0/recompress #HUGE_IDLE pages recompression is activated by `huge_idle` mode echo "type=huge_idle priority=1" > /sys/block/zramX/recompressh]hX`#IDLE pages recompression is activated by `idle` mode echo "type=idle priority=1" > /sys/block/zramX/recompress #HUGE pages recompression is activated by `huge` mode echo "type=huge priority=2" > /sys/block/zram0/recompress #HUGE_IDLE pages recompression is activated by `huge_idle` mode echo "type=huge_idle priority=1" > /sys/block/zramX/recompress}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhMhjhhubh)}(hThe number of idle pages can be significant, so user-space can pass a size threshold (in bytes) to the recompress knob: zram will recompress only pages of equal or greater size:::h]hThe number of idle pages can be significant, so user-space can pass a size threshold (in bytes) to the recompress knob: zram will recompress only pages of equal or greater size::}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hjhhubj")}(h#recompress all pages larger than 3000 bytes echo "threshold=3000 priority=1" > /sys/block/zramX/recompress #recompress idle pages larger than 2000 bytes echo "type=idle threshold=2000 priority=1" > \ /sys/block/zramX/recompressh]h#recompress all pages larger than 3000 bytes echo "threshold=3000 priority=1" > /sys/block/zramX/recompress #recompress idle pages larger than 2000 bytes echo "type=idle threshold=2000 priority=1" > \ /sys/block/zramX/recompress}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhM$hjhhubh)}(hbIt is also possible to limit the number of pages zram re-compression will attempt to recompress:::h]haIt is also possible to limit the number of pages zram re-compression will attempt to recompress::}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM+hjhhubj")}(hUecho "type=huge_idle priority=1 max_pages=42" > \ /sys/block/zramX/recompressh]hUecho "type=huge_idle priority=1 max_pages=42" > \ /sys/block/zramX/recompress}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhM.hjhhubh)}(hXIt is advised to always specify `priority` parameter. While it is also possible to specify `algo` parameter, so that `zram` will use algorithm's name to determine the priority, it is not recommended, since it can lead to unexpected results when the same algorithm is configured with different priorities (e.g. different parameters). `priority` is the only way to guarantee that the expected algorithm will be used.h](h It is advised to always specify }(hjhhhNhNubj)}(h `priority`h]hpriority}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh2 parameter. While it is also possible to specify }(hjhhhNhNubj)}(h`algo`h]halgo}(hj/hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh parameter, so that }(hjhhhNhNubj)}(h`zram`h]hzram}(hjAhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh will use algorithm’s name to determine the priority, it is not recommended, since it can lead to unexpected results when the same algorithm is configured with different priorities (e.g. different parameters). }(hjhhhNhNubj)}(h `priority`h]hpriority}(hjShhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhG is the only way to guarantee that the expected algorithm will be used.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM1hjhhubeh}(h] recompressionah ]h"] recompressionah$]h&]uh1hhjhhhhhMubeh}(h]optional-featureah ]h"]optional featureah$]h&]uh1hhhhhhhhM`ubh)}(hhh](h)}(hmemory trackingh]hmemory tracking}(hj~hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj{hhhhhM9ubh)}(hWith CONFIG_ZRAM_MEMORY_TRACKING, user can know information of the zram block. It could be useful to catch cold or incompressible pages of the process with*pagemap.h]hWith CONFIG_ZRAM_MEMORY_TRACKING, user can know information of the zram block. It could be useful to catch cold or incompressible pages of the process with*pagemap.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM;hj{hhubh)}(h~If you enable the feature, you could see block state via /sys/kernel/debug/zram/zram0/block_state". The output is as follows::h]hIf you enable the feature, you could see block state via /sys/kernel/debug/zram/zram0/block_state”. The output is as follows:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM?hj{hhubj")}(hw300 75.033841 .wh... 301 63.806904 s..... 302 63.806919 ..hi.. 303 62.801919 ....r. 304 146.781902 ..hi.nh]hw300 75.033841 .wh... 301 63.806904 s..... 302 63.806919 ..hi.. 303 62.801919 ....r. 304 146.781902 ..hi.n}hjsbah}(h]h ]h"]h$]h&]j1j2uh1j!hhhMBhj{hhubhdefinition_list)}(hhh](hdefinition_list_item)}(h First column zram's block index.h](hterm)}(h First columnh]h First column}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhMHhjubh definition)}(hhh]h)}(hzram's block index.h]hzram’s block index.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMIhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhMHhjubj)}(h5Second column access time since the system was bootedh](j)}(h Second columnh]h Second column}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhMJhjubj)}(hhh]h)}(h'access time since the system was bootedh]h'access time since the system was booted}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMKhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhMJhjhhubj)}(hXThird column state of the block: s: same page w: written page to backing store h: huge page i: idle page r: recompressed page (secondary compression algorithm) n: none (including secondary) of algorithms could compress it h](j)}(h Third columnh]h Third column}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhMZhjubj)}(hhh](h)}(hstate of the block:h]hstate of the block:}(hj4hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMMhj1ubj)}(hhh](j)}(h s: same pageh](j)}(hs:h]hs:}(hjIhhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhMOhjEubj)}(hhh]h)}(h same pageh]h same page}(hjZhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMPhjWubah}(h]h ]h"]h$]h&]uh1jhjEubeh}(h]h ]h"]h$]h&]uh1jhhhMOhjBubj)}(h w: written page to backing storeh](j)}(hw:h]hw:}(hjxhhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhMQhjtubj)}(hhh]h)}(hwritten page to backing storeh]hwritten page to backing store}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMRhjubah}(h]h ]h"]h$]h&]uh1jhjtubeh}(h]h ]h"]h$]h&]uh1jhhhMQhjBubj)}(h h: huge pageh](j)}(hh:h]hh:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhMShjubj)}(hhh]h)}(h huge pageh]h huge page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMThjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhMShjBubj)}(h i: idle pageh](j)}(hi:h]hi:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhMUhjubj)}(hhh]h)}(h idle pageh]h idle page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMVhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhMUhjBubj)}(h6r: recompressed page (secondary compression algorithm)h](j)}(hr:h]hr:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhMWhjubj)}(hhh]h)}(h3recompressed page (secondary compression algorithm)h]h3recompressed page (secondary compression algorithm)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMXhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhMWhjBubj)}(h>n: none (including secondary) of algorithms could compress it h](j)}(hn:h]hn:}(hj4hhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhMZhj0ubj)}(hhh]h)}(h:none (including secondary) of algorithms could compress ith]h:none (including secondary) of algorithms could compress it}(hjEhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMZhjBubah}(h]h ]h"]h$]h&]uh1jhj0ubeh}(h]h ]h"]h$]h&]uh1jhhhMZhjBubeh}(h]h ]h"]h$]h&]uh1jhj1ubeh}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhMZhjhhubeh}(h]h ]h"]h$]h&]uh1jhj{hhhhhNubh)}(hFirst line of above example says 300th block is accessed at 75.033841sec and the block's state is huge so it is written back to the backing storage. It's a debugging feature so anyone shouldn't rely on it to work properly.h]hFirst line of above example says 300th block is accessed at 75.033841sec and the block’s state is huge so it is written back to the backing storage. It’s a debugging feature so anyone shouldn’t rely on it to work properly.}(hjwhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM\hj{hhubh)}(hNitin Gupta ngupta@vflare.orgh](h Nitin Gupta }(hjhhhNhNubjL)}(hngupta@vflare.orgh]hngupta@vflare.org}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurimailto:ngupta@vflare.orguh1jKhjubeh}(h]h ]h"]h$]h&]uh1hhhhMahj{hhubeh}(h]memory-trackingah ]h"]memory trackingah$]h&]uh1hhhhhhhhM9ubeh}(h]'zram-compressed-ram-based-block-devicesah ]h"](zram: compressed ram-based block devicesah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksj%footnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourcehʌ _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(jjhhjjjFjCjjjjj%j"jhjejjjjj1j.jjjjjjjxjujfjcjjjpjmjju nametypes}(jhjjFjjj%jhjjj1jjjjxjfjjpjuh}(jhhhjjjCjjjIjjj"jjej(jjkjjj.jjj4jjjjjujjcj jjijmjjj{u footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]transform_messages] transformerN include_log] decorationNhhub.