What is a *Page*?

  • Thread starter Thread starter Abubakar
  • Start date Start date
A

Abubakar

Hi,

I'm viewing this stack overflow help page (
http://support.microsoft.com/kb/315937 ) at the ms support site. I cant say
I understand the concept of a "page" the way its used in this
example/explanation. I mean I only am aware of the *simple*, *general*,
paging concept, the one that is discussed often when explaning how an
operating system can support more memory than actually is available by doing
paging on the hard drive (and that also only at a higher-level theoratical
concept). Although the "page"/"page guard"/etc thats referenced here *feels*
something like that but nothing makes sense to me.
For example take this sentence:

"The stack then grows on demand to meet the needs of the thread. This is
implemented by placing a page with PAGE_GUARD access at the end of the
current stack."

here I'm confused.
- What is a "page" here? Is it some data structure? What do they contain?
Can we see it? Is it documented? I need the links to its docs.

- is "stack" some linked list kind of dynamically growing LIFO data
structure? Are the contents of this stack these (unknown for me) "pages", in
which case if the stack size is 5 than there will be 5 pages?

plz clarify...
Regards,

...ab
 
Abubakar said:
here I'm confused.
- What is a "page" here? Is it some data structure? What do they contain?
Can we see it? Is it documented? I need the links to its docs.

On an operating system that uses virtual memory, a page is the smallest
amount of memory which is moved in one go from the page file to physical
memory. If you need to know how much memory is in a page, you call
GetSystemInfo().
- is "stack" some linked list kind of dynamically growing LIFO data
structure?

No. The stack is a contiguous region of memory. By default, it is 1MB large.
But like every other region of memory in Windows it is virtual memory.
Address ranges of memory in the stack region are backed ("committed") by
physical memory on an as needed basis.
Are the contents of this stack these (unknown for me) "pages", in which
case if the stack size is 5 than there will be 5 pages?

It's a rare application which measures the size of anything in pages. The
stack is no different, it is measured in bytes.

Why do you need to know?

Regards,
Will
 
Hi,

I'm viewing this stack overflow help page (
http://support.microsoft.com/kb/315937 ) at the ms support site. I cant say
I understand the concept of a "page" the way its used in this
example/explanation. I mean I only am aware of the *simple*, *general*,
paging concept, the one that is discussed often when explaning how an
operating system can support more memory than actually is available by doing
paging on the hard drive (and that also only at a higher-level theoratical
concept). Although the "page"/"page guard"/etc thats referenced here *feels*
something like that but nothing makes sense to me.
For example take this sentence:

"The stack then grows on demand to meet the needs of the thread. This is
implemented by placing a page with PAGE_GUARD access at the end of the
current stack."

here I'm confused.
- What is a "page" here? Is it some data structure? What do they contain?
Can we see it? Is it documented? I need the links to its docs.

A page is the smallest unit of memory the Windows virtual memory system
deals with. Look up VirtualAlloc, and you'll find a lot of info on pages.
- is "stack" some linked list kind of dynamically growing LIFO data
structure?

No, a thread's stack is a contiguous region of memory that grows
dynamically up to its maximum configured size as the thread pushes data
into the guard page, which causes a structured exception, which further
causes the OS to commit the page and create a new guard page just below it.
Are the contents of this stack these (unknown for me) "pages", in
which case if the stack size is 5 than there will be 5 pages?

It's a lot more common to measure in bytes; when there's doubt, you should
specify the units, as I'm sure the Mars Climate Orbiter people wish they
had done.

You should search MSDN for PAGE_GUARD. This article talks about it, but its
example doesn't illustrate using it to grow a stack:

http://msdn2.microsoft.com/en-us/library/aa366549.aspx

This one talks about reserving and committing memory and shows how to use
structured exceptions to handle page faults to grow an array:

http://msdn2.microsoft.com/en-us/library/aa366803.aspx

What the system does with the thread stack lies somewhere in between...
 
Hey thanks for the useful links and the explanation. I'll have to read a lot
before being able to ask more on this topic.

Regards,

...ab
 
Hi,
thanks for the nice explanation.
Why do you need to know?

Well, I was going through the kb site on microsoft support and it showed how
I could catch the stack overflow exception and handle it and the talk was
all about "pages". I have heard about pages before but I thought that
finally I need to remove my confusion and build up some knowledge about this
concept so I wont have any confusions in the future when somebody mentions
"stack" or "pages" or "heap" etc.

If u find/know any links related to these concepts, do share here.

Regards,

...ab
 
Abubakar said:
thanks for the nice explanation.

You are welcome.
Well, I was going through the kb site on microsoft support and it showed
how I could catch the stack overflow exception and handle it and the talk
was all about "pages". I have heard about pages before but I thought that
finally I need to remove my confusion and build up some knowledge about
this concept so I wont have any confusions in the future when somebody
mentions "stack" or "pages" or "heap" etc.

Well, first you have to remember that the stack by deafult is 1MB large.
Your application shouldn't have to worry in general about overflowing the
stack. If it does overflow it, that's generally due to one of two main
causes:

1) a recursive algorithm recursing too much <g>
2) the allocation of a very large "automatic" array on the stack

One deals with the first problem by recasting an algorithm, and with the
second by moving the allocation to the heap.

Regards,
Will
 
Abubakar said:
Hi,

I'm viewing this stack overflow help page (
http://support.microsoft.com/kb/315937 ) at the ms support site. I cant
say I understand the concept of a "page" the way its used in this
example/explanation. I mean I only am aware of the *simple*, *general*,
paging concept, the one that is discussed often when explaning how an
operating system can support more memory than actually is available by
doing paging on the hard drive (and that also only at a higher-level
theoratical concept). Although the "page"/"page guard"/etc thats
referenced here *feels* something like that but nothing makes sense to me.
For example take this sentence:

While a emulating additional memory using a swap file uses paging as its
implementation (in most OSes, including Windows), it is not the definition
of paging/virtual memory. It's extremely useful for isolating user-mode
processes from each other for security and reliability, and dynamic memory
commitment. A good place to start is by reading up on virtual memory and
the Translation Look-aside Buffer (TLB).

http://en.wikipedia.org/wiki/Virtual_memory
http://en.wikipedia.org/wiki/Page_fault
http://en.wikipedia.org/wiki/Page_table
http://en.wikipedia.org/wiki/Translation_Lookaside_Buffer
 
Thanks.

...ab

Ben Voigt said:
While a emulating additional memory using a swap file uses paging as its
implementation (in most OSes, including Windows), it is not the definition
of paging/virtual memory. It's extremely useful for isolating user-mode
processes from each other for security and reliability, and dynamic memory
commitment. A good place to start is by reading up on virtual memory and
the Translation Look-aside Buffer (TLB).

http://en.wikipedia.org/wiki/Virtual_memory
http://en.wikipedia.org/wiki/Page_fault
http://en.wikipedia.org/wiki/Page_table
http://en.wikipedia.org/wiki/Translation_Lookaside_Buffer
 
Back
Top