AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
kvmem.h File Reference

Go to the source code of this file.

Data Structures

struct  malloc_type
 A malloc type: what an allocation is for, which /proc/kvmem counts by. More...

Macros

#define SLAB_MIN   16
#define SLAB_MAX   1024
#define SLAB_CLASSES   7
#define M_ZERO   0x0001
#define MALLOC_DECLARE(type)
#define MALLOC_DEFINE(type, _name, _desc)

Functions

void * kmalloc (size_t size, struct malloc_type *type, int flags)
 Allocates memory for one of the kernel's structures.
void kfree (void *)
 Frees an object that kmalloc() gave.

Macro Definition Documentation

◆ M_ZERO

◆ MALLOC_DECLARE

#define MALLOC_DECLARE ( type)
Value:
extern struct malloc_type (type)

Definition at line 29 of file kvmem.h.

◆ MALLOC_DEFINE

#define MALLOC_DEFINE ( type,
_name,
_desc )
Value:
struct malloc_type (type) = {.name = (_name), .desc = (_desc)}

Definition at line 30 of file kvmem.h.

◆ SLAB_CLASSES

#define SLAB_CLASSES   7

Definition at line 9 of file kvmem.h.

◆ SLAB_MAX

#define SLAB_MAX   1024

Definition at line 8 of file kvmem.h.

Referenced by kmalloc(), and kvmem_selftest_run().

◆ SLAB_MIN

#define SLAB_MIN   16

Definition at line 7 of file kvmem.h.

Referenced by slab_alloc(), and slab_class().

Function Documentation

◆ kfree()

void kfree ( void * ptr)

Frees an object that kmalloc() gave.

Freeing anything else (a pointer into an object, or one freed already) is a bug, and panics.

Parameters
ptrthe object, or NULL to do nothing

Definition at line 146 of file kvmem.c.

References kfree(), kvmem, kvmem_obj_cnt, kvmem_unmap(), kvmem_used, malloc_type::nr, panic, printk(), slab_free(), slab_owns(), malloc_type::total, vmem_find(), and vmem_free().

Referenced by __arch_cur_thread_kill(), aarch64_fpsimd_drop(), aarch64_thread_new(), acpi_map(), arch_kthread_create(), arch_proc_fork(), arch_sigcode_map(), arch_thread_create(), arch_thread_kill(), at_lookup(), at_path(), ata_partition(), bcache_remove(), binfmt_elf_load_segments(), binfmt_fmt_load(), blkcache_read(), blkcache_write(), cpio_new_node(), cpio_root_node(), creat_path(), dentry_update(), dequeue(), devpts_init(), do_linkat(), do_mknodat(), do_openat(), do_unlinkat(), entry_remove(), exec_script(), exec_script_args(), exec_strings_free(), ext2_block_alloc(), ext2_block_free(), ext2_close(), ext2_dentry_create(), ext2_dentry_find(), ext2_indirect_block_get(), ext2_inode_alloc(), ext2_inode_block_read(), ext2_inode_free(), ext2_load(), ext2_read(), ext2_readdir(), ext2_trunc(), ext2_vmknod(), ext2_write(), file_put(), flush_block(), free_tokens(), free_tree(), hashmap_free(), hashmap_grow(), hashmap_insert(), hashmap_new(), hashmap_node_remove(), irq_uninstall(), kdev_blk_io(), kdev_bread(), kdev_bwrite(), kfree(), kthread_create(), kvmem_selftest_run(), link_path(), minix_inode_build(), minix_load(), minix_read(), minix_trunc(), minix_write(), pf_anon(), pf_object(), pf_zero(), pgrp_release(), pipefs_close(), pipefs_pfree(), pipefs_pipe(), pmap_create(), pmap_release(), pmap_release(), pmap_release(), poll_unregister(), proc_execve(), proc_fork(), proc_kill(), proc_new(), proc_reap(), proc_setpgid(), proc_threads_end(), procfs_close(), procfs_read(), pseudofs_close(), pseudofs_vlink(), pseudofs_vmknod(), pseudofs_vrename(), ptm_close(), pty_free(), pty_new(), queue_node_remove(), queue_remove(), ringbuf_free(), ringbuf_new(), seg_merge(), session_new(), sigcode_in(), socket_inet_create(), socket_inet_shutdown(), socket_tcp_create(), socket_tcp_shutdown(), socket_unix_accept(), socket_unix_bind(), socket_unix_connect(), socket_unix_shutdown(), sys_accept(), sys_chdir(), sys_execve(), sys_getcwd(), sys_mmap(), sys_mount(), sys_munmap(), sys_pipe(), sys_poll(), sys_readlinkat(), sys_renameat(), sys_socket(), sys_symlinkat(), sys_thread_join(), table_alloc(), tcp_pcb_free(), tcp_pcb_new(), thread_create(), thread_new(), tmpfs_close(), tmpfs_mount(), tmpfs_trunc(), tmpfs_write(), tokenize(), tty_new(), tty_release(), uart_8250_attach(), upath_get(), vfs_file_lock_release(), vfs_link(), vfs_lookup_parent(), vfs_mknod(), vfs_mount(), vfs_mount_root_dev(), vfs_remove(), vfs_rename(), vm_anon_copy(), vm_anon_decref(), vm_anon_destroy(), vm_anon_new(), vm_object_vnode(), vm_space_destroy(), vm_space_fork(), vnode_page_in(), vnode_pages_free(), vnode_pages_update(), vt_term_init(), walk(), and x86_smp_init().

