From patchwork Sat Sep 9 15:52:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vern Hao X-Patchwork-Id: 13378209 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 DDF0AEEB580 for ; Sat, 9 Sep 2023 15:52:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C35FB6B0118; Sat, 9 Sep 2023 11:52:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BE5EA6B011A; Sat, 9 Sep 2023 11:52:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AAE8D6B011C; Sat, 9 Sep 2023 11:52:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9FFDB6B0118 for ; Sat, 9 Sep 2023 11:52:54 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 72CADB3695 for ; Sat, 9 Sep 2023 15:52:54 +0000 (UTC) X-FDA: 81217502268.14.5973459 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf20.hostedemail.com (Postfix) with ESMTP id B5AC11C000F for ; Sat, 9 Sep 2023 15:52:52 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=i4HTq36q; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of haoxing990@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=haoxing990@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694274772; a=rsa-sha256; cv=none; b=rk7BSitoMBQj6zJj41hga2m995R0hm84ec8FhWdhHEJykXqUFY17aFYYhyDDXGHh1vRPPR mQoD2ewbHjBiWOu3yVmQFC17MUowwL34Bn9XD0h8j8Df6ZGw7lstBHKmO6XtW29m1QOkx8 +pMtXHBBz7qx2EzCTb0kI1Knm0as4ko= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=i4HTq36q; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of haoxing990@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=haoxing990@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694274772; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=fgpa7ePPXDf81q5q2R0+qC0wZ59LoDUqcXyRaIm3KfE=; b=S0/s7hE+JCm/CgDq5wtA/SEfE2tyxDVnqLw7nfTqmDnjvGcJ8EFnj0fuMbsLSiJ25nc5Qv lM46fSLiGly6uBfpJ1oj5zyRI5A+pexj8FRPPhFHwiYn5WcqkRCl1QG2k+dflPCLY/S3/L RiCts/PIe9AMiRIm9L73vIkG4rydFsY= Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1bf6ea270b2so21789545ad.0 for ; Sat, 09 Sep 2023 08:52:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694274771; x=1694879571; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fgpa7ePPXDf81q5q2R0+qC0wZ59LoDUqcXyRaIm3KfE=; b=i4HTq36qmcHtahTC7BCgsZRvNtiuwkrvk0/jCa7EOkclSQZXY7J0KoJCGvBXfFipeP KUc4/1HcY8AsZMneD5YSgmKGHOCVgXc3O1kY4PniiGeT/M5FAwtJ5RPwIseOn4ozpJHn uZytIZXAF+g0Q/M0/dWzeinwrcL53ClmDXRTQKS+q60hpzf9wd6thSGc0FrGzXwz9K/1 j3gxC64lXin4wYBi8bE1Fj/VgMNAjiZWw2hRyGpmOZhRMPHjHJ69h/u+ny6Z6p5FSIDz RMTgoJFs6ZFkhycnAuh8C+T3MwuU9sz/E+CQhzsBRvLjKdRAgWhMiIxSHNHQfAib1aw+ Jwrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694274771; x=1694879571; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fgpa7ePPXDf81q5q2R0+qC0wZ59LoDUqcXyRaIm3KfE=; b=OOlKJBYiDphYaReffRpuxF+kN2tBVwjhUzapgoIMjlkXQMvxGCnc4if7VJklJkgiJm Kgs0NP8yNHzO7wx6x0pPgI6u0qI5Ca7lNZFfEmWDTMNFSd5WlzuXLwQRuXZBNumek4pU BtzGWcqewf9fFC79sYkTP770CfwzN2TY5qI13ZsCVweXBOBlZPMKORy5Gz7tQtuO978K UclJmB5s/9W9YCQ+7yDalenPDOSkxvrR92DaTtwRoIdA2gWGX+nSIx3vu1CNDCY9+dc7 SzY6Y0YxC14CFwNj34yUmQBVGT5b3bbhuhaFsV9PiGAotZqX7czOHPiaBobugjQKKO0T /FPA== X-Gm-Message-State: AOJu0YxrtdcIfMGahXLkpe5XjByVQelojmkOJ8vqiKKurA8MKnx19QAP stHF6aQ2312Zu/e2E/d+BBY= X-Google-Smtp-Source: AGHT+IHjDCzUL7bJiz6mFbSIE+EIH00p+G4f05fHtvMlNGOTIzh0y+NyM9MBHYLBf8fAqRHqNqAwIQ== X-Received: by 2002:a17:90a:4e47:b0:26b:2f9:a898 with SMTP id t7-20020a17090a4e4700b0026b02f9a898mr4980514pjl.47.1694274771484; Sat, 09 Sep 2023 08:52:51 -0700 (PDT) Received: from VERNHAO-MC1.tencent.com ([111.197.253.118]) by smtp.gmail.com with ESMTPSA id l2-20020a17090a72c200b0025bd4db25f0sm2894612pjk.53.2023.09.09.08.52.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 09 Sep 2023 08:52:51 -0700 (PDT) From: Xin Hao X-Google-Original-From: Xin Hao To: hannes@cmpxchg.org Cc: mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, akpm@linux-foundation.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, haoxing990@gmail.com Subject: [PATCH] mm: memcg: add THP swap out info for anonymous reclaim Date: Sat, 9 Sep 2023 23:52:41 +0800 Message-ID: <20230909155242.22767-1-vernhao@tencent.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B5AC11C000F X-Stat-Signature: j9fkji8u797r94ho5w9r6xx9m9yy98mk X-HE-Tag: 1694274772-109805 X-HE-Meta: U2FsdGVkX1/hbkTISusVzRCd59nePN6NlFjaJBGFUd6GGNx/AKrtpqQ8aRGWracQOqpshgf8DdKn0nukHAPQilO2BLzejPN/Hv1QS6Bijmp45BeWJGU0WX/BrWU1L61SiRQdB6Gs3V/7D0mYoD8L3xXfHP32bgoJdLrkdnQDEr12klM8FteVfeOTgu4oNibVrneOU6FpbjrIKG9WLhpWASyIKwf3W97aLBr5gKtefntk59s9CNrrIQSYOtPyn7O6TQ707DOMqtg5yb/W4l7AwC7sIkC+Pdx3C8b+z4MOLZL7gBLmwKMZUYBpwPQCJvNoo8Y5bHc7WMZxX/a/qILCC2+qdjKiSfIVTELO6DfdicN27EsJMjfj5ZBQMW8PTuNWbDF5+QQWaNMoBCEho3BNVFT5TLiPJcrLtTYADmRjTHPY9+rE7iDFEJmwWQq/RsNZIUEsqb3IR7bq09wU55RhkP5vE/GtvbtUC09GeFxQDfsArf7fqFFRxFJj2zAdNt4O05WNj0eICQBMli4Xz/9Z1YGXQ+emoMUg2VreV9MOb0WJ93wEjiHGxuEyfQHGLV8aJga66HTOw4bkAIQfQH+0lgjrCuA7w+/7+JExfxBattpnohGlmps71NciAaOmbfPnAi/QOZv15dtab0jSfB8znMHtGrx3W8gQavtylf8Ava2Voa9THi8jdJ4e0LulT3nSL2du+Y2heAIZvSpxNiF2UKRyTJFDpCVUpFd7KK9c4IeLYyPjPGIcfphbUewdQYWiLy0XA/r66PwbmicjEfFgfXv3I4D+8heV6hsAK6WyPOIjpJWHJg4COiIWVdzgnYbqE9VPgELEgV8vVLg3hSr1M0AeFnb/L9ZRlqXkPAjg3OmbDitqqksPQ1SbaZ/FdOgsilryBPYykzH+SDJr+r4bzIVvgCZBGVXTEVmZcAALMjFu1/ThO7hwf8wlz9ggx/LGgTcK+4dTSRL0xcBUzYB VYBSCLQX fZL1ilbMPI3S5tU8y7LdVekCYfqUcnGV2ysz5WYS1aaiV4BmTTKe9dhmYNyirJWfNnCQZaLHH1Of9uW6FT4LG8VPaJ157+JUm2KbZ5uUeaog1ym3xbBp3RKNP5BX6jAQDKcvKzCK5/4Zvtx+MPV1kyZ4mkCBW32dyzxbBbLSTfV6mYh1UtSof1QI/LVJt+XP24Ugc0B1F/aZ5mCHjDiOnMi6rZq0y/LGvAJ0aRr5cdnaFKFN51+izFzsEtm2MqHD+t/VkjDVVc+h0DXVSSyYvsS6b+J3AuG6SHJr9tIH3RoHM3o2J5NOdquxGNjZK0Q5QuCBdbKYykijjjl/JccbNfZS+8R8j12d2ZuStgWAtGqnSojpW27gsioxgs3nZb4lYQrfpuRPLVpoR7WOvRXl7Dr7IjyeiLAjYViz8SMX36xP6ptrIzdxM/bztX7v8lNFw12hJ 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: At present, we support per-memcg reclaim strategy, however we do not know the number of transparent huge pages being reclaimed, as we know the transparent huge pages need to be splited before reclaim them, and they will bring some performance bottleneck effect. for example, when two memcg (A & B) are doing reclaim for anonymous pages at same time, and 'A' memcg is reclaiming a large number of transparent huge pages, we can better analyze that the performance bottleneck will be caused by 'A' memcg. therefore, in order to better analyze such problems, there add THP swap out info for per-memcg. Signed-off-by: Xin Hao --- mm/memcontrol.c | 6 ++++++ mm/page_io.c | 4 +++- mm/vmscan.c | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index ecc07b47e813..a644f601e2ca 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -752,6 +752,8 @@ static const unsigned int memcg_vm_event_stat[] = { #ifdef CONFIG_TRANSPARENT_HUGEPAGE THP_FAULT_ALLOC, THP_COLLAPSE_ALLOC, + THP_SWPOUT, + THP_SWPOUT_FALLBACK, #endif }; @@ -4131,6 +4133,10 @@ static const unsigned int memcg1_events[] = { PGPGOUT, PGFAULT, PGMAJFAULT, +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + THP_SWPOUT, + THP_SWPOUT_FALLBACK, +#endif }; static void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s) diff --git a/mm/page_io.c b/mm/page_io.c index fe4c21af23f2..008ada2e024a 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -208,8 +208,10 @@ int swap_writepage(struct page *page, struct writeback_control *wbc) static inline void count_swpout_vm_event(struct folio *folio) { #ifdef CONFIG_TRANSPARENT_HUGEPAGE - if (unlikely(folio_test_pmd_mappable(folio))) + if (unlikely(folio_test_pmd_mappable(folio))) { + count_memcg_events(folio_memcg(folio), THP_SWPOUT, 1); count_vm_event(THP_SWPOUT); + } #endif count_vm_events(PSWPOUT, folio_nr_pages(folio)); } diff --git a/mm/vmscan.c b/mm/vmscan.c index ea57a43ebd6b..29a82b72345a 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1928,6 +1928,8 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, folio_list)) goto activate_locked; #ifdef CONFIG_TRANSPARENT_HUGEPAGE + count_memcg_events(folio_memcg(folio), + THP_SWPOUT_FALLBACK, 1); count_vm_event(THP_SWPOUT_FALLBACK); #endif if (!add_to_swap(folio))