Speeding freeing of stream contexts in minifilter

I want to speed up minifilter unload by freeing stream contexts manually during unload. Instead of registering a stream context cleanup callback, I am freeing the contexts from my unload() callback. This way I am able to cleanup contexts to be cleanup during unload but how do I take care of the contexts that should be freed when a stream is getting closed i.e when driver is still running?

>I want to speed up minifilter unload by freeing stream contexts manually during unload.

Why do you think this will speed up anything?


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

Filter manager doesn’t have to call into my minifilter back for each stream context cleanup. This should speed up the stream context freeing.

How are you planning to free the memory allocated to the members present
inside your stream context?
If you don’t register a context cleanup callback, you won’t be able to free
the memory to the structure members (for instance you have stored the file
name in the stream context).

Regards,
Ayush Gupta

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-375471-
xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Monday, August 03, 2009 5:50 PM
To: Windows File Systems Devs Interest List
Subject: RE:[ntfsd] Speeding freeing of stream contexts in minifilter

Filter manager doesn’t have to call into my minifilter back for each
stream context cleanup. This should speed up the stream context
freeing.


NTFSD is sponsored by OSR

For our schedule of debugging and file system seminars
(including our new fs mini-filter seminar) visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

sorry forgot to mention that I am maintaining list of streamcontexts per volume. So I can just traverse the list per volume and free each stream context. This way I can free the allocated memory in each stream context.

You realize, of course, that in order to get the filter manager to drop
its reference to your context when you clean it up, you’ll have to call
FltDeleteStreamContext? Instead of FltMgr calling into you to do the
per-context cleanup routine, you’ll be calling into it to get it to
forget its reference. And then you’ll still have to call
FltReleaseStreamContext because it’s *still* reference counted, which
means you’ll get called into anyway.

It seems like you’re robbing Peter to pay Paul, and doing at the expense
of more lines of code you need to maintain. I’m not saying what you’re
proposing would be hard to get right, only that it’s already done by
somebody else.

Do you have any evidence that freeing these stream contexts is actually
causing a performance issue?

~Eric

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@gmail.com
Sent: Monday, August 03, 2009 11:16 AM
To: Windows File Systems Devs Interest List
Subject: RE:[ntfsd] Speeding freeing of stream contexts in minifilter

sorry forgot to mention that I am maintaining list of
streamcontexts per volume. So I can just traverse the list
per volume and free each stream context. This way I can free
the allocated memory in each stream context.


NTFSD is sponsored by OSR

For our schedule of debugging and file system seminars
(including our new fs mini-filter seminar) visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online
at http://www.osronline.com/page.cfm?name=ListServer

Yes I am doing exactly this call FltDeleteContext() and then release last reference to the stream context. Since I am not registering the streamcontext cleanup callback, I will not get any callback from filter manager when reference count reaches zero.

How much performance benefit (if any) I get will be known only when I am able to free contexts in this manner. Right now my minifilter spends a lot of time in stream context cleanup.

None.
The idea is that if u r not going to need cleanup for your structure, don’t
register a context cleanup callback. You don’t need to do fancy things like
FltDeleteContext.

Regards,
Ayush Gupta

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-375485-
xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Monday, August 03, 2009 9:46 PM
To: Windows File Systems Devs Interest List
Subject: RE:[ntfsd] Speeding freeing of stream contexts in minifilter

Yes I am doing exactly this call FltDeleteContext() and then release
last reference to the stream context. Since I am not registering the
streamcontext cleanup callback, I will not get any callback from filter
manager when reference count reaches zero.

How much performance benefit (if any) I get will be known only when I
am able to free contexts in this manner. Right now my minifilter spends
a lot of time in stream context cleanup.


NTFSD is sponsored by OSR

For our schedule of debugging and file system seminars
(including our new fs mini-filter seminar) visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Filter manager takes care of the lifetime of your context depending on the lifetime of the underlying object you are
attached to and the lifetime of your instance/filter. This is really really hard to get right and you are better off
offloading this to the filter manager infrastructure rather than do it yourself.

Your perf gain doing it yourself is minimal since to get it right you will have to do no less work than filter manager.

Regards,
Sarosh.
File System Filter Lead
Microsoft Corp

This posting is provided “AS IS” with no warranties, and confers no Rights

Ayush Gupta wrote:

None.
The idea is that if u r not going to need cleanup for your structure, don’t
register a context cleanup callback. You don’t need to do fancy things like
FltDeleteContext.

Regards,
Ayush Gupta

> -----Original Message-----
> From: xxxxx@lists.osr.com [mailto:bounce-375485-
> xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
> Sent: Monday, August 03, 2009 9:46 PM
> To: Windows File Systems Devs Interest List
> Subject: RE:[ntfsd] Speeding freeing of stream contexts in minifilter
>
> Yes I am doing exactly this call FltDeleteContext() and then release
> last reference to the stream context. Since I am not registering the
> streamcontext cleanup callback, I will not get any callback from filter
> manager when reference count reaches zero.
>
> How much performance benefit (if any) I get will be known only when I
> am able to free contexts in this manner. Right now my minifilter spends
> a lot of time in stream context cleanup.
>
>
> —
> NTFSD is sponsored by OSR
>
> For our schedule of debugging and file system seminars
> (including our new fs mini-filter seminar) visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer