Compare commits
64 Commits
4d6ac5cf30
...
56066f332f
Author | SHA1 | Date | |
---|---|---|---|
56066f332f | |||
d535c10061 | |||
8b1632f443 | |||
ed826069e0 | |||
1b683ffd08 | |||
b95d495815 | |||
43061a099f | |||
a529c091f0 | |||
efd21c9a1c | |||
88a2e60ea2 | |||
7b55d594d1 | |||
2c3c5b8aea | |||
e3f31fb463 | |||
7159de0752 | |||
c430146c8b | |||
b7086dabf3 | |||
6d3fdec98a | |||
c3c1ce150e | |||
b3dbbbf257 | |||
537923a5bc | |||
944aa3f3e5 | |||
399edbcf0e | |||
bd4c123fdd | |||
0a3df694c1 | |||
887cc65461 | |||
2b7bb40d14 | |||
b25a9bda6e | |||
a4fde43d4f | |||
84060f2739 | |||
6bb7707e8d | |||
9f4a6639fc | |||
c7d7b9e1ac | |||
c9e172f1c3 | |||
4e1dee5e73 | |||
ad492b42fc | |||
88c09edf53 | |||
2d6300dd65 | |||
8cd8896a87 | |||
4910f55603 | |||
23f3e8822b | |||
fbeafc7ec2 | |||
bdfa05a398 | |||
42c398615a | |||
6599d1a9bd | |||
b83e68f6e1 | |||
d7ffc5f5a0 | |||
8a33aa9c86 | |||
9765a03321 | |||
ebbe755f51 | |||
0f9c5348dd | |||
0b3aac37c8 | |||
2b1ce2a8c0 | |||
de7f487039 | |||
5d6cfc882e | |||
d6c7092e4b | |||
7c86993896 | |||
e57a3ae23c | |||
2f37877644 | |||
4436ea2332 | |||
a0b94ecc6c | |||
4fe5d15ec1 | |||
3ac925a2d3 | |||
6783e9253e | |||
6c40cbd09f |
@ -47,7 +47,6 @@ luna_app(socket-client.cpp socket-client)
|
|||||||
luna_app(input.cpp input)
|
luna_app(input.cpp input)
|
||||||
luna_app(shmem-test.cpp shmem-test)
|
luna_app(shmem-test.cpp shmem-test)
|
||||||
luna_app(touch.cpp touch)
|
luna_app(touch.cpp touch)
|
||||||
luna_app(free.cpp free)
|
|
||||||
luna_app(gclient.cpp gclient)
|
luna_app(gclient.cpp gclient)
|
||||||
target_link_libraries(gclient PUBLIC ui)
|
target_link_libraries(gclient PUBLIC ui)
|
||||||
luna_app(taskbar.cpp taskbar)
|
luna_app(taskbar.cpp taskbar)
|
||||||
|
@ -1,50 +0,0 @@
|
|||||||
#include <luna/Units.h>
|
|
||||||
#include <os/ArgumentParser.h>
|
|
||||||
#include <os/File.h>
|
|
||||||
#include <sys/memstat.h>
|
|
||||||
|
|
||||||
Result<int> luna_main(int argc, char** argv)
|
|
||||||
{
|
|
||||||
bool reserved { false };
|
|
||||||
bool human_readable { false };
|
|
||||||
|
|
||||||
os::ArgumentParser parser;
|
|
||||||
parser.add_description("Query the amount of memory available and used in the system.");
|
|
||||||
parser.add_system_program_info("free"_sv);
|
|
||||||
parser.add_switch_argument(reserved, 'r', "show-reserved"_sv, "show reserved system memory"_sv);
|
|
||||||
parser.add_switch_argument(human_readable, 'h', "human-readable"_sv, "show output in human-readable units"_sv);
|
|
||||||
parser.parse(argc, argv);
|
|
||||||
|
|
||||||
struct membuf buf;
|
|
||||||
memstat(&buf);
|
|
||||||
|
|
||||||
if (human_readable)
|
|
||||||
{
|
|
||||||
auto total = TRY(to_dynamic_unit(buf.mem_total, 10, false, Unit::Binary, true));
|
|
||||||
auto free = TRY(to_dynamic_unit(buf.mem_free, 10, false, Unit::Binary, true));
|
|
||||||
auto used = TRY(to_dynamic_unit(buf.mem_used, 10, false, Unit::Binary, true));
|
|
||||||
|
|
||||||
os::println("%s total memory, out of which:", total.chars());
|
|
||||||
os::println("%s used", used.chars());
|
|
||||||
os::println("%s free", free.chars());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
os::println("%lu total memory, out of which:", buf.mem_total);
|
|
||||||
os::println("%lu used", buf.mem_used);
|
|
||||||
os::println("%lu free", buf.mem_free);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reserved)
|
|
||||||
{
|
|
||||||
if (human_readable)
|
|
||||||
{
|
|
||||||
auto reserved_string = TRY(to_dynamic_unit(buf.mem_reserved, 10, false, Unit::Binary, true));
|
|
||||||
|
|
||||||
os::println("%s reserved", reserved_string.chars());
|
|
||||||
}
|
|
||||||
else { os::println("%lu reserved", buf.mem_reserved); }
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -47,7 +47,6 @@ set(SOURCES
|
|||||||
src/sys/poll.cpp
|
src/sys/poll.cpp
|
||||||
src/sys/alarm.cpp
|
src/sys/alarm.cpp
|
||||||
src/sys/pledge.cpp
|
src/sys/pledge.cpp
|
||||||
src/sys/memstat.cpp
|
|
||||||
src/fs/VFS.cpp
|
src/fs/VFS.cpp
|
||||||
src/fs/Pipe.cpp
|
src/fs/Pipe.cpp
|
||||||
src/fs/Mount.cpp
|
src/fs/Mount.cpp
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include "fs/StorageCache.h"
|
#include "fs/StorageCache.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include <luna/Heap.h>
|
|
||||||
#include <luna/ScopeGuard.h>
|
#include <luna/ScopeGuard.h>
|
||||||
|
|
||||||
static LinkedList<StorageCache> g_storage_caches;
|
static LinkedList<StorageCache> g_storage_caches;
|
||||||
@ -24,13 +23,9 @@ Result<StorageCache::CacheEntry*> StorageCache::fetch_entry(u64 block)
|
|||||||
|
|
||||||
void StorageCache::clear()
|
void StorageCache::clear()
|
||||||
{
|
{
|
||||||
m_mutex.lock();
|
ScopedKMutexLock<100> lock(m_mutex);
|
||||||
|
|
||||||
kdbgln("cache: clearing %lu entries, out of %lu buckets", m_cache_entries.size(), m_cache_entries.capacity());
|
|
||||||
m_cache_entries.clear();
|
m_cache_entries.clear();
|
||||||
kdbgln("cache: done");
|
|
||||||
|
|
||||||
m_mutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StorageCache::StorageCache()
|
StorageCache::StorageCache()
|
||||||
|
@ -31,16 +31,6 @@ void reap_thread()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void oom_thread()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
kernel_wait_for_event();
|
|
||||||
// OOM! Do everything we can to recover memory.
|
|
||||||
StorageCache::clear_caches();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[[noreturn]] void init()
|
[[noreturn]] void init()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@ -68,10 +58,6 @@ void oom_thread()
|
|||||||
"Failed to create the process reaper kernel thread");
|
"Failed to create the process reaper kernel thread");
|
||||||
Scheduler::set_reap_thread(reap);
|
Scheduler::set_reap_thread(reap);
|
||||||
|
|
||||||
auto oom = mark_critical(Scheduler::new_kernel_thread(oom_thread, "[oom]"),
|
|
||||||
"Failed to create the out-of-memory kernel thread");
|
|
||||||
Scheduler::set_oom_thread(oom);
|
|
||||||
|
|
||||||
#ifdef ARCH_X86_64
|
#ifdef ARCH_X86_64
|
||||||
ATA::Controller::scan();
|
ATA::Controller::scan();
|
||||||
#endif
|
#endif
|
||||||
|
@ -146,9 +146,9 @@ namespace MemoryManager
|
|||||||
bool ok = frame_bitmap->find_and_toggle(false, start_index).try_set_value(index);
|
bool ok = frame_bitmap->find_and_toggle(false, start_index).try_set_value(index);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
{
|
{
|
||||||
kwarnln("OOM alert! Scheduling the OOM thread...");
|
kwarnln("OOM alert! Trying to free caches...");
|
||||||
Scheduler::signal_oom_thread();
|
StorageCache::clear_caches();
|
||||||
return err(ENOMEM);
|
if (!frame_bitmap->find_and_toggle(false, start_index).try_set_value(index)) return err(ENOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
start_index = index + 1;
|
start_index = index + 1;
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
#include "Pledge.h"
|
|
||||||
#include "memory/MemoryManager.h"
|
|
||||||
#include "sys/Syscall.h"
|
|
||||||
#include "thread/Scheduler.h"
|
|
||||||
#include <bits/memstat.h>
|
|
||||||
|
|
||||||
Result<u64> sys_memstat(Registers*, SyscallArgs args)
|
|
||||||
{
|
|
||||||
auto* current = Scheduler::current();
|
|
||||||
TRY(check_pledge(current, Promise::p_stdio));
|
|
||||||
|
|
||||||
struct membuf buf;
|
|
||||||
buf.mem_total = MemoryManager::total();
|
|
||||||
buf.mem_used = MemoryManager::used();
|
|
||||||
buf.mem_free = MemoryManager::free();
|
|
||||||
buf.mem_reserved = MemoryManager::reserved();
|
|
||||||
|
|
||||||
if (!MemoryManager::copy_to_user_typed((struct membuf*)args[0], &buf)) return err(EFAULT);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -13,7 +13,6 @@ static Thread g_idle;
|
|||||||
static Thread* g_current = nullptr;
|
static Thread* g_current = nullptr;
|
||||||
static Thread* g_init = nullptr;
|
static Thread* g_init = nullptr;
|
||||||
static Thread* g_reap = nullptr;
|
static Thread* g_reap = nullptr;
|
||||||
static Thread* g_oom = nullptr;
|
|
||||||
|
|
||||||
static const usize TICKS_PER_TIMESLICE = 20;
|
static const usize TICKS_PER_TIMESLICE = 20;
|
||||||
|
|
||||||
@ -71,17 +70,6 @@ namespace Scheduler
|
|||||||
if (g_reap) g_reap->wake_up();
|
if (g_reap) g_reap->wake_up();
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_oom_thread(Thread* thread)
|
|
||||||
{
|
|
||||||
g_oom = thread;
|
|
||||||
g_oom->unrestricted_task = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void signal_oom_thread()
|
|
||||||
{
|
|
||||||
if (g_oom) g_oom->wake_up();
|
|
||||||
}
|
|
||||||
|
|
||||||
Result<Thread*> new_kernel_thread_impl(Thread* thread, const char* name)
|
Result<Thread*> new_kernel_thread_impl(Thread* thread, const char* name)
|
||||||
{
|
{
|
||||||
// If anything fails, make sure to clean up.
|
// If anything fails, make sure to clean up.
|
||||||
@ -166,13 +154,8 @@ namespace Scheduler
|
|||||||
u64 argv = TRY(image->push_string_vector_on_stack(args));
|
u64 argv = TRY(image->push_string_vector_on_stack(args));
|
||||||
u64 envp = TRY(image->push_string_vector_on_stack(env));
|
u64 envp = TRY(image->push_string_vector_on_stack(env));
|
||||||
|
|
||||||
const u64 kernel_stack_base = TRY(MemoryManager::alloc_for_kernel(4, MMU::ReadWrite | MMU::NoExecute));
|
|
||||||
Stack kernel_stack { kernel_stack_base, 4 * ARCH_PAGE_SIZE };
|
|
||||||
|
|
||||||
guard.deactivate();
|
guard.deactivate();
|
||||||
|
|
||||||
thread->kernel_stack = kernel_stack;
|
|
||||||
|
|
||||||
image->apply(thread);
|
image->apply(thread);
|
||||||
thread->set_arguments(args.size(), argv, env.size(), envp);
|
thread->set_arguments(args.size(), argv, env.size(), envp);
|
||||||
|
|
||||||
@ -271,12 +254,8 @@ namespace Scheduler
|
|||||||
new_thread->ticks_left = 1; // The idle task only runs for 1 tick so we can check for new runnable tasks
|
new_thread->ticks_left = 1; // The idle task only runs for 1 tick so we can check for new runnable tasks
|
||||||
// as fast as possible.
|
// as fast as possible.
|
||||||
}
|
}
|
||||||
else if (new_thread->unrestricted_task)
|
else
|
||||||
{
|
new_thread->ticks_left = TICKS_PER_TIMESLICE;
|
||||||
check(new_thread->is_kernel);
|
|
||||||
new_thread->ticks_left = -1;
|
|
||||||
}
|
|
||||||
else { new_thread->ticks_left = TICKS_PER_TIMESLICE; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void switch_task(Registers* regs)
|
void switch_task(Registers* regs)
|
||||||
|
@ -13,9 +13,6 @@ namespace Scheduler
|
|||||||
void set_reap_thread(Thread*);
|
void set_reap_thread(Thread*);
|
||||||
void signal_reap_thread();
|
void signal_reap_thread();
|
||||||
|
|
||||||
void set_oom_thread(Thread*);
|
|
||||||
void signal_oom_thread();
|
|
||||||
|
|
||||||
Result<Thread*> new_kernel_thread(u64 address, const char* name);
|
Result<Thread*> new_kernel_thread(u64 address, const char* name);
|
||||||
Result<Thread*> new_kernel_thread(void (*func)(void), const char* name);
|
Result<Thread*> new_kernel_thread(void (*func)(void), const char* name);
|
||||||
Result<Thread*> new_kernel_thread(void (*func)(void*), void* arg, const char* name);
|
Result<Thread*> new_kernel_thread(void (*func)(void*), void* arg, const char* name);
|
||||||
|
@ -109,8 +109,6 @@ struct Thread : public LinkedListNode<Thread>
|
|||||||
sigset_t pending_signals { 0 };
|
sigset_t pending_signals { 0 };
|
||||||
bool interrupted { false };
|
bool interrupted { false };
|
||||||
|
|
||||||
bool unrestricted_task { false };
|
|
||||||
|
|
||||||
FPData fp_data;
|
FPData fp_data;
|
||||||
|
|
||||||
ThreadState state = ThreadState::Runnable;
|
ThreadState state = ThreadState::Runnable;
|
||||||
|
@ -33,7 +33,6 @@ set(SOURCES
|
|||||||
src/sys/utsname.cpp
|
src/sys/utsname.cpp
|
||||||
src/sys/mount.cpp
|
src/sys/mount.cpp
|
||||||
src/sys/pstat.cpp
|
src/sys/pstat.cpp
|
||||||
src/sys/memstat.cpp
|
|
||||||
src/sys/resource.cpp
|
src/sys/resource.cpp
|
||||||
src/sys/socket.cpp
|
src/sys/socket.cpp
|
||||||
src/sys/poll.cpp
|
src/sys/poll.cpp
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
/* bits/memstat.h: The membuf structure for memstat(). */
|
|
||||||
|
|
||||||
#ifndef _BITS_MEMSTAT_H
|
|
||||||
#define _BITS_MEMSTAT_H
|
|
||||||
|
|
||||||
struct membuf
|
|
||||||
{
|
|
||||||
unsigned long mem_total;
|
|
||||||
unsigned long mem_used;
|
|
||||||
unsigned long mem_free;
|
|
||||||
unsigned long mem_reserved;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,20 +0,0 @@
|
|||||||
/* sys/memstat.h: Memory usage querying. */
|
|
||||||
|
|
||||||
#ifndef _SYS_MEMSTAT_H
|
|
||||||
#define _SYS_MEMSTAT_H
|
|
||||||
|
|
||||||
#include <bits/memstat.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Query system memory usage. */
|
|
||||||
int memstat(struct membuf* mem);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,13 +0,0 @@
|
|||||||
#include <bits/errno-return.h>
|
|
||||||
#include <sys/memstat.h>
|
|
||||||
#include <sys/syscall.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
int memstat(struct membuf* buf)
|
|
||||||
{
|
|
||||||
long rc = syscall(SYS_memstat, buf);
|
|
||||||
__errno_return(rc, int);
|
|
||||||
}
|
|
||||||
}
|
|
@ -49,16 +49,6 @@ template <typename K, typename V> struct HashMap
|
|||||||
return m_table.try_remove(HashPair<K, V> { key, {} });
|
return m_table.try_remove(HashPair<K, V> { key, {} });
|
||||||
}
|
}
|
||||||
|
|
||||||
usize capacity() const
|
|
||||||
{
|
|
||||||
return m_table.capacity();
|
|
||||||
}
|
|
||||||
|
|
||||||
usize size() const
|
|
||||||
{
|
|
||||||
return m_table.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
m_table.clear();
|
m_table.clear();
|
||||||
|
@ -101,23 +101,10 @@ template <typename T> class HashTable
|
|||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
if (m_capacity)
|
for (usize i = 0; i < m_capacity; i++) m_buckets[i].~Option();
|
||||||
{
|
|
||||||
for (usize i = 0; i < m_capacity; i++) m_buckets[i].~Option();
|
|
||||||
|
|
||||||
free_impl(m_buckets);
|
free_impl(m_buckets);
|
||||||
m_capacity = m_size = 0;
|
m_capacity = m_size = 0;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
usize capacity() const
|
|
||||||
{
|
|
||||||
return m_capacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
usize size() const
|
|
||||||
{
|
|
||||||
return m_size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~HashTable()
|
~HashTable()
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
_e(umount) _e(pstat) _e(getrusage) _e(symlinkat) _e(readlinkat) _e(umask) _e(linkat) _e(faccessat) \
|
_e(umount) _e(pstat) _e(getrusage) _e(symlinkat) _e(readlinkat) _e(umask) _e(linkat) _e(faccessat) \
|
||||||
_e(pivot_root) _e(sigreturn) _e(sigaction) _e(kill) _e(sigprocmask) _e(setpgid) _e(isatty) \
|
_e(pivot_root) _e(sigreturn) _e(sigaction) _e(kill) _e(sigprocmask) _e(setpgid) _e(isatty) \
|
||||||
_e(getpgid) _e(socket) _e(bind) _e(connect) _e(listen) _e(accept) _e(poll) _e(msync) \
|
_e(getpgid) _e(socket) _e(bind) _e(connect) _e(listen) _e(accept) _e(poll) _e(msync) \
|
||||||
_e(truncate) _e(ftruncate) _e(utimensat) _e(alarm) _e(pledge) _e(memstat)
|
_e(truncate) _e(ftruncate) _e(utimensat) _e(alarm) _e(pledge)
|
||||||
|
|
||||||
enum Syscalls
|
enum Syscalls
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user