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 71C22C25B75 for ; Wed, 15 May 2024 19:25:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A05636B00BC; Wed, 15 May 2024 15:25:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B5F36B00DC; Wed, 15 May 2024 15:25:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 856226B010C; Wed, 15 May 2024 15:25:33 -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 690756B00BC for ; Wed, 15 May 2024 15:25:33 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 07E48A08B3 for ; Wed, 15 May 2024 19:25:32 +0000 (UTC) X-FDA: 82121609346.08.3D5BF5C Received: from mail-vk1-f182.google.com (mail-vk1-f182.google.com [209.85.221.182]) by imf06.hostedemail.com (Postfix) with ESMTP id 2D69118000B for ; Wed, 15 May 2024 19:25:30 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=F9L+wM6P; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.221.182 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715801131; 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=C1ndkX7VV8ALIoJrthhfCtYHNX/iwR6ECEozudPOcXA=; b=dOcrot4tdPilgG9XKksrPeBu1U1lSbqS6c9C+Lz8/TbH3HveEkZsIOHwBeh48oqFkDi7aZ 6yu1CX5FCf/6fbvHRXOr6IAudZcn4c6aix8uwTJvX040+3NEFLtDZ+OMhxOE1sMNK+AkDf 7obMm09HQIRPIg3AOuxf54kC+XWYFSs= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=F9L+wM6P; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.221.182 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715801131; a=rsa-sha256; cv=none; b=oo8c7H5Cem3AyiGCYUMEy3JIVzDaFI5pKEnS0WQ66ezXnsIg91bM1Ju8Smgb+oK9r1gj0V lIzg4yHeBwtVw4vYYuiv6HO+EcEbK+29DrYyY8WoHaF7/fzkO9s8JL4Cw7SGoPeAAKx7Na 36t3iT83Gr3047ZWBApsE90R1ZlDpJA= Received: by mail-vk1-f182.google.com with SMTP id 71dfb90a1353d-4df344eecd7so2502769e0c.3 for ; Wed, 15 May 2024 12:25:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715801130; x=1716405930; 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=C1ndkX7VV8ALIoJrthhfCtYHNX/iwR6ECEozudPOcXA=; b=F9L+wM6Pxlw7C/HSpT+BtRKmkfEWlcExydLCTKdnt1+yYkWFIrZ/Qx7arf0BmrpHsy iAkhLTMLjRdF+l1vV6nXzOE7WW7ZlikpKivZq280bfee9kXuVI7JAdIJ0o2XzFQ/N3xb A+0jQt3vgaruCUwOHFERGzs88Dt5b9l8vvLAOkNi/q2U8Abq59EQKbh7w46Ti54+ZcoL SF/E+fW4cA6hiqJh8t444MtqnRlGg95uMa0gHUA4yBWjMc3tvybx1CtVdYV20w1NHLDt +RVP/ZGSr2BAju6WgxYPn8O+d4H3KiX3VKEFlqgKMyTK9MRmVuWLaU1TvNyhSPQznZuo BjVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715801130; x=1716405930; 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=C1ndkX7VV8ALIoJrthhfCtYHNX/iwR6ECEozudPOcXA=; b=OYXj3IhLqkdYlQTJ83bRAoLrUdrCrroaDZUG7fjooDHEZY0Y34QJ1+i398nL+hcFjI r517S9bBO9LkQ6mWbdZ7Q3VRGl6he82/PhicNa1bu+1Y1TCUqN60CEv2YbsnYxinM7LH A//4RjPC+L500rvNhSvSXLJVECbBkMsNnYwrrD6qsgMSdVkfeAUhGAjBb2IdNu33qiqC 0ONoN0gxzs3PqF1hJ6cQUAi/yci3PmK0gKjDUoh661Lk+qzwa0s3rFpfZRckSpz8qgOH GdTnuMCVjDN7B+SglQz16PfBt7NwwdxTTQw+B8YsddyTpoPxBxoP90WUmce2HbmfrT59 9sHg== X-Forwarded-Encrypted: i=1; AJvYcCWXtQcn6/hsoWsFOqjphxORF2O8GHihzcJ3PVXOhkZbNuJ4cbEIcuO8tpmtSIX0nMliAkxajWaziHMn5zt1h2+x6O8= X-Gm-Message-State: AOJu0Yze49a4YePULDhoyE+ERl7SnJ3cdSPENNS+j1qdjwZOWyjaKF/f 3el6zJkbsRI1PY1xUa/2xLy2+ZrGR4OrCRNvV9KTVkzNV8eF96F9jBytJ6VVL5hsWl2xlVWJRYw ZhI2Nni8ZJZHAzM2UdeAajw2oiI0JHDlG X-Google-Smtp-Source: AGHT+IEWEyK1JUbSdAJgZx0VFd/nma6uSCxprq5AXTfWFT66awHI3njrIhq5q1MSH3TSeCIe+/10XGkhrc85umw+Kok= X-Received: by 2002:a05:6122:4123:b0:4df:7ba8:5c73 with SMTP id 71dfb90a1353d-4df883692e2mr14730193e0c.14.1715801128419; Wed, 15 May 2024 12:25:28 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Barry Song <21cnbao@gmail.com> Date: Thu, 16 May 2024 07:25:17 +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-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 2D69118000B X-Stat-Signature: 3eka1mg8389xeprmb34k6w93dbic45xf X-HE-Tag: 1715801130-275131 X-HE-Meta: U2FsdGVkX1/UjSoXXnLPK6DYUic3oLpvPJM5w+/8YbTI/GtPuTTrnkAKx7uhcozLHHGQYqm516Aj8g98znYdAHylLpoDGQ923c41i/Mj/+FcCgdxdF3YCwzDhEl2YtU3fVBGRpfX8WKxydZkNwPLpvvoXZixmVNsk0XfJ0mOvy0Co6w/CnHGKdgGdqkr0sSs2bHF5vPDm+tNwTfdsfeY5edRexGVn29DBt5KqoBlmPlFb+y5zv0l2NgSZW6A4U7hTZsyh32s48PONKYcob5eEQyUDhKS8vkoSEPghQAHgLIg4lRtjaWVOPfm0pqPngLbDKyvXlo1wdqQgmL/h45nGZ/ZxAEoEekIka+H4IB455PuX+GIPYOJ0t24rPR767jeUXr74q8MqXWtLvWBt6TNNHXjpegiHnzsDtAPTwsGrvJnWemnCKvFR6x0X5kKepzHijXZ7a5TUTK9zXMyIMGe5HeZ6vt8sOdG9MdkmVDO/tatwA2fjAtaM8RX0jOGgGxyBjtPiuJLF1yxHh+8USposA5UIY7RRTASGlD6kFAB0CCj6OfVepa1XFzSh2lisFJJmtBx3If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vack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, May 16, 2024 at 1:49=E2=80=AFAM Yang Shi wrot= e: > > On Tue, May 14, 2024 at 3:20=E2=80=AFAM Barry Song <21cnbao@gmail.com> wr= ote: > > > > On Sat, May 11, 2024 at 9:18=E2=80=AFAM Yang Shi = wrote: > > > > > > On Thu, May 9, 2024 at 7:22=E2=80=AFPM Barry Song <21cnbao@gmail.com>= wrote: > > > > > > > > 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 likelihoo= d > > > > 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 to= o > > > 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_SWP= OUT > > 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. > > Thank you. Actually I care about 4k vs 64k vs 256k ... > > I did a simple test by calling MADV_PAGEOUT on 4G memory w/ the > swapout optimization then measured the time spent in madvise, I can > see the time was reduced by ~23% between 64k vs 4k. Then there is no > noticeable reduction between 64k and larger sizes. If you engage in perf analysis, what observations can you make? I suspect t= hat even with larger folios, the function try_to_unmap_one() continues to itera= te through PTEs individually. If we're able to batch the unmapping process for the entire folio, we might observe improved performance. > > Actually I saw such a pattern (performance doesn't scale with page > size after 64K) with some real life workload benchmark. I'm going to > talk about it in today's LSF/MM. > > > > > 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@a= rm.com/ > > [2] https://lore.kernel.org/lkml/CAGsJ_4zAcJkuW016Cfi6wicRr8N9X+GJJhgMQ= dSMp+Ah+NSgNQ@mail.gmail.com/ > > > > > > > > > > > > > For instance, if you require large folios, the LRU list's tail co= uld > > > > 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 t= o > > > > allocate large folios. Conversely, > > > > the inverse scenario can occur when the LRU list's tail is populat= ed > > > > 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 lar= ge > > > > folios allocation, and we've > > > > fine-tuned the LRU mechanism to support dual LRU=E2=80=94one for sm= all 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 aesthe= tic > > > > appeal and is primarily tailored > > > > for product purposes, it isn't fully upstreamable. > > > > > > > > You can obtain the architectural diagram of OPPO's approach from li= nk[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 ph= ones. > > > > > > > > - Discuss our future direction=E2=80=94are we leaning towards TAO o= r dedicated > > > > 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-yuzha= o@google.com/ > > > > [2] https://github.com/21cnbao/mTHP/blob/main/largefoliosarch.png > > > > [3] https://lore.kernel.org/linux-mm/20240327214816.31191-1-21cnbao= @gmail.com/ > > > > Thanks, Barry