question about IO_REMOVE_LOCK

Hi,
I use remove lock to synchronize my dispatch routines with device
removal logic(IRP_MN_REMOVE_DEVICE)
I Initialized the remove lock with it’s own tag and then I monitored
that tag in PoolTag.exe. Looks like remove lock does some
allocation(NonPagedPool most probably) every time it is acquired and
then frees up the memory when it is released.

Why is that? As I understand, all it needs to do is simple refcnt logic.

I wanted to keep allocations|deallocations out of main IO path (as much
as possible) but this is making a big hole in that approach.

If art interprets our dreams, the computer executes them in the guise of
programs!

It does that b/c it is tracking each tag and it needs memory to store
the tag value on each reference. BUT, this only happens if you compile
your driver as chk . Also, if the allocation fails, the remlock acquire
still succeeds. On a fre build, the allocations/frees do not occur and
only the reference count is maintained (but tag verification is turned
off). If you look at the definition of IO_REMOVE_LOCK,

typedef struct _IO_REMOVE_LOCK {
IO_REMOVE_LOCK_COMMON_BLOCK Common;
#if DBG
IO_REMOVE_LOCK_DBG_BLOCK Dbg;
#endif
} IO_REMOVE_LOCK, *PIO_REMOVE_LOCK;

And then the routines
#define IoInitializeRemoveLock(Lock, Tag, Maxmin, HighWater) \
IoInitializeRemoveLockEx (Lock, Tag, Maxmin, HighWater, sizeof
(IO_REMOVE_LOCK))
#define IoAcquireRemoveLock(RemoveLock, Tag) \
IoAcquireRemoveLockEx(RemoveLock, Tag, FILE, LINE,
sizeof (IO_REMOVE_LOCK))
#define IoReleaseRemoveLock(RemoveLock, Tag) \
IoReleaseRemoveLockEx(RemoveLock, Tag, sizeof (IO_REMOVE_LOCK))

You see that the fre/chk nature of the remlock is a runtime check.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Harish Arora
Sent: Friday, September 02, 2005 10:55 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] question about IO_REMOVE_LOCK

Hi,
I use remove lock to synchronize my dispatch routines with device
removal logic(IRP_MN_REMOVE_DEVICE)
I Initialized the remove lock with it’s own tag and then I monitored
that tag in PoolTag.exe. Looks like remove lock does some
allocation(NonPagedPool most probably) every time it is acquired and
then frees up the memory when it is released.

Why is that? As I understand, all it needs to do is simple refcnt logic.

I wanted to keep allocations|deallocations out of main IO path (as much
as possible) but this is making a big hole in that approach.

If art interprets our dreams, the computer executes them in the guise of
programs!


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

Are you running in checked kernel ? If so, have you tried running in
release ?

With respect to remlocks, what matters is if your driver is chk or fre,
not the kernel itself.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Satya Das
Sent: Friday, September 02, 2005 11:26 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] question about IO_REMOVE_LOCK

Are you running in checked kernel ? If so, have you tried running in
release ?


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

Perhaps the DDK documentation and IoInitializeRemoveLockEx comments in
the ntddk.h need to be changed ?

I will talk to the WDK folks about updating the docs for remlocks that
talks about fre/chk builds of the driver and the difference that it has
on the remlock code. IoInitializeRemoveLockEx itself will probably
remain undocumented b/c IoInitializeRemoveLock is what you should use to
init the remlock.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Satya Das
Sent: Friday, September 02, 2005 12:40 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] question about IO_REMOVE_LOCK

Perhaps the DDK documentation and IoInitializeRemoveLockEx comments in
the ntddk.h need to be changed ?


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

Thanks Doron and Satya for your responses.

What would happen if I passed a tag value 0 into Aquire and release
functions. Will it still do the allocations and deallocations ?

What would happen if I passed in a different Tag into release which was
never passed into acquire. ?

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-219026-
xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Friday, September 02, 2005 12:50 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] question about IO_REMOVE_LOCK

I will talk to the WDK folks about updating the docs for remlocks that
talks about fre/chk builds of the driver and the difference that it
has
on the remlock code. IoInitializeRemoveLockEx itself will probably
remain undocumented b/c IoInitializeRemoveLock is what you should use
to
init the remlock.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Satya Das
Sent: Friday, September 02, 2005 12:40 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] question about IO_REMOVE_LOCK

Perhaps the DDK documentation and IoInitializeRemoveLockEx comments in
the ntddk.h need to be changed ?


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag
argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag
argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

The whole point of the Tag values is that the tag passed to Release() is
a tag value that was previousl passed to Acquire() and not yet released.
The code doesn’t care about zero/NULL or any other value, allocations
and frees will be made (but only on a debug version of your driver!).
It treats zero like any other value. The usefulness of the Tag value
itself is up to the driver writer, the OS just keeps track of it.

If you pass an unmatched tag on release that was not give to an acquire
call, You will get an assert on a chk KERNEL. A fre KERNEL will not
anything in this case.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Harish Arora
Sent: Friday, September 02, 2005 1:05 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] question about IO_REMOVE_LOCK

Thanks Doron and Satya for your responses.

What would happen if I passed a tag value 0 into Aquire and release
functions. Will it still do the allocations and deallocations ?

What would happen if I passed in a different Tag into release which was
never passed into acquire. ?

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-219026-
xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Friday, September 02, 2005 12:50 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] question about IO_REMOVE_LOCK

I will talk to the WDK folks about updating the docs for remlocks that
talks about fre/chk builds of the driver and the difference that it
has
on the remlock code. IoInitializeRemoveLockEx itself will probably
remain undocumented b/c IoInitializeRemoveLock is what you should use
to
init the remlock.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Satya Das
Sent: Friday, September 02, 2005 12:40 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] question about IO_REMOVE_LOCK

Perhaps the DDK documentation and IoInitializeRemoveLockEx comments in
the ntddk.h need to be changed ?


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag
argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag
argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

>that tag in PoolTag.exe. Looks like remove lock does some

allocation(NonPagedPool most probably) every time it is acquired and
then frees up the memory when it is released.

It does this for some debug tracking I think.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com