swap - memory

I vote for this thread, too.

Iirc marino wrote there is a rule of thumb of about 8GB memory usage per Synth parallel build.
What @legrand wrote seems about the same size (8GB plus minus a few GB) when running poudriere building.
Is it then safe to assume that, with a machine with, say, 16GB free RAM one can do builds without having to expect memory going critically low?
 
Great achix !

I am convinced you right person to take the decision because you opend the thread.

So, I think you could write a final post into "Gereat UI/X preformance gains by turning off sapw"
and say something like:
----
This discussion has moved to thread "swap - memory" by fernandel,
we are discussiong there the same things. Please write there further
considerations, experiences and ideas.
-----
 
Report of experiment: n#1

This post refers to a previous question I wrote as message #17 into thread "Gereat UI/X preformance gains by turning off swap" by achix. There is described my machine hardware.

Problem: My machine is small, runs FreeBSD-11.1. Removing swap it became damnt faster, i would like to keep swap-off but I am scared on consequences (mainly on the disk).

Proposed Sulution: Limit the main user "foo" moemory usage in such a way that system can not go out of memory.

Actions Taken:
Code:
-] Enable resource control writing in /boot/loader.conf
kern.racct.enable=1

-] Reboot

-] login as user "foo", start X, Firefox, Emacs, 2-3 terminals

-] Remove swap
#> swapoff -a

-] Limit user "foo" maxiumu memory use
#> rctl -a user:foo:memoryuse:deny=2g

-] turn on "top" and see what happens
#> top

-]  Run a script as user "foo" that eats memory ad see what happens
---- Ruby code, run from Emacs + Inf-ruby ----
[NOPARSE]
counter = 0
longString = ""
(1..20).each do |i|
  longString = longString + ("x" * 100_000_000)
  counter += 1
  puts "#{i} -- longString takes now ~ #{counter * 100} MBytes"
  sleep 2
end
[/NOPARSE]
-------------------------------------------------------------------

Results:
-] Looking at "top" I saw that memory resctions on user "foo" was not honoured.
The script in Ruby ate more than 2GB.
-] At some point the script ate too much memory and what happend surprised me a lot
--] The script did not stop and in order:
----] I lost control of Emacs
----] Some Firefow windows died
----] I lost control of the system
----] I had to power off
----] On reboot there was some complains about disk status, but I could complete the, luckily.

-] What suprises me most is that I expected the Ruby script should have been
killed by the system, with an error message like "Out of core memory".
Instead the whole system started to do unexpected stuff and eventually froze.
 
Wouldn't the same have happened after filling up the swap?
When the system is thrashing onto the swap and barely (if at all) responds to input, can one stop it safely?

As I understand (and you probably too) the rctl() man page, wouldn one expect to just not be allowed more than 2gigs... so what is wrong?
 
Exactly Snurg,
-] It crashes almost in the same way when i fill up the swap
-] I don't know why the "2gigs" limit is not honoured

... further experiments are needed, but each time i risk to trash the machine ;P
I am writing the "memEater" in C now, I want to run it out of Emacs and Ruby GC control.
 
Maybe you can clone the VM you are using?
When the clone gets fscked up, it won't matter much I guess.
I will verify these experiments on a dedicated PC with ZFS. If the filesystem gets shot, no problem, just reinstall :)
 
Yes, I could do another little vm which would be expendable, i will try leter in afternoon;)

Now i must leave the office, if you want to do some experiments here is the code in C for "memEater" .

Code:
[NOPARSE]
// WHAT:
// -] eats 100 Megybtes each second (or two, three) for "n" times
// -] "n" must me contained in ARGV[1]
//
// Compile
// $> cc -o memEater memEater.c
//
// Example, eats 1 GB in mem
// $> memEater 10
//
// Check
// $> top -w -o size

#include<stdlib.h>
#include<stdio.h>
#include<unistd.h>
#include<locale.h>

