Re: Kernel malloc/realloc?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: G. (na_at_na.na)
Date: 02/06/04


Date: Fri, 6 Feb 2004 16:55:08 +0200

Let's try to be as technical as possible.
In kernel mode (driver) how you do this:

1. Allocate a bunch of pf phisical pages
2. Map them to some VA, continguosly
3. Clear the VA mapping, but not free the phisical pages
4. Alocate more phisical pages
5. Continguosly in VA map the pages allocated from step 1 & 4
6. Destroy the VM mapping.
7. Free the phisical pages.

"Doron Holan [MS]" <doronh@nospam.microsoft.com> wrote in message
news:OfEw6bH7DHA.2168@TK2MSFTNGP12.phx.gbl...
> depends on the application for how to do the resize, but i would either
keep
> a reference count of all the threads who want access or perform all access
> under a lock (like a spinlock) which guarantees only one user of the
buffer
> at once. one reason realloc does not exist is that VA space is limited
and
> more often then not, the same pointer cannot be returned so this is
> functionally the same as free/alloc anyways.
>
> d
>
> --
> This posting is provided "AS IS" with no warranties, and confers no
rights.
> Please reply to newsgroups only.
>
> "G." <na@na.na> wrote in message
> news:OrhiLZG7DHA.3880@tk2msftngp13.phx.gbl...
> > Still, how do you perform the acctual resize?
> > Any reasons as to why there isn't a direct function in kernel to do
this?
> >
> > "Doron Holan [MS]" <doronh@nospam.microsoft.com> wrote in message
> > news:OVwTEKG7DHA.3880@tk2msftngp13.phx.gbl...
> > > maloc/ExAllocatePoolWithTag has a much higher likelyhood of failure in
> the
> > > kernel then in user mode. so, yes, as such you need to guard against
> NULL
> > > being returned as well w/out a doubt. But there is a difference
between
> a
> > > NULL check and making sure all current users of valid pool are not
> > touching
> > > memory when you decide to grow the allocation.
> > >
> > > d
> > >
> > > --
> > > This posting is provided "AS IS" with no warranties, and confers no
> > rights.
> > > Please reply to newsgroups only.
> > >
> > > "Bogdan Bejan" <na@na.na> wrote in message
> > > news:e0oirm%236DHA.2404@TK2MSFTNGP12.phx.gbl...
> > > >
> > > > "Doron Holan [MS]" <doronh@nospam.microsoft.com> wrote in message
> > > > news:u7ysgH66DHA.4012@tk2msftngp13.phx.gbl...
> > > > > one of the semantics of realloc is that the same pointer as before
> can
> > > be
> > > > > returned (i haven't used realloc in such a long time, i can't
> remember
> > > if
> > > > > this true 100% of the time or not).
> > > >
> > > > Any for of realocation of a memory buffer can't possible guarantee
to
> > > return
> > > > the same adress, what if you don't have enought linear virtual
memory
> > > there
> > > > to fulfill the request?
> > > >
> > > > So this applayes to maloc or any other function, i think.
> > > >
> > > > > Based on this assumption if you were to
> > > > > resize a buffer, you would need to
> > > > > 1) make sure any threads that are using the previous buffer have
> > > stopped
> > > > > using it
> > > > > 2) update the field which contains the pointer value so that no
one
> > > picks
> > > > > up the old value and starts using the new one
> > > >
> > > > I really know this.
> > > > I just don't know how to acctualy resize a memory buffer in kernel
> mode.
> > > >
> > > > >
> > > > > d
> > > > >
> > > > > --
> > > > > This posting is provided "AS IS" with no warranties, and confers
no
> > > > rights.
> > > > > Please reply to newsgroups only.
> > > > >
> > > > > "Bogdan Bejan" <na@na.na> wrote in message
> > > > > news:ufvFlI36DHA.2952@TK2MSFTNGP09.phx.gbl...
> > > > > > I wasn't sure is shuch API exists in kernel, thanx for clearing
> it.
> > > > > >
> > > > > > "Doron Holan [MS]" <doronh@nospam.microsoft.com> wrote in
message
> > > > > > news:uocOjcs6DHA.1556@tk2msftngp13.phx.gbl...
> > > > > > > no such API exists. you must be able to update the pointer
> value
> > > > > > atomically
> > > > > > > if you need to have a bigger allocation
> > > > > >
> > > > > > Don't you have to update the pointer with realloc to? Isn't
> realloc
> > > > based
> > > > > on
> > > > > > GlobalRealloc?Which i suppose works by allocating more hardware
> > pages
> > > > and
> > > > > > mapping them in a new vitual location, where you have enough
> virtual
> > > > space
> > > > > > for the new buffer?
> > > > > >
> > > > > > >
> > > > > > > d
> > > > > > >
> > > > > > > --
> > > > > > > This posting is provided "AS IS" with no warranties, and
confers
> > no
> > > > > > rights.
> > > > > > > Please reply to newsgroups only.
> > > > > > >
> > > > > > > "Bogdan Bejan" <na@na.na> wrote in message
> > > > > > > news:euNZM9r6DHA.2764@TK2MSFTNGP09.phx.gbl...
> > > > > > > > How can you alocate then realocate a memory buffer in kernel
> > mode
> > > > > (W2k+)
> > > > > > ?
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Relevant Pages

  • RE: SHIP_BUILD is slowing down the ethernet
    ... The performance difference between CE 3.0 and the new OS releases might be ... caused by the default setting of IMGNOTALLKMODE. ... In CE 3.0, Kernel Mode ... This posting is provided "AS IS" with no warranties, and confers no rights. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: find PDO of hid collection
    ... This posting is provided "AS IS" with no warranties, and confers no rights. ... > How to find PDO of gampad collection in kernel mode? ...
    (microsoft.public.development.device.drivers)