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 72F77C67861 for ; Fri, 5 Apr 2024 09:24:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 054856B0135; Fri, 5 Apr 2024 05:24:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F1E6A6B0137; Fri, 5 Apr 2024 05:24:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D97D26B0138; Fri, 5 Apr 2024 05:24:57 -0400 (EDT) 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 B16696B0135 for ; Fri, 5 Apr 2024 05:24:57 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 678C1810B7 for ; Fri, 5 Apr 2024 09:24:57 +0000 (UTC) X-FDA: 81974943834.02.6870CEE Received: from mail-ua1-f54.google.com (mail-ua1-f54.google.com [209.85.222.54]) by imf09.hostedemail.com (Postfix) with ESMTP id 9A96614000A for ; Fri, 5 Apr 2024 09:24:55 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TFEsjzgd; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf09.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.222.54 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=1712309095; 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=EQFv4zvUIz/GMVT/toPpHj+I12K++yaAhiP6ryBUA4k=; b=4/1Np7A5VveEvghXkyZFlU6y+PVhRbMexY83/MBtBuMI2mfrN7novSP+xQ05oGSwOTeZXs +G8UocnAtvlQA0OyVjsfi8+SQmSVFXr/u/H4SudZJa0drOeupFoDPBp9GxazsBue39i0i3 30U1dq8zj9wSE+7cXpywpdrdOZKXiS4= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TFEsjzgd; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf09.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.222.54 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712309095; a=rsa-sha256; cv=none; b=jAJw0C63qOxznXUm/nll1qdltF4sSsS1YBEqraME0EBhiEyxUuVRB/ePqx2M2JEcx726W2 w3Mwytvh+fnZlYNtRNaNZjgj9ufjBfsmTpDfH4flXx50m9NAKcZvPRD6BNjTPTIf5qz+Ts Zpa51vin4EcGC/BlWQyZUndPhqrekWg= Received: by mail-ua1-f54.google.com with SMTP id a1e0cc1a2514c-7e3b3e33ab9so645867241.1 for ; Fri, 05 Apr 2024 02:24:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712309095; x=1712913895; 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=EQFv4zvUIz/GMVT/toPpHj+I12K++yaAhiP6ryBUA4k=; b=TFEsjzgdcE7xtYX8eDeco2AVol7xxc6DzdS8ErdU79Y0eBPTPT2dt7XQQoyP/cJ0v0 gx/YPLhTvOCYi38pp4hSNghEbdEI6U1+I1nGhYjOqw9yNhm3htvMhx8yTWJTsS3iQIKH 7V+XWBEtK2pIhdfpQOWB7QFgg3VhHlXIyfz0HWiLX+vVhDerE9nnnKvOOKIm8aEVasct 3FJcXhrccUZ6lFJFs5GiBpGbgMLlwN/RCTJz6HtY26DazQPteUqWqGRF9TFqItkOBmS4 JbfhXo6Q/nqlWrnsEYYxWUcFhQjIjTcvKgt1UTzOxUjjfv97Z0c5lp+meTQ7iyHGQB7+ 5SNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712309095; x=1712913895; 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=EQFv4zvUIz/GMVT/toPpHj+I12K++yaAhiP6ryBUA4k=; b=UxHRzGW+achmh2hV0uclqcEExCtwmeMWVmS53rRuJTYaPDKAfvas0w4Q8/5GW9ncVA eS33f6EbrRWC2HwH7bKkzucqGvRripWlGVqzmWsFsLeS5G/DTFsXcAQUj0usUaJWLNlf 5oLvVR+E1hjji3jH8QVDh7GLWIoATN/mkADy3jsCxEc4kmyNiNsCct+rG6hxfjQh5J/z /bDqgKu8FMI5OF2S1uKDGMl2+okwrKANUtZaMUIWXZZPIL5+9zlilW3x2XHOLMiYSY07 U/xE92wS5c9hNghTRnBVx5W2cN69gpBHO28VXunFBv3/epyRQjnBE4Nkma0bX6V7PmYp XQqQ== X-Forwarded-Encrypted: i=1; AJvYcCW6+Sexx0rORV3RLtEom4hSmdksCgRU5pjPZVYzDgyrR1I4wWjO23kfiTawNbJo7vA8U04OZsqDMaqZvNIDAqA5V70= X-Gm-Message-State: AOJu0YzM3WuNFWxqw8HZuXP7dOdnTOxF9ZvuLVLRePY0cVYRMwJuNGZV xgWn7fiWWIX2YlLUnqNJtZlSe7MnqOFvNcb++kwBCGMWpA2Vdp/O9DYuYin08Bv505pjyUmH9Wv EFulIfQdxEoDa3yK25q29OZ/vOrY= X-Google-Smtp-Source: AGHT+IHVJH4bu+djwUr9bZNuMl5CL8cLK/y3LDsc2MnWFUjj9Uryl7SJdEOYi4T+VcREGNh1kVMjV6hQFWZzKdd3dUU= X-Received: by 2002:a05:6102:1621:b0:479:dd02:919a with SMTP id cu33-20020a056102162100b00479dd02919amr1052668vsb.29.1712309094601; Fri, 05 Apr 2024 02:24:54 -0700 (PDT) MIME-Version: 1.0 References: <20240403035502.71356-1-21cnbao@gmail.com> <30392471-71f9-4eb1-8855-d9c12499346f@redhat.com> <38eee542-8567-4c42-ad63-778b4a20c153@redhat.com> In-Reply-To: <38eee542-8567-4c42-ad63-778b4a20c153@redhat.com> From: Barry Song <21cnbao@gmail.com> Date: Fri, 5 Apr 2024 22:24:43 +1300 Message-ID: Subject: Re: [PATCH v3] mm: add per-order mTHP alloc_success and alloc_fail counters To: David Hildenbrand Cc: Ryan Roberts , akpm@linux-foundation.org, linux-mm@kvack.org, cerasuolodomenico@gmail.com, chrisl@kernel.org, kasong@tencent.com, peterx@redhat.com, surenb@google.com, v-songbaohua@oppo.com, willy@infradead.org, yosryahmed@google.com, yuzhao@google.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 9A96614000A X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: afp6seapcqsjj67k94apke51m5pf1xky X-HE-Tag: 1712309095-889131 X-HE-Meta: U2FsdGVkX1+rDDf5vcoieep+ev0B8lUfwcHa1jddpPzw1wZmhg6a1sFKX6JHTwcYcfG4f1uJ8UPlHU199UEktMspSNlJX3sbzKQF1WVqKiUfh1n7FutT26HXEnlT8WdbvF99BTk1znRKoH4wnNkxKKgBmnRcybbsjQg3ynrKOu2Z/JTCJuJSVj/z5t0H4NpFGS7hiAJe0be/w0Xhl/eHedGDHFIBl3H9qGId6/VT5kXSpp7UeLs+NViHuAbtr9RnFWT4SxJG9cnDq7tnMJ2hvZBQ7YTq8pa4jayE/kWhagO3cORyHRHl68RNsWXuPbcxQQoanQ01Uv7mbsq3SVZo2bTK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ZYZHptCi0nOI5G/NO2If1Ry6TpUeeV5fW69SRvigD8w+DWeVNEivrYzPlZbSm+mSjdEfbY6E4I+0nKQlIDRhYU2mhDFAiWi5/HtWnpmpLxi8IYJBzK1caZMxy3o1IXtfizW0vRGazD 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 Fri, Apr 5, 2024 at 10:04=E2=80=AFPM David Hildenbrand wrote: > > On 05.04.24 09:21, Ryan Roberts wrote: > > On 05/04/2024 07:29, David Hildenbrand wrote: > >> On 05.04.24 06:01, Barry Song wrote: > >>> On Fri, Apr 5, 2024 at 3:57=E2=80=AFPM Barry Song <21cnbao@gmail.com>= wrote: > >>>> > >>>> On Fri, Apr 5, 2024 at 4:31=E2=80=AFAM David Hildenbrand wrote: > >>>>> > >>>>> On 04.04.24 09:21, Ryan Roberts wrote: > >>>>>> On 03/04/2024 22:00, Barry Song wrote: > >>>>>>> On Thu, Apr 4, 2024 at 12:48=E2=80=AFAM Ryan Roberts wrote: > >>>>>>>> > >>>>>>>> On 03/04/2024 09:22, David Hildenbrand wrote: > >>>>>>>>> On 03.04.24 05:55, Barry Song wrote: > >>>>>>>>>> From: Barry Song > >>>>>>>>>> > >>>>>>>>>> Profiling a system blindly with mTHP has become challenging du= e > >>>>>>>>>> to the lack of visibility into its operations. Presenting the > >>>>>>>>>> success rate of mTHP allocations appears to be pressing need. > >>>>>>>>>> > >>>>>>>>>> Recently, I've been experiencing significant difficulty debugg= ing > >>>>>>>>>> performance improvements and regressions without these figures= . > >>>>>>>>>> It's crucial for us to understand the true effectiveness of > >>>>>>>>>> mTHP in real-world scenarios, especially in systems with > >>>>>>>>>> fragmented memory. > >>>>>>>>>> > >>>>>>>>>> This patch sets up the framework for per-order mTHP counters, > >>>>>>>>>> starting with the introduction of anon_alloc_success and > >>>>>>>>>> anon_alloc_fail counters. Incorporating additional counters > >>>>>>>>>> should now be straightforward as well. > >>>>>>>>>> > >>>>>>>>>> Signed-off-by: Barry Song > >>>>>>>>>> --- > >>>>>>>>>> -v3: > >>>>>>>>>> * save some memory as order-0 and order-1 can't be THP, R= yan; > >>>>>>>>>> * rename to anon_alloc as right now we only support anon = to address > >>>>>>>>>> David's comment; > >>>>>>>>>> * drop a redundant "else", Ryan > >>>>>>>>>> > >>>>>>>>>> include/linux/huge_mm.h | 18 ++++++++++++++ > >>>>>>>>>> mm/huge_memory.c | 54 ++++++++++++++++++++++++++++= +++++++++++++ > >>>>>>>>>> mm/memory.c | 2 ++ > >>>>>>>>>> 3 files changed, 74 insertions(+) > >>>>>>>>>> > >>>>>>>>>> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h > >>>>>>>>>> index e896ca4760f6..5e9af6be9537 100644 > >>>>>>>>>> --- a/include/linux/huge_mm.h > >>>>>>>>>> +++ b/include/linux/huge_mm.h > >>>>>>>>>> @@ -70,6 +70,7 @@ extern struct kobj_attribute shmem_enabled_a= ttr; > >>>>>>>>>> * (which is a limitation of the THP implementation). > >>>>>>>>>> */ > >>>>>>>>>> #define THP_ORDERS_ALL_ANON ((BIT(PMD_ORDER + 1) - 1) = & ~(BIT(0) > >>>>>>>>>> | BIT(1))) > >>>>>>>>>> +#define THP_MIN_ORDER 2 > >>>>>>>>>> /* > >>>>>>>>>> * Mask of all large folio orders supported for file THP. > >>>>>>>>>> @@ -264,6 +265,23 @@ unsigned long thp_vma_allowable_orders(st= ruct > >>>>>>>>>> vm_area_struct *vma, > >>>>>>>>>> enforce_sysfs, orders); > >>>>>>>>>> } > >>>>>>>>>> +enum thp_event_item { > >>>>>>>>>> + THP_ANON_ALLOC_SUCCESS, > >>>>>>>>>> + THP_ANON_ALLOC_FAIL, > >>>>>>>>>> + NR_THP_EVENT_ITEMS > >>>>>>>>>> +}; > >>>>>>>>> > >>>>>>>>> Maybe use a prefix that resembles matches the enum name and is = "obviously" > >>>>>>>>> different to the ones in vm_event_item.h, like > >>>>>>>>> > >>>>>>>>> enum thp_event { > >>>>>>>>> THP_EVENT_ANON_ALLOC_SUCCESS, > >>>>>>>>> THP_EVENT_ANON_ALLOC_FAIL, > >>>>>>>>> __THP_EVENT_COUNT, > >>>>>>>>> }; > >>>>>>>> > >>>>>>>> FWIW, I'd personally replace "event" with "stat". For me "event"= only ever > >>>>>>>> increments, but "stat" can increment and decrement. An event is = a type of > >>>>>>>> stat. > >>>>>>>> > >>>>>>>> You are only adding events for now, but we have identified a nee= d for > >>>>>>>> inc/dec > >>>>>>>> stats that will be added in future. > >>>>>>> > >>>>>>> What about the below? > >>>>>>> > >>>>>>> enum thp_stat { > >>>> > >>>> It seems we still need to use enum thp_stat_item rather than thp_sta= t. > >>>> This follows > >>>> enum zone_stat_item > >>>> enum numa_stat_item > >>>> enum node_stat_item > >> > >> > >> Right, we can do that. > >> > >> [...] > >> > >>>> ok. > >>> > >>> Hi David, Ryan, > >>> > >>> I've named everything as follows. Please let me know if you have any = further > >>> suggestions before I send the updated version :-) > >>> > >>> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h > >>> index e896ca4760f6..cc13fa14aa32 100644 > >>> --- a/include/linux/huge_mm.h > >>> +++ b/include/linux/huge_mm.h > >>> @@ -264,6 +264,23 @@ unsigned long thp_vma_allowable_orders(struct > >>> vm_area_struct *vma, > >>> enforce_sysfs, orders); > >>> } > >>> > >>> +enum thp_stat_item { > >>> + THP_STAT_ANON_ALLOC, > >>> + THP_STAT_ANON_ALLOC_FALLBACK, > >>> + __THP_STAT_COUNT > >>> +}; > >>> + > >> > >> > >> Final bikeshedding: so we want to call all of that MTHP_, mthp_ etc, t= o make it > >> clearer that this is per mTHP size? > > > > Perviously we concluded that mTHP was only for commit logs, and in the = longer > > term we wanted THP to mean the full set of sizes like it does for huget= lb. > > Neither "mTHP" nor "multi-size THP" currently exist in the code base. > > True, but some indication that these are "per THP size" might be reasonab= le. It seems quite reasonable, especially considering the existence of THP coun= ters. Additionally, there's even an overlap between THP counters and mTHP counter= s, specifically for PMD_ORDER. This complexity could potentially confuse readers of the code. I'm perfectly fine with using "M/m" as a prefix, as long as sysfs hasn't exposed it. Moreover, "M/m" remains a preferable prefix given that "PER_SIZE" is overly long, and people are already familiar with the concept of mTHP. > > -- > Cheers, > > David / dhildenb >