From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1208B22F764 for ; Mon, 16 Jun 2025 09:12:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750065141; cv=none; b=KfVpGQdwSv4JiV1zaB+HUdYi7zYKnV30wzsJUdLnGQF+UnIlX1KfYbnMV53Esf1iAruK9G+SvNmE8j2trh/iLljuX9vyDdj6U/5iidU9jAbRkdFMF9/GVCgh9DQx9qJMIyCraPbWw2Go7Q65Zl77TsPcbpADmEOrIipMQnQFQX8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750065141; c=relaxed/simple; bh=CxFtkUaoICplqKg6mBF/vpC5ZoSwtzbG+6E2tKXhfc8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=APNdh9/qPqMkfKXygaoU9N9+78u7t95yH2X3EqeZbSBRUbDupAqUvA8/ml0yBFj+YJfJ3A774GYJsI4DBCT2cnNIXvU9qmFygK6GciE1RjIH7+FDQt37XK6FMFqQF49rx/GqwN5wOMOktxDwRp/92wsbhMy5s5BVgRMgdcte84Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=hw6vcjDD; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hw6vcjDD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1750065137; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=GQSoqKrp/ddRa/kh3o1Hv7MhPgf13bzJssOJZXJAf18=; b=hw6vcjDDpkSxW06aUE0ZfQo3Fyl7fF/26/NG0WrrHdhvbpo1kvVIwJ5WJW6lr+HkmKOJZz Rr+rT8l5p7aqgkq9VnbvBLPproNHSe3sC/CBe7LLPZoPwoWEGOfzvQmtv1Q8Dl53YFk5YC kuqZ6qF9IhE6mBK+Alr2WYPbK/oF5tU= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-187-XDhG69TCOc-ngVgz8pPb4g-1; Mon, 16 Jun 2025 05:12:14 -0400 X-MC-Unique: XDhG69TCOc-ngVgz8pPb4g-1 X-Mimecast-MFC-AGG-ID: XDhG69TCOc-ngVgz8pPb4g_1750065133 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3a4f3796779so2877160f8f.1 for ; Mon, 16 Jun 2025 02:12:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750065133; x=1750669933; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=GQSoqKrp/ddRa/kh3o1Hv7MhPgf13bzJssOJZXJAf18=; b=AMj/MoeLbdmkzBDscxGAS9MLulKDsEECiRDf0qZkZZ00ODr3MSCVjI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:3a4:d83a:eb4c with SMTP id ffacd0b85a97d-3a572e9a4bamr6400205f8f.57.1750065132645; Mon, 16 Jun 2025 02:12:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHHJYnIt9dUbHvTScNyZFoVWDPNSRLqKY7Pq9JphyPgZ3sOj2Aaa3+c8Ekp/l0yglOVh/h4qQ== X-Received: by 2002:a05:6000:2286:b0:3a4:d83a:eb4c with SMTP id ffacd0b85a97d-3a572e9a4bamr6400152f8f.57.1750065132106; Mon, 16 Jun 2025 02:12:12 -0700 (PDT) Received: from ?IPV6:2003:d8:2f25:bd00:949:b5a9:e02a:f265? (p200300d82f25bd000949b5a9e02af265.dip0.t-ipconnect.de. [2003:d8:2f25:bd00:949:b5a9:e02a:f265]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4532dea1925sm141877845e9.12.2025.06.16.02.12.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Jun 2025 02:12:11 -0700 (PDT) Message-ID: Date: Mon, 16 Jun 2025 11:12:09 +0200 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 0/5] add STATIC_PMD_ZERO_PAGE config option To: "Pankaj Raghav (Samsung)" , Dave Hansen Cc: Pankaj Raghav , Suren Baghdasaryan , Ryan Roberts , Mike Rapoport , Michal Hocko , Thomas Gleixner , Nico Pache , Dev Jain , Baolin Wang , Borislav Petkov , Ingo Molnar , "H . Peter Anvin" , Vlastimil Babka , Zi Yan , Dave Hansen , Lorenzo Stoakes , Andrew Morton , "Liam R . Howlett" , Jens Axboe , linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org, x86@kernel.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Darrick J . Wong" , mcgrof@kernel.org, gost.dev@samsung.com, hch@lst.de References: <20250612105100.59144-1-p.raghav@samsung.com> <30a3048f-efbe-4999-a051-d48056bafe0b@intel.com> <76a48d80-7eb0-4196-972d-ecdcbd4ae709@intel.com> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABzSREYXZpZCBIaWxk ZW5icmFuZCA8ZGF2aWRAcmVkaGF0LmNvbT7CwZgEEwEIAEICGwMGCwkIBwMCBhUIAgkKCwQW AgMBAh4BAheAAhkBFiEEG9nKrXNcTDpGDfzKTd4Q9wD/g1oFAl8Ox4kFCRKpKXgACgkQTd4Q 9wD/g1oHcA//a6Tj7SBNjFNM1iNhWUo1lxAja0lpSodSnB2g4FCZ4R61SBR4l/psBL73xktp rDHrx4aSpwkRP6Epu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format=flowed Content-Transfer-Encoding: 7bit On 13.06.25 10:58, Pankaj Raghav (Samsung) wrote: > On Thu, Jun 12, 2025 at 02:46:34PM -0700, Dave Hansen wrote: >> On 6/12/25 13:36, Pankaj Raghav (Samsung) wrote: >>> On Thu, Jun 12, 2025 at 06:50:07AM -0700, Dave Hansen wrote: >>>> On 6/12/25 03:50, Pankaj Raghav wrote: >>>>> But to use huge_zero_folio, we need to pass a mm struct and the >>>>> put_folio needs to be called in the destructor. This makes sense for >>>>> systems that have memory constraints but for bigger servers, it does not >>>>> matter if the PMD size is reasonable (like in x86). >>>> >>>> So, what's the problem with calling a destructor? >>>> >>>> In your last patch, surely bio_add_folio() can put the page/folio when >>>> it's done. Is the real problem that you don't want to call zero page >>>> specific code at bio teardown? >>> >>> Yeah, it feels like a lot of code on the caller just to use a zero page. >>> It would be nice just to have a call similar to ZERO_PAGE() in these >>> subsystems where we can have guarantee of getting huge zero page. >>> >>> Apart from that, these are the following problems if we use >>> mm_get_huge_zero_folio() at the moment: >>> >>> - We might end up allocating 512MB PMD on ARM systems with 64k base page >>> size, which is undesirable. With the patch series posted, we will only >>> enable the static huge page for sane architectures and page sizes. >> >> Does *anybody* want the 512MB huge zero page? Maybe it should be an >> opt-in at runtime or something. >> > Yeah, I think that needs to be fixed. David also pointed this out in one > of his earlier reviews[1]. > >>> - In the current implementation we always call mm_put_huge_zero_folio() >>> in __mmput()[1]. I am not sure if model will work for all subsystems. For >>> example bio completions can be async, i.e, we might need a reference >>> to the zero page even if the process is no longer alive. >> >> The mm is a nice convenient place to stick an mm but there are other >> ways to keep an efficient refcount around. For instance, you could just >> bump a per-cpu refcount and then have the shrinker sum up all the >> refcounts to see if there are any outstanding on the system as a whole. >> >> I understand that the current refcounts are tied to an mm, but you could >> either replace the mm-specific ones or add something in parallel for >> when there's no mm. > > But the whole idea of allocating a static PMD page for sane > architectures like x86 started with the intent of avoiding the refcounts and > shrinker. > > This was the initial feedback I got[2]: > > I mean, the whole thing about dynamically allocating/freeing it was for > memory-constrained systems. For large systems, we just don't care. For non-mm usage we can just use the folio refcount. The per-mm refcounts are all combined into a single folio refcount. The way the global variable is managed based on per-mm refcounts is the weird thing. In some corner cases we might end up having multiple instances of huge zero folios right now. Just imagine: 1) Allocate huge zero folio during read fault 2) vmsplice() it 3) Unmap the huge zero folio 4) Shrinker runs and frees it 5) Repeat with 1) As long as the folio is vmspliced(), it will not get actually freed ... I would hope that we could remove the shrinker completely, and simply never free the huge zero folio once allocated. Or at least, only free it once it is actually no longer used. -- Cheers, David / dhildenb