static void allocate_objects(PMEMobjpool *pop, size_t size_min, size_t size_max) { size_t allocated_total = 0; size_t sstart = 0; PMEMoid oid = pmemobj_root(pop, 1); uint64_t uuid_lo = oid.pool_uuid_lo; while (allocated_total < ALLOC_TOTAL) { size_t s = RRAND(seed, size_max, size_min); pmemobj_alloc(pop, &oid, s, 0, NULL, NULL); s = pmemobj_alloc_usable_size(oid); UT_ASSERTeq(OID_IS_NULL(oid), 0); objects[nobjects++] = oid.off; UT_ASSERT(nobjects < MAX_OBJECTS); allocated_total += s; allocated_current += s; if (allocated_current > ALLOC_CURR) { shuffle_objects(sstart, nobjects); for (int i = 0; i < FREES_P; ++i) { oid.pool_uuid_lo = uuid_lo; oid.off = remove_last(); allocated_current -= pmemobj_alloc_usable_size(oid); pmemobj_free(&oid); } sstart = nobjects; } } }
static void shuffle_objects(size_t start, size_t end) { uint64_t tmp; size_t dest; for (size_t n = start; n < end; ++n) { dest = RRAND(seed, nobjects - 1, 0); tmp = objects[n]; objects[n] = objects[dest]; objects[dest] = tmp; } }
/* * rand_sizes -- allocates array and calculates random values as allocation * sizes for each object. Used only when range flag set. */ static size_t * rand_sizes(size_t min, size_t max, size_t n_ops) { assert(n_ops != 0); auto *rand_sizes = (size_t *)malloc(n_ops * sizeof(size_t)); if (rand_sizes == nullptr) { perror("malloc"); return nullptr; } for (size_t i = 0; i < n_ops; i++) { rand_sizes[i] = RRAND(max, min); } return rand_sizes; }