Page MenuHomeFreeBSD

vm_phys_enqueue_contig: handle zero pages
ClosedPublic

Authored by dougm on Jul 22 2023, 10:31 PM.
Tags
None
Referenced Files
F102926344: D41154.id125473.diff
Mon, Nov 18, 8:16 PM
F102925648: D41154.id125484.diff
Mon, Nov 18, 8:01 PM
Unknown Object (File)
Mon, Nov 11, 4:33 PM
Unknown Object (File)
Mon, Nov 11, 6:29 AM
Unknown Object (File)
Tue, Nov 5, 8:55 AM
Unknown Object (File)
Oct 17 2024, 5:40 AM
Unknown Object (File)
Oct 17 2024, 4:15 AM
Unknown Object (File)
Oct 17 2024, 4:09 AM
Subscribers

Details

Summary

By letting vm_phys_enqueue_contig handle the case when npages == 0, the callers can stop checking it, and the compiler can stop zero-checking with every call to ffs(). Letting vm_phys_enqueue_contig call vm_phys_enqueue_contig for part of its work also saves a few bytes.

The amd64 object code shrinks by 80 bytes.

Test Plan

Peter, can you test this please?

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

dougm created this revision.

Take care in vm_phys_enqueue_contig to handle npages==0 and npages==1 properly.

Using objdump outputs to compare start addresses of vm_phys functions before and after this change

Before                                                          After
0000000000000090 <vm_phys_mem_affinity>:                        0000000000000090 <vm_phys_mem_affinity>:
00000000000000c0 <vm_phys_add_seg>:                             00000000000000c0 <vm_phys_add_seg>:
0000000000000130 <vm_phys_create_seg>:                          0000000000000130 <vm_phys_create_seg>:
0000000000000350 <vm_phys_init>:                                0000000000000350 <vm_phys_init>:
0000000000000870 <vm_phys_register_domains>:                    0000000000000870 <vm_phys_register_domains>:
0000000000000930 <vm_phys_alloc_npages>:                        0000000000000930 <vm_phys_alloc_npages>:
0000000000000f00 <vm_phys_alloc_pages>:                       | 0000000000000ec0 <vm_phys_alloc_pages>:
0000000000000f70 <vm_phys_alloc_freelist_pages>:              | 0000000000000f30 <vm_phys_alloc_freelist_pages>:
00000000000011d0 <vm_phys_paddr_to_vm_page>:                  | 0000000000001190 <vm_phys_paddr_to_vm_page>:
0000000000001250 <vm_phys_fictitious_to_vm_page>:             | 0000000000001210 <vm_phys_fictitious_to_vm_page>:
00000000000012c0 <vm_phys_fictitious_reg_range>:              | 0000000000001280 <vm_phys_fictitious_reg_range>:
0000000000001790 <vm_phys_fictitious_unreg_range>:            | 0000000000001750 <vm_phys_fictitious_unreg_range>:
0000000000001b50 <vm_phys_free_pages>:                        | 0000000000001b10 <vm_phys_free_pages>:
0000000000001cf0 <vm_phys_enqueue_contig>:                    | 0000000000001cb0 <vm_phys_enqueue_contig>:
0000000000001e90 <vm_phys_free_contig>:                       | 0000000000001e40 <vm_phys_free_contig>:
0000000000001f80 <vm_phys_find_range>:                        | 0000000000001f30 <vm_phys_find_range>:
0000000000002060 <vm_phys_unfree_page>:                       | 0000000000002010 <vm_phys_unfree_page>:
00000000000021f0 <vm_phys_alloc_contig>:                      | 00000000000021a0 <vm_phys_alloc_contig>:
0000000000002730 <vm_phys_avail_largest>:                     | 00000000000026e0 <vm_phys_avail_largest>:
0000000000002790 <vm_phys_avail_size>:                        | 0000000000002740 <vm_phys_avail_size>:
00000000000027b0 <vm_phys_is_dumpable>:                       | 0000000000002760 <vm_phys_is_dumpable>:
0000000000002890 <vm_phys_early_add_seg>:                     | 0000000000002840 <vm_phys_early_add_seg>:
00000000000028f0 <vm_phys_early_alloc>:                       | 00000000000028a0 <vm_phys_early_alloc>:
0000000000002b30 <vm_phys_avail_split>:                       | 0000000000002ae0 <vm_phys_avail_split>:
0000000000002ce0 <vm_phys_early_startup>:                     | 0000000000002c90 <vm_phys_early_startup>:
0000000000002f30 <sysctl_vm_phys_free>:                       | 0000000000002ee0 <sysctl_vm_phys_free>:
0000000000003120 <sysctl_vm_phys_segs>:                       | 00000000000030d0 <sysctl_vm_phys_segs>:
0000000000003220 <sysctl_vm_phys_locality>:                   | 00000000000031d0 <sysctl_vm_phys_locality>:

Make sure the right find-{first,last}-bit is invoked on addresses.

