Code Monkey home page Code Monkey logo

6.s081-all-in-one's Introduction

课程介绍

6.S081 Fall2020是麻省理工2020年秋季的操作系统课程,MIT将学习相关的资源全部公开并放到了官网。本课程**涉及11个实验,需要花费一定时间来完成。由于是国外的课程,文档资料均为英文,为方便自己后续查阅和其他英文水平不足以流畅阅读英文文献的同学也能上手本课程,计划将资料全部翻译为中文。并分享课程笔记和实验记录。

由于水平有限,翻译中难免有错误或词不达意,还请见谅。

img

常用网址

GITBOOK浏览

更好的浏览体验,请查看6.S081-All-In-One-Gitbook(xv6.dgs.zone)

这些笔记开始时写在了飞书上,飞书不支持导出markdown,因此是从飞书上逐篇复制下来的,二者存在一些格式差异,我已经进行了修改,但仍然可能有部分没有注意到~

BY ME A COFFEE

如果你觉得翻译有用而且愿意的话,欢迎请我一杯咖啡或者是一包辣条(doge)

微信 支付宝
wechatpay alipay

6.s081-all-in-one's People

Contributors

1278132270 avatar duguosheng avatar q2333gh avatar ruokeqx avatar sbccznfy avatar yukang-lian avatar yzhe819 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

6.s081-all-in-one's Issues

the trace function in lab 2 misses modifications to fork

as the info in the lab2, the trace should add some modification in the fork() function, which doesn't show in your document.

diff --git a/kernel/proc.c b/kernel/proc.c
index 6afafa1..01c178a 100644
--- a/kernel/proc.c
+++ b/kernel/proc.c
@@ -268,6 +268,10 @@ fork(void)
   }
 
   // Copy user memory from parent to child.
+
+  // add mask
+  np->mask = p->mask;
+
   if(uvmcopy(p->pagetable, np->pagetable, p->sz) < 0){
     freeproc(np);
     release(&np->lock);

but over all, thx for your effort!

关于“flush”翻译的讨论

在xv6book的3.3节,“RISC-V有一个指令sfence.vma,用于刷新当前CPU的TLB”。
此处“刷新”在原文中为“flush”,是否译为清空或者类似的词更合理。
在改变进程的同时会切换页表,所以TLB中原有进程的数据应该被清空而非刷新。

参考 https://mit-public-courses-cn-translatio.gitbook.io/mit6-s081/lec04-page-tables-frans/4.4-ye-biao-huan-cun-translation-lookaside-buffer 中的译文“你们需要知道TLB存在的唯一原因是,如果你切换了page table,操作系统需要告诉处理器当前正在切换page table,处理器会清空TLB。”

如果我的理解有误,烦请指正。

Translation mistake

1.3 管道 最后一句: pipes’ blocking reads and writes are more efficient than the non-blocking semantics of files. 应该是管道的阻塞式读写比文件的非阻塞语义更高效。阻塞读写对应原文中: "If no data is available, a read on a pipe waits for either data to be written"

lab7的实验二写的有问题

RT,我们可以考虑两个线程同时插入相同key键值对,当两个线程都遍历完后,然后开始争取锁插入,我们就可能插入两个一样的key值的entry。

1.3翻译有歧义

If no data is available, a read on a pipe waits for either data to be written or for all file descriptors referring to the write end to be closed; in the latter case, read will return 0, just as if the end of a data file had been reached. The fact that read blocks until it is impossible for new data to arrive is one reason that it’s important for the child to close the write end of the pipe before executing wc above: if one of wc ’s file descriptors referred to the write end of the pipe, wc would never see end-of-file.

如果没有可用的数据,则管道上的read操作等待写入数据或关闭所有指向写入端的文件描述符,在后一种情况下,read将返回0,就像到达数据文件的末尾一样。事实上,read在新数据不可能到达前会一直阻塞,这是子进程在执行上面的wc之前关闭管道的写入端非常重要的一个原因:如果wc的文件描述符之一指向管道的写入端,wc将永远看不到文件的结束。

其中
a read on a pipe waits for either data to be written or for all file descriptors referring to the write end to be closed
应该是:
则管道上的read操作要么等待写入数据,或者等待所有指向write end的fd都被关闭(wait either for A or for B)
翻译版可能会被理解为等待,或者关闭

虽然不是啥大问题,但是我初看看了两三遍都没看懂,翻了英文版才理解
稍微提一下,也许能帮到后来人

lock那个实验的第二个buffer cache解法有问题,会有死锁问题出现

你用的是holding判断,但是去看holding的实现,只有当前线程持有了传入的锁,才会返回1.
所以,用holding判断其实没什么用。
你的那个能够通过测试的原因是因为你优先从当前槽位开始搜索空闲buf,就像博客里面说的,这样会降低死锁的概率。
所以,测试用例就没有测到这种情况。
如果把你的实现改为从第0个槽位开始搜索空闲buf的话,那么就不会通过测试用例了。

另外,我觉得可以把holding函数换一下,自己新写一个函数,去掉后面的判断当前cpu是不是持有锁的cpu。然后使用这个函数。

int
islock(struct spinlock *lk)
{
  int r;
  r = (lk->locked);
  return r;
}

static struct buf*
bget(uint dev, uint blockno)
{
    struct buf *b;

    int index = hash(blockno);
    acquire(&bcache[index].lock);

    // Is the block already cached?
    for(b = bcache[index].head; b != 0; b = b->next){
        if(b->dev == dev && b->blockno == blockno){
            //printf("block num:%d,increcse++\n",blockno);
            b->refcnt++;
            release(&bcache[index].lock);
            acquiresleep(&b->lock);
            return b;
        }
    }

    // printf("inner\n");
    for(int i = 0;i < HASHLEN;i++){
        // 由于在这里的时候,还是持有index这个位置的锁的。所以当当前的i跟index不同的时候,才需要去尝试获取锁。
        if(i != index){
            if(islock(&bcache[i].lock)){
                continue;
            }
            acquire(&bcache[i].lock);
        }

        struct buf *temp = bcache[i].head;
        struct buf *pre = 0;
        while (temp){
            if(temp->refcnt == 0)  {
                // 找到一个空闲的buf,就把它设置好各种参数
                temp->dev = dev;
                temp->blockno = blockno;
                temp->valid = 0;
                temp->refcnt = 1;
                // 开始移动这个buf
                if(i == index){
                    // 如果就是在哈希目标的位置上找到的buf,那就不用移动
                    release(&bcache[i].lock);
                }else{
                    // 不然需要将该buf移动到哈希目标的位置上,在这个分支中,此时已经获取到了两个锁,一个是index,一个是i
                    //  i是找到的空闲buf的位置,index是目标下标位置
                    if(pre != 0){
                        pre->next = temp->next;
                    }else{
                        bcache[i].head = temp->next;
                    }
                    // 将i位置的temp节点从单链表中移除之后,就能够释放i位置的锁了。
                    release(&bcache[i].lock);
                    // 此时还是有index位置的锁,此时将temp加入到index的单链表中
                    temp->next = bcache[index].head;
                    bcache[index].head = temp;
                    release(&bcache[index].lock);
                }

                acquiresleep(&temp->lock);
                //printf("新分配,block num:%d,ref count:%d\n",temp->blockno,temp->refcnt);
                return temp;
            }
            pre = temp;
            temp = temp->next;
        }
        if(i != index){
            release(&bcache[i].lock);
        }

    }

    panic("bget: no buffers");
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.