+2005-10-12 Ulrich Drepper <drepper@redhat.com>
+
+ Correctly implement M_MXFAST.
+ * malloc/malloc.c (struct malloc_state): Replace max_fast with flags
+ fields.
+ (global_max_fast): New variable.
+ (set_max_fast): Change to not require arena parameter and to modify
+ global_max_fast. Change all callers.
+ (get_max_fast): New macro. Use this instead of directly accessing
+ now removed max_fast arena member.
+ (have_fastchunks): Use flags instead of max_fast.
+ (clear_fastchunks): Likewise.
+ (set_fastchunks): Likewise.
+ (contiguous): Likewise.
+ (noncontiguous): Likewise.
+ (set_noncontiguous): Likewise.
+ (set_contiguous): Likewise.
+ (malloc_init_state): Explicitly set FASTCHUNKS_BIT. Call set_max_fast
+ only for main arena.
+ * malloc/hooks.c (public_sET_STATe): Adjust set_max_fast use.
+
2005-10-10 Daniel Jacobowitz <dan@codesourcery.com>
* sysdeps/generic/bits/byteswap.h (__bswap_constant_16): New macro.
#define FASTCHUNKS_BIT (1U)
-#define have_fastchunks(M) (((M)->max_fast & FASTCHUNKS_BIT) == 0)
-#define clear_fastchunks(M) ((M)->max_fast |= FASTCHUNKS_BIT)
-#define set_fastchunks(M) ((M)->max_fast &= ~FASTCHUNKS_BIT)
+#define have_fastchunks(M) (((M)->flags & FASTCHUNKS_BIT) == 0)
+#define clear_fastchunks(M) ((M)->flags |= FASTCHUNKS_BIT)
+#define set_fastchunks(M) ((M)->flags &= ~FASTCHUNKS_BIT)
/*
NONCONTIGUOUS_BIT indicates that MORECORE does not return contiguous
#define NONCONTIGUOUS_BIT (2U)
-#define contiguous(M) (((M)->max_fast & NONCONTIGUOUS_BIT) == 0)
-#define noncontiguous(M) (((M)->max_fast & NONCONTIGUOUS_BIT) != 0)
-#define set_noncontiguous(M) ((M)->max_fast |= NONCONTIGUOUS_BIT)
-#define set_contiguous(M) ((M)->max_fast &= ~NONCONTIGUOUS_BIT)
+#define contiguous(M) (((M)->flags & NONCONTIGUOUS_BIT) == 0)
+#define noncontiguous(M) (((M)->flags & NONCONTIGUOUS_BIT) != 0)
+#define set_noncontiguous(M) ((M)->flags |= NONCONTIGUOUS_BIT)
+#define set_contiguous(M) ((M)->flags &= ~NONCONTIGUOUS_BIT)
/*
Set value of max_fast.
Setting the value clears fastchunk bit but preserves noncontiguous bit.
*/
-#define set_max_fast(M, s) \
- (M)->max_fast = (((s) == 0)? SMALLBIN_WIDTH: request2size(s)) | \
- FASTCHUNKS_BIT | \
- ((M)->max_fast & NONCONTIGUOUS_BIT)
+#define set_max_fast(s) \
+ global_max_fast = ((s) == 0)? SMALLBIN_WIDTH: request2size(s)
+#define get_max_fast() global_max_fast
/*
struct malloc_state {
/* Serialize access. */
mutex_t mutex;
- // Should we have padding to move the mutex to its own cache line?
+
+ /* Flags (formerly in max_fast). */
+ int flags;
#if THREAD_STATS
/* Statistics for locking. Only used if THREAD_STATS is defined. */
long stat_lock_direct, stat_lock_loop, stat_lock_wait;
#endif
- /* The maximum chunk size to be eligible for fastbin */
- INTERNAL_SIZE_T max_fast; /* low 2 bits used as flags */
-
/* Fastbins */
mfastbinptr fastbins[NFASTBINS];
static struct malloc_par mp_;
+
+/* Maximum size of memory handled in fastbins. */
+static INTERNAL_SIZE_T global_max_fast;
+
/*
Initialize a malloc_state struct.
if (av != &main_arena)
#endif
set_noncontiguous(av);
-
- set_max_fast(av, DEFAULT_MXFAST);
+ if (av == &main_arena)
+ set_max_fast(DEFAULT_MXFAST);
+ av->flags |= FASTCHUNKS_BIT;
av->top = initial_top(av);
}
/* properties of fastbins */
/* max_fast is in allowed range */
- assert((av->max_fast & ~1) <= request2size(MAX_FAST_SIZE));
+ assert((get_max_fast () & ~1) <= request2size(MAX_FAST_SIZE));
- max_fast_bin = fastbin_index(av->max_fast);
+ max_fast_bin = fastbin_index(get_max_fast ());
for (i = 0; i < NFASTBINS; ++i) {
p = av->fastbins[i];
can try it without checking, which saves some time on this fast path.
*/
- if ((unsigned long)(nb) <= (unsigned long)(av->max_fast)) {
+ if ((unsigned long)(nb) <= (unsigned long)(get_max_fast ())) {
long int idx = fastbin_index(nb);
fb = &(av->fastbins[idx]);
if ( (victim = *fb) != 0) {
and used quickly in malloc.
*/
- if ((unsigned long)(size) <= (unsigned long)(av->max_fast)
+ if ((unsigned long)(size) <= (unsigned long)(get_max_fast ())
#if TRIM_FASTBINS
/*
yet been initialized, in which case do so below
*/
- if (av->max_fast != 0) {
+ if (get_max_fast () != 0) {
clear_fastchunks(av);
unsorted_bin = unsorted_chunks(av);
reused anyway.
*/
- maxfb = &(av->fastbins[fastbin_index(av->max_fast)]);
+ maxfb = &(av->fastbins[fastbin_index(get_max_fast ())]);
fb = &(av->fastbins[0]);
do {
if ( (p = *fb) != 0) {
switch(param_number) {
case M_MXFAST:
if (value >= 0 && value <= MAX_FAST_SIZE) {
- set_max_fast(av, value);
+ set_max_fast(value);
}
else
res = 0;