Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp3061354lqo; Tue, 14 May 2024 20:14:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUWF4OpzV1eNN9g3A1xB9aDSSijjKxBjpeZWdzgfPHkekjQ262swUu6XIi4GH6EWP8j3RcvhZL0SAH7dh4dUEzfeBkMQniuq5ux+tbk6Q== X-Google-Smtp-Source: AGHT+IFYcVQY4MqdgPKuRRf3VYAn2Woq4VJC7591ztxED8phML64qAgvo+dDFyseBhV4BuzzQJmv X-Received: by 2002:a17:906:44b:b0:a5a:8cc0:8c23 with SMTP id a640c23a62f3a-a5a8cc08dffmr190728566b.27.1715742869932; Tue, 14 May 2024 20:14:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715742869; cv=pass; d=google.com; s=arc-20160816; b=GXxAzZDdEjOJOJ/9WWTwoSkgN4ofiNGQlUWB3pQcpKdC9pIP4GMqw4zZGd5TSDtgoY o4rGGeqf1k6DE/U7st0neichZ9e/P9bpfsqZpMHq4p+c1XEeENDu6BAYyrOE/WxCZ1ea +T3KfKxnM58+gBBNFk8xGPKZ9gmXbhYQ88zqzGBnPmnLd/OU0djmKiWpR6MhsqT1esfC vdUhlhoQRQWl6UG3U3V4oD8PWcsW66bUoNy9NEOiyYu2OGflJqI0ZP4eAaHh7uaNckxP 7P48qOpEB8Hl9netFQpboClJAp95suehgwlkHyQjy2rns1iY29NPXriesNofuWcVlj1A txeQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=UJuzwdjUXcXXpYmOq4Y06/gX6rCmcwYb4f6sZ0kESE0=; fh=VTwbX1hDfBe0HiKt2fsM3I1pgKInCEZqvkUMRJuW8xc=; b=C2a6/bfKlpCa7LJztf8Nd2E/7ZDOGastH+dmBWxIpSgisvwFhWMt4YB8Sl4d+aYGlf JWPN7JYNQLwsoNhva+qV2AyipLi/sCsk3t5CEq4q4wk1BsZXOWy0bVyMk9dP43QWGN6g enQAASON1myJvBzfckvF8AyMv8ZYmDqqk02O9MrmqfCQ9Lzx7dZhIYJ1KxZ5aQAaMYwH pzdLR5OgBvdc3LxQp8DBtCsTlL3ZsIvJmqRIVUOzNI0EUXX65xD2zv/zNi3fFSDjAwjA YB5sVPKehKG7g7GpVrRH9/06P2wUYMusf879l8lXZgiU6+nQuoUdwyWTwWHo0IIo38pf IeTQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=Sm7Jg0zX; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-179370-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179370-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733c3628a5si6955645a12.488.2024.05.14.20.14.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 20:14:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179370-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=Sm7Jg0zX; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-179370-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179370-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8A0591F22764 for ; Wed, 15 May 2024 03:14:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A9F4838DD1; Wed, 15 May 2024 03:14:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="Sm7Jg0zX" Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8338E38385 for ; Wed, 15 May 2024 03:14:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.119 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715742857; cv=none; b=ps6SnXvaX5VB+LzGAhTn9CA1v1oOO7FdKcyG6htnqmUmqO/5rTILFKHUG80z1c/2W5eOEgA9lzNt6YHADeNX1SuaMYnKa7XoipG8aNhhuX9iZG7z6tFSmtnfScXic2Y7oZi8w3TVThI8wmw3kwmenkeyk1rAIWJByWHpQlI7neI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715742857; c=relaxed/simple; bh=TUvjzLLBV5p6w6yO+WR7yOiWHvvv+8d3ODga/cU1Gpc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=DtjxPD73rRbDvxK6tLznZLc0LeGs2Emsg2nwNsDgtrzEWgzUOzt6otd4sG/Olrtl4wpQzdZ9ze958208cYblFM0AfmZ1ygOAbibplvP4JrCxd+P6I6AvhIytHzAO0QzXa7YeVd18qGfmjwp4dbRa5RgLix/MnzuWpn/NRbbICGA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=Sm7Jg0zX; arc=none smtp.client-ip=115.124.30.119 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1715742853; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=UJuzwdjUXcXXpYmOq4Y06/gX6rCmcwYb4f6sZ0kESE0=; b=Sm7Jg0zX3Oy34tc8KZ3XQAHzCSvNgYqleesSL65IckWfyUQel41H3mtxsANPlM5xWUJB90RlNC1jUYb881El1QRXJAnMhmE4wRAQFqwNlLdy3wPvAkuUHW183Gz00FU+xqViO2nWRI56UpSz2amRk51xQ4AE9KowYx4sYd33+os= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R781e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033068173054;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0W6WW.n8_1715742850; Received: from 30.97.56.58(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W6WW.n8_1715742850) by smtp.aliyun-inc.com; Wed, 15 May 2024 11:14:11 +0800 Message-ID: Date: Wed, 15 May 2024 11:14:10 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 7/7] mm: shmem: add mTHP counters for anonymous shmem To: Lance Yang Cc: akpm@linux-foundation.org, hughd@google.com, willy@infradead.org, david@redhat.com, wangkefeng.wang@huawei.com, ying.huang@intel.com, 21cnbao@gmail.com, ryan.roberts@arm.com, shy828301@gmail.com, ziy@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: From: Baolin Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2024/5/14 22:49, Lance Yang wrote: > Hi Baolin, > > On Mon, May 13, 2024 at 1:08 PM Baolin Wang > wrote: >> >> Add mTHP counters for anonymous shmem. >> >> Signed-off-by: Baolin Wang >> --- >> include/linux/huge_mm.h | 3 +++ >> mm/huge_memory.c | 6 ++++++ >> mm/shmem.c | 18 +++++++++++++++--- >> 3 files changed, 24 insertions(+), 3 deletions(-) >> >> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h >> index b5339210268d..e162498fef82 100644 >> --- a/include/linux/huge_mm.h >> +++ b/include/linux/huge_mm.h >> @@ -281,6 +281,9 @@ enum mthp_stat_item { >> MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE, >> MTHP_STAT_ANON_SWPOUT, >> MTHP_STAT_ANON_SWPOUT_FALLBACK, >> + MTHP_STAT_FILE_ALLOC, >> + MTHP_STAT_FILE_FALLBACK, >> + MTHP_STAT_FILE_FALLBACK_CHARGE, >> __MTHP_STAT_COUNT >> }; >> >> diff --git a/mm/huge_memory.c b/mm/huge_memory.c >> index d3080a8843f2..fcda6ae604f6 100644 >> --- a/mm/huge_memory.c >> +++ b/mm/huge_memory.c >> @@ -555,6 +555,9 @@ DEFINE_MTHP_STAT_ATTR(anon_fault_fallback, MTHP_STAT_ANON_FAULT_FALLBACK); >> DEFINE_MTHP_STAT_ATTR(anon_fault_fallback_charge, MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE); >> DEFINE_MTHP_STAT_ATTR(anon_swpout, MTHP_STAT_ANON_SWPOUT); >> DEFINE_MTHP_STAT_ATTR(anon_swpout_fallback, MTHP_STAT_ANON_SWPOUT_FALLBACK); >> +DEFINE_MTHP_STAT_ATTR(file_alloc, MTHP_STAT_FILE_ALLOC); >> +DEFINE_MTHP_STAT_ATTR(file_fallback, MTHP_STAT_FILE_FALLBACK); >> +DEFINE_MTHP_STAT_ATTR(file_fallback_charge, MTHP_STAT_FILE_FALLBACK_CHARGE); >> >> static struct attribute *stats_attrs[] = { >> &anon_fault_alloc_attr.attr, >> @@ -562,6 +565,9 @@ static struct attribute *stats_attrs[] = { >> &anon_fault_fallback_charge_attr.attr, >> &anon_swpout_attr.attr, >> &anon_swpout_fallback_attr.attr, >> + &file_alloc_attr.attr, >> + &file_fallback_attr.attr, >> + &file_fallback_charge_attr.attr, >> NULL, >> }; >> >> diff --git a/mm/shmem.c b/mm/shmem.c >> index 8b020ff09c72..fd2cb2e73a21 100644 >> --- a/mm/shmem.c >> +++ b/mm/shmem.c >> @@ -1786,6 +1786,9 @@ static struct folio *shmem_alloc_and_add_folio(struct vm_fault *vmf, >> >> if (pages == HPAGE_PMD_NR) >> count_vm_event(THP_FILE_FALLBACK); >> +#ifdef CONFIG_TRANSPARENT_HUGEPAGE >> + count_mthp_stat(order, MTHP_STAT_FILE_FALLBACK); >> +#endif > > Seems like we don't need these conditional compilation directives here. > > The THP_FILE_FALLBACK above will result in a compilation error if > CONFIG_TRANSPARENT_HUGEPAGE is not defined. So we don't > worry about that :) > > See THP_FILE_FALLBACK in include/linux/vm_event_item.h. > >> order = next_order(&suitable_orders, order); >> } >> } else { >> @@ -1805,9 +1808,15 @@ static struct folio *shmem_alloc_and_add_folio(struct vm_fault *vmf, >> if (xa_find(&mapping->i_pages, &index, >> index + pages - 1, XA_PRESENT)) { >> error = -EEXIST; >> - } else if (pages == HPAGE_PMD_NR) { >> - count_vm_event(THP_FILE_FALLBACK); >> - count_vm_event(THP_FILE_FALLBACK_CHARGE); >> + } else if (pages > 1) { >> + if (pages == HPAGE_PMD_NR) { >> + count_vm_event(THP_FILE_FALLBACK); >> + count_vm_event(THP_FILE_FALLBACK_CHARGE); >> + } >> +#ifdef CONFIG_TRANSPARENT_HUGEPAGE >> + count_mthp_stat(folio_order(folio), MTHP_STAT_FILE_FALLBACK); >> + count_mthp_stat(folio_order(folio), MTHP_STAT_FILE_FALLBACK_CHARGE); >> +#endif > > As above. > >> } >> goto unlock; >> } >> @@ -2178,6 +2187,9 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, >> if (!IS_ERR(folio)) { >> if (folio_test_pmd_mappable(folio)) >> count_vm_event(THP_FILE_ALLOC); >> +#ifdef CONFIG_TRANSPARENT_HUGEPAGE >> + count_mthp_stat(folio_order(folio), MTHP_STAT_FILE_ALLOC); >> +#endif > > As above. > > Perhaps we need to define MTHP_STAT_FILE_ALLOC and friends > using a same way as THP_FILE_ALLOC, set as '{ BUILD_BUG(); 0; }' > If CONFIG_TRANSPARENT_HUGEPAGE is not defined. > > Likely: > > #ifndef CONFIG_TRANSPARENT_HUGEPAGE > #define MTHP_STAT_FILE_ALLOC ({ BUILD_BUG(); 0; }) > ... > #endif This is not enough, and we should also define a dummy function for count_mthp_stat() when CONFIG_TRANSPARENT_HUGEPAGE is not enabled. I was also hesitant about doing this before, but adding macro controls seems relatively simple:) Thanks for reviewing.