freebsd 14.3 custom kernel wired memory

fresh install on qemu/kvm of freebsd 14.3
with GENERIC kernel , wired memory at 'top' command was 120MB.
I edited the GENERIC kernel file with new name as following and compiled it. I also added "NO_MODULES=true" at /etc/make.conf.
rebooted, kldstat -h shows kernel as 15MB now, "du -sh /boot/kernel is 13M" . but wired memory is still 120MB. what am i missing :/

the kernel file i have edited and compiled is :

Code:
cpu        HAMMER
ident            VMBSD   

makeoptions    DEBUG=-g        # Build kernel with gdb(1) debug symbols
makeoptions    WITH_CTF=1        # Run ctfconvert(1) for DTrace support

options     SCHED_ULE        # ULE scheduler
options     NUMA            # Non-Uniform Memory Architecture support
options     PREEMPTION        # Enable kernel thread preemption
options     VIMAGE            # Subsystem virtualization, e.g. VNET
options     INET            # InterNETworking
nooptions     INET6            # IPv6 communications protocols
nooptions     IPSEC_SUPPORT        # Allow kldload of ipsec and tcpmd5
nooptions     ROUTE_MPATH        # Multipath routing support
nooptions     FIB_ALGO        # Modular fib lookups
nooptions     TCP_OFFLOAD        # TCP offload
nooptions     TCP_BLACKBOX        # Enhanced TCP event logging
nooptions     TCP_HHOOK        # hhook(9) framework for TCP
nooptions     TCP_RFC7413        # TCP Fast Open
nooptions     SCTP_SUPPORT        # Allow kldload of SCTP
nooptions     KERN_TLS        # TLS transmit & receive offload
options     FFS            # Berkeley Fast Filesystem
options     SOFTUPDATES        # Enable FFS soft updates support
options     UFS_ACL            # Support for access control lists
options     UFS_DIRHASH        # Improve performance on big directories
options     UFS_GJOURNAL        # Enable gjournal-based UFS journaling
options     QUOTA            # Enable disk quotas for UFS
nooptions     MD_ROOT            # MD is a potential root device
nooptions     NFSCL            # Network Filesystem Client
nooptions     NFSD            # Network Filesystem Server
nooptions     NFSLOCKD        # Network Lock Manager
nooptions     NFS_ROOT        # NFS usable as /, requires NFSCL
nooptions     MSDOSFS            # MSDOS Filesystem
nooptions     CD9660            # ISO 9660 Filesystem
options     PROCFS            # Process filesystem (requires PSEUDOFS)
options     PSEUDOFS        # Pseudo-filesystem framework
options     TMPFS            # Efficient memory filesystem
options     GEOM_RAID        # Soft RAID functionality.
options     GEOM_LABEL        # Provides labelization
options     EFIRT            # EFI Runtime Services support
nooptions     COMPAT_FREEBSD32    # Compatible with i386 binaries
nooptions     COMPAT_FREEBSD4        # Compatible with FreeBSD4
nooptions     COMPAT_FREEBSD5        # Compatible with FreeBSD5
nooptions     COMPAT_FREEBSD6        # Compatible with FreeBSD6
nooptions     COMPAT_FREEBSD7        # Compatible with FreeBSD7
nooptions     COMPAT_FREEBSD9        # Compatible with FreeBSD9
nooptions     COMPAT_FREEBSD10    # Compatible with FreeBSD10
nooptions     COMPAT_FREEBSD11    # Compatible with FreeBSD11
nooptions     COMPAT_FREEBSD12    # Compatible with FreeBSD12
nooptions     COMPAT_FREEBSD13    # Compatible with FreeBSD13
nooptions     KTRACE            # ktrace(1) support
nooptions     STACK            # stack(9) support
nooptions     SYSVSHM            # SYSV-style shared memory
nooptions     SYSVMSG            # SYSV-style message queues
nooptions     SYSVSEM            # SYSV-style semaphores
options     _KPOSIX_PRIORITY_SCHEDULING # POSIX P1003_1B real-time extensions
options     PRINTF_BUFR_SIZE=128    # Prevent printf output being interspersed.
nooptions     KBD_INSTALL_CDEV    # install a CDEV entry in /dev
options     HWPMC_HOOKS        # Necessary kernel hooks for hwpmc(4)
nooptions     AUDIT            # Security event auditing
nooptions     CAPABILITY_MODE        # Capsicum capability mode
nooptions     CAPABILITIES        # Capsicum capabilities
nooptions     MAC            # TrustedBSD MAC Framework
nooptions     KDTRACE_FRAME        # Ensure frames are compiled in
nooptions     KDTRACE_HOOKS        # Kernel DTrace hooks
options     DDB_CTF            # Kernel ELF linker loads CTF data
options     INCLUDE_CONFIG_FILE    # Include this file in kernel
nooptions     RACCT            # Resource accounting framework
nooptions     RACCT_DEFAULT_TO_DISABLED # Set kern.racct.enable=0 by default
nooptions     RCTL            # Resource limits

