Patch by Zhao Shuai with changes by myself:

* Init swap support in main().
* Added "bool swappable" parameter to
  VMCacheFactory::CreateAnonymousCache(). A cache supporting swapping
  is created when true. Adjusted invocations accordingly.
* The page writer does now write non-locked swappable pages (when
  memory is low).
* Fixed header guard of VMAnonymousNoSwapCache.h.
* Swap support is compiled conditionally, controlled by the
  ENABLE_SWAP_SUPPORT in src/system/kernel/vm/VMAnonymousCache.h. It is
  disabled ATM. Since no swap files are added, it wouldn't have much
  effect anyway.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26625 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2008-07-24 23:33:38 +00:00
parent a6d2523e37
commit c586076dca
7 changed files with 60 additions and 11 deletions

View File

@ -50,6 +50,8 @@
#include <string.h>
#include "vm/VMAnonymousCache.h"
//#define TRACE_BOOT
#ifdef TRACE_BOOT
@ -185,6 +187,10 @@ _start(kernel_args *bootKernelArgs, int currentCPU)
notifications_init();
TRACE("init VFS\n");
vfs_init(&sKernelArgs);
#if ENABLE_SWAP_SUPPORT
TRACE("init swap support\n");
swap_init();
#endif
// bring up the AP cpus in a lock step fashion
TRACE("waking up AP cpus\n");

View File

@ -22,6 +22,9 @@
#include <util/DoublyLinkedList.h>
#include <util/OpenHashTable.h>
#if ENABLE_SWAP_SUPPORT
//#define TRACE_STORE
#ifdef TRACE_STORE
# define TRACE(x) dprintf x
@ -725,3 +728,5 @@ swap_init(void)
sAvailSwapSpace = 0;
}
#endif // ENABLE_SWAP_SUPPORT

View File

@ -12,6 +12,12 @@
#include <vm_types.h>
// uncomment to build in swap support
//#define ENABLE_SWAP_SUPPORT 1
#if ENABLE_SWAP_SUPPORT
typedef page_num_t swap_addr_t;
struct swap_block;
@ -49,4 +55,8 @@ private:
};
extern "C" void swap_init(void);
#endif // ENABLE_SWAP_SUPPORT
#endif /* _KERNEL_VM_STORE_ANONYMOUS_H */

View File

@ -6,8 +6,8 @@
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
* Distributed under the terms of the NewOS License.
*/
#ifndef _KERNEL_VM_STORE_ANONYMOUS_H
#define _KERNEL_VM_STORE_ANONYMOUS_H
#ifndef _KERNEL_VM_STORE_ANONYMOUS_NO_SWAP_H
#define _KERNEL_VM_STORE_ANONYMOUS_NO_SWAP_H
#include <vm_types.h>
@ -39,4 +39,4 @@ private:
};
#endif /* _KERNEL_VM_STORE_ANONYMOUS_H */
#endif /* _KERNEL_VM_STORE_ANONYMOUS_NO_SWAP_H */

View File

@ -1401,7 +1401,7 @@ map_backing_store(vm_address_space *addressSpace, vm_cache *cache,
// create an anonymous cache
status = VMCacheFactory::CreateAnonymousCache(newCache,
(protection & B_STACK_AREA) != 0, 0, USER_STACK_GUARD_PAGES);
(protection & B_STACK_AREA) != 0, 0, USER_STACK_GUARD_PAGES, true);
if (status != B_OK)
goto err1;
@ -1639,7 +1639,8 @@ vm_create_anonymous_area(team_id team, const char *name, void **address,
status = VMCacheFactory::CreateAnonymousCache(cache,
canOvercommit, isStack ? 2 : 0,
isStack ? ((protection & B_USER_PROTECTION) != 0 ?
USER_STACK_GUARD_PAGES : KERNEL_STACK_GUARD_PAGES) : 0);
USER_STACK_GUARD_PAGES : KERNEL_STACK_GUARD_PAGES) : 0,
wiring == B_NO_LOCK);
if (status != B_OK)
goto err1;
@ -2302,7 +2303,7 @@ vm_copy_on_write_area(vm_cache* lowerCache)
// create an anonymous cache
status_t status = VMCacheFactory::CreateAnonymousCache(upperCache, false, 0,
0);
0, true);
if (status != B_OK)
return status;

View File

@ -961,6 +961,7 @@ VMCache::_RemoveConsumer(VMCache* consumer)
#include <heap.h>
#include "VMAnonymousCache.h"
#include "VMAnonymousNoSwapCache.h"
#include "VMDeviceCache.h"
#include "VMNullCache.h"
@ -969,8 +970,28 @@ VMCache::_RemoveConsumer(VMCache* consumer)
/*static*/ status_t
VMCacheFactory::CreateAnonymousCache(VMCache*& _cache, bool canOvercommit,
int32 numPrecommittedPages, int32 numGuardPages)
int32 numPrecommittedPages, int32 numGuardPages, bool swappable)
{
#if ENABLE_SWAP_SUPPORT
if (swappable) {
VMAnonymousCache* cache = new(nogrow) VMAnonymousCache;
if (cache == NULL)
return B_NO_MEMORY;
status_t error = cache->Init(canOvercommit, numPrecommittedPages,
numGuardPages);
if (error != B_OK) {
cache->Delete();
return error;
}
T(Create(cache));
_cache = cache;
return B_OK;
}
#endif
VMAnonymousNoSwapCache* cache = new(nogrow) VMAnonymousNoSwapCache;
if (cache == NULL)
return B_NO_MEMORY;

View File

@ -989,10 +989,16 @@ page_writer(void* /*unused*/)
continue;
vm_cache *cache = page->cache;
// TODO: write back temporary ones as soon as we have swap file support
if (cache->temporary
/*&& low_resource_state(B_KERNEL_RESOURCE_PAGES)
== B_NO_LOW_RESOURCE*/) {
// Don't write back wired (locked) pages and don't write RAM pages
// until we're low on pages.
if (page->wired_count > 0
#if ENABLE_SWAP_SUPPORT
|| cache->temporary
&& low_resource_state(B_KERNEL_RESOURCE_PAGES)
== B_NO_LOW_RESOURCE
#endif
) {
continue;
}