Confusion regarding TLB flush
I as trying to track down sources of TLB flushes (x86_64, kernel version 2.6.31). In the process I found something interesting that I could not really understand why. The issue is as follows:
Many system calls that modify a range of virtual memory addresses (e.g., munmap, madvise etc) needs to do TLB flushes to make sure old mappings are not used from TLB.
In that process they end up calling tlb_flush_mmu(...) function in include/asm-generic/tlb.h. The function takes argument for the start and the end of the virtual address range that needs to be flushed. But what is confusing is that this function ignores the address range parameters (start and end) for which the flushing was intended. Internally it then calls tlb_flush which in turn gets converted to flush_tlb_mm for x86. Calling flush_tlb_mm flushes all user mapping for the process. My question is that when the requirement was only to flush a range of address (which can be done by calling flush_tlb_range ), why all the mapping for the process was invalidated? Is there any other reason/ performance implication of doing it?