# Debugging support.  Always need this:
nooptions     KDB            # Enable kernel debugger support.
nooptions     KDB_TRACE        # Print a stack trace for a panic.

# Kernel Sanitizers
nooptions     COVERAGE        # Generic kernel coverage. Used by KCOV
nooptions     KCOV            # Kernel Coverage Sanitizer
# Warning: KUBSAN can result in a kernel too large for loader to load
nooptions     KUBSAN            # Kernel Undefined Behavior Sanitizer
nooptions     KCSAN            # Kernel Concurrency Sanitizer

# Kernel dump features.
nooptions     EKCD            # Support for encrypted kernel dumps
nooptions     GZIO            # gzip-compressed kernel and user dumps
nooptions     ZSTDIO            # zstd-compressed kernel and user dumps
nooptions     DEBUGNET        # debugnet networking
nooptions     NETDUMP            # netdump(4) client support
nooptions     NETGDB            # netgdb(4) client support

# Make an SMP-capable kernel by default
options     SMP            # Symmetric MultiProcessor Kernel

# CPU frequency control
device        cpufreq

# Bus support.
device        acpi
device        smbios
options     IOMMU
device        pci
options     PCI_HP            # PCI-Express native HotPlug
options     PCI_IOV            # PCI SR-IOV support

nooptions     COMPAT_LINUXKPI

# Enable support for the kernel PLL to use an external PPS signal,
# under supervision of [x]ntpd(8)
# More info in ntpd documentation: http://www.eecis.udel.edu/~ntp

nooptions     PPS_SYNC


# ATA controllers
device        ahci            # AHCI-compatible SATA controllers
device        ata            # Legacy ATA/SATA controllers


# ATA/SCSI peripherals
device        scbus            # SCSI bus (required for ATA/SCSI)
device        da            # Direct Access (disks)


# NVM Express (NVMe) support
device        nvme            # base NVMe driver
device        nvd            # expose NVMe namespaces as disks, depends on nvme


# atkbdc0 controls both the keyboard and the PS/2 mouse
device        atkbdc            # AT keyboard controller
device        atkbd            # AT keyboard
device        psm            # PS/2 mouse

device        kbdmux            # keyboard multiplexer

# syscons is the legacy console driver, resembling an SCO console
device        vga            # VGA video card driver
device        splash            # Splash screen and screen saver support
device        sc
options     SC_PIXEL_MODE        # add support for the raster text mode

# vt is the default video console driver
device        vt
device        vt_vga
device        vt_efifb
device        vt_vbefb

device        agp            # support several AGP chipsets



# PCI/PCI-X/PCIe Ethernet NICs that use iflib infrastructure
device        iflib
device        vmx            # VMware VMXNET3 Ethernet



# Pseudo devices.
device        crypto            # core crypto support
device        aesni            # AES-NI OpenCrypto module
device        loop            # Network loopback
device        padlock_rng        # VIA Padlock RNG
device        rdrand_rng        # Intel Bull Mountain RNG
device        ether            # Ethernet support
device        vlan            # 802.1Q VLAN support
device        tuntap            # Packet tunnel.
device        md            # Memory "disks"
device        gif            # IPv6 and IPv4 tunneling
device        firmware        # firmware assist module
device        xz            # lzma decompression