int main(int argc, char **argv) {
  void *ptr = NULL;
  int step = 100E6;
  int count = 0;
  int nstep = 0;
  // check there is one necessary argument
  if (argc != 2) { printf("Error, read code \n"); exit(2); }
  // no checks ! write a number in ARGV[1] !
  nstep = (int)strtol(argv[1], NULL, 10);
  // for comma seprated long integer
  setlocale(LC_NUMERIC, "en_US.UTF-8");
  for(int i = 0; i < nstep; i++) {
    ptr = malloc(step);
    if (ptr == NULL) {
      printf("Error, in allocating memory\n");
      exit(1);
    } else {
      count += step;
      printf("Allocated space : %'d MBytes \n", (int)(((float)count)/1E6));
    }
    sleep(3);
  }
  exit(0);
}

[/NOPARSE]
 
My FreeBSD 11.1-RELEASE-p4 Thinkpad X61 .mp3 player with 4GB RAM is currently at 62.5 days uptime and showing 3979Mb of swap with 3943Mb free. I don't use any sysctl settings.

I listen to it every day for hours, never close multimedia/xmms, use graphics/gimp to manipulate images, etc. and never have a problem with it.
 
Trihexagonal , if you don't push it to the limit of eating all memory you will not have troubles. When it reaches that limit it behaves in an unexpected way. (I still did not understand well, i need more tests)

If you feel like experinmenting try this:
-] Disable the swap and you will see, X stuff becomes much faster.
-] [extra, but related] Firefox has an ugly way to manage memory (IMHO), keep open "top -w" then open 4-5 Firefox windows and many tabs in them. Browse around, let Firefox eat a lot of memory. Then, now, start to kill tabs one by one and keep an eye on "top". What happens in my system is that Firefox frees memory only when i close ALL its windows.
 
Trihexagonal , if you don't push it to the limit of eating all memory you will not have troubles. When it reaches that limit it behaves in an unexpected way. (I still did not understand well, i need more tests)

If you feel like experinmenting try this:...

As a general rule, if it's not broke I don't fix it. :)

I did think it looked like it was starting to use swap a few days ago (I can monitor it through sysutils/gkrellm2), and worried I might have to reboot and lose my uptime, but it seems to have released it and is purring along nicely.

I keep a terminal open running top most of the time on my other machines.
 
What do you mean by much faster ? All my X stuff are already fast.

If you have every tried changing your disk from ordinary mechianical dish to a solid state and remembre the "WOW, now it s really faster". Ok, that is the feeling when i changed to "swap-off" ! [ Maybe 70% of the disk change offect ]

I can see the difference expecially in opening mails in Thunderbird, and read one of the many GoogleDocuments I need to keep open all the time in Firefox.

I could make a video with my phone if you are really curious and you don't want to test;)
 
As a general rule, if it's not broke I don't fix it. :)

I did think it looked like it was starting to use swap a few days ago (I can monitor it through sysutils/gkrellm2), and worried I might have to reboot and lose my uptime, but it seems to have released it and is purring along nicely.

I keep a terminal open running top most of the time on my other machines.

Ohhh, the "uptime", in a period of time i remember i was also very proud of my uptimes;)

I will try gkrellm2 ASAP.

it is true, I also belive in rule "not broken => don't change it !".
But, if it can be faster, why not ? ;)
 
Report of experiment: n#2

ok, guys I made more tests, I create a toy vm and boldly went where many probably have been before;)

Objective: discover how to limit user "foo" to eat to much memory and avoid system crash when in "swap-off".

What I discovered is :
-] Restricting "memoryuse" with rctl is not enough
-] To see what resources must be limited I used this command:
#> rctl -hu user:foo
-] There I saw, that to stop "memEater" bofore it eats all i must restrict
"swapuse" and/or "vmemoryuse". If I do that "memEater" gets killed properly
and I receive a message in console. Don't be fooled by the name "swapuse", that is positive
in "rctl" output even if you are into "swap-off" !

My conclusion is, to be able to use the system safely with swap-off
I would need a restrction on "swapuser + memoryuse < 3500M" for user "foo".
But, reading the "man rctl" I don't think that is possible.

To understand more I think I would need to read a few chapters of "The design and implementation of the FreeBSD Operating System". But now I'm deep into a web project, I can't do that. So, someone else more experienced must push the cow forward;)
 
If you have every tried changing your disk from ordinary mechianical dish to a solid state and remembre the "WOW, now it s really faster". Ok, that is the feeling when i changed to "swap-off" ! [ Maybe 70% of the disk change offect ]

