plenty of memory, but system us intensively swapping

Trond Endrestøl Trond.Endrestol at fagskolen.gjovik.no
Tue Nov 20 11:22:36 UTC 2018


On Tue, 20 Nov 2018 15:22+0500, Eugene M. Zheganin wrote:

> Hello,
> 
> On 20.11.2018 15:12, Trond Endrestøl wrote:
> > On freebsd-hackers the other day,
> > https://lists.freebsd.org/pipermail/freebsd-hackers/2018-November/053575.html,
> > it was suggested to set vm.pageout_update_period=0. This sysctl is at
> > 600 initially.
> > 
> > ZFS' ARC needs to be capped, otherwise it will eat most, if not all,
> > of your memory.
> Well, as you can see, ARC ate only half, and the other half is eaten by the
> kernel. So far I suppose that if I will cap the ARC, the kernel will simply
> eat the rest.

I know others have created a daemon that observe the ARC and the 
amount of wired and free memory, and when these values exceed some 
threshold, the daemon will allocate a number of gigabytes, writing 
zero to the first byte or word of every page, and then freeing the 
allocated memory before going back to sleep.

The ARC will release most of its allocations and the kernel will also 
release some but not all of its wired memory, and some user pages are 
likely to be thrown onto the swap device, turning the user experience 
to a mild nightmare while waiting for applications to be paged back 
into memory.

ZFS seems to be the common factor in most, if not all, of these cases.

I created my own and not so sophisticated C program that I run every 
now and then:

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

int main(int argc, char **argv)
{
  const size_t pagesize = (size_t)getpagesize();
  const size_t gigabyte = 1024ULL * 1024ULL * 1024ULL;

  size_t amount, n = 1ULL;
  char *p, *offset;

  if (argc > 1) {
    sscanf(argv[1], "%zu", &n);
  }

  amount = n * gigabyte;

  if (amount > 0ULL) {
    if ( (p = malloc(amount)) != NULL) {
      for (offset = p; offset < p + amount; offset += pagesize) {
        *offset = '\0';
      }

      free(p);
    }
    else {
      fprintf(stderr,
              "%s:%s:%d: unable to allocate %zu gigabyte%s\n",
              argv[0], __FILE__, __LINE__,
              n, (n == 1ULL) ? "" : "s");
      return 2;
    }
  }
  else {
    return 1;
  }

  return 0;
} // main()

// allocate_gigabytes.c

-- 
Trond.


More information about the freebsd-stable mailing list