Lines Matching refs:size

185 static size_t setup_test_cache(struct kunit *test, size_t size, slab_flags_t flags,  in setup_test_cache()  argument
189 return size; in setup_test_cache()
191 kunit_info(test, "%s: size=%zu, ctor=%ps\n", __func__, size, ctor); in setup_test_cache()
198 test_cache = kmem_cache_create("test", size, 1, flags, ctor); in setup_test_cache()
201 return size; in setup_test_cache()
213 static inline size_t kmalloc_cache_alignment(size_t size) in kmalloc_cache_alignment() argument
217 return kmalloc_caches[type][__kmalloc_index(size, false)]->align; in kmalloc_cache_alignment()
244 static void *test_alloc(struct kunit *test, size_t size, gfp_t gfp, enum allocation_policy policy) in test_alloc() argument
265 kunit_info(test, "%s: size=%zu, gfp=%x, policy=%s, cache=%i\n", __func__, size, gfp, in test_alloc()
283 alloc = kmalloc(size, gfp); in test_alloc()
289 kmalloc_caches[type][__kmalloc_index(size, false)]; in test_alloc()
320 size_t size = 32; in test_out_of_bounds_read() local
328 setup_test_cache(test, size, 0, NULL); in test_out_of_bounds_read()
335 size = kmalloc_cache_alignment(size); in test_out_of_bounds_read()
339 buf = test_alloc(test, size, GFP_KERNEL, ALLOCATE_LEFT); in test_out_of_bounds_read()
345 buf = test_alloc(test, size, GFP_KERNEL, ALLOCATE_RIGHT); in test_out_of_bounds_read()
346 expect.addr = buf + size; in test_out_of_bounds_read()
354 size_t size = 32; in test_out_of_bounds_write() local
362 setup_test_cache(test, size, 0, NULL); in test_out_of_bounds_write()
363 buf = test_alloc(test, size, GFP_KERNEL, ALLOCATE_LEFT); in test_out_of_bounds_write()
372 const size_t size = 32; in test_use_after_free_read() local
379 setup_test_cache(test, size, 0, NULL); in test_use_after_free_read()
380 expect.addr = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY); in test_use_after_free_read()
388 const size_t size = 32; in test_double_free() local
394 setup_test_cache(test, size, 0, NULL); in test_double_free()
395 expect.addr = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY); in test_double_free()
403 const size_t size = 32; in test_invalid_addr_free() local
410 setup_test_cache(test, size, 0, NULL); in test_invalid_addr_free()
411 buf = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY); in test_invalid_addr_free()
420 size_t size = 32; in test_corruption() local
427 setup_test_cache(test, size, 0, NULL); in test_corruption()
431 buf = test_alloc(test, size, GFP_KERNEL, ALLOCATE_LEFT); in test_corruption()
432 expect.addr = buf + size; in test_corruption()
437 buf = test_alloc(test, size, GFP_KERNEL, ALLOCATE_RIGHT); in test_corruption()
456 const size_t size = 73; in test_kmalloc_aligned_oob_read() local
457 const size_t align = kmalloc_cache_alignment(size); in test_kmalloc_aligned_oob_read()
465 buf = test_alloc(test, size, GFP_KERNEL, ALLOCATE_RIGHT); in test_kmalloc_aligned_oob_read()
478 READ_ONCE(*(buf + size)); in test_kmalloc_aligned_oob_read()
482 expect.addr = buf + size + align; in test_kmalloc_aligned_oob_read()
491 const size_t size = 73; in test_kmalloc_aligned_oob_write() local
498 buf = test_alloc(test, size, GFP_KERNEL, ALLOCATE_RIGHT); in test_kmalloc_aligned_oob_write()
503 expect.addr = buf + size; in test_kmalloc_aligned_oob_write()
513 const size_t size = 32; in test_shrink_memcache() local
516 setup_test_cache(test, size, 0, NULL); in test_shrink_memcache()
518 buf = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY); in test_shrink_memcache()
537 const size_t size = setup_test_cache(test, get_random_u32_inclusive(8, 307), in test_free_bulk() local
540 test_alloc(test, size, GFP_KERNEL, ALLOCATE_RIGHT), in test_free_bulk()
541 test_alloc(test, size, GFP_KERNEL, ALLOCATE_NONE), in test_free_bulk()
542 test_alloc(test, size, GFP_KERNEL, ALLOCATE_LEFT), in test_free_bulk()
543 test_alloc(test, size, GFP_KERNEL, ALLOCATE_NONE), in test_free_bulk()
544 test_alloc(test, size, GFP_KERNEL, ALLOCATE_NONE), in test_free_bulk()
556 const size_t size = 32; in test_init_on_free() local
567 setup_test_cache(test, size, 0, NULL); in test_init_on_free()
568 expect.addr = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY); in test_init_on_free()
569 for (i = 0; i < size; i++) in test_init_on_free()
573 for (i = 0; i < size; i++) { in test_init_on_free()
589 const size_t size = 32; in test_memcache_ctor() local
593 setup_test_cache(test, size, 0, ctor_set_x); in test_memcache_ctor()
594 buf = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY); in test_memcache_ctor()
607 const size_t size = PAGE_SIZE; /* PAGE_SIZE so we can use ALLOCATE_ANY. */ in test_gfpzero() local
614 setup_test_cache(test, size, 0, NULL); in test_gfpzero()
615 buf1 = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY); in test_gfpzero()
616 for (i = 0; i < size; i++) in test_gfpzero()
622 buf2 = test_alloc(test, size, GFP_KERNEL | __GFP_ZERO, ALLOCATE_ANY); in test_gfpzero()
634 for (i = 0; i < size; i++) in test_gfpzero()
658 const size_t size = 32; in test_memcache_typesafe_by_rcu() local
665 setup_test_cache(test, size, SLAB_TYPESAFE_BY_RCU, NULL); in test_memcache_typesafe_by_rcu()
668 expect.addr = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY); in test_memcache_typesafe_by_rcu()
694 const size_t size = 32; in test_krealloc() local
698 .addr = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY), in test_krealloc()
705 KUNIT_EXPECT_EQ(test, ksize(buf), size); /* Precise size match after KFENCE alloc. */ in test_krealloc()
706 for (i = 0; i < size; i++) in test_krealloc()
710 buf = krealloc(buf, size * 3, GFP_KERNEL); /* Grow. */ in test_krealloc()
712 KUNIT_EXPECT_GE(test, ksize(buf), size * 3); in test_krealloc()
713 for (i = 0; i < size; i++) in test_krealloc()
715 for (; i < size * 3; i++) /* Fill to extra bytes. */ in test_krealloc()
718 buf = krealloc(buf, size * 2, GFP_KERNEL); /* Shrink. */ in test_krealloc()
719 KUNIT_EXPECT_GE(test, ksize(buf), size * 2); in test_krealloc()
720 for (i = 0; i < size * 2; i++) in test_krealloc()
734 const size_t size = 32; in test_memcache_alloc_bulk() local
738 setup_test_cache(test, size, 0, NULL); in test_memcache_alloc_bulk()