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 17AA0E668A1 for ; Sun, 24 Nov 2024 07:11:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 677EF6B0082; Sun, 24 Nov 2024 02:11:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 600336B0083; Sun, 24 Nov 2024 02:11:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 479C96B0085; Sun, 24 Nov 2024 02:11:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 250946B0082 for ; Sun, 24 Nov 2024 02:11:20 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C7AB014018C for ; Sun, 24 Nov 2024 07:11:19 +0000 (UTC) X-FDA: 82820117436.18.7089C17 Received: from mail-vk1-f180.google.com (mail-vk1-f180.google.com [209.85.221.180]) by imf28.hostedemail.com (Postfix) with ESMTP id 106C3C000A for ; Sun, 24 Nov 2024 07:11:14 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Yl3EFyzM; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.221.180 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=1732432277; 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=sLzWC7PIwcFcnJcsDsiHmrWmwtgiy+vFsNne+lF+MOA=; b=flgHNMJDxlKSDMPBl2v7fkJjzQwdIU+PRQ5yxwMrKTHU757srviIW1to/18acsfVnOp6B+ Fg9TC3X3kNIUqUqV3o6cxlfbLzX/rDhtho9TDWchj5QZAbhVYk5vOIXqHOF5FVN4Fd12H4 E+nF//JPX++ByC6W6wtX7h1hagYmHkg= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Yl3EFyzM; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.221.180 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732432277; a=rsa-sha256; cv=none; b=e21DrcMDphJBOMovCqNEcMN2ftmT7LxWiEC6RrF+qvMPqF3Ki/KX6+/Si6wKX8dogdfQZb MKZ/9VnlmznSTupghmzJukzfOrYYYoy6KcJvMKj8D6lLWL71pwo1j+P8T+MLgOjPeI1WYi 6vHjYEEjJHQYjYhjjNVlDAaq2viSmrM= Received: by mail-vk1-f180.google.com with SMTP id 71dfb90a1353d-5152685b0d7so44770e0c.1 for ; Sat, 23 Nov 2024 23:11:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732432277; x=1733037077; 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=sLzWC7PIwcFcnJcsDsiHmrWmwtgiy+vFsNne+lF+MOA=; b=Yl3EFyzMWdw9HtIq9cLNMK9iwARnUEi+qbsjQazDztFIDd/1aLGuCsFyIMWN93N2Ws uM2JxeiXq5a3zkeqjEGiW6qI8cH5AeQb2EJQvdn6Npwdni4v52FpCpOs1B13fTAmQbRH V8XYTxaiSXfGxzD6x4T1gGy5FcXts8jp1lFerzgqAQIo2y7GLugdllnLKXSVY0qZ2utF m5wnPeR2NkmEbyTwVpTJXrgtkQWBEPn3xZgTN9lj3K2nBEgX7/nsbe62Okr77goZ1dfk Dtylf3Ihw+C5VutQrLI1a+nIHACJCUyhOSQyKGtw//UrNuK9kxsVwyXOApaOvR35ZE2b euAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732432277; x=1733037077; 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=sLzWC7PIwcFcnJcsDsiHmrWmwtgiy+vFsNne+lF+MOA=; b=MnmTfPUvuTiO2e5/Rd1uazNXke8Wz4qYdaQOugrQqetCAsGQMGx6YebVWf808lmBoe TbKE5YBO53jAUa/sHgQxvT0jbMtOX2wj7aLIaZWnJd4gsEz1+lxCJkgXLUS8qab1csoT MwcKGJdpDnActJ+/RccaqWrG3t7ZS3K1H2TLAjzK4VUNv+UVLY4dsvex69PxvNZe+1d9 d1T54INmwWGsbRbVoBh+S81qJ9fgPSXaaMjixo0bOA7ZAAuJMs35hPKM4gfAqMBOjNwe e6sW8CBDg8PgdlXp2Yia016PvUrfc67PPKkE5M7E8UpZVVEkuZk5sk/xaQpzefBjyfYA 56Vg== X-Forwarded-Encrypted: i=1; AJvYcCUmwPXmmv3MVF7rW/meMCEPcFM6zW7UDl0BuJv62PoUcUjlma6LXZ/4g+sDDepOEKbEpS7hlYA5kQ==@kvack.org X-Gm-Message-State: AOJu0YzU+40TkMbVKdMRdyBHElsDLAIT13rL/RKtwzRCrT5Mi70OoUkU k1AG3mbRTIWRiUGCzTooawq69BY+540K9NP4S20eH70ZDs/Uzn9mUWEPO2SK4w/TX3EjlN+i6iQ bvK4MDkODSEAvTwCGVAHxMBLrrLM= X-Gm-Gg: ASbGnctm6YvEqaguqGm1OM2OqeMBwwSFruW2RwiFqa4UvPr70ASacMLMP3xkY1mt/pa yRB4MANd+VZjLjbAau/KDeBYYjE+iV5gpogGwZV7cEjfuNWcgXYe3ZkBwM2XSlFSvkA== X-Google-Smtp-Source: AGHT+IEM0MIsZ6PBBeeeFX0gjDh35wvArpcl66cKwh1CS3kKhICjwIBFKhYzisYss2ktb2IzdxqhjmcDB+mk8vXFVaE= X-Received: by 2002:a05:6122:4d82:b0:50d:2769:d757 with SMTP id 71dfb90a1353d-51500b6c0b6mr8219721e0c.11.1732432277004; Sat, 23 Nov 2024 23:11:17 -0800 (PST) MIME-Version: 1.0 References: <20241122161443.34667-1-haowenchao22@gmail.com> <24ea047a-7294-4e7a-bf51-66b7f79f5085@gmail.com> In-Reply-To: From: Barry Song <21cnbao@gmail.com> Date: Sun, 24 Nov 2024 15:11:05 +0800 Message-ID: Subject: Re: [PATCH v2] mm: add per-order mTHP swap-in fallback/fallback_charge counters To: Lance Yang 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-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 106C3C000A X-Stat-Signature: jb6uc5rjow8jtod9w8ko7zeij3hoebyg X-HE-Tag: 1732432274-15371 X-HE-Meta: U2FsdGVkX1/eFyRhJgS/zS0kLerlwhVpjWQooPK2TNtokDwgJD5wz8YTPFrtFvHLKhYFBUUvcbN0izg6Na7ZOI9cS3qgGnInr8jntzgYhRGZjOmU37KY7PMBgL0hHXEpf7jXZMgZEXkVRoNYOOEUWrLplSLqRYeovrCnq8BdPhNR+gzDxwT/hQhg3TtkabDympg1+LvxUYEbUrTtGvAg2a5TRVDXn83P3+r5DFbfd2xzFJBY/xXImRJ+CYkRMP52ShnHNsW+sIurXoFPNg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/cnIUk/BMIsKM+syPAbdjPJEQL02N5nqCH4NlcMRIrZ4= 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 2:56=E2=80=AFPM Lance Yang wr= ote: > > 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.com= > 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 method = to > > >>>> analyze their success ratio. Similar to anon_fault_fallback, we in= troduce > > >>>> per-order mTHP swpin_fallback and swpin_fallback_charge counters f= or > > >>>> 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/Document= ation/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 c= harge > > >>> + it and instead falls back to using small pages. > > >>> > > >>> +swpin_fallback_charge > > >>> + is incremented if a huge page swapin fails to charge it and= instead > > >>> + falls back to using small pages even though the allocation = 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 original > > version, I=E2=80=99ve removed the word =E2=80=9Chuge=E2=80=9D from the = first line, and it now > > looks almost identical to anon_fault_fallback/anon_fault_fallback_charg= e. > > 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 feels = less natural to me because "page swapin" sounds quite odd - we often hear "page fault," but we have never encountered "page swapin." 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. > > 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 and > > 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 or = charge > > >>>> + a huge page and instead falls back to using huge pages wit= h > > >>>> + lower orders or small pages. > > >>>> + > > >>>> +swpin_fallback_charge > > >>>> + is incremented if a page swapin fails to charge a huge pag= e and > > >>>> + instead falls back to using huge pages with lower orders o= r > > >>>> + 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, MTH= P_STAT_ANON_FAULT_FALLBACK); > > >>>> DEFINE_MTHP_STAT_ATTR(anon_fault_fallback_charge, MTHP_STAT_ANON_= 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_FALL= BACK_CHARGE); > > >>>> DEFINE_MTHP_STAT_ATTR(swpout, MTHP_STAT_SWPOUT); > > >>>> DEFINE_MTHP_STAT_ATTR(swpout_fallback, MTHP_STAT_SWPOUT_FALLBACK)= ; > > >>>> #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(struc= t vm_fault *vmf) > > >>>> if (!mem_cgroup_swapin_charge_folio(folio,= vma->vm_mm, > > >>>> gfp, e= ntry)) > > >>>> return folio; > > >>>> + count_mthp_stat(order, MTHP_STAT_SWPIN_FAL= LBACK_CHARGE); > > >>>> folio_put(folio); > > >>>> } > > >>>> + count_mthp_stat(order, MTHP_STAT_SWPIN_FALLBACK); > > >>>> order =3D next_order(&orders, order); > > >>>> } > > >>>> > > >>>> -- > > >>>> 2.45.0 > > >>>> > > >> Thanks Barry