Project 7: Optimized checkpoint

Due: June. 5, 2025, 2:30 pm (submission: by email)
Submit a report to TA: Juwon Kim ( email: joo97508@gmail.com  )
Name your report file with “hw6_[your studentid]”. ex: hw6_20251234.zip

In this project you’ll optimize checkpoint of xv6. When a user program modifies contents of filesystem such as file contents and metadata, all the modified data are written first to log area (commit) and written to its original place (checkpoint). See the commit function at 193 line of log.c. That is function that is responsible for logging. It first writes logs (write_log) and log header (write_head), and it write logs to their original place (install_trans). Once the log is not needed anymore, it mark that log that is committed is useless as set log.n to 0 and write that to log header. However, it is a little inefficient and different with modern logging of filesystem. We will modify that and make it efficient and that is similar with modern filesystem.

Part One : Checkpoint without reading log area
See the install_trans function at 70 line of log.c.

install_trans(void)
{
  int tail;

  for (tail = 0; tail < log.lh.n; tail++) {
    struct buf *lbuf = bread(log.dev, log.start+tail+1);
    struct buf *dbuf = bread(log.dev, log.lh.block[tail]);
    memmove(dbuf->data, lbuf->data, BSIZE);
    bwrite(dbuf);  // write dst to disk
    brelse(lbuf);
    brelse(dbuf);
  }
}

It read two blocks and get their buffers. Each block is log block (lbuf) and block of original place of the log (dbuf). And copy the contents of log block to the original block. Lastly write dbuf to its place. However, is it efficient?

The install_trans is called in two points. The one is after the commit and another is after booting. In the first case, the log contents (the modified data) is already loaded on memory because the user program has committed log just before. How can we get modified data without reading log area? Please optimize install_trans to use modified contents that are already loaded on memory and to checkpoint without reading log area.

Just create hello file and fill this file out with some string like "hello,world".

$ echo hello,world > hello

Reboot the xv6 and check the string is in the file or not.

$ cat hello
hello,world
$
  • Hint : See the write_log function. It get the modified contents from log.lh.block array. Think about just after booting. The modified contents are also already loaded just after booting?

Part Two : Separate process for checkpoint
When logs are committed but not checkpointed, logs are safe. Even if logs are not checkpointed, they already written to log area in disk. We can recover logs as use logs that is in log area. So it is not duty that a user program calls install_trans to checkpoint just after commit.

In this part, we will create separate process that is responsible for checkpoint. With this process, a user program do not checkpoint but wake the checkpoint process up and return.

There are some points you have to consider:

  1. Could new log can be committed when a previous log is not checkpointed?
  2. New blocks should be able to be added to log during checkpoint or before checkpoint.
  3. New process should run only kernel code. In the modern kernel, it is called as a kernel thread.

      Checking its validation is same with part one (Please remove fs.img before run the xv6.). Create new file hello and fill this file out with string "hello,world". And reboot the xv6 and check the string is in the file or not.

      Submit : modified log.c and report.