Hello. The diff in this email removes dead code in uvm_pmr_getpages(). This had bothered me for a bit because I had intuitively believed it wasn't necessary, but had never bothered to fully convince myself. Since I have now, I'll share the reasoning.
This diff concerns the following bit of code: if (maxseg == 1 || count == 1) { start_try = 2; search[2] = count; } else if (maxseg >= count && (flags & UVM_PLA_TRYCONTIG) == 0) { start_try = 2; search[2] = 1; } else { start_try = 0; search[0] = count; search[1] = pow2divide(count, maxseg); search[2] = 1; if ((flags & UVM_PLA_TRYCONTIG) == 0) start_try = 1; - if (search[1] >= search[0]) { - search[1] = search[0]; - start_try = 1; - } if (search[2] >= search[start_try]) { start_try = 2; } } The lines indicated are the ones to be removed. The reason is that search[1] will always be less than search[0] at this point in the code. Proof: From pow2divide() we know that search[1] is the smallest power of 2 that is >= 1 such that: search[1]*maxseg >= count == search[0]. This means that if search[1] is > 1 that search[1]*maxseg/2 < search[0]. We already know that maxseg is at least 2 because of the branch if (maxseg == 1 || count == 1) that would have been taken otherwise. Therefore, maxseg/2 is at least 1, so: search[1] <= search[1]*maxseg/2 < search[0] when search[1] is at least 2. If search[1] is 1, then search[1] < search[2] because search[2] == count and count is at least 2 from the branch mentioned previously. QED. Index: uvm_pmemrange.c =================================================================== RCS file: /cvs/src/sys/uvm/uvm_pmemrange.c,v retrieving revision 1.63 diff -u -p -u -p -r1.63 uvm_pmemrange.c --- uvm_pmemrange.c 10 Apr 2023 04:21:20 -0000 1.63 +++ uvm_pmemrange.c 10 Jun 2023 16:28:47 -0000 @@ -909,10 +909,6 @@ uvm_pmr_getpages(psize_t count, paddr_t search[2] = 1; if ((flags & UVM_PLA_TRYCONTIG) == 0) start_try = 1; - if (search[1] >= search[0]) { - search[1] = search[0]; - start_try = 1; - } if (search[2] >= search[start_try]) { start_try = 2; }