I can see the difference expecially in opening mails in Thunderbird, and read one of the many GoogleDocuments I need to keep open all the time in Firefox.

I could make a video with my phone if you are really curious and you don't want to test;)
FreeBSD Host AMD64 ZFS 8Gb RAM + FreeBSD AMD64 UFS Guest in Virtualbox. I tried with and without swap space in guest and didn't notice any meaningful difference, sorry.
 
Just got up and about going shopping, then looking into that more while breakfast.

Imho this is a more-than-critical security and stability issue.
It can break every machine running FreeBSD if some attacker runs an user level process that gobbles up memory.
So this would be an ultra-easy DOS attack vector.
 
To understand more I think I would need to read a few chapters of "The design and implementation of the FreeBSD Operating System". But now I'm deep into a web project, I can't do that. So, someone else more experienced must push the cow forward;)

That's the problem. No one has time to do dedicated testing. Having about 10 projects to run at the same time, I don't feel I can help much here.
Anyways, this morning swap usage was again back to almost 3GB. I *thought* the system was slow, so disabled it, and then decided to actually measure something e.g. web page loading, and so I enabled it again.
 
That's the problem. No one has time to do dedicated testing. Having about 10 projects to run at the same time,
I feel like you. But this issue is critical to me. I have no other OSes as back-up I could use if my FreeBSD installations break due to some stupid program eating up memory and fscking up the filesystem. Must get these rctl things work and verify them.
I have written a small malloc based memory stresser now, going to test that on a dedicated test PC after a naplet.
Will have to add SysV SHM then and do some more tests.
 
Is there a way to tell FreeBSD OS to not swap any X based processes (thus all that stays in memory and X stays snappy fast) yet OS can swap remainder of processes? And if you think a program is using way too much memory then document and submit a bug report I say.
 
Is there a way to tell FreeBSD OS to not swap any X based processes (thus all that stays in memory and X stays snappy fast) yet OS can swap remainder of processes? And if you think a program is using way too much memory then document and submit a bug report I say.

1] If you read "man rctl", and then do some experiments, you will see it is not self evident how to reach this : "not swap any X based processes". BTW, IMHO, the easiest way is to limit a specific user.
Untill now I have not found a way.

2] Yes, in my opinion Firefox memory management is inapproriate, how do I fill "bug?" report to the person who manages the FreeBSD port ? (sorry i'm new)
 
IMO FreeBSD could use a real swappiness setting like Linux has. But, in some ways I see why it doesn't. For the same reason that FreeBSD doesn't come with a GUI, it doesn't have "swappiness". Actually, it has swappiness in the form of many sysctl values that one changes at one's own peril, if one is not a FreeBSD VM expert.

FreeBSD has been optimized as a server system. So, that's where the swappiness is set, via myriad sysctl values. Do a sysctl -a | grep ^vm and see how many there are. They are mostly undocumented, because they're dangerous to set. You easily end up with an unstable system when you play, so play on an unimportant system. Linux's swappiness goes from 0-100, with 100 favoring servers, and 0 favoring desktops. The default favors servers because it's set to 60 (barely favors). FreeBSD can be altered to some extent, in the same way, but only by being a VM expert or by taking chances. As with the GUI, FreeBSD will let you on your own in this area, as it's already set up for servers, and they're happy with that.

I reread some of the Design and Implementation over the weekend. It doesn't explicitly correlate sysctl values to how the VM system actually works, so that has to be inferred by understanding the terms and descriptions. Do we all want to have that level of knowledge about BSD internals? Even tho that'd be great, it seems we could use a 0-100 thrust control and a couple of idiot lights, for those of us who run GUIs and fluff like that :)
 
Umm, I think this thing of "swappiness" could be useful. Or also a documented roadmap to reduce swapping.

This is my rationale.
-] FreeBSD is server oriented, no problem, I like it like that by default.
-] IMO, to know well the system you must live with it, so, use it for servers and personal desktop as well. Each day of use on the desktop i discover something that i can re-use on the
servers.
-] => There should be a documented path to make it more "desktop friendly", we
can write this document all together if we discover how to.

For the moment I'm trying to limit a user *total* memory use. In such a way that, even if i would set "swap off", a general user "foo" could not put the system out of memory and crash all.
 
Back
Top