1 /* 2 * Copyright 2008, 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. 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 struct system_memory_info; 20 21 22 extern "C" { 23 void swap_init(void); 24 void swap_init_post_modules(void); 25 bool swap_free_page_swap_space(vm_page *page); 26 uint32 swap_available_pages(void); 27 uint32 swap_total_swap_pages(void); 28 } 29 30 31 class VMAnonymousCache : public VMCache { 32 public: 33 virtual ~VMAnonymousCache(); 34 35 status_t Init(bool canOvercommit, int32 numPrecommittedPages, 36 int32 numGuardPages); 37 38 virtual status_t Commit(off_t size); 39 virtual bool HasPage(off_t offset); 40 41 virtual status_t Read(off_t offset, const iovec *vecs, size_t count, 42 uint32 flags, size_t *_numBytes); 43 virtual status_t Write(off_t offset, const iovec *vecs, size_t count, 44 uint32 flags, size_t *_numBytes); 45 virtual status_t WriteAsync(off_t offset, const iovec* vecs, 46 size_t count, size_t numBytes, uint32 flags, 47 AsyncIOCallback* callback); 48 virtual bool CanWritePage(off_t offset); 49 50 virtual status_t Fault(struct vm_address_space *aspace, off_t offset); 51 52 virtual void Merge(VMCache* source); 53 54 private: 55 class WriteCallback; 56 friend class WriteCallback; 57 58 void _SwapBlockBuild(off_t pageIndex, 59 swap_addr_t slotIndex, uint32 count); 60 void _SwapBlockFree(off_t pageIndex, uint32 count); 61 swap_addr_t _SwapBlockGetAddress(off_t pageIndex); 62 status_t _Commit(off_t size); 63 64 private: 65 friend bool swap_free_page_swap_space(vm_page *page); 66 67 bool fCanOvercommit; 68 bool fHasPrecommitted; 69 uint8 fPrecommittedPages; 70 int32 fGuardedSize; 71 off_t fCommittedSwapSize; 72 off_t fAllocatedSwapSize; 73 }; 74 75 #endif // ENABLE_SWAP_SUPPORT 76 77 extern "C" void swap_get_info(struct system_memory_info *info); 78 79 #endif /* _KERNEL_VM_STORE_ANONYMOUS_H */ 80