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:
parent
8985112ee5
commit
fbafb4de2b
@ -117,7 +117,7 @@ bool area::contains(void *address)
|
||||
{
|
||||
// no need to lock here...
|
||||
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));
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ area *areaManager::findArea(void *address)
|
||||
for (struct node *cur=areas.rock;cur;cur=cur->next)
|
||||
{
|
||||
area *myArea=(area *)cur;
|
||||
printf ("areaManager::findArea: Looking for %d\n",address);
|
||||
// printf ("areaManager::findArea: Looking for %d\n",address);
|
||||
if (myArea->contains(address))
|
||||
return myArea;
|
||||
}
|
||||
|
@ -19,7 +19,8 @@ class list {
|
||||
rock=newNode;
|
||||
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 remove(void *in)
|
||||
{
|
||||
|
@ -22,10 +22,12 @@ pageManager::pageManager(int pages)
|
||||
unusedLock=create_sem (1,"unused_lock");
|
||||
inUseLock=create_sem (1,"inuse_lock");
|
||||
totalPages=pages;
|
||||
/*
|
||||
printf ("pageManager::pageManager: About to dump the clean pages (should be 0):\n\n");
|
||||
clean.dump();
|
||||
printf ("pageManager::pageManager: About to dump the unused pages (should not be 0):\n\n");
|
||||
unused.dump();
|
||||
*/
|
||||
}
|
||||
|
||||
page *pageManager::getPage(void)
|
||||
@ -75,16 +77,21 @@ void pageManager::freePage(page *toFree)
|
||||
|
||||
void pageManager::cleaner(void)
|
||||
{
|
||||
if (unused.count())
|
||||
while (1)
|
||||
{
|
||||
acquire_sem(unusedLock);
|
||||
page *first=(page *)unused.next();
|
||||
first->zero();
|
||||
acquire_sem(cleanLock);
|
||||
clean.add(first);
|
||||
release_sem(cleanLock);
|
||||
release_sem(unusedLock);
|
||||
snooze(250000);
|
||||
if (unused.count())
|
||||
{
|
||||
printf ("pageManager::cleaner: About to vacuum a page\n");
|
||||
acquire_sem(unusedLock);
|
||||
page *first=(page *)unused.next();
|
||||
first->zero();
|
||||
acquire_sem(cleanLock);
|
||||
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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
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)
|
||||
@ -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)
|
||||
{
|
||||
printf ("swapFileManager::read_block: reading, node.fd = %d, node.offset = %d\n",node.fd, node.offset);
|
||||
lseek(node.fd,SEEK_SET,node.offset);
|
||||
if (node.valid==false)
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -1,19 +1,49 @@
|
||||
#include "vmInterface.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)
|
||||
{
|
||||
vmInterface vm(10);
|
||||
|
||||
unsigned long addr;
|
||||
vm.createArea("Mine",2,(void **)(&addr));
|
||||
printf ("addr = %d\n",addr);
|
||||
vm.setByte(addr,99);
|
||||
printf ("addr = %d\n",addr);
|
||||
printf ("Byte = %d\n",vm.getByte(addr));
|
||||
writeByte(0,99);
|
||||
readByte(0);
|
||||
printf ("\n\n\n\n\n");
|
||||
vm.setByte(addr+4097,99);
|
||||
printf ("addr = %d\n",addr);
|
||||
printf ("Byte = %d\n",vm.getByte(addr));
|
||||
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));
|
||||
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;
|
||||
}
|
||||
|
@ -6,6 +6,19 @@ areaManager am;
|
||||
swapFileManager swapMan;
|
||||
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)
|
||||
{
|
||||
// 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...
|
||||
while (1)
|
||||
{
|
||||
am.pager(pageMan.desperation());
|
||||
snooze(250000);
|
||||
am.pager(pageMan.desperation());
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,8 +106,8 @@ void vmInterface::saver(void)
|
||||
// This should iterate over all processes...
|
||||
while (1)
|
||||
{
|
||||
am.saver();
|
||||
snooze(250000);
|
||||
am.saver();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ class vmInterface // This is the class that "owns" all of the managers.
|
||||
int nextAreaID;
|
||||
areaManager *getAM(void); // This is for testing only...
|
||||
public:
|
||||
vmInterface(int pages) {nextAreaID=0;};
|
||||
vmInterface(int pages);
|
||||
int createArea(char *AreaName,int pageCount,void **address,
|
||||
addressSpec addType=ANY,
|
||||
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)
|
||||
{
|
||||
printf ("vpage::getByte: address = %d\n",address );
|
||||
// printf ("vpage::getByte: address = %d\n",address );
|
||||
if (!physPage)
|
||||
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()));
|
||||
}
|
||||
|
||||
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)
|
||||
fault((void *)(address),true);
|
||||
*((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)
|
||||
|
Loading…
Reference in New Issue
Block a user