Linux-kernel mailing list archive 1999-34,: ISSUE: Writing to mmap creates duplicate pages in 2.2.5 and 2.2.11 kernels

# ISSUE: Writing to mmap creates duplicate pages in 2.2.5 and 2.2.11 kernels

Kevin Kunzelman (kkunzelm@yahoo.com)
Sun, 22 Aug 1999 21:47:23 -0700 (PDT)

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: Matthew Wilcox: "Re: 2.2.11 unstable"
- Previous message: Zach Brown: "OSS maestro driver alpha"
- Next in thread: Kevin Kunzelman: "Re: ISSUE: Writing to mmap creates duplicate pages in 2.2.5 and 2.2.11 kernels"
- Reply: Kevin Kunzelman: "Re: ISSUE: Writing to mmap creates duplicate pages in 2.2.5 and 2.2.11 kernels"

Writing to mmap creates duplicate pages in 2.2.5 and
2.2.11 kernels

------------
Description:
------------

(1) open a new file
(2) populate file with some data
(3) mmap() the file for read/write.
(4) write to the mmap
(5) file will end up longer than it is supposed to,
with duplicate data changes

--------------
Sample Program
--------------

Here is a C program that reproduces the problem:

---begin C---

#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>

#define szBlock 8192

int main (int argc, char **argv)

char *pcFile = "mmaptest";
char ac [szBlock];
char *pcBuf;
off_t off = 0;
int fd;

unlink (pcFile);
memset (ac, 0, szBlock);

if ((fd = open (pcFile, O_CREAT | O_RDWR | O_APPEND,
0644)) < 0)
{
printf ("could not open file '%s'", pcFile);
exit (-1);
}
if (write (fd, ac, szBlock) != szBlock)
{
printf ("could not grow file '%s'", pcFile);
exit (-1);
}

pcBuf = (char *) mmap (0, szBlock,
PROT_READ | PROT_WRITE,
MAP_FILE | MAP_SHARED,
fd,
off);

pcBuf [50] = 'y';
pcBuf [4095] = 'y';
pcBuf [8191] = 'y';
}

---end C---

--------
Analysis
--------

The above program produces a file ("mmaptest") that
should only be 8192 bytes long. In fact, on BSDI and
an older version of Linux (2.0.0) the mmaptest file
properly looks like:

od -x mmaptest
0000000 0000 0000 0000 0000 0000 0000 0000 0000

0000060 0000 0079 0000 0000 0000 0000 0000 0000
0000100 0000 0000 0000 0000 0000 0000 0000 0000

0007760 0000 0000 0000 0000 0000 0000 0000 7900
0010000 0000 0000 0000 0000 0000 0000 0000 0000

0017760 0000 0000 0000 0000 0000 0000 0000 7900
0020000

However, on Linux 2.2.5 (stock RedHat 6.0-i386 and
i686 kernels) and Linux 2.2.11 (compiled myself),
mmaptest ends up incorrectly being 16384 bytes long
and looks like:

od -x mmaptest
0000000 0000 0000 0000 0000 0000 0000 0000 0000

0000060 0000 0079 0000 0000 0000 0000 0000 0000
0000100 0000 0000 0000 0000 0000 0000 0000 0000

0007760 0000 0000 0000 0000 0000 0000 0000 7900
0010000 0000 0000 0000 0000 0000 0000 0000 0000

0017760 0000 0000 0000 0000 0000 0000 0000 7900
0020000 0000 0000 0000 0000 0000 0000 0000 0000

0020060 0000 0079 0000 0000 0000 0000 0000 0000
0020100 0000 0000 0000 0000 0000 0000 0000 0000

0027760 0000 0000 0000 0000 0000 0000 0000 7900
0030000 0000 0000 0000 0000 0000 0000 0000 0000

0037760 0000 0000 0000 0000 0000 0000 0000 7900
0040000

Notice how the data between 0-0017777 and
0020000-0037777 is identical. Looks like the virtual
memory system duplicated the pages or something.

I even ran the same exact binary on both 2.0.0 and
2.2.5 and got the different results.

----------------------
DUMP OF /proc/version:
----------------------

Linux version 2.2.5-15 (root@porky.devel.redhat.com)
(gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2
release)) #1 Mon Apr 19 21:39:28 EDT 1999

----------------------
OUTPUT FROM ver_linux:
----------------------

-- Versions installed: (if some fields are empty or
looks
-- unusual then possibly you have very old versions)
Linux homer 2.2.5-15 #1 Mon Apr 19 21:39:28 EDT 1999
i586 unknown
Kernel modules 2.1.121
Gnu C egcs-2.91.66
Binutils 2.9.1.0.23
Linux C Library 1.1.so
ldd: missing file arguments
Try `ldd --help' for more information.
ls: /usr/lib/libg++.so: No such file or directory
Procps 2.0.2
Mount 2.9o
Net-tools (1999-01-31)
Kbd [option...]
Sh-utils 1.16

----------------------
DUMP OF /proc/cpuinfo:
----------------------

processor : 0
vendor_id : AuthenticAMD
cpu family : 5
model : 6
model name : AMD-K6tm w/ multimedia extensions
stepping : 2
cpu MHz : 233.869449
fdiv_bug : no
hlt_bug : no
sep_bug : no
f00f_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr mce cx8 sep mmx
bogomips : 466.94

----------------------
DUMP OF /proc/modules:
----------------------

ne2k-pci 3748 1 (autoclean)
8390 5920 0 (autoclean)
[ne2k-pci]

BTW, I'm not a member of the list, so please CC me on
any response.

Thanks,
Kevin
__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

- Next message: Matthew Wilcox: "Re: 2.2.11 unstable"
- Previous message: Zach Brown: "OSS maestro driver alpha"
- Next in thread: Kevin Kunzelman: "Re: ISSUE: Writing to mmap creates duplicate pages in 2.2.5 and 2.2.11 kernels"
- Reply: Kevin Kunzelman: "Re: ISSUE: Writing to mmap creates duplicate pages in 2.2.5 and 2.2.11 kernels"