Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp528439lqb; Wed, 17 Apr 2024 03:53:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVC947OWbJck65Tx3qC/H0TDK1u2voHAbVFpYx3vAqIpcje4X3Qn5k8JIfYC31azorzaY5DEMa+XpJCQLQSAvv7J1FisRHLCW7TQ+Tf6A== X-Google-Smtp-Source: AGHT+IEhFMvPIeuIz3EKd9DSIYjrsVrs5xbbl7Lv57Htj9/RoeQijA9Epp3K/yygd0Qe9YSmo1qW X-Received: by 2002:a05:6512:29c:b0:515:d196:6d4d with SMTP id j28-20020a056512029c00b00515d1966d4dmr12382686lfp.24.1713351202897; Wed, 17 Apr 2024 03:53:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713351202; cv=pass; d=google.com; s=arc-20160816; b=FNftDkQ6owgrO3rgNNPayMUCL/9QWZ50MZKpRkYox/9CJT5/IxOW4tDQ6QANOLomj+ 1HaaKq5XP6AKws+azyqIyqTZJY1885VlK4PEQ6FWG9Te7H1DqXUeURMdizLeROD9pECT s/X+7Qls5V81Yx//dtE/uQxBxwgGdp9UT/coAG86JcStiPF3msdmd3nHNtHp6cgGXXX/ eJH1oL97ErNUjERy0v9yqW7RacwNae8YmHsCKPnrzUzHJwu54js2FA8A0ujfuzBxANr3 OuVd7CUJjmDLzGms76XWJwMppUTJQPHs/9hZooXbLDnK07NG+/80BkL+1JBuqR/RZNXN 8ygQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=O171MMBToLq4rk4iXXmJ17mGxrA6Imu6S0PZmUprpsI=; fh=ZO2b3XapRv/LMhkMOL6CxMnkNuYgSTWdcEvXwzsvjCg=; b=viFm2ZJ568ADRPRF/KN01sw2pRKOjqFrm9DtwfsQbViEHYXKj/Rfd0RsTZXixOEE8j dm95Gtizn8VwiuHxQIg273smqfmbuXtyHyP2TqTlrpF4yWULL3CdMidqWo8j2K3SmKSj Gbfy1jXyyGH1wNy8C4furVGa7KlUzhMNNMPSovyTNO2bgQVa/rUksNrLgEhlU6fT3KTC sz94I+6M+0fk9d0cQ1wnb+2nER7iJOdaQcJoyQAaDFGsMhN14SxDEGje+aA0a+AQM2oJ dLPhxc/gqDDID8km3Mxl2exXxn3cOkLRXbL+JNvIeaz/y222h52W9Dw7I3SWurnP9oNU jFKA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-148353-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148353-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id f23-20020a170906049700b00a51e5aa5b2esi6606421eja.575.2024.04.17.03.53.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 03:53:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-148353-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-148353-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148353-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 78F3A1F21AE3 for ; Wed, 17 Apr 2024 10:53:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B88013C698; Wed, 17 Apr 2024 10:53:16 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DD1CD7FBD2 for ; Wed, 17 Apr 2024 10:53:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713351195; cv=none; b=K6MYS10a3Ohf7WlzOpi1RpBPHoFTyfJsWQ0FfA/yeUW0d+h/r8rsxvZyhJuUam4X2No+dh3krzgL7IAyimkCQ0QjvrlS3Wf07La1o/Fz+NTE/WZOHbx/9zKuDe40q+ZPdXTUtxIvJLKLD0UvzJ2ATk3hpM0fQVLhNBFi8I9cQhE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713351195; c=relaxed/simple; bh=DvyqV4VNBcgPHLGo6VzuhHCFubdOg2mGm7XN7iu9Z1s=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=D7BnKSxDnZ7DhEVLFRt1FC1pJ97RAX3A+XPcfTRHaBFo23Qgi3eOnpI9JqCfcKGu5v595E0duwsMPwq6pjdCWuc+FGHtTOYaFazGMuvh+rJ3WSCAMzWfffGFrhExjjxKJqAuV6DEbbmVVrXnOgHPMJKSOL082hdJ5/HxCD6C8to= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 EDE41339; Wed, 17 Apr 2024 03:53:40 -0700 (PDT) Received: from [10.1.37.181] (XHFQ2J9959.cambridge.arm.com [10.1.37.181]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F02873F64C; Wed, 17 Apr 2024 03:53:10 -0700 (PDT) Message-ID: <39905c50-a228-4e85-a5de-3b10cae5f2bc@arm.com> Date: Wed, 17 Apr 2024 11:53:09 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v7 1/3] mm/madvise: introduce clear_young_dirty_ptes() batch helper Content-Language: en-GB To: Lance Yang , David Hildenbrand Cc: 21cnbao@gmail.com, akpm@linux-foundation.org, fengwei.yin@intel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhocko@suse.com, minchan@kernel.org, peterx@redhat.com, shy828301@gmail.com, songmuchun@bytedance.com, wangkefeng.wang@huawei.com, xiehuan09@gmail.com, zokeefe@google.com References: <20240417050426.66194-1-ioworker0@gmail.com> <76d22c08-82db-4ea8-a7cd-c77589e132e3@redhat.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 17/04/2024 10:01, Lance Yang wrote: > On Wed, Apr 17, 2024 at 4:19 PM David Hildenbrand wrote: >> >> On 17.04.24 07:04, Lance Yang wrote: >>> Hey David, Ryan, >>> >>> How about this change? >>> >>> static inline void clear_young_dirty_ptes(struct vm_area_struct *vma, >>> unsigned long addr, pte_t *ptep, >>> unsigned int nr, cydp_t flags) >>> { >>> if (flags == CYDP_CLEAR_YOUNG) { >>> for (;;) { >>> ptep_test_and_clear_young(vma, addr, ptep); >>> if (--nr == 0) >>> break; >>> ptep++; >>> addr += PAGE_SIZE; >>> } >>> return; >>> } >>> >>> pte_t pte; >>> >>> for (;;) { >>> pte = ptep_get_and_clear(vma->vm_mm, addr, ptep); >>> >>> if (flags & CYDP_CLEAR_YOUNG) >>> pte = pte_mkold(pte); >>> if (flags & CYDP_CLEAR_DIRTY) >>> pte = pte_mkclean(pte); >>> >>> if (--nr == 0) >>> break; >>> ptep++; >>> addr += PAGE_SIZE; >>> } >>> } >> >> Likely it might be best to just KIS for now and leave it as is. The >> compiler should optimize out based on flags already, that's what I ignored. > > Got it. Let's keep it as is for now :) Yep agreed; you're passing the flags as constants so the compiler should be completely removing one half of the conditional. And if the input isn't a constant, I'd still expect the compiler to hoist the conditional out of the loop. > > Thanks, > Lance > >> >> -- >> Cheers, >> >> David / dhildenb >>