public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* mm: dirty page problem
@ 2009-06-23  8:17 xue yong
  2009-06-23  9:02 ` xue yong
  0 siblings, 1 reply; 5+ messages in thread
From: xue yong @ 2009-06-23  8:17 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 734 bytes --]

I wrote a test program. It  mmap  a file and do some write, so some
pages become dirty.
and then I do "cat /proc/meminfo", so I get dirty pages that I have
written. this happened in my home
computer with debian, self compiled kernel 2.6.18-5 installed.


but in my company, on the servers (suse kernel 2.6.16.54), after the
test program have written the data, there was no change in
dirty pages column of "cat /proc/meminfo" 's output. after I killed
the test program, the dirty pages changed immediately.


I dont know why such different behavior, can you help me?


becauce we want a program mmap some files, and after the files'
contents were changed, the OS can write out these dirty
data back to disk periodly.




Best regards!

[-- Attachment #2: mmaptest.c --]
[-- Type: application/octet-stream, Size: 1480 bytes --]

#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <time.h>
#include <sys/stat.h>
#include <fcntl.h>
int main()
{
    int fd;
    char *pm;
    struct stat st;
    pid_t p;
//    p = fork();
    fd = open("/home/ice/mmap.dat", O_RDWR);
    if( fd < 0 ){
        perror("open mmap.dat error");
        exit(1);
    }
    if ( fstat(fd, &st) != 0 ){
        perror("stat error");
        exit(1);
    }
    pm = (char*) mmap( NULL, st.st_size, PROT_WRITE | PROT_READ , MAP_SHARED , fd, 0);
//    pm = (char*) mmap( NULL, st.st_size,  PROT_READ , MAP_SHARED , fd, 0);
    if ( pm < 0 || pm == MAP_FAILED ){
        perror("mmap failed");
        exit(1);
    }
    
    struct timeval tBegin, tEnd;
    bzero( &tBegin, sizeof(tBegin) );
    bzero( &tEnd, sizeof(tEnd) );

    gettimeofday( &tBegin, NULL);
    int i;
    char buffer[4096];
//    read( fd, buffer, 4096);
    while(1){
    for( i = 0; i < 1024*100; ++i )
    {
        memcpy( pm + 4096*i,buffer, 4096 );
//        pwrite( fd, buffer, 4096, i * 4096 );

    }
    sleep(300);
    }
//    mlockall(MCL_CURRENT);
//
    gettimeofday( &tEnd, NULL);
    int liTimeDiff = ((tEnd.tv_sec - tBegin.tv_sec) * 1000000 + tEnd.tv_usec - tBegin.tv_usec ) / 1000;
    printf("%d ms\n", liTimeDiff );
    printf("msync\n");
    msync( pm, st.st_size, MS_SYNC );
    munmap( pm, st.st_size );
//    sleep(600);
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-06-23 13:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-23  8:17 mm: dirty page problem xue yong
2009-06-23  9:02 ` xue yong
2009-06-23 10:33   ` Peter Zijlstra
     [not found]     ` <fc71709d0906230443pf8c4b34pcd4b7fa798fbf1ed@mail.gmail.com>
     [not found]       ` <1245757970.19816.1675.camel@twins>
2009-06-23 13:32         ` xue yong
2009-06-23 13:38           ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox