proc: slab allocate proc structs

This commit is contained in:
Michael Shaw 2023-11-22 21:29:15 -05:00
commit 83731d6eab
2 changed files with 6 additions and 2 deletions

View file

@ -52,6 +52,7 @@ struct proc {
spinlock_t page_map_lock; spinlock_t page_map_lock;
struct rbtree fd_map; struct rbtree fd_map;
spinlock_t fd_map_lock;
}; };
struct procregs *proc_current_regs(); struct procregs *proc_current_regs();

View file

@ -8,6 +8,7 @@
#include <fs/vfs.h> #include <fs/vfs.h>
static slab_t *proc_slab;
static struct rbtree *proc_tree; static struct rbtree *proc_tree;
static pid_t *proc_current; static pid_t *proc_current;
@ -63,7 +64,7 @@ void proc_term(pid_t pid)
struct proc *proc = (void *)proc_node->value; struct proc *proc = (void *)proc_node->value;
rbt_delete(proc_tree, proc_node); rbt_delete(proc_tree, proc_node);
kfree(proc); slab_free(proc_slab, proc);
} else { } else {
kprintf(LOG_ERROR "proc: proc_term: proc %u not found\n", pid); kprintf(LOG_ERROR "proc: proc_term: proc %u not found\n", pid);
panic(); panic();
@ -104,7 +105,8 @@ static int proc_insert_charfd(struct proc *proc, int fdno, int flags)
struct proc *proc_create() struct proc *proc_create()
{ {
struct proc *proc = kzalloc(sizeof(struct proc), ALLOC_KERN); struct proc *proc = slab_alloc(proc_slab);
memset(proc, 0, sizeof(struct proc));
proc->pid = rbt_next_key(proc_tree); proc->pid = rbt_next_key(proc_tree);
proc->is_kernel = false; proc->is_kernel = false;
@ -135,6 +137,7 @@ void proc_init(unsigned num_cpus)
/* allocate current process structs */ /* allocate current process structs */
proc_current = kzalloc(num_cpus * sizeof(pid_t), ALLOC_KERN); proc_current = kzalloc(num_cpus * sizeof(pid_t), ALLOC_KERN);
proc_tree = kzalloc(sizeof(struct rbtree), ALLOC_KERN); proc_tree = kzalloc(sizeof(struct rbtree), ALLOC_KERN);
proc_slab = slab_create(sizeof(struct proc), 32 * KB, 0);
for (unsigned i = 0; i < num_cpus; i++) { for (unsigned i = 0; i < num_cpus; i++) {
proc_current[i] = -1; proc_current[i] = -1;