From patchwork Fri Aug 30 08:22:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingxiang Zeng X-Patchwork-Id: 13784543 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 DA661CA0EEF for ; Fri, 30 Aug 2024 08:22:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6609A6B00D4; Fri, 30 Aug 2024 04:22:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E9676B00D5; Fri, 30 Aug 2024 04:22:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 463A26B00D6; Fri, 30 Aug 2024 04:22:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 258346B00D4 for ; Fri, 30 Aug 2024 04:22:57 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9E0AF1A1649 for ; Fri, 30 Aug 2024 08:22:56 +0000 (UTC) X-FDA: 82508221152.29.B37CBCD Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by imf03.hostedemail.com (Postfix) with ESMTP id C2A232002D for ; Fri, 30 Aug 2024 08:22:54 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="RKZ/0+Oq"; spf=pass (imf03.hostedemail.com: domain of jingxiangzeng.cas@gmail.com designates 209.85.215.172 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=1725006084; h=from:from:sender:reply-to: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=8ewjWosioynS9QjLJzPP/p/LP8/+o765Ca4TuY9GDfQ=; b=5trdzPgV+m2eNkKPoO6tpy4opsU+coAVuqUlvQHugfDoRQa1U8tFRqqr2qdeQoySiLaIOR rm7xrfqjirsa+nWvzsQxeT1GAiu0Ew7LA07ttJ+EKLG6h8r9n3Bg7/gV9Fk3zgQpzkAfMn YYbcjczOgcNNjhh+fZc2FzI+K1tDkJE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725006084; a=rsa-sha256; cv=none; b=eKT/J/ABXOMIsbIqZyTy3S4eg9hfMidtX1+7SMwFw/HI0FJUmLK6otT8GgELjhG8l1NUwY 0YwPDHG2h7FuSIPC3ZxpikHBkbokjlMBmJFnOKky90JZOG/G4QawS5k6hacG/pK9L3nCJU k82cteL17CdCuGlIAeWwRfrkAz81RJE= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="RKZ/0+Oq"; spf=pass (imf03.hostedemail.com: domain of jingxiangzeng.cas@gmail.com designates 209.85.215.172 as permitted sender) smtp.mailfrom=jingxiangzeng.cas@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-6e7b121be30so949687a12.1 for ; Fri, 30 Aug 2024 01:22:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725006173; x=1725610973; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=8ewjWosioynS9QjLJzPP/p/LP8/+o765Ca4TuY9GDfQ=; b=RKZ/0+OqFvPdvx00v/naGmbXRlRX1WOLiiBrXJRskaqpC1vrqF3z6Ut00rthAamEB8 CP93jReI+BMyzaHZdHR15fGpj66YPIcZ+Bw6NI3RfzkQuhpMnl9zOWijBYnRFkFJjyjw IF2KjR95ljDy1qzzI1bj+rcnBlzKRRw76OCV5vusk8MZQclt1cmpUwsheHsoMRGRyxH2 kQ5mYnUUGkuJgSltI0S7CGTOor5uvmsO2ygW+An/Djdv08HGC+KPOJ4UVR1uMao5N1lY 9z1UOdoA/uotQUTYHS9TPoKsjBxdVq5iVsYmRmPBDMFY9l4qV3hupCgBWYrxo6o1wxqb KxiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725006173; x=1725610973; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8ewjWosioynS9QjLJzPP/p/LP8/+o765Ca4TuY9GDfQ=; b=Azkoz4bXh0uX4BqSIKx6AsM0bw8kV2S8dYbVGiXg40dBGMiJrQWlW2pnx0Z14tu1Wb 6VVicr0RwlrKwJuMpVpu1ZAhjhNWPgu7AGWCaTKxqaZuNmt299CmwY/WIs5sIYjNvGSu AGhOBQBL6bHJxXjOekyQyqrxU1pj7RlBuAlFxdsN0Ngi2IPhoopOVOq/x+CkzsxYX9Sq 5ve8GTw0rzR8SL0tQ+44SmV8TR4e33aRMyGuQUl8KZ/DG0NAaOwWFHTbV8HIhH0Q91jW HHAOdIzoaYGe3b7a4vpR+UT5qvWUKawBaH3SXCYHx3lG/D7CqrulQCdgm508GtkOOOWb zMbA== X-Gm-Message-State: AOJu0YyKXy+RrvhjcWZcJ9bZhVk0IzjF2DF4cMhAE+DBn7abR/BPRmP8 /+1c/MqdjuseyR9+ZZgK1QqtTZUEBlQ8b8R0G+oTEdD/SVLVqTrqmV/fjIZx X-Google-Smtp-Source: AGHT+IGdtecW2ZO4g4vdfngXfhM0JCRsaqI0LNGJZiq1ZEecxwo+Hlehe5MApd/ZlNiDNIysqYKRJw== X-Received: by 2002:a17:90a:e7c6:b0:2c9:7849:4e22 with SMTP id 98e67ed59e1d1-2d85618c33emr5718939a91.8.1725006172936; Fri, 30 Aug 2024 01:22:52 -0700 (PDT) Received: from localhost.localdomain ([14.116.239.34]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d85b12553asm3165774a91.22.2024.08.30.01.22.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 01:22:52 -0700 (PDT) From: Jingxiang Zeng To: linux-mm@kvack.org Cc: Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Jingxiang Zeng Subject: [PATCH] mm/memcontrol: add per-memcg pgpgin/pswpin counter Date: Fri, 30 Aug 2024 16:22:44 +0800 Message-ID: <20240830082244.156923-1-jingxiangzeng.cas@gmail.com> X-Mailer: git-send-email 2.43.5 Reply-To: Jingxiang Zeng MIME-Version: 1.0 X-Stat-Signature: n4dkhqc7tpfy3hnd5fa6df6o65fxeeqh X-Rspamd-Queue-Id: C2A232002D X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1725006174-67658 X-HE-Meta: U2FsdGVkX1/o8TUjFayJNYdQ9I47UBWj7p31GcHLlbF7zGMNAYnegX1kLssJQoE31C2idn+GzQ6VdrNtf2GinwC3zMJ29oaReYFFVvRmsMh9+Jv+eTaWoFjFr83KFkkui3WiCHOSuprmerLPxPs3BaJBx8MhANcQK/L/H6xEhxwzFYoeyDweUpgjRNMxdzrKGvz/P/6+WF1zlqbFZKP6ceEi6B9xSbB/pxNxz4nKtfWqDUL+czqW+pbbgWBi+7/8C/CIC2pSrM8hd7kSy4jBdQcJJEGUhiI10pY3APkYMMz+AgvUqJJKNzHZGh/Ga4EttxD0gBT43d+w2Ft0AmresNw64gmJcl3JJsT6gX8j8nWw5gjq0s87PSc8P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A43Zbmzf7ExAY1nHvJmnXWRYdkFrTNphenbfv4pxfVN8QUWmMZ755FlC23PbbmW9Z5tcOfcnSacyYYbIDEfmCn5vARpivNztRhtXkZ/y 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. Signed-off-by: Jingxiang Zeng --- mm/memcontrol-v1.c | 2 ++ mm/memcontrol.c | 2 ++ mm/page_io.c | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c index b37c0d870816..44803cbea38a 100644 --- a/mm/memcontrol-v1.c +++ b/mm/memcontrol-v1.c @@ -2729,6 +2729,8 @@ static const char *const memcg1_stat_names[] = { static const unsigned int memcg1_events[] = { PGPGIN, PGPGOUT, + PSWPIN, + PSWPOUT, PGFAULT, PGMAJFAULT, }; diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 087a8cb1a6d8..dde3d026f174 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); }