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 uint32 flags, size_t *_numBytes); 43 virtual status_t WriteAsync(off_t offset, const iovec* vecs, 44 size_t count, size_t numBytes, uint32 flags, 45 AsyncIOCallback* callback); 46 47 virtual status_t Fault(struct vm_address_space *aspace, off_t offset); 48 49 virtual void Merge(VMCache* source); 50 51 private: 52 class WriteCallback; 53 friend class WriteCallback; 54 55 void _SwapBlockBuild(off_t pageIndex, 56 swap_addr_t slotIndex, uint32 count); 57 void _SwapBlockFree(off_t pageIndex, uint32 count); 58 swap_addr_t _SwapBlockGetAddress(off_t pageIndex); 59 status_t _Commit(off_t size); 60 61 private: 62 friend bool swap_free_page_swap_space(vm_page *page); 63 64 bool fCanOvercommit; 65 bool fHasPrecommitted; 66 uint8 fPrecommittedPages; 67 int32 fGuardedSize; 68 off_t fCommittedSwapSize; 69 off_t fAllocatedSwapSize; 70 }; 71 72 #endif // ENABLE_SWAP_SUPPORT 73 74 #endif /* _KERNEL_VM_STORE_ANONYMOUS_H */ 75