[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: __cache_alloc (solved)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Tuesday 03 August 2004 12:30, Borislav Petkov wrote:
> Hi there again,
>
> I've been trying to understand what's going on here but I'm not sure:
>
> <mm/slab.c>
> 2047 static inline void * __cache_alloc (kmem_cache_t *cachep, int flags)
> 2048 {
> 2049 unsigned long save_flags;
> 2050 void* objp;
> 2051 struct array_cache *ac;
> 2052
> 2053 cache_alloc_debugcheck_before(cachep, flags);
> 2054
> 2055 local_irq_save(save_flags);
> 2056 ac = ac_data(cachep);
> 2057 if (likely(ac->avail)) {
> 2058 STATS_INC_ALLOCHIT(cachep);
> 2059 ac->touched = 1;
> 2060 objp = ac_entry(ac)[--ac->avail];
> 2061 } else {
> 2062 STATS_INC_ALLOCMISS(cachep);
> 2063 objp = cache_alloc_refill(cachep, flags);
> 2064 }
> 2065 local_irq_restore(save_flags);
> 2066 objp = cache_alloc_debugcheck_after(cachep, flags, objp,
> __builtin_return_address(0));
> 2067 return objp;
> 2068 }
>
> What puzzles me is line 2060: ac_entry(ac) returns (void **)(ac+1), which,
> if I see it correctly, returns a pointer to the next array_cache struct in
> the per CPU *array in the kmem_cache_t struct. But what exactly do the
> array subscript brackets after it do and an object pointer of what kind
> gets written in objp? --ac->avail decrements the count of available slab
> objects in the cache but (ac+1)[--ac->avail] returns the ac->touched of the
> previous array_cache struct which has just been set to 1 in the previous
> line. hmm, mighty strange ?!
>
> Thanks in advance,
> Boris.
Well, here's the deal:
ac_entry(ac) simply skips the array_cache structure - it returns a pointer to
the object behind the array_cache, which is the first slab object in the
particular slab cache array (ac+1 == sizeof(struct array_cache)) since all
the slab objects are located after the array_cache struct. By being saved
"onslab", the array_cache struct manages the particular cache of objects
(more easily?) At least accesses can be speeded up.
Anyhow, thanks for not answering and making me dig deeper in the books, :)
Boris.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
iD8DBQFBEJUUiBySr3Fn37QRAlK2AJ9QiMjsS5SNW10m9D7N4hHLxig92ACeOj5i
zIYevPUTsJcevBG0f2yicHk=
=rlTC
-----END PGP SIGNATURE-----
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/