Page MenuHomeFreeBSD

pctrie: avoid pointless null check in lookup
Needs ReviewPublic

Authored by dougm on Nov 18 2024, 5:19 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Jan 10, 3:56 AM
Unknown Object (File)
Dec 12 2024, 6:59 AM
Unknown Object (File)
Nov 24 2024, 6:41 PM
Unknown Object (File)
Nov 24 2024, 4:58 PM
Unknown Object (File)
Nov 24 2024, 4:58 PM
Unknown Object (File)
Nov 23 2024, 10:56 AM
Unknown Object (File)
Nov 19 2024, 8:24 PM
Unknown Object (File)
Nov 19 2024, 8:23 PM
Subscribers
None
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

When a pctrie lookup function is checked for a null return value, there are two null checks - one for whether the sought item was found or not, and another, in the case that a non-null address was found, to check to see if computing the start of the struct containing the index field is at address zero. It is never at address zero, so add a __builtin_assume for that case, to allow the compiler to avoid a pointless zero check.

Here's an example of the impact - the difference between the codes generated for vm_page_lookup before and after this change:

2235,2240c2237,2245
<     23bd: 48 8d 48 d8                         leaq    -0x28(%rax), %rcx
<     23c1: 48 85 c0                            testq   %rax, %rax
<     23c4: 48 0f 45 c1                         cmovneq %rcx, %rax
<     23c8: 5d                                  popq    %rbp
<     23c9: c3                                  retq
<     23ca: 66 0f 1f 44 00 00                   nopw    (%rax,%rax)
---
>     23bd: 48 85 c0                            testq   %rax, %rax
>     23c0: 74 06                               je      0x23c8 <vm_page_lookup+0
x18>
>     23c2: 48 83 c0 d8                         addq    $-0x28, %rax
>     23c6: 5d                                  popq    %rbp
>     23c7: c3                                  retq
>     23c8: 31 c0                               xorl    %eax, %eax
>     23ca: 5d                                  popq    %rbp
>     23cb: c3                                  retq
>     23cc: 0f 1f 40 00                         nopl    (%rax)

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

dougm requested review of this revision.Nov 18 2024, 5:19 AM
dougm created this revision.

Use vm_radix_iter_found in swap_pager.c. Tweak the pctrie.h implement to avoid a pointless null check.

dougm retitled this revision from subr_pctrie: add find method to avoid lookup overload to pctrie: avoid pointless null check in lookup.
dougm edited the summary of this revision. (Show Details)

Shouldn't this be abandoned?