From patchwork Tue Sep 13 17:44:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12975092 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 41683C6FA8A for ; Tue, 13 Sep 2022 17:45:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 86BE680018; Tue, 13 Sep 2022 13:45:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 81D2F80014; Tue, 13 Sep 2022 13:45:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 49BCB80018; Tue, 13 Sep 2022 13:45:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 092EF80019 for ; Tue, 13 Sep 2022 13:45:10 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D81871C62FF for ; Tue, 13 Sep 2022 17:45:09 +0000 (UTC) X-FDA: 79907788338.12.F62A1F3 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf01.hostedemail.com (Postfix) with ESMTP id 7D8DE4009F for ; Tue, 13 Sep 2022 17:45:09 +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 dfw.source.kernel.org (Postfix) with ESMTPS id E515161510; Tue, 13 Sep 2022 17:45:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D271C43470; Tue, 13 Sep 2022 17:45:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663091108; bh=9ivYQelMNdPJnaUU9EF7chmzaREKfF8OhPMBITLg3Ro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lMkprEXAQC24XJuiTGGjHyvCehrXWfCWngVdHpBZekHiCxDCwHZs0bOCXOeUCGKF8 NAWMZpAkMK5j5PUmvn9X13/I1Xx+Q3H3d8j6AH3HocE847FyXcbB6E0u2ImFA1+HiW XcP4TCbJSNnGyPtX5aBTXrfh8r6R56LOXK7Gx2fZgrTD4kVu1uEWKufBq3AF/YeWfU kFigvWxhkISGTBBEeedP/5RwKIBFKlDPHTlQk3gqZByQpGK9poN3cLcmo80BDROsnc Cjen7hGO3HLbS2379iozDv043UszchvmX+3WKTheH4+4Sw7BMZXvVAjUurep7BxVqc JnJE5k/ZtpKhQ== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 22/22] mm/damon/lru_sort: deduplicate hot/cold schemes generators Date: Tue, 13 Sep 2022 17:44:49 +0000 Message-Id: <20220913174449.50645-23-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220913174449.50645-1-sj@kernel.org> References: <20220913174449.50645-1-sj@kernel.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663091109; 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=ldNhff0kaVXaeRjSyuhUy4uwPOhoVYcKed2+byV8/QI=; b=1dL4LeiA1eRuM45uik7tPFhpCVrwI4DOkY0aJ2nItZMl81U/K03WlJNXXe5O4aT6P0+uQd PQ5R06UPt3pZ7SdpCDc1KaxWE53othWaQ2fIKpEmleglewcokTSuatReWnctu1sNbHLPlh YuUmT6foVjSVFEdkxOayeN1LoOOAyJQ= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lMkprEXA; spf=pass (imf01.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663091109; a=rsa-sha256; cv=none; b=43ciAjzpeJ91TtPiF5vmKfrm7tr78haYCsuh8sCeCEgePLFmQC1XuqSrT5fZdqQ3LNbcPN Qej5Oxx6pOJ98tyWCoapwuIDtBAab0zmD4WNHdIDbV6CtcGjo2PGawKNTvUtJpnMxHqMBW +0tZ9+SN39quwkYPyqe2ibmZ7VbXUBk= X-Rspamd-Queue-Id: 7D8DE4009F X-Rspam-User: Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lMkprEXA; spf=pass (imf01.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspamd-Server: rspam02 X-Stat-Signature: k455jwfirhbc88cikm686iad4msda68r X-HE-Tag: 1663091109-814481 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: damon_lru_sort_new_{hot,cold}_scheme() have quite a lot of duplicates. This commit factors out the duplicate to a separate function and use it for reducing the duplicate. Signed-off-by: SeongJae Park --- mm/damon/lru_sort.c | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 8d9c3d1fd6be..07a0908963fd 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -135,6 +135,25 @@ DEFINE_DAMON_MODULES_DAMOS_STATS_PARAMS(damon_lru_sort_cold_stat, static struct damon_ctx *ctx; static struct damon_target *target; +static struct damos *damon_lru_sort_new_scheme( + struct damos_access_pattern *pattern, enum damos_action action) +{ + struct damos_quota quota = damon_lru_sort_quota; + + /* Use half of total quota for hot/cold pages sorting */ + quota.ms = quota.ms / 2; + + return damon_new_scheme( + /* find the pattern, and */ + pattern, + /* (de)prioritize on LRU-lists */ + action, + /* under the quota. */ + "a, + /* (De)activate this according to the watermarks. */ + &damon_lru_sort_wmarks); +} + /* Create a DAMON-based operation scheme for hot memory regions */ static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres) { @@ -149,19 +168,8 @@ static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres) .min_age_region = 0, .max_age_region = UINT_MAX, }; - struct damos_quota quota = damon_lru_sort_quota; - - /* Use half of total quota for hot pages sorting */ - quota.ms = quota.ms / 2; - return damon_new_scheme( - &pattern, - /* prioritize those on LRU lists, as soon as found */ - DAMOS_LRU_PRIO, - /* under the quota. */ - "a, - /* (De)activate this according to the watermarks. */ - &damon_lru_sort_wmarks); + return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_PRIO); } /* Create a DAMON-based operation scheme for cold memory regions */ @@ -178,19 +186,8 @@ static struct damos *damon_lru_sort_new_cold_scheme(unsigned int cold_thres) .min_age_region = cold_thres, .max_age_region = UINT_MAX, }; - struct damos_quota quota = damon_lru_sort_quota; - /* Use half of total quota for cold pages sorting */ - quota.ms = quota.ms / 2; - - return damon_new_scheme( - &pattern, - /* mark those as not accessed, as soon as found */ - DAMOS_LRU_DEPRIO, - /* under the quota. */ - "a, - /* (De)activate this according to the watermarks. */ - &damon_lru_sort_wmarks); + return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_DEPRIO); } static int damon_lru_sort_apply_parameters(void)