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

Anons: the pages a process has written to, in one of its mappings. More...

#include <core/system.h>
#include <core/panic.h>
#include <mm/vm.h>

Go to the source code of this file.

Functions

static int vm_aref_eq (void *_a, void *_b)
 Says whether an aref is the one for an offset (_b, a size_t *), for the anon's hashmap.
struct vm_anon * vm_anon_new (void)
 Makes a new, empty anon.
void vm_aref_destroy (struct vm_aref *vm_aref)
 Releases what an aref holds.
void vm_aref_decref (struct vm_aref *vm_aref)
 Drops a reference to an aref.
void vm_anon_destroy (struct vm_anon *vm_anon)
 Releases an anon's arefs, and the pages of those that no other anon shares.
void vm_anon_incref (struct vm_anon *vm_anon)
 Adds a reference to an anon: another mapping shares it (a fork).
void vm_anon_decref (struct vm_anon *vm_anon)
 Drops a reference to an anon, and frees it with the last one.
static int vm_anon_copy_arefs (struct vm_anon *src, struct vm_anon *dst)
 Puts all of src's arefs in dst as well, shared: each gets one more reference.
struct vm_anon * vm_anon_copy (struct vm_anon *vm_anon)
 Makes a copy of an anon that shares its arefs, and so its pages, when a mapping's shared anon is written to after a fork.

Detailed Description

Anons: the pages a process has written to, in one of its mappings.

An anon (struct vm_anon) holds a mapping's private pages, each through an aref (struct vm_aref), keyed by its offset in the mapping. A fork shares the anon, and its arefs, between parent and child, copy on write: the first one to write a shared page gets its own copy (mm/fault.c). This is a simplified form of NetBSD's UVM amaps and anons.

Definition in file vm_anon.c.

Function Documentation

◆ vm_anon_copy()

struct vm_anon * vm_anon_copy ( struct vm_anon * vm_anon)

Makes a copy of an anon that shares its arefs, and so its pages, when a mapping's shared anon is written to after a fork.

The pages themselves are copied later, one by one, as they are written to.

Parameters
vm_anonthe anon to copy
Returns
the new anon, with one reference, or NULL if there was no memory for it

Definition at line 174 of file vm_anon.c.

References vm_anon::flags, kfree(), NULL, vm_anon::ref, vm_anon_copy(), vm_anon_copy_arefs(), vm_anon_destroy(), vm_anon_new(), and VM_COPY.

Referenced by pf_anon(), and vm_anon_copy().

◆ vm_anon_copy_arefs()

int vm_anon_copy_arefs ( struct vm_anon * src,
struct vm_anon * dst )
static

Puts all of src's arefs in dst as well, shared: each gets one more reference.

Returns 0, -EINVAL, or -ENOMEM if there was no memory for one; the arefs put in dst before that have their reference, and go with vm_anon_destroy(dst).

Definition at line 147 of file vm_anon.c.

References vm_anon::arefs, hashmap_node::entry, hashmap_node::hash, hashmap_for, vm_aref::ref, qnode::value, and vm_anon_copy_arefs().

Referenced by vm_anon_copy(), and vm_anon_copy_arefs().

◆ vm_anon_decref()

void vm_anon_decref ( struct vm_anon * vm_anon)

Drops a reference to an anon, and frees it with the last one.

Parameters
vm_anonthe anon (NULL does nothing)

Definition at line 130 of file vm_anon.c.

References kfree(), vm_anon::ref, vm_anon_decref(), and vm_anon_destroy().

Referenced by pf_anon(), vm_anon_decref(), and vm_entry_destroy().

◆ vm_anon_destroy()

void vm_anon_destroy ( struct vm_anon * vm_anon)

Releases an anon's arefs, and the pages of those that no other anon shares.

The anon's structure itself is freed by its caller.

Parameters
vm_anonthe anon (NULL does nothing)

Definition at line 85 of file vm_anon.c.

References vm_anon::arefs, hashmap_node::entry, hashmap_for, kfree(), mm_page_dealloc(), vm_page::paddr, vm_aref::ref, qnode::value, vm_anon_destroy(), vm_aref_decref(), and vm_aref::vm_page.

Referenced by vm_anon_copy(), vm_anon_decref(), and vm_anon_destroy().

◆ vm_anon_incref()

void vm_anon_incref ( struct vm_anon * vm_anon)

Adds a reference to an anon: another mapping shares it (a fork).

Parameters
vm_anonthe anon (NULL does nothing)

Definition at line 117 of file vm_anon.c.

References vm_anon::ref, and vm_anon_incref().

Referenced by vm_anon_incref(), and vm_space_fork().

◆ vm_anon_new()

struct vm_anon * vm_anon_new ( void )

Makes a new, empty anon.

Returns
the anon, with no references, or NULL if there was no memory

Definition at line 36 of file vm_anon.c.

References vm_anon::arefs, kfree(), kmalloc(), M_ZERO, NULL, vm_anon_new(), and vm_aref_eq().

Referenced by pf_object(), pf_zero(), vm_anon_copy(), and vm_anon_new().

◆ vm_aref_decref()

void vm_aref_decref ( struct vm_aref * vm_aref)

Drops a reference to an aref.

Parameters
vm_arefthe aref

Definition at line 74 of file vm_anon.c.

References vm_aref::ref, and vm_aref_decref().

Referenced by vm_anon_destroy(), and vm_aref_decref().

◆ vm_aref_destroy()

void vm_aref_destroy ( struct vm_aref * vm_aref)

Releases what an aref holds.

An aref holds nothing besides its page, which its anon frees, so this does nothing.

Parameters
vm_arefthe aref

Definition at line 64 of file vm_anon.c.

References vm_aref_destroy().

Referenced by vm_aref_destroy().

◆ vm_aref_eq()

int vm_aref_eq ( void * _a,
void * _b )
static

Says whether an aref is the one for an offset (_b, a size_t *), for the anon's hashmap.

An aref without a page is for no offset.

Definition at line 19 of file vm_anon.c.

References vm_page::off, vm_aref_eq(), and vm_aref::vm_page.

Referenced by vm_anon_new(), and vm_aref_eq().