Page MenuHomeFreeBSD

pctrie: avoid pointless null check in lookup
AbandonedPublic

Authored by dougm on Nov 18 2024, 5:19 AM.
Tags
None
Referenced Files
F132580160: D47656.diff
Sat, Oct 18, 3:42 AM
Unknown Object (File)
Sun, Oct 12, 4:57 PM
Unknown Object (File)
Fri, Oct 10, 12:28 AM
Unknown Object (File)
Sun, Oct 5, 11:42 PM
Unknown Object (File)
Fri, Oct 3, 12:34 PM
Unknown Object (File)
Sat, Sep 27, 11:01 PM
Unknown Object (File)
Sep 15 2025, 12:19 PM
Unknown Object (File)
Sep 12 2025, 9:37 PM
Subscribers
None

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?