# Freebsd and RAM



## polv (Mar 23, 2021)

Freebsd 12.2 64G ram

He noticed that when he reached about 30 gig, he began to swap. He tried to complete the memory, created a memory disk and copied the file there 10G. the system hung.

Freed the server and has already created a memory disk in ram 50 gig.

Mem: 26M Active, 35M Inact, 1051M Wired, 40K Buf, 61G Free

write file 10G  
see in the top 

Mem: 10G Active, 9821M Inact, 1342M Wired, 227M Buf, 42G Free

write second file 10G and look in the top, 

Mem: 20G Active, 19G Inact, 1620M Wired, 455M Buf, 22G Free

Add file 3 in 10G? look the top

Mem: 29G Active, 28G Inact, 4476K Laundry, 1846M Wired, 677M Buf, 2989M Free



Where does memory go, maybe who can tell and how to cure it?


----------



## polv (Mar 23, 2021)

Work systems htop

1  [||                                4.1%]    7  [|||||||||||                      26.4%]   13 [|||||||                          17.6%]    19 [|||||                            11.4%]
  2  [||||                              8.8%]    8  [|||||                            12.2%]   14 [|||||||||||                      26.9%]    20 [||||||||                         19.2%]
  3  [||||                              6.2%]    9  [||||||                           13.5%]   15 [||||||                           13.0%]    21 [|||||                            10.7%]
  4  [||||||||||                       25.9%]    10 [|||||||||||||                    33.5%]   16 [|||                               6.5%]    22 [||||                              7.7%]
  5  [|||||                            11.9%]    11 [|||||||||||||||                  37.1%]   17 [|||||                            10.9%]    23 [||||                              8.5%]
  6  [|||||||                          15.9%]    12 [|||||||                          17.2%]   18 [||||                              9.7%]    24 [|||||||||||||                    32.1%]
  Mem[||||||||||||||||||||||||||||||||||||||||||                                22.9G/64.0G]   Tasks: 61, 0 thr; 2 running
  Swp[||||||||||||||||||||||||||||||                                            10.4G/30.0G]   Load average: 2.24 2.49 2.65 
                                                                                               Uptime: 6 days, 01:14:31


----------



## SirDice (Mar 23, 2021)

I can't make any sense of this. What exactly are you doing and what is running on that system?


----------



## polv (Mar 23, 2021)

server used for bhyve
I was doing a test of why memory is not used all
and found out that when using 10Gig memory, free to become less by 10 Gig. Why I can't understand that.


----------



## SirDice (Mar 23, 2021)

polv said:


> and found out that when using 10Gig memory, free to become less by 10 Gig. Why I can't understand that.


You've created a RAM disk, copied 10G to it and are now wondering why there's 10G less free memory? Where did you expect that RAM disk to store its data?


----------



## polv (Mar 23, 2021)

I get -20 gigabytes of free memory
and if I copy 20 I get -40 gigabytes of free memory

i write 10G free 40G
write 20G Free 20G
write 30G free 3G


----------



## SirDice (Mar 23, 2021)

Inactive Memory vs. Free Memory
					

We have a couple of boxes running; top perpetually looks like this:  last pid: 66910;  load averages:  0.02,  0.11,  0.07   up 17+13:35:30  10:21:28 80 processes:  2 running, 78 sleeping CPU:  1.6% user,  0.0% nice,  3.1% system,  3.5% interrupt, 91.8% idle Mem: 62M Active, 2813M Inact, 223M...




					forums.freebsd.org


----------



## zirias@ (Mar 23, 2021)

Most plausible answer: It's written on your RAM disk _and_ in a cache. Caches will make room as soon as the RAM is needed for something else.

So, what problem are you trying to solve?


----------



## polv (Mar 23, 2021)

Zirias said:


> Most plausible answer: It's written on your RAM disk _and_ in a cache. Caches will make room as soon as the RAM is needed for something else.
> 
> So, what problem are you trying to solve?


My FreeBSD doesn't use more than 30 gig of memory, about 30gig starts using swap. When trying to clear swapof -a writes that there is no free memory.


----------



## zirias@ (Mar 23, 2021)

Having 30G of swap seems excessive to me, I'd suggest to reduce it (maybe around 8G). But then, do you observe any _problem_ in situations with a lot of swap usage? Any performance degradation? Because, if not, just leave it. Leaving things in swap that just aren't needed at the moment and instead using the RAM for caches speeding up I/O is generally a good strategy.


----------



## SirDice (Mar 23, 2021)

You haven't given us a lot of information.  For comparison here is my bhyve host, it's currently running 13-STABLE but it was 12-STABLE before, with the same settings:

```
root@hosaka:~ # vm list
NAME            DATASTORE  LOADER     CPU  MEMORY  VNC           AUTOSTART  STATE
case            default    bhyveload  4    4096M   -             Yes [4]    Running (2748)
jenkins         default    bhyveload  4    4096M   -             Yes [6]    Running (3269)
kdc             default    none       2    2048M   0.0.0.0:5901  Yes [2]    Running (2178)
lady3jane       default    bhyveload  4    8192M   -             Yes [3]    Running (2488)
debian          stor10k    uefi       2    4096M   -             No         Stopped
fbsd-test       stor10k    bhyveload  2    4096M   -             Yes [13]   Running (5133)
gitlab          stor10k    bhyveload  4    6144M   -             Yes [11]   Running (5081)
gitlab-runner   stor10k    bhyveload  4    4096M   -             Yes [12]   Running (5110)
kibana          stor10k    bhyveload  4    6144M   -             Yes [1]    Running (1975)
plex            stor10k    bhyveload  4    4096M   -             Yes [7]    Running (3779)
riviera         stor10k    bhyveload  2    4096M   -             Yes [10]   Running (4566)
sdgame01        stor10k    bhyveload  4    4096M   -             No         Stopped
tessierashpool  stor10k    bhyveload  2    4096M   -             Yes [5]    Running (3247)
wintermute      stor10k    bhyveload  4    4096M   -             Yes [9]    Running (4303)
```


```
last pid: 24032;  load averages:  3.02,  2.66,  1.96                                                        up 2+13:36:30  12:38:17
59 processes:  1 running, 58 sleeping
CPU:  0.2% user,  0.0% nice, 14.4% system,  0.1% interrupt, 85.3% idle
Mem: 12G Active, 19G Inact, 6452M Laundry, 50G Wired, 5476M Free
ARC: 39G Total, 5812M MFU, 30G MRU, 1056K Anon, 1924M Header, 717M Other
     34G Compressed, 42G Uncompressed, 1.23:1 Ratio
Swap: 16G Total, 72M Used, 16G Free
```

Are you using ZFS? Then you're going to need to limit `vfs.zfs.arc_max`:

```
root@hosaka:~ # sysctl vfs.zfs.arc_max
vfs.zfs.arc_max: 42949672960
```


----------

