* Added debug output to vm_low_memory.cpp.

* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15568 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2005-12-16 17:35:03 +00:00
parent 2058e6c1d4
commit 89f5f72a15
6 changed files with 61 additions and 43 deletions

View File

@ -113,7 +113,7 @@ lookup_transaction(block_cache *cache, int32 id)
} }
// #pragma mark - private block_cache // #pragma mark - cached_block
/* static */ /* static */
@ -142,7 +142,7 @@ cached_block::Hash(void *_cacheEntry, const void *_block, uint32 range)
} }
// #pragma mark - // #pragma mark - block_cache
block_cache::block_cache(int _fd, off_t numBlocks, size_t blockSize) block_cache::block_cache(int _fd, off_t numBlocks, size_t blockSize)
@ -672,7 +672,7 @@ block_cache_init(void)
} }
// #pragma mark - public transaction // #pragma mark - public transaction API
extern "C" int32 extern "C" int32
@ -1032,7 +1032,7 @@ cache_blocks_in_sub_transaction(void *_cache, int32 id)
} }
// #pragma mark - public block cache // #pragma mark - public block cache API
// public interface // public interface

View File

@ -1436,7 +1436,7 @@ unload_kernel_add_on(image_id id)
status_t status_t
elf_init(kernel_args *ka) elf_init(kernel_args *args)
{ {
struct preloaded_image *image; struct preloaded_image *image;
@ -1451,11 +1451,11 @@ elf_init(kernel_args *ka)
// Build a image structure for the kernel, which has already been loaded. // Build a image structure for the kernel, which has already been loaded.
// The preloaded_images were already prepared by the VM. // The preloaded_images were already prepared by the VM.
if (insert_preloaded_image(&ka->kernel_image, true) < B_OK) if (insert_preloaded_image(&args->kernel_image, true) < B_OK)
panic("could not create kernel image.\n"); panic("could not create kernel image.\n");
// Build image structures for all preloaded images. // Build image structures for all preloaded images.
for (image = ka->preloaded_images; image != NULL; image = image->next) { for (image = args->preloaded_images; image != NULL; image = image->next) {
insert_preloaded_image(image, false); insert_preloaded_image(image, false);
} }

View File

@ -46,10 +46,10 @@
//#define TRACE_VFS //#define TRACE_VFS
#ifdef TRACE_VFS #ifdef TRACE_VFS
# define PRINT(x) dprintf x # define TRACE(x) dprintf x
# define FUNCTION(x) dprintf x # define FUNCTION(x) dprintf x
#else #else
# define PRINT(x) ; # define TRACE(x) ;
# define FUNCTION(x) ; # define FUNCTION(x) ;
#endif #endif
@ -704,7 +704,7 @@ dec_vnode_ref_count(struct vnode *vnode, bool reenter)
oldRefCount = atomic_add(&vnode->ref_count, -1); oldRefCount = atomic_add(&vnode->ref_count, -1);
PRINT(("dec_vnode_ref_count: vnode %p, ref now %ld\n", vnode, vnode->ref_count)); TRACE(("dec_vnode_ref_count: vnode %p, ref now %ld\n", vnode, vnode->ref_count));
if (oldRefCount == 1) { if (oldRefCount == 1) {
bool freeNode = false; bool freeNode = false;
@ -750,7 +750,7 @@ static void
inc_vnode_ref_count(struct vnode *vnode) inc_vnode_ref_count(struct vnode *vnode)
{ {
atomic_add(&vnode->ref_count, 1); atomic_add(&vnode->ref_count, 1);
PRINT(("inc_vnode_ref_count: vnode %p, ref now %ld\n", vnode, vnode->ref_count)); TRACE(("inc_vnode_ref_count: vnode %p, ref now %ld\n", vnode, vnode->ref_count));
} }
@ -810,7 +810,7 @@ restart:
goto restart; goto restart;
} }
PRINT(("get_vnode: tried to lookup vnode, got %p\n", vnode)); TRACE(("get_vnode: tried to lookup vnode, got %p\n", vnode));
status_t status; status_t status;
@ -844,7 +844,7 @@ restart:
mutex_unlock(&sVnodeMutex); mutex_unlock(&sVnodeMutex);
PRINT(("get_vnode: returning %p\n", vnode)); TRACE(("get_vnode: returning %p\n", vnode));
*_vnode = vnode; *_vnode = vnode;
return B_OK; return B_OK;
@ -881,7 +881,7 @@ put_vnode(struct vnode *vnode)
static void static void
vnode_low_memory_handler(void */*data*/, int32 level) vnode_low_memory_handler(void */*data*/, int32 level)
{ {
PRINT(("vnode_low_memory_handler(level = %ld)\n", level)); TRACE(("vnode_low_memory_handler(level = %ld)\n", level));
int32 count = 1; int32 count = 1;
switch (level) { switch (level) {
@ -906,7 +906,7 @@ vnode_low_memory_handler(void */*data*/, int32 level)
mutex_unlock(&sVnodeMutex); mutex_unlock(&sVnodeMutex);
break; break;
} }
PRINT((" free vnode %ld:%Ld (%p)\n", vnode->device, vnode->id, vnode)); TRACE((" free vnode %ld:%Ld (%p)\n", vnode->device, vnode->id, vnode));
vnode->busy = true; vnode->busy = true;
sUnusedVnodes--; sUnusedVnodes--;
@ -1389,7 +1389,7 @@ vnode_path_to_vnode(struct vnode *vnode, char *path, bool traverseLeafLink,
vnode_id vnodeID; vnode_id vnodeID;
char *nextPath; char *nextPath;
PRINT(("vnode_path_to_vnode: top of loop. p = %p, p = '%s'\n", path, path)); TRACE(("vnode_path_to_vnode: top of loop. p = %p, p = '%s'\n", path, path));
// done? // done?
if (path[0] == '\0') if (path[0] == '\0')
@ -1454,7 +1454,7 @@ vnode_path_to_vnode(struct vnode *vnode, char *path, bool traverseLeafLink,
size_t bufferSize; size_t bufferSize;
char *buffer; char *buffer;
PRINT(("traverse link\n")); TRACE(("traverse link\n"));
// it's not exactly nice style using goto in this way, but hey, it works :-/ // it's not exactly nice style using goto in this way, but hey, it works :-/
if (count + 1 > MAX_SYM_LINKS) { if (count + 1 > MAX_SYM_LINKS) {
@ -1830,7 +1830,7 @@ dir_vnode_to_path(struct vnode *vnode, char *buffer, size_t bufferSize)
if (path[insert] == '\0') if (path[insert] == '\0')
path[--insert] = '/'; path[--insert] = '/';
PRINT((" path is: %s\n", path + insert)); TRACE((" path is: %s\n", path + insert));
// copy the path to the output buffer // copy the path to the output buffer
length = sizeof(path) - insert; length = sizeof(path) - insert;
@ -2316,7 +2316,7 @@ new_vnode(mount_id mountID, vnode_id vnodeID, fs_vnode privateNode)
vnode->unpublished = true; vnode->unpublished = true;
} }
PRINT(("returns: %s\n", strerror(status))); TRACE(("returns: %s\n", strerror(status)));
mutex_unlock(&sVnodeMutex); mutex_unlock(&sVnodeMutex);
return status; return status;
@ -2344,7 +2344,7 @@ publish_vnode(mount_id mountID, vnode_id vnodeID, fs_vnode privateNode)
} else } else
status = B_BAD_VALUE; status = B_BAD_VALUE;
PRINT(("returns: %s\n", strerror(status))); TRACE(("returns: %s\n", strerror(status)));
mutex_unlock(&sVnodeMutex); mutex_unlock(&sVnodeMutex);
return status; return status;
@ -2489,7 +2489,7 @@ vfs_get_vnode_from_path(const char *path, bool kernel, void **_vnode)
status_t status; status_t status;
char buffer[B_PATH_NAME_LENGTH + 1]; char buffer[B_PATH_NAME_LENGTH + 1];
PRINT(("vfs_get_vnode_from_path: entry. path = '%s', kernel %d\n", path, kernel)); TRACE(("vfs_get_vnode_from_path: entry. path = '%s', kernel %d\n", path, kernel));
strlcpy(buffer, path, sizeof(buffer)); strlcpy(buffer, path, sizeof(buffer));
@ -2557,7 +2557,7 @@ vfs_get_fs_node_from_path(mount_id mountID, const char *path, bool kernel, void
struct vnode *vnode; struct vnode *vnode;
status_t status; status_t status;
PRINT(("vfs_get_fs_node_from_path(mountID = %ld, path = \"%s\", kernel %d)\n", mountID, path, kernel)); TRACE(("vfs_get_fs_node_from_path(mountID = %ld, path = \"%s\", kernel %d)\n", mountID, path, kernel));
strlcpy(buffer, path, sizeof(buffer)); strlcpy(buffer, path, sizeof(buffer));
status = path_to_vnode(buffer, true, &vnode, NULL, kernel); status = path_to_vnode(buffer, true, &vnode, NULL, kernel);
@ -2647,7 +2647,7 @@ vfs_get_module_path(const char *basePath, const char *moduleName, char *pathBuff
return B_OK; return B_OK;
} else { } else {
PRINT(("vfs_get_module_path(): something is strange here: %d...\n", type)); TRACE(("vfs_get_module_path(): something is strange here: %d...\n", type));
status = B_ERROR; status = B_ERROR;
goto err; goto err;
} }
@ -2693,7 +2693,7 @@ vfs_normalize_path(const char *path, char *buffer, size_t bufferSize,
if (!path || !buffer || bufferSize < 1) if (!path || !buffer || bufferSize < 1)
return B_BAD_VALUE; return B_BAD_VALUE;
PRINT(("vfs_normalize_path(`%s')\n", path)); TRACE(("vfs_normalize_path(`%s')\n", path));
// copy the supplied path to the stack, so it can be modified // copy the supplied path to the stack, so it can be modified
char mutablePath[B_PATH_NAME_LENGTH + 1]; char mutablePath[B_PATH_NAME_LENGTH + 1];
@ -2705,7 +2705,7 @@ vfs_normalize_path(const char *path, char *buffer, size_t bufferSize,
char leaf[B_FILE_NAME_LENGTH]; char leaf[B_FILE_NAME_LENGTH];
status_t error = path_to_dir_vnode(mutablePath, &dirNode, leaf, kernel); status_t error = path_to_dir_vnode(mutablePath, &dirNode, leaf, kernel);
if (error != B_OK) { if (error != B_OK) {
PRINT(("vfs_normalize_path(): failed to get dir vnode: %s\n", strerror(error))); TRACE(("vfs_normalize_path(): failed to get dir vnode: %s\n", strerror(error)));
return error; return error;
} }
@ -2715,7 +2715,7 @@ vfs_normalize_path(const char *path, char *buffer, size_t bufferSize,
if (isDir) if (isDir)
error = vnode_path_to_vnode(dirNode, leaf, false, 0, &dirNode, NULL, NULL); error = vnode_path_to_vnode(dirNode, leaf, false, 0, &dirNode, NULL, NULL);
if (error != B_OK) { if (error != B_OK) {
PRINT(("vfs_normalize_path(): failed to get dir vnode for \".\" or \"..\": %s\n", strerror(error))); TRACE(("vfs_normalize_path(): failed to get dir vnode for \".\" or \"..\": %s\n", strerror(error)));
return error; return error;
} }
@ -2723,7 +2723,7 @@ vfs_normalize_path(const char *path, char *buffer, size_t bufferSize,
error = dir_vnode_to_path(dirNode, buffer, bufferSize); error = dir_vnode_to_path(dirNode, buffer, bufferSize);
put_vnode(dirNode); put_vnode(dirNode);
if (error < B_OK) { if (error < B_OK) {
PRINT(("vfs_normalize_path(): failed to get dir path: %s\n", strerror(error))); TRACE(("vfs_normalize_path(): failed to get dir path: %s\n", strerror(error)));
return error; return error;
} }
@ -2737,7 +2737,7 @@ vfs_normalize_path(const char *path, char *buffer, size_t bufferSize,
} }
} }
PRINT(("vfs_normalize_path() -> `%s'\n", buffer)); TRACE(("vfs_normalize_path() -> `%s'\n", buffer));
return B_OK; return B_OK;
} }
@ -4878,7 +4878,7 @@ fs_mount(char *path, const char *device, const char *fsName, uint32 flags,
} }
if (!partition) { if (!partition) {
PRINT(("fs_mount(): Partition `%s' not found.\n", TRACE(("fs_mount(): Partition `%s' not found.\n",
normalizedDevice.Path())); normalizedDevice.Path()));
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
} }
@ -4893,7 +4893,7 @@ fs_mount(char *path, const char *device, const char *fsName, uint32 flags,
if (partition) { if (partition) {
diskDevice = ddm->WriteLockDevice(partition->Device()->ID()); diskDevice = ddm->WriteLockDevice(partition->Device()->ID());
if (!diskDevice) { if (!diskDevice) {
PRINT(("fs_mount(): Failed to lock disk device!\n")); TRACE(("fs_mount(): Failed to lock disk device!\n"));
return B_ERROR; return B_ERROR;
} }
} }
@ -4902,7 +4902,7 @@ fs_mount(char *path, const char *device, const char *fsName, uint32 flags,
if (partition) { if (partition) {
// make sure, that the partition is not busy // make sure, that the partition is not busy
if (partition->IsBusy() || partition->IsDescendantBusy()) { if (partition->IsBusy() || partition->IsDescendantBusy()) {
PRINT(("fs_mount(): Partition is busy.\n")); TRACE(("fs_mount(): Partition is busy.\n"));
return B_BUSY; return B_BUSY;
} }
@ -4910,13 +4910,13 @@ fs_mount(char *path, const char *device, const char *fsName, uint32 flags,
if (!fsName) { if (!fsName) {
KDiskSystem *diskSystem = partition->DiskSystem(); KDiskSystem *diskSystem = partition->DiskSystem();
if (!diskSystem) { if (!diskSystem) {
PRINT(("fs_mount(): No FS name was given, and the DDM didn't " TRACE(("fs_mount(): No FS name was given, and the DDM didn't "
"recognize it.\n")); "recognize it.\n"));
return B_BAD_VALUE; return B_BAD_VALUE;
} }
if (!diskSystem->IsFileSystem()) { if (!diskSystem->IsFileSystem()) {
PRINT(("fs_mount(): No FS name was given, and the DDM found a " TRACE(("fs_mount(): No FS name was given, and the DDM found a "
"partitioning system.\n")); "partitioning system.\n"));
return B_BAD_VALUE; return B_BAD_VALUE;
} }
@ -5102,7 +5102,7 @@ fs_unmount(char *path, uint32 flags, bool kernel)
if (partition) { if (partition) {
diskDevice = ddm->WriteLockDevice(partition->Device()->ID()); diskDevice = ddm->WriteLockDevice(partition->Device()->ID());
if (!diskDevice) { if (!diskDevice) {
PRINT(("fs_unmount(): Failed to lock disk device!\n")); TRACE(("fs_unmount(): Failed to lock disk device!\n"));
return B_ERROR; return B_ERROR;
} }
} }
@ -5111,7 +5111,7 @@ fs_unmount(char *path, uint32 flags, bool kernel)
// make sure, that the partition is not busy // make sure, that the partition is not busy
if (partition) { if (partition) {
if (partition->IsBusy() || partition->IsDescendantBusy()) { if (partition->IsBusy() || partition->IsDescendantBusy()) {
PRINT(("fs_unmount(): Partition is busy.\n")); TRACE(("fs_unmount(): Partition is busy.\n"));
return B_BUSY; return B_BUSY;
} }
} }
@ -5974,7 +5974,7 @@ _kern_remove_index(dev_t device, const char *name)
status_t status_t
_kern_getcwd(char *buffer, size_t size) _kern_getcwd(char *buffer, size_t size)
{ {
PRINT(("_kern_getcwd: buf %p, %ld\n", buffer, size)); TRACE(("_kern_getcwd: buf %p, %ld\n", buffer, size));
// Call vfs to get current working directory // Call vfs to get current working directory
return get_cwd(buffer, size, true); return get_cwd(buffer, size, true);
@ -6838,7 +6838,7 @@ _user_getcwd(char *userBuffer, size_t size)
char buffer[B_PATH_NAME_LENGTH]; char buffer[B_PATH_NAME_LENGTH];
status_t status; status_t status;
PRINT(("user_getcwd: buf %p, %ld\n", userBuffer, size)); TRACE(("user_getcwd: buf %p, %ld\n", userBuffer, size));
if (!IS_USER_ADDRESS(userBuffer)) if (!IS_USER_ADDRESS(userBuffer))
return B_BAD_ADDRESS; return B_BAD_ADDRESS;
@ -6863,7 +6863,7 @@ _user_setcwd(int fd, const char *userPath)
{ {
char path[B_PATH_NAME_LENGTH]; char path[B_PATH_NAME_LENGTH];
PRINT(("user_setcwd: path = %p\n", userPath)); TRACE(("user_setcwd: path = %p\n", userPath));
if (userPath != NULL) { if (userPath != NULL) {
if (!IS_USER_ADDRESS(userPath) if (!IS_USER_ADDRESS(userPath)

View File

@ -345,7 +345,7 @@ heap_init(addr_t heapBase)
status_t status_t
heap_init_post_sem(kernel_args *ka) heap_init_post_sem(kernel_args *args)
{ {
if (mutex_init(&heap_lock, "heap_mutex") < 0) if (mutex_init(&heap_lock, "heap_mutex") < 0)
panic("error creating heap mutex\n"); panic("error creating heap mutex\n");
@ -358,7 +358,7 @@ heap_init_post_sem(kernel_args *ka)
status_t status_t
heap_init_post_thread(kernel_args *ka) heap_init_post_thread(kernel_args *args)
{ {
#if USE_CHECKING_WALL #if USE_CHECKING_WALL
register_kernel_daemon(check_wall_daemon, NULL, WALL_CHECK_FREQUENCY); register_kernel_daemon(check_wall_daemon, NULL, WALL_CHECK_FREQUENCY);

View File

@ -80,7 +80,7 @@ static spinlock sPortSpinlock = 0;
status_t status_t
port_init(kernel_args *ka) port_init(kernel_args *args)
{ {
int i; int i;
int size = sizeof(struct port_entry) * sMaxPorts; int size = sizeof(struct port_entry) * sMaxPorts;

View File

@ -14,7 +14,16 @@
#include <util/AutoLock.h> #include <util/AutoLock.h>
static const bigtime_t kLowMemoryInterval = 2000000; // 2 secs //#define TRACE_LOW_MEMORY
#ifdef TRACE_LOW_MEMORY
# define TRACE(x) dprintf x
#else
# define TRACE(x) ;
#endif
// TODO: the priority is currently ignored, and probably can be removed
static const bigtime_t kLowMemoryInterval = 3000000; // 3 secs
// page limits // page limits
static const size_t kNoteLimit = 1024; static const size_t kNoteLimit = 1024;
@ -75,6 +84,10 @@ low_memory(void *)
snooze(kLowMemoryInterval); snooze(kLowMemoryInterval);
sLowMemoryState = compute_state(); sLowMemoryState = compute_state();
TRACE(("vm_low_memory: state = %ld, %ld free pages\n",
sLowMemoryState, vm_page_num_free_pages()));
if (sLowMemoryState < B_LOW_MEMORY_NOTE) if (sLowMemoryState < B_LOW_MEMORY_NOTE)
continue; continue;
@ -126,8 +139,10 @@ vm_low_memory_init(void)
status_t status_t
unregister_low_memory_handler(low_memory_func function, void *data) unregister_low_memory_handler(low_memory_func function, void *data)
{ {
MutexLocker locker(&sLowMemoryMutex); TRACE(("unregister_low_memory_handler(function = %p, data = %p)\n",
function, data));
MutexLocker locker(&sLowMemoryMutex);
HandlerList::Iterator iterator = sLowMemoryHandlers.GetIterator(); HandlerList::Iterator iterator = sLowMemoryHandlers.GetIterator();
while (iterator.HasNext()) { while (iterator.HasNext()) {
@ -147,6 +162,9 @@ unregister_low_memory_handler(low_memory_func function, void *data)
status_t status_t
register_low_memory_handler(low_memory_func function, void *data, int32 priority) register_low_memory_handler(low_memory_func function, void *data, int32 priority)
{ {
TRACE(("register_low_memory_handler(function = %p, data = %p)\n",
function, data));
low_memory_handler *handler = (low_memory_handler *)malloc(sizeof(low_memory_handler)); low_memory_handler *handler = (low_memory_handler *)malloc(sizeof(low_memory_handler));
if (handler == NULL) if (handler == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;