But what puzzles me most is what will happen when I loaded into CR3 a page directory that has changed the mapping of the page marked as global?
when the page is marked as global in the TLB (clearing it in the tables will not affect it if it is currently in the TLB), it will
not be updated on a CR3 write, you must invlpg the page to change it (that is why the instruction was created -- it came to exist at the same time as the global bit)
when the CPU needs to access memory, it first looks in the TLB, if there is no entry, it loads the page table into a TLB -- when you reload CR3, all TLBs are marked as empy, so they will be reloaded as needed -- unless the TLB is marked global -- then it will retain its previous values, and the CPU wont even notice the changed table (all invlpg does is mark the TLB as invalid)
Yes, for threads that makes sense. But the sayings in the manual seems to suggest it be kept during task switches. I am sort of confused over the concept of "Task" and "Threads", "Process". It seems to me that "Task" is somewhat equivalent to "Process". But on the other side, "Thread" means execution path switching and in the processor realm, "Tasking Switching"(either hardware or software) is the only way so "Threads" can be treated as "Task" in a broad sense. Am I wrong?
this confusion is normal -- everyone has a different definition of process and thread
some OSs treat both threads and processes exactly the same -- without any difference, but most keep threads as processes which share address space -- they are handled by the task-switch, but they are handled differently (no CR3 load if switch is a new thread in the same process), so yes, there is a task-switch, and the address space stays the same through it, and other times (when switching to a different process) it does change, making this a true hybred solution
So as a summary, different processes (these forked or copy-on-write excluded) shall have different page directory mappings yet they all contain some entries that are common among all which are for shared resources (code or data, such as interrupt call, system kernel data). Is that right?
yes, i think that is correct (ignoring, for now, threads -- which some treat the same as processes anyway)
i hope ive been able to help you