# The `bpf' device enables the Berkeley Packet Filter.
# Be aware of the administrative consequences of enabling this!
# Note that 'bpf' is required for DHCP.
device        bpf            # Berkeley packet filter

# USB support
options     USB_DEBUG        # enable debug msgs
device        uhci            # UHCI PCI->USB interface
device        ohci            # OHCI PCI->USB interface
device        ehci            # EHCI PCI->USB interface (USB 2.0)
device        xhci            # XHCI PCI->USB interface (USB 3.0)
device        usb            # USB Bus (required)
device        usbhid            # USB HID Transport
device        hkbd            # HID Keyboard
device        ukbd            # USB Keyboard
device        umass            # Disks/Mass storage - Requires scbus and da

# Sound support
device        sound            # Generic sound driver (required)
device        snd_hda            # Intel High Definition Audio
device        snd_ich            # Intel, NVidia and other ICH AC'97 Audio


# VirtIO support
device        virtio            # Generic VirtIO bus (required)
device        virtio_pci        # VirtIO PCI device
device        vtnet            # VirtIO Ethernet device
device        virtio_blk        # VirtIO Block device
device        virtio_scsi        # VirtIO SCSI device
device        virtio_balloon        # VirtIO Memory Balloon device

# Linux KVM paravirtualization support
device        kvm_clock        # KVM paravirtual clock driver



# Netmap provides direct access to TX/RX rings on supported NICs
device        netmap            # netmap(4) support

# evdev interface
options     EVDEV_SUPPORT        # evdev support in legacy drivers
device        evdev            # input event device support
device        uinput            # install /dev/uinput cdev

# HID support
options     HID_DEBUG        # enable debug msgs
device        hid            # Generic HID support
device        hidbus            # Generic HID Bus
options     IICHID_SAMPLING        # Workaround missing GPIO INTR support
 
Regarding wired memory being 120 MB (greater than size of kernel file): as far as I know, wired memory does not a 1-to-1 reflection of memory taken by the kernel file, i.e. wired memory does not consist only of kernel file. Sure, the kernel file is always wired, but some other processes can wire the memory too. You will most likely notice it if you start some more applications.

Regarding the fact that kldstat(8) and du(1) on kernel file report different sizes: well, I don't know the answer yet, but it seems interesting to me. I have a pretty lean kernel configuration on my 14.3-STABLE and kldstat reports 15 MB, and du - 12 MB. So I got really curious and tried to trace it through source code. Well, it came down to kldstat(2) syscall and into some kernel sources. So far I've found that `linker_file` has the `size` member which is eventually got reported (or I may be wrong). I found `kern_kldstat` function in /usr/src/sys/kern/kern_linker.c, where `linker_file` is obtained and `size` from it is used. However, I still can not find the place, where `size` itself is set. Well, I found kobj_create(9) in /usr/src/sys/kern/subr_kobj.c, but there size is initialized to 0.

Like that, that's what I can give you.
 
Last edited:
thanks for the reply :)

well the thing is i'm trying to figure out if the kernel size is 15MB , what is the rest 105MB wired to in the memory that is non interchangeable ? :-/ given the kernel config i have added at my 1st post, there is not much of things (device or option) to make 100MB :what:

but some other processes can wire the memory too. You will most likely notice it if you start some more applications.
its fresh 14.3 install with no additional installed application


to make things even more interesting : vmstat -m

Code:
              Type  Use Memory Req Size(s)
CAM I/O Scheduler    1   128    1 128
      CAM periph    4   896   20 16,32,64,128,256
       CAM queue   11  6.1K   33 16,32,1K
   CAM dev queue    5   320    5 64
         CAM SIM    5   640    5 128
         CAM XPT   24  1.8K   53 16,32,128,512,1K,2K,64K
         CAM DEV    6   12K   13 2K
         CAM CCB    0     0   39 2K
        CAM path    7   224   48 32
        acpiintr    1    64    1 64
          acpica 2.8k  283K 162k 16,32,64,128,256,384,512,1K,2K
        acpitask    1  224K    1
         acpisem   62  7.8K   62 128
         acpidev   45  5.1K   45 64,128
       acpi_perf    4   512    4 128
             agp    1    32    1 32
           evdev    9  9.5K    9 512,1K,2K
          kbdmux    6   27K    6 16,384,1K,2K,8K,16K
         entropy    0     0   73 32,64,4K
            hdaa    5   34K    5 384,512,1K,16K
            hdac    1  1.0K    1 1K
           hdacc    1    32    1 32
          feeder   11   736   13 32,128
           mixer    1  4.0K    1 4K
             USB   45  110K   49 16,32,128,256,384,1K,2K,4K,8K,32K,64K
          USBdev   36  4.2K   36 32,64,128,256,384,512
           vtbuf   24  1.9M   46 4K
              vt   11  4.1K   11 384
          DEVFS3  132   33K  156 256
          DEVFS1  109  109K  141 1K
      DEVFS_RULE   61   21K   61 64,384
           DEVFS   18   400   19 16,128
   NFSD srvcache    3   68K    3 4K,32K
   NFSD V4client    1   256    1 256
    NFSD lckfile    1   256    1 256
    NFSD session    1  1.0K    1 1K
       pfs_nodes   20  5.0K   20 256
     pfs_vncache    1  8.0K    1 8K
            GEOM   50  9.2K  736 16,32,64,128,256,512,1K,2K,8K,16K
       raid_data    0     0  108 32,128,256
          isadev    3   384    3 128
            cdev    3   768    3 256
        filedesc    1  4.0K    1 4K
         pwddesc   41  2.6K 1.5k 64
           sigio    0     0    1 64
        filecaps    0     0  260 16,32,64
         kdtrace  218   47K 1.7k 64,256
            kenv  117   13K  117 16,32,64,128,8K
          kqueue   41  2.6K 1.5k 64
       proc-args   74  2.4K 4.3k 16,32,64,128,256
     Fail Points    0     0   48 1K
           hhook   15  4.9K   17 16,32,384
         ithread   66   11K   66 32,128,256
          prison    6   192    6 32
          KTRACE  100  200K  100 2K
          linker  347  459K  406 16,32,64,128,256,384,512,1K,2K,4K,8K,16K,32K
           lockf   17  1.8K  281 64,128
      loginclass    3   192    3 64
          devbuf 2.5k   11M 2.7k 16,32,64,128,256,384,512,1K,2K,4K,8K,32K,64K
            temp   42   53K 5.0k 16,32,64,128,256,384,512,1K,2K,4K,8K,16K,32K,64K
          module  511   64K  511 128
        mtx_pool    2   72K    2 8K,64K
             osd    8   400   37 16,32,64,128,256
        pmchooks    1   128    1 128
             pmc    1    64    1 64
         session   17  2.1K  161 128
            proc    3   17K    3 512,8K
         subproc  130  197K 1.6k 384,4K
            cred   21  5.3K 1.4k 256
          plimit   17  6.4K 2.4k 384
         uidinfo    3  2.3K  133 128,2K
          dumper    2   640    2 128,512
          sysctl    1    32   61 32,64
       sysctloid  22k  1.2M  22k 16,32,64,128
       sysctltmp    0     0 1.6k 16,32,64,256,1K
         tidhash    3  141K    3 1K,16K
         callout    4  1.0M    4
            umtx  400   50K  400 128
        p1003.1b    1    16    1 16
            SWAP    1  264K    1
             bus 1.2k  105K  13k 16,32,64,128,256,4K
          bus-sc   89  921K 3.7k 16,32,64,128,256,384,512,1K,2K,4K,8K,16K,32K,64K
         devstat    6   12K    6 32,4K
    eventhandler  137   11K  137 64,128
      gtaskqueue   30   99K   30 16,32,256,32K
            kobj  336  1.3M  556 4K
         Per-cpu    1    32    1 32
            rman  237   27K  586 16,32,128
            sbuf    1   128 4.8k 16,32,64,128,256,512,1K,4K,8K,64K
       toponodes   11  2.8K   11 256
           stack    0     0  480 256
       taskqueue   60  6.3K  132 16,32,64,256
        terminal   11  2.8K   11 256
          Unitno   29  1.8K   63 32,64
            vmem    3  138K    4 1K,2K,8K
        ioctlops    0     0   78 256,384,1K
          select    7   896   53 128
             iov    0     0  26k 16,64,128,256,384
           selfd   22  1.4K 147k 64
        procdesc    0     0   16 128
             msg    4   30K    4 2K,4K,8K,16K
             sem    4  106K    4 2K,4K
             shm    1   32K    1 32K
             tty   13   13K   13 1K
             pts    1   256    1 256
           shmfd    1  8.0K    1 8K
          soname    5   240 6.9k 16,32,64,128
             pcb   16  524K   58 16,64,256,1K,2K
          biobuf    1  1.0K    1 1K
        vfscache    3  1.0M    3 1K,2K
        vfs_hash    1  512K    1
          vnodes    1   256    1 256
           mount   16   736   89 16,32,64,128,256,1K
          statfs    0     0   12 4K
     vnodemarker    2  1.0K 1.6k 512
  chacha20random    1  1.0K    1 1K
             BPF    2   256    2 128
           ifnet    3  4.1K    3 128,2K
          ifaddr   35   11K   35 16,32,64,128,256,384,2K,4K
     ether_multi   17  1.3K   17 16,32,64,128
           clone    8  2.0K    8 256
         lltable   11  3.1K   12 256,384
             tun    3    96    3 32
            pfil    5   640    5 128
           nhops    6   768    6 128
        routetbl   43  9.1K  131 32,64,128,256,384,512,1K,2K
            vnet    1    64    1 64
       vnet_data    1  112K    1
  vnet_data_free    1    32    1 32
       80211node    0     0 1.7k 16
       80211scan    1   16K    1 16K
            igmp    2   256    2 128
        in_multi    2   512    2 256
