Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp262401rwn; Wed, 14 Sep 2022 20:27:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR4Ewly5kXd0gfiBlfEOhqVE9cgA5TsPhhDh1XLIflAld7/mGFI6s2tHcR1Npqt3RFsBtTkL X-Received: by 2002:a05:6402:40d1:b0:44f:e974:f981 with SMTP id z17-20020a05640240d100b0044fe974f981mr30119529edb.222.1663212427624; Wed, 14 Sep 2022 20:27:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663212427; cv=none; d=google.com; s=arc-20160816; b=pmHnA+lSM4m7Y1i8ziEb6RMF1PDJO/ZhEEg81nWigIfrcR0dcRJBv4nP2oQazLSfgq p4jEHFG1hhVqARnYnBBajxUrEMhnGOyI1Pyyi9UWOl6GPYaTh43KjbnZLss18hNl7VG6 44yQp7wusRiWdWeWYDRT5uxQMDThSWvGyoQqaQSu7Xeva15iVXO6tXl4TGxCqjFPYXzT +8keN9nJnRlmkC/iWvnxgPsIZqheaH82f9gPoD8VWXIhzyqfIqUGWbTo2emjz1azAX8+ SFgqMzP08g2DwcikYXgPdAsasAeLvh4DSfQNr8IZcwTtewzOtJqa1v0MvONSZaSRJg/v Lj9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=8v5UJ5gntnkzxtROwwY5OhFcu9IAYI1ggfSsvNDSV8c=; b=F1yQ4ADDERsdxKD9VpraPF5MeMlyyH7aBd8l/lB37JebtW21+c35yByNtzS6GOrx70 wwobmXe554flEClQZbZoW7mto8vq3JoTTCmKcdLR8lMReNgyoqLlYcLgOUsUdobbjN0R M4jVeFEjHFDKXYo5JAUKQsuC89VK7yNT54BllLD8u0baAsc1GYpDeEBXcJnz1S9P9N/Z gk53aO/UyxMKnEzNGaOZK+X+z9+0jd9pf7g848wxdnyVvvubaJ3TzqiRpxkcCiSBoMQz WXNER304YUn4S71l2LLhuC//MLnO4dQcnigtEGYMW48L/RQUvhUAjehSyPq1UjJbqUE9 OMWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b15-20020a056402278f00b00451a9bc10casi11560817ede.196.2022.09.14.20.26.30; Wed, 14 Sep 2022 20:27:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230194AbiIOChF (ORCPT + 99 others); Wed, 14 Sep 2022 22:37:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbiIOChD (ORCPT ); Wed, 14 Sep 2022 22:37:03 -0400 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D745433360 for ; Wed, 14 Sep 2022 19:37:01 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R631e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VPqc0wr_1663209417; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VPqc0wr_1663209417) by smtp.aliyun-inc.com; Thu, 15 Sep 2022 10:36:58 +0800 From: Xin Hao To: sj@kernel.org Cc: akpm@linux-foundation.org, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, xhao@linux.alibaba.com Subject: [PATCH V3] mm/damon: simplify scheme create in lru_sort.c Date: Thu, 15 Sep 2022 10:36:55 +0800 Message-Id: <20220915023655.41923-1-xhao@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In damon_lru_sort_new_hot_scheme() and damon_lru_sort_new_cold_scheme(), they have so much in common, so we can combine them into a single function, and we just need to distinguish their differences. Suggested-by: SeongJae Park Signed-off-by: Xin Hao Changes from v2 (https://lore.kernel.org/linux-mm/20220914113859.37637-1-xhao@linux.alibaba.com/) - Add static global 'struct damos_access_pattern' stub variable --- mm/damon/lru_sort.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 07a0908963fd..6a26c5822286 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -132,6 +132,18 @@ DEFINE_DAMON_MODULES_DAMOS_STATS_PARAMS(damon_lru_sort_cold_stat, lru_sort_tried_cold_regions, lru_sorted_cold_regions, cold_quota_exceeds); +struct damos_access_pattern damon_lru_sort_stub_access_pattern = { + /* Find regions having PAGE_SIZE or larger size */ + .min_sz_region = PAGE_SIZE, + .max_sz_region = ULONG_MAX, + /* and accessed for more than the threshold */ + .min_nr_accesses = 0, + .max_nr_accesses = UINT_MAX, + /* no matter its age */ + .min_age_region = 0, + .max_age_region = UINT_MAX, +}; + static struct damon_ctx *ctx; static struct damon_target *target; @@ -157,17 +169,9 @@ static struct damos *damon_lru_sort_new_scheme( /* Create a DAMON-based operation scheme for hot memory regions */ static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres) { - struct damos_access_pattern pattern = { - /* Find regions having PAGE_SIZE or larger size */ - .min_sz_region = PAGE_SIZE, - .max_sz_region = ULONG_MAX, - /* and accessed for more than the threshold */ - .min_nr_accesses = hot_thres, - .max_nr_accesses = UINT_MAX, - /* no matter its age */ - .min_age_region = 0, - .max_age_region = UINT_MAX, - }; + struct damos_access_pattern pattern = damon_lru_sort_stub_access_pattern; + + pattern.min_nr_accesses = hot_thres; return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_PRIO); } @@ -175,17 +179,10 @@ static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres) /* Create a DAMON-based operation scheme for cold memory regions */ static struct damos *damon_lru_sort_new_cold_scheme(unsigned int cold_thres) { - struct damos_access_pattern pattern = { - /* Find regions having PAGE_SIZE or larger size */ - .min_sz_region = PAGE_SIZE, - .max_sz_region = ULONG_MAX, - /* and not accessed at all */ - .min_nr_accesses = 0, - .max_nr_accesses = 0, - /* for min_age or more micro-seconds */ - .min_age_region = cold_thres, - .max_age_region = UINT_MAX, - }; + struct damos_access_pattern pattern = damon_lru_sort_stub_access_pattern; + + pattern.max_nr_accesses = 0; + pattern.min_age_region = cold_thres; return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_DEPRIO); } -- 2.31.0