🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: fa.netbsd.tech.kern
Article #127

Re: [Milkymist port] virtual memory management

#127
From: Eduardo Horvath
Date: Thu, 30 May 2013 20:46
59 lines
4460 bytes
On Wed, 29 May 2013, Yann Sionneau wrote:

> Hello NetBSD fellows,
> 
> As I mentioned in my previous e-mail, I may need from time to time a little
> bit of help since this is my first "full featured OS" port.
> 
> I am wondering how I can manage virtual memory (especially how to avoid tlb
> miss, or deal with them) in exception handlers.

There are essentially three ways to do this.  Which one you chose depends 
on the hardware.

1) Turn off the MMU on exception

2) Keep parts of the address space untranslated

3) Lock important pages into the TLB


Turning off the MMU is pretty straight-forward.  ISTR the PowerPC Book E 
processors do this.  Just look up the TLB entry in the table and return 
from exception.  You just have to make sure that the kernel manages page 
tables using physical addresses.

Keeping parts of the address space untranslated is what MIPS does.  2GB 
goes through the MMU for user space, 1GB is kernel virtual addresses, and 
512MB is untranslated VA->PA (+offset).  In this scheme usually the 
kernel text is untranslated but kernel data is virtual.  If the hardware 
doesn't support untranslated parts of the address space, you can fake it 
by checking the address in the TLB miss handler and generating an entry 
based on the fault address.  (I did something similar to that for the 
PowerPC Book E port 'cause parts of the MD code make assumptions about 
accessing untranslated data.)  

This design does have some disadvantages.  User address space is reduced 
by both the kernel address space and the direct mapped address space.  You 
can't distinguish pages mapped into the kernel from random memory so 
kernel core dumps involve dumping all of RAM, not just kernel space.  It's 
also difficult to properly protect kernel text and data structures if you 
can scribble on random physical addresses.

If your MMU supports huge pages, you can lock the trap table and important 
bits of the kernel text and data segment in the TLB.  When I did the 
sparc64 port I used one 4MB TLB entry for kernel text, and another 4MB 
entry for kernel data.  After a while the kernel text overflowed the 4MB 
page and we needed to sacrifice a couple more TLB entries.  

I like this scheme since it allows 32-bit processes to use all 4GB of 
address space, but I did use some interesting features of the SPARC 
instruction set that allow load/store operations on alternate address 
spaces and physical addresses without needing to fiddle with the MMU.

So you can implement your VM subsystem several different ways.  Just 
remember that on a TLB-only machine you need to make sure the MMU handlers 
can access the page tables, either bypassing the MMU or using some trick 
that does not result in recursive TLB faults.

Eduardo
Technical Details
Message-ID: <fa.a/Nr8kFgmeefrHl8CNZayzk+Fkk@ifi.uio.no>
Path: arc1-ca.pugleaf.net!bp1ni25830pbd.1!nntp.google.com!npeer01.iad.highwinds-media.com!feed-me.highwinds-media.com!cyclone01.ams2.highwinds-media.com!news.highwinds-media.com!voer-me.highwinds-media.com!goblin2!goblin1!goblin.stu.neva.ru!uio.no!nntp.uio.no!.POSTED!not-for-mail
References: <fa.P+LZ+1jPGPfiK1II+UjtSSikPxk@ifi.uio.no>

Show Full Headers
Complete Article Headers
X-Google-Thread: b7e13b6095,8afd96964b6c90d9,start
X-Google-Attributes: gidb7e13b6095,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: ENGLISH,ASCII-7-bit
X-Received: by 10.66.192.8 with SMTP id hc8mr1772607pac.11.1369946764240;
        Thu, 30 May 2013 13:46:04 -0700 (PDT)
Path: arc1-ca.pugleaf.net!bp1ni25830pbd.1!nntp.google.com!npeer01.iad.highwinds-media.com!feed-me.highwinds-media.com!cyclone01.ams2.highwinds-media.com!news.highwinds-media.com!voer-me.highwinds-media.com!goblin2!goblin1!goblin.stu.neva.ru!uio.no!nntp.uio.no!.POSTED!not-for-mail
From: Eduardo Horvath <eeh@NetBSD.org>
Newsgroups: fa.netbsd.tech.kern
Subject: Re: [Milkymist port] virtual memory management
Date: Thu, 30 May 2013 20:46:03 UTC
Organization: Internet mailing list
Lines: 61
Sender: tech-kern-owner@NetBSD.org
Message-ID: <fa.a/Nr8kFgmeefrHl8CNZayzk+Fkk@ifi.uio.no>
References: <fa.P+LZ+1jPGPfiK1II+UjtSSikPxk@ifi.uio.no>
NNTP-Posting-Host: mail-jess.uio.no
Mime-Version: 1.0
X-Trace: readme.uio.no 1369946763 7509 129.240.7.9 (30 May 2013 20:46:03 GMT)
X-Complaints-To: abuse@uio.no
NNTP-Posting-Date: Thu, 30 May 2013 20:46:03 +0000 (UTC)
Cc: tech-kern@netbsd.org, devel@lists.milkymist.org, 
    Radoslaw Kujawa <radoslaw.kujawa@c0ff33.net>
To: Yann Sionneau <yann.sionneau@gmail.com>
Delivered-To: tech-kern@netbsd.org
In-Reply-To: <51A64013.8030603@gmail.com>
List-Id: tech-kern.NetBSD.org
Original-Date: Thu, 30 May 2013 20:45:50 +0000 (UTC)
Original-Message-Id: <Pine.NEB.4.64.1305302015370.9828@mail.netbsd.org>
Original-References: <51A64013.8030603@gmail.com>
X-Received-Bytes: 4085
Content-Type: TEXT/PLAIN; charset=US-ASCII