Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1584093rdb; Wed, 31 Jan 2024 03:14:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IFPm+uYvtG9g25+Be1Hu1r2cqZPeS+GV2M+oCSbdLo6A9ScIo4J2ilFcz9Q77fY/AiwzN5j X-Received: by 2002:a17:903:2a8d:b0:1d6:f185:f13b with SMTP id lv13-20020a1709032a8d00b001d6f185f13bmr1669923plb.17.1706699661370; Wed, 31 Jan 2024 03:14:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706699661; cv=pass; d=google.com; s=arc-20160816; b=oBks7vk/uLrjnEVFk/kqPCY7gcVO0zzzuhxD3ga1KuE3CxjpfMJ1A+Y7KN/UIC7IOu kYtR0KcPC8t6Qr9Mi7QmDTSwnCM/3IqqePd0YVvJnSjfOrGbu7o2CJHclflKx1+LUAr1 WRZJQr+JgGJp8TgNapo3Cm6n5DAYzKpJXX4cv10qeAEzcU8TLBbl9kA3XOvoSWcTn4Gz iUAT1KhSvyW4HJrl2HI/HfgHApg/gbIkaqnys9HUMaFr5olEmtzDOvT3rT6a2Cf0AN60 zFTHoY5zAqSOj1wUgrYXWs6EjunmnpaqYxRxs1a+iAx4e/S/gFG3rzjqs5xVTbUHYym8 lTAQ== 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=PcxmOncJZQGI2zs4eR/9n/qUB3nTm/aoYfWMqmVbjAs=; fh=+i2/9MBxeN1joZtF3UZ6z6UcKz7h4zXz6cUtKj9EDi4=; b=HcJ4BNzpOBQLE5mM+0xjoY/zjaOBQ6xHy9UxZq7K4soqhTz2TjEh2rXcG0BRvNZsy6 SkxrX94ZAw7GIvT/g0D/Bzs2m3xTLkuQNOWwhYTi+9ebGVEObppSAwro0IYzXSs9v4SA H27H3w+KM6iTuoKP1Zrm7BXAK7vtMX9UF852jSBUsNocBt/kRcha9k2HqJKhSNfnwfZX AgsGQNajFSj8J/OGtA+a6n1ZvENQ03LMR3i9Wth5xi0zE32Sw3EfygIPRNTOsXkYzaF+ wpfisBy5x3Fe7zJr+7eY5/jH0+JzI31vZhKWb5i7uSSu5zsKK6SDVlFbWl6yTUUZSz+5 Ct+g==; 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-46238-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46238-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=1; AJvYcCWrFK2sbYn+qQjr0lCfSk5DVMWGKo4QmqfC19fz3z4136OIdxVByAWNIP/GRFsgkH66IHbfo0jEb2kuA7imTsUCGBt7PTpOzrfqTqs62w== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id o17-20020a170902e29100b001d4af7a3cd3si4210281plc.83.2024.01.31.03.14.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 03:14:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46238-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; 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-46238-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46238-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id A9C15B2913D for ; Wed, 31 Jan 2024 10:32:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9020069D07; Wed, 31 Jan 2024 10:32:03 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E7E44C61; Wed, 31 Jan 2024 10:31:59 +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=1706697123; cv=none; b=SB5PFaA39wKusTHIbvjtimTkBfhbu73KKloxifu+5L2OhYCwAGLTz7g8OSLuhXRVxgywS1n7zRr+d3qGjsylJQ+hC5IPrkagJrO36C6J9rlMUt0IDRebg78dQDfTzLKAoGDtmvBISY3jeQJMcnQqlK7Cl6E3LDpTVf8NNILMrgg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706697123; c=relaxed/simple; bh=p+76q6wFys2x4uxnvAIjBWutVg1nOrqx8fPv9A+DXxk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=fjLDaIaKpnAntE3xabPYS0iiGV+y4rlNi+7axTw/ikdsxV+wVNdrWx2TeEBWGLXeDRfWUE7KrRe6KpcyohMaoi0+jZuQFKk5tPKao/ofz/OFxyVpVyvE/3tAoADWDWDWZJhT5LM1lTGgaH/xfIlLRwW8WtsnnmOtFo+I8yEJhNM= 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 A3E8FDA7; Wed, 31 Jan 2024 02:32:42 -0800 (PST) Received: from [10.57.79.60] (unknown [10.57.79.60]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A65A23F5A1; Wed, 31 Jan 2024 02:31:53 -0800 (PST) Message-ID: <424115a2-a924-4c28-8027-32db6ab9278d@arm.com> Date: Wed, 31 Jan 2024 10:31:51 +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 v1 9/9] mm/memory: optimize unmap/zap with PTE-mapped THP Content-Language: en-GB To: David Hildenbrand , linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Andrew Morton , Matthew Wilcox , Catalin Marinas , Will Deacon , "Aneesh Kumar K.V" , Nick Piggin , Peter Zijlstra , Michael Ellerman , Christophe Leroy , "Naveen N. Rao" , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Arnd Bergmann , linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org References: <20240129143221.263763-1-david@redhat.com> <20240129143221.263763-10-david@redhat.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 31/01/2024 10:21, David Hildenbrand wrote: > >>> + >>> +#ifndef clear_full_ptes >>> +/** >>> + * clear_full_ptes - Clear PTEs that map consecutive pages of the same folio. >> >> I know its implied from "pages of the same folio" (and even more so for the >> above variant due to mention of access/dirty), but I wonder if its useful to >> explicitly state that "all ptes being cleared are present at the time of the >> call"? > > "Clear PTEs" -> "Clear present PTEs" ? > > That should make it clearer. Works for me. > > [...] > >>>       if (!delay_rmap) { >>> -        folio_remove_rmap_pte(folio, page, vma); >>> +        folio_remove_rmap_ptes(folio, page, nr, vma); >>> + >>> +        /* Only sanity-check the first page in a batch. */ >>>           if (unlikely(page_mapcount(page) < 0)) >>>               print_bad_pte(vma, addr, ptent, page); >> >> Is there a case for either removing this all together or moving it into >> folio_remove_rmap_ptes()? It seems odd to only check some pages. >> > > I really wanted to avoid another nasty loop here. > > In my thinking, for 4k folios, or when zapping subpages of large folios, we > still perform the exact same checks. Only when batching we don't. So if there is > some problem, there are ways to get it triggered. And these problems are barely > ever seen. > > folio_remove_rmap_ptes() feels like the better place -- especially because the > delayed-rmap handling is effectively unchecked. But in there, we cannot > "print_bad_pte()". > > [background: if we had a total mapcount -- iow cheap folio_mapcount(), I'd check > here that the total mapcount does not underflow, instead of checking per-subpage] All good points... perhaps extend the comment to describe how this could be solved in future with cheap total_mapcount()? Or in the commit log if you prefer? > >> >>>       } >>> -    if (unlikely(__tlb_remove_page(tlb, page, delay_rmap))) { >>> +    if (unlikely(__tlb_remove_folio_pages(tlb, page, nr, delay_rmap))) { >>>           *force_flush = true; >>>           *force_break = true; >>>       } >>>   } >>>   -static inline void zap_present_pte(struct mmu_gather *tlb, >>> +/* >>> + * Zap or skip one present PTE, trying to batch-process subsequent PTEs that >>> map >> >> Zap or skip *at least* one... ? > > Ack >