Rather perhaps this is the problem:Brendan wrote:Here's what you're trying to avoid:
- Process 1, thread 1, running on CPU#1 frees the page (and TLB entry is invalidated on CPU#1, and the IPI is sent to other CPUs)
- Process 2, thread ?, running on CPU#2 allocates the page and stores your passwords in it
- Process 1, thread 2, running on CPU#3 still has an old TLB entry for the page (because it hasn't invalidated yet), and reads the passwords from process 2
- CPU #2 receives the IPI, but it's too late
- Process 1, thread 1, running on CPU#1 frees the page (and makes it available in the free pool of pages)
- Process 2, thread ?, running on CPU#2 allocates the page and stores your passwords in it
- Process 1, thread 2, running on CPU#3 still has an old TLB entry (CPU#1 still hasn't reached the point where it invalidates TLBs with IPIs), and reads the passwords from process 2
- Process 1, thread 1, running on CPU#1 sends the IPIs
With this new algorithm, the scenario changes to this:
- Process 1, thread 1, running on CPU#1 frees the page and places it in a locked page-pool
- Process 2, thread ?, running on CPU#2 cannot allocate this page (but gets another page).
- Process 1, thread 2, running on CPU#3 still has an old TLB entry, and can read/modify it until it receives the IPI
- Process 1, thread 1, running on CPU#1 sends the IPIs
- CPU#2 and CPU#3 gets the IPIs
- The scheduler on CPU#2 notices that the locked pool contains pages, and that there are no pending IPIs, so it puts the page in the free pool.
OK. So the new interface should actually do one more thing. If it is a non-SMP-system, it should place the freed physical pages in the free pool, while if it is a SMP system, it should place them in the locked page-pool.
With this design, the header will contain the pages from a request, which could contain one or more physical pages. The header could also contain a timestamp that can be used to know when it would be safe to place the pages in the free pool (especially under heavy load when there might always be pending IPIs).