How do you setup your text and data for the kernel? Do you setup separate text and data region with different protections (execute for the text and read write for data) or do you just put it as one big region.
The advantage of having it one region is that you can use large pages without wasting too much memory and let kernel heap continue on the pages. For example you let the kernel heap expand upwards in large steps of 2MB for example. The benefit is that you get less TLB misses with large pages and have the option to lock one or more TLB entries. The disadvantage is that you get less protection in the kernel and more errors might slip through. Also once you allocate a new large page you will probably never get rid of it because of fragmentation.
You can also do the traditional and split code and data with different protection settings. Litter 4KB pages around but not waste RAM as much.
What do you think? Is the advantage of only using large pages that way in the kernel pages really worth it?
Page protection in kernel mode or not?
-
- Member
- Posts: 595
- Joined: Mon Jul 05, 2010 4:15 pm
Re: Page protection in kernel mode or not?
Both methods seem to have advantages. So why not use big pages, and if you suspect a bug that caught be caught by having finer grained protection then switch temporarily to 4k pages until the bug is fixed.
If a trainstation is where trains stop, what is a workstation ?
-
- Member
- Posts: 255
- Joined: Tue Jun 15, 2010 9:27 am
- Location: Flyover State, United States
- Contact:
Re: Page protection in kernel mode or not?
I prefer smaller pages, but I don't know if I can explain why.
What I am planning on doing is marking pages which contain only code or constant strings as read-only, as it would make debugging easier and help keep things more stable. Having an ELF kernel makes this easier, as I can make all my sections page-aligned and then use the base addresses and length of the sections to allocate pages initially.
What I am planning on doing is marking pages which contain only code or constant strings as read-only, as it would make debugging easier and help keep things more stable. Having an ELF kernel makes this easier, as I can make all my sections page-aligned and then use the base addresses and length of the sections to allocate pages initially.