Re: Memory is not becoming available even after freeing it.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Apr 15, 2010 at 11:26 AM, Vikash Kumar <vikashskumar@xxxxxxxxx> wrote:
> On Wed, Apr 14, 2010 at 9:09 PM, Manish Regmi <regmi.manish@xxxxxxxxx> wrote:
>> On Wed, Apr 14, 2010 at 10:18 AM, Manish Katiyar <mkatiyar@xxxxxxxxx> wrote:
>>> On Wed, Apr 14, 2010 at 8:04 PM, Vikash Kumar <vikashskumar@xxxxxxxxx> wrote:
>>>> Hi everyone,
>>>>
>>>> I am writing a simple memory manager for my application which will
>>>> free any excess memory being used by my modules, so that it's
>>>> available again for use. My modules allocate memory using alloc_page &
>>>> kmem_cache_alloc and so the memory manager uses put_page &
>>>> kmem_cache_free respectively to free up the memory which is not in
>>>> use.
>>>>
>>>> The problem I am facing is, even after I free the memory using
>>>> put_page & kmem_cache_free, my modules are not able to get the free
>>>> memory. I have written a test code which allocates a lot of memory in
>>>> loop and when out of memory sleeps on memory manager to free up the
>>>> memory. Memory manager successfully executes free code and wakes up
>>>> the sleeping process as memory should be available now. Interestingly
>>>> the alloc_page /  kmem_cache_alloc calls still fail to allocate
>>>> memory. Now, I am clueless why it is happening so seeking help.
>>>
>>> Random guess... Are you sure it is still free between your free and
>>> allocate. ie.. no one else comes in between takes away your memory ?
>
> Yes I am sure that no one else comes in to take away the freed memory.
> As it is a closed system and only consumers of memory present in the
> system are my modules, which are executing in a controlled environment
> for testing purpose.
>
>>>
>>> Thanks -
>>> Manish
>>>
>>>
>>
>> Slab allocator does not just free the pages when u call
>> kmem_cache_free. It has a list of empty, partial and full slabs. So if
>> yo free it will just be in free list. have you called
>> kmem_cache_destroy to destroy the whole cache?
>> correct me if i am wrong here.
>>
>
> Well it's not just the slab allocator. The main memory is consumed
> using alloc_page and I keep invoking alloc_page until it fails. Slab
> allocator is only used to allocate data structure to serve as the
> container for these memory pages. When alloc_page fails I start
> freeing up memory using put_page. But even after freeing thousands of
> pages, any call to alloc_page still fails and that is the main
> problem.
>
> As far as slab allocator is concerned. I don't want to actually
> destroy them as I will need to allocate memory using them again. I was
> under impression that if system is low on memory then linux memory
> manager will trim the slab caches to make some memory available
> anyway. Now I am not at all sure how linux memory management is
> working as I don't seem to get any free memory at all.
>
>
>>
>> ---------------------------------------------------------------
>> regards
>> Manish Regmi
>>
>> http://manish-cs.blogspot.com
>> http://ext2read.sf.net
>>
>
> Regards,
> Vikash Kumar
> http://VikashKumar.com
>

I figured out the problem, it was with the API I was using. If I use
__free_page instead of put_page to free the memory pages, everything
works absolutely fine.

That brings another question on when and why "put_page" is used. I can
guess it has some thing to do with swap memory as it is defined in
mm/swap.c and my system is an embedded system without any swap memory
support.

Thanks everyone.

Regards,
Vikash

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux