I'm reading about huge pages in Linux, where the idea is using, say, 2MiB page size instead of 4KiB page size, to reduce TLB misses. I understand that modern CPUs have both data and instruction TLBs, and have separate TLBs for huge pages. What I don't understand is how does the CPU know that a given virtual address is actually pointing to a huge page? It can't just be alignment because there's no guarantee that there are any huge pages allocated at all. Does this mean that the CPU always have to look in both the 4K and the 2M TLBs, just in case? Or what's the mechanism being used?
A related question is, how does Linux handle page tables when a process uses a mixture of 4K and 2M pages? I mean, it can't just mix them in the same page tables, right?