From: Muchun Song <songmuchun@bytedance.com>
To: guro@fb.com, hannes@cmpxchg.org, mhocko@kernel.org,
akpm@linux-foundation.org, shakeelb@google.com,
vdavydov.dev@gmail.com
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
duanxiongchun@bytedance.com, fam.zheng@bytedance.com,
Muchun Song <songmuchun@bytedance.com>
Subject: [PATCH 4/7] mm: memcontrol: simplify lruvec_holds_page_lru_lock
Date: Tue, 13 Apr 2021 14:51:50 +0800 [thread overview]
Message-ID: <20210413065153.63431-5-songmuchun@bytedance.com> (raw)
In-Reply-To: <20210413065153.63431-1-songmuchun@bytedance.com>
We already have a helper lruvec_memcg() to get the memcg from lruvec, we
do not need to do it ourselves in the lruvec_holds_page_lru_lock(). So use
lruvec_memcg() instead. And if mem_cgroup_disabled() returns false, the
page_memcg(page) (the LRU pages) cannot be NULL. So remove the odd logic
of "memcg = page_memcg(page) ? : root_mem_cgroup". And use lruvec_pgdat
to simplify the code. We can have a single definition for this function
that works for !CONFIG_MEMCG, CONFIG_MEMCG + mem_cgroup_disabled() and
CONFIG_MEMCG.
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
---
include/linux/memcontrol.h | 31 +++++++------------------------
1 file changed, 7 insertions(+), 24 deletions(-)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 4f49865c9958..38b8d3fb24ff 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -755,22 +755,6 @@ static inline struct lruvec *mem_cgroup_page_lruvec(struct page *page)
return mem_cgroup_lruvec(memcg, pgdat);
}
-static inline bool lruvec_holds_page_lru_lock(struct page *page,
- struct lruvec *lruvec)
-{
- pg_data_t *pgdat = page_pgdat(page);
- const struct mem_cgroup *memcg;
- struct mem_cgroup_per_node *mz;
-
- if (mem_cgroup_disabled())
- return lruvec == &pgdat->__lruvec;
-
- mz = container_of(lruvec, struct mem_cgroup_per_node, lruvec);
- memcg = page_memcg(page) ? : root_mem_cgroup;
-
- return lruvec->pgdat == pgdat && mz->memcg == memcg;
-}
-
struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm);
@@ -1229,14 +1213,6 @@ static inline struct lruvec *mem_cgroup_page_lruvec(struct page *page)
return &pgdat->__lruvec;
}
-static inline bool lruvec_holds_page_lru_lock(struct page *page,
- struct lruvec *lruvec)
-{
- pg_data_t *pgdat = page_pgdat(page);
-
- return lruvec == &pgdat->__lruvec;
-}
-
static inline void lruvec_memcg_debug(struct lruvec *lruvec, struct page *page)
{
}
@@ -1518,6 +1494,13 @@ static inline void unlock_page_lruvec_irqrestore(struct lruvec *lruvec,
spin_unlock_irqrestore(&lruvec->lru_lock, flags);
}
+static inline bool lruvec_holds_page_lru_lock(struct page *page,
+ struct lruvec *lruvec)
+{
+ return lruvec_pgdat(lruvec) == page_pgdat(page) &&
+ lruvec_memcg(lruvec) == page_memcg(page);
+}
+
/* Don't lock again iff page's lruvec locked */
static inline struct lruvec *relock_page_lruvec_irq(struct page *page,
struct lruvec *locked_lruvec)
--
2.11.0
next prev parent reply other threads:[~2021-04-13 6:58 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-13 6:51 [PATCH 0/7] memcontrol code cleanup and simplification Muchun Song
2021-04-13 6:51 ` [PATCH 1/7] mm: memcontrol: fix page charging in page replacement Muchun Song
2021-04-13 17:45 ` Roman Gushchin
2021-04-14 9:20 ` Michal Hocko
2021-04-13 6:51 ` [PATCH 2/7] mm: memcontrol: bail out early when !mm in get_mem_cgroup_from_mm Muchun Song
2021-04-13 17:47 ` Roman Gushchin
2021-04-14 9:24 ` Michal Hocko
2021-04-14 10:04 ` [External] " Muchun Song
2021-04-14 10:15 ` Michal Hocko
2021-04-15 3:13 ` Muchun Song
2021-04-15 7:09 ` Michal Hocko
2021-04-13 6:51 ` [PATCH 3/7] mm: memcontrol: remove the pgdata parameter of mem_cgroup_page_lruvec Muchun Song
2021-04-13 13:12 ` Shakeel Butt
2021-04-13 17:48 ` Roman Gushchin
2021-04-14 9:27 ` Michal Hocko
2021-04-13 6:51 ` Muchun Song [this message]
2021-04-13 13:28 ` [PATCH 4/7] mm: memcontrol: simplify lruvec_holds_page_lru_lock Shakeel Butt
2021-04-13 17:57 ` Roman Gushchin
2021-04-14 9:44 ` Michal Hocko
2021-04-14 10:00 ` [External] " Muchun Song
2021-04-14 17:49 ` Johannes Weiner
2021-04-15 7:08 ` Michal Hocko
2021-04-15 10:01 ` Muchun Song
2021-04-13 6:51 ` [PATCH 5/7] mm: memcontrol: simplify the logic of objcg pinning memcg Muchun Song
2021-04-13 14:16 ` Shakeel Butt
2021-04-13 17:51 ` Roman Gushchin
2021-04-13 6:51 ` [PATCH 6/7] mm: memcontrol: move obj_cgroup_uncharge_pages() out of css_set_lock Muchun Song
2021-04-13 14:18 ` Shakeel Butt
2021-04-13 17:54 ` Roman Gushchin
2021-04-13 18:03 ` Johannes Weiner
2021-04-13 6:51 ` [PATCH 7/7] mm: vmscan: remove noinline_for_stack Muchun Song
2021-04-14 9:46 ` Michal Hocko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210413065153.63431-5-songmuchun@bytedance.com \
--to=songmuchun@bytedance.com \
--cc=akpm@linux-foundation.org \
--cc=duanxiongchun@bytedance.com \
--cc=fam.zheng@bytedance.com \
--cc=guro@fb.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=shakeelb@google.com \
--cc=vdavydov.dev@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).