Re: Re: can enbd server run in kernel?

Ming Zhang <[email protected]>
Newsgroups gmane.linux.enbd.general
Message-ID <[email protected]>
i am afraid that my previous email with attachment is blocked, so resend again.

-------------------------------------------------------------------
i wrote a small code to test the mmap performance. and i get some
results different from you. i guess the kernel version may have impact
on it or because of some parameters.

what kernel i use, from a fedora core 2 box
[mingz@whoami mmap]$ uname -a
Linux whoami.localdomain 2.6.8-1.521 #1 Mon Aug 16 09:01:18 EDT 2004
i686 i686 i386 GNU/Linux

test c file attached. compile with 
gcc -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
test.c

change the len from 1024768 to 1024768*100 do two tests. dd a 600MB file
'test' as the data file.

1) with len = 1MB

[mingz@whoami mmap]$ strace -c ./a.out
execve("./a.out", ["./a.out"], [/* 35 vars */]) = 0
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 26.86    0.000047           9         5           old_mmap
 25.14    0.000044          11         4         1 open
  8.57    0.000015           8         2           mprotect
  8.57    0.000015          15         1           mmap2
  6.86    0.000012          12         1           munmap
  5.71    0.000010           5         2           fstat64
  5.14    0.000009           9         1           read
  4.57    0.000008           4         2           close
  3.43    0.000006           6         1           uname
  2.86    0.000005           5         1           set_thread_area
  2.29    0.000004           4         1           brk
------ ----------- ----------- --------- --------- ----------------
100.00    0.000175                    21         1 total

2) with len = 100MB

[mingz@whoami mmap]$ strace -c ./a.out
execve("./a.out", ["./a.out"], [/* 35 vars */]) = 0
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 26.63    0.000049          12         4         1 open
 26.63    0.000049          10         5           old_mmap
  9.24    0.000017          17         1           mmap2
  8.15    0.000015           8         2           mprotect
  6.52    0.000012          12         1           munmap
  5.43    0.000010           5         2           fstat64
  4.89    0.000009           9         1           read
  4.35    0.000008           4         2           close
  3.26    0.000006           6         1           uname
  2.72    0.000005           5         1           set_thread_area
  2.17    0.000004           4         1           brk
------ ----------- ----------- --------- --------- ----------------
100.00    0.000184                    21         1 total

so there is no big difference on total time.

[mingz@whoami mmap]$ strace ./a.out
execve("./a.out", ["./a.out"], [/* 35 vars */]) = 0
uname({sys="Linux", node="whoami.localdomain", ...}) = 0
brk(0)                                  = 0x8a9d000
open("/etc/ld.so.preload", O_RDONLY)    = -1 ENOENT (No such file or
directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=58108, ...}) = 0
old_mmap(NULL, 58108, PROT_READ, MAP_PRIVATE, 3, 0) = 0xf6ff1000
close(3)                                = 0
open("/lib/tls/libc.so.6", O_RDONLY)    = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\300+\300"...,
512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=1459344, ...}) = 0
old_mmap(0xbee000, 1162188, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) =
0xbee000
old_mmap(0xd04000, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED,
3, 0x116000) = 0xd04000
old_mmap(0xd08000, 7116, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xd08000
close(3)                                = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0xf6ff0000
mprotect(0xd04000, 4096, PROT_READ)     = 0
mprotect(0xbea000, 4096, PROT_READ)     = 0
set_thread_area({entry_number:-1 -> 6, base_addr:0xf6ff0300,
limit:1048575, seg_32bit:1, contents:0, read_exec_only:0,
limit_in_pages:1, seg_not_present:0, useable:1}) = 0
munmap(0xf6ff1000, 58108)               = 0
open("test", O_RDWR|O_LARGEFILE)        = 3
mmap2(NULL, 102476800, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0) =
0xf0e35000
exit_group(-253538304)                  = ?

see this mmap2 usage.

not sure if these will change when multiple processes open it.

ming

---------test.c-----------------
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
 
int main(int argc, char **argv)
{
        int fd;
        char *t;
        int len = 1024768 * 100;
        char *path = "test";
 
        fd = open(path, O_RDWR|O_LARGEFILE);
        if (fd < 0)
                printf("fail to open file\n");
        t = mmap(0, len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
        if ((long)t == -1)
                printf("fail to mmap");
 
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.