[Autogenerated] we know that the normal page size is four kilobytes on
all Windows architectures but there's also a large page size and the
purpose of a large page sizes to make mapping easier and faster because
there's no need for a page table.
The PD points the beginning of a page over large page in
physical memory and then the offset is provided by the 21
bits at the lower end of the address.
And the size of a large page is two megabytes in in most
Windows architectures today for Windows 11,
it's always two megabytes because arm is not being used by Windows 11.
The main advantage here is the better use of the T L B.
cache Remember the TsB cash is very important in practice because
it holds mapping that have been done recently.
So now a single entry can point to two megabyte page
instead of just to a four K page.
Now by default, regardless of how applications are using large pages,
Windows maps,
the Colonel and the ____ you and some other data
structures like part of the non page pool.
We're using large pages because the Colonel Hall are always there.
So it's a good idea to make these mapping because we need all that
memory anyway and this is not going to go away anywhere.
The potential disadvantages of large pages exist as well.
Otherwise all pages would be used with large pages.
So one thing is that the entire page must be protected using a single
protection so you can't have better granularity.
You have to have a single protection for these two mega byte chunk.
More problematic perhaps is that you have to find a
page size in physical member,
which is also contagious in the size that you're
trying to allocate using large pages.
So for example, if you want to allocate 100 kilobyte chunk,
you have to find 50 large pages,
in the physical memory to be contagious and because you might have many small
pages that might have this sort of fragmentation between them,
you might not be able to do that when system is very low on memory.
So this kind of allocation might in fact fail.
And another thing which is, well,
it's a disadvantage or an advantage depending on your perspective,
there are always non tangible.
Large pages are always allocated directly from RAM, so they're mapped to RAM.
And that mapping is never going to go away unless the
process wants to de allocate that memory,
which could be a good thing,
but also perhaps a bad thing because it consumes RAM,
that can never be used by other processes.
While that memory is consumed,
even if the process didn't touch that memory for a long time,
how do you lose large pages?
In terms of a p i is the only way to use large pages by
applications is by using the mutual a lock function,
which is, as we know, is the closest one to the memory manager.
It has a flag called large page,
which you have to specify as part of the flags to this function and that in
fact requires a privilege called lock memory privilege,
which by default is not provided to any user or group.
And that's because you're acquiring memory which is directly from RAM.
And so you should have that privilege.
Otherwise you might end up using lots and lots of memory which could cripple
the system or at least make other processes fail certain allocations when you
make that kind of allocation using large pages,
the size and alignment must be multiple of a page size of
a large page size to be more precise.
So you can't allocate three megabytes of memory.
For example,
you have to allocate two megabytes or four megabytes or
anything that is a multiple of that size,
if you want to get that information dynamically,
you can call the function, get large page minimum,
which returns the large page size.
Now.
Today, it's always two megabytes of course,
but it could be different in earlier systems and
could change perhaps in the future.
Where are huge pages coming into the picture?
So huge pages are used today automatically.
If the thing you're trying to allocate has a size
which is larger than one gigabyte,
then the system will try to use huge pages if possible and fall
back to large pages for the rest of the memory.
So for example, if you want to allocate 1.2 gigabyte of memory,
then the one gigabyte will be allocated with a huge page.
If possible, that is,
if we can find a big enough chunk in physical memory and the rest
is going to be allocated using large pages.