From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0B611474B9 for ; Thu, 19 Dec 2024 04:06:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734581194; cv=none; b=igtWPkl0WF21g0tuAgPxcpFAz+/YhIrntJvYX+8A/julcNQV8CjP8iRc+UZJFl3n2uoKKBVH09CDnhLKS+S+zhwUuB4aaRrTXdORzy3G2vXYGE0TfUlIZdNBTv0NctJRpfUZfR1/lroG2weJSyqePM135wEqkbPn600b1TDHS3I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734581194; c=relaxed/simple; bh=pw62i09HpIW46wtTBRxpC7uQMwudeu516JHR9u/cv3o=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=UlXzk/u6O0EcJqUQwZy3ryoMqn95Cg3sR4HzHRX4F1BNlaXTxeECdydSCT5SjW7+fmGk63d7m19Ow5aFvmogMVGyupKBLG4JVz+fKr2kVWJMOVZ7edcKv9raIvJifz/4dD3c8coH+RS0VjFkuRvqNkSG0IQYKVGHBcRFS7TbyM8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=J4B179Em; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="J4B179Em" Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4BJ3reeN020411; Thu, 19 Dec 2024 04:06:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= mAXUIEdbuEL+OPqhlwBDPcDmCaHOBBQunVwuJEZQsJw=; b=J4B179EmcQVDdYZJ gMQXEdWqsit2ohpcx0hZrMFG6z031gV2N3jslNurUfYyHFEfAYr2rN2Gr/EErE0m bKM75vKYA+doM0esqPh80jD9s84NpcS4i6drlDNGIGJQIlKouFygRK+pjRtDVjTc oIJ6d6L2h9YGxbUSYw95BGd+0yjQHvjMYHm4OG3P/FkBU4oKShis7QfFns0KytEe Oarsf/8Vi9XpUpqBejEprR/iG3PL+Jhv8slKri4XHmvpz0M3NlQHbnEB34FtAHEo e3jwZnz4QA7E9gK7uPtlUiHCwrpCBqQxPJ+vsh+FF6aPe/ngsw5N344dlYzgxQ/E XZDVyQ== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 43mbyxr0tf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 19 Dec 2024 04:06:12 +0000 (GMT) Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4BJ46Bbv027951 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 19 Dec 2024 04:06:11 GMT Received: from [10.239.132.245] (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 18 Dec 2024 20:06:09 -0800 Message-ID: <395cab19-e3b4-4581-9fe3-902e9b5d4ea7@quicinc.com> Date: Thu, 19 Dec 2024 12:06:07 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] lib/alloc_tag: Add accumulative call counter for memory allocation profiling To: David Wang <00107082@163.com>, Suren Baghdasaryan CC: , , , References: <20240913055729.7208-1-00107082@163.com> <710f85e7.a802.193d9d08d8a.Coremail.00107082@163.com> <2ff6b906.2743.193dcc1d53b.Coremail.00107082@163.com> Content-Language: en-US From: Zhenhua Huang In-Reply-To: <2ff6b906.2743.193dcc1d53b.Coremail.00107082@163.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: 2Bew7GXs8vB4Q0VtNgvT_SxoUrkQZjj3 X-Proofpoint-ORIG-GUID: 2Bew7GXs8vB4Q0VtNgvT_SxoUrkQZjj3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 malwarescore=0 adultscore=0 mlxscore=0 spamscore=0 priorityscore=1501 phishscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2412190028 On 2024/12/19 10:31, David Wang wrote: > HI, > At 2024-12-19 02:22:53, "Suren Baghdasaryan" wrote: >> On Wed, Dec 18, 2024 at 4:49 AM David Wang <00107082@163.com> wrote: >>> >>> Hi, >>> >>> I found another usage/benefit for accumulative counters: >>> >>> On my system, /proc/allocinfo yields about 5065 lines, of which 2/3 lines have accumulative counter *0*. >>> meaning no memory activities. (right?) >>> It is quite a waste to keep those items which are *not alive yet*. >>> With additional changes, only 1684 lines in /proc/allocinfo on my system: >>> >>> --- a/lib/alloc_tag.c >>> +++ b/lib/alloc_tag.c >>> @@ -95,8 +95,11 @@ static void alloc_tag_to_text(struct seq_buf *out, struct codetag *ct) >>> struct alloc_tag_counters counter = alloc_tag_read(tag); >>> s64 bytes = counter.bytes; >>> >>> + if (counter.accu_calls == 0) >>> + return; >>> seq_buf_printf(out, "%12lli %8llu ", bytes, counter.calls); >>> >>> >>> I think this is quite an improvement worth pursuing. >>> (counter.calls could also be used to filter out "inactive" items, but >>> lines keep disappearing/reappearing can confuse monitoring systems.) >> >> Please see discussion at >> https://lore.kernel.org/all/20241211085616.2471901-1-quic_zhenhuah@quicinc.com/ > > Thanks for the information. > >> My point is that with this change we lose information which can be >> useful. For example if I want to analyze all the places in the kernel >> where memory can be potentially allocated, your change would prevent >> me from doing that > > Maybe the filter can be disabled when DEBUG is on? > > > No, I disagree. Allocation that was never invoked is not the same as >> no allocation at all. How would we know the difference if we filter >> out the empty ones? > > Totally agree with this, I think (bytes || counter.calls) does not make good filter. Accumulative counter is the answer. :) hmm... it really depends on the use case IMHO. If memory consumption is a concern, using counter.calls should suffice. However, for performance-related scenarios as you stated, it's definitely better to use an accumulative counter." Both of these can't address Suren's comment: "if I want to analyze all the places in the kernel where memory can be potentially allocated, your change would prevent me from doing that", but. > >> If you don't want to see all the unused sites, you can filter them in >> the userspace. I also suspect that for practical purposes you would >> want to filter small ones (below some threshold) as well. > > I have setup monitoring tool polling /proc/allocinfo every 5 seconds on my system, > and it takes totally ~11ms and ~100 read syscalls just read out all the content in one round, > and with (counter.accu_calls == 0) filter, it takes totally ~4.4ms and 34 read syscalls. > it would be nice to have ~60% performance improvement.... > > > > Thanks > David