From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30590C3DA61 for ; Mon, 29 Jul 2024 05:16:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A8616B00A1; Mon, 29 Jul 2024 01:16:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 858546B00A2; Mon, 29 Jul 2024 01:16:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F9366B00A4; Mon, 29 Jul 2024 01:16:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4A9616B00A1 for ; Mon, 29 Jul 2024 01:16:15 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id AD60F80233 for ; Mon, 29 Jul 2024 05:16:14 +0000 (UTC) X-FDA: 82391629068.01.7BA403F Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) by imf18.hostedemail.com (Postfix) with ESMTP id 8133F1C0028 for ; Mon, 29 Jul 2024 05:16:11 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=mhhvB76n; spf=pass (imf18.hostedemail.com: domain of ying.huang@intel.com designates 198.175.65.21 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722230169; h=from:from:sender:reply-to:subject:subject: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:dkim-signature; bh=c7ykCrs/BDMjCxQhec6R51k2bg8NXANAIaaodTo9TzU=; b=24/n8yrP9pT1Na/8nAUR8B6t/lXHlCv/TT6/FQwXw4zEVzv4L0GGgOAgVscjAvWLrB+gNY 46r0glsPLpsGfKaDIBOs8ZFcJ7sGXJJKe0NxKobb6FZLuDIqyTDKt/FI78QM4EwH6Zjq3z Ik81DJujC8GRejeJIxh17hWMLKJuu9w= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=mhhvB76n; spf=pass (imf18.hostedemail.com: domain of ying.huang@intel.com designates 198.175.65.21 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722230169; a=rsa-sha256; cv=none; b=i/0x+aUByS8lNC1YCtS9nspSvJJcckFT8R7diKu6yssblp1WEpB4eCaXcPn8ooRgBG6NMo fsC6Gs84VYWjVICJcrSrkb0scXTnsbD2xT1ShZ60h7SJPT66wtNOAgUD+6rgECUuJew4ms OwGd8PSP3bPn+U55R3yi+CFvReRAinE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1722230172; x=1753766172; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version:content-transfer-encoding; bh=KGyc1O4NQoNgjTE+70m048lzAaINEct4zWDip0TFuzE=; b=mhhvB76nAzZ3H0kL2Ce8XzhlszQ1zdA8POHfbY5Zwh+v5HoHA9pZ4e4O XM1JA32Kzdn63xfRT1H+HgnuOtdF9bSpavTpoK0MAJsMVRLltzpMUTcqF uaHDEsvxf0/+ChW2aInx3rkw/7tgl+7nvs/9mGQ4n/rqNfnjh4mlfJAvY 30iySDhxO60U0HAL4gsBHp7K1aGu7f9iXKUghhdTh7m2pvE3FgIfX4iEX GECMJLQykIShmAQ7MajO3o0jgauSPd/cG60k573+V2F0L/3Q/Wu4qduNh Zr3SHUQB37eg1jcG3huVqH1Ui2bNbpiNZ7fuFE0rsT/ypTfQzjNc9x08I g==; X-CSE-ConnectionGUID: B5UJ45pYQA29SU5QG12/uw== X-CSE-MsgGUID: lyNlPaSGR8WbGzdxPDhcfQ== X-IronPort-AV: E=McAfee;i="6700,10204,11147"; a="19913975" X-IronPort-AV: E=Sophos;i="6.09,245,1716274800"; d="scan'208";a="19913975" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2024 22:16:10 -0700 X-CSE-ConnectionGUID: bhS/877ITtWDLdhnTI5TaA== X-CSE-MsgGUID: QyonfWtVTjSXysf//bL6dA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,245,1716274800"; d="scan'208";a="53801896" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2024 22:16:07 -0700 From: "Huang, Ying" To: Yafang Shao Cc: akpm@linux-foundation.org, mgorman@techsingularity.net, linux-mm@kvack.org, Matthew Wilcox , David Rientjes Subject: Re: [PATCH v2 3/3] mm/page_alloc: Introduce a new sysctl knob vm.pcp_batch_scale_max In-Reply-To: (Yafang Shao's message of "Mon, 29 Jul 2024 11:40:18 +0800") References: <20240729023532.1555-1-laoar.shao@gmail.com> <20240729023532.1555-4-laoar.shao@gmail.com> <878qxkyjfr.fsf@yhuang6-desk2.ccr.corp.intel.com> Date: Mon, 29 Jul 2024 13:12:34 +0800 Message-ID: <874j88ye65.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Stat-Signature: ct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kw8YjhBETD0r2YBXTgIk2m4kXOuEGeRIfRmnKEjfn9HdGXTB//cVnIBBGwAQPIw8kbQtnV8gNjtmP/H9h5y+HuMpcjT61WkyN7U41C8d0dME2VBAsY7AI0qqyAoWilrMLPnW5TffekFMOA8AW99LareXwzhcLRcZY+J5t36aQ+unn1ffkaD8PUBz0/tjhGS77esYdxuYGkHdQ5jIWYeYkISeGBYC7ZSp6HfyzBASlykTSaqJX0uPgaG9GGw61MEHKHUaYKCahCe/tEp5/BL109FDhDUTrtwc2w3Db4Vyz8n013dj2xk2tR5004cN3VTdWcPR8bnfHKadZEoTVo+046qHbJArDpy3U5lhrZyNvSYG++i4OA/Ow== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Yafang Shao writes: > On Mon, Jul 29, 2024 at 11:22=E2=80=AFAM Huang, Ying wrote: >> >> Hi, Yafang, >> >> Yafang Shao writes: >> >> > During my recent work to resolve latency spikes caused by zone->lock >> > contention[0], I found that CONFIG_PCP_BATCH_SCALE_MAX is difficult to= use >> > in practice. >> >> As we discussed before [1], I still feel confusing about the description >> about zone->lock contention. How about change the description to >> something like, > > Sure, I will change it. > >> >> Larger page allocation/freeing batch number may cause longer run time of >> code holding zone->lock. If zone->lock is heavily contended at the same >> time, latency spikes may occur even for casual page allocation/freeing. >> Although reducing the batch number cannot make zone->lock contended >> lighter, it can reduce the latency spikes effectively. >> >> [1] https://lore.kernel.org/linux-mm/87ttgv8hlz.fsf@yhuang6-desk2.ccr.co= rp.intel.com/ >> >> > To demonstrate this, I wrote a Python script: >> > >> > import mmap >> > >> > size =3D 6 * 1024**3 >> > >> > while True: >> > mm =3D mmap.mmap(-1, size) >> > mm[:] =3D b'\xff' * size >> > mm.close() >> > >> > Run this script 10 times in parallel and measure the allocation latenc= y by >> > measuring the duration of rmqueue_bulk() with the BCC tools >> > funclatency[1]: >> > >> > funclatency -T -i 600 rmqueue_bulk >> > >> > Here are the results for both AMD and Intel CPUs. >> > >> > AMD EPYC 7W83 64-Core Processor, single NUMA node, KVM virtual server >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> > >> > - Default value of 5 >> > >> > nsecs : count distribution >> > 0 -> 1 : 0 | = | >> > 2 -> 3 : 0 | = | >> > 4 -> 7 : 0 | = | >> > 8 -> 15 : 0 | = | >> > 16 -> 31 : 0 | = | >> > 32 -> 63 : 0 | = | >> > 64 -> 127 : 0 | = | >> > 128 -> 255 : 0 | = | >> > 256 -> 511 : 0 | = | >> > 512 -> 1023 : 12 | = | >> > 1024 -> 2047 : 9116 | = | >> > 2048 -> 4095 : 2004 | = | >> > 4096 -> 8191 : 2497 | = | >> > 8192 -> 16383 : 2127 | = | >> > 16384 -> 32767 : 2483 | = | >> > 32768 -> 65535 : 10102 | = | >> > 65536 -> 131071 : 212730 |******************* = | >> > 131072 -> 262143 : 314692 |***************************** = | >> > 262144 -> 524287 : 430058 |*********************************= *******| >> > 524288 -> 1048575 : 224032 |******************** = | >> > 1048576 -> 2097151 : 73567 |****** = | >> > 2097152 -> 4194303 : 17079 |* = | >> > 4194304 -> 8388607 : 3900 | = | >> > 8388608 -> 16777215 : 750 | = | >> > 16777216 -> 33554431 : 88 | = | >> > 33554432 -> 67108863 : 2 | = | >> > >> > avg =3D 449775 nsecs, total: 587066511229 nsecs, count: 1305242 >> > >> > The avg alloc latency can be 449us, and the max latency can be higher >> > than 30ms. >> > >> > - Value set to 0 >> > >> > nsecs : count distribution >> > 0 -> 1 : 0 | = | >> > 2 -> 3 : 0 | = | >> > 4 -> 7 : 0 | = | >> > 8 -> 15 : 0 | = | >> > 16 -> 31 : 0 | = | >> > 32 -> 63 : 0 | = | >> > 64 -> 127 : 0 | = | >> > 128 -> 255 : 0 | = | >> > 256 -> 511 : 0 | = | >> > 512 -> 1023 : 92 | = | >> > 1024 -> 2047 : 8594 | = | >> > 2048 -> 4095 : 2042818 |****** = | >> > 4096 -> 8191 : 8737624 |************************** = | >> > 8192 -> 16383 : 13147872 |*********************************= *******| >> > 16384 -> 32767 : 8799951 |************************** = | >> > 32768 -> 65535 : 2879715 |******** = | >> > 65536 -> 131071 : 659600 |** = | >> > 131072 -> 262143 : 204004 | = | >> > 262144 -> 524287 : 78246 | = | >> > 524288 -> 1048575 : 30800 | = | >> > 1048576 -> 2097151 : 12251 | = | >> > 2097152 -> 4194303 : 2950 | = | >> > 4194304 -> 8388607 : 78 | = | >> > >> > avg =3D 19359 nsecs, total: 708638369918 nsecs, count: 36604636 >> > >> > The avg was reduced significantly to 19us, and the max latency is redu= ced >> > to less than 8ms. >> > >> > - Conclusion >> > >> > On this AMD CPU, reducing vm.pcp_batch_scale_max significantly helps r= educe >> > latency. Latency-sensitive applications will benefit from this tuning. >> > >> > However, I don't have access to other types of AMD CPUs, so I was unab= le to >> > test it on different AMD models. >> > >> > Intel(R) Xeon(R) Platinum 8260 CPU @ 2.40GHz, two NUMA nodes >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> > >> > - Default value of 5 >> > >> > nsecs : count distribution >> > 0 -> 1 : 0 | = | >> > 2 -> 3 : 0 | = | >> > 4 -> 7 : 0 | = | >> > 8 -> 15 : 0 | = | >> > 16 -> 31 : 0 | = | >> > 32 -> 63 : 0 | = | >> > 64 -> 127 : 0 | = | >> > 128 -> 255 : 0 | = | >> > 256 -> 511 : 0 | = | >> > 512 -> 1023 : 2419 | = | >> > 1024 -> 2047 : 34499 |* = | >> > 2048 -> 4095 : 4272 | = | >> > 4096 -> 8191 : 9035 | = | >> > 8192 -> 16383 : 4374 | = | >> > 16384 -> 32767 : 2963 | = | >> > 32768 -> 65535 : 6407 | = | >> > 65536 -> 131071 : 884806 |*********************************= *******| >> > 131072 -> 262143 : 145931 |****** = | >> > 262144 -> 524287 : 13406 | = | >> > 524288 -> 1048575 : 1874 | = | >> > 1048576 -> 2097151 : 249 | = | >> > 2097152 -> 4194303 : 28 | = | >> > >> > avg =3D 96173 nsecs, total: 106778157925 nsecs, count: 1110263 >> > >> > - Conclusion >> > >> > This Intel CPU works fine with the default setting. >> > >> > Intel(R) Xeon(R) Platinum 8260 CPU @ 2.40GHz, single NUMA node >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> > >> > Using the cpuset cgroup, we can restrict the test script to run on NUMA >> > node 0 only. >> > >> > - Default value of 5 >> > >> > nsecs : count distribution >> > 0 -> 1 : 0 | = | >> > 2 -> 3 : 0 | = | >> > 4 -> 7 : 0 | = | >> > 8 -> 15 : 0 | = | >> > 16 -> 31 : 0 | = | >> > 32 -> 63 : 0 | = | >> > 64 -> 127 : 0 | = | >> > 128 -> 255 : 0 | = | >> > 256 -> 511 : 46 | = | >> > 512 -> 1023 : 695 | = | >> > 1024 -> 2047 : 19950 |* = | >> > 2048 -> 4095 : 1788 | = | >> > 4096 -> 8191 : 3392 | = | >> > 8192 -> 16383 : 2569 | = | >> > 16384 -> 32767 : 2619 | = | >> > 32768 -> 65535 : 3809 | = | >> > 65536 -> 131071 : 616182 |*********************************= *******| >> > 131072 -> 262143 : 295587 |******************* = | >> > 262144 -> 524287 : 75357 |**** = | >> > 524288 -> 1048575 : 15471 |* = | >> > 1048576 -> 2097151 : 2939 | = | >> > 2097152 -> 4194303 : 243 | = | >> > 4194304 -> 8388607 : 3 | = | >> > >> > avg =3D 144410 nsecs, total: 150281196195 nsecs, count: 1040651 >> > >> > The zone->lock contention becomes severe when there is only a single N= UMA >> > node. The average latency is approximately 144us, with the maximum >> > latency exceeding 4ms. >> > >> > - Value set to 0 >> > >> > nsecs : count distribution >> > 0 -> 1 : 0 | = | >> > 2 -> 3 : 0 | = | >> > 4 -> 7 : 0 | = | >> > 8 -> 15 : 0 | = | >> > 16 -> 31 : 0 | = | >> > 32 -> 63 : 0 | = | >> > 64 -> 127 : 0 | = | >> > 128 -> 255 : 0 | = | >> > 256 -> 511 : 24 | = | >> > 512 -> 1023 : 2686 | = | >> > 1024 -> 2047 : 10246 | = | >> > 2048 -> 4095 : 4061529 |********* = | >> > 4096 -> 8191 : 16894971 |*********************************= *******| >> > 8192 -> 16383 : 6279310 |************** = | >> > 16384 -> 32767 : 1658240 |*** = | >> > 32768 -> 65535 : 445760 |* = | >> > 65536 -> 131071 : 110817 | = | >> > 131072 -> 262143 : 20279 | = | >> > 262144 -> 524287 : 4176 | = | >> > 524288 -> 1048575 : 436 | = | >> > 1048576 -> 2097151 : 8 | = | >> > 2097152 -> 4194303 : 2 | = | >> > >> > avg =3D 8401 nsecs, total: 247739809022 nsecs, count: 29488508 >> > >> > After setting it to 0, the avg latency is reduced to around 8us, and t= he >> > max latency is less than 4ms. >> > >> > - Conclusion >> > >> > On this Intel CPU, this tuning doesn't help much. Latency-sensitive >> > applications work well with the default setting. >> > >> > It is worth noting that all the above data were tested using the upstr= eam >> > kernel. >> > >> > Why introduce a systl knob? >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D >> > >> > From the above data, it's clear that different CPU types have varying >> > allocation latencies concerning zone->lock contention. Typically, peop= le >> > don't release individual kernel packages for each type of x86_64 CPU. >> > >> > Furthermore, for latency-insensitive applications, we can keep the def= ault >> > setting for better throughput. In our production environment, we set t= his >> > value to 0 for applications running on Kubernetes servers while keepin= g it >> > at the default value of 5 for other applications like big data. It's n= ot >> > common to release individual kernel packages for each application. >> >> Thanks for detailed performance data! >> >> Is there any downside observed to set CONFIG_PCP_BATCH_SCALE_MAX to 0 in >> your environment? If not, I suggest to use 0 as default for >> CONFIG_PCP_BATCH_SCALE_MAX. Because we have clear evidence that >> CONFIG_PCP_BATCH_SCALE_MAX hurts latency for some workloads. After >> that, if someone found some other workloads need larger >> CONFIG_PCP_BATCH_SCALE_MAX, we can make it tunable dynamically. >> > > The decision doesn=E2=80=99t rest with us, the kernel team at our company. > It=E2=80=99s made by the system administrators who manage a large number = of > servers. The latency spikes only occur on the Kubernetes (k8s) > servers, not in other environments like big data servers. We have > informed other system administrators, such as those managing the big > data servers, about the latency spike issues, but they are unwilling > to make the change. > > No one wants to make changes unless there is evidence showing that the > old settings will negatively impact them. However, as you know, > latency is not a critical concern for big data; throughput is more > important. If we keep the current settings, we will have to release > different kernel packages for different environments, which is a > significant burden for us. Totally understand your requirements. And, I think that this is better to be resolved in your downstream kernel. If there are clear evidences to prove small batch number hurts throughput for some workloads, we can make the change in the upstream kernel. -- Best Regards, Huang, Ying