Репозиторий Sisyphus
Последнее обновление: 1 октября 2023 | Пакетов: 18631 | Посещений: 37411982
en ru br
Репозитории ALT

Группа :: Система/Настройка/Прочее
Пакет: vzfree

 Главная   Изменения   Спек   Патчи   Исходники   Загрузить   Gear   Bugs and FR  Repocop 

vzfree-0.1/000075500000000000000000000000001155654627500126715ustar00rootroot00000000000000vzfree-0.1/Makefile000064400000000000000000000002371155654627500143330ustar00rootroot00000000000000CFLAGS=-O2 -s
PREFIX=/usr/local
TARGET=vzfree

all: ${TARGET}

clean:
rm -f ${TARGET}

vzfree: vzfree.c

install: vzfree
install -s ${TARGET} ${PREFIX}/bin/
vzfree-0.1/README000064400000000000000000000041701155654627500135530ustar00rootroot00000000000000Usage
I am running vzfree on my VPSLink VPS (256MB OpenVZ).

# vzfree
Total Used Free
Kernel: 49.83M 3.57M 46.26M
Allocate: 250.00M 103.91M 146.09M (256M Guaranteed)
Commit: 147.93M 53.07M 94.86M (47.6% of Allocated)
Swap: 0.03M (0.1% of Committed)
So how do they make sense?

Kernel is the Б─°unswappable memory allocated by the operating system
kernelБ─². Each process will continue a bit of kernel memory.

Allocate shows the maximum amount that your processes can allocate
(via malloc(3) calls, i.e. the burstable memory), and how much has
already been allocated. It also shows the guaranteed amount (i.e. the
guaranteed memory).

You can see that on VPSLink, the burstable amount is actually less than
the guaranteed amount and itБ─≥s a feature instead of a bug according
to them to prevent overselling.

Commit shows the actual memory pages that have been used. On Linux itБ─≥s
possible to over-commit your memory as what you have allocated might
not be the same as what you have used. I have discussed them here, and
the amount under Б─°UsedБ─² is the sum of physical pages + swapped pages.

The amount under Б─°TotalБ─² is actually the out-of-memory kill guarantee,
i.e. if the host node is running out of memory, processes in your VE might
be killed if Used > Total. In fact it is possible to commit more pages
than OOM kill guarantee (so Б─°FreeБ─² actually becomes negative). Watch
out for that if you are on a server thatБ─≥s massively oversold.

The last number also shows the ratio between Б─°allocatedБ─² and
Б─°committedБ─². YouБ─≥ll find this number very low if you are running
apps such as Java, MySQL, etc who allocate big chunks of memory but
donБ─≥t use all of them at once.

Swap is my guess on how many pages have been swapped on the physical
node. Bean counts tell you how many RAM pages are used so it should be
possible to work out the proximity of swap from other values. If the
percentage of committed memory have been swapped is high, then you know
your host is overselling.

Hopefully this little util is making more sense out of memory information
from the bean counters.
vzfree-0.1/vzfree.c000064400000000000000000000116101155654627500143350ustar00rootroot00000000000000#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct resource_t {
char name[32];
long long held;
long long maxheld;
long long barrier;
long long limit;
long long failcnt;
struct resource_t *next;
};


struct resource_t *
get_resource(char* buffer) {
struct resource_t *resource;
char *buffer2 = buffer;
char buffer3[80];
int state = 0;
int count = 0;

resource = malloc(sizeof(struct resource_t));
resource->next = NULL;

while (1) {
switch (state) {
case 0:
if (*buffer2 == ' ') {
strncpy(resource->name, buffer, (int) (buffer2 - buffer));
resource->name[(int) (buffer2 - buffer)] = '\0';
state = 1;
}
break;
case 1:
if (*buffer2 != ' ') {
buffer = buffer2;
state = 2;
}
break;
case 2:
if (*buffer2 == ' ' || !*buffer2) {
if (count < 5) {
sscanf(buffer, "%lld", (&(resource->held) + count));
count ++;
}
state = 1;
}
break;
}
if (!*buffer2) {
break;
}
buffer2 ++;
}

if (strcmp(resource->name, "dummy") == 0) {
free(resource);
return NULL;
} else if (count == 5) {
return resource;
} else {
free(resource);
return NULL;
}
}

struct resource_t*
find_resource(struct resource_t* resource, char* name) {
while (resource) {
if (strcmp(name, resource->name) == 0) {
return resource;
} else {
resource = resource->next;
}
}
return resource;
}

void
print_memory(struct resource_t *resource) {
struct resource_t *kmemsize, *privvmpages, *physpages,
*oomguarpages, *vmguarpages;

float committed_total;
float committed_used;

kmemsize = find_resource(resource, "kmemsize");
privvmpages = find_resource(resource, "privvmpages");
physpages = find_resource(resource, "physpages");
oomguarpages = find_resource(resource, "oomguarpages");
vmguarpages = find_resource(resource, "vmguarpages");

committed_total = oomguarpages->barrier / 256.0;
committed_used = (oomguarpages->held / 256.0) + (kmemsize->held / 1048576.0);

printf(" Total Used Free\n");
printf("Kernel: %7.2fM %7.2fM %7.2fM\n",
kmemsize->barrier / 1048576.0,
kmemsize->held / 1048576.0,
(kmemsize->barrier - kmemsize->held) / 1048576.0);
printf("Allocate: %7.2fM %7.2fM %7.2fM (%lldM Guaranteed)\n",
privvmpages->barrier / 256.0,
privvmpages->held / 256.0 ,
(privvmpages->barrier - privvmpages->held) / 256.0,
vmguarpages->barrier / 256);
printf("Commit: %7.2fM %7.2fM %7.2fM (%.1f%% of Allocated)\n",
committed_total,
committed_used,
committed_total - committed_used,
oomguarpages->held * 100.0 / privvmpages->held);
printf("Swap: %7.2fM (%.1f%% of Committed)\n",
(oomguarpages->held - physpages->held) / 256.0,
(oomguarpages->held - physpages->held) /
(float) (oomguarpages->held) * 100.0);
}

struct resource_t *
get_meminfo(char* beanfile) {
FILE *fp;
char buffer[256];
char* tmpchar;
int state = 0, offset = 0;
struct resource_t *resource = NULL, *resource2, *resource3;

if (!( fp = fopen(beanfile, "r"))) {
return 0;
}

while (fgets(buffer, 256, fp)) {
switch (state) {
case 0:
if (strncasecmp(buffer, "Version:", 8) == 0) {
state = 1;
}
break;
case 1:
tmpchar = strstr(buffer, "resource");
if (tmpchar) {
offset = (int) (tmpchar - buffer);
state = 2;
}
break;
case 2:
if (resource2 = get_resource((char*) (buffer + offset))) {
if (resource) {
resource3->next = resource2;
resource3 = resource2;
} else {
resource = resource3 = resource2;
}
}
break;
}
}

return resource;
}

int
main(int argc, char **argv) {
struct resource_t* resource;
char* beanfile;
if (argc > 1) {
beanfile = argv[1];
} else {
beanfile = "/proc/user_beancounters";
}
if (resource = get_meminfo(beanfile)) {
print_memory(resource);
return 0;
} else {
fprintf(stderr, "Unable to read %s\n", beanfile);
return -1;
}
}
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin