From patchwork Fri Jun 2 09:29:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 102423 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp906706vqr; Fri, 2 Jun 2023 02:49:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ72XC60prwAbi3rQ6CbNOoRIqauOobEOV7I5KdQt9v2vk/RZb0wMAV5HFDR5yTMbun41k2d X-Received: by 2002:a05:6358:4315:b0:123:3ea3:2bd2 with SMTP id r21-20020a056358431500b001233ea32bd2mr8790474rwc.32.1685699358762; Fri, 02 Jun 2023 02:49:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685699358; cv=none; d=google.com; s=arc-20160816; b=0v5aM7wru53coh49r1cDTEzCKd4TLVx+WZrz1aLD+KolY0yFvyvwppNwArVYMk5mdi cPUXpk8ksI5oT7wSnY/L8PSBgho+O9Gcy/uI4K4OYOCK0uMbvK3sz+40732ZrihFqYqR MWMNhCQn3K5JOx00MLDjbgzB8tK8PfyQm0sSwMqUlKJ3KzJ8ULVGGXYAo/brBql3WMKF MrPcQbyAOvHDibbgwOnKKq19+OAeR4pu5EiM/wekWzHkAoMbR8TkayVBcwTB0ZkKHYvC AI0TAgXV6m349jYYIfnUgrxWjE0JV7WYWBmTnIVPKY1UQHokYjfrMf7hVZtXNkthhSLP Ntog== 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; bh=VKRNb17rmx4CrscdLqv68+7Swb2k3gEeCrh0aTpL6lk=; b=twP7lxIa9CBqxmU3Ajf38WCyzaaeABiRyeE2ymBTm1OTkeabIY4UcdYJfbovTng1Ff GZLphBWEHV3xvCrnweFWCbiqT6R0UpVbrHL5twC9SFassjNQ2E1HG4EhLQHDCZYtXZKi Tn82CU9Tm4aZrcxVNqAl9f87V0guizYY0YHELZb9yTHsriUlxtZ6uz4V/ZitNmmXxqpu /LLW8tu5v7CTgVgi2UCcjMbLmhWspNzzcevE58yu14wWArHl/bePJ8mzlClpQW42zuPM c4OFe9vfF51yPCSkwwGNhXMHvlk+jNCQOkk/JCaDWy92cDLfovtsnJo6U2QU6JKJgNF3 Acmg== 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=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z11-20020a17090ab10b00b00256c8abe403si2466626pjq.167.2023.06.02.02.49.04; Fri, 02 Jun 2023 02:49:18 -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=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235109AbjFBJbX (ORCPT + 99 others); Fri, 2 Jun 2023 05:31:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234695AbjFBJal (ORCPT ); Fri, 2 Jun 2023 05:30:41 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CD8B910F3 for ; Fri, 2 Jun 2023 02:30:09 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0D42D176A; Fri, 2 Jun 2023 02:30:55 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D73083F7BD; Fri, 2 Jun 2023 02:30:07 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , SeongJae Park , Christoph Hellwig Cc: Ryan Roberts , "Matthew Wilcox (Oracle)" , "Kirill A. Shutemov" , Lorenzo Stoakes , Uladzislau Rezki , Zi Yan , Yu Zhao , Mike Rapoport , linux-kernel@vger.kernel.org, linux-mm@kvack.org, damon@lists.linux.dev Subject: [PATCH v3 3/4] mm/damon/ops-common: Refactor to use {pte|pmd}p_clear_young_notify() Date: Fri, 2 Jun 2023 10:29:48 +0100 Message-Id: <20230602092949.545577-4-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230602092949.545577-1-ryan.roberts@arm.com> References: <20230602092949.545577-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767583890677331626?= X-GMAIL-MSGID: =?utf-8?q?1767583890677331626?= With the fix in place to atomically test and clear young on ptes and pmds, simplify the code to handle the clearing for both the primary mmu and the mmu notifier with a single API call. Signed-off-by: Ryan Roberts Acked-by: Yu Zhao Reviewed-by: SeongJae Park --- mm/damon/ops-common.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c index acc264b97903..d4ab81229136 100644 --- a/mm/damon/ops-common.c +++ b/mm/damon/ops-common.c @@ -39,21 +39,12 @@ struct folio *damon_get_folio(unsigned long pfn) void damon_ptep_mkold(pte_t *pte, struct vm_area_struct *vma, unsigned long addr) { - bool referenced = false; struct folio *folio = damon_get_folio(pte_pfn(*pte)); if (!folio) return; - if (ptep_test_and_clear_young(vma, addr, pte)) - referenced = true; - -#ifdef CONFIG_MMU_NOTIFIER - if (mmu_notifier_clear_young(vma->vm_mm, addr, addr + PAGE_SIZE)) - referenced = true; -#endif /* CONFIG_MMU_NOTIFIER */ - - if (referenced) + if (ptep_clear_young_notify(vma, addr, pte)) folio_set_young(folio); folio_set_idle(folio); @@ -63,21 +54,12 @@ void damon_ptep_mkold(pte_t *pte, struct vm_area_struct *vma, unsigned long addr void damon_pmdp_mkold(pmd_t *pmd, struct vm_area_struct *vma, unsigned long addr) { #ifdef CONFIG_TRANSPARENT_HUGEPAGE - bool referenced = false; struct folio *folio = damon_get_folio(pmd_pfn(*pmd)); if (!folio) return; - if (pmdp_test_and_clear_young(vma, addr, pmd)) - referenced = true; - -#ifdef CONFIG_MMU_NOTIFIER - if (mmu_notifier_clear_young(vma->vm_mm, addr, addr + HPAGE_PMD_SIZE)) - referenced = true; -#endif /* CONFIG_MMU_NOTIFIER */ - - if (referenced) + if (pmdp_clear_young_notify(vma, addr, pmd)) folio_set_young(folio); folio_set_idle(folio);