Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4407189pxy; Tue, 27 Apr 2021 04:28:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3KTVMRasRlKeifMJGk3amaPTxc/JzILPC10tySufIvu387fexxtvSTb/uhXl7VHq4rnEA X-Received: by 2002:a63:ad05:: with SMTP id g5mr4990253pgf.239.1619522926318; Tue, 27 Apr 2021 04:28:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619522926; cv=none; d=google.com; s=arc-20160816; b=yBrkl9OUXtUApH8bojB/MZB/8Pc+/X4uXS55y21lcm7La/5RBBOEUS2qYKi/Hf6wpL S/AiyRyTqi7VJ3wK1WA1i8MTXRDM5oNNj/Pd13+rZsLwbseM47/P0v2lWSxFvmS7Ckn4 Ut6EuqXGKe9ka3k7P8BwpSavFsFpDq1KXeY9WV6ZegpdGRQI1Ei4mcRQVHHTgt73QROI tUfZaC22ob8WFt4T0vW8yiYM3vzzRbeSmOa3J5nJemHtBYrCwzSxcBysPIYFm7Z/uPaW PPacX8xVczex0cUPcBMdFKSeuzQdS6ejMuJkKLf42SYXrgI0o2HfduDK+cVNDpOnpzXG XTaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=7jRpqar9SQV8YDRO6fEObuydnQktt3oGyEBIeNr8C2Y=; b=nLDxH0T2j/LpEIZaSPn7um1IEeSnen9rooOdZh3hXy579QWVh3OR2kQ6Xla4vjY82H /ErdTmie/zDcDX2f0NrmEfOWwZLoDZ2H3x3ntniGRzxrgvm2DLjxuIQExjitA/nqFnOn dCNWZMkZwY9GaHyMbPaA8f/eD5GXIrGyTNZ/JDjyoIe24pMVBCGuB/E4la8jEvyI4P+y xJakjlBLAWZNwk9aWjJTVnnM3Y8MI93SelyNh2WRluQwTUFFvHCVbo+WSuXbaUxYFON7 w6vGA/VUSqT0NDh18Syw30MDpd41VVuTG3h1zGiQTuEKq4dnM5VzJyLBooTKZSO5RDB6 Pl2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=uft5Bnsd; 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 c21si7931993plo.353.2021.04.27.04.28.33; Tue, 27 Apr 2021 04:28:46 -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=@infradead.org header.s=casper.20170209 header.b=uft5Bnsd; 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 S235831AbhD0L1a (ORCPT + 99 others); Tue, 27 Apr 2021 07:27:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235811AbhD0L1a (ORCPT ); Tue, 27 Apr 2021 07:27:30 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1B3AC061574 for ; Tue, 27 Apr 2021 04:26:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=7jRpqar9SQV8YDRO6fEObuydnQktt3oGyEBIeNr8C2Y=; b=uft5BnsdR+cxu63relHri/o/dC 1oydk+1v/Xa0mTUxScG5CEcyKOUSD3+QP7yjBdd4jYiTdp78lreavZPffw1BPuXiP+i/VcLV9LfMF rJiebDefsRamz8Ok/eVZSuzBiaIaauXGwOfzDcTc1+JduO5QRWaJPZeJYaSksb+fy5YRudomSa3By Xs8UcBfZPboxhyV1scpQn7icBKVSJ/nihbM/FAy6+ojmpvg3T0TUADPHGUYUOWaD7Uwr85GJnN9zm D+7jWZcNZJlFbn1XPB34u3ULf+nhnbd2QrQizfRw2MeUZ8VYsZXV37HRRjcGNgQkGQM+CCvZXvAeR /FAqr1LA==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lbLqJ-006qFz-SO; Tue, 27 Apr 2021 11:25:33 +0000 Date: Tue, 27 Apr 2021 12:25:27 +0100 From: Matthew Wilcox To: Xiongwei Song Cc: Xiongwei Song , cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, vbabka@suse.cz, linux-mm@kvack.org, Linux Kernel Mailing List Subject: Re: [PATCH] mm: append __GFP_COMP flag for trace_malloc Message-ID: <20210427112527.GX235567@casper.infradead.org> References: <1619491400-1904-1-git-send-email-sxwjean@me.com> <20210427025358.GV235567@casper.infradead.org> <20210427033632.GW235567@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 27, 2021 at 01:30:48PM +0800, Xiongwei Song wrote: > Hi Mattew, > > One more thing I should explain, the kmalloc_order() appends the > __GFP_COMP flags, > not by the caller. > > void *kmalloc_order(size_t size, gfp_t flags, unsigned int order) > { > ........................................................... > > flags |= __GFP_COMP; > page = alloc_pages(flags, order); > ........................................................... > return ret; > } > EXPORT_SYMBOL(kmalloc_order); > > #ifdef CONFIG_TRACING > void *kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order) > { > void *ret = kmalloc_order(size, flags, order); > trace_kmalloc(_RET_IP_, ret, size, PAGE_SIZE << order, flags); > return ret; > } > EXPORT_SYMBOL(kmalloc_order_trace); > #endif Yes, I understood that. What I don't understand is why appending the __GFP_COMP to the trace would have been less confusing for you. Suppose I have some code which calls: kmalloc(10 * 1024, GFP_ATOMIC|__GFP_NOWARN|__GFP_NOMEMALLOC); and I see in my logs 0.08% call_site=ffffffff851d0cb0 ptr=0xffff8c04a4ca0000 bytes_req=10176 bytes_alloc=16384 gfp_flags=GFP_ATOMIC|__GFP_NOWARN|__GFP_NOMEMALLOC|__GFP_COMP That seems to me _more_ confusing because I would wonder "Where did that __GFP_COMP come from?" > > Regards, > Xiongwei > > On Tue, Apr 27, 2021 at 12:11 PM Xiongwei Song wrote: > > > > On Tue, Apr 27, 2021 at 11:36 AM Matthew Wilcox wrote: > > > > > > On Tue, Apr 27, 2021 at 11:29:32AM +0800, Xiongwei Song wrote: > > > > On Tue, Apr 27, 2021 at 10:54 AM Matthew Wilcox wrote: > > > > > > > > > > On Tue, Apr 27, 2021 at 10:43:20AM +0800, Xiongwei Song wrote: > > > > > > From: Xiongwei Song > > > > > > > > > > > > When calling kmalloc_order, the flags should include __GFP_COMP here, > > > > > > so that trace_malloc can trace the precise flags. > > > > > > > > > > I suppose that depends on your point of view. > > > > Correct. > > > > > > > > Should we report the > > > > > flags used by the caller, or the flags that we used to allocate memory? > > > > > And why does it matter? > > > > When I capture kmem:kmalloc events on my env with perf: > > > > (perf record -p my_pid -e kmem:kmalloc) > > > > I got the result below: > > > > 0.08% call_site=ffffffff851d0cb0 ptr=0xffff8c04a4ca0000 > > > > bytes_req=10176 bytes_alloc=16384 > > > > gfp_flags=GFP_ATOMIC|__GFP_NOWARN|__GFP_NOMEMALLOC > > > > > > Hmm ... if you have a lot of allocations about this size, that would > > > argue in favour of adding a kmem_cache of 10880 [*] bytes. That way, > > > we'd get 3 allocations per 32kB instead of 2. > > I understand you. But I don't think our process needs this size. This size > > may be a bug in our code or somewhere, I don't know the RC for now. > > > > > [*] 32768 / 3, rounded down to a 64 byte cacheline > > > > > > But I don't understand why this confused you. Your caller at > > > ffffffff851d0cb0 didn't specify __GFP_COMP. I'd be more confused if > > > this did report __GFP_COMP. > > > > > I just wanted to save some time when debugging. > > > > Regards