Bug 209360 - Can bmalloc work on systems with 64 kB pages?
Summary: Can bmalloc work on systems with 64 kB pages?
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: bmalloc (show other bugs)
Version: WebKit Nightly Build
Hardware: PC Linux
: P2 Normal
Assignee: Nobody
: 200566 (view as bug list)
Depends on:
Blocks: 209670
  Show dependency treegraph
Reported: 2020-03-20 13:35 PDT by Michael Catanzaro
Modified: 2021-09-28 13:53 PDT (History)
8 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Michael Catanzaro 2020-03-20 13:35:56 PDT
Currently, WebKitFeatures.cmake enables bmalloc on aarch64, x86_64, arm, and mips. All other architectures build with USE_SYSTEM_MALLOC=ON.

It seems one of the reasons that bmalloc does not work on many CPU architectures is that it doesn't support systems with 64 kB page size. We can be confident of this because bmalloc on aarch64 works in Fedora (which uses 4 kB pages) but not in RHEL (64 kB pages).

Looking through bmalloc for potentially-problematic places, I found configSizeToProtect in Gigacage.h set to 16 kB, which is too small. I also found in Sizes.h:

static constexpr size_t smallLineSize = 256;
static constexpr size_t smallPageSize = 4 * kB;
static constexpr size_t smallPageLineCount = smallPageSize / smallLineSize;

static constexpr size_t maskSizeClassMax = 512;
static constexpr size_t smallMax = 32 * kB;

static constexpr size_t pageSizeMax = smallMax * 2;
static constexpr size_t pageClassCount = pageSizeMax / smallPageSize;

I guess we would need to raise smallPageSize and smallMax both to 64 kB?

Before I try this, are there any other theoretical problems that would stop bmalloc from working on a given CPU architecture? Are there page size assumptions anywhere else? Does it make endianness assumptions?
Comment 1 Yusuke Suzuki 2020-03-31 17:16:01 PDT
If you change these values, please do not change them in the existing architectures.
We are tuning performance / memory-consumption heavily on the current numbers.
Comment 2 Saam Barati 2020-03-31 17:56:46 PDT
I don't think that's right, since malloc is already tuned to 16kb pages. It's not obvious setting "smallPageSize" to 64kb actually makes bmalloc better
Comment 3 Yusuke Suzuki 2020-03-31 20:26:18 PDT
(In reply to Saam Barati from comment #2)
> I don't think that's right, since malloc is already tuned to 16kb pages.
> It's not obvious setting "smallPageSize" to 64kb actually makes bmalloc
> better

physical page size and smallPageSize are different concept, no?

" smallPageSize is now unrelated to the OS's page size -- it just reflects the optimal unit of memory to recycle between small objects."
Comment 4 Saam Barati 2020-03-31 21:20:27 PDT
Your question is a more general one: does bmalloc work with 64kb pages.

Why wouldn’t it? I’d guess the only thing needing to be changed is “configSizeToProtect” in Gigacage

In the previous bug where you reference this bug, you say this is a bmalloc issue. What exactly is the issue?
Comment 5 Michael Catanzaro 2020-04-01 07:31:22 PDT
Saam left some additional hints here:

Comment 6 Michael Catanzaro 2020-05-15 14:26:27 PDT
*** Bug 200566 has been marked as a duplicate of this bug. ***
Comment 7 Michael Catanzaro 2020-10-20 16:31:35 PDT
Carlos Lopez found there is also ConfigAlignment and another ConfigSizeToProtect in mbmalloc.cpp.