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 78FDFC04FFE for ; Tue, 14 May 2024 09:20:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B7C6B6B0209; Tue, 14 May 2024 05:20:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B06846B024B; Tue, 14 May 2024 05:20:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 97F196B024C; Tue, 14 May 2024 05:20:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6F44F6B0209 for ; Tue, 14 May 2024 05:20:40 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id F1E621C0428 for ; Tue, 14 May 2024 09:20:39 +0000 (UTC) X-FDA: 82116456198.23.5004E61 Received: from mail-ua1-f54.google.com (mail-ua1-f54.google.com [209.85.222.54]) by imf16.hostedemail.com (Postfix) with ESMTP id 3749E180017 for ; Tue, 14 May 2024 09:20:38 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AntUuofW; spf=pass (imf16.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.222.54 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715678438; 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=YHZud2DTi9bi3QrcfxinnJ00QHHrboW9dHQ02Mh7sD8=; b=z2LT3HRBjhf1mo9cn1GTKAE6CaqocYuuIc1s5u+Utut01dW/1j1/yw7pyXBoM+4L8znzgb ZEG3h1K9l/1bIWIQK65MrXJ2T6g+4IF+WELPGZdwTR9f3pPuSPIXw9FGvqh190u2L2+a82 qF0l9qyTQ0UWoSh8iAK67DzIIwsB19Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715678438; a=rsa-sha256; cv=none; b=UFcqA/XK9fUDqc9bdPPmpKPv0f0LXKMlvEU8kdViCudkzwYegmsJaK1qsUqJ0FMyHEs3K1 1i1EPMwN7mwDg08PtTCR9mgJCxE6aCzpo9rySXjNFLBnv4Gr+toPC6SSlz+Mg+dsUsu5k0 5vnavOK5JRT8YKDJCpyk9Ds87RBvcdw= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AntUuofW; spf=pass (imf16.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.222.54 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ua1-f54.google.com with SMTP id a1e0cc1a2514c-7f16ec9798cso1228657241.3 for ; Tue, 14 May 2024 02:20:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715678437; x=1716283237; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=YHZud2DTi9bi3QrcfxinnJ00QHHrboW9dHQ02Mh7sD8=; b=AntUuofWzngtuAGgmj2AlttSpozhFvcNhg+1NLEZZhAXbRA8hXv0HV0nbM2RXTiOda /+XL9T6rL0JnD56hVS8v89Tyc31zFpvSuBoSmTdM058ZUzGJxDpMOydLqBaHhawtQWkG wlTlRgq7VussuX8jXoCXcMRG32c7GPj8XleyItT/bjScH5ac6IyHI6/yI0jCzEsnfg4O gbVp67zYFrKTiKIi6R0m6evymHc/Io4laj9CLSpdjrwoz16OVlYyr0LzEiylBdtetXhQ pSTmxYmzsbQy1PJCycxXUx7ZwO7QxIDe50dg0oq5RC8LelEHc5APUKPnMbo61KBA16bB J/vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715678437; x=1716283237; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YHZud2DTi9bi3QrcfxinnJ00QHHrboW9dHQ02Mh7sD8=; b=MQesGF8jYRw6QHRSv3PPMmY7hgUY/2rbKNHvdFsB1aaB0HSsMbdatrKhAETBrgt1i1 RgCJrZPA/nbOPRsG/fRPQal2Hor7mJIOo1XhM+lQkrZ3wN7TQ9yBCXPqoZkeP2TqkFkK YUeVUB4+9MIMVyev7MVYubV2DjqxHQnrdKFd7tJTyclHl9nnsKB1iRsMfZgY6pKCOD3W aLHrPaRXsvKH/OQWjJ89RRSK5OkUDxyxn3dfIZKy1aP3Bs7KcKod+yz/SjeV0Ypc9Ioq f9NyyckByPzvs2O/7zcouL1MHEkhyICe10Tc+mLavIyduLN+Q0hM+YQjRyd6I8OpNqDn l2ww== X-Forwarded-Encrypted: i=1; AJvYcCWLnBQaJGEViagm31SXx/oCkev0/mXpC3bERsZYcrWQlQDvrd2M2FmojQFjzSNwMvMPRBgjhQWHEv694XLYKDHG7iM= X-Gm-Message-State: AOJu0YyjA2703ISa2CWVEZpUtjNGVbAGiB+MxIVQ35YXwBc1R8Rb62NX sdN4glT36iNB53sSmsOGpsO/c1KeOgjWQwGpwBaUW6huyHxavp6pTsRIotggI/VkqoJvqCUQqvS 3eUUdm59QVVSLDpCUFP3+Np8TAVk= X-Google-Smtp-Source: AGHT+IF2rr74OwO4poZ4pM+HnnE0kyjQTTgjB7IKdmWLX+CPC4R+LXqGU1jwApaTuD3n/bhq+lm8l47w6WGXeNDdwC8= X-Received: by 2002:a05:6102:dcb:b0:47c:2d52:8c08 with SMTP id ada2fe7eead31-48077e16d27mr10156732137.17.1715678436817; Tue, 14 May 2024 02:20:36 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Barry Song <21cnbao@gmail.com> Date: Tue, 14 May 2024 21:20:25 +1200 Message-ID: Subject: Re: [LSF/MM/BPF TOPIC]mTHP reliable allocation and reclamation To: Yang Shi Cc: lsf-pc@lists.linux-foundation.org, Linux-MM Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Stat-Signature: 6f4uhzj3afdfcc4xj8n566q8i7ija6sf X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3749E180017 X-HE-Tag: 1715678438-741291 X-HE-Meta: U2FsdGVkX19XXRVd3iPggdj2iQ0df7UlPUEOuXD+tnCTscVPV+HgVzDyXvsmts+wrHom58KLUr91Kxka+Kgsjlh3CakIYPECjkw4ZAzzOX0db2+nGGO/s9GzKKnD8DDZWXhivCu7bMc8F8JtI0bUCz3r7dcgVDnWUfzHaMYCWBjhjj7z6tyQfL0+H53F2J7OcRnHxVoRxDYUCwXSrKo/93T0Vrp8R5H6ZD9i4Mwcs+8IKJEnpWReptHVjA1ynZY2PVLOfxyl3ua/yXB62MM7uOUVjeZqRlv0TX21hLi87tj1tZxOLGZG+dxcprzUKFDh9KWIOTLaC71AXUZ+A9rVT90sUwJME5dOAt9MNeLF7AyhNLtw7iVYRJr88vGp2fREKyiX/sQIaVbU/rWfH1KGlLNjlTQKMT7ZhKGMnJawwgYQkPmbtakmNtoA8iuGD6jCIDVdrGE0dcOe4DNrXVFps+WDCS46bsSJGMLwnS6OIFM26Epqb44KsClOsNaLgEOvpsTYtarOx6EgnrE3GJAeaNVZfBf//6lmyVVG07dccIyY6vVniWIT1y8Q/JRe34HBSaqWOUCNkxijx/PNNhmnYuhGPqz74MTIrNmA/EQvi8HHcfF9HvhstFXPw590o1zPZ038WkjEwhuF35EdEc7rkWxzWp2WEqPzSSwImcCrUOZgE1yZIhcAqhGnNtYKfh3GHVDySFbS+jWD4GH0pzyrfMNlp4gg1rasrPjPN8YUYQv60TGfkDSytoKKIfwnO37v/kUJ0jqGQRsDlsXgjm1e5vF7n54DZI/8jptYHKrU8pBmyjClcdhXfpo0M0ecVSudgJnHxU4vLsjyYjEHzdMgrzA6+oaPfkkUWZwahSPLTIQLiX5c/UlgwgZMydTY110sSjbupYzysJw9pFkp1cNwEzVMYbWWmtxkbfaLh9QsAbRiTn27uE62MKz61C9Mj3k4uGdF7vNQRuAnj4FRSpW 6JmZFgJo eW+1wiNLND3jFznbs8BBhXRePiWyRqA8TpHdhn+FT8uHQfGui3PDaiKUhNVdw+5vf1z8+oybJpjoiF/23h0CwUkZSALD9cp8xfWfN8EQJq3YWLhpiKYUtzSMkOGclmFL/Xx0rDa1pu4NQhzGr8WAkNXGDr7Jl3fsv7vZAQ5QJDRmwsHG0POgIDrOeRZC+ZArAfc6ZWasL8bLGYfkFKIXt6xa/R+FREyEIcmoT5Ns6fowb0T2xcOvNMuwzp0oqOoaA3VsBqLJLIwmV1mLDBdhkDI7qCSKeHgr0T6ph+0SJuLm331zYKdPovMTidXR4Vd1tq/UYfA625RgS63I7M+BqkljMOfmd4KxRsKX6cIuLnpNv/KDa8CBRuPfDnfNsou2N1BopL/1eZv9Ql6WDTrHliHvmYPwYIgk0p7LTh6LnDmHITNZ3bX1dnnjTX0CvVdEgm6yozDFpgUhssoneVw2/fQlcEhjbYQEEwouvozaobXarouWesKMgJFXKn5+l7qg/iREZ6cP2eHK4dCMCr3JdgrKFIG2qD4wf7nkgHduPLuCyoN/roPByhMT3req++X0hbLNoDy0M/sp5yeuD55Uh5i4PqNG2cImyvF+Z7/W68UZe8Jc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.114213, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Sat, May 11, 2024 at 9:18=E2=80=AFAM Yang Shi wrot= e: > > On Thu, May 9, 2024 at 7:22=E2=80=AFPM Barry Song <21cnbao@gmail.com> wro= te: > > > > Hi, > > > > I'd like to propose a session about the allocation and reclamation of > > mTHP. This is related to Yu Zhao's > > TAO[1] but not the same. > > > > OPPO has implemented mTHP-like large folios across thousands of > > genuine Android devices, utilizing > > ARM64 CONT-PTE. However, we've encountered challenges: > > > > - The allocation of mTHP isn't consistently reliable; even after > > prolonged use, obtaining large folios > > remains uncertain. > > As an instance, following a few hours of operation, the likelihood > > of successfully allocating large > > folios on a phone may decrease to just 2%. > > > > - Mixing large and small folios in the same LRU list can lead to > > mutual blocking and unpredictable > > latency during reclamation/allocation. > > I'm also curious how much large folios can improve reclamation > efficiency. Having large folios is supposed to reduce the scan time > since there should be fewer folios on LRU. But IIRC I haven't seen too > much data or benchmark (particularly real life workloads) regarding > this. Hi Yang, We lack direct data on this matter, but information from Ryan's THP_SWPOUT series [1] provides insights as follows: | alloc size | baseline | + this series | | | mm-unstable (~v6.9-rc1) | | |:-----------|------------------------:|------------------------:| | 4K Page | 0.0% | 1.3% | | 64K THP | -13.6% | 46.3% | | 2M THP | 91.4% | 89.6% | I suspect the -13.6% performance decrease is due to the split operation. Once the split is eliminated, the patchset observed a 46.3% increase. It is presumed that the overhead required to reclaim 64K is reduced compared to reclaiming 16 * 4K. However, at present, in actual android devices, we are observing nearly 100% occurrence of anon_thp_swpout_fallback after the device has been in operation for several hours[2]. Hence, it is likely that we will experience regression instead of improvement due to the absence of measures to mitigate swap fragmentation. [1] https://lore.kernel.org/all/20240408183946.2991168-1-ryan.roberts@arm.c= om/ [2] https://lore.kernel.org/lkml/CAGsJ_4zAcJkuW016Cfi6wicRr8N9X+GJJhgMQdSMp= +Ah+NSgNQ@mail.gmail.com/ > > > > > For instance, if you require large folios, the LRU list's tail could > > be filled with small folios. > > LRU(LF- large folio, SF- small folio): > > > > LF - LF - LF - SF - SF - SF - SF - SF - SF -SF - SF - SF - SF - SF = - SF - SF > > > > You might end up reclaiming many small folios yet still struggle to > > allocate large folios. Conversely, > > the inverse scenario can occur when the LRU list's tail is populated > > with large folios. > > > > SF - SF - SF - LF - LF - LF - LF - LF - LF -LF - LF - LF - LF - LF = - LF - LF > > > > In OPPO's products, we allocate dedicated pageblocks solely for large > > folios allocation, and we've > > fine-tuned the LRU mechanism to support dual LRU=E2=80=94one for small = folios > > and another for large ones. > > Dedicated page blocks offer a fundamental guarantee of allocating > > large folios. Additionally, segregating > > small and large folios into two LRUs ensures that both can be > > efficiently reclaimed for their respective > > users' requests. However, while the implementation may lack aesthetic > > appeal and is primarily tailored > > for product purposes, it isn't fully upstreamable. > > > > You can obtain the architectural diagram of OPPO's approach from link[2= ]. > > > > Therefore, my plan is to present: > > > > - Introduce the architecture of OPPO's mTHP-like approach, which > > encompasses additional optimizations > > we've made to address swap fragmentation issues and improve swap > > performance, such as dual-zRAM > > and compression/decompression of large folios [3]. > > > > - Present OPPO's method of utilizing dedicated page blocks and a > > dual-LRU system for mTHP. > > > > - Share our observations from employing Yu Zhao's TAO on Pixel 6 phones= . > > > > - Discuss our future direction=E2=80=94are we leaning towards TAO or de= dicated > > page blocks? If we opt for page > > blocks, how do we plan to resolve the LRU issue? > > > > [1] https://lore.kernel.org/linux-mm/20240229183436.4110845-1-yuzhao@go= ogle.com/ > > [2] https://github.com/21cnbao/mTHP/blob/main/largefoliosarch.png > > [3] https://lore.kernel.org/linux-mm/20240327214816.31191-1-21cnbao@gma= il.com/ > > Thanks, Barry