Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp689300lqb; Fri, 15 Mar 2024 03:55:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVIIK+Kuj775AwWYqEYsFat41dmxUHVKe0tAuAjQLkE59WBy81gwUVO+vCFDTOHaS6RBGqc0TJ3tumHWVgUiNyM/DMauux7FrY0QbBrIA== X-Google-Smtp-Source: AGHT+IHeUFskU6BKaJYtqEH9Mx4Ds3oE9kxlGWHEzUQ0zqydZdKHqI7HyvR3GAIrxDKFwZBHtLDm X-Received: by 2002:a05:622a:1214:b0:42e:b2c3:d77a with SMTP id y20-20020a05622a121400b0042eb2c3d77amr3838161qtx.46.1710500137127; Fri, 15 Mar 2024 03:55:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710500137; cv=pass; d=google.com; s=arc-20160816; b=opdOEWcaaFec3mzw6xSpGsNbHCvcSdxSdJEbP0pfXmcH/FNjw1DvUKEBRzkGUBQn2e 6PnTsOE9LMnlmLwNFe+v83G5vfxMHQ76e3ZoqjdelPDG268byBL+vKqUfmlMqqtqrtXA D2F/GcAzopk5yx/cPmHZKJe5JzbeOsxXwZCHGNy9qqpZYSONfztj9/Uvv7x0K/Q9ki3N t4eIJS03oz+/z4qWnfLPqUOpX/K4GhNzSYBHlK55NcFnT+orDWVYvdvdWQsEgO8KjIFq 0oWoDKhouQJ+kEMCE6GB+8X4Q1OBpkC/THrt7rXmeknkSqs3pb4BeLTOVQyF8vi5vcHm HbGQ== 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=dVISdFxlCnLtDT3M38ABbrRIg78dyfX+9/DO6lkUNLA=; fh=EatWRA+kWOkGGma4xICrb5bPxHeCxy/gAUSouUxAN9A=; b=B+V5XdMhzWwG3ZUeka5NklFWldfmA5kuln2Nzl/K4TC2ox/o7pngD2r5RBVrGoe2Hu xzkEIriZ6BzHnDps4czC3FxXdjpUAscGkFrr7BZPizWoTYPqHX/rVqHnU/buGu09y+Vw Uoq3Et2+hT8qbhsyJpuO8+4EripAOH6Q7DYoVCfywVd8icA1dXiefRpHcnUnX8c2I2QT 0PuGu+eEc7VHshIExH3v64tG+wwoRDs71ggw7PfkwHlTqKU2MbGrmGVnbasiYn9EjeKl EZilOC+WrcMvUI34DX8/qEsSkG7S6v0ElLqyS5rPzQ6GSYwm//gSfQQXiUv9blsdLSF+ /RnQ==; 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-104291-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104291-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id v11-20020a05622a188b00b0042f213929b5si3462302qtc.420.2024.03.15.03.55.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 03:55:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-104291-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; 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-104291-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104291-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B8D511C22015 for ; Fri, 15 Mar 2024 10:55:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6DC1B1B969; Fri, 15 Mar 2024 10:55:22 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 671821B960 for ; Fri, 15 Mar 2024 10:55:19 +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=1710500122; cv=none; b=q8b2ASTTGETLnEhyMFhI0/78Kn+dW33NekF+GYaZNIfQmanrWzGq02f3/Zr7pBzK/oSaxBlZE7cwhJhgrBwrwF0CDSSxun6bViF3zSBX4jd6UaX7Py6fSqR6LuxuK6Xm2fPc1FoeiipK/3tI6/L6MChAN433O++g+qlQXwHXh/0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710500122; c=relaxed/simple; bh=7l16go4HlTlmkmb7nNzK3ps56IPRMeTS+78pgRjsfgY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=f/ckq5kpgE/ljjB/zSy1HbD/93X/TdQsBm+g2wQfYKMMFRiRfq4gCZF8F9qd6lJ40ZuKRjNmDOo00j0upLwuXZnLURPF/hv6EGQfMIsZMemyUoN7tXpAh6uWmZEjZfSVEp0Ab9gV677JAFQFM4yk/yXPAG27FphAgju0BeKZbWY= 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 CB7A8C15; Fri, 15 Mar 2024 03:55:53 -0700 (PDT) Received: from [10.57.69.160] (unknown [10.57.69.160]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 026733F762; Fri, 15 Mar 2024 03:55:15 -0700 (PDT) Message-ID: Date: Fri, 15 Mar 2024 10:55:14 +0000 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 v4 6/6] mm: madvise: Avoid split during MADV_PAGEOUT and MADV_COLD Content-Language: en-GB To: David Hildenbrand , Andrew Morton , Matthew Wilcox , Huang Ying , Gao Xiang , Yu Zhao , Yang Shi , Michal Hocko , Kefeng Wang , Barry Song <21cnbao@gmail.com>, Chris Li Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20240311150058.1122862-1-ryan.roberts@arm.com> <20240311150058.1122862-7-ryan.roberts@arm.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 15/03/2024 10:35, David Hildenbrand wrote: >> -        if (!pageout && pte_young(ptent)) { >> -            ptent = ptep_get_and_clear_full(mm, addr, pte, >> -                            tlb->fullmm); >> -            ptent = pte_mkold(ptent); >> -            set_pte_at(mm, addr, pte, ptent); >> -            tlb_remove_tlb_entry(tlb, pte, addr); >> +        if (!pageout) { >> +            for (; nr != 0; nr--, pte++, addr += PAGE_SIZE) { >> +                if (ptep_test_and_clear_young(vma, addr, pte)) >> +                    tlb_remove_tlb_entry(tlb, pte, addr); >> +            } >>           } > > > The following might turn out a bit nicer: Make folio_pte_batch() collect > "any_young", then doing something like we do with "any_writable" in the fork() > case: > > ... >     nr = folio_pte_batch(folio, addr, pte, ptent, max_nr, >                  fpb_flags, NULL, any_young); >     if (any_young) >         pte_mkyoung(ptent) > ... > > if (!pageout && pte_young(ptent)) { >     mkold_full_ptes(mm, addr, pte, nr, tlb->fullmm); >     tlb_remove_tlb_entries(tlb, pte, nr, addr); > } > I thought about that but decided that it would be better to only TLBI the actual entries that were young. Although looking at tlb_remove_tlb_entry() I see that it just maintains a range between the lowest and highest address, so this won't actually make any difference. So, yes, this will be a nice improvement, and also prevent the O(n^2) pte reads for the contpte case. I'll change in the next version.