Skip to content

New alloca#43

Open
Km1zZzoU wants to merge 21 commits into
masterfrom
new-alloca
Open

New alloca#43
Km1zZzoU wants to merge 21 commits into
masterfrom
new-alloca

Conversation

@Km1zZzoU
Copy link
Copy Markdown
Collaborator

new allocator and refactoring

@Km1zZzoU Km1zZzoU requested review from chronorose and Copilot August 27, 2025 10:35
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new allocator system with a garbage collector and refactors the memory management architecture. The changes implement a hierarchical allocator with thread management, garbage collection capabilities, and a more sophisticated arena-based memory allocation system.

Key changes include:

  • Introduction of a hierarchical allocator (HAllocator) with garbage collection support
  • New thread management system with mutable/immutable phases and thread pools
  • Replacement of simple Object trait with a concrete Object struct containing size and bitset information

Reviewed Changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
runtime/src/utils/object.rs Defines new Object struct with size and bitset fields
runtime/src/utils/mod.rs Introduces reg type alias and exports Object utilities
runtime/src/threads/threadpool.rs Implements ThreadPool for managing worker threads with state transitions
runtime/src/threads/nthread.rs Defines thread state management with phases and contexts
runtime/src/threads/mod.rs Main thread management interface with stop-the-world coordination
runtime/src/gc/mod.rs Core garbage collector implementation with mark-and-sweep algorithm
runtime/src/gc/markqueue.rs Queue system for GC marking phase
runtime/src/lib.rs Main runtime interface with initialization and allocation functions
runtime/src/alloca/mod.rs Refactored allocator module exports and test updates
runtime/src/alloca/hedgearena.rs Enhanced arena implementation with GC support
runtime/src/alloca/hallocator.rs Hierarchical allocator with tiered block management
runtime/src/alloca/cfg.rs Configuration system for allocator parameters
runtime/src/alloca/arena.rs Updated Arena3 trait with new lifecycle methods
runtime/src/alloca/allocator.rs Simplified allocator trait interface

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread runtime/src/threads/threadpool.rs
Comment thread runtime/src/threads/threadpool.rs
Comment thread runtime/src/gc/mod.rs
Comment thread runtime/src/gc/mod.rs
Comment thread runtime/src/gc/mod.rs Outdated
Comment thread runtime/src/alloca/hallocator.rs
Comment thread runtime/src/lib.rs Outdated
Comment thread runtime/src/alloca/mod.rs Outdated
Comment thread runtime/src/alloca/cfg.rs
Comment thread runtime/src/alloca/mod.rs
Comment on lines +79 to 88
fn alloc3() {
let mut aa = HAllocator::new(config1());
let inst = Object {
size: 48,
bitset: &[0],
};
for i in 0..100_000_000 {
test_alloc(&inst, &mut aa);
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

не проходит если поставить размер >=64

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

при i in 0..2048 ещё всё хорошо а на 2049 уже ломается

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

пофиксил

Comment thread runtime/src/gc/markqueue.rs Outdated
Comment on lines +25 to +33
pub fn popn(&self, n: usize) -> Vec<MarkQueueElement> {
let mut lock = self.queue.write().expect("popn");
let bound = min(lock.len(), n);
let mut result = vec![];
for _ in 0..bound {
result.push(lock.pop().expect("popn copy"));
}
result
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

не с той стороны

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

пофиксил

Comment thread runtime/src/gc/mod.rs
Comment on lines +34 to +58
pub struct Gc<U: Arena3 + Send + Sync + 'static> {
pub alloca: Arc<Mutex<alloca::HAllocator<U>>>,

threads: Arc<Mutex<threads::Threads>>,

stw_is_done: Arc<Mutex<bool>>,
stw_cv: Arc<std::sync::Condvar>,

heap_is_done: Arc<Mutex<bool>>,
heap_cv: Arc<std::sync::Condvar>,

mark_is_done: Arc<Mutex<bool>>,
mark_cv: Arc<std::sync::Condvar>,

root_is_done: Arc<Mutex<bool>>,
root_cv: Arc<std::sync::Condvar>,

work_is_done: Arc<Mutex<bool>>,
work_cv: Arc<std::sync::Condvar>,
workers: Vec<JoinHandle<()>>,
count_active_workers: Arc<AtomicUsize>,

root: Arc<Vec<ptr>>,
mark_queue: Arc<MarkQueue>,
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

чето не юзается много че

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

убрал

Comment thread runtime/src/gc/mod.rs Outdated
Comment on lines +121 to +123
if !(local_queue.len() & 15 == 0) {
// TODO: make somethink like cfg
(*thread_mark_queue).pushn(&mut local_queue);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

:trollface:

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

пофиксил

Comment thread runtime/src/gc/mod.rs
Comment on lines +151 to +167
loop {
if (*thread_mark_queue).last_is_end() {
thread_count_active_workers.fetch_add(1, Ordering::SeqCst);
{
let mut work_is_done_flag =
thread_work_is_done.lock().unwrap();
while !*work_is_done_flag {
work_is_done_flag =
thread_work_cv.wait(work_is_done_flag).unwrap()
}
}
break 'external;
} else {
local_queue = (*thread_mark_queue).popn(16);
break;
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

:trollface:

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

там кстати все таки нужен этот луп, там если в очередь не попал конец, и при этом в ней никого нет, то надо покрутиться

Comment thread runtime/src/gc/mod.rs
@Km1zZzoU Km1zZzoU requested a review from chronorose August 27, 2025 19:04
@Km1zZzoU
Copy link
Copy Markdown
Collaborator Author

Pull Request Overview

This PR introduces a new allocator system with a garbage collector and refactors the memory management architecture. The changes implement a hierarchical allocator with thread management, garbage collection capabilities, and a more sophisticated arena-based memory allocation system.

Key changes include:

* Introduction of a hierarchical allocator (`HAllocator`) with garbage collection support

* New thread management system with mutable/immutable phases and thread pools

* Replacement of simple Object trait with a concrete Object struct containing size and bitset information

Reviewed Changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 8 comments.
Show a summary per file

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

я пофиксил, го новое ревью

@Km1zZzoU Km1zZzoU requested review from chronorose and removed request for chronorose August 27, 2025 19:06
@Km1zZzoU
Copy link
Copy Markdown
Collaborator Author

соре за спам :3

@battlemag3
Copy link
Copy Markdown

Ревью нэ будэ

Comment thread runtime/src/gc/mod.rs
}
}

'external: loop {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

а че экстернал не ушёл в итоге

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

потому что все таки не ушел внутрений цикл который в else, потому что там есть кейс, в котором надо нихуя не делать и сидеть ждать конец

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

надо этот цикл разнести по методам постараться наверное всё таки, слишком крепко

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

попозже посмотрю че куда можно будет

Comment thread runtime/src/gc/mod.rs Outdated
Comment on lines +119 to +121
while local_queue.len() > 0 {
Self::mark(thread_alloca.clone(), local_queue.pop_front().unwrap());
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

учитывая что это локальная история это просто фолд

Comment on lines +29 to +33
let bound = min(lock.len(), n);
let mut result = VecDeque::new();
for _ in 0..bound {
result.push_back(lock.pop_front().expect("popn copy"));
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

0..min(lock.len(), n).map(|_| lock.pop_front().expect(...))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Не выебывайся

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

дело вкуса

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ну конкретно тут то не только дело вкуса ибо оно ресайзится никогда не будет с мапом, а вот с циклом не факт

Comment thread runtime/src/gc/mod.rs
Comment on lines +86 to +93
let thread_root_is_done = self.root_is_done.clone();
let thread_root_cv = self.root_cv.clone();
let mut thread_root = self.root.clone();
let thread_alloca = self.alloca.clone();
let thread_mark_queue = self.mark_queue.clone().clone();
let thread_count_active_workers = self.count_active_workers.clone();
let thread_mark_is_done = self.mark_is_done.clone();
let thread_mark_cv = self.mark_cv.clone();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

может это в отдельный стракт какой-то логический и просто клонить его сразу весь?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

не вижу смысл, тут либо вынести сигнальное говно, но там есть мьютекс+кондд вар которые не нужны именно треду, можно вынести то, что нужно треду, но аллока, count_active_workers и тд нужны не только воркерам, + все равно эти 8 строчек надо будет перенести в метод клон, будто мы все равно метод останется едва читаемым

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

не, там задерайвить клон можно будет просто, не нужно будет писать эти строчки

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

так пусть будут нужны никто же не забирает, пусть они просто вместе в одном стракте лежать будут а так останутся на месте

Comment thread runtime/src/gc/mod.rs Outdated
let mut local_queue = VecDeque::new();

let count_for_scan = thread_root.len() / count + 1;
for j in min(i * count_for_scan, thread_root.len())..thread_root.len() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

этот min наверное стоит вынести перед циклом всё таки, для уверенности в завтрашнем дне

Comment thread runtime/src/gc/mod.rs Outdated
}

local_queue = (*thread_mark_queue).popn(16);
if local_queue.len() == 0 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is_empty или как-то по другому но точно есть чето такое

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yep

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants