I know that PAGED_CODE() can be called to make the code and buffers pagable. So why do i need to make my code pageable. Is there any problems with non pageable code ?
xxxxx@gmail.com wrote:
I know that PAGED_CODE() can be called to make the code and buffers pagable.
No. The PAGED_CODE macro doesn’t change anything. All it does is cause
a blue screen if it is called at a raised IRQL (where paging is not
allowed). You have to use pragmas to move your code in a paged section.
So why do i need to make my code pageable. Is there any problems with non pageable code ?
The problem is that non-paged code uses memory 100% of the time, even if
it is not used… On a normal system, you might convince yourself that a
few dozen kilobytes is trivial, but consider a system running 50 VMs.
Microsoft says it makes a difference.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
PAGED_CODE() does not make anything pageable; it’s an assert that checks the
current IRQL to see if you may run pageable code.
Something like:
#define PAGED_CODE() {
\
if (KeGetCurrentIrql() > APC_LEVEL) {
\
KdPrint((“EX: Pageable code called at IRQL %d\n”,
KeGetCurrentIrql())); \
PAGED_ASSERT(FALSE);
\
}
\
}
In order to actually page code, you need to use the alloc_text #pragma.
For example (from the src\general\ioctl\wdm\sioctl.c)
#ifdef ALLOC_PRAGMA
#pragma alloc_text( INIT, DriverEntry )
#pragma alloc_text( PAGE, SioctlCreateClose)
#pragma alloc_text( PAGE, SioctlDeviceControl)
#pragma alloc_text( PAGE, SioctlUnloadDriver)
#pragma alloc_text( PAGE, PrintIrpInfo)
#pragma alloc_text( PAGE, PrintChars)
#endif // ALLOC_PRAGMA
Regarding your fundamental question of whether to page code or not, this is
somewhat of religious issue here.
One camp says that you should because it’s important to conserve memory
especially in the presence of virtual machines today.
Another (the one to which I subscribe) says that while conserving memory is
a very laudable goal, nobody else seems to be bothered enough to do this, so
why should we introduce complexity and potential errors when (for most of
us) our drivers don’t consume anything even chartable compared to what other
drivers (and for that matter services) do. Whatever the merits of this
argument are or are not, one problem with not making anything pageable is
that you might be missing a whole class of errors that will be a problem,
should you ever make anything pageable.
In the case of code (v. data), the amount of memory that you are saving is
not much, so my opinion is that if you are new to this stuff, get working
first and then worry about saving memory this way later, if you wish.
Good luck,
mm
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@gmail.com
Sent: Tuesday, November 23, 2010 6:12 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Use of PAGED_CODE ?
I know that PAGED_CODE() can be called to make the code and buffers pagable.
So why do i need to make my code pageable. Is there any problems with non
pageable code ?
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars 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
Make a big difference on resource constrained devices like netbooks too
d
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
Sent: Tuesday, November 23, 2010 3:21 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Use of PAGED_CODE ?
xxxxx@gmail.com wrote:
I know that PAGED_CODE() can be called to make the code and buffers pagable.
No. The PAGED_CODE macro doesn’t change anything. All it does is cause a blue screen if it is called at a raised IRQL (where paging is not allowed). You have to use pragmas to move your code in a paged section.
So why do i need to make my code pageable. Is there any problems with non pageable code ?
The problem is that non-paged code uses memory 100% of the time, even if it is not used… On a normal system, you might convince yourself that a few dozen kilobytes is trivial, but consider a system running 50 VMs.
Microsoft says it makes a difference.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars 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
+1
I’ve had customers who broke OEM agreements because the lousy drivers
from the vendor would not fix things and aggressively use paged code.
Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
“Doron Holan” wrote in message
news:xxxxx@ntdev:
> Make a big difference on resource constrained devices like netbooks too
>
> d
>
> -----Original Message-----
> From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
> Sent: Tuesday, November 23, 2010 3:21 PM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] Use of PAGED_CODE ?
>
> xxxxx@gmail.com wrote:
> > I know that PAGED_CODE() can be called to make the code and buffers pagable.
>
> No. The PAGED_CODE macro doesn’t change anything. All it does is cause a blue screen if it is called at a raised IRQL (where paging is not allowed). You have to use pragmas to move your code in a paged section.
>
> > So why do i need to make my code pageable. Is there any problems with non pageable code ?
>
> The problem is that non-paged code uses memory 100% of the time, even if it is not used… On a normal system, you might convince yourself that a few dozen kilobytes is trivial, but consider a system running 50 VMs.
> Microsoft says it makes a difference.
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars 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
Thanks so much guys.