From patchwork Wed Nov 30 20:09:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13060349 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 9ECF3C47090 for ; Wed, 30 Nov 2022 20:09:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EDCF56B0075; Wed, 30 Nov 2022 15:09:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E2E706B007D; Wed, 30 Nov 2022 15:09:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A86116B0078; Wed, 30 Nov 2022 15:09:46 -0500 (EST) 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 7FF1A6B0074 for ; Wed, 30 Nov 2022 15:09:46 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3B957120CED for ; Wed, 30 Nov 2022 20:09:46 +0000 (UTC) X-FDA: 80191199172.22.BDF7021 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf08.hostedemail.com (Postfix) with ESMTP id 8B480160008 for ; Wed, 30 Nov 2022 20:09:45 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0439FB81CD6; Wed, 30 Nov 2022 20:09:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CE37C433B5; Wed, 30 Nov 2022 20:09:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669838982; bh=A+37s6JJXYN+1C0NX4ExPJftU7PAKfFK4zc/BA9nVsg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aJTehjTN01AwdSRZIxWRXChbipb5IKA2UrcYJAqmQnUdb5pA7EkkQLdyPI/PW3qUc Qls2bOUz1Q6sdDSEhKow2+/4fVZroN/glCQClVUhMUgdQ5t3VoS83iiS/w8Yxo09nn CdJivAV8keHFdBzQHinNkD/ZyOeIS/Kozcs0CRE8jzQwi2YFH2IpLR3GEsO6vTYYNS GIQLQM6qqbOH1kuilz+GLI933zjCbDE+t8GezmKmu/txjY3YhO0xZPj676hBtTqIWR flgLSStWY1Z+c6TMRHuEws/WpWXPLO/hXtAkjr/q9tFcRgLumXS5AJ9GE6RxdctOS6 TyNjam9ZAGCPA== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v2 02/11] mm/damon/paddr: support DAMOS filters Date: Wed, 30 Nov 2022 20:09:28 +0000 Message-Id: <20221130200937.118005-3-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221130200937.118005-1-sj@kernel.org> References: <20221130200937.118005-1-sj@kernel.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669838985; a=rsa-sha256; cv=none; b=ht/ecsY1vCCge4JETEk9w1DJclbvMio9Cey0ATpKkRo5hictMPsTNx5gq8nqlu1RXupQyN JnwIRLQpJ177zpIQbAJZUqepVhFUvSZ6udQxVPEgNwc6RExXmV25xHezWp3t7toMANwuei 9I/bTgABnuM8x6NaIEbJejaN3vnYZ/8= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=aJTehjTN; spf=pass (imf08.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669838985; 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=CDD01R5AGR0VCKXOUvbXwSINuJd3g9aT00R1KPyCMrI=; b=I/64Enkm5e4JmTarYmfdxh2V1vMO4AjHRdsrCQ/8HhcZRpSL+Clpcl8IAwJ1EInfhAAKmd ollY0IXdeC/Zbw7aMr6B9VdknhJ6B0FNJgGK7wpkO3OeAFOZnbFfJDaJca8V66iI29x75P E2TknViciY6Uw1809L3tCFc318vpNNo= X-Stat-Signature: stnykam4itmxn9nib9i779gqj546yzic Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=aJTehjTN; spf=pass (imf08.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 8B480160008 X-Rspam-User: X-HE-Tag: 1669838985-397426 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: Implement support of the DAMOS filters in the physical address space monitoring operations set, for all DAMOS actions that it supports including 'pageout', 'lru_prio', and 'lru_deprio'. Signed-off-by: SeongJae Park --- mm/damon/paddr.c | 71 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 9 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index e1a4315c4be6..ebd1905eed6f 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -202,7 +202,47 @@ static unsigned int damon_pa_check_accesses(struct damon_ctx *ctx) return max_nr_accesses; } -static unsigned long damon_pa_pageout(struct damon_region *r) +static bool __damos_pa_filter_out(struct damos_filter *filter, + struct page *page) +{ + bool matched = false; + struct mem_cgroup *memcg; + + switch (filter->type) { + case DAMOS_FILTER_TYPE_ANON: + matched = PageAnon(page); + break; + case DAMOS_FILTER_TYPE_MEMCG: + rcu_read_lock(); + memcg = page_memcg_check(page); + if (!memcg) + matched = false; + else + matched = filter->memcg_id == mem_cgroup_id(memcg); + rcu_read_unlock(); + break; + default: + break; + } + + return matched == filter->matching; +} + +/* + * damos_pa_filter_out - Return true if the page should be filtered out. + */ +static bool damos_pa_filter_out(struct damos *scheme, struct page *page) +{ + struct damos_filter *filter; + + damos_for_each_filter(filter, scheme) { + if (__damos_pa_filter_out(filter, page)) + return true; + } + return false; +} + +static unsigned long damon_pa_pageout(struct damon_region *r, struct damos *s) { unsigned long addr, applied; LIST_HEAD(page_list); @@ -213,6 +253,11 @@ static unsigned long damon_pa_pageout(struct damon_region *r) if (!page) continue; + if (damos_pa_filter_out(s, page)) { + put_page(page); + continue; + } + ClearPageReferenced(page); test_and_clear_page_young(page); if (isolate_lru_page(page)) { @@ -232,7 +277,7 @@ static unsigned long damon_pa_pageout(struct damon_region *r) } static inline unsigned long damon_pa_mark_accessed_or_deactivate( - struct damon_region *r, bool mark_accessed) + struct damon_region *r, struct damos *s, bool mark_accessed) { unsigned long addr, applied = 0; @@ -241,6 +286,12 @@ static inline unsigned long damon_pa_mark_accessed_or_deactivate( if (!page) continue; + + if (damos_pa_filter_out(s, page)) { + put_page(page); + continue; + } + if (mark_accessed) mark_page_accessed(page); else @@ -251,14 +302,16 @@ static inline unsigned long damon_pa_mark_accessed_or_deactivate( return applied * PAGE_SIZE; } -static unsigned long damon_pa_mark_accessed(struct damon_region *r) +static unsigned long damon_pa_mark_accessed(struct damon_region *r, + struct damos *s) { - return damon_pa_mark_accessed_or_deactivate(r, true); + return damon_pa_mark_accessed_or_deactivate(r, s, true); } -static unsigned long damon_pa_deactivate_pages(struct damon_region *r) +static unsigned long damon_pa_deactivate_pages(struct damon_region *r, + struct damos *s) { - return damon_pa_mark_accessed_or_deactivate(r, false); + return damon_pa_mark_accessed_or_deactivate(r, s, false); } static unsigned long damon_pa_apply_scheme(struct damon_ctx *ctx, @@ -267,11 +320,11 @@ static unsigned long damon_pa_apply_scheme(struct damon_ctx *ctx, { switch (scheme->action) { case DAMOS_PAGEOUT: - return damon_pa_pageout(r); + return damon_pa_pageout(r, scheme); case DAMOS_LRU_PRIO: - return damon_pa_mark_accessed(r); + return damon_pa_mark_accessed(r, scheme); case DAMOS_LRU_DEPRIO: - return damon_pa_deactivate_pages(r); + return damon_pa_deactivate_pages(r, scheme); case DAMOS_STAT: break; default: