Fix: Avoid closing the file after loading segments to be able to lazily load from file without opening, w/ G
This commit is contained in:
@@ -69,30 +69,34 @@ page_get (void *upage)
|
||||
bool
|
||||
page_load (struct page_entry *page, bool writable)
|
||||
{
|
||||
void *frame = frame_alloc (PAL_USER, page->upage, thread_current());
|
||||
/* Allocate a frame for the page. If a frame allocation fails, then
|
||||
frame_alloc should try to evict a page. If it is still NULL, the OS
|
||||
panics as this should not happen if eviction is working correctly. */
|
||||
void *frame = frame_alloc (PAL_USER, page->upage, thread_current ());
|
||||
if (frame == NULL)
|
||||
return false; // TODO: Try to evict a page instead.
|
||||
PANIC ("Could not allocate a frame to load page into memory.");
|
||||
|
||||
/* Map the page to the frame. */
|
||||
if (!install_page (page->upage, frame, writable))
|
||||
{
|
||||
frame_free (frame);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf ("Hi! 3\n");
|
||||
{
|
||||
frame_free (frame);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Move the file pointer to the correct location in the file. Then, read the
|
||||
data from the file into the frame. Checks that we were able to read the
|
||||
expected number of bytes. */
|
||||
file_seek (page->file, page->offset);
|
||||
int read = -1;
|
||||
if ((read = file_read (page->file, frame, page->read_bytes)) != (int) page->read_bytes)
|
||||
if (file_read (page->file, frame, page->read_bytes) != (int) page->read_bytes)
|
||||
{
|
||||
printf ("%p, %p, %d %d\n", page->file, frame, read, page->offset);
|
||||
frame_free (frame);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf ("Hi! 4\n");
|
||||
|
||||
/* Zero out the remaining bytes in the frame. */
|
||||
memset (frame + page->read_bytes, 0, page->zero_bytes);
|
||||
|
||||
/* Mark the page as loaded successfully. */
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user