btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / system / kernel / vm / VMAnonymousCache.h
blobb68800047c000388572315bd23c9d8b1ae9c7be1
1 /*
2 * Copyright 2008-2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2004-2008, Axel Dörfler, axeld@pinc-software.de.
4 * Distributed under the terms of the MIT License.
6 * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
7 * Distributed under the terms of the NewOS License.
8 */
9 #ifndef _KERNEL_VM_STORE_ANONYMOUS_H
10 #define _KERNEL_VM_STORE_ANONYMOUS_H
13 #include <vm/VMCache.h>
16 #if ENABLE_SWAP_SUPPORT
18 typedef uint32 swap_addr_t;
19 // TODO: Should be wider, but RadixBitmap supports only a 32 bit type ATM!
20 struct swap_block;
21 struct system_memory_info;
24 extern "C" {
25 void swap_init(void);
26 void swap_init_post_modules(void);
27 bool swap_free_page_swap_space(vm_page* page);
28 uint32 swap_available_pages(void);
29 uint32 swap_total_swap_pages(void);
33 class VMAnonymousCache : public VMCache {
34 public:
35 virtual ~VMAnonymousCache();
37 status_t Init(bool canOvercommit,
38 int32 numPrecommittedPages,
39 int32 numGuardPages,
40 uint32 allocationFlags);
42 virtual status_t Resize(off_t newSize, int priority);
44 virtual status_t Commit(off_t size, int priority);
45 virtual bool HasPage(off_t offset);
46 virtual bool DebugHasPage(off_t offset);
48 virtual int32 GuardSize() { return fGuardedSize; }
50 virtual status_t Read(off_t offset, const generic_io_vec* vecs,
51 size_t count, uint32 flags,
52 generic_size_t* _numBytes);
53 virtual status_t Write(off_t offset, const generic_io_vec* vecs,
54 size_t count, uint32 flags,
55 generic_size_t* _numBytes);
56 virtual status_t WriteAsync(off_t offset,
57 const generic_io_vec* vecs, size_t count,
58 generic_size_t numBytes, uint32 flags,
59 AsyncIOCallback* callback);
60 virtual bool CanWritePage(off_t offset);
62 virtual int32 MaxPagesPerAsyncWrite() const;
64 virtual status_t Fault(struct VMAddressSpace* aspace,
65 off_t offset);
67 virtual void Merge(VMCache* source);
69 protected:
70 virtual void DeleteObject();
72 private:
73 class WriteCallback;
74 friend class WriteCallback;
76 void _SwapBlockBuild(off_t pageIndex,
77 swap_addr_t slotIndex, uint32 count);
78 void _SwapBlockFree(off_t pageIndex, uint32 count);
79 swap_addr_t _SwapBlockGetAddress(off_t pageIndex);
80 status_t _Commit(off_t size, int priority);
82 void _MergePagesSmallerSource(
83 VMAnonymousCache* source);
84 void _MergePagesSmallerConsumer(
85 VMAnonymousCache* source);
86 void _MergeSwapPages(VMAnonymousCache* source);
88 private:
89 friend bool swap_free_page_swap_space(vm_page* page);
91 bool fCanOvercommit;
92 bool fHasPrecommitted;
93 uint8 fPrecommittedPages;
94 int32 fGuardedSize;
95 off_t fCommittedSwapSize;
96 off_t fAllocatedSwapSize;
99 #endif // ENABLE_SWAP_SUPPORT
102 extern "C" void swap_get_info(system_info* info);
105 #endif /* _KERNEL_VM_STORE_ANONYMOUS_H */