On 04/17/2013 07:38 AM, Kirill A. Shutemov wrote: >> > Ugh. This is essentially a copy-n-paste of code in __do_fault(), >> > including the comments. Is there no way to consolidate the code so that >> > there's less duplication here? > I've looked into it once again and it seems there's not much space for > consolidation. Code structure looks very similar, but there are many > special cases for thp: fallback path, pte vs. pmd, etc. I don't see how we > can consolidate them in them in sane way. > I think copy is more maintainable :( I took the two copies, put them each in a file, changed some of the _very_ trivial stuff to match (foo=1 vs foo=true) and diffed them. They're very similar lengths (in lines): 185 __do_fault 197 do_huge_linear_fault If you diff them: 1 file changed, 68 insertions(+), 56 deletions(-) That means that of 185 lines in __do_fault(), 129 (70%) of them were copied *VERBATIM*. Not similar in structure or appearance. Bit-for-bit the same. I took a stab at consolidating them. I think we could add a VM_FAULT_FALLBACK flag to explicitly indicate that we need to do a huge->small fallback, as well as a FAULT_FLAG_TRANSHUGE to indicate that a given fault has not attempted to be handled by a huge page. If we call __do_fault() with FAULT_FLAG_TRANSHUGE and we get back VM_FAULT_FALLBACK or VM_FAULT_OOM, then we clear FAULT_FLAG_TRANSHUGE and retry in handle_mm_fault(). I only went about 1/4 of the way in to __do_fault(). If went and spent another hour or two, I'm pretty convinced I could push this even further. Are you still sure you can't do _any_ better than a verbatim copy of 129 lines?