提交 2db6c3ef 创建 作者: Austin Clements's avatar Austin Clements

Use distributed refcounts to free VMAs

This eliminates all reports of unexpected sharing except a few cases of honest-to-goodness memory reuse.
上级 f08c7712
...@@ -147,18 +147,11 @@ private: ...@@ -147,18 +147,11 @@ private:
}; };
class radix_elem : public rcu_freed { class radix_elem : public rcu_freed {
private:
std::atomic<u64> ref_;
public: public:
radix_elem() : rcu_freed("radix_elem"), ref_(0) {} radix_elem() : rcu_freed("radix_elem") {}
virtual ~radix_elem() {} virtual ~radix_elem() {}
void decref(u64 delta = 1) { virtual void decref(u64 delta = 1) = 0;
if ((ref_ -= delta) == 0) { virtual void incref(u64 delta = 1) = 0;
gc_delayed(this);
}
}
void incref(u64 delta = 1) { ref_ += delta; }
}; };
struct radix_node { struct radix_node {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "cpputil.hh" #include "cpputil.hh"
#include "hwvm.hh" #include "hwvm.hh"
#include "uwq.hh" #include "uwq.hh"
#include "distref.hh"
#define VM_CRANGE 0 #define VM_CRANGE 0
#define VM_RADIX 1 #define VM_RADIX 1
...@@ -53,7 +54,7 @@ struct vma ...@@ -53,7 +54,7 @@ struct vma
: public range : public range
#endif #endif
#if VM_RADIX #if VM_RADIX
: public radix_elem : public radix_elem, public distributed_refcnt
#endif #endif
{ {
const uptr vma_start; // start of mapping const uptr vma_start; // start of mapping
...@@ -64,8 +65,27 @@ struct vma ...@@ -64,8 +65,27 @@ struct vma
vma(vmap *vmap, uptr start, uptr end, enum vmatype vtype, vmnode *vmn); vma(vmap *vmap, uptr start, uptr end, enum vmatype vtype, vmnode *vmn);
~vma(); ~vma();
NEW_DELETE_OPS(vma);
virtual void do_gc() { delete this; } virtual void do_gc() { delete this; }
NEW_DELETE_OPS(vma)
#if VM_RADIX
void decref(u64 delta)
{
distref_dec(delta);
}
void incref(u64 delta)
{
distref_inc(delta);
}
private:
void distref_free()
{
gc_delayed(this);
}
#endif
}; };
class print_stream; class print_stream;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论