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 8F8A6E668A0 for ; Sun, 24 Nov 2024 07:29:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D37066B0082; Sun, 24 Nov 2024 02:29:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CE8636B0083; Sun, 24 Nov 2024 02:29:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B87B26B0085; Sun, 24 Nov 2024 02:29:01 -0500 (EST) 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 9C5336B0082 for ; Sun, 24 Nov 2024 02:29:01 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 20B7F12011A for ; Sun, 24 Nov 2024 07:29:01 +0000 (UTC) X-FDA: 82820161956.03.1316053 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) by imf11.hostedemail.com (Postfix) with ESMTP id 0E95240005 for ; Sun, 24 Nov 2024 07:28:56 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jsFZSnUQ; spf=pass (imf11.hostedemail.com: domain of ioworker0@gmail.com designates 209.85.208.46 as permitted sender) smtp.mailfrom=ioworker0@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=1732433338; 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=dN8zRcfhE6ALGBdKKjyOrLy2sDPTD/bNAD8E4U8U+TA=; b=Ku+QH+9IpzAIJ8lTiyQ2lPadDTVkf5zwLSnJ6Mm3dCrUlPAQz4je5K3dU1F37xwgAt8ejD 0NRYOvRWLEsDwOCgHW2XvvlVjBmUuT63GKazauvhVvrtRVftAiH5XvMG/hZsCL7TXZSuhR MLoqkzX2Ykc+T1FAXrV9M8ingZJQXh0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732433338; a=rsa-sha256; cv=none; b=1OHkExPXpWCq4HrMZuW9pc7ioh/k/mF4nReATnHqjmLFs+dD2PYFFJrkcfPL0m4yLr3cPJ wM73XRk5sGBRVWVE5vT2rvZhsU10ZumL0vdFuPj879OnGiMxg75YAOQ+uKWn3nBRpPBk3X n60avePmUdk7dUwhaBrYA5zrjrCvFr8= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jsFZSnUQ; spf=pass (imf11.hostedemail.com: domain of ioworker0@gmail.com designates 209.85.208.46 as permitted sender) smtp.mailfrom=ioworker0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-5cfddb70965so4356046a12.0 for ; Sat, 23 Nov 2024 23:28:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732433338; x=1733038138; 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=dN8zRcfhE6ALGBdKKjyOrLy2sDPTD/bNAD8E4U8U+TA=; b=jsFZSnUQZqFahzJ39bSIgZezZOV6RBZivDOQywHlSpDaSbONqRIRE8kyR0ODSiYF43 OEmg6F1bQbsZcgmsngbr2l8RRkUzvugR6FPZe2De6K7Irhe/wDRnwGN+OjmsRQhtitQZ f24LUcIPcA1rRRTLytjhyQs7NQbOPTh3OwbJ2qTAXq5Hr4AK9LJxAOHwmu2GkEa9EPUx IBIGLN9CQhZrDJdrz79QCqqDLTaTvfVTUkH7q8bu8PC5O8bho+mQhoap9/A/ZUYA4wqb Ezrcr/7SPIjnq19KkhtYZa4os2E7bkW5MAkEnBoGJ8tfFkO1NoDzigiNwlvi+hDgS7vt mJDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732433338; x=1733038138; 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=dN8zRcfhE6ALGBdKKjyOrLy2sDPTD/bNAD8E4U8U+TA=; b=gQHT28XV77/38o4vALhurCGQw3akiGyzQHfU7ytXOBnYOJytq1+dR8Y40E86o2ByKI NgWQOYhPBBZvmBYi2tZGPTWfg3c9hNYBPf+5FSEWQO7PH8/pmjMpJOL1vErlzM7Ypxle oDZaoXPmKtw50KpYzciUGvZyh1UJQfkPwPFh3VvCKgM9RUHYKcT6cq3mKh23hn8/LHHk sibVXLdkrweCYb3MUIOGsO5FWAgjFQDtZIpKpeNTYwW5ZbcggpAAZX9UC1RRrOVs4d+z qmGq9rK8tlrpftZTXWtqLrgvzsMbmoN14sNAJvSlB5fvgWbVW6KqfKSOS0M0sJstohET yuuQ== X-Forwarded-Encrypted: i=1; AJvYcCWSv25Hoe4pDZLJCVUJNRsCdQ7unL6NwUo4PRP4JPIjI+TTKXDO1lUP8dDcjHAhnbsnt//7RH+cEA==@kvack.org X-Gm-Message-State: AOJu0YyvA0j5v05qQDJ4NHD81T/mWDt1BOaYfJaiOSe5jmbK+g2aaWSv lsjTScTGgljUelqxJLUAIovQ9MoIoEsSmUcLM9OMw1UJkV+f+6tc4K6F8/Qpm5ejme03FUoHuU1 nG9NVnB45+3lwy5Jvjh7kdNrOumE= X-Gm-Gg: ASbGncuJJrT3qfvwn7A8mp9lOLD3Y8h2msNIerBH8sDgk4ZC36ZwXL2WBvCTsjjVezI k6yVTmBb2znRneZV3ONJ7Y2LSX/JbatY= X-Google-Smtp-Source: AGHT+IHQhXPpC7w3S+OsrD9bMx3Bl7PdOgS9WEILMbAxdgTosfcsQynYpY+AL5kStwp3O5oT+MZE72YqOWeioPkEtws= X-Received: by 2002:a05:6402:3489:b0:5cf:e240:4065 with SMTP id 4fb4d7f45d1cf-5d0205f7449mr7488876a12.8.1732433337457; Sat, 23 Nov 2024 23:28:57 -0800 (PST) MIME-Version: 1.0 References: <20241122161443.34667-1-haowenchao22@gmail.com> <24ea047a-7294-4e7a-bf51-66b7f79f5085@gmail.com> In-Reply-To: From: Lance Yang Date: Sun, 24 Nov 2024 15:28:21 +0800 Message-ID: Subject: Re: [PATCH v2] mm: add per-order mTHP swap-in fallback/fallback_charge counters To: Barry Song <21cnbao@gmail.com> Cc: Wenchao Hao , Jonathan Corbet , Andrew Morton , David Hildenbrand , Ryan Roberts , Baolin Wang , Usama Arif , Matthew Wilcox , Peter Xu , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: toy1djnnsybt36e4d6uspt4wgiymtmno X-Rspam-User: X-Rspamd-Queue-Id: 0E95240005 X-Rspamd-Server: rspam02 X-HE-Tag: 1732433336-332640 X-HE-Meta: U2FsdGVkX1+LMPVtrVxW4+dsLNpPrSxcKZEXUYOuGPisM8fr+OTN7SUWrxZjsDZbgOdKAyj4UDZVtMvPl6HlaaVjA6bYJP7CCPm49kwUvM6Ogq6BoC9qiEDtq69U5mwkyI3LI4VJBHg1BILC6enSrzT9MsoXGvLrVZf/G3Exyd62XD8200tnBZz1pfRpPO3qcK6BW5l/hm4Y7dLKbUd8DOwDnejn4+O+0JBU3NXpG8nrsP1oiM3qW7hhvsj3gb2mliHY9g/e00WMF25vv+TTpG04j5GcjCR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h5Gpv3cPpkPaIkC6M59w= 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 Sun, Nov 24, 2024 at 3:11=E2=80=AFPM Barry Song <21cnbao@gmail.com> wrot= e: > > On Sun, Nov 24, 2024 at 2:56=E2=80=AFPM Lance Yang = wrote: > > > > On Sat, Nov 23, 2024 at 9:17=E2=80=AFPM Wenchao Hao wrote: > > > > > > On 2024/11/23 19:52, Lance Yang wrote: > > > > On Sat, Nov 23, 2024 at 6:27=E2=80=AFPM Barry Song <21cnbao@gmail.c= om> wrote: > > > >> > > > >> On Sat, Nov 23, 2024 at 10:36=E2=80=AFAM Lance Yang wrote: > > > >>> > > > >>> Hi Wenchao, > > > >>> > > > >>> On Sat, Nov 23, 2024 at 12:14=E2=80=AFAM Wenchao Hao wrote: > > > >>>> > > > >>>> Currently, large folio swap-in is supported, but we lack a metho= d to > > > >>>> analyze their success ratio. Similar to anon_fault_fallback, we = introduce > > > >>>> per-order mTHP swpin_fallback and swpin_fallback_charge counters= for > > > >>>> calculating their success ratio. The new counters are located at= : > > > >>>> > > > >>>> /sys/kernel/mm/transparent_hugepage/hugepages-/stats/ > > > >>>> swpin_fallback > > > >>>> swpin_fallback_charge > > > >>>> > > > >>>> Signed-off-by: Wenchao Hao > > > >>>> --- > > > >>>> V2: > > > >>>> Introduce swapin_fallback_charge, which increments if it fails = to > > > >>>> charge a huge page to memory despite successful allocation. > > > >>>> > > > >>>> Documentation/admin-guide/mm/transhuge.rst | 10 ++++++++++ > > > >>>> include/linux/huge_mm.h | 2 ++ > > > >>>> mm/huge_memory.c | 6 ++++++ > > > >>>> mm/memory.c | 2 ++ > > > >>>> 4 files changed, 20 insertions(+) > > > >>>> > > > >>>> diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Docume= ntation/admin-guide/mm/transhuge.rst > > > >>>> index 5034915f4e8e..9c07612281b5 100644 > > > >>>> --- a/Documentation/admin-guide/mm/transhuge.rst > > > >>>> +++ b/Documentation/admin-guide/mm/transhuge.rst > > > >>>> @@ -561,6 +561,16 @@ swpin > > > >>>> is incremented every time a huge page is swapped in from= a non-zswap > > > >>>> swap device in one piece. > > > >>>> > > > >>> > > > >>> Would the following be better? > > > >>> > > > >>> +swpin_fallback > > > >>> + is incremented if a huge page swapin fails to allocate or= charge > > > >>> + it and instead falls back to using small pages. > > > >>> > > > >>> +swpin_fallback_charge > > > >>> + is incremented if a huge page swapin fails to charge it a= nd instead > > > >>> + falls back to using small pages even though the allocatio= n was > > > >>> + successful. > > > >> > > > >> much better, but it is better to align with "huge pages with > > > >> lower orders or small pages", not necessarily small pages: > > > >> > > > >> anon_fault_fallback > > > >> is incremented if a page fault fails to allocate or charge > > > >> a huge page and instead falls back to using huge pages with > > > >> lower orders or small pages. > > > >> > > > >> anon_fault_fallback_charge > > > >> is incremented if a page fault fails to charge a huge page and > > > >> instead falls back to using huge pages with lower orders or > > > >> small pages even though the allocation was successful. > > > > > > > > Right, I clearly overlooked that ;) > > > > > > > > > > Hi Lance and Barry, > > > > > > Do you think the following expression is clear? Compared to my origin= al > > > version, I=E2=80=99ve removed the word =E2=80=9Chuge=E2=80=9D from th= e first line, and it now > > > looks almost identical to anon_fault_fallback/anon_fault_fallback_cha= rge. > > > > Well, that's fine with me. And let's see Barry's opinion as well ;) > > I still prefer Lance's version. The fallback path in it only needs to > be adjusted to > include huge pages with lower orders. In contrast, Wenchao's version feel= s less > natural to me because "page swapin" sounds quite odd - we often hear > "page fault," > but we have never encountered "page swapin." Yeah, it makes sense to me ~ > > So I mean: > > swpin_fallback > is incremented if swapin fails to allocate or charge a huge > page and instead > falls back to using huge pages with lower orders or small pages. > > swpin_fallback_charge > is incremented if swapin fails to charge a huge page and instead > falls back to using huge pages with lower orders or small > pages even though > the allocation was successful. IHMO, much better and clearer than before ;) Thank, Lance > > > > > Thanks, > > Lance > > > > > > > > swpin_fallback > > > is incremented if a page swapin fails to allocate or charge > > > a huge page and instead falls back to using huge pages with > > > lower orders or small pages. > > > > > > swpin_fallback_charge > > > is incremented if a page swapin fails to charge a huge page an= d > > > instead falls back to using huge pages with lower orders or > > > small pages even though the allocation was successful. > > > > > > Thanks, > > > Wencaho > > > > > > > Thanks, > > > > Lance > > > > > > > >> > > > >>> > > > >>> Thanks, > > > >>> Lance > > > >>> > > > >>>> +swpin_fallback > > > >>>> + is incremented if a huge page swapin fails to allocate o= r charge > > > >>>> + a huge page and instead falls back to using huge pages w= ith > > > >>>> + lower orders or small pages. > > > >>>> + > > > >>>> +swpin_fallback_charge > > > >>>> + is incremented if a page swapin fails to charge a huge p= age and > > > >>>> + instead falls back to using huge pages with lower orders= or > > > >>>> + small pages even though the allocation was successful. > > > >>>> + > > > >>>> swpout > > > >>>> is incremented every time a huge page is swapped out to = a non-zswap > > > >>>> swap device in one piece without splitting. > > > >>>> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h > > > >>>> index b94c2e8ee918..93e509b6c00e 100644 > > > >>>> --- a/include/linux/huge_mm.h > > > >>>> +++ b/include/linux/huge_mm.h > > > >>>> @@ -121,6 +121,8 @@ enum mthp_stat_item { > > > >>>> MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE, > > > >>>> MTHP_STAT_ZSWPOUT, > > > >>>> MTHP_STAT_SWPIN, > > > >>>> + MTHP_STAT_SWPIN_FALLBACK, > > > >>>> + MTHP_STAT_SWPIN_FALLBACK_CHARGE, > > > >>>> MTHP_STAT_SWPOUT, > > > >>>> MTHP_STAT_SWPOUT_FALLBACK, > > > >>>> MTHP_STAT_SHMEM_ALLOC, > > > >>>> diff --git a/mm/huge_memory.c b/mm/huge_memory.c > > > >>>> index ee335d96fc39..46749dded1c9 100644 > > > >>>> --- a/mm/huge_memory.c > > > >>>> +++ b/mm/huge_memory.c > > > >>>> @@ -617,6 +617,8 @@ DEFINE_MTHP_STAT_ATTR(anon_fault_fallback, M= THP_STAT_ANON_FAULT_FALLBACK); > > > >>>> DEFINE_MTHP_STAT_ATTR(anon_fault_fallback_charge, MTHP_STAT_ANO= N_FAULT_FALLBACK_CHARGE); > > > >>>> DEFINE_MTHP_STAT_ATTR(zswpout, MTHP_STAT_ZSWPOUT); > > > >>>> DEFINE_MTHP_STAT_ATTR(swpin, MTHP_STAT_SWPIN); > > > >>>> +DEFINE_MTHP_STAT_ATTR(swpin_fallback, MTHP_STAT_SWPIN_FALLBACK)= ; > > > >>>> +DEFINE_MTHP_STAT_ATTR(swpin_fallback_charge, MTHP_STAT_SWPIN_FA= LLBACK_CHARGE); > > > >>>> DEFINE_MTHP_STAT_ATTR(swpout, MTHP_STAT_SWPOUT); > > > >>>> DEFINE_MTHP_STAT_ATTR(swpout_fallback, MTHP_STAT_SWPOUT_FALLBAC= K); > > > >>>> #ifdef CONFIG_SHMEM > > > >>>> @@ -637,6 +639,8 @@ static struct attribute *anon_stats_attrs[] = =3D { > > > >>>> #ifndef CONFIG_SHMEM > > > >>>> &zswpout_attr.attr, > > > >>>> &swpin_attr.attr, > > > >>>> + &swpin_fallback_attr.attr, > > > >>>> + &swpin_fallback_charge_attr.attr, > > > >>>> &swpout_attr.attr, > > > >>>> &swpout_fallback_attr.attr, > > > >>>> #endif > > > >>>> @@ -669,6 +673,8 @@ static struct attribute *any_stats_attrs[] = =3D { > > > >>>> #ifdef CONFIG_SHMEM > > > >>>> &zswpout_attr.attr, > > > >>>> &swpin_attr.attr, > > > >>>> + &swpin_fallback_attr.attr, > > > >>>> + &swpin_fallback_charge_attr.attr, > > > >>>> &swpout_attr.attr, > > > >>>> &swpout_fallback_attr.attr, > > > >>>> #endif > > > >>>> diff --git a/mm/memory.c b/mm/memory.c > > > >>>> index 209885a4134f..774dfd309cfe 100644 > > > >>>> --- a/mm/memory.c > > > >>>> +++ b/mm/memory.c > > > >>>> @@ -4189,8 +4189,10 @@ static struct folio *alloc_swap_folio(str= uct vm_fault *vmf) > > > >>>> if (!mem_cgroup_swapin_charge_folio(foli= o, vma->vm_mm, > > > >>>> gfp,= entry)) > > > >>>> return folio; > > > >>>> + count_mthp_stat(order, MTHP_STAT_SWPIN_F= ALLBACK_CHARGE); > > > >>>> folio_put(folio); > > > >>>> } > > > >>>> + count_mthp_stat(order, MTHP_STAT_SWPIN_FALLBACK)= ; > > > >>>> order =3D next_order(&orders, order); > > > >>>> } > > > >>>> > > > >>>> -- > > > >>>> 2.45.0 > > > >>>> > > > >> > > Thanks > Barry