Skip to content

[k2] add separate memory for coroutines - #1675

Open
LLirikkkk wants to merge 26 commits into
masterfrom
kkotliar/k2_add_coroutine_memory
Open

[k2] add separate memory for coroutines#1675
LLirikkkk wants to merge 26 commits into
masterfrom
kkotliar/k2_add_coroutine_memory

Conversation

@LLirikkkk

Copy link
Copy Markdown
Contributor

No description provided.

@LLirikkkk LLirikkkk self-assigned this Aug 11, 2026
@LLirikkkk LLirikkkk added optimization Memory comsumption / CPU speedup runtime Feature related to runtime k2 Affects compiler or runtime in K2 mode labels Aug 11, 2026
@LLirikkkk LLirikkkk added this to the next milestone Aug 11, 2026
@LLirikkkk
LLirikkkk marked this pull request as ready for review August 14, 2026 10:03
@LLirikkkk
LLirikkkk requested a review from apolyakov August 14, 2026 10:03

namespace memory {

namespace details {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: you can merge this into namespace kphp::memory::details {...}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed


constexpr uint64_t MALLOC_REPLACER_MAX_ALLOC = 0xFFFFFF00; // 4GiB

template<auto AllocatorGetter>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: auto get_allocator_func

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

auto realloc_script_memory(void* mem, size_t new_size, size_t old_size) noexcept -> void*;
auto free_script_memory(void* mem, size_t size) noexcept -> void;

auto alloc_global_memory(size_t size) noexcept -> void*;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need these global alloc functions here? They are not related to unsynchronized_pool_resource. If so, this allocator can even have an allocator-like interface: alloc, free, realloc, calloc


namespace kphp::memory::details {

struct PoolAllocator : vk::not_copyable {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: pool_allocator. Let's follow runtime-light's naming policy

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed


private:
void request_extra_memory(size_t requested_size) noexcept;
auto alloc_script_memory(size_t size) noexcept -> void*;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we have common implementations for some of these methods?

inline bool is_power_of_2(uint64_t v) noexcept {
return v && !(v & (v - 1));
inline auto alloc(size_t size) noexcept -> void* {
return details::malloc_interface<RuntimeAllocator::get>::alloc(size);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you please use fully qualified names? Otherwise this code isn't so obvious:

  1. ::details::malloc_interface
  2. kphp::details::malloc_interface
  3. kphp::memory::details::malloc_interface
  4. kphp::memory::script::details::malloc_interface

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

#include "runtime-common/core/allocator/runtime-allocator.h"
#include "runtime-common/core/utils/kphp-assert-core.h"

namespace kphp {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: namespace kphp::memory::script {...}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

auto init() noexcept -> void;

private:
static constexpr auto INIT_INSTANCE_ALLOCATOR_SIZE = static_cast<size_t>(16U * 1024U * 1024U); // 16MiB

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why did you change this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

reverted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

k2 Affects compiler or runtime in K2 mode optimization Memory comsumption / CPU speedup runtime Feature related to runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants