Skip to content

Conversation

@yiguolei
Copy link
Contributor

Proposed changes

  1. disable page cache by default
  2. disable chunk allocator by default
  3. not use chunk allocator for vectorized allocator by default
  4. add a new config memory_linear_growth_threshold = 128Mb, not allocate memory by RoundUpToPowerOf2 if the allocated size is larger than this threshold. This config is added to MemPool, ChunkAllocator, PodArray, Arena.

Problem summary

Describe your changes.

Checklist(Required)

  1. Does it affect the original behavior:
    • Yes
    • No
    • I don't know
  2. Has unit tests been added:
    • Yes
    • No
    • No Need
  3. Has document been added or modified:
    • Yes
    • No
    • No Need
  4. Does it need to update dependencies:
    • Yes
    • No
  5. Are there any changes that cannot be rolled back:
    • Yes (If Yes, please explain WHY)
    • No

Further comments

If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...

@xinyiZzz
Copy link
Contributor

xinyiZzz commented Oct 11, 2022

Gives the performance impact of disable page cache and disable chunk allocator, and the benefits of doing so, such as increasing OOM risk because they have no gc.

@xinyiZzz
Copy link
Contributor

xinyiZzz commented Oct 11, 2022

If want to discard the doris application layer cache. what is the replacement method?
such as, using optimized code + general memory allocator + system page cache

There are more application layer caches in doris, such as segment cache.

I think a self-managed application layer cache is necessary.
I think ultimately, an efficient and unified self-controllable cache is needed, rather than relying entirely on the system.

@xinyiZzz
Copy link
Contributor

Maybe we can discuss the idea of subsequent cache optimization~, I mentioned a proposal a long time ago
#9580

@yiguolei
Copy link
Contributor Author

Gives the performance impact of disable page cache and disable chunk allocator, and the benefits of doing so, such as increasing OOM risk because they have no gc.

  1. Currently, we use a hard limit for page cache(20%) or chunk allocator(10%), if the application need memory, there is no gc mechanism to collect memory from page cache or chunk allocator.
  2. page cache is very useful in some cases such as POC test, run benchmarks, some reporting secenarios. But in some cases like adhoc query, etl query, it is not very useful. And we have disable page cache in 1.1 and many company have disable page cache online such as xiaomi.
  3. chunk allocator impacts about 10% performance in clickbench test.

Doris's memory usage is not very stable, I want to disable them first, and try to fix other memory problems and then open them again. This may need about 2 months and there are many releases during this stage, so that I disable them like we have done in branch 1.1-lts.

@xinyiZzz
Copy link
Contributor

xinyiZzz commented Oct 13, 2022

Gives the performance impact of disable page cache and disable chunk allocator, and the benefits of doing so, such as increasing OOM risk because they have no gc.

  1. Currently, we use a hard limit for page cache(20%) or chunk allocator(10%), if the application need memory, there is no gc mechanism to collect memory from page cache or chunk allocator.
  2. page cache is very useful in some cases such as POC test, run benchmarks, some reporting secenarios. But in some cases like adhoc query, etl query, it is not very useful. And we have disable page cache in 1.1 and many company have disable page cache online such as xiaomi.
  3. chunk allocator impacts about 10% performance in clickbench test.

Doris's memory usage is not very stable, I want to disable them first, and try to fix other memory problems and then open them again. This may need about 2 months and there are many releases during this stage, so that I disable them like we have done in branch 1.1-lts.

I agree, page cache and chunk allocator may hide memory inelegant use on the code.

Later we can find a time to talk about the use of the cache

