From patchwork Tue Jun 8 11:52:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12306577 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07919C47082 for ; Tue, 8 Jun 2021 11:53:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ADB9461351 for ; Tue, 8 Jun 2021 11:53:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ADB9461351 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4E17A6B006E; Tue, 8 Jun 2021 07:53:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B8656B0070; Tue, 8 Jun 2021 07:53:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 331E36B0071; Tue, 8 Jun 2021 07:53:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0231.hostedemail.com [216.40.44.231]) by kanga.kvack.org (Postfix) with ESMTP id 0416D6B006E for ; Tue, 8 Jun 2021 07:53:14 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 9E0078249980 for ; Tue, 8 Jun 2021 11:53:14 +0000 (UTC) X-FDA: 78230395908.09.095D70D Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) by imf21.hostedemail.com (Postfix) with ESMTP id 22237E000259 for ; Tue, 8 Jun 2021 11:53:10 +0000 (UTC) Received: by mail-qt1-f182.google.com with SMTP id t17so14977544qta.11 for ; Tue, 08 Jun 2021 04:53:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vycya5wChR8O11SPvwfrbgcahHWj2DvmeexI6w+aeRE=; b=VMaxIBn2qqbfUX6zKsHmZqwhLISgllu71tVzGJYE73tltZNe5U2IHXkvAALM8X9Yj1 QM3OQAud62cywUIC6AA2ohHBOniYB7AMSqJnrYzHHVIDgDushX7SBkzGId48qa3AjzRL osZi/YBaZITPanGvi2HJfoTrXjd3jNWeGbktte7mqMWCHLIPFHH/l5wSv4LmrXs0PhBy UocXgZQFJuwOYCZ5NcVz90UnQE9nXlAJp3Q67VE0VDwxaxCOp8gwkG4G2nmGQvukBE6M 80bTzbpafanF3H7Mt6P/Xq1Tj2EKncenNryrmYDhwlXFe9EwBlIc+fgQPJ1LNxvKr93a AO1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vycya5wChR8O11SPvwfrbgcahHWj2DvmeexI6w+aeRE=; b=e8O9bW9WpNBxVxTbnZpyACJ5+wM8VnHMEqMQBWjMAaUj2KlHpnvgWMkE0WRLD1+TeA /xogfcRQnXHMszy6tqESoXLyvPzXoVyZQ2mlfMrdr5HeVePDtLO6Twv1Rf6vzPeFWEKG WBqHMUmgwd30BqrRk3jHbfQ6bPz6mmtkKCUbm+XuoYxWRro+tGt4lzjHRXFC7NWkKhr0 W4HjHQKhFJ+XRUbEUECDYkUb8rgV8nChrNp5q5aqHigaaOVJZZwl5Xb3TOW886UpzrfA yOwEKu/5nHGbfoAPDprd8rgq/FWsDrys1hzYikxrVNJM8ruYrYMhrnTxWrGK4uv2P8AX AfKw== X-Gm-Message-State: AOAM530PUaIynMyE+pQqdXFuJgksIbAOy8z2xj35wUsb45QwZD+502E7 ohf+mMlqpbUOJeS8AmYDm6Y= X-Google-Smtp-Source: ABdhPJx845C6iRrgasVW+zarBTjWb+SmovQC2wL/Jo6i9FC3w095hG/aJB033l3Kh9Gyf0GzT+yN5Q== X-Received: by 2002:ac8:604:: with SMTP id d4mr20607540qth.304.1623153193659; Tue, 08 Jun 2021 04:53:13 -0700 (PDT) Received: from localhost.localdomain (ec2-35-169-212-159.compute-1.amazonaws.com. [35.169.212.159]) by smtp.gmail.com with ESMTPSA id h4sm2133927qth.66.2021.06.08.04.53.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 04:53:13 -0700 (PDT) From: SeongJae Park To: akpm@linux-foundation.org Cc: SeongJae Park , Jonathan.Cameron@Huawei.com, acme@kernel.org, alexander.shishkin@linux.intel.com, amit@kernel.org, benh@kernel.crashing.org, brendanhiggins@google.com, corbet@lwn.net, david@redhat.com, dwmw@amazon.com, elver@google.com, fan.du@intel.com, foersleo@amazon.de, greg@kroah.com, gthelen@google.com, guoju.fgj@alibaba-inc.com, jgowans@amazon.com, mgorman@suse.de, minchan@kernel.org, mingo@redhat.com, namhyung@kernel.org, peterz@infradead.org, riel@surriel.com, rientjes@google.com, rostedt@goodmis.org, rppt@kernel.org, shakeelb@google.com, shuah@kernel.org, sj38.park@gmail.com, snu@zelle79.org, vbabka@suse.cz, vdavydov.dev@gmail.com, zgf574564920@gmail.com, linux-damon@amazon.com, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC v2 01/14] mm/damon/paddr: Support the pageout scheme Date: Tue, 8 Jun 2021 11:52:41 +0000 Message-Id: <20210608115254.11930-2-sj38.park@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210608115254.11930-1-sj38.park@gmail.com> References: <20210608115254.11930-1-sj38.park@gmail.com> X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 22237E000259 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=VMaxIBn2; spf=pass (imf21.hostedemail.com: domain of sj38park@gmail.com designates 209.85.160.182 as permitted sender) smtp.mailfrom=sj38park@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: f4ik7rft9jrpoqui6ukk8g86hi9zuu46 X-HE-Tag: 1623153190-293263 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: SeongJae Park This commit makes the DAMON primitives for physical address space to support the pageout action for DAMON-based Operation Schemes. IOW, now the users can implement their own data access-aware reclamations for whole system using DAMOS. Signed-off-by: SeongJae Park --- mm/damon/paddr.c | 38 +++++++++++++++++++++++++++++++++++++- mm/damon/prmtv-common.c | 2 +- mm/damon/prmtv-common.h | 2 ++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index b92b07a3ce53..303db372e53b 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -7,6 +7,9 @@ #define pr_fmt(fmt) "damon-pa: " fmt +#include + +#include "../internal.h" #include "prmtv-common.h" /* @@ -85,6 +88,39 @@ bool damon_pa_target_valid(void *t) return true; } +int damon_pa_apply_scheme(struct damon_ctx *ctx, struct damon_target *t, + struct damon_region *r, struct damos *scheme) +{ + unsigned long addr; + LIST_HEAD(page_list); + + if (scheme->action != DAMOS_PAGEOUT) + return -EINVAL; + + for (addr = r->ar.start; addr < r->ar.end; addr += PAGE_SIZE) { + struct page *page = damon_get_page(PHYS_PFN(addr)); + + if (!page) + continue; + + ClearPageReferenced(page); + test_and_clear_page_young(page); + if (isolate_lru_page(page)) { + put_page(page); + continue; + } + if (PageUnevictable(page)) { + putback_lru_page(page); + } else { + list_add(&page->lru, &page_list); + put_page(page); + } + } + reclaim_pages(&page_list); + cond_resched(); + return 0; +} + void damon_pa_set_primitives(struct damon_ctx *ctx) { ctx->primitive.init = NULL; @@ -94,5 +130,5 @@ void damon_pa_set_primitives(struct damon_ctx *ctx) ctx->primitive.reset_aggregated = NULL; ctx->primitive.target_valid = damon_pa_target_valid; ctx->primitive.cleanup = NULL; - ctx->primitive.apply_scheme = NULL; + ctx->primitive.apply_scheme = damon_pa_apply_scheme; } diff --git a/mm/damon/prmtv-common.c b/mm/damon/prmtv-common.c index 08e9318d67ed..01c1c1b37859 100644 --- a/mm/damon/prmtv-common.c +++ b/mm/damon/prmtv-common.c @@ -14,7 +14,7 @@ * The body of this function is stolen from the 'page_idle_get_page()'. We * steal rather than reuse it because the code is quite simple. */ -static struct page *damon_get_page(unsigned long pfn) +struct page *damon_get_page(unsigned long pfn) { struct page *page = pfn_to_online_page(pfn); diff --git a/mm/damon/prmtv-common.h b/mm/damon/prmtv-common.h index 939c41af6b59..ba0c4eecbb79 100644 --- a/mm/damon/prmtv-common.h +++ b/mm/damon/prmtv-common.h @@ -18,6 +18,8 @@ /* Get a random number in [l, r) */ #define damon_rand(l, r) (l + prandom_u32_max(r - l)) +struct page *damon_get_page(unsigned long pfn); + void damon_va_mkold(struct mm_struct *mm, unsigned long addr); bool damon_va_young(struct mm_struct *mm, unsigned long addr, unsigned long *page_sz);