From patchwork Thu Oct 31 22:45:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinsey Ho X-Patchwork-Id: 13858417 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 284B0E6748D for ; Thu, 31 Oct 2024 22:46:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A3B36B0095; Thu, 31 Oct 2024 18:46:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 579DF6B0096; Thu, 31 Oct 2024 18:46:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 442386B0098; Thu, 31 Oct 2024 18:46: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 2249F6B0095 for ; Thu, 31 Oct 2024 18:46:57 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BE0DAC19EB for ; Thu, 31 Oct 2024 22:46:56 +0000 (UTC) X-FDA: 82735383192.10.3584A6F Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf04.hostedemail.com (Postfix) with ESMTP id 01DFD40005 for ; Thu, 31 Oct 2024 22:46:19 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=xwt81EE3; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 33QgkZwgKCL4omrwi2lsksskpi.gsqpmry1-qqozego.svk@flex--kinseyho.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=33QgkZwgKCL4omrwi2lsksskpi.gsqpmry1-qqozego.svk@flex--kinseyho.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730414695; a=rsa-sha256; cv=none; b=Zi9+RUQsRlOe6JcDplrpWGrnK+rWNUYAlz5OG7e2wLGHXmIQ2OqyFznOIO3nJCIZHvc/kr XJl9DC1T5afbjXXsOo7hunU2TihayzrDEKf05sj76PX1mRnhm7FI7fBTqTJ0/QLWACDAu3 PCyfWN6DRnslqALwc3e6S/8jVfATP1c= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=xwt81EE3; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 33QgkZwgKCL4omrwi2lsksskpi.gsqpmry1-qqozego.svk@flex--kinseyho.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=33QgkZwgKCL4omrwi2lsksskpi.gsqpmry1-qqozego.svk@flex--kinseyho.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730414695; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=guCTOxzKlbAV7mFNRx7TvPMOy3sTYQa/R9Du6hcfImY=; b=r5tvNND03SpVS05rDCSBrUYPL9vJx+X4stQ1Lv/dS6FEc5e7D/FsMY8bUtPIHznmIDuhH/ 31l+1bqmTrJAtaew0pqyisWY2mP0sKdq9W00809ND4LrXL4apDs9N0GnRMWfoekOL7w8v8 H1Rx7WfXVbhgSxXa1gV06yUl45SFpD8= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e321d26b38so27165197b3.2 for ; Thu, 31 Oct 2024 15:46:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730414814; x=1731019614; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=guCTOxzKlbAV7mFNRx7TvPMOy3sTYQa/R9Du6hcfImY=; b=xwt81EE3mreyOJlCoPxiVwu7JswuotdzBW+ABvBcoWnZImcSGEg7kOaZ/A0PghJ0UB l3K+1DtAyyMSLOqZriwAIqNpndkw+ZEpc3s+KGzWclKopMmj4NfwnagAoH16d/Q594EF 0q+qB8FpyismKgUTeclWLaFY8qVyHOB4dtsLu1oo3pjIv5vy49ioouaIRiQ+Klx1VW12 XuoHlEJMMxuIUi+9DEwbehhZQfX/7B+QoVUfB7A+xSZURlFlA6affBsrXKInEzk2eklu Mi67hHRjS/YbhQw3E4pdUbnht2/v6ALpaS+bPExiZkfBVVthalHo6OOQhmxlVX7pswGm v03w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730414814; x=1731019614; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=guCTOxzKlbAV7mFNRx7TvPMOy3sTYQa/R9Du6hcfImY=; b=KaxbExBqwZvVL7c0d1usmpqkZKvxlTp/mnxCpQMEdxLr0os9r7wEJY2NU6j+t5oOGQ yV4G3cwyJb+dTwrcMABaSVmZggkpJT6WY/1SyQevfXAe25nRUxWEmt9HgNZ700K0fLT2 qnqUK1ym3FR2UAz1NOCYvD2LS8xx5dfDYKpN0htqpSjWqQhx2F2nKVQIcdmEQpExZnJ3 hfNxgScwjjp7Ck/DqpNFRMBuavfJwGa2IMOg98YR6GQdY2q2z4WlmxPwQFSf2uQUrnDC TBDY1OT80M7N1K1iOVBxIcu1lwfauNMGSbz6bKrShjY4qTsBRXwx0LAsV57RpULvtAch xONQ== X-Forwarded-Encrypted: i=1; AJvYcCW6UovYeHzoA3ANrbC4V0Am5EUvOIgdF57gdzhE+EAWBOlBcPhFxgeXpK+weI1ItUdpmY5SewT0Aw==@kvack.org X-Gm-Message-State: AOJu0YysLBjeQBU34DKRkc5SIA2cngTM0Pykzh+TSZKC+3xY5K2Dr+Gm BO7I2QbHDmsIsHfiegTGnnFLiS+uiR+Z+NKre75tUSVSXX/J8dDGja8KWkkRSBB9cT6aIPOFNiW COSwA672+lw== X-Google-Smtp-Source: AGHT+IGA5sjZe8vpyl9lON3SR0LDoe9B+CE24eA4rKmGB1vEzw7Pi4vx0K181caj3vNLVFXCXdibXtjqBQbgGQ== X-Received: from kinseyct.c.googlers.com ([fda3:e722:ac3:cc00:a1:836b:ac13:31a5]) (user=kinseyho job=sendgmr) by 2002:a25:6b49:0:b0:e0e:8b26:484e with SMTP id 3f1490d57ef6-e30e5b41dffmr2685276.8.1730414813939; Thu, 31 Oct 2024 15:46:53 -0700 (PDT) Date: Thu, 31 Oct 2024 22:45:50 +0000 In-Reply-To: <20241031224551.1736113-1-kinseyho@google.com> Mime-Version: 1.0 References: <20241031224551.1736113-1-kinseyho@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241031224551.1736113-2-kinseyho@google.com> Subject: [PATCH mm-unstable v1 1/2] mm: add generic system-wide page counters From: Kinsey Ho To: Andrew Morton Cc: Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Pasha Tatashin , David Rientjes , willy@infradead.org, Vlastimil Babka , David Hildenbrand , Kinsey Ho , Joel Granados , Kaiyang Zhao , Sourav Panda , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org X-Rspamd-Queue-Id: 01DFD40005 X-Stat-Signature: 65eomf8khjap34dr5n6yai8wt376dcax X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1730414779-405255 X-HE-Meta: U2FsdGVkX1+2kq1QB53V0iQqtHkkR2gJBBnOWQiGOVT/vLSJ34pbtvrNonW2K3vPBe2GAVH9nXsN2TAGr43c6imBaqpqVme63Pu9Ul3xClHKzpveoFGA9STeNoBZQjob09sVh5Xn56faovJUvZP+thQZtFai9FL7e/W+TjS1+BJ6ZtA0cL1UDnWmA2FjMZWPVocn+tlwSVanVUGpD9Gdr4obvF/jmvNzHG9xjM4thaK3cFnt9FTnQO1Ece5aTletE1NWn44Q8As6lbihtz15wWPQCxMj55FxydumMBQtn58Uv85FK9sVRo+DACVAdUTOtDvp2tUEhQmeqRDW1ETVihKVQWp+Xz1qerp+VOfxgnXrLZXNW75XtePvlvPFBKR8zxIOvYZmMnWbP084qo5nST/ButqXhavgaCpCPW0k+u4V3XEuMBE5uFjQS70yz8I43WtX85DxCKnYSBkEVXABl6snGQF5PuLTu+qBIfYNxpscDnAaoc3M/rBXHVrALwAtgwjhGmmRo8u8CDYC6ZCQAYQf2VIriyReZ9JOpsc/0VluhnrqGODbRzzLufnSN1ACXqcGnuESpE1perBgOcdrA6UocEFHRS+CI2aJbSp0CAYOErbO1vF1qPma3z6+xASFyXI8CYT+g7LWwKKxpBnLqRlPUp2wt8zcTKkhT/GFyg56dxzcCG5EKhSkGYsNOWhtZB0IRDXbWgiazXFn/s3ID1uWbDMxkXVuulD5dG87oxv6PZJWRYJ+ZxipudAVkP5b9cfRdNEY+iyiyOcZUhRXZX9rHicgqNrS5t43Q3TDe3DtEO106+aXi8xL77TBFKbteb17TxC+eR/lE/upfXHbFENrXmJ1fT/+GsXD1Kz8pJh+bgEdooabhliQh2ML8hAJp6vN9cgsgCS07XDKq6c7S1Q6wCbU/GIzO+f/BKxUI8E9BTNtUcBMXK3zP3LcC1pHHF/siDDA4R/sGCSPhEr XAJ+j6Lv C2BunCOwLUysdMZFV+0O5E3uFFlRG5RM8aDS/m2zlcCLBbGudYa+YHQ7CmDxfdTyxYYfzkqc6CMRiQ9hOrofDbH5PXMDUFbiX6In6U6J8MdCwfEIST7e2ZdKkyClwVd7MDYV51HVdmd/8897D06QZMsozd+4/EHeNAiOnNsimbVF5oOE9XbotE5nglnN9G9BecuL1SueekHo2tyDeXcK3oKXwH0PySmTLz3IvLSB5+54xURUHnRrSqObRSs+ejQocoHcmJmHODEb3cLWRjUULksuLPcY94EieiPcgUsJcRGwWhZl1RGNIO6pGb1I++u1IpCLgpuHESL6tB1pn71ObhKfAxI6wX6k158coUR6LIMxuO4mMNawQQbPKfpZFoO4j53uzuCvAb6aJzmQfg7+OZUmocowQVcrnaTiDXuZ5N+aFWOdRBvKzZFUoi8XyADchfD4GYuLfhhcd7YafuBah7srOe4NFQwkMmsSF06e2ZrJD80TWg0khhzojK+Echeiu/Zsur4FrcASLYEvUYnTzNZJzxs3SpqQARrYbyfB7+cYL96yQOcr9ZkS7ow== 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: commit f4cb78af91e3 ("mm: add system wide stats items category") and commit 9d8573111024 ("mm: don't account memmap per-node") renamed NR_VM_WRITEBACK_STAT_ITEMS to NR_VM_STAT_ITEMS to track memmap/memmap_boot pages system wide. Extend the implementation so that the system wide page statistics can be tracked using a generic interface. This patch is in preparation for the next patch which adds a rarely modified system wide vmstat. Note that this implementation uses global atomic fields with no per-cpu optimizations as the existing usecase (memmap pages) is rarely modified as well. Signed-off-by: Kinsey Ho --- include/linux/vmstat.h | 8 ++++++++ mm/vmstat.c | 32 +++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h index d2761bf8ff32..ac4d42c4fabd 100644 --- a/include/linux/vmstat.h +++ b/include/linux/vmstat.h @@ -145,6 +145,11 @@ extern atomic_long_t vm_zone_stat[NR_VM_ZONE_STAT_ITEMS]; extern atomic_long_t vm_node_stat[NR_VM_NODE_STAT_ITEMS]; extern atomic_long_t vm_numa_event[NR_VM_NUMA_EVENT_ITEMS]; +/* + * Global page accounting (no per cpu differentials). + */ +extern atomic_long_t vm_global_stat[NR_VM_STAT_ITEMS]; + #ifdef CONFIG_NUMA static inline void zone_numa_event_add(long x, struct zone *zone, enum numa_stat_item item) @@ -491,6 +496,9 @@ static inline void node_stat_sub_folio(struct folio *folio, mod_node_page_state(folio_pgdat(folio), item, -folio_nr_pages(folio)); } +void mod_global_page_state(enum vm_stat_item item, long nr); +unsigned long global_page_state(enum vm_stat_item item); + extern const char * const vmstat_text[]; static inline const char *zone_stat_name(enum zone_stat_item item) diff --git a/mm/vmstat.c b/mm/vmstat.c index 22a294556b58..e5a6dd5106c2 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -161,9 +161,11 @@ void vm_events_fold_cpu(int cpu) */ atomic_long_t vm_zone_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp; atomic_long_t vm_node_stat[NR_VM_NODE_STAT_ITEMS] __cacheline_aligned_in_smp; +atomic_long_t vm_global_stat[NR_VM_STAT_ITEMS] __cacheline_aligned_in_smp; atomic_long_t vm_numa_event[NR_VM_NUMA_EVENT_ITEMS] __cacheline_aligned_in_smp; EXPORT_SYMBOL(vm_zone_stat); EXPORT_SYMBOL(vm_node_stat); +EXPORT_SYMBOL(vm_global_stat); #ifdef CONFIG_NUMA static void fold_vm_zone_numa_events(struct zone *zone) @@ -1033,22 +1035,34 @@ unsigned long node_page_state(struct pglist_data *pgdat, } #endif +void mod_global_page_state(enum vm_stat_item item, long nr) +{ + atomic_long_add(nr, &vm_global_stat[item]); +} + +unsigned long global_page_state(enum vm_stat_item item) +{ + long x = atomic_long_read(&vm_global_stat[item]); +#ifdef CONFIG_SMP + if (x < 0) + x = 0; +#endif + return x; +} + /* * Count number of pages "struct page" and "struct page_ext" consume. - * nr_memmap_boot_pages: # of pages allocated by boot allocator - * nr_memmap_pages: # of pages that were allocated by buddy allocator + * NR_MEMMAP_BOOT_PAGES: # of pages allocated by boot allocator + * NR_MEMMAP_PAGES: # of pages that were allocated by buddy allocator */ -static atomic_long_t nr_memmap_boot_pages = ATOMIC_LONG_INIT(0); -static atomic_long_t nr_memmap_pages = ATOMIC_LONG_INIT(0); - void memmap_boot_pages_add(long delta) { - atomic_long_add(delta, &nr_memmap_boot_pages); + mod_global_page_state(NR_MEMMAP_BOOT_PAGES, delta); } void memmap_pages_add(long delta) { - atomic_long_add(delta, &nr_memmap_pages); + mod_global_page_state(NR_MEMMAP_PAGES, delta); } #ifdef CONFIG_COMPACTION @@ -1880,8 +1894,8 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos) global_dirty_limits(v + NR_DIRTY_BG_THRESHOLD, v + NR_DIRTY_THRESHOLD); - v[NR_MEMMAP_PAGES] = atomic_long_read(&nr_memmap_pages); - v[NR_MEMMAP_BOOT_PAGES] = atomic_long_read(&nr_memmap_boot_pages); + for (int i = NR_MEMMAP_PAGES; i < NR_VM_STAT_ITEMS; i++) + v[i] = global_page_state(i); v += NR_VM_STAT_ITEMS; #ifdef CONFIG_VM_EVENT_COUNTERS From patchwork Thu Oct 31 22:45:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinsey Ho X-Patchwork-Id: 13858418 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 51301E6748E for ; Thu, 31 Oct 2024 22:47:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 66C446B0098; Thu, 31 Oct 2024 18:46:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6190B6B0099; Thu, 31 Oct 2024 18:46:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F42D6B009A; Thu, 31 Oct 2024 18:46:59 -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 1F1476B0098 for ; Thu, 31 Oct 2024 18:46:59 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C12B7120451 for ; Thu, 31 Oct 2024 22:46:58 +0000 (UTC) X-FDA: 82735382898.08.49B0BD4 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf09.hostedemail.com (Postfix) with ESMTP id BA435140006 for ; Thu, 31 Oct 2024 22:46:37 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=QZhH8kuM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of 33wgkZwgKCMAqotyk4numuumrk.iusrot03-ssq1giq.uxm@flex--kinseyho.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=33wgkZwgKCMAqotyk4numuumrk.iusrot03-ssq1giq.uxm@flex--kinseyho.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730414654; a=rsa-sha256; cv=none; b=UsbOpPL6+LQz+NgapquKDidN7/QEDhgOKXRURbisKcMzajZYjxEb9Ft8/vctb2a0kfErnZ WCH0e1DlGavGYrvzK9Avslk9eIM0YBwUUzcOxXclwB8eT57H4k7BXvWN8q1qVCA1Iegs4E EgV25rfDirFrl1FL35tzz2j2htkDNRo= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=QZhH8kuM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of 33wgkZwgKCMAqotyk4numuumrk.iusrot03-ssq1giq.uxm@flex--kinseyho.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=33wgkZwgKCMAqotyk4numuumrk.iusrot03-ssq1giq.uxm@flex--kinseyho.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730414654; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xsh0ecj9Etn04xB/gBU/50JDS6BBsG2RgrIM+NKe2T8=; b=jsyD167phBwVKLq0lvZP2sL0FMlmXNm4+J9I4LvbeSUIAYDfuICr5fAIehatNLGf30Qx9I Fd9cIvKwiHE5GV5GcvEt6hn2bMUao7m1Fx6m2kNtkTlFb7G8y2qyLjYi6yRwleFhDnWBJo 8eww5RxEQnqNfT9JA9V+wZKvpBg/MWk= Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7cbe272efa6so1611846a12.3 for ; Thu, 31 Oct 2024 15:46:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730414816; x=1731019616; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xsh0ecj9Etn04xB/gBU/50JDS6BBsG2RgrIM+NKe2T8=; b=QZhH8kuMTIPf4MAUp6yDnFxhFw73OospuPXBTOiSq2uqgrxBJ2tcAEwucTmymv7X+C U5hobV2ZnCi09XIoMCuKKvEOaLM9xxA1DO3eZ5KkCIrk5J4IlDXViKkiAVFJ+y3p4+lN S0jDqBDVJPIfOFkd00C6L6wRoUUAvIKcx0e9ZfnNs1huB7GQMuuNbEsfdI+ilFhrrBwB 736N6vHiC9qmT2MKPsdrgI7lQrDQgqu2GhrzrJYI3otAWPeQ+po5hVzw6eCbqnGY6B4K sc/YYe1bzpiK2W9y31rYVgzGwSpo1FWoxeOSWT6zNV9Jpn2z7GgZUtVv66+3CV/e/twu BkDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730414816; x=1731019616; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xsh0ecj9Etn04xB/gBU/50JDS6BBsG2RgrIM+NKe2T8=; b=CDYLMhNRsfJw4Bt4+9cFSWTYZ1FJI6FZkcTN9ilcAKOSEt78cYq2ohSMJBTeh3Grbj C8ierKs7j3PtTtpeiPhM3qRhqXFNSXpCvMotLDApnjdbCA2Byt5lj6Qiw+TwGtRV9BQt a0w5bws+UKsh6RWifvKRKe5aEYx8Roz04CR3Mb1HSU6EJsABItWsx0VPpjQDqXMy4tZA RWvtRIs+9AkXhiY2XOxmfLZ1KDdbcVrlMaZ7Xdol1WkbkzuOXeZhX/pxjay7s8jQrRN7 KRzUTMs+U1w51I6hPu8z5cY3rw4AkRJiMhPdpej6DvyU4yrVt37kexMDb7EX4sHoXY+7 OBWA== X-Forwarded-Encrypted: i=1; AJvYcCW87nJE3A/yWeMPSIqkO6i7KMaZuhgaDj1BMglO7uV/lqwOrIwFMbzsWRwfNNRiO6Q6n87/HIceRQ==@kvack.org X-Gm-Message-State: AOJu0YyX0Y0XTYlltUlwIdvxkaa8lbXMoKq4jYx8iWuThL7Q5Nsmyaz4 Q07/64Ri9V7h4gdKL6emMk1BNiMKMVjAWJirSUbapd68vSGU0sR1Tj1rcgyF1/5oD3hmfMfBjtf 52Z5w6k2Ybw== X-Google-Smtp-Source: AGHT+IHArSVwIyggeWsU6JRSK21WNKSRntcwjMdlKacSUh+G18VKzCn39+gQ7DKViVCf1aeNUXLCZjBpRJnC0A== X-Received: from kinseyct.c.googlers.com ([fda3:e722:ac3:cc00:a1:836b:ac13:31a5]) (user=kinseyho job=sendgmr) by 2002:a63:34c1:0:b0:7ea:c554:d831 with SMTP id 41be03b00d2f7-7ee290c2030mr8465a12.7.1730414815657; Thu, 31 Oct 2024 15:46:55 -0700 (PDT) Date: Thu, 31 Oct 2024 22:45:51 +0000 In-Reply-To: <20241031224551.1736113-1-kinseyho@google.com> Mime-Version: 1.0 References: <20241031224551.1736113-1-kinseyho@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241031224551.1736113-3-kinseyho@google.com> Subject: [PATCH mm-unstable v1 2/2] mm, swap: add pages allocated for struct swap_cgroup to vmstat From: Kinsey Ho To: Andrew Morton Cc: Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Pasha Tatashin , David Rientjes , willy@infradead.org, Vlastimil Babka , David Hildenbrand , Kinsey Ho , Joel Granados , Kaiyang Zhao , Sourav Panda , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org X-Stat-Signature: hr4ed5ugsmr9w744ixioooub47xrrqmb X-Rspamd-Queue-Id: BA435140006 X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1730414797-64308 X-HE-Meta: U2FsdGVkX1+CTgDzIj2MTTyk77FPCZ7OGqRW4fbIrdC54mbLeGIEzA7HItI4uvlVIYZKsq+Q0/+Jnb3JP3aSWin4qRm+8cHeaF5h/KPHixRsZZ9NM+XTP4Hn/8UP4gq+JoNam2mkglK/EiryP6bYBQLuTikf3Hl4LbPrx1Qs7f2F8i9yBzrop+zthRSVxIVwCvfztYxwpj/ZYHgqW10mEKxhQUPopHqI4Mef4LR2rh8m8XzQ/O7ZmqH77m50BBnCTdudje7cYwXSdmM53qxQ5Mpo1g2X+7rSQpAv0XuExxV9MIbFGNtnYBCW255f48e5wYSOGmhtr28W/DkO9ds8bD80wOqPyy6lBRRg3Pu0UDz2ttLMXIbrxk11SGiZLoijjmxVP69y4I2vbgwpJex6JP8ngg3IB439PzsJZFmMjFR1JPZudBq0apkoG9Z7xR9XbUms99IKWO1Ucdl+QnHHe3ukueZI0ETqvhF56ummQnEVRc2QssnLkDs7WkoShYcnJbzxjsp2dQ38bi6p40dbx+dkPAFi43W0BXgCtWYAaoI829ikzxGa6Xb6NRH34h3ACz/xEzXmZW6918aIW5wO/N3hVDJyC9Tl0OBEj6GeFRi95v6FCp+hSMaYOllXfVvxx/w2nASE+Wi79ZEul3VzM3RN9A4k53DLESPkgyf0O6fJmBcDmQd2UpHLocLhzQbJYs9wi0lxc0CwLoNxKjU+I1mCO3MRqoMD+2mO7QNMvMN3lEaqqgBshEeHjBVutR0GSoxL+HWYTq5AjGjAEO222JYAhYzK38RoonWfYQ4EtoLaCI5nbtBccDAhiysQuTWz6mx149KOkPqUBi0mTUmdcL5es86XCtPSIeO7MetlSjU1VE+oXkR+UVxiU3inZbAFOklcM9d6I4rh8ZEBKER6ob0YkMrNNIW6uMRrJZBsjrFR6iC3Hh+F2g8bkjWUuxnMUb1Eemy9epGHcBasZNh OCQkhzuO dzyFAF2N08Yjwz8FlXb3f6meBJQZfXjk4UgOM/gEV5qMfZ6ajKzT1IYVC826fCI9/EW70Hct3mengBlG4WPZwNqkTcGcddrF7G3wRLujEqybVqZc2sSyZX3SERnf8ofj6ttvcvxCn2Lf82FjSCfncIdF1lJ8TajkINGf6NpH1ERNQ1PbbakIo1UUBpnggkHcgnKi3dwO36oxWogjZnYtYe0Sud/VjddkogM6Krqd6l/uXdEhZrgiGJnRZEr3pReqv/oqSOdmejvmkwwM2dLPggr78ou2FF6QS29YRziXtLyHuA1Yzn7t7uqKEowIwlNls5+EUJ4IV2PtlWGsmdn8ycGSRRnU2hI9fr8kQn7rrTsompz4CQmZ7iqcIawEiQfYnYeA0pwyUEAULz6gyBZWTMoDHH31tnx5sRuH6EzF9JzJeBNJ9XejzlNjT1pMw5fAJnuQ3cE25/t1D8jJVP2gotlzeCZUVlUngxgBqwSbeu8dzb5i0JfmzJjHodqnKVDroru4RDfOgccFJz6kjayn+VqH7j8m+DdLdpUrzeMQ6y43vvQMG2DKEdMAOSkJqc+Eu2wv0wpoSDevTIzn709cFGE/l/e6c9tot5TKSYXRSJmHWyKw= 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: Export the number of pages allocated for storing struct swap_cgroup in vmstat using global system-wide counters. Signed-off-by: Kinsey Ho --- include/linux/vmstat.h | 3 +++ mm/swap_cgroup.c | 3 +++ mm/vmstat.c | 3 +++ 3 files changed, 9 insertions(+) diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h index ac4d42c4fabd..227e951d1219 100644 --- a/include/linux/vmstat.h +++ b/include/linux/vmstat.h @@ -41,6 +41,9 @@ enum vm_stat_item { NR_DIRTY_BG_THRESHOLD, NR_MEMMAP_PAGES, /* page metadata allocated through buddy allocator */ NR_MEMMAP_BOOT_PAGES, /* page metadata allocated through boot allocator */ +#if defined(CONFIG_MEMCG) && defined(CONFIG_SWAP) + NR_SWAP_CGROUP_PAGES, /* allocated to store struct swap_cgroup */ +#endif NR_VM_STAT_ITEMS, }; diff --git a/mm/swap_cgroup.c b/mm/swap_cgroup.c index da1278f0563b..82eda8a3efe1 100644 --- a/mm/swap_cgroup.c +++ b/mm/swap_cgroup.c @@ -53,6 +53,8 @@ static int swap_cgroup_prepare(int type) if (!(idx % SWAP_CLUSTER_MAX)) cond_resched(); } + mod_global_page_state(NR_SWAP_CGROUP_PAGES, ctrl->length); + return 0; not_enough_page: max = idx; @@ -228,6 +230,7 @@ void swap_cgroup_swapoff(int type) if (!(i % SWAP_CLUSTER_MAX)) cond_resched(); } + mod_global_page_state(NR_SWAP_CGROUP_PAGES, -length); vfree(map); } } diff --git a/mm/vmstat.c b/mm/vmstat.c index e5a6dd5106c2..259574261ec1 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1295,6 +1295,9 @@ const char * const vmstat_text[] = { "nr_dirty_background_threshold", "nr_memmap_pages", "nr_memmap_boot_pages", +#if defined(CONFIG_MEMCG) && defined(CONFIG_SWAP) + "nr_swap_cgroup_pages", +#endif #if defined(CONFIG_VM_EVENT_COUNTERS) || defined(CONFIG_MEMCG) /* enum vm_event_item counters */