From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Subject: Re: New daily reports - debugging alloc.c et al
Date: Sat, 6 Aug 2011 16:34:33 +0200 [thread overview]
Message-ID: <20110806143433.GV29562@port70.net> (raw)
In-Reply-To: <20110806115014.GT29562@port70.net>
[-- Attachment #1: Type: text/plain, Size: 293 bytes --]
* Szabolcs Nagy <nsz@port70.net> [2011-08-06 13:50:15 +0200]:
> interestingly /proc/self/smaps does not seem to
> list all the successful mmaps.. i wonder why but
this is false, i failed to read smaps entirely
as discussed on irc here is a code that can
fill up the vm quickly and painlessly
[-- Attachment #2: vmfill.c --]
[-- Type: text/x-csrc, Size: 1453 bytes --]
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#ifndef PAGE_SIZE
#define PAGE_SIZE sysconf(_SC_PAGE_SIZE)
#endif
static void printvm() {
int fd = open("/proc/self/smaps", O_RDONLY);
char buf[4096];
int n;
printf("/proc/self/smaps:\n");
fflush(stdout);
while ((n = read(fd, buf, sizeof buf)) > 0)
write(1, buf, n);
close(fd);
}
static size_t mmapmax(int fd, void **p) {
size_t i,j,n=0;
for (i=j=SIZE_MAX/2; i>0; i/=2) {
if ((*p=mmap(NULL, j, PROT_NONE, MAP_PRIVATE, fd, 0)) == MAP_FAILED)
j -= i/2;
else {
n = j;
munmap(*p, n);
j += i/2;
}
}
if (n && (*p=mmap(NULL, n, PROT_NONE, MAP_PRIVATE, fd, 0)) == MAP_FAILED) {
fprintf(stderr, "failed to mmap the same amount again.\n");
exit(1);
}
return n;
}
int main(int argc, char *argv[]) {
const int fd = open("/dev/zero", O_RDWR);
void *p[100];
size_t n[100];
size_t sum = 0;
int i;
int vmmaps = 0;
if (argc == 2 && argv[1][0]=='-' && argv[1][1]=='v')
vmmaps = 1;
for (i=0; i<sizeof p/sizeof *p; i++) {
n[i] = mmapmax(fd, p+i);
if (!n[i])
break;
sum += n[i];
printf("%d %16zu B %012zx-%012zx\n", i, n[i], (size_t)p[i], (size_t)p[i]+n[i]);
}
printf("mmaped %zu B in %d blocks.\n", sum, i);
printf("try malloc:");
for(i=0; i < 1000 && malloc(PAGE_SIZE) != NULL; i++)
printf(".");
printf(" %zu B\n", i*(size_t)PAGE_SIZE);
if (vmmaps)
printvm();
return 0;
}
next prev parent reply other threads:[~2011-08-06 14:34 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-03 22:14 New daily reports Luka Marčetić
2011-08-03 22:46 ` Solar Designer
2011-08-04 10:51 ` Luka Marčetić
2011-08-04 11:54 ` Solar Designer
2011-08-04 12:01 ` Luka Marčetić
2011-08-04 12:12 ` Solar Designer
2011-08-05 0:02 ` New daily reports - started pthread_eintr.c Luka Marčetić
2011-08-05 0:10 ` Solar Designer
2011-08-06 4:40 ` New daily reports - debugging alloc.c et al Luka Marčetić
2011-08-06 11:15 ` Szabolcs Nagy
2011-08-06 11:50 ` Szabolcs Nagy
2011-08-06 14:34 ` Szabolcs Nagy [this message]
2011-08-06 15:38 ` Szabolcs Nagy
2011-08-07 2:41 ` New daily reports - debugging alloc.c still Luka Marčetić
2011-08-07 2:50 ` Solar Designer
2011-08-07 7:32 ` Rich Felker
2011-08-07 22:25 ` Luka Marčetić
2011-08-09 3:02 ` New daily reports - buf.c Luka Marčetić
2011-08-10 1:34 ` New daily reports - nothing Luka Marčetić
2011-08-10 1:38 ` Rich Felker
2011-08-10 11:47 ` Luka Marčetić
2011-08-10 2:02 ` Solar Designer
2011-08-10 11:23 ` Luka Marčetić
2011-08-10 11:56 ` Solar Designer
2011-08-10 12:13 ` Luka Marčetić
2011-08-10 2:07 ` Solar Designer
2011-08-10 2:12 ` Rich Felker
2011-08-10 4:59 ` Rich Felker
2011-08-10 12:09 ` Luka Marčetić
2011-08-10 12:44 ` Luka Marčetić
2011-08-10 14:25 ` Rich Felker
2011-08-10 17:21 ` Luka Marčetić
2011-08-10 17:33 ` Rich Felker
2011-08-10 18:23 ` Luka Marčetić
2011-08-10 18:21 ` Rich Felker
2011-08-10 18:34 ` Luka Marčetić
2011-08-10 18:33 ` Rich Felker
2011-08-14 20:00 ` Rich Felker
2011-08-15 14:14 ` Luka Marčetić
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110806143433.GV29562@port70.net \
--to=nsz@port70.net \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).