From patchwork Sat Sep 9 03:37:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13377946 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 DA53AEEB580 for ; Sat, 9 Sep 2023 03:37:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 003266B00F8; Fri, 8 Sep 2023 23:37:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EA6746B00FE; Fri, 8 Sep 2023 23:37:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6E666B0102; Fri, 8 Sep 2023 23:37:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C6FFF6B00F8 for ; Fri, 8 Sep 2023 23:37:29 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 876FB40527 for ; Sat, 9 Sep 2023 03:37:29 +0000 (UTC) X-FDA: 81215649018.22.D0AE9C5 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf04.hostedemail.com (Postfix) with ESMTP id B52BD40004 for ; Sat, 9 Sep 2023 03:37:27 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=G4g9Ika5; spf=pass (imf04.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694230648; 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=xlq3E3DVQjLA3U4TLTkT3nYNLUiEsTpudJTXACXcv8w=; b=ay22P6VXyRyE40KEaaBFtd4Y7LprcCKmfcVIpoBGLakhwZVKBmvwD5e+70KHfR3oOjtAnF xeoVySvpO2ccM4j7K6Rc5BGRetOOPUBuYPjLtZ7mkI2sM8Lqnbo3+BVkdTI9acBMOcLLqi VeiQi11VPAvxGeJfmKfE/k28hyDNdB0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694230648; a=rsa-sha256; cv=none; b=c2s7sHAy+QgHRCXaLNJSihgu0Y9PnH1pW5v1zp0L4jbxcy7Yk2+85nM+zxyvNeZytd48M7 MEsIe26HMcFi5SgJ7uZBxG4rw7RJTULPoHV6FIBT6ETKMl5fFI5j7U+2V7tmyBFdFfktlJ b5LIRCGg8tIRa93aJmC04Ulc6jcrhm0= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=G4g9Ika5; spf=pass (imf04.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id EF8FDB821D3; Sat, 9 Sep 2023 03:37:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55D1CC433C9; Sat, 9 Sep 2023 03:37:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694230644; bh=CWWNXIT/Dwd1+BhRyAHtcclmBn8xtMZ9uwzWWOesbz8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G4g9Ika5VasJRZpdNkehsQGg8kmNgm1qwLM5nZc1OQ3bp6R4DT1lFH3+zQDyEhyuv mefns1GVzCJtq+OvVa44z8SXvojBkwZ34RpBCIV1f5cCrtu/W7gTjDfqjXKyttEonk /4N1vy0njVJ9mulokK5u9jis8z2OUzLntqRp8t07GX2o24Kwfc2nr74r5yzPoYtRRp XHMGOcsoRuAex+MbtNun2Ggn/Y+i1aTbNVuNSbMvQjpAERbfaphUfeGRNyJ6Yd1iAj OuFS/cHAejFEM+RrL/gstTaIoFQXWfmO+6ELklli6wCU9/VV+c6IGRUfZJGWdtfprd faNCXU0uVKbnA== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC 1/8] mm/damon/core: define and use a dedicated function for region access rate update Date: Sat, 9 Sep 2023 03:37:04 +0000 Message-Id: <20230909033711.55794-2-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230909033711.55794-1-sj@kernel.org> References: <20230909033711.55794-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: B52BD40004 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: x8ya7ni3xaspiqbg63qg5no5waj8nmd5 X-HE-Tag: 1694230647-676649 X-HE-Meta: U2FsdGVkX19ChyEmap+F2N7hHZP5lkwBbUdrB9RMKq27tC/m1Sc6k5C6iHPwrEYq+Q0XO21Yo7fKUtDKn3buBoeJb/GMNR6+9jweUsyDb854AINNDFAhlmjq8tzGkGPy0T0H3OHayGm/7EQkr5o8IWIRLnFu+z9Ys5DhnmXj6D+qK23wZrfOZoKT0iY52Pbp/98bS63+pNDF9i55J+nGKxto6aZ0w6vBbvaEav7WuVts0hjNqmUZNBU6MHrtSP7Ej0fxbMmH7VIrvViBPC0Kcz1jNnB3dVK0j4qQBvP30vIPrh/pNAoFg8WjQjJw4XHnPRXhsIuHDTrNo+O5wnptzAuGXF3QxSF2oJ6gZxg0MmMnXKb/4qEDiHbnBrVUWL46kQcgFVuXsWBDCaN1sIVzz36Q/2RpjWBhEvfo4U04l1MRDgm/Ruia7Q4VJQutYTgMbTO3D5knF19vuYNLSyLNsXReiQioOCK6IIo+fxVjQReIqyIGn6JPTONv48Nh8tpsoPvYF9kv2OMq47HnDpkIM2tuGq7Vj++2KZMQKT2DMqozKpKUF21aDrR1H5R/20cwXgirQnqZdQESbKYFENm1h9C72ztJFmx/eW9PysCYHaI1VJjglCXuuzXmBKdU+V4X9GixkCxlQgEEr5+O2FNPD6si7mQqeUNX+8QyBgX/qxAcRr/d2Ai44SmeQrh3TfITM8C144AoFnoct4KtTXYav+no/fFvblc3ObK6E57Hv1IAIp0lgFmAHpY20QTq5AmCkQ0h9lsBgrOAqhrlmsI23B+p/XVFgs9lbXqUN6JthA1LCcM+zP58EJzE1ybKJiuZcZMtlHHDn3TMl7MGajAdEpuAe7ODD38ijs8XnVtYWEohOuWQk5HAIreWkRBeYR968gcwby19U+Geq3oajsGjJxibnwUfTiHQMnALSwqXyxvRzpSqCpxXQrSW7Msw/i9W6l2zGmoKsJOPsCECBes qqFJktZd fruvsTx+KT2rj9UZIf84IBgWwNMBaDOVbkS1AG/7geZKrdxHkL0mAdp2sBQ64dGyHiRWQVGqaALIfDN/+K6OlSFVduLrZO7nuBxZW2Ir3k++LwKxxqOYmMh6WMqsHEM17nqH1vCi3+/aQ6BvuVxBs16OddglD0Ovv3akh6SVCxxAYVlJL7FSOIg0k0Zd3NtJ585mSlDP+d/1xBdsMlQOv9kR1n9Vc3nhDpftKZYviL1AQvatKo2DW2HzCAJW2jcW6XmO5FTn7Smbeyh0H/LSOX0fWMo5yJLrEd6La6LM11fqfQYlD+UZODDwFotPDibH8txZccFfy7RkDxjkbLnBWuiNQqA== 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: 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 6f37997afc54..3d51a1dfe104 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1589,6 +1589,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; }