Hi,
ces_mohab wrote:
Run kernel with disabling paging, while user applications enable paging. This will reserve benefits of paging and reduce time of mapping in kernel mode. Why not?
;D
One reason is that it's impossible to switch to the kernel (CPL=0) and disable paging at the same time (and impossible to return from the kernel and enable paging at the same time). This means you need to switch to the kernel, then run some kernel code that disables paging (then run more kernel code, enable paging, and return to user-level). Given that you must run some kernel code with paging enabled, you wouldn't gain a lot from running some kernel code with paging disabled (especially considering how often the CPU enters and leaves the kernel - IRQs, exceptions, the kernel API, etc).
Pype.Clicker wrote:
the big question is "does setting CR0.PG also flush the TLBs" ? if it does, that will be a performance killer.
According to my Intel manual, writing to CR3 or doing a hardware task switch causes TLB entries to be flushed
unless the are marked as "global"; and changing the PG or PE flag in CR0, an MTRR, or the PSE, PGE or PAE in CR4 will flush all TLB entries (regardless of whether they are marked as "global" or not).
Put simply, to minimize TLB flushing mark pages as "global" where possible, and never touch PG, PE, PSE, PGE PAE or MTRRs unless you absolutely must.
ces_mohab wrote:how will you translate that argument into a physical address ?
This can be done exactly as processor does. But is it more efficient than mapping and flushing TLB may be?? but I think in that way the kernel will take control over all memory directly.
I wouldn't be too sure about that - for fun, write down the steps you'd take to retrieve an 80-bit floating point value from the virtual address 0x12300FFC and load it into a floating point register. Don't forget to add potential data cache misses to your list (including data cache misses your kernel could cause while trying to access the user level code's page tables, and data cache misses your kernel could cause as it stores both parts of the 80-bit number in a temporary buffer).
ces_mohab wrote:Well I am not sure. I read before that processor under real mode is excuting faster than protected mode. And by the way I think that fetching page dirs and tables may be slower than segmented mode. ???
For "always use paging vs. never use paging", if you look at small sequences of instructions paging is slower because of the potential TLB misses. If you look at the system as a whole (e.g. an OS running several independant applications) paging is faster because of easier memory management and swap space control, shared pages, allocation on demand, etc.
For a simple example, imagine an application wants 200 MB of RAM for data. Without paging you'd need to allocate 200 MB of contiguous RAM and that RAM (regardless of whether it's actually used or not) can't be used for things like file system caches to improve performance, and it'll also increase the chance of needing swap space. With paging, the RAM you allocate doesn't need to be contiguous, and it doesn't need to be allocated immediately - you can allocate each page when it's accessed and keep using it to improve performance until then.
Cheers,
Brendan