Exemple #1
0
JEMALLOC_INLINE_C size_t
extent_quantize(size_t size)
{

	/*
	 * Round down to the nearest chunk size that can actually be requested
	 * during normal huge allocation.
	 */
	return (index2size(size2index(size + 1) - 1));
}
Exemple #2
0
static void
arena_large_reset_stats_cancel(arena_t *arena, size_t usize)
{
	szind_t index = size2index(usize);
	szind_t hindex = (index >= NBINS) ? index - NBINS : 0;

	cassert(config_stats);

	arena->stats.ndalloc_large--;
	arena->stats.lstats[hindex].ndalloc--;
}
Exemple #3
0
TEST_END

TEST_BEGIN(test_overflow)
{
	size_t max_size_class;

	max_size_class = get_max_size_class();

	assert_u_eq(size2index(max_size_class+1), NSIZES,
	    "size2index() should return NSIZES on overflow");
	assert_u_eq(size2index(ZU(PTRDIFF_MAX)+1), NSIZES,
	    "size2index() should return NSIZES on overflow");
	assert_u_eq(size2index(SIZE_T_MAX), NSIZES,
	    "size2index() should return NSIZES on overflow");

	assert_zu_eq(s2u(max_size_class+1), 0,
	    "s2u() should return 0 for unsupported size");
	assert_zu_eq(s2u(ZU(PTRDIFF_MAX)+1), 0,
	    "s2u() should return 0 for unsupported size");
	assert_zu_eq(s2u(SIZE_T_MAX), 0,
	    "s2u() should return 0 on overflow");

	assert_u_eq(psz2ind(max_size_class+1), NPSIZES,
	    "psz2ind() should return NPSIZES on overflow");
	assert_u_eq(psz2ind(ZU(PTRDIFF_MAX)+1), NPSIZES,
	    "psz2ind() should return NPSIZES on overflow");
	assert_u_eq(psz2ind(SIZE_T_MAX), NPSIZES,
	    "psz2ind() should return NPSIZES on overflow");

	assert_zu_eq(psz2u(max_size_class+1), 0,
	    "psz2u() should return 0 for unsupported size");
	assert_zu_eq(psz2u(ZU(PTRDIFF_MAX)+1), 0,
	    "psz2u() should return 0 for unsupported size");
	assert_zu_eq(psz2u(SIZE_T_MAX), 0,
	    "psz2u() should return 0 on overflow");
}
Exemple #4
0
/*
 * Round down to the nearest chunk size that can actually be requested during
 * normal huge allocation.
 */
JEMALLOC_INLINE_C size_t
extent_quantize(size_t size)
{
	size_t ret;
	szind_t ind;

	assert(size > 0);

	ind = size2index(size + 1);
	if (ind == 0) {
		/* Avoid underflow. */
		return (index2size(0));
	}
	ret = index2size(ind - 1);
	assert(ret <= size);
	return (ret);
}
Exemple #5
0
static void
arena_large_dalloc_stats_update(arena_t *arena, size_t usize)
{
	szind_t index, hindex;

	cassert(config_stats);

	if (usize < LARGE_MINCLASS)
		usize = LARGE_MINCLASS;
	index = size2index(usize);
	hindex = (index >= NBINS) ? index - NBINS : 0;

	arena->stats.ndalloc_large++;
	arena->stats.allocated_large -= usize;
	arena->stats.lstats[hindex].ndalloc++;
	arena->stats.lstats[hindex].curlextents--;
}