From cee6a383d3d1732e78827c839ee9513847e03aa6 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Sat, 26 May 2012 18:11:06 -0400 Subject: [PATCH] Windows: Adjust extent release strategy All extents were flushed whenever AFSReleaseExtentsWithFlush was executed. This included a call at the completion of each NonCached Read operation which could result in heavy thrashing as the data would be released prior to it being needed by the application. This patchset makes the following adjustments. First, AFSReleaseExtentsWithFlush() has been modified to release all but 1024 extents belonging to the file. Second, NonCached Reads only execute AFSReleaseExtentsWithFlush() when there are more than 4096 extents associated with the file. Third, AFSReleaseExtentsWithFlush() now has a 'bReleaseAll' parameter which is used for calls from AFSCleanup() and AFSFlushExtents() which need to be able to flush all extents attached to a FCB. Change-Id: Id8b05f02c59eb46b1881e4d905a511a2597455e8 Reviewed-on: http://gerrit.openafs.org/7520 Tested-by: BuildBot Reviewed-by: Jeffrey Altman Tested-by: Jeffrey Altman --- src/WINNT/afsrdr/kernel/lib/AFSCleanup.cpp | 3 +++ src/WINNT/afsrdr/kernel/lib/AFSExtentsSupport.cpp | 12 +++++------- src/WINNT/afsrdr/kernel/lib/AFSFlushBuffers.cpp | 3 ++- src/WINNT/afsrdr/kernel/lib/AFSGeneric.cpp | 6 ++++-- src/WINNT/afsrdr/kernel/lib/AFSRead.cpp | 10 ++++++++-- src/WINNT/afsrdr/kernel/lib/AFSWorker.cpp | 3 ++- src/WINNT/afsrdr/kernel/lib/Include/AFSCommon.h | 3 ++- 7 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/WINNT/afsrdr/kernel/lib/AFSCleanup.cpp b/src/WINNT/afsrdr/kernel/lib/AFSCleanup.cpp index fc6af3333..28d4ffc42 100644 --- a/src/WINNT/afsrdr/kernel/lib/AFSCleanup.cpp +++ b/src/WINNT/afsrdr/kernel/lib/AFSCleanup.cpp @@ -557,6 +557,9 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject, AFSWaitOnQueuedFlushes( pFcb); ulNotificationFlags |= AFS_REQUEST_FLAG_FLUSH_FILE; + + AFSTearDownFcbExtents( pFcb, + &pCcb->AuthGroup); } // diff --git a/src/WINNT/afsrdr/kernel/lib/AFSExtentsSupport.cpp b/src/WINNT/afsrdr/kernel/lib/AFSExtentsSupport.cpp index b90915b22..6d503d4fc 100644 --- a/src/WINNT/afsrdr/kernel/lib/AFSExtentsSupport.cpp +++ b/src/WINNT/afsrdr/kernel/lib/AFSExtentsSupport.cpp @@ -2885,7 +2885,8 @@ try_exit: NTSTATUS AFSReleaseExtentsWithFlush( IN AFSFcb *Fcb, - IN GUID *AuthGroup) + IN GUID *AuthGroup, + IN BOOLEAN bReleaseAll) { AFSNonPagedFcb *pNPFcb = Fcb->NPFcb; AFSExtent *pExtent; @@ -2956,18 +2957,15 @@ AFSReleaseExtentsWithFlush( IN AFSFcb *Fcb, try_return ( ntStatus = STATUS_INSUFFICIENT_RESOURCES ); } - if( Fcb->OpenHandleCount > 0) + if( Fcb->OpenHandleCount > 0 && + !bReleaseAll) { // // Don't release everything ... // - // - // For now release everything - // - - //ulRemainingExtentLength = 1500; + ulRemainingExtentLength = 1024; } while( Fcb->Specific.File.ExtentLength > (LONG)ulRemainingExtentLength) diff --git a/src/WINNT/afsrdr/kernel/lib/AFSFlushBuffers.cpp b/src/WINNT/afsrdr/kernel/lib/AFSFlushBuffers.cpp index d868a4999..eedfd9a22 100644 --- a/src/WINNT/afsrdr/kernel/lib/AFSFlushBuffers.cpp +++ b/src/WINNT/afsrdr/kernel/lib/AFSFlushBuffers.cpp @@ -126,7 +126,8 @@ AFSFlushBuffers( IN PDEVICE_OBJECT LibDeviceObject, { AFSReleaseExtentsWithFlush( pFcb, - &pCcb->AuthGroup); + &pCcb->AuthGroup, + TRUE); ntStatus = STATUS_SUCCESS; } diff --git a/src/WINNT/afsrdr/kernel/lib/AFSGeneric.cpp b/src/WINNT/afsrdr/kernel/lib/AFSGeneric.cpp index a8804f668..ac81d7c3c 100644 --- a/src/WINNT/afsrdr/kernel/lib/AFSGeneric.cpp +++ b/src/WINNT/afsrdr/kernel/lib/AFSGeneric.cpp @@ -7028,7 +7028,8 @@ AFSCleanupFcb( IN AFSFcb *Fcb, { AFSReleaseExtentsWithFlush( Fcb, - NULL); + NULL, + TRUE); } } @@ -7073,7 +7074,8 @@ AFSCleanupFcb( IN AFSFcb *Fcb, { AFSReleaseExtentsWithFlush( Fcb, - NULL); + NULL, + TRUE); } } diff --git a/src/WINNT/afsrdr/kernel/lib/AFSRead.cpp b/src/WINNT/afsrdr/kernel/lib/AFSRead.cpp index 1e8dbb97f..775c9aa57 100644 --- a/src/WINNT/afsrdr/kernel/lib/AFSRead.cpp +++ b/src/WINNT/afsrdr/kernel/lib/AFSRead.cpp @@ -691,8 +691,14 @@ AFSNonCachedRead( IN PDEVICE_OBJECT DeviceObject, // The data is there now. Give back the extents now so the service // has some in hand // - (VOID) AFSReleaseExtentsWithFlush( pFcb, - &pCcb->AuthGroup); + + if ( pFcb->Specific.File.ExtentLength > 4096) + { + + (VOID) AFSReleaseExtentsWithFlush( pFcb, + &pCcb->AuthGroup, + FALSE); + } try_exit: diff --git a/src/WINNT/afsrdr/kernel/lib/AFSWorker.cpp b/src/WINNT/afsrdr/kernel/lib/AFSWorker.cpp index 2af9c67d4..9239c40e8 100644 --- a/src/WINNT/afsrdr/kernel/lib/AFSWorker.cpp +++ b/src/WINNT/afsrdr/kernel/lib/AFSWorker.cpp @@ -739,7 +739,8 @@ AFSWorkerThread( IN PVOID Context) { AFSReleaseExtentsWithFlush( pWorkItem->Specific.Fcb.Fcb, - &pWorkItem->AuthGroup); + &pWorkItem->AuthGroup, + FALSE); } ASSERT( pWorkItem->Specific.Fcb.Fcb->OpenReferenceCount != 0); diff --git a/src/WINNT/afsrdr/kernel/lib/Include/AFSCommon.h b/src/WINNT/afsrdr/kernel/lib/Include/AFSCommon.h index 0b666696e..ffe175434 100644 --- a/src/WINNT/afsrdr/kernel/lib/Include/AFSCommon.h +++ b/src/WINNT/afsrdr/kernel/lib/Include/AFSCommon.h @@ -395,7 +395,8 @@ AFSFlushExtents( IN AFSFcb *pFcb, NTSTATUS AFSReleaseExtentsWithFlush( IN AFSFcb *Fcb, - IN GUID *AuthGroup); + IN GUID *AuthGroup, + IN BOOLEAN bReleaseAll); NTSTATUS AFSReleaseCleanExtents( IN AFSFcb *Fcb, -- 2.39.5