From patchwork Tue Jun 27 09:17:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 13294227 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 12BFEEB64DD for ; Tue, 27 Jun 2023 09:19:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7D7548D0003; Tue, 27 Jun 2023 05:19:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 787948D0001; Tue, 27 Jun 2023 05:19:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6280C8D0003; Tue, 27 Jun 2023 05:19:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 4BACA8D0001 for ; Tue, 27 Jun 2023 05:19:06 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id F0AED140939 for ; Tue, 27 Jun 2023 09:19:05 +0000 (UTC) X-FDA: 80947978650.24.45DA9AF Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by imf09.hostedemail.com (Postfix) with ESMTP id C2390140005 for ; Tue, 27 Jun 2023 09:19:02 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf09.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687857544; a=rsa-sha256; cv=none; b=U4mzMPmzFTje2m89esHdNScEGYOy4qoP1otsgbm+V16sjyvkMRHoJz+qHHfWVb7nQjbnqw f8RiOL7sjn7AY3OMvEv4jTxOqjamn/yliCUSs3PnC5k8y+FleUdDCH8BGti+VRRSw9j2hQ U6M57wU/sYptvyEtpyImr5gcKs0Vl8E= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf09.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687857544; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references; bh=hw6Uf5cq6qN6YRc0O4Wky45QCBN8e/c7RTMf9Ej1vyw=; b=8ouYj++PU4bCU2Q1K3xa/Mz+hvWNVSR03Pks4Ma4Quqf258V7JcOGqyH+qLNzBPuWmNcup 9qcOPidI2akhuIZny1J4X999emRxS1hvZ+xBuiqKHm13pMtHuaPS9XdUZuOFWa9r0bFI7b +ij6f7PTY8USXdfz6MqZWf5+xojJux4= Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 35R9HcE0076619; Tue, 27 Jun 2023 17:17:38 +0800 (+08) (envelope-from zhaoyang.huang@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4Qqzcd589hz2LDdKh; Tue, 27 Jun 2023 17:17:05 +0800 (CST) Received: from bj03382pcu.spreadtrum.com (10.0.73.76) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Tue, 27 Jun 2023 17:17:36 +0800 From: "zhaoyang.huang" To: Alexander Viro , Andrew Morton , Matthew Wilcox , Vlastimil Babka , Yang Shi , Suren Baghdasaryan , Yu Zhao , , , , Zhaoyang Huang , Subject: [PATCH] mm: introduce statistic for inode's gen&tier Date: Tue, 27 Jun 2023 17:17:18 +0800 Message-ID: <1687857438-29142-1-git-send-email-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.0.73.76] X-ClientProxiedBy: SHCAS01.spreadtrum.com (10.0.1.201) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 35R9HcE0076619 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: C2390140005 X-Stat-Signature: d6y8pigu8psmjbyc1k55zzr7iu3ixfdt X-Rspam-User: X-HE-Tag: 1687857542-623765 X-HE-Meta: U2FsdGVkX198KSvurpUWIYBxjEHjykl+a6Pgnw1HQq27YWVL3J6JvfaMY/JaqTVhPxOL/Ea4eaCWjtxJFbBV9BOVEKgUUC0CMvU4+IGyXiRsRp+ZJQozQ6ei+eTUiR/7oQ7RIedj5AWBC1yTSlzT19MD3hm/32p3NgZmE9zJeHZwJfTHC8cwFMbXLuTrHhUZC+YtRCL4bfE0R77Kd/i4g0+VDxULU+Gsj+w9YgQ7iPbkMwipwowqUeFVhXkxTCneszwObUSIGeLIfevn7jDclF/JpH17UhdbpLCuJ5yzak92wW48m5eT/Nha4kcI7yA3uq0W4T0lSmE/OOzJCtE/AS7HkRzkemglDznZy10ylTCwx8AHReskMM/gHghqEW4jwkIGgpUf4J+aRWGTvVlUC9x7KLgpPPgjApoh17I5BcTler+9gmN6p6m6pgujGKvhC6xcJwxXxtsvvrz40ugxAvlnvwkGLwhbNdohM02Z7E0e+YfaJg5CSSxjBvDgv8rleUskFNlUlkNpr77iprR6ovqejkA4pZpLXXhWJSq/IxpiBHam3ZrGX6v/wxLZJKnlRUtaFT8B3X6tFr35gysqHVGc99xoyuPXa0kb6b1FZWDjcUqxd1Bk5TPwVAeYZuNpbu5ozPqmqXZezbBEvVwsWTYa7LVjix6XXyq49vtlrqmL6DtZXwbNPZ4AuGm0CXFfcthNUuOnAf36s+cC7eIwIWMBtEx+wnOBAPE/CGWEfgF4Eu1JYORVWTYrnBMpdCpQB9m2ogwW42qRnNosgM3zWJ/AgltDdY1Ho0Qu2fiPetcH8kUYrslVSfwgstcquXaPY93qj22onlzY8wrRPlxBJ0JAOVyQwmeeENvkjc+vNPKn/H5exL8MgX0Zlsg9qOsr8OJXjf3wvZf9Tq3nSIpG+ReSORJXfAwBZhwIWPMvSnzjUq1XAU5urTG1+g6Xtt6vKch02giXVQLnBHXrxgU MiFCci4g NWT8MoZirqMl6LaQ0UhJoOg0YhrwXoK0wBgdEXj+3v194KBvx9AJHkPD3c+mPU+tuT/z6V2Dt2sjR0yn8+SbZGRv3Dj6Nt0ZSIdcnAaukR2Rz23HVtLM6VyI7ZrFUuFLm4hWA/QJrlEVK5G2fbWuhDX/Ey/ZOoXt1aARr//pw052VeblFgBV02xGeQ/p0zBc0xhwTf7ybfwbb5pVq5eeenk8tocJWwy3xZxZOvUtX03Nk+wHWlL6CoopN3bsXuphvmaWk 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: From: Zhaoyang Huang As mglru scale page's activity more presiced than before, I would like to introduce statistics over these two properties on all pages of the inode, which could help some mechanisms have ability to judge the inode's activity, etc madivse. Signed-off-by: Zhaoyang Huang --- fs/proc/task_mmu.c | 9 +++++++++ include/linux/fs.h | 2 ++ include/linux/mm_inline.h | 14 ++++++++++++++ mm/filemap.c | 11 +++++++++++ mm/swap.c | 1 + 5 files changed, 37 insertions(+) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index e35a039..3ed30ef 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -283,17 +283,26 @@ static void show_vma_header_prefix(struct seq_file *m, unsigned long start, end; dev_t dev = 0; const char *name = NULL; + long nrpages = 0, gen = 0, tier = 0; if (file) { struct inode *inode = file_inode(vma->vm_file); dev = inode->i_sb->s_dev; ino = inode->i_ino; pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT; + nrpages = inode->i_mapping->nrpages; + gen = atomic_long_read(&inode->i_mapping->gen); + tier = atomic_long_read(&inode->i_mapping->tier); } start = vma->vm_start; end = vma->vm_end; show_vma_header_prefix(m, start, end, flags, pgoff, dev, ino); + + seq_put_hex_ll(m, NULL, nrpages, 8); + seq_put_hex_ll(m, ":", gen, 8); + seq_put_hex_ll(m, ":", tier, 8); + if (mm) anon_name = anon_vma_name(vma); diff --git a/include/linux/fs.h b/include/linux/fs.h index c1769a2..4f4c3a2 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -434,6 +434,8 @@ struct address_space { struct rb_root_cached i_mmap; struct rw_semaphore i_mmap_rwsem; unsigned long nrpages; + atomic_long_t gen; + atomic_long_t tier; pgoff_t writeback_index; const struct address_space_operations *a_ops; unsigned long flags; diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h index ff3f3f2..f68bd06 100644 --- a/include/linux/mm_inline.h +++ b/include/linux/mm_inline.h @@ -307,6 +307,20 @@ static inline bool lru_gen_del_folio(struct lruvec *lruvec, struct folio *folio, return false; } +static inline int lru_tier_from_refs(int refs) +{ + return 0; +} + +static inline int folio_lru_refs(struct folio *folio) +{ + return 0; +} + +static inline int folio_lru_gen(struct folio *folio) +{ + return 0; +} #endif /* CONFIG_LRU_GEN */ static __always_inline diff --git a/mm/filemap.c b/mm/filemap.c index c4d4ace..a1c68a9 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -45,6 +45,7 @@ #include #include #include "internal.h" +#include #define CREATE_TRACE_POINTS #include @@ -126,6 +127,9 @@ static void page_cache_delete(struct address_space *mapping, { XA_STATE(xas, &mapping->i_pages, folio->index); long nr = 1; + int refs = folio_lru_refs(folio); + int tier = lru_tier_from_refs(refs); + int gen = folio_lru_gen(folio); mapping_set_update(&xas, mapping); @@ -143,6 +147,8 @@ static void page_cache_delete(struct address_space *mapping, folio->mapping = NULL; /* Leave page->index set: truncation lookup relies upon it */ mapping->nrpages -= nr; + atomic_long_sub(gen, &mapping->gen); + atomic_long_sub(tier, &mapping->tier); } static void filemap_unaccount_folio(struct address_space *mapping, @@ -844,6 +850,9 @@ noinline int __filemap_add_folio(struct address_space *mapping, int huge = folio_test_hugetlb(folio); bool charged = false; long nr = 1; + int refs = folio_lru_refs(folio); + int tier = lru_tier_from_refs(refs); + int gen = folio_lru_gen(folio); VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); VM_BUG_ON_FOLIO(folio_test_swapbacked(folio), folio); @@ -898,6 +907,8 @@ noinline int __filemap_add_folio(struct address_space *mapping, goto unlock; mapping->nrpages += nr; + atomic_long_add(gen, &mapping->gen); + atomic_long_add(tier, &mapping->tier); /* hugetlb pages do not participate in page cache accounting */ if (!huge) { diff --git a/mm/swap.c b/mm/swap.c index 70e2063..6322c1c 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -468,6 +468,7 @@ static void folio_inc_refs(struct folio *folio) new_flags += BIT(LRU_REFS_PGOFF); new_flags |= old_flags & ~LRU_REFS_MASK; } while (!try_cmpxchg(&folio->flags, &old_flags, new_flags)); + atomic_long_inc(&folio->mapping->tier); } #else static void folio_inc_refs(struct folio *folio)