Fix some issues uncovered by the spawn stress test.

This commit is contained in:
Andreas Kling 2018-12-26 22:02:24 +01:00
parent f6179ad9f9
commit 3f3535213b
5 changed files with 9 additions and 7 deletions

View file

@ -164,6 +164,7 @@ public:
void unchecked_append(T&& value)
{
ASSERT((size() + 1) <= capacity());
new (m_impl->slot(m_impl->m_size)) T(move(value));
++m_impl->m_size;
}

View file

@ -189,7 +189,8 @@ void ProcFS::remove_process(Process& process)
InterruptDisabler disabler;
auto pid = process.pid();
auto it = m_pid2inode.find(pid);
ASSERT(it != m_pid2inode.end());
if (it == m_pid2inode.end())
return;
bool success = remove_file((*it).value);
ASSERT(success);
m_pid2inode.remove(pid);

View file

@ -690,7 +690,8 @@ Process::~Process()
ProcFS::the().remove_process(*this);
system.nprocess--;
gdt_free_entry(selector());
if (selector())
gdt_free_entry(selector());
if (m_kernelStack) {
kfree(m_kernelStack);

View file

@ -34,7 +34,7 @@ word gdt_alloc_entry()
void gdt_free_entry(word entry)
{
s_gdt_freelist->append(entry);
s_gdt_freelist->unchecked_append(entry);
}
extern "C" void handle_irq();

View file

@ -36,14 +36,13 @@ Keyboard* keyboard;
static void spawn_stress() NORETURN;
static void spawn_stress()
{
dword lastAlloc = sum_alloc;
dword last_sum_alloc = sum_alloc;
for (unsigned i = 0; i < 10000; ++i) {
int error;
Process::create_user_process("/bin/true", (uid_t)100, (gid_t)100, (pid_t)0, error, Vector<String>(), Vector<String>(), tty0);
kprintf("malloc stats: alloc:%u free:%u eternal:%u ", sum_alloc, sum_free, kmalloc_sum_eternal);
kprintf("delta:%u\n", sum_alloc - lastAlloc);
lastAlloc = sum_alloc;
dbgprintf("malloc stats: alloc:%u free:%u eternal:%u !delta:%u\n", sum_alloc, sum_free, kmalloc_sum_eternal, sum_alloc - last_sum_alloc);
last_sum_alloc = sum_alloc;
sleep(60);
}
for (;;) {