Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1724404rwe; Sat, 27 Aug 2022 15:31:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR7O1IOnnKgt+IyQ/6OxrhHxsRkhmGggzc/TZb4l9hoESzvzby7M726ZkLs0rg3g+nhxvokX X-Received: by 2002:a05:6402:5513:b0:43a:b866:b9ab with SMTP id fi19-20020a056402551300b0043ab866b9abmr11542915edb.290.1661639488472; Sat, 27 Aug 2022 15:31:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661639488; cv=none; d=google.com; s=arc-20160816; b=q6iAj6elJ6Z8Y8+xRwSzoH5t6aqxkuute3wcLWjvw5tmVFJxLUfORIvtcRzwJn2moz ii7FSpEUIUiFEMHIQeknAUkHxh4Rm5eMNGU41XBSZODU9eOBfEJ8DMb0J3mpoWSEPIvV WyZHEOgX2WKB+Va8jDQsSyNr6L44fFEH/P1g9zOdzaqeGZepCTaqXyTjhfSHY4IKso2K X58P6Gfz6QmvttGuiflq3+9EALhNmDBoJ2v6jdc4nXxzcV2RlpgLG6MnSPyQB5nNDyQS Ci6PEeYyfeNvUnXC6lJjoVXg0tS1Q5zirltSwEgLBrbrinoVhCwkO4lp4T6nS4WU7eGd EBkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=Ga3usIol0H8BHmJDe3+t4HpliZkVnqnXhdNWwhpv+k8=; b=0mpTkGkSvJQXFb0j3ufgF8ofvS3DcQuu7MEoG9DELCNqF2AmPa3JszStu4v8JN0PRt nIWnjYAYubnW+YADVGDONC+4H9WKjdD2rDp2NCIpW2/CNQzTq/jO5YeHXkh30gGGzz3U g8Z5WmhmFrecro1SOoZo4tyxSqUeU8y2js6hLaR5YJHSaWhJ95Dg3zq3eki/pySb4Ala NbzqIZoLOicCGYyFrrk3biR4c4k5W05PQUF47Br7mDG6lYSdpYhiTga52eT6Hu/fDZpV 6khQQcApHoJ3FsIUE1XNc92JmLmoOTy/klTgtt6S4mxSedSWxy5dr9kMnk9Wrom5gYfT NCWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=C4FWztKI; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w3-20020a170906184300b00736ce5254f9si3613569eje.335.2022.08.27.15.31.03; Sat, 27 Aug 2022 15:31:28 -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; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=C4FWztKI; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229916AbiH0VZJ (ORCPT + 99 others); Sat, 27 Aug 2022 17:25:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbiH0VZH (ORCPT ); Sat, 27 Aug 2022 17:25:07 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77179237DD for ; Sat, 27 Aug 2022 14:25:04 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id 88862B807EB for ; Sat, 27 Aug 2022 21:25:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2361C433C1; Sat, 27 Aug 2022 21:25:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661635502; bh=068uzntAkNH5X9Td+k8jUVFGtdkDKzgG4mnydnaanMc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C4FWztKIudC8xTWLlZ26k0EWVjG6yfms7TsrfOUSuA4LrHAdJ68l+1TO66PZ3kzvq MUJIgPeLqae0lG74qHSvhKg5EpaPyJ1hI3XJ+ZNEHgoTzwIReBwEJulqx7soYRjc/l jJ5zcKjQNui9V8rMbkNe6Eo6v6ojMrHDM5rbJ0WJ+Zv/S2X2i7ApuL4+bHe5zE5zGh kSOoiTq7kDRg3M2roTL9qVPfuXexvfZD9q2LRxQsgOl3HEbenxmhoiGZFH2o1dKd+x o+fjMQirr4GFDEG66ApAPmLYsTvOy5TnFlwSp24nMTt49T4jm6wWZ5drPDDSlWoL95 johV6GXOQ72Sw== From: SeongJae Park Cc: sj@kernel.org, akpm@linux-foundation.org, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Kaixu Xia Subject: Re: [PATCH v2 2/2] mm/damon/vaddr: remove comparison between mm and last_mm when checking region accesses Date: Sat, 27 Aug 2022 21:25:00 +0000 Message-Id: <20220827212500.50479-1-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <1661590971-20893-3-git-send-email-kaixuxia@tencent.com> References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Kaixu, > From: Kaixu Xia > > The damon regions that belong to the same damon target have the same > 'struct mm_struct *mm', so it's unnecessary to compare the mm and last_mm > objects among the damon regions in one damon target when checking accesses. > But the check is necessary when the target changed in > '__damon_va_check_accesses()', so we can simplify the whole operation by > using the bool 'same_target' to indicate whether the target changed. > > Signed-off-by: Kaixu Xia Reviewed-by: SeongJae Park Thanks, SJ > --- > mm/damon/vaddr.c | 11 ++++++----- > 1 file changed, 6 insertions(+), 5 deletions(-) > > diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c > index e481f81c3efb..5f66c826ee3a 100644 > --- a/mm/damon/vaddr.c > +++ b/mm/damon/vaddr.c > @@ -533,15 +533,14 @@ 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) > + struct damon_region *r, bool same_target) > { > - static struct mm_struct *last_mm; > static unsigned long last_addr; > static unsigned long last_page_sz = PAGE_SIZE; > static bool last_accessed; > > /* If the region is in the last checked page, reuse the result */ > - if (mm == last_mm && (ALIGN_DOWN(last_addr, last_page_sz) == > + if (same_target && (ALIGN_DOWN(last_addr, last_page_sz) == > ALIGN_DOWN(r->sampling_addr, last_page_sz))) { > if (last_accessed) > r->nr_accesses++; > @@ -552,7 +551,6 @@ static void __damon_va_check_access(struct mm_struct *mm, > if (last_accessed) > r->nr_accesses++; > > - last_mm = mm; > last_addr = r->sampling_addr; > } > > @@ -562,14 +560,17 @@ static unsigned int damon_va_check_accesses(struct damon_ctx *ctx) > struct mm_struct *mm; > struct damon_region *r; > unsigned int max_nr_accesses = 0; > + bool same_target; > > 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); > + __damon_va_check_access(mm, r, same_target); > max_nr_accesses = max(r->nr_accesses, max_nr_accesses); > + same_target = true; > } > mmput(mm); > } > -- > 2.27.0