@@ -39,13 +39,12 @@ With CONFIG_ZSMALLOC_STAT, we could see zsmalloc internal information via
3939
4040 # cat /sys/kernel/debug/zsmalloc/zram0/classes
4141
42- class size almost_full almost_empty obj_allocated obj_used pages_used pages_per_zspage
42+ class size 10% 20% 30% 40% 50% 60% 70% 80% 90% 99% 100% obj_allocated obj_used pages_used pages_per_zspage freeable
4343 ...
4444 ...
45- 9 176 0 1 186 129 8 4
46- 10 192 1 0 2880 2872 135 3
47- 11 208 0 1 819 795 42 2
48- 12 224 0 1 219 159 12 4
45+ 30 512 0 12 4 1 0 1 0 0 1 0 414 3464 3346 433 1 14
46+ 31 528 2 7 2 2 1 0 1 0 0 2 117 4154 3793 536 4 44
47+ 32 544 6 3 4 1 2 1 0 0 0 1 260 4170 3965 556 2 26
4948 ...
5049 ...
5150
@@ -54,10 +53,28 @@ class
5453 index
5554size
5655 object size zspage stores
57- almost_empty
58- the number of ZS_ALMOST_EMPTY zspages(see below)
59- almost_full
60- the number of ZS_ALMOST_FULL zspages(see below)
56+ 10%
57+ the number of zspages with usage ratio less than 10% (see below)
58+ 20%
59+ the number of zspages with usage ratio between 10% and 20%
60+ 30%
61+ the number of zspages with usage ratio between 20% and 30%
62+ 40%
63+ the number of zspages with usage ratio between 30% and 40%
64+ 50%
65+ the number of zspages with usage ratio between 40% and 50%
66+ 60%
67+ the number of zspages with usage ratio between 50% and 60%
68+ 70%
69+ the number of zspages with usage ratio between 60% and 70%
70+ 80%
71+ the number of zspages with usage ratio between 70% and 80%
72+ 90%
73+ the number of zspages with usage ratio between 80% and 90%
74+ 99%
75+ the number of zspages with usage ratio between 90% and 99%
76+ 100%
77+ the number of zspages with usage ratio 100%
6178obj_allocated
6279 the number of objects allocated
6380obj_used
@@ -66,19 +83,14 @@ pages_used
6683 the number of pages allocated for the class
6784pages_per_zspage
6885 the number of 0-order pages to make a zspage
86+ freeable
87+ the approximate number of pages class compaction can free
6988
70- We assign a zspage to ZS_ALMOST_EMPTY fullness group when n <= N / f, where
71-
72- * n = number of allocated objects
73- * N = total number of objects zspage can store
74- * f = fullness_threshold_frac(ie, 4 at the moment)
75-
76- Similarly, we assign zspage to:
77-
78- * ZS_ALMOST_FULL when n > N / f
79- * ZS_EMPTY when n == 0
80- * ZS_FULL when n == N
81-
89+ Each zspage maintains inuse counter which keeps track of the number of
90+ objects stored in the zspage. The inuse counter determines the zspage's
91+ "fullness group" which is calculated as the ratio of the "inuse" objects to
92+ the total number of objects the zspage can hold (objs_per_zspage). The
93+ closer the inuse counter is to objs_per_zspage, the better.
8294
8395Internals
8496=========
@@ -94,10 +106,10 @@ of objects that each zspage can store.
94106
95107For instance, consider the following size classes:::
96108
97- class size almost_full almost_empty obj_allocated obj_used pages_used pages_per_zspage freeable
109+ class size 10% .... 100% obj_allocated obj_used pages_used pages_per_zspage freeable
98110 ...
99- 94 1536 0 0 0 0 0 3 0
100- 100 1632 0 0 0 0 0 2 0
111+ 94 1536 0 .... 0 0 0 0 3 0
112+ 100 1632 0 .... 0 0 0 0 2 0
101113 ...
102114
103115
@@ -134,10 +146,11 @@ reduces memory wastage.
134146
135147Let's take a closer look at the bottom of `/sys/kernel/debug/zsmalloc/zramX/classes `:::
136148
137- class size almost_full almost_empty obj_allocated obj_used pages_used pages_per_zspage freeable
149+ class size 10% .... 100% obj_allocated obj_used pages_used pages_per_zspage freeable
150+
138151 ...
139- 202 3264 0 0 0 0 0 4 0
140- 254 4096 0 0 0 0 0 1 0
152+ 202 3264 0 .. 0 0 0 0 4 0
153+ 254 4096 0 .. 0 0 0 0 1 0
141154 ...
142155
143156Size class #202 stores objects of size 3264 bytes and has a maximum of 4 pages
@@ -151,40 +164,42 @@ efficient storage of large objects.
151164
152165For zspage chain size of 8, huge class watermark becomes 3632 bytes:::
153166
154- class size almost_full almost_empty obj_allocated obj_used pages_used pages_per_zspage freeable
167+ class size 10% .... 100% obj_allocated obj_used pages_used pages_per_zspage freeable
168+
155169 ...
156- 202 3264 0 0 0 0 0 4 0
157- 211 3408 0 0 0 0 0 5 0
158- 217 3504 0 0 0 0 0 6 0
159- 222 3584 0 0 0 0 0 7 0
160- 225 3632 0 0 0 0 0 8 0
161- 254 4096 0 0 0 0 0 1 0
170+ 202 3264 0 .. 0 0 0 0 4 0
171+ 211 3408 0 .. 0 0 0 0 5 0
172+ 217 3504 0 .. 0 0 0 0 6 0
173+ 222 3584 0 .. 0 0 0 0 7 0
174+ 225 3632 0 .. 0 0 0 0 8 0
175+ 254 4096 0 .. 0 0 0 0 1 0
162176 ...
163177
164178For zspage chain size of 16, huge class watermark becomes 3840 bytes:::
165179
166- class size almost_full almost_empty obj_allocated obj_used pages_used pages_per_zspage freeable
180+ class size 10% .... 100% obj_allocated obj_used pages_used pages_per_zspage freeable
181+
167182 ...
168- 202 3264 0 0 0 0 0 4 0
169- 206 3328 0 0 0 0 0 13 0
170- 207 3344 0 0 0 0 0 9 0
171- 208 3360 0 0 0 0 0 14 0
172- 211 3408 0 0 0 0 0 5 0
173- 212 3424 0 0 0 0 0 16 0
174- 214 3456 0 0 0 0 0 11 0
175- 217 3504 0 0 0 0 0 6 0
176- 219 3536 0 0 0 0 0 13 0
177- 222 3584 0 0 0 0 0 7 0
178- 223 3600 0 0 0 0 0 15 0
179- 225 3632 0 0 0 0 0 8 0
180- 228 3680 0 0 0 0 0 9 0
181- 230 3712 0 0 0 0 0 10 0
182- 232 3744 0 0 0 0 0 11 0
183- 234 3776 0 0 0 0 0 12 0
184- 235 3792 0 0 0 0 0 13 0
185- 236 3808 0 0 0 0 0 14 0
186- 238 3840 0 0 0 0 0 15 0
187- 254 4096 0 0 0 0 0 1 0
183+ 202 3264 0 .. 0 0 0 0 4 0
184+ 206 3328 0 .. 0 0 0 0 13 0
185+ 207 3344 0 .. 0 0 0 0 9 0
186+ 208 3360 0 .. 0 0 0 0 14 0
187+ 211 3408 0 .. 0 0 0 0 5 0
188+ 212 3424 0 .. 0 0 0 0 16 0
189+ 214 3456 0 .. 0 0 0 0 11 0
190+ 217 3504 0 .. 0 0 0 0 6 0
191+ 219 3536 0 .. 0 0 0 0 13 0
192+ 222 3584 0 .. 0 0 0 0 7 0
193+ 223 3600 0 .. 0 0 0 0 15 0
194+ 225 3632 0 .. 0 0 0 0 8 0
195+ 228 3680 0 .. 0 0 0 0 9 0
196+ 230 3712 0 .. 0 0 0 0 10 0
197+ 232 3744 0 .. 0 0 0 0 11 0
198+ 234 3776 0 .. 0 0 0 0 12 0
199+ 235 3792 0 .. 0 0 0 0 13 0
200+ 236 3808 0 .. 0 0 0 0 14 0
201+ 238 3840 0 .. 0 0 0 0 15 0
202+ 254 4096 0 .. 0 0 0 0 1 0
188203 ...
189204
190205Overall the combined zspage chain size effect on zsmalloc pool configuration:::
@@ -214,9 +229,10 @@ zram as a build artifacts storage (Linux kernel compilation).
214229
215230 zsmalloc classes stats:::
216231
217- class size almost_full almost_empty obj_allocated obj_used pages_used pages_per_zspage freeable
232+ class size 10% .... 100% obj_allocated obj_used pages_used pages_per_zspage freeable
233+
218234 ...
219- Total 13 51 413836 412973 159955 3
235+ Total 13 .. 51 413836 412973 159955 3
220236
221237 zram mm_stat:::
222238
@@ -227,9 +243,10 @@ zram as a build artifacts storage (Linux kernel compilation).
227243
228244 zsmalloc classes stats:::
229245
230- class size almost_full almost_empty obj_allocated obj_used pages_used pages_per_zspage freeable
246+ class size 10% .... 100% obj_allocated obj_used pages_used pages_per_zspage freeable
247+
231248 ...
232- Total 18 87 414852 412978 156666 0
249+ Total 18 .. 87 414852 412978 156666 0
233250
234251 zram mm_stat:::
235252
0 commit comments