* An variable used before init
@ 2023-11-11 15:42 geng sun
2023-11-13 1:35 ` Xiongwei Song
0 siblings, 1 reply; 3+ messages in thread
From: geng sun @ 2023-11-11 15:42 UTC (permalink / raw)
To: linux-mm
[-- Attachment #1: Type: text/plain, Size: 1068 bytes --]
Hi linux-mm
I find one odd variable “new” in slub, it was used before init.
Maybe the value in new was undefined.
And I can not understand how it work.
Could you explain this code for me?
Thanks.
Best regards.
static void __slab_free(struct kmem_cache *s, struct page *page,
void *head, void *tail, int cnt,
unsigned long addr)
{
void *prior;
int was_frozen;
struct page new;
unsigned long counters;
struct kmem_cache_node *n = NULL;
unsigned long flags;
stat(s, FREE_SLOWPATH);
if (kmem_cache_debug(s) &&
!free_debug_processing(s, page, head, tail, cnt, addr))
return;
do {
if (unlikely(n)) {
spin_unlock_irqrestore(&n->list_lock, flags);
n = NULL;
}
prior = page->freelist;
counters = page->counters;
set_freepointer(s, tail, prior);
new.counters = counters;
was_frozen = new.frozen;
new.inuse -= cnt;
if ((!new.inuse || !prior) && !was_frozen) {
[-- Attachment #2: Type: text/html, Size: 7902 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: An variable used before init
2023-11-11 15:42 An variable used before init geng sun
@ 2023-11-13 1:35 ` Xiongwei Song
2023-11-13 8:55 ` geng sun
0 siblings, 1 reply; 3+ messages in thread
From: Xiongwei Song @ 2023-11-13 1:35 UTC (permalink / raw)
To: geng sun; +Cc: linux-mm
Hi,
You can see the definition of struct slab, the counters uses same space
with inuse, objects and frozen because they are in a union. So when
counters gets a value, the other 3 members also get a value.
struct slab {
......snip......
union {
unsigned long counters;
struct {
unsigned inuse:16;
unsigned objects:15;
unsigned frozen:1;
};
};
......snip......
}
Regards,
Xiongwei
On Sun, Nov 12, 2023 at 5:55 AM geng sun <sun.gengeration.sun@gmail.com> wrote:
>
> Hi linux-mm
>
> I find one odd variable “new” in slub, it was used before init.
> Maybe the value in new was undefined.
> And I can not understand how it work.
> Could you explain this code for me?
> Thanks.
>
> Best regards.
> static void __slab_free(struct kmem_cache *s, struct page *page,
> void *head, void *tail, int cnt,
> unsigned long addr)
>
> {
> void *prior;
> int was_frozen;
> struct page new;
> unsigned long counters;
> struct kmem_cache_node *n = NULL;
> unsigned long flags;
> stat(s, FREE_SLOWPATH);
> if (kmem_cache_debug(s) &&
> !free_debug_processing(s, page, head, tail, cnt, addr))
> return;
>
> do {
> if (unlikely(n)) {
> spin_unlock_irqrestore(&n->list_lock, flags);
> n = NULL;
> }
> prior = page->freelist;
> counters = page->counters;
> set_freepointer(s, tail, prior);
> new.counters = counters;
> was_frozen = new.frozen;
> new.inuse -= cnt;
> if ((!new.inuse || !prior) && !was_frozen) {
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: An variable used before init
2023-11-13 1:35 ` Xiongwei Song
@ 2023-11-13 8:55 ` geng sun
0 siblings, 0 replies; 3+ messages in thread
From: geng sun @ 2023-11-13 8:55 UTC (permalink / raw)
To: Xiongwei Song; +Cc: linux-mm
[-- Attachment #1: Type: text/plain, Size: 2078 bytes --]
Thank you for your explanation. Iunderstand. Thank you very much.
> On Nov 13, 2023, at 09:36, Xiongwei Song <sxwjean@gmail.com> wrote:
>
> Hi,
>
> You can see the definition of struct slab, the counters uses same space
> with inuse, objects and frozen because they are in a union. So when
> counters gets a value, the other 3 members also get a value.
>
> struct slab {
> ......snip......
> union {
> unsigned long counters;
> struct {
> unsigned inuse:16;
> unsigned objects:15;
> unsigned frozen:1;
> };
> };
> ......snip......
> }
>
> Regards,
> Xiongwei
>
>> On Sun, Nov 12, 2023 at 5:55 AM geng sun <sun.gengeration.sun@gmail.com> wrote:
>>
>> Hi linux-mm
>>
>> I find one odd variable “new” in slub, it was used before init.
>> Maybe the value in new was undefined.
>> And I can not understand how it work.
>> Could you explain this code for me?
>> Thanks.
>>
>> Best regards.
>> static void __slab_free(struct kmem_cache *s, struct page *page,
>> void *head, void *tail, int cnt,
>> unsigned long addr)
>>
>> {
>> void *prior;
>> int was_frozen;
>> struct page new;
>> unsigned long counters;
>> struct kmem_cache_node *n = NULL;
>> unsigned long flags;
>> stat(s, FREE_SLOWPATH);
>> if (kmem_cache_debug(s) &&
>> !free_debug_processing(s, page, head, tail, cnt, addr))
>> return;
>>
>> do {
>> if (unlikely(n)) {
>> spin_unlock_irqrestore(&n->list_lock, flags);
>> n = NULL;
>> }
>> prior = page->freelist;
>> counters = page->counters;
>> set_freepointer(s, tail, prior);
>> new.counters = counters;
>> was_frozen = new.frozen;
>> new.inuse -= cnt;
>> if ((!new.inuse || !prior) && !was_frozen) {
[-- Attachment #2: Type: text/html, Size: 10854 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-11-13 8:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-11 15:42 An variable used before init geng sun
2023-11-13 1:35 ` Xiongwei Song
2023-11-13 8:55 ` geng sun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox