xref: /OK3568_Linux_fs/kernel/Documentation/admin-guide/blockdev/zram.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun========================================
2*4882a593Smuzhiyunzram: Compressed RAM-based block devices
3*4882a593Smuzhiyun========================================
4*4882a593Smuzhiyun
5*4882a593SmuzhiyunIntroduction
6*4882a593Smuzhiyun============
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunThe zram module creates RAM-based block devices named /dev/zram<id>
9*4882a593Smuzhiyun(<id> = 0, 1, ...). Pages written to these disks are compressed and stored
10*4882a593Smuzhiyunin memory itself. These disks allow very fast I/O and compression provides
11*4882a593Smuzhiyungood amounts of memory savings. Some of the use cases include /tmp storage,
12*4882a593Smuzhiyunuse as swap disks, various caches under /var and maybe many more. :)
13*4882a593Smuzhiyun
14*4882a593SmuzhiyunStatistics for individual zram devices are exported through sysfs nodes at
15*4882a593Smuzhiyun/sys/block/zram<id>/
16*4882a593Smuzhiyun
17*4882a593SmuzhiyunUsage
18*4882a593Smuzhiyun=====
19*4882a593Smuzhiyun
20*4882a593SmuzhiyunThere are several ways to configure and manage zram device(-s):
21*4882a593Smuzhiyun
22*4882a593Smuzhiyuna) using zram and zram_control sysfs attributes
23*4882a593Smuzhiyunb) using zramctl utility, provided by util-linux (util-linux@vger.kernel.org).
24*4882a593Smuzhiyun
25*4882a593SmuzhiyunIn this document we will describe only 'manual' zram configuration steps,
26*4882a593SmuzhiyunIOW, zram and zram_control sysfs attributes.
27*4882a593Smuzhiyun
28*4882a593SmuzhiyunIn order to get a better idea about zramctl please consult util-linux
29*4882a593Smuzhiyundocumentation, zramctl man-page or `zramctl --help`. Please be informed
30*4882a593Smuzhiyunthat zram maintainers do not develop/maintain util-linux or zramctl, should
31*4882a593Smuzhiyunyou have any questions please contact util-linux@vger.kernel.org
32*4882a593Smuzhiyun
33*4882a593SmuzhiyunFollowing shows a typical sequence of steps for using zram.
34*4882a593Smuzhiyun
35*4882a593SmuzhiyunWARNING
36*4882a593Smuzhiyun=======
37*4882a593Smuzhiyun
38*4882a593SmuzhiyunFor the sake of simplicity we skip error checking parts in most of the
39*4882a593Smuzhiyunexamples below. However, it is your sole responsibility to handle errors.
40*4882a593Smuzhiyun
41*4882a593Smuzhiyunzram sysfs attributes always return negative values in case of errors.
42*4882a593SmuzhiyunThe list of possible return codes:
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun========  =============================================================
45*4882a593Smuzhiyun-EBUSY	  an attempt to modify an attribute that cannot be changed once
46*4882a593Smuzhiyun	  the device has been initialised. Please reset device first.
47*4882a593Smuzhiyun-ENOMEM	  zram was not able to allocate enough memory to fulfil your
48*4882a593Smuzhiyun	  needs.
49*4882a593Smuzhiyun-EINVAL	  invalid input has been provided.
50*4882a593Smuzhiyun========  =============================================================
51*4882a593Smuzhiyun
52*4882a593SmuzhiyunIf you use 'echo', the returned value is set by the 'echo' utility,
53*4882a593Smuzhiyunand, in general case, something like::
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun	echo 3 > /sys/block/zram0/max_comp_streams
56*4882a593Smuzhiyun	if [ $? -ne 0 ]; then
57*4882a593Smuzhiyun		handle_error
58*4882a593Smuzhiyun	fi
59*4882a593Smuzhiyun
60*4882a593Smuzhiyunshould suffice.
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun1) Load Module
63*4882a593Smuzhiyun==============
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun::
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun	modprobe zram num_devices=4
68*4882a593Smuzhiyun
69*4882a593SmuzhiyunThis creates 4 devices: /dev/zram{0,1,2,3}
70*4882a593Smuzhiyun
71*4882a593Smuzhiyunnum_devices parameter is optional and tells zram how many devices should be
72*4882a593Smuzhiyunpre-created. Default: 1.
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun2) Set max number of compression streams
75*4882a593Smuzhiyun========================================
76*4882a593Smuzhiyun
77*4882a593SmuzhiyunRegardless of the value passed to this attribute, ZRAM will always
78*4882a593Smuzhiyunallocate multiple compression streams - one per online CPU - thus
79*4882a593Smuzhiyunallowing several concurrent compression operations. The number of
80*4882a593Smuzhiyunallocated compression streams goes down when some of the CPUs
81*4882a593Smuzhiyunbecome offline. There is no single-compression-stream mode anymore,
82*4882a593Smuzhiyununless you are running a UP system or have only 1 CPU online.
83*4882a593Smuzhiyun
84*4882a593SmuzhiyunTo find out how many streams are currently available::
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun	cat /sys/block/zram0/max_comp_streams
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun3) Select compression algorithm
89*4882a593Smuzhiyun===============================
90*4882a593Smuzhiyun
91*4882a593SmuzhiyunUsing comp_algorithm device attribute one can see available and
92*4882a593Smuzhiyuncurrently selected (shown in square brackets) compression algorithms,
93*4882a593Smuzhiyunor change the selected compression algorithm (once the device is initialised
94*4882a593Smuzhiyunthere is no way to change compression algorithm).
95*4882a593Smuzhiyun
96*4882a593SmuzhiyunExamples::
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun	#show supported compression algorithms
99*4882a593Smuzhiyun	cat /sys/block/zram0/comp_algorithm
100*4882a593Smuzhiyun	lzo [lz4]
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun	#select lzo compression algorithm
103*4882a593Smuzhiyun	echo lzo > /sys/block/zram0/comp_algorithm
104*4882a593Smuzhiyun
105*4882a593SmuzhiyunFor the time being, the `comp_algorithm` content does not necessarily
106*4882a593Smuzhiyunshow every compression algorithm supported by the kernel. We keep this
107*4882a593Smuzhiyunlist primarily to simplify device configuration and one can configure
108*4882a593Smuzhiyuna new device with a compression algorithm that is not listed in
109*4882a593Smuzhiyun`comp_algorithm`. The thing is that, internally, ZRAM uses Crypto API
110*4882a593Smuzhiyunand, if some of the algorithms were built as modules, it's impossible
111*4882a593Smuzhiyunto list all of them using, for instance, /proc/crypto or any other
112*4882a593Smuzhiyunmethod. This, however, has an advantage of permitting the usage of
113*4882a593Smuzhiyuncustom crypto compression modules (implementing S/W or H/W compression).
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun4) Set Disksize
116*4882a593Smuzhiyun===============
117*4882a593Smuzhiyun
118*4882a593SmuzhiyunSet disk size by writing the value to sysfs node 'disksize'.
119*4882a593SmuzhiyunThe value can be either in bytes or you can use mem suffixes.
120*4882a593SmuzhiyunExamples::
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun	# Initialize /dev/zram0 with 50MB disksize
123*4882a593Smuzhiyun	echo $((50*1024*1024)) > /sys/block/zram0/disksize
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun	# Using mem suffixes
126*4882a593Smuzhiyun	echo 256K > /sys/block/zram0/disksize
127*4882a593Smuzhiyun	echo 512M > /sys/block/zram0/disksize
128*4882a593Smuzhiyun	echo 1G > /sys/block/zram0/disksize
129*4882a593Smuzhiyun
130*4882a593SmuzhiyunNote:
131*4882a593SmuzhiyunThere is little point creating a zram of greater than twice the size of memory
132*4882a593Smuzhiyunsince we expect a 2:1 compression ratio. Note that zram uses about 0.1% of the
133*4882a593Smuzhiyunsize of the disk when not in use so a huge zram is wasteful.
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun5) Set memory limit: Optional
136*4882a593Smuzhiyun=============================
137*4882a593Smuzhiyun
138*4882a593SmuzhiyunSet memory limit by writing the value to sysfs node 'mem_limit'.
139*4882a593SmuzhiyunThe value can be either in bytes or you can use mem suffixes.
140*4882a593SmuzhiyunIn addition, you could change the value in runtime.
141*4882a593SmuzhiyunExamples::
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun	# limit /dev/zram0 with 50MB memory
144*4882a593Smuzhiyun	echo $((50*1024*1024)) > /sys/block/zram0/mem_limit
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun	# Using mem suffixes
147*4882a593Smuzhiyun	echo 256K > /sys/block/zram0/mem_limit
148*4882a593Smuzhiyun	echo 512M > /sys/block/zram0/mem_limit
149*4882a593Smuzhiyun	echo 1G > /sys/block/zram0/mem_limit
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun	# To disable memory limit
152*4882a593Smuzhiyun	echo 0 > /sys/block/zram0/mem_limit
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun6) Activate
155*4882a593Smuzhiyun===========
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun::
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun	mkswap /dev/zram0
160*4882a593Smuzhiyun	swapon /dev/zram0
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun	mkfs.ext4 /dev/zram1
163*4882a593Smuzhiyun	mount /dev/zram1 /tmp
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun7) Add/remove zram devices
166*4882a593Smuzhiyun==========================
167*4882a593Smuzhiyun
168*4882a593Smuzhiyunzram provides a control interface, which enables dynamic (on-demand) device
169*4882a593Smuzhiyunaddition and removal.
170*4882a593Smuzhiyun
171*4882a593SmuzhiyunIn order to add a new /dev/zramX device, perform a read operation on the hot_add
172*4882a593Smuzhiyunattribute. This will return either the new device's device id (meaning that you
173*4882a593Smuzhiyuncan use /dev/zram<id>) or an error code.
174*4882a593Smuzhiyun
175*4882a593SmuzhiyunExample::
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun	cat /sys/class/zram-control/hot_add
178*4882a593Smuzhiyun	1
179*4882a593Smuzhiyun
180*4882a593SmuzhiyunTo remove the existing /dev/zramX device (where X is a device id)
181*4882a593Smuzhiyunexecute::
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun	echo X > /sys/class/zram-control/hot_remove
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun8) Stats
186*4882a593Smuzhiyun========
187*4882a593Smuzhiyun
188*4882a593SmuzhiyunPer-device statistics are exported as various nodes under /sys/block/zram<id>/
189*4882a593Smuzhiyun
190*4882a593SmuzhiyunA brief description of exported device attributes follows. For more details
191*4882a593Smuzhiyunplease read Documentation/ABI/testing/sysfs-block-zram.
192*4882a593Smuzhiyun
193*4882a593Smuzhiyun======================  ======  ===============================================
194*4882a593SmuzhiyunName            	access            description
195*4882a593Smuzhiyun======================  ======  ===============================================
196*4882a593Smuzhiyundisksize          	RW	show and set the device's disk size
197*4882a593Smuzhiyuninitstate         	RO	shows the initialization state of the device
198*4882a593Smuzhiyunreset             	WO	trigger device reset
199*4882a593Smuzhiyunmem_used_max      	WO	reset the `mem_used_max` counter (see later)
200*4882a593Smuzhiyunmem_limit         	WO	specifies the maximum amount of memory ZRAM can
201*4882a593Smuzhiyun				use to store the compressed data
202*4882a593Smuzhiyunwriteback_limit   	WO	specifies the maximum amount of write IO zram
203*4882a593Smuzhiyun				can write out to backing device as 4KB unit
204*4882a593Smuzhiyunwriteback_limit_enable  RW	show and set writeback_limit feature
205*4882a593Smuzhiyunmax_comp_streams  	RW	the number of possible concurrent compress
206*4882a593Smuzhiyun				operations
207*4882a593Smuzhiyuncomp_algorithm    	RW	show and change the compression algorithm
208*4882a593Smuzhiyuncompact           	WO	trigger memory compaction
209*4882a593Smuzhiyundebug_stat        	RO	this file is used for zram debugging purposes
210*4882a593Smuzhiyunbacking_dev	  	RW	set up backend storage for zram to write out
211*4882a593Smuzhiyunidle		  	WO	mark allocated slot as idle
212*4882a593Smuzhiyun======================  ======  ===============================================
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun
215*4882a593SmuzhiyunUser space is advised to use the following files to read the device statistics.
216*4882a593Smuzhiyun
217*4882a593SmuzhiyunFile /sys/block/zram<id>/stat
218*4882a593Smuzhiyun
219*4882a593SmuzhiyunRepresents block layer statistics. Read Documentation/block/stat.rst for
220*4882a593Smuzhiyundetails.
221*4882a593Smuzhiyun
222*4882a593SmuzhiyunFile /sys/block/zram<id>/io_stat
223*4882a593Smuzhiyun
224*4882a593SmuzhiyunThe stat file represents device's I/O statistics not accounted by block
225*4882a593Smuzhiyunlayer and, thus, not available in zram<id>/stat file. It consists of a
226*4882a593Smuzhiyunsingle line of text and contains the following stats separated by
227*4882a593Smuzhiyunwhitespace:
228*4882a593Smuzhiyun
229*4882a593Smuzhiyun =============    =============================================================
230*4882a593Smuzhiyun failed_reads     The number of failed reads
231*4882a593Smuzhiyun failed_writes    The number of failed writes
232*4882a593Smuzhiyun invalid_io       The number of non-page-size-aligned I/O requests
233*4882a593Smuzhiyun notify_free      Depending on device usage scenario it may account
234*4882a593Smuzhiyun
235*4882a593Smuzhiyun                  a) the number of pages freed because of swap slot free
236*4882a593Smuzhiyun                     notifications
237*4882a593Smuzhiyun                  b) the number of pages freed because of
238*4882a593Smuzhiyun                     REQ_OP_DISCARD requests sent by bio. The former ones are
239*4882a593Smuzhiyun                     sent to a swap block device when a swap slot is freed,
240*4882a593Smuzhiyun                     which implies that this disk is being used as a swap disk.
241*4882a593Smuzhiyun
242*4882a593Smuzhiyun                  The latter ones are sent by filesystem mounted with
243*4882a593Smuzhiyun                  discard option, whenever some data blocks are getting
244*4882a593Smuzhiyun                  discarded.
245*4882a593Smuzhiyun =============    =============================================================
246*4882a593Smuzhiyun
247*4882a593SmuzhiyunFile /sys/block/zram<id>/mm_stat
248*4882a593Smuzhiyun
249*4882a593SmuzhiyunThe mm_stat file represents the device's mm statistics. It consists of a single
250*4882a593Smuzhiyunline of text and contains the following stats separated by whitespace:
251*4882a593Smuzhiyun
252*4882a593Smuzhiyun ================ =============================================================
253*4882a593Smuzhiyun orig_data_size   uncompressed size of data stored in this disk.
254*4882a593Smuzhiyun                  Unit: bytes
255*4882a593Smuzhiyun compr_data_size  compressed size of data stored in this disk
256*4882a593Smuzhiyun mem_used_total   the amount of memory allocated for this disk. This
257*4882a593Smuzhiyun                  includes allocator fragmentation and metadata overhead,
258*4882a593Smuzhiyun                  allocated for this disk. So, allocator space efficiency
259*4882a593Smuzhiyun                  can be calculated using compr_data_size and this statistic.
260*4882a593Smuzhiyun                  Unit: bytes
261*4882a593Smuzhiyun mem_limit        the maximum amount of memory ZRAM can use to store
262*4882a593Smuzhiyun                  the compressed data
263*4882a593Smuzhiyun mem_used_max     the maximum amount of memory zram has consumed to
264*4882a593Smuzhiyun                  store the data
265*4882a593Smuzhiyun same_pages       the number of same element filled pages written to this disk.
266*4882a593Smuzhiyun                  No memory is allocated for such pages.
267*4882a593Smuzhiyun pages_compacted  the number of pages freed during compaction
268*4882a593Smuzhiyun huge_pages	  the number of incompressible pages
269*4882a593Smuzhiyun ================ =============================================================
270*4882a593Smuzhiyun
271*4882a593SmuzhiyunFile /sys/block/zram<id>/bd_stat
272*4882a593Smuzhiyun
273*4882a593SmuzhiyunThe bd_stat file represents a device's backing device statistics. It consists of
274*4882a593Smuzhiyuna single line of text and contains the following stats separated by whitespace:
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun ============== =============================================================
277*4882a593Smuzhiyun bd_count	size of data written in backing device.
278*4882a593Smuzhiyun		Unit: 4K bytes
279*4882a593Smuzhiyun bd_reads	the number of reads from backing device
280*4882a593Smuzhiyun		Unit: 4K bytes
281*4882a593Smuzhiyun bd_writes	the number of writes to backing device
282*4882a593Smuzhiyun		Unit: 4K bytes
283*4882a593Smuzhiyun ============== =============================================================
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun9) Deactivate
286*4882a593Smuzhiyun=============
287*4882a593Smuzhiyun
288*4882a593Smuzhiyun::
289*4882a593Smuzhiyun
290*4882a593Smuzhiyun	swapoff /dev/zram0
291*4882a593Smuzhiyun	umount /dev/zram1
292*4882a593Smuzhiyun
293*4882a593Smuzhiyun10) Reset
294*4882a593Smuzhiyun=========
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun	Write any positive value to 'reset' sysfs node::
297*4882a593Smuzhiyun
298*4882a593Smuzhiyun		echo 1 > /sys/block/zram0/reset
299*4882a593Smuzhiyun		echo 1 > /sys/block/zram1/reset
300*4882a593Smuzhiyun
301*4882a593Smuzhiyun	This frees all the memory allocated for the given device and
302*4882a593Smuzhiyun	resets the disksize to zero. You must set the disksize again
303*4882a593Smuzhiyun	before reusing the device.
304*4882a593Smuzhiyun
305*4882a593SmuzhiyunOptional Feature
306*4882a593Smuzhiyun================
307*4882a593Smuzhiyun
308*4882a593Smuzhiyunwriteback
309*4882a593Smuzhiyun---------
310*4882a593Smuzhiyun
311*4882a593SmuzhiyunWith CONFIG_ZRAM_WRITEBACK, zram can write idle/incompressible page
312*4882a593Smuzhiyunto backing storage rather than keeping it in memory.
313*4882a593SmuzhiyunTo use the feature, admin should set up backing device via::
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun	echo /dev/sda5 > /sys/block/zramX/backing_dev
316*4882a593Smuzhiyun
317*4882a593Smuzhiyunbefore disksize setting. It supports only partition at this moment.
318*4882a593SmuzhiyunIf admin wants to use incompressible page writeback, they could do via::
319*4882a593Smuzhiyun
320*4882a593Smuzhiyun	echo huge > /sys/block/zramX/writeback
321*4882a593Smuzhiyun
322*4882a593SmuzhiyunTo use idle page writeback, first, user need to declare zram pages
323*4882a593Smuzhiyunas idle::
324*4882a593Smuzhiyun
325*4882a593Smuzhiyun	echo all > /sys/block/zramX/idle
326*4882a593Smuzhiyun
327*4882a593SmuzhiyunFrom now on, any pages on zram are idle pages. The idle mark
328*4882a593Smuzhiyunwill be removed until someone requests access of the block.
329*4882a593SmuzhiyunIOW, unless there is access request, those pages are still idle pages.
330*4882a593Smuzhiyun
331*4882a593SmuzhiyunAdmin can request writeback of those idle pages at right timing via::
332*4882a593Smuzhiyun
333*4882a593Smuzhiyun	echo idle > /sys/block/zramX/writeback
334*4882a593Smuzhiyun
335*4882a593SmuzhiyunWith the command, zram writeback idle pages from memory to the storage.
336*4882a593Smuzhiyun
337*4882a593SmuzhiyunIf admin want to write a specific page in zram device to backing device,
338*4882a593Smuzhiyunthey could write a page index into the interface.
339*4882a593Smuzhiyun
340*4882a593Smuzhiyun	echo "page_index=1251" > /sys/block/zramX/writeback
341*4882a593Smuzhiyun
342*4882a593SmuzhiyunIf there are lots of write IO with flash device, potentially, it has
343*4882a593Smuzhiyunflash wearout problem so that admin needs to design write limitation
344*4882a593Smuzhiyunto guarantee storage health for entire product life.
345*4882a593Smuzhiyun
346*4882a593SmuzhiyunTo overcome the concern, zram supports "writeback_limit" feature.
347*4882a593SmuzhiyunThe "writeback_limit_enable"'s default value is 0 so that it doesn't limit
348*4882a593Smuzhiyunany writeback. IOW, if admin wants to apply writeback budget, he should
349*4882a593Smuzhiyunenable writeback_limit_enable via::
350*4882a593Smuzhiyun
351*4882a593Smuzhiyun	$ echo 1 > /sys/block/zramX/writeback_limit_enable
352*4882a593Smuzhiyun
353*4882a593SmuzhiyunOnce writeback_limit_enable is set, zram doesn't allow any writeback
354*4882a593Smuzhiyununtil admin sets the budget via /sys/block/zramX/writeback_limit.
355*4882a593Smuzhiyun
356*4882a593Smuzhiyun(If admin doesn't enable writeback_limit_enable, writeback_limit's value
357*4882a593Smuzhiyunassigned via /sys/block/zramX/writeback_limit is meaningless.)
358*4882a593Smuzhiyun
359*4882a593SmuzhiyunIf admin want to limit writeback as per-day 400M, he could do it
360*4882a593Smuzhiyunlike below::
361*4882a593Smuzhiyun
362*4882a593Smuzhiyun	$ MB_SHIFT=20
363*4882a593Smuzhiyun	$ 4K_SHIFT=12
364*4882a593Smuzhiyun	$ echo $((400<<MB_SHIFT>>4K_SHIFT)) > \
365*4882a593Smuzhiyun		/sys/block/zram0/writeback_limit.
366*4882a593Smuzhiyun	$ echo 1 > /sys/block/zram0/writeback_limit_enable
367*4882a593Smuzhiyun
368*4882a593SmuzhiyunIf admins want to allow further write again once the bugdet is exhausted,
369*4882a593Smuzhiyunhe could do it like below::
370*4882a593Smuzhiyun
371*4882a593Smuzhiyun	$ echo $((400<<MB_SHIFT>>4K_SHIFT)) > \
372*4882a593Smuzhiyun		/sys/block/zram0/writeback_limit
373*4882a593Smuzhiyun
374*4882a593SmuzhiyunIf admin wants to see remaining writeback budget since last set::
375*4882a593Smuzhiyun
376*4882a593Smuzhiyun	$ cat /sys/block/zramX/writeback_limit
377*4882a593Smuzhiyun
378*4882a593SmuzhiyunIf admin want to disable writeback limit, he could do::
379*4882a593Smuzhiyun
380*4882a593Smuzhiyun	$ echo 0 > /sys/block/zramX/writeback_limit_enable
381*4882a593Smuzhiyun
382*4882a593SmuzhiyunThe writeback_limit count will reset whenever you reset zram (e.g.,
383*4882a593Smuzhiyunsystem reboot, echo 1 > /sys/block/zramX/reset) so keeping how many of
384*4882a593Smuzhiyunwriteback happened until you reset the zram to allocate extra writeback
385*4882a593Smuzhiyunbudget in next setting is user's job.
386*4882a593Smuzhiyun
387*4882a593SmuzhiyunIf admin wants to measure writeback count in a certain period, he could
388*4882a593Smuzhiyunknow it via /sys/block/zram0/bd_stat's 3rd column.
389*4882a593Smuzhiyun
390*4882a593Smuzhiyunmemory tracking
391*4882a593Smuzhiyun===============
392*4882a593Smuzhiyun
393*4882a593SmuzhiyunWith CONFIG_ZRAM_MEMORY_TRACKING, user can know information of the
394*4882a593Smuzhiyunzram block. It could be useful to catch cold or incompressible
395*4882a593Smuzhiyunpages of the process with*pagemap.
396*4882a593Smuzhiyun
397*4882a593SmuzhiyunIf you enable the feature, you could see block state via
398*4882a593Smuzhiyun/sys/kernel/debug/zram/zram0/block_state". The output is as follows::
399*4882a593Smuzhiyun
400*4882a593Smuzhiyun	  300    75.033841 .wh.
401*4882a593Smuzhiyun	  301    63.806904 s...
402*4882a593Smuzhiyun	  302    63.806919 ..hi
403*4882a593Smuzhiyun
404*4882a593SmuzhiyunFirst column
405*4882a593Smuzhiyun	zram's block index.
406*4882a593SmuzhiyunSecond column
407*4882a593Smuzhiyun	access time since the system was booted
408*4882a593SmuzhiyunThird column
409*4882a593Smuzhiyun	state of the block:
410*4882a593Smuzhiyun
411*4882a593Smuzhiyun	s:
412*4882a593Smuzhiyun		same page
413*4882a593Smuzhiyun	w:
414*4882a593Smuzhiyun		written page to backing store
415*4882a593Smuzhiyun	h:
416*4882a593Smuzhiyun		huge page
417*4882a593Smuzhiyun	i:
418*4882a593Smuzhiyun		idle page
419*4882a593Smuzhiyun
420*4882a593SmuzhiyunFirst line of above example says 300th block is accessed at 75.033841sec
421*4882a593Smuzhiyunand the block's state is huge so it is written back to the backing
422*4882a593Smuzhiyunstorage. It's a debugging feature so anyone shouldn't rely on it to work
423*4882a593Smuzhiyunproperly.
424*4882a593Smuzhiyun
425*4882a593SmuzhiyunNitin Gupta
426*4882a593Smuzhiyunngupta@vflare.org
427