public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeff Epler <jepler@unpythonic.dhs.org>
To: Peter Zaitsev <pz@spylog.ru>
Cc: Andrew Morton <akpm@zip.com.au>, linux-kernel@vger.kernel.org
Subject: Re: MMAP issues
Date: Tue, 27 Nov 2001 16:36:51 -0600	[thread overview]
Message-ID: <20011127163650.B15307@unpythonic.dhs.org> (raw)
In-Reply-To: <183721898675.20011127194607@spylog.ru> <3C03D108.E3FADE95@zip.com.au> <149725995035.20011127205424@spylog.ru>
In-Reply-To: <149725995035.20011127205424@spylog.ru>

The difference in runtime between successive runs of your program
doesn't look terribly significant.

You open 'fd' each time, and never close it.  I die about 1000 mmap()s
into the process (-EMFILE returned by sys_open).  You may be testing
Linux' performance with huge fd sets in your test as well.

Moving the open() outside the loop, and running on a 512M, kernel 2.2
machine that's also running a full gnome desktop I get really intense
kernel CPU usage, and the following output:
 10000  Time: 12
 20000  Time: 45
 30000  Time: 79
 40000  Time: 113
[and I got too bored to watch it go on]

Unmapping the page after each map yields much better results:

 10000  Time: 4
 20000  Time: 4
 30000  Time: 4
 40000  Time: 5
 50000  Time: 4
 60000  Time: 4
 70000  Time: 5
 80000  Time: 5
 90000  Time: 5
 100000  Time: 4
[etc]

Interestingly, forcing the test to allocate at successively lower
addresses gives fast results until mmap fails (collided with a shared
library?):
 10000  Time: 4
 20000  Time: 4
 30000  Time: 4
 40000  Time: 4
 50000  Time: 4
 60000  Time: 4
Failed 0x60007000 12

So in kernel 2.2, it looks like some sort of linked list ordered by user
address is being traversed in order to complete the mmap() operation.
If so, then the O(N^2)-like behavior you saw in your original report is
explained as the expected performance of linux' mmap for a given # of
mappings.

Jeff

#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>

int main()
{
    int i = 0;
    void *p;
    int t;
    int fd;
    int addr = (void *) 0x70000000;

    fd = open("test.dat", O_RDWR);
    if (fd < 0) {
	puts("Unable to open file !");
	return;
    }
    t = time(NULL);
    while (1) {
	p = mmap(addr, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
	addr = addr - 4096;
	if ((int) p == -1) {
	    printf("Failed %p %d\n", addr, errno);
	    return;
	}
	i++;
	if (i % 10000 == 0) {
	    printf(" %d  Time: %d\n", i, time(NULL) - t);
	    t = time(NULL);
	}
    }
}

  reply	other threads:[~2001-11-27 22:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-27 16:46 MMAP issues Peter Zaitsev
     [not found] ` <3C03D108.E3FADE95@zip.com.au>
2001-11-27 17:54   ` Re[2]: " Peter Zaitsev
2001-11-27 22:36     ` Jeff Epler [this message]
2001-11-28  9:44       ` Peter Zaitsev
  -- strict thread matches above, loose matches on Subject: below --
2002-05-08 23:02 mmap issues David Stroupe

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=20011127163650.B15307@unpythonic.dhs.org \
    --to=jepler@unpythonic.dhs.org \
    --cc=akpm@zip.com.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pz@spylog.ru \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox