Skip to content

[k2] add separate memory for coroutines - #1675

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

[k2] add separate memory for coroutines#1675
LLirikkkk wants to merge 40 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
Comment thread runtime-common/core/allocator/details/malloc-interface.h Outdated
Comment thread runtime-common/core/allocator/details/malloc-interface.h Outdated
Comment thread runtime-common/core/allocator/details/pool-allocator.h Outdated
Comment thread runtime-common/core/allocator/details/pool-allocator.h Outdated
Comment thread runtime-common/core/allocator/runtime-allocator.h
Comment thread runtime-common/core/allocator/script-malloc-interface.h Outdated
Comment thread runtime-common/core/allocator/script-malloc-interface.h Outdated
Comment thread runtime-light/components/confdata/state/instance-state.h

namespace kphp::memory::details {

struct pool_allocator : private 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.

It may be worth making it public

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 <cstddef>

namespace kphp::memory::global {

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: kphp::memory::platform

@LLirikkkk LLirikkkk Aug 21, 2026

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

namespace kphp::memory::global {

auto alloc(size_t size) noexcept -> void*;
auto alloc0(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.

nit: calloc

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 alloc(size_t size) noexcept -> void*;
auto alloc0(size_t size) noexcept -> void*;
auto realloc(void* mem, size_t new_size, size_t old_size) noexcept -> void*;
auto free(void* mem, 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 malloc-like free 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.

added

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 get_memory_resource() noexcept -> memory_resource::unsynchronized_pool_resource&;

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.

Isn't it better to have this method defined here?

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:
static constexpr auto INIT_IMAGE_ALLOCATOR_SIZE = static_cast<size_t>(1024U * 1024U); // 1MiB
static constexpr auto INIT_IMAGE_ALLOCATOR_SIZE = static_cast<size_t>(1024U * 1024U); // 1MiB
static constexpr auto DEFAULT_MIN_EXTRA_MEMORY_POOL_SIZE = static_cast<size_t>(1024U * 1024U); // 1MiB

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.

Looks like DEFAULT_ is redundant here

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

Comment thread runtime-light/coroutine/event.h Outdated
// 3) empty list => the event is triggered and all coroutines are resumed
std::variant<std::monostate, vk::intrusive::list<vk::intrusive::list_node<std::coroutine_handle<>>>> m_state;

void* operator new(size_t n) noexcept {

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.

Does it really need to be allocated in coro memory?

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.

i think, you're right, let's move it to default memory

@LLirikkkk
LLirikkkk force-pushed the kkotliar/k2_add_coroutine_memory branch from 80eed40 to a784e3b Compare August 21, 2026 17:28
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