From patchwork Tue Oct 6 12:39:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11818601 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3DFF313B2 for ; Tue, 6 Oct 2020 12:41:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EBEF2208C7 for ; Tue, 6 Oct 2020 12:41:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="tnJz8Ux9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EBEF2208C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 221DF6B005C; Tue, 6 Oct 2020 08:41:48 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1D0D86B0071; Tue, 6 Oct 2020 08:41:48 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 097A96B0072; Tue, 6 Oct 2020 08:41:48 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0098.hostedemail.com [216.40.44.98]) by kanga.kvack.org (Postfix) with ESMTP id CC8786B005C for ; Tue, 6 Oct 2020 08:41:47 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 5762D180AD801 for ; Tue, 6 Oct 2020 12:41:47 +0000 (UTC) X-FDA: 77341462254.01.ant26_561142e271c6 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin01.hostedemail.com (Postfix) with ESMTP id 43A401004D187 for ; Tue, 6 Oct 2020 12:41:47 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=54163b472=sjpark@amazon.com,,RULES_HIT:30003:30005:30012:30054:30064,0,RBL:52.95.49.90:@amazon.com:.lbl8.mailshell.net-64.10.201.10 62.18.0.100;04yfp86nuddzda7r93y75cuio7r6yocgmncfod1w6pjss4c6y7gokbbmmj6h78a.yc6baikshg38bgtcjs7xh71595mhteindtmrrs3a4n8dkt85h3afqyo7nknrxiq.1-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: ant26_561142e271c6 X-Filterd-Recvd-Size: 6772 Received: from smtp-fw-6002.amazon.com (smtp-fw-6002.amazon.com [52.95.49.90]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Tue, 6 Oct 2020 12:41:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1601988107; x=1633524107; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=PAYn8w+uMmIbD04eOFO3e2KDvKGrIy/WNCbGQFZGDiY=; b=tnJz8Ux9D8VNRa/HXYgeQQWftO72vV5At7ODJZdbHmX7wgOKovggpyOh KMYIQ4SA+brRR3mwe7+BZmVjVmiVgaXAYrQGG7j3X/1CzzQlN30mfAXJ8 YrYYK5Prvxzt08Rc6zsRxPmTLphaiOE2ARHbc+nY0iBrzcUTan1RP6ZJ3 Q=; X-IronPort-AV: E=Sophos;i="5.77,343,1596499200"; d="scan'208";a="58312529" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2b-c300ac87.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 06 Oct 2020 12:41:42 +0000 Received: from EX13D31EUA004.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-c300ac87.us-west-2.amazon.com (Postfix) with ESMTPS id 0E7C2A0489; Tue, 6 Oct 2020 12:41:29 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.161.237) by EX13D31EUA004.ant.amazon.com (10.43.165.161) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 6 Oct 2020 12:41:11 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v15 3/8] mm/damon/primitives: Support DAMON-based Operation Schemes Date: Tue, 6 Oct 2020 14:39:26 +0200 Message-ID: <20201006123931.5847-4-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201006123931.5847-1-sjpark@amazon.com> References: <20201006123931.5847-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.237] X-ClientProxiedBy: EX13D18UWA002.ant.amazon.com (10.43.160.199) To EX13D31EUA004.ant.amazon.com (10.43.165.161) 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 DAMON's default primitives for virtual address spaces to support DAMON-based Operation Schemes (DAMOS) by implementing actions application functions and registering it to the monitoring context. The implementation simply links 'madvise()' for related DAMOS actions. That is, 'madvise(MADV_WILLNEED)' is called for 'WILLNEED' DAMOS action and similar for other actions ('COLD', 'PAGEOUT', 'HUGEPAGE', 'NOHUGEPAGE'). So, the kernel space DAMON users can now use the DAMON-based optimizations with only small amount of code. Signed-off-by: SeongJae Park --- include/linux/damon.h | 2 ++ mm/damon/primitives.c | 62 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 92944a336286..3aaea4fdde80 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -323,6 +323,8 @@ void damon_va_prepare_access_checks(struct damon_ctx *ctx); unsigned int damon_va_check_accesses(struct damon_ctx *ctx); bool damon_va_target_valid(struct damon_target *t); void damon_va_cleanup(struct damon_ctx *ctx); +int damon_va_apply_scheme(struct damon_ctx *context, struct damon_target *t, + struct damon_region *r, struct damos *scheme); void damon_va_set_primitives(struct damon_ctx *ctx); #endif /* CONFIG_DAMON_PRIMITIVES */ diff --git a/mm/damon/primitives.c b/mm/damon/primitives.c index abc072008faf..2224e3e139a8 100644 --- a/mm/damon/primitives.c +++ b/mm/damon/primitives.c @@ -7,6 +7,7 @@ #define pr_fmt(fmt) "damon-prmt: " fmt +#include #include #include #include @@ -582,6 +583,66 @@ void damon_va_cleanup(struct damon_ctx *ctx) } } +#ifndef CONFIG_ADVISE_SYSCALLS +static int damos_madvise(struct damon_target *target, struct damon_region *r, + int behavior) +{ + return -EINVAL; +} +#else +static int damos_madvise(struct damon_target *target, struct damon_region *r, + int behavior) +{ + struct task_struct *t; + struct mm_struct *mm; + int ret = -ENOMEM; + + t = damon_get_task_struct(target); + if (!t) + goto out; + mm = damon_get_mm(target); + if (!mm) + goto put_task_out; + + ret = do_madvise(t, mm, PAGE_ALIGN(r->ar.start), + PAGE_ALIGN(r->ar.end - r->ar.start), behavior); + mmput(mm); +put_task_out: + put_task_struct(t); +out: + return ret; +} +#endif /* CONFIG_ADVISE_SYSCALLS */ + +int damon_va_apply_scheme(struct damon_ctx *ctx, struct damon_target *t, + struct damon_region *r, struct damos *scheme) +{ + int madv_action; + + switch (scheme->action) { + case DAMOS_WILLNEED: + madv_action = MADV_WILLNEED; + break; + case DAMOS_COLD: + madv_action = MADV_COLD; + break; + case DAMOS_PAGEOUT: + madv_action = MADV_PAGEOUT; + break; + case DAMOS_HUGEPAGE: + madv_action = MADV_HUGEPAGE; + break; + case DAMOS_NOHUGEPAGE: + madv_action = MADV_NOHUGEPAGE; + break; + default: + pr_warn("Wrong action %d\n", scheme->action); + return -EINVAL; + } + + return damos_madvise(t, r, madv_action); +} + void damon_va_set_primitives(struct damon_ctx *ctx) { ctx->primitive.init_target_regions = damon_va_init_regions; @@ -590,6 +651,7 @@ void damon_va_set_primitives(struct damon_ctx *ctx) ctx->primitive.check_accesses = damon_va_check_accesses; ctx->primitive.target_valid = damon_va_target_valid; ctx->primitive.cleanup = damon_va_cleanup; + ctx->primitive.apply_scheme = damon_va_apply_scheme; } #include "primitives-test.h"