as_copy() when source page is on disk

What is expected behaviour of as_copy() if the source page is on disk?
Can I simply block_read() the data from disk, put that data in my newly allocated page and mark the status of that page as ON_MEMORY, or do I have to swapin() the source page, use memmove() to copy the data, then put both of the pages back into disk?
Basically, does the data of my newly created page have to go to disk or is it ok if its in memory.
Thank You.

You can do any of the following:

  • Copy from one disk location to another, resulting in both pages on disk
  • Read into memory at the location of the new page, resulting in the original page on disk and the new page in memory
  • Read into memory at either location and memcpy to the other, resulting in both pages in memory

Any of these options are feasible. Personally we chose the last one, though I’m not sure whether this was the best choice.

(You could also implement copy-on-write, but this is probably more trouble than it’s worth at this point.)


Thank you so much, I think I’ll choose the 2nd one since its most easily implemented on my current code interface.

1 Like