xref: /haiku/src/system/kernel/vm/VMAnonymousCache.h (revision b06a48ab8f30b45916a9c157b992827779182163)
1 /*
2  * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Copyright 2004-2007, Axel Dörfler, axeld@pinc-software.de.
4  * Distributed under the terms of the MIT License.
5  *
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
11 
12 #include <vm_types.h>
13 
14 
15 #if ENABLE_SWAP_SUPPORT
16 
17 typedef page_num_t swap_addr_t;
18 struct swap_block;
19 
20 extern "C" {
21 	void swap_init(void);
22 	void swap_init_post_modules(void);
23 	bool swap_free_page_swap_space(vm_page *page);
24 	uint32 swap_available_pages(void);
25 	uint32 swap_total_swap_pages(void);
26 }
27 
28 
29 class VMAnonymousCache : public VMCache {
30 public:
31 	virtual				~VMAnonymousCache();
32 
33 			status_t	Init(bool canOvercommit, int32 numPrecommittedPages,
34 							int32 numGuardPages);
35 
36 	virtual	status_t	Commit(off_t size);
37 	virtual	bool		HasPage(off_t offset);
38 
39 	virtual	status_t	Read(off_t offset, const iovec *vecs, size_t count,
40 							size_t *_numBytes);
41 	virtual	status_t	Write(off_t offset, const iovec *vecs, size_t count,
42 							size_t *_numBytes);
43 
44 	virtual	status_t	Fault(struct vm_address_space *aspace, off_t offset);
45 
46 	virtual	void		MergeStore(VMCache* source);
47 
48 private:
49 			void		_SwapBlockBuild(off_t pageIndex,
50 							swap_addr_t swapAddress, uint32 count);
51 			void        _SwapBlockFree(off_t pageIndex, uint32 count);
52 			swap_addr_t	_SwapBlockGetAddress(off_t pageIndex);
53 			status_t	_Commit(off_t size);
54 
55 private:
56 	friend bool swap_free_page_swap_space(vm_page *page);
57 
58 	bool	fCanOvercommit;
59 	bool	fHasPrecommitted;
60 	uint8	fPrecommittedPages;
61 	int32	fGuardedSize;
62 	off_t   fCommittedSwapSize;
63 	off_t   fAllocatedSwapSize;
64 };
65 
66 #endif	// ENABLE_SWAP_SUPPORT
67 
68 #endif	/* _KERNEL_VM_STORE_ANONYMOUS_H */
69