Added more tests and we now start the thread for the page cleaner.
Verified (manually) that cleaned pages are used where possible. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@539 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -117,7 +117,7 @@ bool area::contains(void *address)
|
|||||||
{
|
{
|
||||||
// no need to lock here...
|
// no need to lock here...
|
||||||
unsigned long base=(unsigned long)(address);
|
unsigned long base=(unsigned long)(address);
|
||||||
printf ("area::contains: looking for %d in %d -- %d, value = %d\n",base,start_address,end_address, ((start_address<=base) && (end_address>=base)));
|
// printf ("area::contains: looking for %d in %d -- %d, value = %d\n",base,start_address,end_address, ((start_address<=base) && (end_address>=base)));
|
||||||
|
|
||||||
return ((start_address<=base) && (end_address>=base));
|
return ((start_address<=base) && (end_address>=base));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ area *areaManager::findArea(void *address)
|
|||||||
for (struct node *cur=areas.rock;cur;cur=cur->next)
|
for (struct node *cur=areas.rock;cur;cur=cur->next)
|
||||||
{
|
{
|
||||||
area *myArea=(area *)cur;
|
area *myArea=(area *)cur;
|
||||||
printf ("areaManager::findArea: Looking for %d\n",address);
|
// printf ("areaManager::findArea: Looking for %d\n",address);
|
||||||
if (myArea->contains(address))
|
if (myArea->contains(address))
|
||||||
return myArea;
|
return myArea;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ class list {
|
|||||||
rock=newNode;
|
rock=newNode;
|
||||||
nodeCount++;
|
nodeCount++;
|
||||||
}
|
}
|
||||||
int count(void) {printf ("list::count: About to return %d\n",nodeCount);return nodeCount;}
|
//int count(void) {printf ("list::count: About to return %d\n",nodeCount);return nodeCount;}
|
||||||
|
int count(void) {return nodeCount;}
|
||||||
void *next(void) {nodeCount--;node *n=rock;if (rock) rock=rock->next;return n;}
|
void *next(void) {nodeCount--;node *n=rock;if (rock) rock=rock->next;return n;}
|
||||||
void remove(void *in)
|
void remove(void *in)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,10 +22,12 @@ pageManager::pageManager(int pages)
|
|||||||
unusedLock=create_sem (1,"unused_lock");
|
unusedLock=create_sem (1,"unused_lock");
|
||||||
inUseLock=create_sem (1,"inuse_lock");
|
inUseLock=create_sem (1,"inuse_lock");
|
||||||
totalPages=pages;
|
totalPages=pages;
|
||||||
|
/*
|
||||||
printf ("pageManager::pageManager: About to dump the clean pages (should be 0):\n\n");
|
printf ("pageManager::pageManager: About to dump the clean pages (should be 0):\n\n");
|
||||||
clean.dump();
|
clean.dump();
|
||||||
printf ("pageManager::pageManager: About to dump the unused pages (should not be 0):\n\n");
|
printf ("pageManager::pageManager: About to dump the unused pages (should not be 0):\n\n");
|
||||||
unused.dump();
|
unused.dump();
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
page *pageManager::getPage(void)
|
page *pageManager::getPage(void)
|
||||||
@@ -75,16 +77,21 @@ void pageManager::freePage(page *toFree)
|
|||||||
|
|
||||||
void pageManager::cleaner(void)
|
void pageManager::cleaner(void)
|
||||||
{
|
{
|
||||||
if (unused.count())
|
while (1)
|
||||||
{
|
{
|
||||||
acquire_sem(unusedLock);
|
if (unused.count())
|
||||||
page *first=(page *)unused.next();
|
{
|
||||||
first->zero();
|
printf ("pageManager::cleaner: About to vacuum a page\n");
|
||||||
acquire_sem(cleanLock);
|
acquire_sem(unusedLock);
|
||||||
clean.add(first);
|
page *first=(page *)unused.next();
|
||||||
release_sem(cleanLock);
|
first->zero();
|
||||||
release_sem(unusedLock);
|
acquire_sem(cleanLock);
|
||||||
snooze(250000);
|
clean.add(first);
|
||||||
|
release_sem(cleanLock);
|
||||||
|
release_sem(unusedLock);
|
||||||
|
printf ("pageManager::cleaner: All done with vacuum a page\n");
|
||||||
|
snooze(125000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
#include "swapFileManager.h"
|
#include "swapFileManager.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
swapFileManager::swapFileManager(void)
|
swapFileManager::swapFileManager(void)
|
||||||
{
|
{
|
||||||
swapFile = open("/boot/var/tmp/OBOS_swap",O_RDWR );
|
swapFile = open("/boot/var/tmp/OBOS_swap",O_RDWR|O_CREAT,0x777 );
|
||||||
|
if (swapFile==-1)
|
||||||
|
printf ("swapfileManager::swapFileManger: swapfile not opened, errno = %ul, %s\n",errno,strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
void swapFileManager::write_block(vnode node,void *loc,unsigned long size)
|
void swapFileManager::write_block(vnode node,void *loc,unsigned long size)
|
||||||
@@ -16,10 +20,10 @@ void swapFileManager::write_block(vnode node,void *loc,unsigned long size)
|
|||||||
|
|
||||||
void swapFileManager::read_block(vnode node,void *loc,unsigned long size)
|
void swapFileManager::read_block(vnode node,void *loc,unsigned long size)
|
||||||
{
|
{
|
||||||
printf ("swapFileManager::read_block: reading, node.fd = %d, node.offset = %d\n",node.fd, node.offset);
|
|
||||||
lseek(node.fd,SEEK_SET,node.offset);
|
lseek(node.fd,SEEK_SET,node.offset);
|
||||||
if (node.valid==false)
|
if (node.valid==false)
|
||||||
return; // Do nothing. This prevents "garbage" data on disk from being read in...
|
return; // Do nothing. This prevents "garbage" data on disk from being read in...
|
||||||
|
printf ("swapFileManager::read_block: reading, node.fd = %d, node.offset = %d\n",node.fd, node.offset);
|
||||||
read(node.fd,loc,size);
|
read(node.fd,loc,size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+40
-10
@@ -1,19 +1,49 @@
|
|||||||
#include "vmInterface.h"
|
#include "vmInterface.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
unsigned long addr;
|
||||||
|
vmInterface vm(10);
|
||||||
|
|
||||||
|
void writeByte(unsigned int offset, char value)
|
||||||
|
{
|
||||||
|
//printf ("writeByte: writing %d to offset %d\n",value,offset);
|
||||||
|
vm.setByte(addr+offset,value);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char readByte(unsigned int offset )
|
||||||
|
{
|
||||||
|
char value=vm.getByte(addr+offset);
|
||||||
|
//printf ("readByte: read %d from offset %d\n",value,offset);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc,char **argv)
|
int main(int argc,char **argv)
|
||||||
{
|
{
|
||||||
vmInterface vm(10);
|
|
||||||
|
|
||||||
unsigned long addr;
|
|
||||||
vm.createArea("Mine",2,(void **)(&addr));
|
vm.createArea("Mine",2,(void **)(&addr));
|
||||||
printf ("addr = %d\n",addr);
|
writeByte(0,99);
|
||||||
vm.setByte(addr,99);
|
readByte(0);
|
||||||
printf ("addr = %d\n",addr);
|
|
||||||
printf ("Byte = %d\n",vm.getByte(addr));
|
|
||||||
printf ("\n\n\n\n\n");
|
printf ("\n\n\n\n\n");
|
||||||
vm.setByte(addr+4097,99);
|
writeByte(4097,99);
|
||||||
printf ("addr = %d\n",addr);
|
readByte(4097);
|
||||||
printf ("Byte = %d\n",vm.getByte(addr));
|
printf ("\n\n\n\n\n");
|
||||||
|
for (int i=0;i<8192;i++)
|
||||||
|
writeByte(i,i%256);
|
||||||
|
for (int i=0;i<8192;i++)
|
||||||
|
if (i%256!=readByte(i))
|
||||||
|
printf ("ERROR! Byte at offset %d does not match: expected: %d, found: %d\n",i,i%256,readByte(i));
|
||||||
|
snooze(10000000);
|
||||||
|
vm.createArea("Mine",2,(void **)(&addr));
|
||||||
|
writeByte(0,99);
|
||||||
|
readByte(0);
|
||||||
|
printf ("\n\n\n\n\n");
|
||||||
|
writeByte(4097,99);
|
||||||
|
readByte(4097);
|
||||||
|
printf ("\n\n\n\n\n");
|
||||||
|
for (int i=0;i<8192;i++)
|
||||||
|
writeByte(i,i%256);
|
||||||
|
for (int i=0;i<8192;i++)
|
||||||
|
if (i%256!=readByte(i))
|
||||||
|
printf ("ERROR! Byte at offset %d does not match: expected: %d, found: %d\n",i,i%256,readByte(i));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,19 @@ areaManager am;
|
|||||||
swapFileManager swapMan;
|
swapFileManager swapMan;
|
||||||
pageManager pageMan(10); // Obviously this hard coded number is a hack...
|
pageManager pageMan(10); // Obviously this hard coded number is a hack...
|
||||||
|
|
||||||
|
int32 cleanerThread(void *pageMan)
|
||||||
|
{
|
||||||
|
pageManager *pm=(pageManager *)pageMan;
|
||||||
|
pm->cleaner();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
vmInterface::vmInterface(int pages)
|
||||||
|
{
|
||||||
|
nextAreaID=0;
|
||||||
|
resume_thread(spawn_thread(cleanerThread,"cleanerThread",0,&pageMan));
|
||||||
|
}
|
||||||
|
|
||||||
areaManager *vmInterface::getAM(void)
|
areaManager *vmInterface::getAM(void)
|
||||||
{
|
{
|
||||||
// Normally, we would go to the current user process to get this. Since there no such thing exists here...
|
// Normally, we would go to the current user process to get this. Since there no such thing exists here...
|
||||||
@@ -83,8 +96,8 @@ void vmInterface::pager(void)
|
|||||||
// This should iterate over all processes...
|
// This should iterate over all processes...
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
am.pager(pageMan.desperation());
|
|
||||||
snooze(250000);
|
snooze(250000);
|
||||||
|
am.pager(pageMan.desperation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,8 +106,8 @@ void vmInterface::saver(void)
|
|||||||
// This should iterate over all processes...
|
// This should iterate over all processes...
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
am.saver();
|
|
||||||
snooze(250000);
|
snooze(250000);
|
||||||
|
am.saver();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class vmInterface // This is the class that "owns" all of the managers.
|
|||||||
int nextAreaID;
|
int nextAreaID;
|
||||||
areaManager *getAM(void); // This is for testing only...
|
areaManager *getAM(void); // This is for testing only...
|
||||||
public:
|
public:
|
||||||
vmInterface(int pages) {nextAreaID=0;};
|
vmInterface(int pages);
|
||||||
int createArea(char *AreaName,int pageCount,void **address,
|
int createArea(char *AreaName,int pageCount,void **address,
|
||||||
addressSpec addType=ANY,
|
addressSpec addType=ANY,
|
||||||
pageState state=NO_LOCK,protectType protect=writable);
|
pageState state=NO_LOCK,protectType protect=writable);
|
||||||
|
|||||||
@@ -76,20 +76,20 @@ bool vpage::fault(void *fault_address, bool writeError) // true = OK, false = pa
|
|||||||
|
|
||||||
char vpage::getByte(unsigned long address)
|
char vpage::getByte(unsigned long address)
|
||||||
{
|
{
|
||||||
printf ("vpage::getByte: address = %d\n",address );
|
// printf ("vpage::getByte: address = %d\n",address );
|
||||||
if (!physPage)
|
if (!physPage)
|
||||||
fault((void *)(address),false);
|
fault((void *)(address),false);
|
||||||
printf ("vpage::getByte: About to return %d\n", *((char *)(address-start_address+physPage->getAddress())));
|
// printf ("vpage::getByte: About to return %d\n", *((char *)(address-start_address+physPage->getAddress())));
|
||||||
return *((char *)(address-start_address+physPage->getAddress()));
|
return *((char *)(address-start_address+physPage->getAddress()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void vpage::setByte(unsigned long address,char value)
|
void vpage::setByte(unsigned long address,char value)
|
||||||
{
|
{
|
||||||
printf ("vpage::setByte: address = %d, value = %d\n",address, value);
|
// printf ("vpage::setByte: address = %d, value = %d\n",address, value);
|
||||||
if (!physPage)
|
if (!physPage)
|
||||||
fault((void *)(address),true);
|
fault((void *)(address),true);
|
||||||
*((char *)(address-start_address+physPage->getAddress()))=value;
|
*((char *)(address-start_address+physPage->getAddress()))=value;
|
||||||
printf ("vpage::setByte: physical address = %d, value = %d\n",physPage->getAddress(), *((char *)(physPage->getAddress())));
|
// printf ("vpage::setByte: physical address = %d, value = %d\n",physPage->getAddress(), *((char *)(physPage->getAddress())));
|
||||||
}
|
}
|
||||||
|
|
||||||
int vpage::getInt(unsigned long address)
|
int vpage::getInt(unsigned long address)
|
||||||
|
|||||||
Reference in New Issue
Block a user