Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3977794pxb; Tue, 2 Nov 2021 01:46:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1zN+mL01CN58a5J6Kh8vDVvQ9xBOqGAJNcI2G0aDDB01zFFSoU8yFp8S1rusnhC3Vw1WB X-Received: by 2002:a17:907:1614:: with SMTP id hb20mr26811118ejc.299.1635842777293; Tue, 02 Nov 2021 01:46:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635842777; cv=none; d=google.com; s=arc-20160816; b=J1+Crlkz1sCNQIujp5SSYR+obQf2BjvIGMUUFrgYvQlKm8JtrduIGwRa5qRhGTUcGe IvNZC/8gruQ3qnwcqSxxkW0TbvIHxUezvCWH9dgiHY/bmpnQjmK4FE124oK1AxBat+Ng BEw94Tnx+2WFBpxkKYzaK5V0rQ0rpKb3vdgHa93w2y4RhjgawUAokV2CNp/LwMf2gQuH vFACJl4aLi+Z9iU27GAWxDw/JimUCvtSHqduuLGwLrYfjekHzmKutOTlTrpZsYQviEur 0tj/9pregDS7mXz8Mz9leg1AO+JKGfWVZJqwG8A8ssVKhmjO07M+jV/fek6R9+LDyLeF wDFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=tz+vql88CgsF58vdIu35HL5zvxpH8YjJc4+0TvPpKZU=; b=kkQ03wUyQ9DdBy8iTDSpe9Sh5K8W5s8NVE7oEiq4YNJ/Mi228queFQbgrnYQOwI6gS YRcTTfudKFLZM5m1PtSF/rAiLfwLHwDh2xWEiya0kaX2k4vptcvj7WY+M2Caqg0P5K/h z8CtYJKAnRhBGqTFd5URRziS6didYIVwTlWmwmm1LxWVSmbn7OXw54KIJs/oNjxXWScH 48EKejJBgARb16H1xyfWk4s8m6T2yh8SWfUP8b6qrOjKyjJnoTzJFSXdeZpjtIP9JLA5 h5PxLqWPoGX+wqJcZ+bZU8LagRS6fzSduwHSSgDwxtrLwDM7NvIRHOUfjZEi0o94Dl9r IMhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=H9YxqWEu; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b="XT0uu/od"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i20si22271993ejd.100.2021.11.02.01.45.49; Tue, 02 Nov 2021 01:46:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=H9YxqWEu; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b="XT0uu/od"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230465AbhKBIo0 (ORCPT + 99 others); Tue, 2 Nov 2021 04:44:26 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:50734 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230000AbhKBIoZ (ORCPT ); Tue, 2 Nov 2021 04:44:25 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 7AD221FD78; Tue, 2 Nov 2021 08:41:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1635842510; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tz+vql88CgsF58vdIu35HL5zvxpH8YjJc4+0TvPpKZU=; b=H9YxqWEuNTYd76rLiYI4L2XWYeZpjWLmlKrUXU9juLdw0BiHN+rc/+2tqDR7Fy5Se8CEEs ckR+mYMKzMouG8AAdyCrXUQoGApmouZx3jOViMTAaaiQMvr3zWWYVivsmtKHsdKeJZ1O04 jEhFZ/seHwuQ3OclEt90swpZcmneaXo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1635842510; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tz+vql88CgsF58vdIu35HL5zvxpH8YjJc4+0TvPpKZU=; b=XT0uu/odAQtZWNn7poivWN7ZKPovW+GJIMttnv1upl52cpOvfSU2FT1dMPk/YkdsZKcob2 eB4XzNx8FV47N/DQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4EC1013B16; Tue, 2 Nov 2021 08:41:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id HgZZEs75gGEFawAAMHmgww (envelope-from ); Tue, 02 Nov 2021 08:41:50 +0000 Message-ID: Date: Tue, 2 Nov 2021 09:41:50 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 Subject: Re: [PATCH] mm, slub: place the trace before freeing memory in kmem_cache_free() Content-Language: en-US To: John Hubbard , Yunfeng Ye , cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: wuxu.wu@huawei.com, Hewenliang References: <867f6da4-6d38-6435-3fbb-a2a3744029f1@huawei.com> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Vlastimil Babka