encap_export_host    8   448    8 32,64
        IP reass    1  128K    1
          CC Mem    3   768    3 256
      tfo_ccache    1  128K    1
       hostcache    1   32K    1 32K
         tcpfunc    1    64    1 64
        syncache    1   68K    1
       in6_multi   15  1.6K   15 32,256
             mld    2   256    2 128
          ip6ndp    3   384    3 64,256
     inpcbpolicy    5   160   47 32
        secasvar    1  1.0K    1 1K
          sahead    1  1.0K    1 1K
     ipsecpolicy    1  1.0K    1 1K
       ipsec-saq    2  2.0K    2 1K
         netlink    2   512   37 128,384,2K
     lkpikmalloc    8   752    9 16,32,64,512
          crypto    3   704    3 64,256,384
   audit_evclass  239  7.5K  301 32
         pagedep    2  128K   26 256
        inodedep    4  513K  149 384
       bmsafemap    2  8.3K  125 256,8K
          newblk    2  1.0M   76 256
        freefrag    0     0    1 128
        freeblks    1   256   57 256
        freefile    0     0   26 128
          diradd    1   128   44 128
           mkdir    0     0   12 128
          dirrem    1   128   34 128
       newdirblk    0     0    6 64
        freework    2   272   58 16,256
         jaddref    0     0   56 256
         jremref    0     0   46 256
         jnewblk    0     0   75 128
       jfreefrag    0     0    1 128
            jseg    1   128  105 128
         jsegdep    3   192  178 64
           sbdep    0     0   55 64
        savedino    0     0   23 256
         jblocks    2   384    2 128,256
         softdep    1  1.0K    1 1K
     ufs_dirhash   30  5.7K   30 16,32,64,128,512
       ufs_quota    1  512K    1
       ufs_mount    4   25K    5 32,512,8K,16K
       vm_pgdata    1   128    1 128
             UMA  142  2.3K  142 16,32
             rpc    4  8.1K    4 16,128,4K
        pci_link   16  1.5K   16 64,128
        atkbddev    2   128    2 64
          apmdev    1   128    1 128
          busdma 8.2k  512K 8.2k 64,256
          bounce 8.2k   32M 8.2k
            intr    4  472K    4 64K
             MCA    5   640    5 128
            cpus    2    32    2 16
        nexusdev    7   112    7 16
         memdesc    1  4.0K    1 4K
      madt_table    0     0    2 32,4K
         io_apic    1  2.0K    1 2K
      local_apic    1  4.0K    1 4K
             msi    4   512    4 128
    netgraph_msg    0     0   40 64,128,256,1K,32K
   netgraph_hook   10  1.3K   10 128
   netgraph_node    9  2.1K   19 128,256
    netgraph_hci    1   256    1 256
  netgraph_l2cap    1   128    1 128
