NetBSD-Users archive

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

Re: jemalloc SEGV problem



Hi,
I checked the implementation i found the line because of which this
problem is noticed.

        /*
         * No usable runs.  Create a new chunk from which to allocate the run.
         */
1.        chunk = arena_chunk_alloc(arena);
2.       if (chunk == NULL)
3.                return (NULL);
4.        run = (arena_run_t *)((uintptr_t)chunk + (arena_chunk_header_npages <<
            pagesize_2pow));

In the above code see the line no 4 where 'run' is calculated , i
think its doing some alignment of
the memory allocated i am not sure, if i change the line number '4' as below:

        run = (arena_run_t *)((uintptr_t)chunk + (arena_chunk_header_npages <<
            19));

If i change the pagesize_2pow to 19 it works fine.

Since in my environment pagesize_2pow is calculated as value 11.

I changed only one line in the code rest all is same. The above line
appears in arena_run_alloc() function.

Could you please tell me what is the line.no 4 trying to do??

Thanks in Advance,
Channa
2008/11/18 Channa <channa.kad%gmail.com@localhost>:
> Hi,
> mmap does not fail.
> mamap does allocate memory for the variable "chunk"
>
> and then when the program tries to modify "chunk"  SEGV is recieved.
>
> I checked the problem is below:
> The variable
> 'pagesize_2pow' is calculated as
>
>                result = sysconf(_SC_PAGESIZE);
>                assert(result != -1);
>                pagesize = (unsigned) result;
>
>                /*
>                 * We assume that pagesize is a power of 2 when calculating
>                 * pagesize_mask and pagesize_2pow.
>                 */
>                assert(((result - 1) & result) == 0);
>                pagesize_mask = result - 1;
>                pagesize_2pow = ffs((int)result) - 1;
>
> In my case case pagesize_2pow comes as 11.
>
> Since sysconf(_SC_PAGESIZE) returns 4096.
>
> If i retain the macro value CHUNK_2POW_DEFAULT as 20 and initialize
>  pagesize_2pow = 19
>  which means my pagesize is 2^20..
>
> jemalloc() works fine , does not give any SEGV.
>
> In anycase mamp () is not failing.
> I feel the problem is with the alignment of the memory which is not happening
> properly..
> Also i checked none of the variables are overflowing.
>
> Thanks & Regards,
> Channa
>
>
>
>
> 2008/11/17 Christos Zoulas <christos%zoulas.com@localhost>:
>> On Nov 17, 12:42pm, channa.kad%gmail.com@localhost (Channa) wrote:
>> -- Subject: Re: jemalloc SEGV problem
>>
>> | Hi,
>> | Ya i understand but when i changed the pagesize to 64K in mips arch
>> |  and retained the macro CHUNK_2POW_DEFAULT as present in jemalloc.c
>> | original file.I dint get any seg fault.
>> |
>> | But when i changed the pagesize again to 4K i got SEGV.
>> |
>> | Regards,
>> | Channa
>>
>> What does the ktrace of your program show? Does the mmap fail?
>>
>> christos
>>
>


Home | Main Index | Thread Index | Old Index