Moved VMCache related definitions to <vm/VMCache.h>.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34535 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2009-12-07 14:14:21 +00:00
parent 74e2b87511
commit be7328a9f6
8 changed files with 181 additions and 171 deletions
+166
View File
@@ -1,4 +1,5 @@
/*
* Copyright 2008-2009, Ingo Weinhold, [email protected].
* Copyright 2003-2007, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License.
*
@@ -11,11 +12,175 @@
#include <kernel.h>
#include <vm/vm.h>
#include <vm/vm_types.h>
#include "kernel_debug_config.h"
struct kernel_args;
enum {
CACHE_TYPE_RAM = 0,
CACHE_TYPE_VNODE,
CACHE_TYPE_DEVICE,
CACHE_TYPE_NULL
};
struct VMCachePagesTreeDefinition {
typedef page_num_t KeyType;
typedef vm_page NodeType;
static page_num_t GetKey(const NodeType* node)
{
return node->cache_offset;
}
static SplayTreeLink<NodeType>* GetLink(NodeType* node)
{
return &node->cache_link;
}
static int Compare(page_num_t key, const NodeType* node)
{
return key == node->cache_offset ? 0
: (key < node->cache_offset ? -1 : 1);
}
static NodeType** GetListLink(NodeType* node)
{
return &node->cache_next;
}
};
typedef IteratableSplayTree<VMCachePagesTreeDefinition> VMCachePagesTree;
struct VMCache {
public:
VMCache();
virtual ~VMCache();
status_t Init(uint32 cacheType);
virtual void Delete();
bool Lock()
{ return mutex_lock(&fLock) == B_OK; }
bool TryLock()
{ return mutex_trylock(&fLock) == B_OK; }
bool SwitchLock(mutex* from)
{ return mutex_switch_lock(from, &fLock)
== B_OK; }
void Unlock();
void AssertLocked()
{ ASSERT_LOCKED_MUTEX(&fLock); }
void AcquireRefLocked();
void AcquireRef();
void ReleaseRefLocked();
void ReleaseRef();
void ReleaseRefAndUnlock()
{ ReleaseRefLocked(); Unlock(); }
vm_page* LookupPage(off_t offset);
void InsertPage(vm_page* page, off_t offset);
void RemovePage(vm_page* page);
void AddConsumer(VMCache* consumer);
status_t InsertAreaLocked(VMArea* area);
status_t RemoveArea(VMArea* area);
status_t WriteModified();
status_t SetMinimalCommitment(off_t commitment);
status_t Resize(off_t newSize);
status_t FlushAndRemoveAllPages();
// for debugging only
mutex* GetLock()
{ return &fLock; }
int32 RefCount() const
{ return fRefCount; }
// backing store operations
virtual status_t Commit(off_t size);
virtual bool HasPage(off_t offset);
virtual status_t Read(off_t offset, const iovec *vecs, size_t count,
uint32 flags, size_t *_numBytes);
virtual status_t Write(off_t offset, const iovec *vecs, size_t count,
uint32 flags, size_t *_numBytes);
virtual status_t WriteAsync(off_t offset, const iovec* vecs,
size_t count, size_t numBytes, uint32 flags,
AsyncIOCallback* callback);
virtual bool CanWritePage(off_t offset);
virtual int32 MaxPagesPerWrite() const
{ return -1; } // no restriction
virtual int32 MaxPagesPerAsyncWrite() const
{ return -1; } // no restriction
virtual status_t Fault(struct VMAddressSpace *aspace,
off_t offset);
virtual void Merge(VMCache* source);
virtual status_t AcquireUnreferencedStoreRef();
virtual void AcquireStoreRef();
virtual void ReleaseStoreRef();
private:
inline bool _IsMergeable() const;
void _MergeWithOnlyConsumer();
void _RemoveConsumer(VMCache* consumer);
public:
struct VMArea* areas;
struct list_link consumer_link;
struct list consumers;
// list of caches that use this cache as a source
VMCachePagesTree pages;
VMCache* source;
off_t virtual_base;
off_t virtual_end;
off_t committed_size;
// TODO: Remove!
uint32 page_count;
uint32 temporary : 1;
uint32 scan_skip : 1;
uint32 type : 6;
#if DEBUG_CACHE_LIST
struct VMCache* debug_previous;
struct VMCache* debug_next;
#endif
private:
int32 fRefCount;
mutex fLock;
};
#if DEBUG_CACHE_LIST
extern VMCache* gDebugCacheList;
#endif
class VMCacheFactory {
public:
static status_t CreateAnonymousCache(VMCache*& cache,
bool canOvercommit, int32 numPrecommittedPages,
int32 numGuardPages, bool swappable);
static status_t CreateVnodeCache(VMCache*& cache,
struct vnode* vnode);
static status_t CreateDeviceCache(VMCache*& cache,
addr_t baseAddress);
static status_t CreateNullCache(VMCache*& cache);
};
#ifdef __cplusplus
extern "C" {
#endif
@@ -28,4 +193,5 @@ struct VMCache *vm_cache_acquire_locked_page_cache(struct vm_page *page,
}
#endif
#endif /* _KERNEL_VM_VM_CACHE_H */
-161
View File
@@ -125,166 +125,5 @@ enum {
PAGE_STATE_UNUSED
};
enum {
CACHE_TYPE_RAM = 0,
CACHE_TYPE_VNODE,
CACHE_TYPE_DEVICE,
CACHE_TYPE_NULL
};
struct VMCachePagesTreeDefinition {
typedef page_num_t KeyType;
typedef vm_page NodeType;
static page_num_t GetKey(const NodeType* node)
{
return node->cache_offset;
}
static SplayTreeLink<NodeType>* GetLink(NodeType* node)
{
return &node->cache_link;
}
static int Compare(page_num_t key, const NodeType* node)
{
return key == node->cache_offset ? 0
: (key < node->cache_offset ? -1 : 1);
}
static NodeType** GetListLink(NodeType* node)
{
return &node->cache_next;
}
};
typedef IteratableSplayTree<VMCachePagesTreeDefinition> VMCachePagesTree;
struct VMCache {
public:
VMCache();
virtual ~VMCache();
status_t Init(uint32 cacheType);
virtual void Delete();
bool Lock()
{ return mutex_lock(&fLock) == B_OK; }
bool TryLock()
{ return mutex_trylock(&fLock) == B_OK; }
bool SwitchLock(mutex* from)
{ return mutex_switch_lock(from, &fLock)
== B_OK; }
void Unlock();
void AssertLocked()
{ ASSERT_LOCKED_MUTEX(&fLock); }
void AcquireRefLocked();
void AcquireRef();
void ReleaseRefLocked();
void ReleaseRef();
void ReleaseRefAndUnlock()
{ ReleaseRefLocked(); Unlock(); }
vm_page* LookupPage(off_t offset);
void InsertPage(vm_page* page, off_t offset);
void RemovePage(vm_page* page);
void AddConsumer(VMCache* consumer);
status_t InsertAreaLocked(VMArea* area);
status_t RemoveArea(VMArea* area);
status_t WriteModified();
status_t SetMinimalCommitment(off_t commitment);
status_t Resize(off_t newSize);
status_t FlushAndRemoveAllPages();
// for debugging only
mutex* GetLock()
{ return &fLock; }
int32 RefCount() const
{ return fRefCount; }
// backing store operations
virtual status_t Commit(off_t size);
virtual bool HasPage(off_t offset);
virtual status_t Read(off_t offset, const iovec *vecs, size_t count,
uint32 flags, size_t *_numBytes);
virtual status_t Write(off_t offset, const iovec *vecs, size_t count,
uint32 flags, size_t *_numBytes);
virtual status_t WriteAsync(off_t offset, const iovec* vecs,
size_t count, size_t numBytes, uint32 flags,
AsyncIOCallback* callback);
virtual bool CanWritePage(off_t offset);
virtual int32 MaxPagesPerWrite() const
{ return -1; } // no restriction
virtual int32 MaxPagesPerAsyncWrite() const
{ return -1; } // no restriction
virtual status_t Fault(struct VMAddressSpace *aspace,
off_t offset);
virtual void Merge(VMCache* source);
virtual status_t AcquireUnreferencedStoreRef();
virtual void AcquireStoreRef();
virtual void ReleaseStoreRef();
private:
inline bool _IsMergeable() const;
void _MergeWithOnlyConsumer();
void _RemoveConsumer(VMCache* consumer);
public:
struct VMArea* areas;
struct list_link consumer_link;
struct list consumers;
// list of caches that use this cache as a source
VMCachePagesTree pages;
VMCache* source;
off_t virtual_base;
off_t virtual_end;
off_t committed_size;
// TODO: Remove!
uint32 page_count;
uint32 temporary : 1;
uint32 scan_skip : 1;
uint32 type : 6;
#if DEBUG_CACHE_LIST
struct VMCache* debug_previous;
struct VMCache* debug_next;
#endif
private:
int32 fRefCount;
mutex fLock;
};
#if DEBUG_CACHE_LIST
extern VMCache* gDebugCacheList;
#endif
class VMCacheFactory {
public:
static status_t CreateAnonymousCache(VMCache*& cache,
bool canOvercommit, int32 numPrecommittedPages,
int32 numGuardPages, bool swappable);
static status_t CreateVnodeCache(VMCache*& cache,
struct vnode* vnode);
static status_t CreateDeviceCache(VMCache*& cache,
addr_t baseAddress);
static status_t CreateNullCache(VMCache*& cache);
};
#endif // _KERNEL_VM_VM_TYPES_H
+2 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2008, Ingo Weinhold, [email protected].
* Copyright 2008-2009, Ingo Weinhold, [email protected].
* Copyright 2004-2007, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License.
*/
@@ -7,7 +7,7 @@
#define VNODE_STORE_H
#include <vm/vm_types.h>
#include <vm/VMCache.h>
struct file_cache_ref;
+1
View File
@@ -22,6 +22,7 @@
#include <thread.h>
#include <vm/vm.h>
#include <vm/VMArea.h>
#include <vm/VMCache.h>
#include "VMKernelAddressSpace.h"
#include "VMUserAddressSpace.h"
+3 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2008, Ingo Weinhold, [email protected].
* Copyright 2008-2009, Ingo Weinhold, [email protected].
* Copyright 2004-2008, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License.
*
@@ -9,7 +9,8 @@
#ifndef _KERNEL_VM_STORE_ANONYMOUS_H
#define _KERNEL_VM_STORE_ANONYMOUS_H
#include <vm/vm_types.h>
#include <vm/VMCache.h>
#if ENABLE_SWAP_SUPPORT
@@ -1,5 +1,5 @@
/*
* Copyright 2008, Ingo Weinhold, [email protected].
* Copyright 2008-2009, Ingo Weinhold, [email protected].
* Copyright 2004-2007, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License.
*
@@ -9,7 +9,8 @@
#ifndef _KERNEL_VM_STORE_ANONYMOUS_NO_SWAP_H
#define _KERNEL_VM_STORE_ANONYMOUS_NO_SWAP_H
#include <vm/vm_types.h>
#include <vm/VMCache.h>
class VMAnonymousNoSwapCache : public VMCache {
+3 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2008, Ingo Weinhold, [email protected].
* Copyright 2008-2009, Ingo Weinhold, [email protected].
* Copyright 2005-2007, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License.
*
@@ -9,7 +9,8 @@
#ifndef _KERNEL_VM_STORE_DEVICE_H
#define _KERNEL_VM_STORE_DEVICE_H
#include <vm/vm_types.h>
#include <vm/VMCache.h>
class VMDeviceCache : public VMCache {
+3 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2008, Ingo Weinhold, [email protected].
* Copyright 2008-2009, Ingo Weinhold, [email protected].
* Copyright 2005-2007, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License.
*
@@ -9,7 +9,8 @@
#ifndef _KERNEL_VM_STORE_NULL_H
#define _KERNEL_VM_STORE_NULL_H
#include <vm/vm_types.h>
#include <vm/VMCache.h>
class VMNullCache : public VMCache {