#define REPORT_FAILURES_IN_FN() \ do { \ if (failures) \
pr_info("%s failed %d out of %d times\n", \
__func__, failures, num_tests); \ else \
pr_info("all %d tests in %s passed\n", \
num_tests, __func__); \
} while (0)
/* Calculate the number of uninitialized bytes in the buffer. */ staticint __init count_nonzero_bytes(void *ptr, size_t size)
{ int i, ret = 0; unsignedchar *p = (unsignedchar *)ptr;
for (i = 0; i < size; i++) if (p[i])
ret++; return ret;
}
/* Fill a buffer with garbage, skipping |skip| first bytes. */ staticvoid __init fill_with_garbage_skip(void *ptr, int size, size_t skip)
{ unsignedint *p = (unsignedint *)((char *)ptr + skip); int i = 0;
WARN_ON(skip > size);
size -= skip;
while (size >= sizeof(*p)) {
p[i] = GARBAGE_INT;
i++;
size -= sizeof(*p);
} if (size)
memset(&p[i], GARBAGE_BYTE, size);
}
/* Test the page allocator by calling alloc_pages with different orders. */ staticint __init test_pages(int *total_failures)
{ int failures = 0, num_tests = 0; int i;
for (i = 0; i < NR_PAGE_ORDERS; i++)
num_tests += do_alloc_pages_order(i, &failures);
buf = kmalloc(size, GFP_KERNEL); if (!buf) goto err; if (count_nonzero_bytes(buf, size))
(*total_failures)++;
fill_with_garbage(buf, size);
kfree(buf); return1;
err:
(*total_failures)++; return1;
}
/* Test vmalloc() with given parameters. */ staticint __init do_vmalloc_size(size_t size, int *total_failures)
{ void *buf;
buf = vmalloc(size); if (!buf) goto err;
fill_with_garbage(buf, size);
vfree(buf);
buf = vmalloc(size); if (!buf) goto err; if (count_nonzero_bytes(buf, size))
(*total_failures)++;
fill_with_garbage(buf, size);
vfree(buf); return1;
err:
(*total_failures)++; return1;
}
/* Test kmalloc()/vmalloc() by allocating objects of different sizes. */ staticint __init test_kvmalloc(int *total_failures)
{ int failures = 0, num_tests = 0; int i, size;
for (i = 0; i < 20; i++) {
size = 1 << i;
num_tests += do_kmalloc_size(size, &failures);
num_tests += do_vmalloc_size(size, &failures);
}
c = kmem_cache_create("test_cache", size, 1,
want_rcu ? SLAB_TYPESAFE_BY_RCU : 0,
want_ctor ? test_ctor : NULL); for (iter = 0; iter < 10; iter++) { /* Do a test of bulk allocations */ if (!want_rcu && !want_ctor) { int ret;
ret = kmem_cache_alloc_bulk(c, alloc_mask, BULK_SIZE, bulk_array); if (!ret) {
fail = true;
} else { int i; for (i = 0; i < ret; i++)
fail |= check_buf(bulk_array[i], size, want_ctor, want_rcu, want_zero);
kmem_cache_free_bulk(c, ret, bulk_array);
}
}
buf = kmem_cache_alloc(c, alloc_mask); /* Check that buf is zeroed, if it must be. */
fail |= check_buf(buf, size, want_ctor, want_rcu, want_zero);
fill_with_garbage_skip(buf, size, want_ctor ? CTOR_BYTES : 0);
if (!want_rcu) {
kmem_cache_free(c, buf); continue;
}
/* Test the behavior of SLAB_TYPESAFE_BY_RCU caches of different sizes. */ staticint __init test_rcu_persistent(int *total_failures)
{ int failures = 0, num_tests = 0; int i, size;
for (i = 0; i < 10; i++) {
size = 8 << i;
num_tests += do_kmem_cache_rcu_persistent(size, &failures);
}
REPORT_FAILURES_IN_FN();
*total_failures += failures; return num_tests;
}
MODULE_DESCRIPTION("Test cases for SL[AOU]B/page initialization at alloc/free time");
MODULE_LICENSE("GPL");
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.11Bemerkung:
(vorverarbeitet am 2026-09-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.