process/vm; replace vm_range list by a rbtree

This replaces the chained list used to keep track of all memory ranges
of a process by a standard rbtree (no need of interval tree here
because there is no overlap)

Accesses that were done directly through vm_range_list before were
replaced by lookup_process_memory_range, even full list scan (e.g.
coredump).
The full scans will thus be less efficient because calls to rb_next()
will not be inlined, but these are rarer calls that can probably afford
this compared to code simplicity.

The only reference to the actual backing structure left outside of
process.c is a call to rb_erase in xpmem_free_process_memory_range.

v2: fix lookup_process_memory_range with small start address

v3: make vm_range_insert error out properly

Panic does not lead to easy debug, all error paths
are handled to just return someting on error

v4: fix lookup_process_memory_range (again)

That optimistically going left was a more serious bug than just
last iteration, we could just pass by a match and continue down
the tree if the match was not a leaf.

v5: some users actually needed leftmost match, so restore behavior
without the breakage (hopefully)
This commit is contained in:
Dominique Martinet
2017-09-12 16:43:46 +09:00
parent 99da5b6484
commit 4d4279121b
11 changed files with 191 additions and 132 deletions

View File

@ -19,6 +19,7 @@
#include <ihk/mm.h>
#include <ihk/atomic.h>
#include <list.h>
#include <rbtree.h>
#include <signal.h>
#include <memobj.h>
#include <affinity.h>
@ -377,7 +378,7 @@ struct user
#define AUXV_LEN 18
struct vm_range {
struct list_head list;
struct rb_node vm_rb_node;
unsigned long start, end;
unsigned long flag;
struct memobj *memobj;
@ -695,7 +696,7 @@ struct thread {
struct process_vm {
struct address_space *address_space;
struct list_head vm_range_list;
struct rb_root vm_range_tree;
struct vm_regions region;
struct process *proc; /* process that reside on the same page */
void *opt;