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 CE456187FFE for ; Wed, 13 Nov 2024 09:46:30 +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=1731491193; cv=none; b=Qr44dvOar0AQfX1S9fSOET+6z1k4qMKaUlGtjpVhkCnZIFGvtf0Nd8H8PxsZBmI2byk46KKJgMrF9f0cqvwy/kBRTTg7Ep+hq/swCcG3AsKCnL3wMJbQ/QA0t03M0XEgSFLMZM8n6RPhIj8z+uGd9pJpALtKFbooyshZ0c0X8/s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731491193; c=relaxed/simple; bh=j8JB6dTuYQXwjiiuFTNkDGKPphj+rJ0FINK0dp8nh6c=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=Hxo8TEXMP9mwyD7KrA1Y+xGXOGx7hymZRymYLshs0r2tNeYtEPRGqUs9NiIcSZzb4ElV1URIZr/o2DAYvm992ZtyBQ+A+ff+vMpwpXUst6jqCl2PBgbLuU4YANPrlWhzwAg26p/s+WJtJlK62dquVjdaGHy5adv1b/5OmQbr7NM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=OUlkVScb; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="OUlkVScb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731491190; 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=oC3QsMMLjV0lEnPQ7x1H3Fq9IelCnx6YRR2jMeCABYI=; b=OUlkVScbHDrpounlSGKY9A7knC61d1fSD9Ct0gr2nAZbFA5dZZVMI2uh/6psJEZP0pZlRJ HRdMC0Sfq/iMakD8dlZfmie5fLLwGRiyp1Fs2CSzJ3xL7z4IADHYonr8HI47o+19hyY29b 2FLHRm5m5tofOmodLi+kwyGl4/wxEig= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-437-X91kuDqoOd2gUuZwdQEGlw-1; Wed, 13 Nov 2024 04:46:26 -0500 X-MC-Unique: X91kuDqoOd2gUuZwdQEGlw-1 X-Mimecast-MFC-AGG-ID: X91kuDqoOd2gUuZwdQEGlw Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-37d56061a4cso3592446f8f.2 for ; Wed, 13 Nov 2024 01:46:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731491185; x=1732095985; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=oC3QsMMLjV0lEnPQ7x1H3Fq9IelCnx6YRR2jMeCABYI=; b=GnXWFfBH0cGItRUYOluNF2P4vrKNBcgUDmVcEBP4B4PQadVe1e/3Xx2qIrgsB9PVX4 q5nQCNCPyOJNj+AFM6/JcSTnPp/iXxW0AXCp4LFXzZQe3gcPYojn/YqoLMssuh0Mc4qi pbA/zfl5WcMIpmdcfxnBrBYkXsOOREPae6dKgLseeNgUbaXX+1iOkiqix20HnJbSP8zY pEsJsreULYw++zUzjvriD3aW/BcJeOHAoPH6NjQBOHfsTP2UorZxKO2QBCzG0uS5p7ZE SqzXKVtXPvbMo+b9t/xEhhwadC39Bt8Zu6UTvHZbKFwPB5mxLMb/KsRrua5nmhPOBY4z Jc1w== X-Forwarded-Encrypted: i=1; AJvYcCWLUvW3jMxt0h/n7U5AsNeRBtNNcFt6tp2WXNsxs/tjWpoF6oGmuaAfTKr+O+kELJUBxwy8YJc=@vger.kernel.org X-Gm-Message-State: AOJu0YzyOOnSeFLcQoweaSASzF2FXhTni+MxdcxR9w9l2X/DcF2oBpie TXBeJslLJXlkFPJ8ISDmbhkdaMSLrMhE0xvt/1XRORnCYAFgSUAoLhTaFGhVCH+dfuuAU82SI+r s25FsmrsIYqeQJK/evwbrNkYI4pWrAeMGFsEdZZjlB6L4p/+S3el5Rg== X-Received: by 2002:a05:6000:1fa8:b0:37c:ddab:a626 with SMTP id ffacd0b85a97d-382080f6b00mr4643907f8f.7.1731491185483; Wed, 13 Nov 2024 01:46:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHNVeneRcdPTumQPGNmARtthwkMVVbNFk0l/YGl497DOIOL387fClj5sENzorvrpIx4AEq77w== X-Received: by 2002:a05:6000:1fa8:b0:37c:ddab:a626 with SMTP id ffacd0b85a97d-382080f6b00mr4643886f8f.7.1731491185024; Wed, 13 Nov 2024 01:46:25 -0800 (PST) Received: from ?IPV6:2003:cb:c708:1500:d584:7ad8:d3f7:5539? (p200300cbc7081500d5847ad8d3f75539.dip0.t-ipconnect.de. [2003:cb:c708:1500:d584:7ad8:d3f7:5539]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381ed99681csm18254342f8f.49.2024.11.13.01.46.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 Nov 2024 01:46:23 -0800 (PST) Message-ID: Date: Wed, 13 Nov 2024 10:46:22 +0100 Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] mm/readahead: Fix large folio support in async readahead From: David Hildenbrand To: Yafang Shao Cc: willy@infradead.org, akpm@linux-foundation.org, linux-mm@kvack.org, stable@vger.kernel.org References: <20241108141710.9721-1-laoar.shao@gmail.com> <85cfc467-320f-4388-b027-2cbad85dfbed@redhat.com> <88211032-80e1-4067-a74c-c9dcea1abff8@redhat.com> 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 B3JfpUqcWwE7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QDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <88211032-80e1-4067-a74c-c9dcea1abff8@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 13.11.24 09:28, David Hildenbrand wrote: > On 13.11.24 03:16, Yafang Shao wrote: >> On Tue, Nov 12, 2024 at 11:19 PM David Hildenbrand wrote: >>> >>>>> Sorry, but this code is getting quite confusing, especially with such >>>>> misleading "large folio" comments. >>>>> >>>>> Even without MADV_HUGEPAGE we will be allocating large folios, as >>>>> emphasized by Willy [1]. So the only thing MADV_HUGEPAGE controls is >>>>> *which* large folios we allocate. .. as Willy says [2]: "We were only >>>>> intending to breach the 'max' for the MADV_HUGE case, not for all cases." >>>>> >>>>> I have no idea how *anybody* should derive from the code here that we >>>>> treat MADV_HUGEPAGE in a special way. >>>>> >>>>> Simply completely confusing. >>>>> >>>>> My interpretation of "I don't know if we should try to defend a stupid >>>>> sysadmin against the consequences of their misconfiguration like this" >>>>> means" would be "drop this patch and don't change anything". >>>> >>>> Without this change, large folios won’t function as expected. >>>> Currently, to support MADV_HUGEPAGE, you’d need to set readahead_kb to >>>> 2MB, 4MB, or more. However, many applications run without >>> > MADV_HUGEPAGE, and a larger readahead_kb might not be optimal for> them. >>> >>> Someone configured: "Don't readahead more than 128KiB" >>> >>> And then we complain why we "don't readahead more than 128KiB". >> >> That is just bikeshielding. > > It's called "reading the documentation and trying to make sense of a > patch". ;) > >> >> So, what’s your suggestion? Simply setting readahead_kb to 2MB? That >> would almost certainly cause issues elsewhere. > > I'm not 100% sure. I'm trying to make sense of it all. > > And I assume there is a relevant difference now between "readahead 2M > using all 4k pages" and "readahead 2M using a single large folio". > > I agree that likely readahead using many 4k pages is a worse idea than > just using a single large folio ... if we manage to allocate one. And > it's all not that clear in the code ... > > FWIW, I looked at "read_ahead_kb" values on my Fedora40 notebook and > they are all set to 128KiB. I'm not so sure if they really should be > that small ... or if large folio readahead code should just be able to > exceed it. > >>> "mm/filemap: Support VM_HUGEPAGE for file mappings" talks about "even if >>> we have no history of readahead being successful". >>> >>> So not about exceeding the configured limit, but exceeding the >>> "readahead history". >>> >>> So I consider VM_HUGEPAGE the sign here to "ignore readahead history" >>> and not to "violate the config". >> >> MADV_HUGEPAGE is definitely a new addition to readahead, and its >> behavior isn’t yet defined in the documentation. All we need to do is >> clarify its behavior there. The documentation isn’t set in stone—we >> can update it as long as it doesn’t disrupt existing applications. > > If Willy thinks this is the way to go, then we should document that > MADV_HUGEPAGE may ignore the parameter, agreed. > > I still don't understand your one comment: > > "It's worth noting that if read_ahead_kb is set to a larger value that > isn't aligned with huge page sizes (e.g., 4MB + 128KB), it may still > fail to map to hugepages." I just played with your patch and your reproducer. Setting read_ahead_kb to 0/128/4096 will give us PMDs with MADV_HUGEPAGE. So we're ignoring the parameter. But with 4224 we are not ignoring the parameter with MADV_HUGEPAGE. :( root@localhost:~# cat /proc/`pgrep readhahead`/smaps_rollup 00400000-7ffe3a206000 ---p 00000000 00:00 0 [rollup] Rss: 1049728 kB Pss: 1048700 kB Pss_Dirty: 968576 kB Pss_Anon: 84 kB Pss_File: 1048616 kB Pss_Shmem: 0 kB Shared_Clean: 1056 kB Shared_Dirty: 0 kB Private_Clean: 80096 kB Private_Dirty: 968576 kB Referenced: 1049728 kB Anonymous: 84 kB KSM: 0 kB LazyFree: 0 kB AnonHugePages: 0 kB ShmemPmdMapped: 0 kB FilePmdMapped: 135168 kB Shared_Hugetlb: 0 kB Private_Hugetlb: 0 kB Swap: 0 kB SwapPss: 0 kB Locked: 0 kB -- Cheers, David / dhildenb