Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp252554pxu; Tue, 6 Oct 2020 05:43:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoDKfqs/PwgtFOoFwiZmu1uc5tBCwDvxxLSd2svedML08TRw9C5wlVyB2tZT0NzVfbW/Uw X-Received: by 2002:a05:6402:2207:: with SMTP id cq7mr5320932edb.359.1601988225620; Tue, 06 Oct 2020 05:43:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601988225; cv=none; d=google.com; s=arc-20160816; b=bRZRKQtiodhf4hAviRcEX402dTDYDL5jzu/EDZJxkeHm/JZ3sRf6DDk2i2FTCBWMXC /jRAqwMBReUVbBaYrH06OoZ/vnM85P8y6jaykNSgxnx5LfOczmIJkqKseGnV4QAcOmrX W/C5XuqIN/egx0Dvl88z2g4Dz7xJnANbRgs9yjF5Pa2egbm0TCLkBcK1SLjFhXb1ORUr V9N2CkakIEAkbQKHQwgerHCey0kX7CJumIYhYyWT/o7TrdHF61pQ575g/cNYmxnN4T3B bi3y554QHlEnDx9p5L57fSxslghJ6okJG1CBKgHkjtoNOfpPEEZrcU3fDxQUECE7sOJj 0yDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=PAYn8w+uMmIbD04eOFO3e2KDvKGrIy/WNCbGQFZGDiY=; b=o64dc1Dh19UGbodPKPf6FMGARp/B4uUWw0KL8yQd8aWp8Alwd9XDiAQZcqcIk47TzU rLxeSTdoibXSG0Smr8cYXvG6LSaymOmFR6pvnZLdWVAwNYfrxpMmKXVF+XrTshCL/EV0 96dUbxlGbiHbeN8rc0Qgnx1xSXbzG7FGIhYZlUgZCa2AZ/66WHJ32mVzQBm8v3boAELh SU+tZPpoxf+hRhX0FiH9Ae8ZZB5OTXuhEt8uORt5dNXp+fywZqssSiUYdHlSioWOeVZ+ bdtIa1LSHNeVL0+iGMVShbDS+Y46SBLA8iU3BqJptzSVZnqzUl2Bv0Tg59PRxXNvhLfw VT8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=tnJz8Ux9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g4si2206511edh.445.2020.10.06.05.43.22; Tue, 06 Oct 2020 05:43:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=tnJz8Ux9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726637AbgJFMls (ORCPT + 99 others); Tue, 6 Oct 2020 08:41:48 -0400 Received: from smtp-fw-6002.amazon.com ([52.95.49.90]:10878 "EHLO smtp-fw-6002.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726439AbgJFMls (ORCPT ); Tue, 6 Oct 2020 08:41:48 -0400 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 Content-Type: text/plain 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) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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" -- 2.17.1