Cache coherence between two streams

Dear all,

I met a big headache about cache coherence in my ext2 file system driver:

I use one volume stream object for all the meta data (including directory, file ind/dind/tind blocks) and file streams for separate files.

See such case: ( One block size is 1024 (0x400) bytes.)


| | | | | | | | | |
…| | File block 1 | | File block 2 | | Meta data 1 | | File block 3 | |…
| || |_____________ | |_____________| || |

File block 1 2 3 belong to a file stream, and meta data1 belongs to the volume stream object. The meta data 1 is the ind-block. When making modifications on it, I use CcPinRead with one block size (0x400).

When paging writing for the file stream, I’ll split the writing stream into two groups to avoid writing the meta data block.

But when I receive paging writing for the volume object, the starting address is (File block 1), and the size is 0x1000 (PAGE_SIZE, 4 blocks).

I’ve tried ways to solve it, but no progress …

1, I use CcFlushCache/CcPurgeCacheSection when expanding file size in cached write (IRP_MJ_WRITE). But I’ll be blocked in CcPurgeCacheSection.

if (!Nocache && FileExtended) {

for(i=0; i {
CcFlushCache( &(Vcb->SectionObject),
(PLARGE_INTEGER)&(ext2_bdl[i].Lba),
ext2_bdl[i].Length,
NULL);

if (Vcb->SectionObject.DataSectionObject != NULL)
{
ExAcquireSharedStarveExclusive(&Vcb->PagingIoResource, TRUE);
ExReleaseResource(&Vcb->PagingIoResource);

CcPurgeCacheSection( &(Vcb->SectionObject),
(PLARGE_INTEGER)&(ext2_bdl[i].Lba),
ext2_bdl[i].Length,
FALSE );
}

}

2, I let the above codes in paging writing, just before sending file writing irp to the disk drivers.

This time, system hangs perhaps because deadlocks. But I can’t figure it out.
When it hang, I got 2 locks exclusived owned by one thread and 2 locks for another.

Thread 1: –> Ext2Cleanup -> (Acquire Vcb->MainResource/Fcb->MainResource) -> CcFlushCache to File Stream.
Thread 2: —>Ext2Write -> (Unknown eresource acquired / Fcb->PagingioResource) -> CcFlushCache to Volume Stream.

3, I split the process CcFlushCache and CcPurgeCacheSection and let Ext2Cleanup release Vcb->MainResource before CcFlushCache.
Do CcFlushCache in cached writing and CcPurgeCacheSection in pagingio writing.
No dead locks occur but new problems arise … I’m analyzing this case now with hoping to solve the problems.

Does Anyone have a clue ? Any words will be sincerely appreciated.

Thanks in advance,

Matt

Hi,

But when I receive paging writing for the volume object, the starting
address is (File block 1), and the size is 0x1000 (PAGE_SIZE, 4 blocks).

Paging IO always has granularity 1 page (0x1000 on x86). If you want mark
dirty some range inside page you have to implement bookkeeping yourself
and skip writing parts of page that not supposed to be written inside your
dispatch routine based on your own bookkeeping.

if (Vcb->SectionObject.DataSectionObject != NULL)
{
ExAcquireSharedStarveExclusive(&Vcb->PagingIoResource, TRUE);
ExReleaseResource(&Vcb->PagingIoResource);

CcPurgeCacheSection( &(Vcb->SectionObject),
(PLARGE_INTEGER)&(ext2_bdl[i].Lba),
ext2_bdl[i].Length,
FALSE );
}

}

This time, system hangs perhaps because deadlocks. But I can’t figure it
out.

If you will try use CcPurgeCacheSection while some range of the file is
pinned you will have deadlock - CcPurgeCacheSection waits for CcUnpinData.
Also, you can’t use CcPurgeCacheSection to purge just part of the page.

FAT file system uses MCB and bunch of Rtl rotines to keep track of dirty
sectors instead of dirty pages - take a look at FatCommonWrite for
TypeOfWrite == VirtualVolumeFile.

Alexei.

Alexei Jelvis£¬

Thank you very much for your valuable clue!

Best wishes,

Matt

does different streams of a file have the same fscontext value?

Ho Mun Chuen
@@ “Not everything that counts can be counted;
<” )~ and not everything that can be counted counts"
//\ … Albert Einstein

another question, is there any set request for streams? there is for query.

thanks!

Ho Mun Chuen
@@ “Not everything that counts can be counted;
<” )~ and not everything that can be counted counts"
//\ … Albert Einstein
----- Original Message -----
From: “Ho Mun Chuen”
To: “File Systems Developers”
Sent: Monday, August 26, 2002 2:43 PM
Subject: [ntfsd] streams

does different streams of a file have the same fscontext value?

Ho Mun Chuen
@@ “Not everything that counts can be counted;
<” )~ and not everything that can be counted counts"
//\ … Albert Einstein


You are currently subscribed to ntfsd as: xxxxx@pmail.ntu.edu.sg
To unsubscribe send a blank email to %%email.unsub%%