◆ kmalloc()

void * kmalloc ( size_t size,
struct malloc_type * type,
int flags )

Allocates memory for one of the kernel's structures.

Parameters
sizethe size wanted, in bytes
typethe malloc type it's counted as (MALLOC_DEFINE())
flagsM_ZERO to have it zeroed, or 0
Returns
the object, or NULL if there was no memory for it

Definition at line 123 of file kvmem.c.

References kmalloc(), kvmem_alloc(), M_ZERO, malloc_types, memset(), NULL, malloc_type::qnode, slab_alloc(), and SLAB_MAX.

Referenced by aarch64_fpsimd_fork(), aarch64_fpsimd_trap(), aarch64_thread_new(), acpi_map(), arch_kthread_create(), arch_proc_fork(), arch_proc_init(), arch_sigcode_map(), arch_thread_create(), ata_partition(), bcache_insert(), binfmt_fmt_load(), blkcache_read(), blkcache_write(), block_new(), copy_fds(), cpio_new_node(), cpio_root_node(), creat_path(), dentry_update(), devfs_init(), devpts_init(), enqueue(), enqueue_head(), exec_script_args(), exec_strings_get(), ext2_block_alloc(), ext2_block_free(), ext2_dentry_create(), ext2_dentry_find(), ext2_indirect_block_get(), ext2_inode_alloc(), ext2_inode_block_read(), ext2_inode_build(), ext2_inode_free(), ext2_load(), ext2_read(), ext2_readdir(), ext2_trunc(), ext2_vmknod(), ext2_write(), file_new(), flush_block(), free_tree(), hashmap_grow(), hashmap_insert(), hashmap_new(), irq_install(), kdev_blk_io(), kdev_bread(), kdev_bwrite(), kmalloc(), kproc_init(), kvmem_guardtest(), kvmem_selftest_run(), link_path(), load_ramdisk(), minix_bcache_get(), minix_inode_build(), minix_load(), minix_read(), minix_trunc(), minix_write(), pf_anon(), pf_object(), pf_zero(), pipefs_end(), pipefs_mkpipe(), pmap_alloc(), pmap_alloc(), pmap_create(), poll_register(), proc_execve(), proc_init(), proc_new(), proc_setpgid(), procfs_init(), procfs_read(), procfs_vget(), pseudofs_vlink(), pseudofs_vmknod(), ptm_new(), pty_new(), queue_new(), ringbuf_new(), session_new(), sigcode_in(), socket_inet_create(), socket_tcp_accept(), socket_tcp_create(), socket_unix_accept(), socket_unix_bind(), socket_unix_connect(), socket_unix_create(), strdup(), sys_getcwd(), sys_poll(), sys_readlinkat(), table_alloc(), tcp_pcb_new(), thread_new(), tmpfs_mount(), tmpfs_trunc(), tmpfs_write(), tokenize(), tty_new(), uart_8250_attach(), upath_get(), vfs_file_flock(), vfs_install(), vfs_mount(), vfs_mount_root_dev(), vm_anon_new(), vm_entry_new(), vm_object_vnode(), vm_space_fork(), vm_space_insert(), vmem_alloc(), vmem_init(), vnode_page_in(), vnode_pages_update(), vt_probe(), vt_term_init(), walk(), x86_fpu_load_from(), x86_fpu_trap(), and x86_smp_init().