netgraph_btsocks_hci_raw    1  8.0K   23 128,8K
netgraph_btsocks_l2cap_raw    1    32    1 32
netgraph_btsocks_l2cap    1    32    1 32
   netgraph_path    0     0   11 16
   netgraph_sock    0     0   18 128

and this vmstat -m 's outputs total memory usage calculation is:
Code:
The total memory usage calculated from the "Memory" column of the provided vmstat -m output is 59314.33 KB, which is equivalent to approximately 57.92 MB.
so where is the rest of the remaning of 120M wired memory's (62M) is coming from ? :-/
(since GENERIC and custom kernel's both wired memory is 120M, I have pasted the GENERIC kernel's vmstat -m 's data)


I found `kern_kldstat` function in /usr/src/sys/kern/kern_linker.c, where `linker_file` is obtained and `size` from it is used. However, I still can not find the place, where `size` itself is set. Well, I found kobj_create(9) in /usr/src/sys/kern/subr_kobj.c, but there size is initialized to 0.
i got this from google gemini, regarding why size is initialized to 0 and where `size` itself is set. (it sounds logical, might be helpful)

Code:
The size field of a linker_file structure is not set directly by kobj_create(). kobj_create() is part of the kernel object (kobj) system, which is used for creating polymorphic objects within the kernel, but it doesn't handle the core loading and sizing of kernel modules.

The size of a linker_file is set by the kernel linker when it loads the module from disk into memory.

The Kernel Linking Process

    kldload(8): When you run kldload mymodule.ko, the userland utility sends a request to the kernel to load a module.

    kld_load(): The kernel receives this request and calls the kld_load() function in /usr/src/sys/kern/kern_linker.c.

    File Reading and Mapping: kld_load() is responsible for opening the .ko file, reading its contents, and allocating memory for it. It's during this process that the size is determined. The linker reads the ELF header of the module file, which contains information about the size of the code, data, and symbol sections.

    linker_load_module(): The core work is done by linker_load_module(), which is called by kld_load(). This function parses the ELF file format, allocates the necessary memory, and then copies the sections (text, data, BSS) from the file into that memory. The total size of all these sections and the relocation information is calculated, and this final value is used to set the size field of the linker_file structure.

    Relocation and Initialization: After the module is loaded and its size is set, the linker performs relocations (fixing up addresses) and then calls the module's initialization function (MOD_LOAD event).

kobj_create()'s role is different. A kernel module might use kobj_create() to create objects for its internal use, but this happens after the module itself has been loaded and its overall size has been determined and recorded by the kernel linker. The size parameter in kobj_create() refers to the size of the specific object being created, not the size of the entire kernel module file.


kldstat > kobj_create : interesting all that syscalls from kldstat makes 2MB road



Like that, that's what I can give you.[/man][/man]
:beer::beer:
 
update:

freebsd-hackers maillist requested output of top command and fgrep memory output of dmesg.boot. (I sent an reply to maillist but to my luck, my webmail created a mess with encoding issues, so i pasted requested outputs to plain text to a pastebin website. ( https://pastebin.pl/view/f6932000 ) , in any case i also add the requested outputs to here.

Code:
top command output:
 
last pid:   803;  load averages:  0.11,  0.15,  0.07  up 0+00:05:01    00:01:12
35 processes:  2 running, 31 sleeping, 2 waiting
CPU:  0.0% user,  0.0% nice,  0.1% system,  0.0% interrupt, 99.9% idle
Mem: 9624K Active, 1388K Inact, 109M Wired, 15M Buf, 3824M Free
Swap: 3584M Total, 3584M Free
 
  PID USERNAME    THR PRI NICE   SIZE    RES STATE    C   TIME    WCPU COMMAND
   10 root          4 187 ki31     0B    64K RUN      0  19:58 400.00% idle
    4 root          3 -16    -     0B    48K -        1   0:00   0.00% cam
    2 root          4 -60    -     0B    64K WAIT     0   0:00   0.00% clock
   11 root         19 -60    -     0B   304K WAIT     0   0:00   0.00% intr
   14 root         20 -60    -     0B   320K -        3   0:00   0.00% usb
    6 root          1 -16    -     0B    16K -        1   0:00   0.00% rand_harvestq
  769 root          1  20    0    14M  3208K wait     1   0:00   0.00% sh
    7 root          3 -16    -     0B    48K psleep   3   0:00   0.00% pagedaemon
  757 root          1  23    0    14M  2988K wait     1   0:00   0.00% login
    9 root          4 -16    -     0B    64K psleep   0   0:00   0.00% bufdaemon
  765 moot          1  24    0    14M  3184K wait     2   0:00   0.00% sh
  768 moot          1  21    0    14M  2956K wait     3   0:00   0.00% su
  648 root          1  20    0    14M  2712K select   3   0:00   0.00% syslogd
   16 root          1  16    -     0B    16K syncer   1   0:00   0.00% syncer
    1 root          1  20    0    12M  1164K wait     2   0:00   0.00% init
    0 root         30 -16    -     0B   480K swapin   0   0:00   0.00% kernel
  458 root          1  20    0    15M  4008K select   0   0:00   0.00% devd
  730 root          1  20    0    14M  2604K nanslp   3   0:00   0.00% cron
  762 root          1  68    0    14M  2280K ttyin    0   0:00   0.00% getty
  760 root          1  68    0    14M  2276K ttyin    1   0:00   0.00% getty
  761 root          1  68    0    14M  2276K ttyin    0   0:00   0.00% getty
  759 root          1  68    0    14M  2280K ttyin    1   0:00   0.00% getty
   15 root          1 -16    -     0B    16K vlruwt   3   0:00   0.00% vnlru
  758 root          1  68    0    14M  2272K ttyin    2   0:00   0.00% getty
  763 root          1  68    0    14M  2272K ttyin    2   0:00   0.00% getty
  764 root          1  68    0    14M  2272K ttyin    3   0:00   0.00% getty
   12 root          3  -8    -     0B    48K -        2   0:00   0.00% geom
  394 root          1  68    0    14M  2572K select   3   0:00   0.00% dhclient
  397 root          1   4    0    14M  2696K select   3   0:00   0.00% dhclient
  803 root          1  20    0    15M  3112K CPU0     0   0:00   0.00% top
  457 _dhcp         1  68    0    14M  2760K select   3   0:00   0.00% dhclient
    8 root          1 -16    -     0B    16K psleep   0   0:00   0.00% vmdaemon
    3 root          5 -16    -     0B    80K crypto   3   0:00   0.00% crypto
   13 root          1 -16    -     0B    16K seqsta   3   0:00   0.00% sequencer 00
    5 root          1 -60    -     0B    16K -        3   0:00   0.00% busdma
 
 
 
fgrep memory output:
 
real memory  = 4294967296 (4096 MB)
avail memory = 4122767360 (3931 MB)
 
 
kldstat -h output:
Id Refs Address             Size Name
 1    1 0xffffffff80200000   15M kernel


Code:
command: "vmstat -z | sed 's/:/,/' | awk -F, '{printf "%10s %s\n", $2*$4/1024/1024, $1}' | sort -k1,1 -rn | head"

output:
23.2852 vm pgcache
18.9492 vm pgcache
9.91821e-05 fakepg
6.10352e-05 pcpu-16
3.05176e-05 udp_inpcb ports
2.20312 kstack_cache
1.98438 mbuf_cluster
1.82812 malloc-4096
1 mbuf_jumbo_page
0.907349 malloc-128
 
sorry for the delay of the update. here is the summary of the developments:

from the freebsd-hackers maillist :

regarding du(1), kldstat(8) question (size diffrence) :

du(1) is "the on-disk size" (the amount of physical storage space the
.ko file consumes on the disk) (compressed, unlinked ELF file), (a
storage container)

kldstat(8) is "the in-memory size" (the amount of virtual memory the
kernel module occupies after it has been loaded into the kernel's adress
space) (decompressed, linked, running code) , (a running program in
kernel space)

-.ko file that du(1) reports is compressed,
-kldstat(8) reports decompressed code (if it was compressed).
-kldstat(8) linker performs neccesary relocations (adjusting memory
addresses so the code runs correctly at its loaded location, allocates
memory for the module's code and data segments within the kernel's
memory space).
-in short kldstat(8) shows the size of the decompressed, relocated, and
loaded module in RAM. it reports the runtime memory footprint (in
short it is a process of kernel's packing (du(1)'s reporting) and
loading (kldstat(8)'s reporting) process )

and

Why should it report same size? Kernel file has its own storage format, just some source data
for kernel image in memory that has another format.

so the text i have copy/paste'd (from google gemini) at my previous post is also seems valid. :
The size field of a linker_file structure is not set directly by kobj_create(). kobj_create() is part of the kernel object (kobj) system, which is used for creating polymorphic objects within the kernel, but it doesn't handle the core loading and sizing of kernel modules.
The size of a linker_file is set by the kernel linker when it loads the module from disk into memory.
The Kernel Linking Process
kldload(8): When you run kldload mymodule.ko, the userland utility sends a request to the kernel to load a module.
kld_load(): The kernel receives this request and calls the kld_load() function in /usr/src/sys/kern/kern_linker.c.
File Reading and Mapping: kld_load() is responsible for opening the .ko file, reading its contents, and allocating memory for it. It's during this process that the size is determined. The linker reads the ELF header of the module file, which contains information about the size of the code, data, and symbol sections.
linker_load_module(): The core work is done by linker_load_module(), which is called by kld_load(). This function parses the ELF file format, allocates the necessary memory, and then copies the sections (text, data, BSS) from the file into that memory. The total size of all these sections and the relocation information is calculated, and this final value is used to set the size field of the linker_file structure.
Relocation and Initialization: After the module is loaded and its size is set, the linker performs relocations (fixing up addresses) and then calls the module's initialization function (MOD_LOAD event).
kobj_create()'s role is different. A kernel module might use kobj_create() to create objects for its internal use, but this happens after the module itself has been loaded and its overall size has been determined and recorded by the kernel linker. The size parameter in kobj_create() refers to the size of the specific object being created, not the size of the entire kernel module file.



regarding the issue of custom kernel's why wired memory is 120MB , same as GENERIC kernel's wired memory :

>> command: "vmstat -z | sed 's/:/,/' | awk -F, '{printf "%10s %s\n", $2*$4/1024/1024, $1}' | sort -k1,1 -rn | head"
>> output:
>> 23.2852 vm pgcache
>> 18.9492 vm pgcache
>> 9.91821e-05 fakepg
>> 6.10352e-05 pcpu-16
>> 3.05176e-05 udp_inpcb ports
>> 2.20312 kstack_cache
>> 1.98438 mbuf_cluster
>> 1.82812 malloc-4096
>> 1 mbuf_jumbo_page
>> 0.907349 malloc-128
>
> Well, it explains most part of wired memory usage, in megabytes.
> First two lines show 42.2MB of virtual memory page cache in total.
>
> kstack_cache + mbuf_cluster + malloc* + mbuf_jumbo_page
> sum to about 8MB extra wired memory to about 60MB including above 42.2MB.
>
> Add to this a number shown with "kldstat -h" multipled by two,
> that's amount of wired memory reserved at boot time for kernel code itself and its
> internal working set needed to start the rest of the system and thereafter.
>
> Some more kernel dynamic memory allocated using malloc(9) is shown with "vmstat -m"

in short it seems all that 120MB wired memory is , triangle of : virtual memory, buffer and cache ..
 
oo2025 Thank you so much for updates and posting answers from mailing list here as well. The information is extremely valuable and interesting!
 
oo2025 Thank you so much for updates and posting answers from mailing list here as well. The information is extremely valuable and interesting!
:beer::beer:

giphy.gif
 
Back
Top