From patchwork Fri Sep 13 08:44:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingxiang Zeng X-Patchwork-Id: 13803152 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 5A60CFA3732 for ; Fri, 13 Sep 2024 08:45:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DFFA76B00CE; Fri, 13 Sep 2024 04:45:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DA76B6B00CF; Fri, 13 Sep 2024 04:45:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C6DDF6B00D0; Fri, 13 Sep 2024 04:45:07 -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 A8A8D6B00CE for ; Fri, 13 Sep 2024 04:45:07 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 15F2A1C6F8D for ; Fri, 13 Sep 2024 08:45:07 +0000 (UTC) X-FDA: 82559080254.18.5246E9C Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by imf26.hostedemail.com (Postfix) with ESMTP id 3804A140022 for ; Fri, 13 Sep 2024 08:45:05 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Um6Lz/pJ"; spf=pass (imf26.hostedemail.com: domain of jingxiangzeng.cas@gmail.com designates 209.85.215.181 as permitted sender) smtp.mailfrom=jingxiangzeng.cas@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=1726217000; 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:in-reply-to:references:references:dkim-signature; bh=FUS5oZWz1q1hL0PjDhEQP80uJLgD2DBG0JdaSzX6lAM=; b=CsFS9JbDXFRtz3LLt4AfnRmprMhGQ2FEGuElLWpprUjGnMCdzI9MxjRb847nyH3hP9YnCv YjBT1PzWOJakXluitAczlbk8op9Qn3f4yHbSUrrwS7I+NWDhkloMKwc2MP7WboenzU/NX0 P8+rAvN3JM1qC9E5vfNC+Ei/putFG4Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726217000; a=rsa-sha256; cv=none; b=LEgp5faAudIpwyCcPm+wZ89HHj49e+KjYHuJgS0tJyQ29fc2yuBZlWLm9J8nr1om4gG+ey ZRfc8BZbfxfgDBOtk/5XDSLn1eTM0wLF5Oxs6J8mrYI9FxQlazt8tA3yp3l5Qnwgx9QZHc qD3/UK4zmnX8L3AS3QDMWOekaNs0crY= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Um6Lz/pJ"; spf=pass (imf26.hostedemail.com: domain of jingxiangzeng.cas@gmail.com designates 209.85.215.181 as permitted sender) smtp.mailfrom=jingxiangzeng.cas@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-70b2421471aso427856a12.0 for ; Fri, 13 Sep 2024 01:45:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726217103; x=1726821903; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FUS5oZWz1q1hL0PjDhEQP80uJLgD2DBG0JdaSzX6lAM=; b=Um6Lz/pJCgkZmtp21pfiik0tYHWV8SxCoiJBGMbgFNtq0sQzr5sAqsZQjLM1FKqSM+ yuG1E5Y6TtUD8CZheBPR9j5A+YRQ7zvbAjpnnwvVIcPYtUmc8IHOzxtvSV1FwkglAfDv L45n8I5pD8u5SnSG9vrwAHfVoT+6AHSPrdEx4Bs8VWZkqU4zKvfz6y25Mob6spdb73f7 F/iETlrTz/h3WicJH5+918vtlKreDBP4ELfNzN/3/hKGpxL2GNVU9wdRAKOvGoEYMHud fAQp/sQuA1LzPu2tWbKTC8qY2GaaMGC9GXvbROXB7IogTH7j4N9/tv7yg2WOlhrQAdyK TZYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726217103; x=1726821903; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FUS5oZWz1q1hL0PjDhEQP80uJLgD2DBG0JdaSzX6lAM=; b=RVIOj7ceNpObh6ScreDclNnXzzMWiuwtCSG13BDsyrE5+KJOxTNrYAXHfwoJpuhZnd uEz4tCP/omfhtyVLFdGgYlVtZeEPl3pvOoajZ5uN7ok4aGtT9Kym16nfAZaUa5nj5l3p pse6IenTsbeyGsxpDU1Mv0Lt5429V8IpE8yFP0fot0JtEKuyV46v7165ahGaeno6lELd wrPpH8kn0WU4zXLqygDDuXU/RB5s/zC0AH8apQwUst4evyc61TygD5hBAImYvshBG+gt G5MbYJDBeC8zLjqljF8QiAxcuXd6IGpXC16i3QK+wF9/CJH5DmlnjGbCXRYD31pgsDeI s0Qg== X-Gm-Message-State: AOJu0YyErunmb0SO8/yoWWI52sRN6FZzqUZ9sOgdV/RuYZhQgvhLwC0O /tZtr73ley3UEUfA7biAooXGfE2aOCzFzawo12lvwXLWWidoYjWzYAJiZ0qF X-Google-Smtp-Source: AGHT+IFM3fsIXbQsAGSP8vEDOA2RW06x2PLYcdAG+HgQRZL8tAE5rlmiB9X133hAyyTkQv9uiljeEQ== X-Received: by 2002:a05:6a20:c6ce:b0:1cf:4fa8:49f2 with SMTP id adf61e73a8af0-1d112eb2521mr2897580637.49.1726217103144; Fri, 13 Sep 2024 01:45:03 -0700 (PDT) Received: from localhost.localdomain ([14.22.11.161]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8506sm5696295b3a.5.2024.09.13.01.44.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 01:45:02 -0700 (PDT) From: Jingxiang Zeng To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, cgroups@vger.kernel.org, hannes@cmpxchg.org, linuszeng@tencent.com, linux-kernel@vger.kernel.org, mhocko@kernel.org, muchun.song@linux.dev, roman.gushchin@linux.dev, shakeel.butt@linux.dev, yosryahmed@google.com Subject: [PATCH V2] mm/memcontrol: add per-memcg pgpgin/pswpin counter Date: Fri, 13 Sep 2024 16:44:53 +0800 Message-ID: <20240913084453.3605621-1-jingxiangzeng.cas@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 3804A140022 X-Stat-Signature: pjjtssqgnd67atcg53hbapjkzotx6u8o X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1726217104-559976 X-HE-Meta: U2FsdGVkX1+UVEzDot+3Yl6IlYTKdv/jIW6Np1dNU403pr4YMLJiANrT/LgNUMRyrk4Yh+RedidKHsG5q4HDsvsx00aJMuET9thcwHn1qrUjUJDpJPvQGd+GOtR+47PF+qN+L6XDIcfPWGCBQVmXwLMJv60XGKv6sez5gQKqhGbd7454iZhkF68N1Bmx5tUBMyKLLkjdCjyc5N3s6lOfgGctCxwEkg/LYWDcI7mjqgkwaIzhW//xMbcioi/K9ZgcU/++k6hpzESnFyupYgd1BVppTFBzrsldZH8BuGqDRUY0SJtMY/z1MvCDafQnTeJxTnIgTYsgf/Ab4/MgbcRSS4Kfm2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iXsB0FNQ4rs81JhYou4x+afIncr9bmsihHX0jROqMzCJgRh2Sq9QJOvPOvS90ik8zCYXy+PXC0AfEMtF/mlLqEJI+vfEiJZ+0F67CBRL3/Hbo+9zRKbIZVeRQD2Avxi+lTknp 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: From: Jingxiang Zeng In proactive memory reclamation scenarios, it is necessary to estimate the pswpin and pswpout metrics of the cgroup to determine whether to continue reclaiming anonymous pages in the current batch. This patch will collect these metrics and expose them. Link: https://lkml.kernel.org/r/20240830082244.156923-1-jingxiangzeng.cas@gmail.com Signed-off-by: Jingxiang Zeng Cc: Johannes Weiner Cc: Michal Hocko Cc: Muchun Song Cc: Roman Gushchin Cc: Shakeel Butt Signed-off-by: Andrew Morton Acked-by: Nhat Pham --- mm/memcontrol.c | 2 ++ mm/page_io.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 6efbfc9399d0..dbc1d43a5c4c 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -418,6 +418,8 @@ static const unsigned int memcg_vm_event_stat[] = { PGPGIN, PGPGOUT, #endif + PSWPIN, + PSWPOUT, PGSCAN_KSWAPD, PGSCAN_DIRECT, PGSCAN_KHUGEPAGED, diff --git a/mm/page_io.c b/mm/page_io.c index b6f1519d63b0..4bc77d1c6bfa 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -310,6 +310,7 @@ static inline void count_swpout_vm_event(struct folio *folio) } count_mthp_stat(folio_order(folio), MTHP_STAT_SWPOUT); #endif + count_memcg_folio_events(folio, PSWPOUT, folio_nr_pages(folio)); count_vm_events(PSWPOUT, folio_nr_pages(folio)); } @@ -505,6 +506,7 @@ static void sio_read_complete(struct kiocb *iocb, long ret) for (p = 0; p < sio->pages; p++) { struct folio *folio = page_folio(sio->bvec[p].bv_page); + count_memcg_folio_events(folio, PSWPIN, folio_nr_pages(folio)); folio_mark_uptodate(folio); folio_unlock(folio); } @@ -588,6 +590,7 @@ static void swap_read_folio_bdev_sync(struct folio *folio, * attempt to access it in the page fault retry time check. */ get_task_struct(current); + count_memcg_folio_events(folio, PSWPIN, folio_nr_pages(folio)); count_vm_event(PSWPIN); submit_bio_wait(&bio); __end_swap_bio_read(&bio); @@ -603,6 +606,7 @@ static void swap_read_folio_bdev_async(struct folio *folio, bio->bi_iter.bi_sector = swap_folio_sector(folio); bio->bi_end_io = end_swap_bio_read; bio_add_folio_nofail(bio, folio, folio_size(folio), 0); + count_memcg_folio_events(folio, PSWPIN, folio_nr_pages(folio)); count_vm_event(PSWPIN); submit_bio(bio); }