Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Continuously increasing memory usage since the update to 2.6

    Scheduled Pinned Locked Moved General pfSense Questions
    42 Posts 9 Posters 11.8k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      kprovost @Techniker_ctr
      last edited by

      @techniker_ctr said in Continuously increasing memory usage since the update to 2.6:

      128: 128, 0, 1962118, 182,96462269, 0, 0

      It looks like the '128' zone is the most likely culprit. Rather unhelpfully that's a generic zone used by the in-kernel 'malloc()' call.

      Let's confirm that that's the problem first. Can you keep an eye on the vmstat output for a few hours to see if the used number (currently at 1962118) increases roughly in line with the growing memory use you see?

      (Napkin math: we've got 1962118 allocations of 128 bytes, so about 240 MB. That seems to be about right for what we're looking for.)

      Once that's confirmed the following running Dtrace script on the router may provide clues:

      #!/usr/bin/env -S /usr/sbin/dtrace -x nolibs -s
      
      struct uma_zone {
              uint32_t *mtx;
              char *uz_name;
      };
      
      fbt:kernel:uma_zalloc_arg:entry
      / ((struct uma_zone *)arg0)->uz_name == "128" /
      {
              @num[stack()] = count();
      }
      

      Let that run for a few minutes and then terminate it with Ctrl+C. It'll likely produce a large amount of output, but with any luck the top user will give us a clue as to where that memory is going.

      T 1 Reply Last reply Reply Quote 1
      • T
        Techniker_ctr @kprovost
        last edited by

        @kprovost I wasn't able to run the script for minutes, it crashed after ~20 sec with message "Killed". So attached the output for about 15 seconds: output.txt

        The 128 zone increase during one day:

        2022-05-22 08:48 :

        128:                    128,      0,   14566,     221,  812169,   0,   0
        

        2022-05-22 17:19 :

        128:                    128,      0,   29424,     119, 1566853,   0,   0
        
        K 1 Reply Last reply Reply Quote 0
        • K
          kprovost @Techniker_ctr
          last edited by kprovost

          @techniker_ctr
          Okay, it's pretty safe to conclude we're indeed leaking from the 128 zone.

          The dtrace output doesn't immediately point to an obvious suspect, but having looked through it I think this is where the problem is:

                    kernel`malloc+0x72
                    kernel`nvpair_create_number+0x3f
                    kernel`nvlist_add_number+0x26
                    kernel`pf_get_syncookies+0xa2
                    kernel`pfioctl+0x2bd6
                    kernel`devfs_ioctl+0xb0
                    kernel`VOP_IOCTL_APV+0x7b
                    kernel`vn_ioctl+0x16c
                    kernel`devfs_ioctl_f+0x1e
                    kernel`kern_ioctl+0x2b7
                    kernel`sys_ioctl+0x101
                    kernel`amd64_syscall+0x387
                    kernel`0xffffffff8135af6e
                      4
          

          There's nothing there to distinguish it from some of the other calls, but 2.6 does not have this commit: https://github.com/pfsense/FreeBSD-src/commit/410b11b25bdf39be3a73003ae5e5fadd9e3497fd
          That fixes a memory leak in that code path, and pfsense ends up calling that regularly to obtain unrelated counters.

          I expect you to be able to confirm this by running pfctl -si -v in a loop. That should leak memory quickly.

          The good news is that the fix is already included in the upcoming 22.05 (plus) release and will also be in future CE releases.

          fireodoF 1 Reply Last reply Reply Quote 5
          • stephenw10S
            stephenw10 Netgate Administrator
            last edited by

            Looks like it's already in 2.7 snapshots too if you're able to test one.

            1 Reply Last reply Reply Quote 1
            • fireodoF
              fireodo @kprovost
              last edited by

              @kprovost said in Continuously increasing memory usage since the update to 2.6:

              The good news is that the fix is already included in the upcoming 22.05 (plus) release and will also be in future CE releases.

              Dumb Question: is there a command to release that memory on a running system? (I think no)

              Kettop Mi4300YL CPU: i5-4300Y @ 1.60GHz RAM: 8GB Ethernet Ports: 4
              SSD: SanDisk pSSD-S2 16GB (ZFS) WiFi: WLE200NX
              pfsense 2.8.0 CE
              Packages: Apcupsd, Cron, Iftop, Iperf, LCDproc, Nmap, pfBlockerNG, RRD_Summary, Shellcmd, Snort, Speedtest, System_Patches.

              K 1 Reply Last reply Reply Quote 0
              • K
                kprovost @fireodo
                last edited by

                @fireodo There is not, no.

                That's sort of why we call it 'leaked' memory. It's gone (at least until the system is rebooted). If this were a user space leak you could restart the application to reclaim the memory, but as it's leaking from the kernel you have to restart the kernel (i.e. reboot).

                fireodoF 1 Reply Last reply Reply Quote 2
                • fireodoF
                  fireodo @kprovost
                  last edited by fireodo

                  @kprovost said in Continuously increasing memory usage since the update to 2.6:

                  It's gone (at least until the system is rebooted).

                  Understood. Thank you!
                  BTW: I can also confirm this as I made myself researches in this matter on my Lab machine. (Following the instructions in this thread)

                  Best regards,
                  fireodo

                  Kettop Mi4300YL CPU: i5-4300Y @ 1.60GHz RAM: 8GB Ethernet Ports: 4
                  SSD: SanDisk pSSD-S2 16GB (ZFS) WiFi: WLE200NX
                  pfsense 2.8.0 CE
                  Packages: Apcupsd, Cron, Iftop, Iperf, LCDproc, Nmap, pfBlockerNG, RRD_Summary, Shellcmd, Snort, Speedtest, System_Patches.

                  M 1 Reply Last reply Reply Quote 0
                  • fireodoF fireodo referenced this topic on
                  • fireodoF fireodo referenced this topic on
                  • M
                    manueljv2 @fireodo
                    last edited by

                    @fireodo Good day, this problem was solved? I have the same problem and I have not managed to solve it. can help me please

                    572d8cd8-0951-4114-af7c-8b8c288791fe-image.png

                    7ae76760-0a5b-4f6a-827f-4adb435be4d1-image.png

                    a8a5df67-fbbe-48a3-a47b-a371ffb17e87-image.png

                    7e130ad5-90d9-4ed7-b16d-bb111eacbd33-image.png

                    d467f455-f82c-478b-8046-3f3432d6e640-image.png

                    K 1 Reply Last reply Reply Quote 0
                    • K
                      kprovost @manueljv2
                      last edited by

                      @manueljv2 Yes, the fix is in both the current 2.7 snapshots and the upcoming 23.01 plus release.

                      D 1 Reply Last reply Reply Quote 0
                      • D
                        dschmitz @kprovost
                        last edited by

                        @kprovost Has this issue been fixed? I am having the same issues and I am on 23.01.
                        Any ideas?
                        059e4b6b-d8fc-49e6-a5f0-e5d4b0f47e8e-image.png
                        5e93c5de-9a5e-445d-95e5-6e5abaa89b5c-image.png
                        43f73b94-7d1a-4005-90fe-797306fb6f56-image.png

                        S 1 Reply Last reply Reply Quote 0
                        • S
                          SteveITS Galactic Empire @dschmitz
                          last edited by

                          @dschmitz said in Continuously increasing memory usage since the update to 2.6:

                          @kprovost Has this issue been fixed? I am having the same issues and I am on 23.01.

                          See
                          https://forum.netgate.com/topic/178568/netgate-1100-high-memory-consumption/4

                          Pre-2.7.2/23.09: Only install packages for your version, or risk breaking it. Select your branch in System/Update/Update Settings.
                          When upgrading, allow 10-15 minutes to restart, or more depending on packages and device speed.
                          Upvote 👍 helpful posts!

                          D 1 Reply Last reply Reply Quote 0
                          • D
                            dschmitz @SteveITS
                            last edited by

                            @steveits Thank you! Have installed the patch and configured the system tunable. Will post back if continue to have issues.

                            K 1 Reply Last reply Reply Quote 0
                            • K
                              kprovost @dschmitz
                              last edited by

                              @dschmitz Steve's already pointed you at a way to have the UI show lower memory use, but I wanted to reinforce the point that what your 'top' screenshot shows is not a problem.

                              It does show that the majority of RAM is in use, but if you look one line lower you can see that 13 out of the 14 GB of wired memory is used by the ARC (ZFS's buffer cache).
                              That's a good thing. It means that the memory you paid for is doing stuff, rather than sitting around burning electrons for nothing. Once memory is needed for other things (such as pf states, or installing packages or any of the thousands of other things the system does) the ARC will release that memory.

                              As a general rule, memory usage on modern operating systems is much more complicated than you think it is, even if you take this rule into account.

                              1 Reply Last reply Reply Quote 2
                              • fireodoF fireodo referenced this topic on
                              • First post
                                Last post
                              Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.