This revision is now accepted and ready to land.Aug 1 2023, 10:28 PM
This revision was automatically updated to reflect the committed changes.
dougm edited the test plan for this revision. (Show Details)
dougm added a subscriber: pho.

Fix, hopefully, the length parameter in the last call to vm_phys_enq_range.

This revision is now accepted and ready to land.Aug 2 2023, 11:15 PM

With D41154.125484.patch I now see:

igb0: <Intel(R) I350 (Copper)> port 0xd020-0xd03f mem 0xfb320000-0xfb33ffff,0xfb344000-0xfb347fff irq 16 at device 0.0 on pci8
igb0: EEPROM V1.63-0 eTrack 0x800009fa
igb0: Using 1024 TX descriptors and 1024 RX descriptors
igb0: queue equality override not set, capping rx_queues at 6 and tx_queues at 6
igb0: Usin
db> show panic
panic: vm_phys_enq_range: page 0xfffffe0002fd4c18 and npages 0 are misaligned
db> x/s version
version:        FreeBSD 14.0-CURRENT #0 main-n264491-8a5c836b51ce2-dirty: Thu Aug  3 06:23:37 CEST 2023\012    pho@mercat1.netperf.freebsd.org:/usr/sr
db> bt
Tracing pid 37 tid 100210 td 0xfffffe010e620900  
kdb_enter() at kdb_enter+0x32/frame 0xfffffe010db821f0
vpanic() at vpanic+0x17a/frame 0xfffffe010db82240
panic() at panic+0x43/frame 0xfffffe010db822a0
vm_phys_enq_range() at vm_phys_enq_range+0x11d/frame 0xfffffe010db822b0
vm_phys_alloc_npages() at vm_phys_alloc_npages+0x5a6/frame 0xfffffe010db82320
vm_page_zone_import() at vm_page_zone_import+0xa7/frame 0xfffffe010db82370
zone_alloc_item() at zone_alloc_item+0x78/frame 0xfffffe010db823c0
vm_page_alloc_domain_after() at vm_page_alloc_domain_after+0x151/frame 0xfffffe010db82450
vm_page_alloc() at vm_page_alloc+0x64/frame 0xfffffe010db824b0
vm_fault_allocate() at vm_fault_allocate+0x1a5/frame 0xfffffe010db82520
vm_fault() at vm_fault+0x448/frame 0xfffffe010db82650
vm_fault_trap() at vm_fault_trap+0x6f/frame 0xfffffe010db82690
trap_pfault() at trap_pfault+0x24a/frame 0xfffffe010db82700
calltrap() at calltrap+0x8/frame 0xfffffe010db82700
--- trap 0xc, rip = 0xffffffff8104db36, rsp = 0xfffffe010db827d0, rbp = 0xfffffe010db827d0 ---
copyout_nosmap_erms() at copyout_nosmap_erms+0x156/frame 0xfffffe010db827d0
elf64_load_sections() at elf64_load_sections+0x283/frame 0xfffffe010db82860
elf64_load_file() at elf64_load_file+0x280/frame 0xfffffe010db828c0
elf64_load_interp() at elf64_load_interp+0x67/frame 0xfffffe010db82900
exec_elf64_imgact() at exec_elf64_imgact+0xe01/frame 0xfffffe010db829f0
kern_execve() at kern_execve+0x772/frame 0xfffffe010db82d80
sys_execve() at sys_execve+0x58/frame 0xfffffe010db82e00
amd64_syscall() at amd64_syscall+0x14f/frame 0xfffffe010db82f30
fast_syscall_common() at fast_syscall_common+0xf8/frame 0xfffffe010db82f30
--- syscall (59, FreeBSD ELF64, execve), rip = 0x254589a5b30a, rsp = 0x2545874dfdf8, rbp = 0x2545874dff40 ---
db> 
db> show proc
Process 37 (sh) at 0xfffffe010e96b000:
 state: NORMAL
 uid: 0  gids: 0
 parent: pid 20 at 0xfffffe003ce595c0
 ABI: FreeBSD ELF64
 flag: 0x14000002  flag2: 0
 arguments: /bin/sh -o verify /etc/rc autoboot
 reaper: 0xfffffe00e4c65040 reapsubtree: 1
 sigparent: 20
 vmspace: 0xfffffe010e95a860
   (map 0xfffffe010e95a860)
   (map.pmap 0xfffffe010e95a920)
   (pmap 0xfffffe010e95a990)
 threads: 1
100210                   Run     CPU 0                       sh
db> 
``

Rewrite the KASSERT at the start of vm_phys_enq_range to handle npages==0.

This revision now requires review to proceed.Aug 3 2023, 5:04 AM

I ran a buildkernel and a few other test with D41154.125493.patch.
I did not observe any issues.

This revision was not accepted when it landed; it landed in state Needs Review.Aug 3 2023, 2:22 PM
This revision was automatically updated to reflect the committed changes.