From patchwork Fri Sep 15 02:52:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 140044 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp765660vqi; Thu, 14 Sep 2023 19:53:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENPR3tindb509SzP8aoF80pHgUANqrJgsLNekweJu7CDzt3b1byvbC8+44GIC9c0gP269d X-Received: by 2002:a17:902:7404:b0:1bd:d14a:7e14 with SMTP id g4-20020a170902740400b001bdd14a7e14mr351263pll.65.1694746431177; Thu, 14 Sep 2023 19:53:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694746431; cv=none; d=google.com; s=arc-20160816; b=W2l4Lv7okxi05fhbN6Bf2crjPaLWsTzdt7x/uliiSY33VZFCtZQSUv6tVgrFNn/Uqs qFVbjGIKs8wriuLlEiX8TueJTVhUrXqjAOind3mQHHLco2ITrN8aWc5QGFifQX9WiEHm z0KOhHJkS0dzk4JqEx+iDBsAlaeYc/X3MRUIcUu8ft5O64R64Uk3acGPvoL47D3TTd12 uJurI4yOWApK/SJpx1a1ugJiJdAHJt//0IGVXzR5vo0SwpB3sc7V84gCnaDgnM2cBqi0 ZWMpP4w+CLM/3foOLinZdgDS9Kp3WhrAqMP5ZkBKezvp088ck50YnrvmobJgw1YJi7Lp OR8w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SFT1RvfBesgWan9n0zdO5A0vFQzl8kYATAnJYbXppOU=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=LYySRC3RQBGFUjGL8qmRz0oHz3fqx289EG28lKmtVX8QwofuCryA1ikFZhFO6m9TGz +7Yey3PWvt0Pz4dI+ZDfaszsF52It0gfvIjYpaht0qKh9Y2eZ+T9E9R8WavsZR1qD3/w 4gbpDJT+8CU4e9u32PphUYndcgx1cl1EDrL7U/jySPCMeuitfp2NUlgqXh3nYpTSJ33m /mfbahIq3hucQq3wFinPDeQgJB8rAIG+nI/ETvxYj3tDzNcybKIPfR2Lq8BxUkiab7NB tv1HE7p1nXFtUWMy0iEtT1lNb6bSfQZjPp6ia/MQ9dNrnaciOK8cxkSraUEYMUbJ1nfL XF2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Ntf/iecF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id i9-20020a17090332c900b001bdc664cd65si2790825plr.165.2023.09.14.19.53.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 19:53:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Ntf/iecF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 0656C83DABEE; Thu, 14 Sep 2023 19:53:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231635AbjIOCxK (ORCPT + 33 others); Thu, 14 Sep 2023 22:53:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229548AbjIOCxG (ORCPT ); Thu, 14 Sep 2023 22:53:06 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AFEB26AB for ; Thu, 14 Sep 2023 19:53:02 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0D1BC433C9; Fri, 15 Sep 2023 02:53:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694746382; bh=zCDEsnRSxn3q8lrPgI2u2ZG1f3Dh76TJLw6d3uQsNjg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ntf/iecFSdd3DqQwgfLRXzHl/czWjON3PowvUDhFaFyZaByn8EF15Fwy+Baodq8g+ T3UWUH/geUbs9IOLQVJYRq0S8CBgSo4GgagPuJ8w6urJT7ThOqf23T6XPZn1nCvmmA /fFveCT57SDIgI7SE2h4z9zxsTlTLoi/TsBBxgaBOU6/ORSdPSV4k/zDhOVrqDvmex LK3zQ8xnLrH5yMnM2cfOF65ovLvphaX+SoNR/uigrIopOng3jzRjsCAWmJcMYDW4u7 446GqrWFI4ki83YgevvKhpiMya0lXnUqLfCMS5ETOm1sWgXKjyk07Xu86nXLNrzVU/ xvjn5jhsklxHQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/8] mm/damon/core: define and use a dedicated function for region access rate update Date: Fri, 15 Sep 2023 02:52:44 +0000 Message-Id: <20230915025251.72816-2-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230915025251.72816-1-sj@kernel.org> References: <20230915025251.72816-1-sj@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 14 Sep 2023 19:53:22 -0700 (PDT) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777070433650245445 X-GMAIL-MSGID: 1777070433650245445 Each DAMON operarions set is updating nr_accesses field of each damon_region for each of their access check results, from the check_accesses() callback. Directly accessing the field could make things complex to manage and change in future. Define and use a dedicated function for the purpose. Signed-off-by: SeongJae Park --- include/linux/damon.h | 5 ++++- mm/damon/core.c | 16 ++++++++++++++++ mm/damon/paddr.c | 6 ++---- mm/damon/vaddr.c | 6 ++---- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 9a32b8fd0bd3..17c504d236b9 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -45,7 +45,9 @@ struct damon_addr_range { * * @nr_accesses is reset to zero for every &damon_attrs->aggr_interval and be * increased for every &damon_attrs->sample_interval if an access to the region - * during the last sampling interval is found. + * during the last sampling interval is found. The update of this field should + * not be done with direct access but with the helper function, + * damon_update_region_access_rate(). * * @age is initially zero, increased for each aggregation interval, and reset * to zero again if the access frequency is significantly changed. If two @@ -620,6 +622,7 @@ void damon_add_region(struct damon_region *r, struct damon_target *t); void damon_destroy_region(struct damon_region *r, struct damon_target *t); int damon_set_regions(struct damon_target *t, struct damon_addr_range *ranges, unsigned int nr_ranges); +void damon_update_region_access_rate(struct damon_region *r, bool accessed); struct damos_filter *damos_new_filter(enum damos_filter_type type, bool matching); diff --git a/mm/damon/core.c b/mm/damon/core.c index c5b7296c69a0..10532159323a 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1549,6 +1549,22 @@ int damon_set_region_biggest_system_ram_default(struct damon_target *t, return damon_set_regions(t, &addr_range, 1); } +/** + * damon_update_region_access_rate() - Update the access rate of a region. + * @r: The DAMON region to update for its access check result. + * @accessed: Whether the region has accessed during last sampling interval. + * + * Update the access rate of a region with the region's last sampling interval + * access check result. + * + * Usually this will be called by &damon_operations->check_accesses callback. + */ +void damon_update_region_access_rate(struct damon_region *r, bool accessed) +{ + if (accessed) + r->nr_accesses++; +} + static int __init damon_init(void) { damon_region_cache = KMEM_CACHE(damon_region, 0); diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index 909db25efb35..44f21860b555 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -157,14 +157,12 @@ static void __damon_pa_check_access(struct damon_region *r) /* If the region is in the last checked page, reuse the result */ if (ALIGN_DOWN(last_addr, last_folio_sz) == ALIGN_DOWN(r->sampling_addr, last_folio_sz)) { - if (last_accessed) - r->nr_accesses++; + damon_update_region_access_rate(r, last_accessed); return; } last_accessed = damon_pa_young(r->sampling_addr, &last_folio_sz); - if (last_accessed) - r->nr_accesses++; + damon_update_region_access_rate(r, last_accessed); last_addr = r->sampling_addr; } diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c index 4c81a9dbd044..7fc0bda73b4c 100644 --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -566,14 +566,12 @@ static void __damon_va_check_access(struct mm_struct *mm, /* If the region is in the last checked page, reuse the result */ if (same_target && (ALIGN_DOWN(last_addr, last_folio_sz) == ALIGN_DOWN(r->sampling_addr, last_folio_sz))) { - if (last_accessed) - r->nr_accesses++; + damon_update_region_access_rate(r, last_accessed); return; } last_accessed = damon_va_young(mm, r->sampling_addr, &last_folio_sz); - if (last_accessed) - r->nr_accesses++; + damon_update_region_access_rate(r, last_accessed); last_addr = r->sampling_addr; } From patchwork Fri Sep 15 02:52:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 140040 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp765624vqi; Thu, 14 Sep 2023 19:53:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFrUAFfnFQS45LnGkxgVxHAsn5IQDyIAIUEbfQeqx/T5xHsP/TZTE9/+9ZAOKpdH+CS5PAV X-Received: by 2002:a17:903:48f:b0:1c3:76c4:7246 with SMTP id jj15-20020a170903048f00b001c376c47246mr398992plb.9.1694746424359; Thu, 14 Sep 2023 19:53:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694746424; cv=none; d=google.com; s=arc-20160816; b=DlxgsenMtcCoEhEYXsheHeDvXrI74xUQf2JNxNplvfs+xRC8dkuKHEDEtPACozGqgQ soDQF++b5Zvcppb0wyzWu4SGkeoG0sikim7vIC+SItVVWJUa1DOKwYbv1rvs2nFeCS8A LmuwOtHPd94Fd6k5SeYwFiDzejyJftAK4AG7K9+bwamn1oNTGS6k5I0HcjEp3LRLW8Ze 7oWozDk9sxKpE4Rxr6Y4WEPmLqGAKHgFOO3SpLSRhfQVAyCNW2nDhbk2cof435LWmFVg NTE9RimO3QZTc031JNauGJlE0z7K5pDhCERESxorwAKaMUXAgeqGrD5ZHq4YeLeMF0Zc XVyw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=s9CCrAW2k5JfZmWyxspFJIvVkuWytxqxD9bxjnqhVns=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=MH2VpnQZvS9YkZWBD8VGUa/fqrTjETfVE1PhrT8tcH1xgq667HQslXDvHGKFqmYZCb HAXoKjvS/fCAocXj9ZIq+p4EOnNJC5xQDsFbFmHaFb7PJObTePSdLNWU/pz+LRpeG2Ox xb9TOvoZl92GFxByIW5fWeNoBCQ7z1oDx2rzQAyQCbfN/Y5SO0c85x3bhl7jtioQ9JLh IhIWD/0GgJ35VB9MRHX3mOH+d9toD1TTHl7hmU+FcO4AtkwdAHgBoYIYV3acpxvsVI7h jtk1ubJ+V0e1cOdAdkSjJBg4fQ8axqPsbI2ncVlf7mbrT7KBLgMnAC5hHhp/5teXMZ9z ld6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EyWd6QeH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id e15-20020a17090301cf00b001c3a05b0b67si2706268plh.566.2023.09.14.19.53.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 19:53:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EyWd6QeH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id AA44C83669CB; Thu, 14 Sep 2023 19:53:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231691AbjIOCxM (ORCPT + 33 others); Thu, 14 Sep 2023 22:53:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231648AbjIOCxI (ORCPT ); Thu, 14 Sep 2023 22:53:08 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F6322701 for ; Thu, 14 Sep 2023 19:53:04 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68B15C433CA; Fri, 15 Sep 2023 02:53:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694746383; bh=i00VYLhoAf7cwF/8O1Xi88bbaOl2lSsV4k5ng0qJ0ek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EyWd6QeH+I+otwhxDe5iLd5XAOviRv5NU62+pG7wOYSt1RxJd562R/9kRGV/14S6k wqwgK3S/aoyzhC6ERZqSSiw7JvU7BAbifNwCKIe6Ic1N++Fm4YodPXqekKh7wy5E4c frf4PtL+Dv7zzGaMntbeugmrQFPZnEwcCuwZ6MVTdQMvr7clAKApk58dlqzx4D9XB7 gFmgUFdVfZXcHnVsiUAYX4nj2eQscAJwIuXzXjzAOvHwZF0ZRQvEYWdpSJfowFNMuu CkJENgkBPYUg94GulS9lebSqQJdp3mZ2b0vLC1KWqzgCeo/tyq22w10Ies9ncnlHit 8JGVkX6Fe/OWA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/8] mm/damon/vaddr: call damon_update_region_access_rate() always Date: Fri, 15 Sep 2023 02:52:45 +0000 Message-Id: <20230915025251.72816-3-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230915025251.72816-1-sj@kernel.org> References: <20230915025251.72816-1-sj@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 14 Sep 2023 19:53:40 -0700 (PDT) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777070426974987364 X-GMAIL-MSGID: 1777070426974987364 When getting mm_struct of the monitoring target process fails, there wil be no need to increase the access rate counter (nr_accesses) of the regions for the process. Hence, damon_va_check_accesses() skips calling damon_update_region_access_rate() in the case. This breaks the assumption that damon_update_region_access_rate() is called for every region, for every sampling interval. Call the function for every region even in the case. This might increase the overhead in some cases, but such case would not be frequent, so no significant impact is really expected. Signed-off-by: SeongJae Park --- mm/damon/vaddr.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c index 7fc0bda73b4c..e36303271f9d 100644 --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -563,6 +563,11 @@ static void __damon_va_check_access(struct mm_struct *mm, static unsigned long last_folio_sz = PAGE_SIZE; static bool last_accessed; + if (!mm) { + damon_update_region_access_rate(r, false); + return; + } + /* If the region is in the last checked page, reuse the result */ if (same_target && (ALIGN_DOWN(last_addr, last_folio_sz) == ALIGN_DOWN(r->sampling_addr, last_folio_sz))) { @@ -586,15 +591,14 @@ static unsigned int damon_va_check_accesses(struct damon_ctx *ctx) damon_for_each_target(t, ctx) { mm = damon_get_mm(t); - if (!mm) - continue; same_target = false; damon_for_each_region(r, t) { __damon_va_check_access(mm, r, same_target); max_nr_accesses = max(r->nr_accesses, max_nr_accesses); same_target = true; } - mmput(mm); + if (mm) + mmput(mm); } return max_nr_accesses; From patchwork Fri Sep 15 02:52:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 140041 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp765625vqi; Thu, 14 Sep 2023 19:53:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFs99Ycn0AJhrfJtV8kGg2qLs9fKZTK4ufZiQ4HIfHP3bEf7HMyyCoKumARmJ70KuNSgvv5 X-Received: by 2002:a05:6830:1b78:b0:6c0:ef3c:5ab4 with SMTP id d24-20020a0568301b7800b006c0ef3c5ab4mr376720ote.0.1694746424595; Thu, 14 Sep 2023 19:53:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694746424; cv=none; d=google.com; s=arc-20160816; b=s+mNdb9R8tUbzbHSNJAtIQTM2V/TiLAsqRqjTwJ9ezCLeNXzKwtX1P6z1Y5VRf05O+ vxlDqY4dorqpAQbi5SYa3mTGduEmAZULnF7ZIaLidwZ7Z8dM2foapjnGXSJXsjQ2Owb5 /ZRdxuEoNSA3P3TDyaSrJU2CmaPROgsaOd4NGUW1l/mgj6DtzIsTNpnyaI62nHiqrWGU Mifbe6dlZxn1WjjVQhZqKN0vGryZJ9IXWd2Oj16TI/O7ItiSQ4BOqeFwZ+mHtoaV2luh I7hqtnISMuPwAqxRRGO4X4bnLbnamxH5kHhKHeaaumafJzVyGHL5jIu+x+fYHiM/9cdO FGmg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TR+0ywkwjASKLQUKEDWUDGl5u35ACwoap9KEj50pecQ=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=T+q5GPX6mWSf+qkDAOufte64ZcOaWZ+8OEhLHcwAdwT9Y31tIvPDPx36TWxB34KsZ4 +PFAf0dz91BiYq6VnHgYqNUmzQ66PBnZbRJ3qcKnEZ08VxJ1DT73saRoi569aQ+kF1q6 Tu+AwJHmyD2GfzaFo3W1tHDTtNvlL071K0+7s9AJkjYVSFynCyuvuLwVTzj9GEPlMzkc ESIcwnwSwxKoOEvdgq9SK2HKMREQ7NSlfd28S1uFfqDZ7tZhLqjI5kS5tXMIm0OeZEmA ORDPS8er2Sduipja/FI606ReepQZa8RO1p+x+NqdNe5gn9UGluhZc2MBsr6rYStTQBkQ c98g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pq35bGOV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id a5-20020a655c85000000b00563fc0ccc31si2350058pgt.665.2023.09.14.19.53.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 19:53:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pq35bGOV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 165FE8313D08; Thu, 14 Sep 2023 19:53:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231782AbjIOCxO (ORCPT + 33 others); Thu, 14 Sep 2023 22:53:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231681AbjIOCxK (ORCPT ); Thu, 14 Sep 2023 22:53:10 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B68222707 for ; Thu, 14 Sep 2023 19:53:05 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF5EEC433C9; Fri, 15 Sep 2023 02:53:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694746385; bh=1bmqeGHeOEZ2+59SSNfs3s06RBUS+Jm7Zbyglu1mAv8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pq35bGOVZLCqwdN44XaOtHhtXWKjJs4HFDnB6LU85Y8bqJGxt1jDLEDCJU2EyKY+O YX5rUFZ2j1WYGzXpnC7MZBLFG2mDmvZeEfZdKl41qov99fPrnnqoh+cNnRDJkUYL3p rFdgb+uAr4opnrxmKSWOZexjjdsFRCkMkgrfNixVpJCRtruxa93AEdCyE1NRTx291T ro0iKYQKhKzXv3roZ+Ja5LGJ073h+DG/Vps8OkaCtQV1TNatAvCkVTNcX7c/2nEbsz hABBbXn7jgj5tI+nARlpwXKPSnM88OeQJWahUNlym4aIYY5r7PefSlPgceGMj0AeCt I0BpGP+LqEcKA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/8] mm/damon/core: implement a pseudo-moving sum function Date: Fri, 15 Sep 2023 02:52:46 +0000 Message-Id: <20230915025251.72816-4-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230915025251.72816-1-sj@kernel.org> References: <20230915025251.72816-1-sj@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 14 Sep 2023 19:53:42 -0700 (PDT) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777070427094359625 X-GMAIL-MSGID: 1777070427094359625 For values that continuously change, moving average or sum are good ways to provide fast updates while handling temporal and errorneous variability of the value. For example, the access rate counter (nr_accesses) is calculated as a sum of the number of positive sampled access check results that collected during a discrete time window (aggregation interval), and hence it handles temporal and errorneous access check results, but provides the update only for every aggregation interval. Using a moving sum method for that could allow providing the value for every sampling interval. That could be useful for getting monitoring results snapshot or running DAMOS in fine-grained timing. However, supporting the moving sum for cases that number of samples in the time window is arbirary could impose high overhead, since the number of past values that it needs to keep could be too high. The nr_accesses would also be one of the cases. To mitigate the overhead, implement a pseudo-moving sum function that only provides an estimated pseudo-moving sum. It assumes there was no error in last discrete time window and subtract constant portion of last discrete time window sum. Note that the function is not strictly implementing the moving sum, but it keeps a property of moving sum, which makes the value same to the dsicrete-window based sum for each time window-aligned timing. Hence, people collecting the value in the old timings would show no difference. Signed-off-by: SeongJae Park --- include/linux/damon.h | 2 ++ mm/damon/core.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 17c504d236b9..487a545a11b4 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -622,6 +622,8 @@ void damon_add_region(struct damon_region *r, struct damon_target *t); void damon_destroy_region(struct damon_region *r, struct damon_target *t); int damon_set_regions(struct damon_target *t, struct damon_addr_range *ranges, unsigned int nr_ranges); +unsigned int damon_moving_sum(unsigned int mvsum, unsigned int nomvsum, + unsigned int len_window, unsigned int new_value); void damon_update_region_access_rate(struct damon_region *r, bool accessed); struct damos_filter *damos_new_filter(enum damos_filter_type type, diff --git a/mm/damon/core.c b/mm/damon/core.c index 10532159323a..b005dc15009f 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1549,6 +1549,46 @@ int damon_set_region_biggest_system_ram_default(struct damon_target *t, return damon_set_regions(t, &addr_range, 1); } +/* + * damon_moving_sum() - Calculate an inferred moving sum value. + * @mvsum: Inferred sum of the last @len_window values. + * @nomvsum: Non-moving sum of the last discrete @len_window window values. + * @len_window: The number of last values to take care of. + * @new_value: New value that will be added to the pseudo moving sum. + * + * Moving sum (moving average * window size) is good for handling noise, but + * the cost of keeping past values can be high for arbitrary window size. This + * function implements a lightweight pseudo moving sum function that doesn't + * keep the past window values. + * + * It simply assumes there was no noise in the past, and get the no-noise + * assumed past value to drop from @nomvsum and @len_window. @nomvsum is a + * non-moving sum of the last window. For example, if @len_window is 10 and we + * have 25 values, @nomvsum is the sum of the 11th to 20th values of the 25 + * values. Hence, this function simply drops @nomvsum / @len_window from + * given @mvsum and add @new_value. + * + * For example, if @len_window is 10 and @nomvsum is 50, the last 10 values for + * the last window could be vary, e.g., 0, 10, 0, 10, 0, 10, 0, 0, 0, 20. For + * calculating next moving sum with a new value, we should drop 0 from 50 and + * add the new value. However, this function assumes it got value 5 for each + * of the last ten times. Based on the assumption, when the next value is + * measured, it drops the assumed past value, 5 from the current sum, and add + * the new value to get the updated pseduo-moving average. + * + * This means the value could have errors, but the errors will be disappeared + * for every @len_window aligned calls. For example, if @len_window is 10, the + * pseudo moving sum with 11th value to 19th value would have an error. But + * the sum with 20th value will not have the error. + * + * Return: Pseudo-moving average after getting the @new_value. + */ +unsigned int damon_moving_sum(unsigned int mvsum, unsigned int nomvsum, + unsigned int len_window, unsigned int new_value) +{ + return mvsum - nomvsum / len_window + new_value; +} + /** * damon_update_region_access_rate() - Update the access rate of a region. * @r: The DAMON region to update for its access check result. From patchwork Fri Sep 15 02:52:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 140042 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp765631vqi; Thu, 14 Sep 2023 19:53:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEls1EpxckH5mAabOk6Bi3jQlDhAzwjHtmZLPYRrWWkDheBLyce/M6vFq6BlfEeQJGpepcj X-Received: by 2002:a05:6a20:1581:b0:12c:b10d:693d with SMTP id h1-20020a056a20158100b0012cb10d693dmr684628pzj.6.1694746425282; Thu, 14 Sep 2023 19:53:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694746425; cv=none; d=google.com; s=arc-20160816; b=rZ7HMS9yZSs40OlArSSuMfYwmQWvMP/lNDJe8fYWRKwe3jc2HYNkN3bsYUjo3RKTL9 0c7IOU1E5LdDeUuYXtYyIS1sXYAbDOr4OkNyGBrp1HANLHdH6SRCfdbu10adsF8GTX7Z 2NWvD8GKvJVoAw1+/cDfajrMQWIwePn79DIO3WKEX9az90E4Pa2JU6yeRzx5UghQdeKt avBHyzmNW5TPU7vSRA0w1uD0dBpwqh4vJKUBjY/AmFefDtD98uyk2dSvW3fc0GPFgfri +v/en2ql/kCyTAyLIKMrDAtJaOy9NJyFtlYR7veVSwvZ4S6HREIjAUN8vGiiQjkW3cPk EKQA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=u9TmyMjuPTNAblor8OwPK1A1ey4pwH8Hdhs6lWbOca8=; fh=KYrqrUZLyrFtzsRGU6oAoSUmY0DAP9CMMvmnxe+fdzY=; b=TTIjvlwgi9QoV/XUdUgGbhMfeyZT3tp+EAIZY3HzMzt9ayaewG3ozZo+3M5XV7oYPA OHAC3LQN8TfegM0f98RKmkZYI5o7ppmL98jC2TqJigZ05PAmtZbhlGszyWNgAWypuLle MU/eGE7DqKm/Ar27xCbDENZ0TvkY1fbaXgieF2tGPVrdjX/nUR+UN3uHS2Z6X/VpC+k7 98qdfi9x93XbRoEMz9HXEh2svw3/iOxA5pQiEnpKIC3Go7FGpDiTqQU7N1nqIfv4aoyO 1TWuJHv3RZ7wm8lsCydLri+TInG6s0cv7/BohsgX9aCRfVGhKiaqp4ApYzw3EYqS08mB Gnfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vE+6+K2v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id on16-20020a17090b1d1000b00274681ee3adsi2691201pjb.8.2023.09.14.19.53.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 19:53:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vE+6+K2v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 26BB1838F07F; Thu, 14 Sep 2023 19:53:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231803AbjIOCxP (ORCPT + 33 others); Thu, 14 Sep 2023 22:53:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231722AbjIOCxL (ORCPT ); Thu, 14 Sep 2023 22:53:11 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 806B72703; Thu, 14 Sep 2023 19:53:07 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44B9DC433C8; Fri, 15 Sep 2023 02:53:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694746386; bh=xT8faQ/VQn4QsrSETrKl21TSbXbkbXRLNmsjtMslsE0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vE+6+K2v8eFHCuG2uMpBuFLYWDxqqOXd+irJE2hgT8Kzn2qCdWCy1yLXm/zxJGcle 766beCUyr429m9vHPiYbpBIH1ir4Ac1FU1pAssUxZCd0fxPupJtIfjmwwqCV1CizFh urwwnI45LhwWV3A+6CX6il2CrZWabaG/fK1UIvPJW4QNgmq7jiOh7NATX2Jh8W9xyx sboRSLtK7W/n1muo988SNeyulnEUWTL/ZqrG2xmmHhw+zkZA3YEHyXowMDaMr2B5hD XGukIVihyc7OyD/VMQU5eVcRYGaRVI6Xe4hn3oV8PWGyIPnbyMw5YD+9QK8yLIrpZk HOBb+tcLjtjgQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Brendan Higgins , damon@lists.linux.dev, linux-mm@kvack.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/8] mm/damon/core-test: add a unit test for damon_moving_sum() Date: Fri, 15 Sep 2023 02:52:47 +0000 Message-Id: <20230915025251.72816-5-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230915025251.72816-1-sj@kernel.org> References: <20230915025251.72816-1-sj@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 14 Sep 2023 19:53:43 -0700 (PDT) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777070427241354467 X-GMAIL-MSGID: 1777070427241354467 Add a simple unit test for the pseudo moving-sum function (damon_moving_sum()). Signed-off-by: SeongJae Park --- mm/damon/core-test.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h index 6cc8b245586d..c539f0e8377e 100644 --- a/mm/damon/core-test.h +++ b/mm/damon/core-test.h @@ -341,6 +341,21 @@ static void damon_test_set_attrs(struct kunit *test) KUNIT_EXPECT_EQ(test, damon_set_attrs(c, &invalid_attrs), -EINVAL); } +static void damon_test_moving_sum(struct kunit *test) +{ + unsigned int mvsum = 50000, nomvsum = 50000, len_window = 10; + unsigned int new_values[] = {10000, 0, 10000, 0, 0, 0, 10000, 0, 0, 0}; + unsigned int expects[] = {55000, 50000, 55000, 50000, 45000, 40000, + 45000, 40000, 35000, 30000}; + int i; + + for (i = 0; i < ARRAY_SIZE(new_values); i++) { + mvsum = damon_moving_sum(mvsum, nomvsum, len_window, + new_values[i]); + KUNIT_EXPECT_EQ(test, mvsum, expects[i]); + } +} + static void damos_test_new_filter(struct kunit *test) { struct damos_filter *filter; @@ -425,6 +440,7 @@ static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_set_regions), KUNIT_CASE(damon_test_update_monitoring_result), KUNIT_CASE(damon_test_set_attrs), + KUNIT_CASE(damon_test_moving_sum), KUNIT_CASE(damos_test_new_filter), KUNIT_CASE(damos_test_filter_out), {}, From patchwork Fri Sep 15 02:52:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 140039 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp765617vqi; Thu, 14 Sep 2023 19:53:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFcdcxUXbAoggbXCDjxlrGUt3s3Ny7BekAM2AN5xsaIHeV6Ydwc6w8dykuePziqUt8NtHTI X-Received: by 2002:a05:6a20:4304:b0:145:6857:457a with SMTP id h4-20020a056a20430400b001456857457amr675717pzk.4.1694746422864; Thu, 14 Sep 2023 19:53:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694746422; cv=none; d=google.com; s=arc-20160816; b=GzPUf6ris32J2CFLlTXleY5HfyO1iMSzy8KB7iyIV4EMcpbUrQevzFLJb4zO3przGY 1udoObqTJEwLNhxhXfSfJVaEREFWvdrEJ/I4ca7bjPgYCHLwUYs3DClI+6BBfp3gRuv8 rBBkhPoC9pkRB4igAJwPiU2AIwK1st8rRzYcPyB6/fhHQK01MY+XM2xpC+VNMnbL8Rjv ypUxyl5RtOxQjy54DZyu03NSEYXtS9bFb/miJFZ8SizmtSGiTFeWXw+HVwcLFU3aLkdG 2FTQGeXzBm+Fjae3vhfR1jVo1vZRcNQoyvq/jz8h2BV6sJAzVJhoi0yN8Ss9TU0OBSbH YUeQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kq5huNrcaXucw0j7mRG+Q0tHkEUy8BekbmYeCC7zaEU=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=JL/LWTast/77CLVvg36xr/j0ZrN6k2ZXNFojFGGMGzFwea/uotQflKytUpKqRhqZ9q +BpzAlvmSjDVH0cpKmDgRqh0cy3PCjMPWek863bOJLgBua9+LONY5Pdk0ve0cY7NASKZ qcyBxNJfZx0zSJUMssX7FiX9NRr7F7OxiZLAfBnNDPZ0I3df5FD+mC/6LAVFpEl0UHt/ i9zhJUVNuz6GFaAHIlCB4tBaJUb7zcbidQTWhhMxJR+ANAy7EcXz2V+eFmvM6TUMZQyX GtaGuKKHuH0lXSKJIXxajKH0WWc0Wxg0H8WQLwWEsYCMnjc5eXfG4ORjgj52RMKIGMHS kQbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UNlsCXn2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id t8-20020a170902e84800b001b80b061e8asi2841352plg.341.2023.09.14.19.53.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 19:53:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UNlsCXn2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id CE0EB83669C3; Thu, 14 Sep 2023 19:53:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231892AbjIOCxW (ORCPT + 33 others); Thu, 14 Sep 2023 22:53:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231759AbjIOCxM (ORCPT ); Thu, 14 Sep 2023 22:53:12 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 843B12701 for ; Thu, 14 Sep 2023 19:53:08 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAF88C433C7; Fri, 15 Sep 2023 02:53:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694746388; bh=wBwPsUGsJdUgsPRGuDP3t7LM9PStyxdXiFRE+6KpN8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UNlsCXn2IBMaifeZPCzuHLGLs2hxZKyJo15KTVgqw2yb4GmWro5TL/tfPUSK6bwAq QSOAsTa0LGtwiKWKcmD1j92KgS8dR/UlLaruT1InEnnlxtuvkE5wIM8GnH2+tyScCR HMt5/hYyduUJntyRBoJPQoWIIz97O2i1IEi621u4wpsk80vovp6HWkUWxkTJjc6RjB MZymM9MTewhbrj7bf1/KSdeYXkLuE/8doyfioVpzF8G9iUZWTtpW9qXiCvu+xpL69h an2xvGCqhontwiXgJKZVeoJGDGf/60hYDKC+MCOd7c9xjhhgMRJAHQNtxTeZMy/dlP HM07jOkZBw0Cw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/8] mm/damon/core: introduce nr_accesses_bp Date: Fri, 15 Sep 2023 02:52:48 +0000 Message-Id: <20230915025251.72816-6-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230915025251.72816-1-sj@kernel.org> References: <20230915025251.72816-1-sj@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 14 Sep 2023 19:53:36 -0700 (PDT) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777070425236365208 X-GMAIL-MSGID: 1777070425236365208 Add yet another representation of the access rate of each region, namely nr_accesses_bp. It is just same to the nr_accesses but represents the value in basis point (1 in 10,000), and updated at once in every aggregation interval. That is, moving_accesses_bp is just nr_accesses * 10000. This may seems useless at the moment. However, it will be useful for representing less than one nr_accesses value that will be needed to make moving sum-based nr_accesses. Signed-off-by: SeongJae Park --- include/linux/damon.h | 5 +++++ mm/damon/core-test.h | 5 +++++ mm/damon/core.c | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 487a545a11b4..15f24b23c9a0 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -40,6 +40,7 @@ struct damon_addr_range { * @ar: The address range of the region. * @sampling_addr: Address of the sample for the next access check. * @nr_accesses: Access frequency of this region. + * @nr_accesses_bp: @nr_accesses in basis point (0.01%). * @list: List head for siblings. * @age: Age of this region. * @@ -49,6 +50,9 @@ struct damon_addr_range { * not be done with direct access but with the helper function, * damon_update_region_access_rate(). * + * @nr_accesses_bp is another representation of @nr_accesses in basis point + * (1 in 10,000) that updated every aggregation interval. + * * @age is initially zero, increased for each aggregation interval, and reset * to zero again if the access frequency is significantly changed. If two * regions are merged into a new region, both @nr_accesses and @age of the new @@ -58,6 +62,7 @@ struct damon_region { struct damon_addr_range ar; unsigned long sampling_addr; unsigned int nr_accesses; + unsigned int nr_accesses_bp; struct list_head list; unsigned int age; diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h index c539f0e8377e..79f1f12e0dd5 100644 --- a/mm/damon/core-test.h +++ b/mm/damon/core-test.h @@ -94,6 +94,7 @@ static void damon_test_aggregate(struct kunit *test) for (ir = 0; ir < 3; ir++) { r = damon_new_region(saddr[it][ir], eaddr[it][ir]); r->nr_accesses = accesses[it][ir]; + r->nr_accesses_bp = accesses[it][ir] * 10000; damon_add_region(r, t); } it++; @@ -147,9 +148,11 @@ static void damon_test_merge_two(struct kunit *test) t = damon_new_target(); r = damon_new_region(0, 100); r->nr_accesses = 10; + r->nr_accesses_bp = 100000; damon_add_region(r, t); r2 = damon_new_region(100, 300); r2->nr_accesses = 20; + r2->nr_accesses_bp = 200000; damon_add_region(r2, t); damon_merge_two_regions(t, r, r2); @@ -196,6 +199,7 @@ static void damon_test_merge_regions_of(struct kunit *test) for (i = 0; i < ARRAY_SIZE(sa); i++) { r = damon_new_region(sa[i], ea[i]); r->nr_accesses = nrs[i]; + r->nr_accesses_bp = nrs[i] * 10000; damon_add_region(r, t); } @@ -297,6 +301,7 @@ static void damon_test_update_monitoring_result(struct kunit *test) struct damon_region *r = damon_new_region(3, 7); r->nr_accesses = 15; + r->nr_accesses_bp = 150000; r->age = 20; new_attrs = (struct damon_attrs){ diff --git a/mm/damon/core.c b/mm/damon/core.c index b005dc15009f..ce85c00b0a4c 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -128,6 +128,7 @@ struct damon_region *damon_new_region(unsigned long start, unsigned long end) region->ar.start = start; region->ar.end = end; region->nr_accesses = 0; + region->nr_accesses_bp = 0; INIT_LIST_HEAD(®ion->list); region->age = 0; @@ -508,6 +509,7 @@ static void damon_update_monitoring_result(struct damon_region *r, { r->nr_accesses = damon_nr_accesses_for_new_attrs(r->nr_accesses, old_attrs, new_attrs); + r->nr_accesses_bp = r->nr_accesses * 10000; r->age = damon_age_for_new_attrs(r->age, old_attrs, new_attrs); } @@ -1115,6 +1117,7 @@ static void damon_merge_two_regions(struct damon_target *t, l->nr_accesses = (l->nr_accesses * sz_l + r->nr_accesses * sz_r) / (sz_l + sz_r); + l->nr_accesses_bp = l->nr_accesses * 10000; l->age = (l->age * sz_l + r->age * sz_r) / (sz_l + sz_r); l->ar.end = r->ar.end; damon_destroy_region(r, t); @@ -1138,6 +1141,8 @@ static void damon_merge_regions_of(struct damon_target *t, unsigned int thres, else r->age++; + r->nr_accesses_bp = r->nr_accesses * 10000; + if (prev && prev->ar.end == r->ar.start && abs(prev->nr_accesses - r->nr_accesses) <= thres && damon_sz_region(prev) + damon_sz_region(r) <= sz_limit) @@ -1186,6 +1191,7 @@ static void damon_split_region_at(struct damon_target *t, new->age = r->age; new->last_nr_accesses = r->last_nr_accesses; + new->nr_accesses_bp = r->nr_accesses_bp; damon_insert_region(new, r, damon_next_region(r), t); } From patchwork Fri Sep 15 02:52:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 140045 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp765677vqi; Thu, 14 Sep 2023 19:53:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEePT11n87SMzIFInSVpuemqWFz+wRmCj5J0VIRzQmueHNfpQTKZwggtSd/ncX+5XRluKis X-Received: by 2002:a17:90a:9417:b0:26f:87d1:e48 with SMTP id r23-20020a17090a941700b0026f87d10e48mr4980166pjo.20.1694746436956; Thu, 14 Sep 2023 19:53:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694746436; cv=none; d=google.com; s=arc-20160816; b=vMBdhD6ftfaMjzaTcXWJh+dj/t0EEEE4mARFCkdIoryOJ9ghOoNx+hoHOUVPBPj86R yCr0ORao0buLL8y6u+vOmbccVdXJ6gMtWkk7GQD5VlV9WL9+ZW9WCxJBzGiLTi7innYO VRkPmHTHS8Qwv2mGkI3VggyZbcxUguSyJTz3Df9tq1w6GVTSssm4eid5SxwMiEXmEECT XTyK0aQeIEHt90rfkl0psBJfbEPQtcbu/LAJXtBYnCGBv9Vo1InwHUa34mA8kXfpwdPe pckGDfSDL6FdEL84b/e9ZAazyT8rcgE5XtiWJPTg8rFuG0J/zg3WGMWdamSzdbtP+8WO ZOqw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yas1krmMytP5jdv3DOjnLBNiWh5GBRJ7GxfCNOjPUeE=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=YW9CSdIaQ4FBfpktZILnInj6XBwjJxDdhQf7bKqe+rJqAS+Qk5Lrs5E88EMigkRQeF mpbcktc4ndiN5C1uTKDUJu/sPKgiKzLkoVzwihhQ8j3Li2ApK2/Yg5T31H2XdH4SoC9A lzUXtFjymNjpHVNcx0efgDX/g/qLieKVXKYCFtxRtXWaIb1KXUVSxXUo9RuJ76XjUx9F Rl336ruUCh3OcFU970KCGPmzI6SNElLyrY+ztyouF/BWqlNy9q+f3BeY5rj0kQVrT2f7 YYXbwlDPzR4/SnJbDIffd2mStV7W6444e7xxENRi+YaeOXE01ugQKKS3N/PaRgWY6j+w IdYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="gKRZh/eQ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id o6-20020a6548c6000000b005780a1effa4si1369156pgs.375.2023.09.14.19.53.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 19:53:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="gKRZh/eQ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 0AB3383CF4B5; Thu, 14 Sep 2023 19:53:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231877AbjIOCx2 (ORCPT + 33 others); Thu, 14 Sep 2023 22:53:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231808AbjIOCxU (ORCPT ); Thu, 14 Sep 2023 22:53:20 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E139D270C for ; Thu, 14 Sep 2023 19:53:09 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22D18C433CA; Fri, 15 Sep 2023 02:53:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694746389; bh=Nt+EQkpN6g4pK9W8aFPRK0//Zoaw9gTVad64o5lt3eA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gKRZh/eQUciGBq4zsaSk5NtoLQsupXcxMJ/a50/LGY+nOoGWuUjC6y2orIQp3obtI kXAhaTSvmkPcLcIBo83U43YcT5/rR5+67cCeNTXQlVjlTdinObZwE9rv8twhhAoFQ+ hfODNrii+3froco6CXwiwvl/To4vC87JSvSxXDv/eJWIQZELjCY1rxBMVpzzcvLU93 LKH7YRnIV2jtSEIA2qyPFoj0BJ7KiovZ49aLLrfHP/SjF8OE2hm2oY/XWCe7owdqgw /nEekEFdyI15efQdNOybauZ+1SdgCXF10FOBqA+Hs0IMEHvkEUrNqT1fUkNKZoBVdj COaVPLwQxu3zw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/8] mm/damon/core: use pseudo-moving sum for nr_accesses_bp Date: Fri, 15 Sep 2023 02:52:49 +0000 Message-Id: <20230915025251.72816-7-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230915025251.72816-1-sj@kernel.org> References: <20230915025251.72816-1-sj@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 14 Sep 2023 19:53:45 -0700 (PDT) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777070439772545876 X-GMAIL-MSGID: 1777070439772545876 Let nr_accesses_bp be calculated as a pseudo-moving sum that updated for every sampling interval, using damon_moving_sum(). This is assumed to be useful for cases that the aggregation interval is set quite huge, but the monivoting results need to be collected earlier than next aggregation interval is passed. Signed-off-by: SeongJae Park --- include/linux/damon.h | 12 +++++++++--- mm/damon/core.c | 16 +++++++++++++++- mm/damon/paddr.c | 9 +++++---- mm/damon/vaddr.c | 12 +++++++----- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 15f24b23c9a0..0fe13482df63 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -40,7 +40,8 @@ struct damon_addr_range { * @ar: The address range of the region. * @sampling_addr: Address of the sample for the next access check. * @nr_accesses: Access frequency of this region. - * @nr_accesses_bp: @nr_accesses in basis point (0.01%). + * @nr_accesses_bp: @nr_accesses in basis point (0.01%) that updated for + * each sampling interval. * @list: List head for siblings. * @age: Age of this region. * @@ -51,7 +52,11 @@ struct damon_addr_range { * damon_update_region_access_rate(). * * @nr_accesses_bp is another representation of @nr_accesses in basis point - * (1 in 10,000) that updated every aggregation interval. + * (1 in 10,000) that updated for every &damon_attrs->sample_interval in a + * manner similar to moving sum. By the algorithm, this value becomes + * @nr_accesses * 10000 for every &struct damon_attrs->aggr_interval. This can + * be used when the aggregation interval is too huge and therefore cannot wait + * for it before getting the access monitoring results. * * @age is initially zero, increased for each aggregation interval, and reset * to zero again if the access frequency is significantly changed. If two @@ -629,7 +634,8 @@ int damon_set_regions(struct damon_target *t, struct damon_addr_range *ranges, unsigned int nr_ranges); unsigned int damon_moving_sum(unsigned int mvsum, unsigned int nomvsum, unsigned int len_window, unsigned int new_value); -void damon_update_region_access_rate(struct damon_region *r, bool accessed); +void damon_update_region_access_rate(struct damon_region *r, bool accessed, + struct damon_attrs *attrs); struct damos_filter *damos_new_filter(enum damos_filter_type type, bool matching); diff --git a/mm/damon/core.c b/mm/damon/core.c index ce85c00b0a4c..29ee1fc18393 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1599,14 +1599,28 @@ unsigned int damon_moving_sum(unsigned int mvsum, unsigned int nomvsum, * damon_update_region_access_rate() - Update the access rate of a region. * @r: The DAMON region to update for its access check result. * @accessed: Whether the region has accessed during last sampling interval. + * @attrs: The damon_attrs of the DAMON context. * * Update the access rate of a region with the region's last sampling interval * access check result. * * Usually this will be called by &damon_operations->check_accesses callback. */ -void damon_update_region_access_rate(struct damon_region *r, bool accessed) +void damon_update_region_access_rate(struct damon_region *r, bool accessed, + struct damon_attrs *attrs) { + unsigned int len_window = 1; + + /* + * sample_interval can be zero, but cannot be larger than + * aggr_interval, owing to validation of damon_set_attrs(). + */ + if (attrs->sample_interval) + len_window = attrs->aggr_interval / attrs->sample_interval; + r->nr_accesses_bp = damon_moving_sum(r->nr_accesses_bp, + r->last_nr_accesses * 10000, len_window, + accessed ? 10000 : 0); + if (accessed) r->nr_accesses++; } diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index 44f21860b555..081e2a325778 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -148,7 +148,8 @@ static bool damon_pa_young(unsigned long paddr, unsigned long *folio_sz) return accessed; } -static void __damon_pa_check_access(struct damon_region *r) +static void __damon_pa_check_access(struct damon_region *r, + struct damon_attrs *attrs) { static unsigned long last_addr; static unsigned long last_folio_sz = PAGE_SIZE; @@ -157,12 +158,12 @@ static void __damon_pa_check_access(struct damon_region *r) /* If the region is in the last checked page, reuse the result */ if (ALIGN_DOWN(last_addr, last_folio_sz) == ALIGN_DOWN(r->sampling_addr, last_folio_sz)) { - damon_update_region_access_rate(r, last_accessed); + damon_update_region_access_rate(r, last_accessed, attrs); return; } last_accessed = damon_pa_young(r->sampling_addr, &last_folio_sz); - damon_update_region_access_rate(r, last_accessed); + damon_update_region_access_rate(r, last_accessed, attrs); last_addr = r->sampling_addr; } @@ -175,7 +176,7 @@ static unsigned int damon_pa_check_accesses(struct damon_ctx *ctx) damon_for_each_target(t, ctx) { damon_for_each_region(r, t) { - __damon_pa_check_access(r); + __damon_pa_check_access(r, &ctx->attrs); max_nr_accesses = max(r->nr_accesses, max_nr_accesses); } } diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c index e36303271f9d..af2cb82e1fad 100644 --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -557,26 +557,27 @@ static bool damon_va_young(struct mm_struct *mm, unsigned long addr, * r the region to be checked */ static void __damon_va_check_access(struct mm_struct *mm, - struct damon_region *r, bool same_target) + struct damon_region *r, bool same_target, + struct damon_attrs *attrs) { static unsigned long last_addr; static unsigned long last_folio_sz = PAGE_SIZE; static bool last_accessed; if (!mm) { - damon_update_region_access_rate(r, false); + damon_update_region_access_rate(r, false, attrs); return; } /* If the region is in the last checked page, reuse the result */ if (same_target && (ALIGN_DOWN(last_addr, last_folio_sz) == ALIGN_DOWN(r->sampling_addr, last_folio_sz))) { - damon_update_region_access_rate(r, last_accessed); + damon_update_region_access_rate(r, last_accessed, attrs); return; } last_accessed = damon_va_young(mm, r->sampling_addr, &last_folio_sz); - damon_update_region_access_rate(r, last_accessed); + damon_update_region_access_rate(r, last_accessed, attrs); last_addr = r->sampling_addr; } @@ -593,7 +594,8 @@ static unsigned int damon_va_check_accesses(struct damon_ctx *ctx) mm = damon_get_mm(t); same_target = false; damon_for_each_region(r, t) { - __damon_va_check_access(mm, r, same_target); + __damon_va_check_access(mm, r, same_target, + &ctx->attrs); max_nr_accesses = max(r->nr_accesses, max_nr_accesses); same_target = true; } From patchwork Fri Sep 15 02:52:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 140064 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp772271vqi; Thu, 14 Sep 2023 20:11:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHWTCJbsGfkUPo8hLmc3wjzOz/Drbh1rOgxfZe+LonbaRv020A7mDT5Qacuj+SGE7G+RD53 X-Received: by 2002:a05:6a00:1141:b0:68f:c057:b567 with SMTP id b1-20020a056a00114100b0068fc057b567mr409217pfm.26.1694747511133; Thu, 14 Sep 2023 20:11:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694747511; cv=none; d=google.com; s=arc-20160816; b=bPbMjvkouz3KQ8pcDbx3XhE5kGLkYtyswfRQSJkbJBOfjIMUhJ0VHfWYIQ2k4Ge3rz /rcpYChgMjBNbD+58mFVtJebkHud6SdY7DYFfwX7evWvOHFu8IwQ6YsIzY/cCwLnP7O+ qrDfd1WUj+aM8joACbJd+vTOneMotlN87fjYUUYX4s46eSiy2aZOCRRvVBOo7AiZGtyi CoagiwA5jDWvASFYwEJrlDGhhd7CDgvTwuE7FIwcumUHvOlIBun8uj4SCb1y3yRE1c67 yavMOwmLFQksiBVNKuRI8IjthIe/hpNe7tesNvdW0PtuGWnBmZQALbZ3VojL3vFdIpk3 Z+Yw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=35ICP7tkeKkUG2m8I3W+MDZQL7PDEnmFeI1sDSKJbJU=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=OGLOJhihNXTm7RAGoNqPY3yfKcUPk77YHqSOzFHaacJy65BA44Z6dezmPa2joP55gJ GanBvfEpWLXxLCXZYlNxf7z118oZVWLkqQO1aviYk+XODexSEn4u8BBqBqcZ4sfR9pwv 6bGSfOkLrqzUCk3HzA2njHXN6qsz+Akp/GAF0du4ETmX/qfs5o/lrmcvTm/u2azYcjSy cqxSzyoBvI3hVoWYer7ADBBxd4j/H8EdndNoJ952/yO0yb+6pgIKGp1Kcebu8JDVY3P0 TRazuLjRMbhF93HZVXDPVySJF2FRmisRzRIcuN/0eCyUxQyzj1xgAM0UTFD6q1r9ClyC j8oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eSK3bW5S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id g14-20020a056a000b8e00b0068a4ba92eafsi2655926pfj.54.2023.09.14.20.11.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 20:11:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eSK3bW5S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 835D282CA0F6; Thu, 14 Sep 2023 19:53:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231844AbjIOCxX (ORCPT + 33 others); Thu, 14 Sep 2023 22:53:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231758AbjIOCxU (ORCPT ); Thu, 14 Sep 2023 22:53:20 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 447BB2719 for ; Thu, 14 Sep 2023 19:53:11 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 755C8C433C9; Fri, 15 Sep 2023 02:53:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694746390; bh=54IK7cTm7KTNNX3XLRdWLVNJIup7inyJ/KiBfKYDcxs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eSK3bW5SwDXeS5zPCPPJiBwfd5vAIC7cx1I5DGDc3g1gvuXMCm8OZyYZaFTizCXr6 IGsoW8btGA90xigquM8091rNDyfmkhLNZwW7AIw8V9/opp1tvo1+424tjJaU6cby3j I/vcCzrwXGjBievjJ4k0LmkDlgt7Vpsff/hAU6iCuuvjFBQdjenQIAcfFr6mVvqAxE lvVQoEfYtTh4DFK+Os4lxuxXzBf8ovK+gvvU36ZpNYmDj0Q6OOWQtg+hcgCSutY3O4 y0w09Gspx4AymqefNtFvvOVgLXTTfoD0VfrvZtP6/fxVMSrz1FavT9eJGsqjrrSzLS oT47TwypudG+g== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 7/8] mm/damon/core: skip updating nr_accesses_bp for each aggregation interval Date: Fri, 15 Sep 2023 02:52:50 +0000 Message-Id: <20230915025251.72816-8-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230915025251.72816-1-sj@kernel.org> References: <20230915025251.72816-1-sj@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 14 Sep 2023 19:53:35 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777071565983263586 X-GMAIL-MSGID: 1777071565983263586 damon_merge_regions_of(), which is called for each aggregation interval, updates nr_accesses_bp to nr_accesses * 10000. However, nr_accesses_bp is updated for each sampling interval via damon_moving_sum() using the aggregation interval as the moving time window. And by the definition of the algorithm, the value becomes same to discrete-window based sum for each time window-aligned time. Hence, nr_accesses_bp will be same to nr_accesses * 10000 for each aggregation interval without explicit update. Remove the unnecessary update of nr_accesses_bp in damon_merge_regions_of(). Signed-off-by: SeongJae Park --- mm/damon/core.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 29ee1fc18393..45cc108c0fe1 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1141,8 +1141,6 @@ static void damon_merge_regions_of(struct damon_target *t, unsigned int thres, else r->age++; - r->nr_accesses_bp = r->nr_accesses * 10000; - if (prev && prev->ar.end == r->ar.start && abs(prev->nr_accesses - r->nr_accesses) <= thres && damon_sz_region(prev) + damon_sz_region(r) <= sz_limit) From patchwork Fri Sep 15 02:52:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 140043 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp765640vqi; Thu, 14 Sep 2023 19:53:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE1xgI4NmIQp9cRbccwyMxBd9dzIk25hPUwjzliOPOfJus7ZECz//vhUKE9JY15SfVe8Df/ X-Received: by 2002:a05:6a21:819e:b0:156:dc22:96a6 with SMTP id pd30-20020a056a21819e00b00156dc2296a6mr528668pzb.55.1694746426734; Thu, 14 Sep 2023 19:53:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694746426; cv=none; d=google.com; s=arc-20160816; b=IXkb0sJY0UoOAkhqcfYz+fay0NQIHghj5dry/Pozk3t9ZdcpaR0DhUEPkiV1AbeSPa hyVzZ2MX5shQDPxKP6DMCqYVV5TzCFBRrZKb/4vrIXAyZte1549AyzpJL1t0t9biTSUh TuxSxywZqV3p96Y1rfgPwlkLjxTvE3Lkmi2U+0W0jw3tp9gUPtwd+CCHtg85APxXMVKe Y1jY7AQihrPjcCgEUEOLTL5tgs3rukZLiGFcPgayCC0/oBMgCOi1gB24KXY+V8XQ/AhM wTpXsFvlQAdNX3IEFVwggin6g0HGIdGOTRdJw/+2tZrJqkYkFT5brsOMRoeZxu6IwJMK 3gRg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5nv6ta+5+IPL0DQgGt4qp4kHWCSK8jkn9EGeLE0STJY=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=xzBpGtKQA2KBhhmgf9FaCFEvAb/36j9vzkExe1LZD7JzcInsdR6FqHfCgIWVgEigp8 HhTCSBVEbMUzh04QFQZk2xU4z2dhKKAB0D+eFUQNftE4xpOfcmQmskJd/qvr1MzQqKFn XfV2wEu5yOXD9XUALVfNm94cNk1tXRfLFWvUqGLVmcA4dc+w3ldtTTMi37fNdtxFrB5g msA6K7oDvw6z9d/dKOqDSfHIIYxqt9y7K+6DqmS0MYm0DhfrC8O5vLiLhfjat1BLdnu6 GtM99GSKevIh0NDS2GdYxm651+3TJI0dX2y/SqakivUVqESBFOFrU7SiyyQTucHCcdAQ 6ysg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="GgK6DIT/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id x7-20020a056a000bc700b0068e45c9c986si2436459pfu.136.2023.09.14.19.53.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 19:53:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="GgK6DIT/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id A06868313D02; Thu, 14 Sep 2023 19:53:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231808AbjIOCxb (ORCPT + 33 others); Thu, 14 Sep 2023 22:53:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231859AbjIOCxV (ORCPT ); Thu, 14 Sep 2023 22:53:21 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97669272C for ; Thu, 14 Sep 2023 19:53:12 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBC4AC43391; Fri, 15 Sep 2023 02:53:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694746392; bh=RYtjac5KN7rdOK43JC6LnDJ12z7FKzya3dCtCsi8Y0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GgK6DIT/rJEDrFaud01fxNb9X9ulgXc+DHEZpEYNHpQBHaq6gCDhkm5CNvhTtn3nY UbHvgHF8XfDy9iIQIOfKt9G99WrG6wz1rwaSpybz3ut17/5oFJLGNwPwq1dcXrWKXw 07Q++0DI8CyHA7uWn8iE/iur/xjP7LIoSyXDJG46430Bw910FuSgyA45Gs5G4frZcV Ta3OJrD342CslwNXGEcjPCByNlfc4PH3dXgyopGgHEaLztbBRCa9GDKaRR+CsuB4V7 OzStFx2T2Mv1/CPjbye7T09snFeyN6HXv+p2/gZ5lgLUNFJItBRAK+qhQ0xw8XEGD0 hlGk0P+/2eBlQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 8/8] mm/damon/core: mark damon_moving_sum() as a static function Date: Fri, 15 Sep 2023 02:52:51 +0000 Message-Id: <20230915025251.72816-9-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230915025251.72816-1-sj@kernel.org> References: <20230915025251.72816-1-sj@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 14 Sep 2023 19:53:44 -0700 (PDT) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777070429275153215 X-GMAIL-MSGID: 1777070429275153215 The function is used by only mm/damon/core.c. Mark it as a static function. Signed-off-by: SeongJae Park --- include/linux/damon.h | 2 -- mm/damon/core.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 0fe13482df63..491fdd3e4c76 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -632,8 +632,6 @@ void damon_add_region(struct damon_region *r, struct damon_target *t); void damon_destroy_region(struct damon_region *r, struct damon_target *t); int damon_set_regions(struct damon_target *t, struct damon_addr_range *ranges, unsigned int nr_ranges); -unsigned int damon_moving_sum(unsigned int mvsum, unsigned int nomvsum, - unsigned int len_window, unsigned int new_value); void damon_update_region_access_rate(struct damon_region *r, bool accessed, struct damon_attrs *attrs); diff --git a/mm/damon/core.c b/mm/damon/core.c index 45cc108c0fe1..b15cf47d2d29 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1587,7 +1587,7 @@ int damon_set_region_biggest_system_ram_default(struct damon_target *t, * * Return: Pseudo-moving average after getting the @new_value. */ -unsigned int damon_moving_sum(unsigned int mvsum, unsigned int nomvsum, +static unsigned int damon_moving_sum(unsigned int mvsum, unsigned int nomvsum, unsigned int len_window, unsigned int new_value) { return mvsum - nomvsum / len_window + new_value;