From: DJ Delorie <dj@redhat.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH] malloc: Remove bin scanning from memalign (bug 30723)
Date: Mon, 14 Aug 2023 16:49:25 -0400 [thread overview]
Message-ID: <xnsf8lnycq.fsf@greed.delorie.com> (raw)
In-Reply-To: <87y1iearj2.fsf@oldenburg.str.redhat.com> (message from Florian Weimer on Mon, 14 Aug 2023 11:42:57 +0200)
Florian Weimer <fweimer@redhat.com> writes:
> On the test workload (mpv --cache=yes with VP9 video decoding), the
> bin scanning has a very poor success rate (less than 2%). The tcache
> scanning has about 50% success rate, so keep that.
>
> Update comments in malloc/tst-memalign-2 to indicate the purpose
> of the tests. Even with the scanning removed, the additional
> merging opportunities since commit 542b1105852568c3ebc712225ae78b
> ("malloc: Enable merging of remainders in memalign (bug 30723)")
> are sufficient to pass the existing large bins test.
>
> Remove leftover variables from _int_free from refactoring in the
> same commit.
LGTM
Reviewed-by: DJ Delorie <dj@redhat.com>
> - mchunkptr nextchunk; /* next contiguous chunk */
> - INTERNAL_SIZE_T nextsize; /* its size */
> - int nextinuse; /* true if nextchunk is used */
> - INTERNAL_SIZE_T prevsize; /* size of previous contiguous chunk */
> - mchunkptr bck; /* misc temp for linking */
> - mchunkptr fwd; /* misc temp for linking */
No longer needed in this scope, ok.
> @@ -5032,42 +5026,6 @@ _int_realloc (mstate av, mchunkptr oldp, INTERNAL_SIZE_T oldsize,
> ------------------------------ memalign ------------------------------
> */
>
> -/* Returns 0 if the chunk is not and does not contain the requested
> - aligned sub-chunk, else returns the amount of "waste" from
> - trimming. NB is the *chunk* byte size, not the user byte
> - size. */
> -static size_t
> -chunk_ok_for_memalign (mchunkptr p, size_t alignment, size_t nb)
> -{
> . . .
> -}
Only used for bin scanning, so no longer needed. Ok.
> - mchunkptr victim;
No longer needed, ok.
> - /* This will be set if we found a candidate chunk. */
> - victim = NULL;
> + /* Call malloc with worst case padding to hit alignment. */
> + m = (char *) (_int_malloc (av, nb + alignment + MINSIZE));
Consistent with what the remaining code expects, ok.
> + if (m == 0)
> + return 0; /* propagate failure */
Ok.
> - /* Fast bins are singly-linked, hard to remove a chunk from the middle
> - and unlikely to meet our alignment requirements. We have not done
> - any experimentation with searching for aligned fastbins. */
> - if (av != NULL)
> - {
> . . .
> - }
Ok.
> - /* Strategy: find a spot within that chunk that meets the alignment
> - request, and then possibly free the leading and trailing space.
> - This strategy is incredibly costly and can lead to external
> - fragmentation if header and footer chunks are unused. */
> -
> - if (victim != NULL)
> - {
> - p = victim;
> - m = chunk2mem (p);
> - set_inuse (p);
> - if (av != &main_arena)
> - set_non_main_arena (p);
> - }
> - else
> - {
> - /* Call malloc with worst case padding to hit alignment. */
> -
> - m = (char *) (_int_malloc (av, nb + alignment + MINSIZE));
> -
> - if (m == 0)
> - return 0; /* propagate failure */
> -
> - p = mem2chunk (m);
> - }
No longer needed, ok.
> + p = mem2chunk (m);
Ok.
> diff --git a/malloc/tst-memalign-2.c b/malloc/tst-memalign-2.c
> index f229283dbf..ecd6fa249e 100644
> --- a/malloc/tst-memalign-2.c
> +++ b/malloc/tst-memalign-2.c
> @@ -86,7 +86,8 @@ do_test (void)
> TEST_VERIFY (tcache_allocs[i].ptr1 == tcache_allocs[i].ptr2);
> }
>
> - /* Test for non-head tcache hits. */
> + /* Test for non-head tcache hits. This exercises the memalign
> + scanning code to find matching allocations. */
> for (i = 0; i < array_length (ptr); ++ i)
> {
> if (i == 4)
> @@ -113,7 +114,9 @@ do_test (void)
> free (p);
> TEST_VERIFY (count > 0);
>
> - /* Large bins test. */
> + /* Large bins test. This verifies that the over-allocated parts
> + that memalign releases for future allocations can be reused by
> + memalign itself at least in some cases. */
>
> for (i = 0; i < LN; ++ i)
> {
Ok.
next prev parent reply other threads:[~2023-08-14 20:49 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-14 9:42 Florian Weimer
2023-08-14 20:49 ` DJ Delorie [this message]
-- strict thread matches above, loose matches on Subject: below --
2023-08-10 17:36 Florian Weimer
2023-08-10 18:04 ` DJ Delorie
2023-08-11 7:20 ` Florian Weimer
2023-08-11 23:14 ` DJ Delorie
2023-08-21 14:01 ` Sam James
2023-08-21 14:45 ` Florian Weimer
2023-08-11 8:54 ` Maxim Kuvyrkov
2023-08-11 9:14 ` Florian Weimer
2023-08-11 14:52 ` Florian Weimer
2023-08-12 6:52 ` Andreas Schwab
2023-08-12 13:23 ` Florian Weimer
2023-08-12 13:33 ` Florian Weimer
2023-08-12 14:50 ` Andreas Schwab
2023-08-14 2:14 ` Xi Ruoyao
2023-08-14 9:16 ` Florian Weimer
2023-08-15 11:58 ` Adhemerval Zanella Netto
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xnsf8lnycq.fsf@greed.delorie.com \
--to=dj@redhat.com \
--cc=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).