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 59005C3DA6E for ; Wed, 10 Jan 2024 09:09:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF32C6B0087; Wed, 10 Jan 2024 04:09:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C7E806B008A; Wed, 10 Jan 2024 04:09:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD1776B008C; Wed, 10 Jan 2024 04:09:25 -0500 (EST) 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 4A7116B0087 for ; Wed, 10 Jan 2024 04:09:25 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1DE7BA04B9 for ; Wed, 10 Jan 2024 09:09:25 +0000 (UTC) X-FDA: 81662827890.07.1344F84 Received: from mail-vk1-f178.google.com (mail-vk1-f178.google.com [209.85.221.178]) by imf26.hostedemail.com (Postfix) with ESMTP id 4AE8C140014 for ; Wed, 10 Jan 2024 09:09:23 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FzbZ9LBe; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.221.178 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=1704877763; 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=v+obCr/kFT3mwWTpDKYwgtBrrNK0rNMlrL0QGptVGbE=; b=Rdv0702vy1ihDA2ULWDfAIg3i9o279Xm6dfooUW/1UQBNwRj1DR+Z5QRHOScd+kfSANJVo 2MZp79u5CMoXMQkl/wp0NwFHHROYPQGdwDrFr8XbWHwgSonJITR3TKcTmAFWUx66dAUMAk nrp+pQUpFo4W6fIDiLuCFaQCL6BSAZg= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FzbZ9LBe; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.221.178 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704877763; a=rsa-sha256; cv=none; b=uM5fuwTioB0VY1CLUP9qdsAXADZvgta6e5kb1QyiuZiK4Wtk/f1JF/qiL5q7M0Yar7sLr/ vQBxaPoA+eRno55+Ur1L1Shs1oMo5H9MJCMSnrO6uutxjErVOdfc2YsIyRDxCvz03Rfbfy Gj1+6SxIgRcyYoCThPUPse0IzRq+0Yo= Received: by mail-vk1-f178.google.com with SMTP id 71dfb90a1353d-4b77c844087so2277216e0c.1 for ; Wed, 10 Jan 2024 01:09:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704877762; x=1705482562; 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=v+obCr/kFT3mwWTpDKYwgtBrrNK0rNMlrL0QGptVGbE=; b=FzbZ9LBeDMwOabbAJH7tmBErYTpoTJugEqi69GhIAReH4MnUmkYt71Ah9UNYX5Y3ZC 2/F8bcZO/7p78+Q8om0rB/FRGz/LoX5skgPUCecB3ACzHN4EF86RHc5h1XzIW4dGWBuD vV/0Wj0+8RlwXJhCLzH5Se9hLI2UNRinIusXdEUAyZkNaDK/4MW7hURQLlgRhYCH5yk1 6WWVPZeV249a/FQRf2H1Yv8j5d+GipMme53ifbgTvP0zrnr+ffRbSDc5c3nW+u8CcMxq 9Yy8h8bNs4JKoQ0tQBRwloR33MjWNOAI1I8IkZsu/Jou1nwQ38VE7ydWqx2feBF3truI YZuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704877762; x=1705482562; 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=v+obCr/kFT3mwWTpDKYwgtBrrNK0rNMlrL0QGptVGbE=; b=rVIfNE6hJGVb7fRD+koul/wQ9n0ms673pxO3yCjOAzyn5lzFJTWNmU92hg675yPjvR ONGFUqKAAyEC5FRilFe00BSxO88HZmyjLeVZNR8EMm2uO1mNSLCdRYgIVkVY1e5HZGHO njU6ogx4c/XUMcBmxJCM6CdP7vQqWOCLFgMQeB409Q6LOnx1AGOxfyxNT0255Pa4KPKX ZHIpxoLShSvPC1asCgHtclRvb7NN0kEuT0sBmzBfm4kPPSY5aF2SE0X8+KcQxT1wDNNs dvE9YwBIt/flg1pZWfz0wpEXXw/esySUB4a/5mSoJFbB7VNm7sZ1bPjbCclriJxb1U12 47PQ== X-Gm-Message-State: AOJu0YwFmFyXGxjTSwS6ptHuZg/yYpdaK8bsvKnfwMaWJfhJVT7JcwKo V3nV/sTTpl3xRPnIVVK0XDp8OVCPsLjZPFs6qjk= X-Google-Smtp-Source: AGHT+IGWUVgpf2m5PLg+/jxPKnaMPFXeDWHo8uVd4jwslWUnsm/tVNS0bNGDREebSJK40mspM/GYAAOYrZgf4xdSM5E= X-Received: by 2002:a05:6122:54a:b0:4b7:3141:ff7f with SMTP id y10-20020a056122054a00b004b73141ff7fmr513736vko.7.1704877762225; Wed, 10 Jan 2024 01:09:22 -0800 (PST) MIME-Version: 1.0 References: <20240102153828.1002295-1-ryan.roberts@arm.com> <4e7445a0-acc9-487f-999f-a2b6d03d265e@nvidia.com> <3bd5e4a3-9f67-4483-9a0e-9abb5eb783cd@arm.com> In-Reply-To: <3bd5e4a3-9f67-4483-9a0e-9abb5eb783cd@arm.com> From: Barry Song <21cnbao@gmail.com> Date: Wed, 10 Jan 2024 17:09:10 +0800 Message-ID: Subject: Re: [RFC PATCH v1] tools/mm: Add thpmaps script to dump THP usage info To: Ryan Roberts Cc: John Hubbard , Andrew Morton , Zenghui Yu , Matthew Wilcox , David Hildenbrand , Kefeng Wang , Zi Yan , Alistair Popple , linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 4AE8C140014 X-Stat-Signature: 6er8o1gjqftwrjzs6t9jsdn46f6zq8yy X-HE-Tag: 1704877763-586967 X-HE-Meta: U2FsdGVkX1/fUR+CPukY80aH6ZOxssoYFkgoxBL8COdP0yDKqPSDCECzZJ0gsNPAmdBxxWgvTSlUOea9h6ThAmOxrBLHIMH3LYaeOe9fe9aMISA9sMNiCmMY3VVEV/BXmkWCmob0l1s0pIhfum/RJJqDlAxmbywY5v6bH4Z3th/NaeGm0NwIO/P0cUJDb1K3MLmAZJb3LTmwGlY6bzOYbDu2x/k90+iNEH/z5k7OXSbrpFB0L8CQZJLpX2pZtnyTUNfz3AsDos9IqLsje8MVqJIdqua8N1yYlDg7XovGfrK4VIu2EYUaU3GsIWdS3f0h7OPpvB9P1P8GvyUf/YK0mGJFqkM1tV+KG57LxGGQUgkZbQgaRPFLmUZQl34dIqDhG24WCFOWo39eR9Qtz/PwC56fjvS1OTO81fORCyAgCyu4+R2SHeweRC1tl4Ptcg7gbsYiv/lv6k8Y9lsGx8hY8Xa3DX2RanE7FP1gq9ZrX23qTQb/lOcsZTNDN+u0HHEjnNKYriLdWaIlFNzEQs04ukq4STC6i/4JQC7KtOBkzCkqbEJuRO/MmqeUfEqyDREfAfOsua/3xEP29qRj/usS0JUFeMvAuQV1XBJ74bvDjyBMAyhkB9VKeAWyXp/Sc9kj698jCMldbI/ovC+MoNue6afvyZBBtCHLDeK/SwqmRDtpyplhZyUpLZYrxOzzWQi4lgPmKDEKdwomBiA/6Xa2xgaLbx/GVDux9q7Ygkjxz1OQzYOJ7/f8MHSDK7FSo61iQvP3A0Ou7oU5tgHcBagdB2wn4vxwif1VsgoHW7DB2pQdzvBf7S33aVTZqgz7F0M1Y7Wua2f1FEi/D8ewCADNKO4sNzHrhRapNxI6IAsle9NOL4TXfAheCWyoQUw1elqIsIoFjGuSIGcr76OMfjTTOr9PPn3x5makV4L1Axl4XCjPfpT79RN4/vOvzBycQyNX0xS859Iiiv9/dtmGCpC ETtxOK5T nwMxQ7xEmufcYeaFkjSiA5K+fhBSP+gV1tjd4pjENC+Z2rJXtywNyi+x0NV1OcG5a7U65ijmYatmX3yVIhGlMDa5Qd6aWOOT8Sv4VDSCGW0l8p41hhFDBs9cmhqqg48wm06yWDgXJwTAwC5Z7f1umJA/yBkscwY5bOpdLlPxlGspRCdIUZao85MQgDtrAVi6Hnn5gQo3lI0lDwIfKK4qcRp3QzG1dGGK7NkqhVIGgeYT7JA4iIHceMzJOQB59GISr9gGQsZXjyuQZRKAp0tSVDl4KuEn70+l3pxRzzhxRRIlU6AbdSx+KMV4zzyLnWrqAXOY7bKOZJSdKmdQJ268FHEXST/sNPGJz0/CZY2WEXgcACzQBoolF0XB95Yw9FMUSzPUEsHRCb25hb0ccuTfhRcSxlkh2zGEoF6YhRzMmseeXuECRLbq7PwfD0Q== 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: On Wed, Jan 10, 2024 at 4:58=E2=80=AFPM Ryan Roberts = wrote: > > On 10/01/2024 08:02, Barry Song wrote: > > On Wed, Jan 10, 2024 at 12:16=E2=80=AFPM John Hubbard wrote: > >> > >> On 1/9/24 19:51, Barry Song wrote: > >>> On Wed, Jan 10, 2024 at 11:35=E2=80=AFAM John Hubbard wrote: > >> ... > >>>> Hi Ryan, > >>>> > >>>> One thing that immediately came up during some recent testing of mTH= P > >>>> on arm64: the pid requirement is sometimes a little awkward. I'm run= ning > >>>> tests on a machine at a time for now, inside various containers and > >>>> such, and it would be nice if there were an easy way to get some num= bers > >>>> for the mTHPs across the whole machine. > > Just to confirm, you're expecting these "global" stats be truely global a= nd not > per-container? (asking because you exploicitly mentioned being in a conta= iner). > If you want per-container, then you can probably just create the containe= r in a > cgroup? > > >>>> > >>>> I'm not sure if that changes anything about thpmaps here. Probably > >>>> this is fine as-is. But I wanted to give some initial reactions from > >>>> just some quick runs: the global state would be convenient. > > Thanks for taking this for a spin! Appreciate the feedback. > > >>> > >>> +1. but this seems to be impossible by scanning pagemap? > >>> so may we add this statistics information in kernel just like > >>> /proc/meminfo or a separate /proc/mthp_info? > >>> > >> > >> Yes. From my perspective, it looks like the global stats are more usef= ul > >> initially, and the more detailed per-pid or per-cgroup stats are the > >> next level of investigation. So feels odd to start with the more > >> detailed stats. > >> > > > > probably because this can be done without the modification of the kerne= l. > > Yes indeed, as John said in an earlier thread, my previous attempts to ad= d stats > directly in the kernel got pushback; DavidH was concerned that we don't r= eally > know exectly how to account mTHPs yet > (whole/partial/aligned/unaligned/per-size/etc) so didn't want to end up a= dding > the wrong ABI and having to maintain it forever. There has also been some > pushback regarding adding more values to multi-value files in sysfs, so D= avid > was suggesting coming up with a whole new scheme at some point (I know > /proc/meminfo isn't sysfs, but the equivalent files for NUMA nodes and cg= roups > do live in sysfs). > > Anyway, this script was my attempt to 1) provide a short term solution to= the > "we need some stats" request and 2) provide a context in which to explore= what > the right stats are - this script can evolve without the ABI problem. > > > The detailed per-pid or per-cgroup is still quite useful to my case in = which > > we set mTHP enabled/disabled and allowed sizes according to vma types, > > eg. libc_malloc, java heaps etc. > > > > Different vma types can have different anon_name. So I can use the deta= iled > > info to find out if specific VMAs have gotten mTHP properly and how man= y > > they have gotten. > > > >> However, Ryan did clearly say, above, "In future we may wish to > >> introduce stats directly into the kernel (e.g. smaps or similar)". And > >> earlier he ran into some pushback on trying to set up /proc or /sys > >> values because this is still such an early feature. > >> > >> I wonder if we could put the global stats in debugfs for now? That's > >> specifically supposed to be a "we promise *not* to keep this ABI stabl= e" > >> location. > > Now that I think about it, I wonder if we can add a --global mode to the = script > (or just infer global when neither --pid nor --cgroup are provided). I th= ink I > should be able to determine all the physical memory ranges from /proc/iom= em, > then grab all the info we need from /proc/kpageflags. We should then be a= ble to > process it all in much the same way as for --pid/--cgroup and provide the= same > stats, but it will apply globally. What do you think? for debug purposes, it should be good. imaging there is a health monitor which needs to sample the stats of large folios online and periodically, this might be too expensive. > > If we can possibly avoid sysfs/debugfs I would prefer to keep it all in a= script > for now. > > > > > +1. > > > >> > >> > >> thanks, > >> -- > >> John Hubbard > >> NVIDIA > >> > > Thanks Barry