linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: John Hubbard <jhubbard@nvidia.com>,
	Yunfeng Ye <yeyunfeng@huawei.com>,
	cl@linux.com, penberg@kernel.org, rientjes@google.com,
	iamjoonsoo.kim@lge.com, Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: wuxu.wu@huawei.com, Hewenliang <hewenliang4@huawei.com>
Subject: Re: [PATCH] mm, slub: place the trace before freeing memory in kmem_cache_free()
Date: Tue, 2 Nov 2021 09:41:50 +0100	[thread overview]
Message-ID: <b3843ab5-a2d9-fc12-6ed9-4646c3c6fdd7@suse.cz> (raw)
In-Reply-To: <df216633-cc14-6c3b-29ed-cdce136402eb@nvidia.com>

On 11/2/21 08:03, John Hubbard wrote:
> On 10/30/21 03:11, Yunfeng Ye wrote:
>> After the memory is freed, it may be allocated by other CPUs and has
>> been recorded by trace. So the timing sequence of the memory tracing is
>> inaccurate.
>>
>> For example, we expect the following timing sequeuce:
>>
>>      CPU 0                 CPU 1
>>
>>    (1) alloc xxxxxx
>>    (2) free  xxxxxx
>>                           (3) alloc xxxxxx
>>                           (4) free  xxxxxx
>>
>> However, the following timing sequence may occur:
>>
>>      CPU 0                 CPU 1
>>
>>    (1) alloc xxxxxx
>>                           (2) alloc xxxxxx
>>    (3) free  xxxxxx
>>                           (4) free  xxxxxx
>>
>> So place the trace before freeing memory in kmem_cache_free().
> 
> Hi Yunfeng,
> 
> Like Muchun, I had some difficulty with the above description, but
> now I think I get it. :)
> 
> In order to make it easier for others, how about this wording and subject
> line, instead:
> 
> 
> mm, slub: emit the "free" trace report before freeing memory in
> kmem_cache_free()
> 
> After the memory is freed, it can be immediately allocated by other
> CPUs, before the "free" trace report has been emitted. This causes
> inaccurate traces.
> 
> For example, if the following sequence of events occurs:
> 
>     CPU 0                 CPU 1
> 
>   (1) alloc xxxxxx
>   (2) free  xxxxxx
>                          (3) alloc xxxxxx
>                          (4) free  xxxxxx
> 
> ...then they will be inaccurately reported via tracing, so that they
> appear to have happened in this order. This makes it look like CPU 1
> somehow managed to allocate mmemory that CPU 0 still had allocated for
> itself:
> 
>     CPU 0                 CPU 1
> 
>   (1) alloc xxxxxx
>                          (2) alloc xxxxxx
>   (3) free  xxxxxx
>                          (4) free  xxxxxx
> 
> In order to avoid this, emit the "free xxxxxx" tracing report just
> before the actual call to free the memory, instead of just after it.

Agree, this wording is better.
IIRC the same problem was fixed for mmap_lock trace ordering just recently.

>> Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>

Reviewed-by: Vlastimil Babka <vbabka@suse.cz>


  reply	other threads:[~2021-11-02  8:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-30 10:11 Yunfeng Ye
2021-10-30 12:23 ` Muchun Song
2021-10-31 12:54   ` Matthew Wilcox
2021-11-02  7:03 ` John Hubbard
2021-11-02  8:41   ` Vlastimil Babka [this message]
2021-11-02  9:06   ` Yunfeng Ye

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b3843ab5-a2d9-fc12-6ed9-4646c3c6fdd7@suse.cz \
    --to=vbabka@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=hewenliang4@huawei.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=jhubbard@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=wuxu.wu@huawei.com \
    --cc=yeyunfeng@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox