[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnet/image image.h,1.18,1.19 pecoff_writer.c
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnet/image image.h,1.18,1.19 pecoff_writer.c,1.9,1.10 writer.c,1.9,1.10 |
Date: |
Fri, 07 Feb 2003 23:24:31 -0500 |
Update of /cvsroot/dotgnu-pnet/pnet/image
In directory subversions:/tmp/cvs-serv28307/image
Modified Files:
image.h pecoff_writer.c writer.c
Log Message:
Implement a caching mechanism for back-patching to smooth out
filesystem performance, particular on NFS-mounted filesystems.
Index: image.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/image.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -r1.18 -r1.19
*** image.h 7 Feb 2003 11:31:30 -0000 1.18
--- image.h 8 Feb 2003 04:24:29 -0000 1.19
***************
*** 351,354 ****
--- 351,360 ----
int writeFailed; /* The write failed at
some point */
+ /* Back-patch cache */
+ int backpatching; /* Non-zero if last
write was back-patch */
+ unsigned long backpatchSeek; /* Seek position of back-patch cache */
+ unsigned long backpatchLen; /* Length of back-patch cache */
+ unsigned char *backpatchBuf; /* Buffer containing back-patch data */
+
};
Index: pecoff_writer.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/pecoff_writer.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** pecoff_writer.c 26 Nov 2002 05:04:46 -0000 1.9
--- pecoff_writer.c 8 Feb 2003 04:24:29 -0000 1.10
***************
*** 27,30 ****
--- 27,58 ----
/*
+ * Flush the back-patch cache if necessary.
+ */
+ static void FlushBackPatchCache(ILWriter *writer)
+ {
+ if(writer->backpatching)
+ {
+ /* Seek to the beginning of the back-patch area */
+ if(fseek(writer->stream, writer->backpatchSeek, 0) < 0)
+ {
+ writer->writeFailed = 1;
+ return;
+ }
+
+ /* Write the modified contents of the back-patch buffer */
+ if(fwrite(writer->backpatchBuf, 1,
(unsigned)(writer->backpatchLen),
+ writer->stream) !=
(unsigned)(writer->backpatchLen))
+ {
+ writer->writeFailed = 1;
+ return;
+ }
+
+ /* Record the new seek position and exit the back-patching mode
*/
+ writer->currSeek = writer->backpatchSeek + writer->backpatchLen;
+ writer->backpatching = 0;
+ }
+ }
+
+ /*
* Write a block of data to an output image.
*/
***************
*** 38,41 ****
--- 66,72 ----
if(writer->seekable)
{
+ /* Flush the back-patching cache, if present */
+ FlushBackPatchCache(writer);
+
/* This is a seekable stream, so write directly to it */
if(writer->offset != writer->currSeek)
***************
*** 110,113 ****
--- 141,149 ----
}
}
+ else
+ {
+ /* Flush the back-patching cache */
+ FlushBackPatchCache(writer);
+ }
}
***************
*** 141,144 ****
--- 177,224 ----
if(writer->seekable)
{
+ /* Can we add the bytes to the current back-patch cache? */
+ if(writer->backpatching && posn >= writer->backpatchSeek &&
+ (posn + size) <= (writer->backpatchSeek +
writer->backpatchLen))
+ {
+ ILMemCpy(writer->backpatchBuf +
+ (unsigned)(posn -
writer->backpatchSeek), buffer, size);
+ return;
+ }
+
+ /* Flush the current back-patch cache contents */
+ FlushBackPatchCache(writer);
+
+ /* Only do caching for small values (usually 32-bit quantities)
*/
+ if(size <= 4 && writer->backpatchBuf)
+ {
+ /* Align the back-patch cache for better filesystem
performance */
+ writer->backpatchSeek = posn & ~511;
+ writer->backpatchLen = writer->offset -
writer->backpatchSeek;
+ if(writer->backpatchLen > IL_WRITE_BUFFER_SIZE)
+ {
+ writer->backpatchLen = IL_WRITE_BUFFER_SIZE;
+ }
+
+ /* Read the block to be patched into memory */
+ if(fseek(writer->stream, writer->backpatchSeek, 0) < 0)
+ {
+ writer->writeFailed = 1;
+ return;
+ }
+ if(fread(writer->backpatchBuf, 1,
(unsigned)(writer->backpatchLen),
+ writer->stream) !=
(unsigned)(writer->backpatchLen))
+ {
+ writer->writeFailed = 1;
+ return;
+ }
+ writer->currSeek = writer->backpatchSeek +
writer->backpatchLen;
+
+ /* Patch the required bytes and return */
+ ILMemCpy(writer->backpatchBuf +
+ (unsigned)(posn -
writer->backpatchSeek), buffer, size);
+ writer->backpatching = 1;
+ return;
+ }
+
/* Seek back in the file and write the change */
if(posn != writer->currSeek)
Index: writer.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/writer.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** writer.c 7 Jan 2003 11:57:18 -0000 1.9
--- writer.c 8 Feb 2003 04:24:29 -0000 1.10
***************
*** 119,122 ****
--- 119,126 ----
writer->maxDebugTokens = 0;
writer->debugHash = 0;
+ writer->backpatching = 0;
+ writer->backpatchSeek = 0;
+ writer->backpatchLen = 0;
+ writer->backpatchBuf = 0;
/* Initialize buffer lists */
***************
*** 132,135 ****
--- 136,147 ----
writer->lastFixup = 0;
+ /* Allocate the back-patching buffer. If we run out of
+ memory, then disable the back-patch cache */
+ if(seekable)
+ {
+ writer->backpatchBuf = (unsigned char *)ILMalloc
+ (IL_WRITE_BUFFER_SIZE);
+ }
+
/* Write the headers to the output stream */
if(flags & IL_WRITEFLAG_JVM_MODE)
***************
*** 623,626 ****
--- 635,644 ----
{
ILHashDestroy(writer->debugHash);
+ }
+
+ /* Free the back-patch buffer */
+ if(writer->backpatchBuf)
+ {
+ ILFree(writer->backpatchBuf);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnet/image image.h,1.18,1.19 pecoff_writer.c,1.9,1.10 writer.c,1.9,1.10,
Rhys Weatherley <address@hidden> <=