Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

slub: allow stats to be cleared

When collecting slub stats for particular workloads, it's necessary to
collect each statistic for all caches before the job is even started
because the counters are usually greater than zero just from boot and
initialization.

This allows a statistic to be cleared on each cpu by writing '0' to its
sysfs file. This creates a baseline for statistics of interest before
the workload is started.

Setting a statistic to a particular value is not supported, so all values
written to these files other than '0' returns -EINVAL.

Cc: Christoph Lameter <cl@linux-foundation.org>
Signed-off-by: David Rientjes <rientjes@google.com>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>

authored by

David Rientjes and committed by
Pekka Enberg
78eb00cc 374576a8

+75 -52
+58 -51
Documentation/ABI/testing/sysfs-kernel-slab
··· 45 45 Contact: Pekka Enberg <penberg@cs.helsinki.fi>, 46 46 Christoph Lameter <cl@linux-foundation.org> 47 47 Description: 48 - The alloc_fastpath file is read-only and specifies how many 49 - objects have been allocated using the fast path. 48 + The alloc_fastpath file shows how many objects have been 49 + allocated using the fast path. It can be written to clear the 50 + current count. 50 51 Available when CONFIG_SLUB_STATS is enabled. 51 52 52 53 What: /sys/kernel/slab/cache/alloc_from_partial ··· 56 55 Contact: Pekka Enberg <penberg@cs.helsinki.fi>, 57 56 Christoph Lameter <cl@linux-foundation.org> 58 57 Description: 59 - The alloc_from_partial file is read-only and specifies how 60 - many times a cpu slab has been full and it has been refilled 61 - by using a slab from the list of partially used slabs. 58 + The alloc_from_partial file shows how many times a cpu slab has 59 + been full and it has been refilled by using a slab from the list 60 + of partially used slabs. It can be written to clear the current 61 + count. 62 62 Available when CONFIG_SLUB_STATS is enabled. 63 63 64 64 What: /sys/kernel/slab/cache/alloc_refill ··· 68 66 Contact: Pekka Enberg <penberg@cs.helsinki.fi>, 69 67 Christoph Lameter <cl@linux-foundation.org> 70 68 Description: 71 - The alloc_refill file is read-only and specifies how many 72 - times the per-cpu freelist was empty but there were objects 73 - available as the result of remote cpu frees. 69 + The alloc_refill file shows how many times the per-cpu freelist 70 + was empty but there were objects available as the result of 71 + remote cpu frees. It can be written to clear the current count. 74 72 Available when CONFIG_SLUB_STATS is enabled. 75 73 76 74 What: /sys/kernel/slab/cache/alloc_slab ··· 79 77 Contact: Pekka Enberg <penberg@cs.helsinki.fi>, 80 78 Christoph Lameter <cl@linux-foundation.org> 81 79 Description: 82 - The alloc_slab file is read-only and specifies how many times 83 - a new slab had to be allocated from the page allocator. 80 + The alloc_slab file is shows how many times a new slab had to 81 + be allocated from the page allocator. It can be written to 82 + clear the current count. 84 83 Available when CONFIG_SLUB_STATS is enabled. 85 84 86 85 What: /sys/kernel/slab/cache/alloc_slowpath ··· 90 87 Contact: Pekka Enberg <penberg@cs.helsinki.fi>, 91 88 Christoph Lameter <cl@linux-foundation.org> 92 89 Description: 93 - The alloc_slowpath file is read-only and specifies how many 94 - objects have been allocated using the slow path because of a 95 - refill or allocation from a partial or new slab. 90 + The alloc_slowpath file shows how many objects have been 91 + allocated using the slow path because of a refill or 92 + allocation from a partial or new slab. It can be written to 93 + clear the current count. 96 94 Available when CONFIG_SLUB_STATS is enabled. 97 95 98 96 What: /sys/kernel/slab/cache/cache_dma ··· 121 117 Contact: Pekka Enberg <penberg@cs.helsinki.fi>, 122 118 Christoph Lameter <cl@linux-foundation.org> 123 119 Description: 124 - The file cpuslab_flush is read-only and specifies how many 125 - times a cache's cpu slabs have been flushed as the result of 126 - destroying or shrinking a cache, a cpu going offline, or as 127 - the result of forcing an allocation from a certain node. 120 + The file cpuslab_flush shows how many times a cache's cpu slabs 121 + have been flushed as the result of destroying or shrinking a 122 + cache, a cpu going offline, or as the result of forcing an 123 + allocation from a certain node. It can be written to clear the 124 + current count. 128 125 Available when CONFIG_SLUB_STATS is enabled. 129 126 130 127 What: /sys/kernel/slab/cache/ctor ··· 144 139 Contact: Pekka Enberg <penberg@cs.helsinki.fi>, 145 140 Christoph Lameter <cl@linux-foundation.org> 146 141 Description: 147 - The file deactivate_empty is read-only and specifies how many 148 - times an empty cpu slab was deactivated. 142 + The deactivate_empty file shows how many times an empty cpu slab 143 + was deactivated. It can be written to clear the current count. 149 144 Available when CONFIG_SLUB_STATS is enabled. 150 145 151 146 What: /sys/kernel/slab/cache/deactivate_full ··· 154 149 Contact: Pekka Enberg <penberg@cs.helsinki.fi>, 155 150 Christoph Lameter <cl@linux-foundation.org> 156 151 Description: 157 - The file deactivate_full is read-only and specifies how many 158 - times a full cpu slab was deactivated. 152 + The deactivate_full file shows how many times a full cpu slab 153 + was deactivated. It can be written to clear the current count. 159 154 Available when CONFIG_SLUB_STATS is enabled. 160 155 161 156 What: /sys/kernel/slab/cache/deactivate_remote_frees ··· 164 159 Contact: Pekka Enberg <penberg@cs.helsinki.fi>, 165 160 Christoph Lameter <cl@linux-foundation.org> 166 161 Description: 167 - The file deactivate_remote_frees is read-only and specifies how 168 - many times a cpu slab has been deactivated and contained free 169 - objects that were freed remotely. 162 + The deactivate_remote_frees file shows how many times a cpu slab 163 + has been deactivated and contained free objects that were freed 164 + remotely. It can be written to clear the current count. 170 165 Available when CONFIG_SLUB_STATS is enabled. 171 166 172 167 What: /sys/kernel/slab/cache/deactivate_to_head ··· 175 170 Contact: Pekka Enberg <penberg@cs.helsinki.fi>, 176 171 Christoph Lameter <cl@linux-foundation.org> 177 172 Description: 178 - The file deactivate_to_head is read-only and specifies how 179 - many times a partial cpu slab was deactivated and added to the 180 - head of its node's partial list. 173 + The deactivate_to_head file shows how many times a partial cpu 174 + slab was deactivated and added to the head of its node's partial 175 + list. It can be written to clear the current count. 181 176 Available when CONFIG_SLUB_STATS is enabled. 182 177 183 178 What: /sys/kernel/slab/cache/deactivate_to_tail ··· 186 181 Contact: Pekka Enberg <penberg@cs.helsinki.fi>, 187 182 Christoph Lameter <cl@linux-foundation.org> 188 183 Description: 189 - The file deactivate_to_tail is read-only and specifies how 190 - many times a partial cpu slab was deactivated and added to the 191 - tail of its node's partial list. 184 + The deactivate_to_tail file shows how many times a partial cpu 185 + slab was deactivated and added to the tail of its node's partial 186 + list. It can be written to clear the current count. 192 187 Available when CONFIG_SLUB_STATS is enabled. 193 188 194 189 What: /sys/kernel/slab/cache/destroy_by_rcu ··· 206 201 Contact: Pekka Enberg <penberg@cs.helsinki.fi>, 207 202 Christoph Lameter <cl@linux-foundation.org> 208 203 Description: 209 - The file free_add_partial is read-only and specifies how many 210 - times an object has been freed in a full slab so that it had to 211 - added to its node's partial list. 204 + The free_add_partial file shows how many times an object has 205 + been freed in a full slab so that it had to added to its node's 206 + partial list. It can be written to clear the current count. 212 207 Available when CONFIG_SLUB_STATS is enabled. 213 208 214 209 What: /sys/kernel/slab/cache/free_calls ··· 227 222 Contact: Pekka Enberg <penberg@cs.helsinki.fi>, 228 223 Christoph Lameter <cl@linux-foundation.org> 229 224 Description: 230 - The free_fastpath file is read-only and specifies how many 231 - objects have been freed using the fast path because it was an 232 - object from the cpu slab. 225 + The free_fastpath file shows how many objects have been freed 226 + using the fast path because it was an object from the cpu slab. 227 + It can be written to clear the current count. 233 228 Available when CONFIG_SLUB_STATS is enabled. 234 229 235 230 What: /sys/kernel/slab/cache/free_frozen ··· 238 233 Contact: Pekka Enberg <penberg@cs.helsinki.fi>, 239 234 Christoph Lameter <cl@linux-foundation.org> 240 235 Description: 241 - The free_frozen file is read-only and specifies how many 242 - objects have been freed to a frozen slab (i.e. a remote cpu 243 - slab). 236 + The free_frozen file shows how many objects have been freed to 237 + a frozen slab (i.e. a remote cpu slab). It can be written to 238 + clear the current count. 244 239 Available when CONFIG_SLUB_STATS is enabled. 245 240 246 241 What: /sys/kernel/slab/cache/free_remove_partial ··· 249 244 Contact: Pekka Enberg <penberg@cs.helsinki.fi>, 250 245 Christoph Lameter <cl@linux-foundation.org> 251 246 Description: 252 - The file free_remove_partial is read-only and specifies how 253 - many times an object has been freed to a now-empty slab so 254 - that it had to be removed from its node's partial list. 247 + The free_remove_partial file shows how many times an object has 248 + been freed to a now-empty slab so that it had to be removed from 249 + its node's partial list. It can be written to clear the current 250 + count. 255 251 Available when CONFIG_SLUB_STATS is enabled. 256 252 257 253 What: /sys/kernel/slab/cache/free_slab ··· 261 255 Contact: Pekka Enberg <penberg@cs.helsinki.fi>, 262 256 Christoph Lameter <cl@linux-foundation.org> 263 257 Description: 264 - The free_slab file is read-only and specifies how many times an 265 - empty slab has been freed back to the page allocator. 258 + The free_slab file shows how many times an empty slab has been 259 + freed back to the page allocator. It can be written to clear 260 + the current count. 266 261 Available when CONFIG_SLUB_STATS is enabled. 267 262 268 263 What: /sys/kernel/slab/cache/free_slowpath ··· 272 265 Contact: Pekka Enberg <penberg@cs.helsinki.fi>, 273 266 Christoph Lameter <cl@linux-foundation.org> 274 267 Description: 275 - The free_slowpath file is read-only and specifies how many 276 - objects have been freed using the slow path (i.e. to a full or 277 - partial slab). 268 + The free_slowpath file shows how many objects have been freed 269 + using the slow path (i.e. to a full or partial slab). It can 270 + be written to clear the current count. 278 271 Available when CONFIG_SLUB_STATS is enabled. 279 272 280 273 What: /sys/kernel/slab/cache/hwcache_align ··· 353 346 Contact: Pekka Enberg <penberg@cs.helsinki.fi>, 354 347 Christoph Lameter <cl@linux-foundation.org> 355 348 Description: 356 - The file order_fallback is read-only and specifies how many 357 - times an allocation of a new slab has not been possible at the 358 - cache's order and instead fallen back to its minimum possible 359 - order. 349 + The order_fallback file shows how many times an allocation of a 350 + new slab has not been possible at the cache's order and instead 351 + fallen back to its minimum possible order. It can be written to 352 + clear the current count. 360 353 Available when CONFIG_SLUB_STATS is enabled. 361 354 362 355 What: /sys/kernel/slab/cache/partial
+17 -1
mm/slub.c
··· 4371 4371 return len + sprintf(buf + len, "\n"); 4372 4372 } 4373 4373 4374 + static void clear_stat(struct kmem_cache *s, enum stat_item si) 4375 + { 4376 + int cpu; 4377 + 4378 + for_each_online_cpu(cpu) 4379 + get_cpu_slab(s, cpu)->stat[si] = 0; 4380 + } 4381 + 4374 4382 #define STAT_ATTR(si, text) \ 4375 4383 static ssize_t text##_show(struct kmem_cache *s, char *buf) \ 4376 4384 { \ 4377 4385 return show_stat(s, buf, si); \ 4378 4386 } \ 4379 - SLAB_ATTR_RO(text); \ 4387 + static ssize_t text##_store(struct kmem_cache *s, \ 4388 + const char *buf, size_t length) \ 4389 + { \ 4390 + if (buf[0] != '0') \ 4391 + return -EINVAL; \ 4392 + clear_stat(s, si); \ 4393 + return length; \ 4394 + } \ 4395 + SLAB_ATTR(text); \ 4380 4396 4381 4397 STAT_ATTR(ALLOC_FASTPATH, alloc_fastpath); 4382 4398 STAT_ATTR(ALLOC_SLOWPATH, alloc_slowpath);