statically declared variable

Suppose I declare a KEVENT statically in the global scope of a driver
file, like this:

KEVENT gEvent;

In different functions of the module where I’ve declared this event I then
initialize it, set it, and clear it.

Since I haven’t allocated gEvent using ExAllocatePool(NonPagedPool,
sizeof(KEVENT)) is it possible that the variable will be paged out?

your data segment is by default non-paged so the event won’t get paged
out. However given the reentrant nature of device drivers you need to
be very careful to ensure you don’t have two threads initializing,
setting & clearing it at the same time.

-p

-----Original Message-----
From: skip [mailto:xxxxx@hotmail.com]
Sent: Friday, May 03, 2002 2:50 PM
To: NT Developers Interest List
Subject: [ntdev] statically declared variable

Suppose I declare a KEVENT statically in the global scope of a driver
file, like this:

KEVENT gEvent;

In different functions of the module where I’ve declared this event I
then initialize it, set it, and clear it.

Since I haven’t allocated gEvent using ExAllocatePool(NonPagedPool,
sizeof(KEVENT)) is it possible that the variable will be paged out?


You are currently subscribed to ntdev as: xxxxx@microsoft.com To
unsubscribe send a blank email to %%email.unsub%%

> Since I haven’t allocated gEvent using ExAllocatePool(NonPagedPool,

sizeof(KEVENT)) is it possible that the variable will be paged out?

By default, no, unless you have used #pragma data_seg(“PAGE”)

Max

At 23.50 03/05/2002, you wrote:

Suppose I declare a KEVENT statically in the global scope of a driver
file, like this:
KEVENT gEvent;
In different functions of the module where I’ve declared this event I then
initialize it, set it, and clear it.

(be careful not to access the object from multiple threads at the same time)

Since I haven’t allocated gEvent using ExAllocatePool(NonPagedPool,
sizeof(KEVENT)) is it possible that the variable will be paged out?

static variables reside, IIRC, in the .data section of the executable, or
some other section with the appropriate attributes. I think it depends on
the section’s flags, and I think that by default sections are marked as
pageable. I’m no expert here, though

> some other section with the appropriate attributes. I think it depends on

the section’s flags,

No, on section name. If it starts with “PAGE” - then the section is pageable.

and I think that by default sections are marked as
pageable.

As NONpageable.

Max

Max is right. But it’s worth noting the full syntax. (Perhaps I missed
this in an earlier part of the thread. If so, sorry.)

If you want static data to end up in a particular section, the
constructs I use within the DDK environment look like this:

#ifdef ALLOC_DATA_PRAGMA
#pragma data_seg(“INIT”)
#endif

(definitions for static data that can disappear after the end of
DriverEntry)

#ifdef ALLOC_DATA_PRAGMA
#pragma data_seg(“PAGE”)
#endif

(definitions for static data that can be paged)

#ifdef ALLOC_DATA_PRAGMA
#pragma data_seg(“PAGELK”)
#endif

(definitions for static data that can be paged, but which I will lock
down occasionally, as when the system is about to go to sleep)

#ifdef ALLOC_DATA_PRAGMA
#pragma data_seg()
#endif

(this causes the other directives to be ignored)

In another thread, I think it was Bill who said that he thinks that it’s
not worth ever using pageable memory in a driver, mostly because the
performance benefit is small and the test hassle is large. I agree that
the performance benefit has gotten pretty small as memories have gotten
larger. But I believe the test hassle is also small, as long as you
turn on IRQL Checking in the Driver Verifier.

This feature of the DV will page out all of your pageable allocations,
your pageable code and your pageable static data whenever you’re running
at raised IRQL, which will cause any access to paged data to immediately
fault. If you do your development with this flag enabled, then managing
paged data is actually quite simple.

Just an opinion,
Jake

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

-----Original Message-----
Subject: Re: statically declared variable
From: “Maxim S. Shatskih”
Date: Sat, 4 May 2002 19:41:18 +0400
X-Message-Number: 7

> some other section with the appropriate attributes. I think it depends
on
> the section’s flags,

No, on section name. If it starts with “PAGE” - then the section is
pageable.

>and I think that by default sections are marked as
> pageable.

As NONpageable.

Max

Page it all if it is not being used!

We have several drivers that require some action for large chunks of the
driver to become active. It is a filter and it sits there passive 95% of
the time. We page those chunks out until needed.

Laziness is not excuses…

Jamey

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jake Oshins
Sent: Sunday, May 05, 2002 1:04 AM
To: NT Developers Interest List
Subject: [ntdev] RE: statically declared variable

Max is right. But it’s worth noting the full syntax. (Perhaps I missed
this in an earlier part of the thread. If so, sorry.)

If you want static data to end up in a particular section, the
constructs I use within the DDK environment look like this:

#ifdef ALLOC_DATA_PRAGMA
#pragma data_seg(“INIT”)
#endif

(definitions for static data that can disappear after the end of
DriverEntry)

#ifdef ALLOC_DATA_PRAGMA
#pragma data_seg(“PAGE”)
#endif

(definitions for static data that can be paged)

#ifdef ALLOC_DATA_PRAGMA
#pragma data_seg(“PAGELK”)
#endif

(definitions for static data that can be paged, but which I will lock
down occasionally, as when the system is about to go to sleep)

#ifdef ALLOC_DATA_PRAGMA
#pragma data_seg()
#endif

(this causes the other directives to be ignored)

In another thread, I think it was Bill who said that he thinks that it’s
not worth ever using pageable memory in a driver, mostly because the
performance benefit is small and the test hassle is large. I agree that
the performance benefit has gotten pretty small as memories have gotten
larger. But I believe the test hassle is also small, as long as you
turn on IRQL Checking in the Driver Verifier.

This feature of the DV will page out all of your pageable allocations,
your pageable code and your pageable static data whenever you’re running
at raised IRQL, which will cause any access to paged data to immediately
fault. If you do your development with this flag enabled, then managing
paged data is actually quite simple.

Just an opinion,
Jake

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

-----Original Message-----
Subject: Re: statically declared variable
From: “Maxim S. Shatskih”
Date: Sat, 4 May 2002 19:41:18 +0400
X-Message-Number: 7

> some other section with the appropriate attributes. I think it depends
on
> the section’s flags,

No, on section name. If it starts with “PAGE” - then the section is
pageable.

>and I think that by default sections are marked as
> pageable.

As NONpageable.

Max


You are currently subscribed to ntdev as: xxxxx@storagecraft.com To
unsubscribe send a blank email to %%email.unsub%%