return Status::InternalError(ss.str());
}
chunk_reserved_bytes_limit =
BitUtil::RoundDown(chunk_reserved_bytes_limit, config::min_chunk_reserved_bytes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BitUtil::RoundDown(chunk_reserved_bytes_limit, 4096) here ensures that chunk_reserved_bytes_limit is a multiple of 4096

4096 is the minimum chunk size currently allocated by the chunk allocator

A separate conf min_chunk_reserved_bytes is not necessary, but RoundDown is meaningful

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes ... I will move back min_chunk_reserved_bytes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove min_chunk_reserved_bytes, const 4096 is fine, the user will not modify it
This knowledge suggests~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I remove it.

/// Not round up, keep the size just as the application pass in like std::vector
void alloc_for_num_elements(size_t num_elements) {
alloc(round_up_to_power_of_two_or_zero(minimum_memory_for_elements(num_elements)));
alloc(minimum_memory_for_elements(num_elements));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allocating in powers of 2 has a positive impact on performance, if you wish to reduce memory usage,

join #ifndef STRICT_MEMORY_USE, similar to hash_table.h expansion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think this should be a config, because if it is a config, we do not know when to open the config since it is a macro. Actually, there are two types of memory allocation in PODArray:

  1. reserve, sometimes the developer know the expected size of the array, then he should call reserve method to allocate the EXPECTED memory.
  2. push_back, the developer does not know the expected size of the array, then he just call push back to allocate memory. In this scenario, we should allocate memory using power of 2.

For most cases, we should reserve or resize memory size before push back, then we could reduce memory reallocation or memory copy.
This PR try to fix some problems. #13088.

CONF_Int32(min_chunk_reserved_bytes, "1024");

// Whether using chunk allocator to cache memory chunk
CONF_Bool(disable_chunk_allocator, "true");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disable_chunk_allocator_in_mem_pool

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I will remove mempool after we removed non-vectorized engine. MemPool is used as MemPool.cpp, it is like a arena. The config disable_mem_pools is also very confused. I will remove them.

DCHECK(chunk.core_id != -1);
CHECK((chunk.size & (chunk.size - 1)) == 0);
if (config::disable_mem_pools) {
if (config::disable_chunk_allocator) {
Copy link
Contributor

@xinyiZzz xinyiZzz Oct 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to move the condition into MemPool and rename disable_chunk_allocator_in_mem_pool, Similar to disable_chunk_allocator_in_vec

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not use this. I will remove disable_mem_pools in the future after non-vectorized engine is removed. It is very confused with MemPool.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try removing disable_chunk_allocator_in_vec and replace with disable_chunk_allocator. (more detailed config comments)

@yiguolei yiguolei force-pushed the forbidden_pagecache_default branch from e906afb to eb659d1 Compare October 14, 2022 06:11
@yiguolei yiguolei force-pushed the forbidden_pagecache_default branch from eb659d1 to f8ad6c0 Compare October 15, 2022 02:30
Copy link
Contributor

@xinyiZzz xinyiZzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Oct 15, 2022
@github-actions
Copy link
Contributor

PR approved by at least one committer and no changes requested.

@github-actions
Copy link
Contributor

PR approved by anyone and no changes requested.

@xinyiZzz xinyiZzz merged commit a5f3880 into apache:master Oct 15, 2022
Gabriel39 added a commit to Gabriel39/incubator-doris that referenced this pull request Oct 18, 2022
… optimize memory allocate size (apache#13285)"

This reverts commit a5f3880.
HappenLee added a commit to HappenLee/incubator-doris that referenced this pull request Oct 19, 2022
… optimize memory allocate size (apache#13285)"

This reverts commit a5f3880.
HappenLee added a commit to HappenLee/incubator-doris that referenced this pull request Oct 20, 2022
… optimize memory allocate size (apache#13285)"

This reverts commit a5f3880.
yiguolei pushed a commit that referenced this pull request Oct 21, 2022
)

* Revert "[fix](mem) failure of allocating memory (#13414)"

This reverts commit 971eb91.

* Revert "[improvement](memory) disable page cache and chunk allocator, optimize memory allocate size (#13285)"

This reverts commit a5f3880.
dataroaring pushed a commit that referenced this pull request Oct 21, 2022
)

* Revert "[fix](mem) failure of allocating memory (#13414)"

This reverts commit 971eb91.

* Revert "[improvement](memory) disable page cache and chunk allocator, optimize memory allocate size (#13285)"

This reverts commit a5f3880.
Conflicts:
	be/src/common/config.h
@morningman morningman mentioned this pull request Nov 21, 2022
@yiguolei yiguolei deleted the forbidden_pagecache_default branch March 30, 2023 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. area/vectorization reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants