From patchwork Tue Jun 18 18:17:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13702817 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 133A9C27C4F for ; Tue, 18 Jun 2024 18:18:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 875F28D0040; Tue, 18 Jun 2024 14:18:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D2A78D004B; Tue, 18 Jun 2024 14:18:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CCBE8D0047; Tue, 18 Jun 2024 14:18:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5B2ED8D0036 for ; Tue, 18 Jun 2024 14:18:23 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 14CC180987 for ; Tue, 18 Jun 2024 18:18:23 +0000 (UTC) X-FDA: 82244819286.03.0B7B0A5 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf08.hostedemail.com (Postfix) with ESMTP id D084E160019 for ; Tue, 18 Jun 2024 18:18:20 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rkohSxYo; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf08.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718734696; a=rsa-sha256; cv=none; b=EhrXWNjHTOAUjTFeIRulvaR0e4A/5JWT7VRqH+opH3kl86OEHE7xhEuIqZdJPJpHaDAMi7 yd2SctZnRW4csjWwdHy7oHpxs3/GD/nrDF5Q3thAYrWAAOc3FItaz4xzdaMNp0hzjucmPX idmlgC73451Cq1D/apYrhbhQuGiyo4k= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rkohSxYo; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf08.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718734695; 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=4Olb4eAhnSZNbvkfoM5pKR9yW2Wt1Y7pa2nNIcSLxGM=; b=Bah4gJ72aBuhCY1ZXcp08MlpIqxeJl84o1eEIJEfmRA+2Hwb6Iv/n4YX3tToBfA8fWPxNU 1vD0k09WmFPxLWJFRhgzMOzkHxRllnCn7XuN126q+e3nmgFaY4i6YanQiczGrWZ9ZH4Xtu EyDO/T4vUJFWU/zAEodUosWQEzjsXV8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 123E4CE1C03; Tue, 18 Jun 2024 18:18:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D542BC4AF48; Tue, 18 Jun 2024 18:18:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718734697; bh=7hRdxjHOSIuwrdZCOKzvtYTSDa0l/gnw+9kuPa/0bZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rkohSxYoVet+2VnInROCLHYvbmT/IcPl8P0ZgsPJ3X5uqKAAALvILpaMNTgGw2HL+ pA+wVpDtiRRJCmbVDvwOy8kIDC3Ybx/M7EllPDu5PiuRpxWxCTL1Q0o//xVXjeXAGc PyxuRULZuqMY6uvSC9/eijvV1adFiBJ7alMLDXzn7OXN4Zl0nxghlYw9X1AKmLb/8K rMXmH7ZDhYb7tpjfcBqUr0HQacYPAy6ttPJ76I2ENZCQwJaXxJVzD1oE9uKvrub2Wt 6v82xCBHrO/7cykYCj+gtLR88OKpLBk1gH6iTcPcMlSflBWhDl/2OVHuce76tLx/hu h+yFlMoGobSuQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 01/12] mm/damon/core: implement DAMOS quota goals online commit function Date: Tue, 18 Jun 2024 11:17:58 -0700 Message-Id: <20240618181809.82078-2-sj@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240618181809.82078-1-sj@kernel.org> References: <20240618181809.82078-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: D084E160019 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: uxuy7qdfuwi881nxfj9fjy5ywntth3rn X-HE-Tag: 1718734700-858941 X-HE-Meta: U2FsdGVkX18I+WVfideR9TlzRn9QVwOj9+/xG42ypXj3VTv3+d3mO5HXSkmht+LzB3xhdyU+3Yv0thPKVb0fV0NmlNpcceOM5oBnSFjl7CTF87biAqxrf1ihi4WsxIjW6iSV5x3SbQ7GnZuPW9d6Sqc9c0l/31PdSAn8mqchJJNoXc/dVzAggGpKLgBKuLPVsV1K/BlovP24J6QS8tQ/2bJZnf6MhpPdZJJPNDoHYQzVoUx6vvz6Z6NpK5oKbFtpGrWS2ARspEKdleUOem2hmqt1nBYZT8bCBIUFUC9jop3Rd5CAFMX1AvaPOcXWClu3PP+bB7DyMDYubgFRBaxgZRFFZZyBYHxeERFui++lNP/+BB92zRfEJDNNmjHh/v9tjql2Cm4rXq7fabvg9s9w+LEyFkQgAxOIPthcPpL/OC5zHGO45QfGwth24rob6wc78VlscMPKkcHjj2rrCwOmd7w/a4DjoOr+PtsQLtO/y7Sjsz73YD8HIPlHHuZSWH1DBdwHMtjeFdpPLpHhRksFsaKG+orkkO2248IY40juQMqt3sLEryqheFaLOGO2+ne6wrmq7UTuKA5OyMAAfnHmlA6B6CYVeuSIeiYBQk9Uj0t9R4E0W7pdrtYkv/HOGffYRuP91+Fvpk8UVCAu2IEhf6frxr4OSwHV3rhPgZ51XwlJiNjRTuRZt36Tlkoni7yDXJ+s7jry5wkaxpj8vKtesjcTp68L754Gjay8g0pdjf5wZpj/bsGTg30OXCOjowTwcdmSuiD+1BnlLE9liUq6vF8BZ3fG7hqDB34DJmFnZ/pJ+B1uabBVh1x3rImxvC7Ipk55Qb/CUmKoiNjEQeaZQzmWYKtQ+d6PBYg2BrnFUn7kJe39kyS4G9djDHTXYj6B9R4YFvVk6KiGTm7xwqHezCW+sT4KZO6DvmuNvEb1XeJS6pKRV36a0UR5v+EIGWawPlLdzVmQK3QL3iWNEUp EmXMIQWG oH6NbbWnFTLK9Y8xAa6bP6pnB7PJv4FK25aIPQ0cMU/8zga0YXneUnsPI19gxQ65/tbjyOmq9Iwb5ouGhCqPBpZPsfuF0PRowTH61yV4z1ctdU2+XrdwKmAPR9b/Z+vzVEtckHbjio1ZdcV2mYSFdtnZflxNFwRGQpfNDf3uZ/pcYpiOeY6ARq98pN9babPqC/dm2nUhEHBk1Po1T1cE/Tx3bdsdHlhRyphloADwlsg7a4ms= 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: List-Subscribe: List-Unsubscribe: Implement functions for supporting online DAMOS quota goals parameters update. The function receives two DAMOS quota structs. One is the struct that currently being used by a kdamond and therefore to be updated. The other one contains the parameters to be applied to the first one. The function applies the new parameters to the destination struct while keeping/updating the internal status. The function should be called from parameters-update safe place, like DAMON callbacks. Signed-off-by: SeongJae Park --- include/linux/damon.h | 1 + mm/damon/core.c | 59 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 3d62d98d6359..ce12c9f1b4e4 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -742,6 +742,7 @@ struct damos *damon_new_scheme(struct damos_access_pattern *pattern, int target_nid); void damon_add_scheme(struct damon_ctx *ctx, struct damos *s); void damon_destroy_scheme(struct damos *s); +int damos_commit_quota_goals(struct damos_quota *dst, struct damos_quota *src); struct damon_target *damon_new_target(void); void damon_add_target(struct damon_ctx *ctx, struct damon_target *t); diff --git a/mm/damon/core.c b/mm/damon/core.c index c0ec5be4f56e..b538a31fbd83 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -666,6 +666,65 @@ void damon_set_schemes(struct damon_ctx *ctx, struct damos **schemes, damon_add_scheme(ctx, schemes[i]); } +static struct damos_quota_goal *damos_nth_quota_goal( + int n, struct damos_quota *q) +{ + struct damos_quota_goal *goal; + int i = 0; + + damos_for_each_quota_goal(goal, q) { + if (i++ == n) + return goal; + } + return NULL; +} + +static void damos_commit_quota_goal( + struct damos_quota_goal *dst, struct damos_quota_goal *src) +{ + dst->metric = src->metric; + dst->target_value = src->target_value; + if (dst->metric == DAMOS_QUOTA_USER_INPUT) + dst->current_value = src->current_value; + /* keep last_psi_total as is, since it will be updated in next cycle */ +} + +/** + * damos_commit_quota_goals() - Commit DAMOS quota goals to another quota. + * @dst: The commit destination DAMOS quota. + * @src: The commit source DAMOS quota. + * + * Copies user-specified parameters for quota goals from @src to @dst. Users + * should use this function for quota goals-level parameters update of running + * DAMON contexts, instead of manual in-place updates. + * + * This function should be called from parameters-update safe context, like + * DAMON callbacks. + */ +int damos_commit_quota_goals(struct damos_quota *dst, struct damos_quota *src) +{ + struct damos_quota_goal *dst_goal, *next, *src_goal, *new_goal; + int i = 0, j = 0; + + damos_for_each_quota_goal_safe(dst_goal, next, dst) { + src_goal = damos_nth_quota_goal(i++, src); + if (src_goal) + damos_commit_quota_goal(dst_goal, src_goal); + else + damos_destroy_quota_goal(dst_goal); + } + damos_for_each_quota_goal_safe(src_goal, next, src) { + if (j++ < i) + continue; + new_goal = damos_new_quota_goal( + src_goal->metric, src_goal->target_value); + if (!new_goal) + return -ENOMEM; + damos_add_quota_goal(dst, new_goal); + } + return 0; +} + /** * damon_nr_running_ctxs() - Return number of currently running contexts. */