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.133.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 B707FE57D for ; Tue, 19 Nov 2024 14:35:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732026940; cv=none; b=UeUCDGKT+mfXdBUO/a6Q8t7u0VvTFrDiMLDE4QjM43XQV/PisgMxQfUIjCWsrIkv6vSERRmSGzMQIdg4m2Lb/dd2vnGFqgK/LvMAbUKB2ov8IeQQI/ZokoCyBKKJTERQESFFZYBtBsk5DPaQlRnwJEbpYcK78dX/A2HBVBDqIeU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732026940; c=relaxed/simple; bh=inyP8EzpXjrTYOwbBZhVZakTi62ByPip/mFB2T5+hAk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=UBpLZNRVbNds2ZG1xPFVGGNmPJfcp5zsSuXkrvwg5C1IdmpGnQoufCCo001MvNLeimXej7QueLQMY/g9rRij5R+qy7w0emYxKAERWMr0Tr7Eqo4ilKG2J9/eJuERGS/+aVO5cK/NLf7TmRzZ9a8i3vfc0r3AK2GjXq+PlZMt558= 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=UxxdH3Hc; arc=none smtp.client-ip=170.10.133.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="UxxdH3Hc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732026936; 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=JKx890WpfnsU0/gagsqAu/7bg4tMVV8GUtdV3TL7xsM=; b=UxxdH3Hc3xxHGVkKbPSchB0vztmPosD97VhIDHDqHVXarC/0h9H49NOP/0OFHg3a8+u9ty Vyq7ZcylmRcPVgCtWq+3oyr0AA+RxELHUywJrzcjog6iFM3FGYTVJPXgKRA/P+90V5/iMS V+1Tz51CovcItTC3pvDfB7y1u7uMB7Y= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-488-BYsFHhMMOwW_UYwVVAnD4A-1; Tue, 19 Nov 2024 09:35:35 -0500 X-MC-Unique: BYsFHhMMOwW_UYwVVAnD4A-1 X-Mimecast-MFC-AGG-ID: BYsFHhMMOwW_UYwVVAnD4A Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4315f48bd70so28990875e9.2 for ; Tue, 19 Nov 2024 06:35:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732026934; x=1732631734; 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=JKx890WpfnsU0/gagsqAu/7bg4tMVV8GUtdV3TL7xsM=; b=vJplF7GCs2rvU88NG5wOt7ZnpwLMq+qgeK4pw77UIsDaVeM6og0CyaETfsRgj+kW68 la/f6Cf8qeTZUqlXUr6P8u3GRE2iKOhGqLv433m+y0ndur22SKU7zP0K6f8PfROCid2p jDIf09Sa0/lqsZLg52mCCgxWTaKO1pZE+rgSnHecHRBMf92yEtI9uT4FxSDXp5h3TIEo QyqJshqtCwfkUTZXKffhTPWZsodMquV/xD+W0Dhb041eg+lXO92YEJSmDXaRJ0Bh6hxn NB/NxIUktrjXrkCTIP/VRhC5MBOk18c5hoZ+4TUVmT5hARtIrPGY5P+D11+vwkZXMg+9 EHOw== X-Forwarded-Encrypted: i=1; AJvYcCWQUwlVCGqRt2HF0GacoHnFZeHeOLKCq8RgZWSt4BymaFd5Ya3vM9rbaWB68Q1Q3DL2f8LoHeiaoqKlkA8=@vger.kernel.org X-Gm-Message-State: AOJu0YyeCJD6tbCCNJ/iJWEk+9PHr3M+IBZPfDx3cMW+yWKixh8NdXlx MCdMXFCOk4rUwIvMsA5nYLpkeF6LswoDuJ4spcNxdRG0aI5nHnXFYVJH3nO2s5b/wC9nJpw1vBl lKKpHmk0yLTjcl8+X1VxiqE1B2tdB7hItEnEETTNtnpWTDMsZkNa4q9cT5mMJpA== X-Received: by 2002:a05:600c:5492:b0:431:5d89:646e with SMTP id 5b1f17b1804b1-432df792df0mr123888895e9.32.1732026934041; Tue, 19 Nov 2024 06:35:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGWNHgoarbx3hUcQezjymarz8pGO7PL0597K0482rDOTfSC0yJPFVaW9DwAPbLFRBl1lqybvA== X-Received: by 2002:a05:600c:5492:b0:431:5d89:646e with SMTP id 5b1f17b1804b1-432df792df0mr123888685e9.32.1732026933695; Tue, 19 Nov 2024 06:35:33 -0800 (PST) Received: from ?IPV6:2003:cb:c74b:d000:3a9:de5c:9ae6:ccb3? (p200300cbc74bd00003a9de5c9ae6ccb3.dip0.t-ipconnect.de. [2003:cb:c74b:d000:3a9:de5c:9ae6:ccb3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab80582sm195595185e9.19.2024.11.19.06.35.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Nov 2024 06:35:33 -0800 (PST) Message-ID: Date: Tue, 19 Nov 2024 15:35:31 +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 v2] mm: Respect mmap hint address when aligning for THP To: Kalesh Singh Cc: kernel-team@android.com, android-mm@google.com, Andrew Morton , Vlastimil Babka , Yang Shi , Rik van Riel , Ryan Roberts , Suren Baghdasaryan , Minchan Kim , Hans Boehm , Lokesh Gidra , stable@vger.kernel.org, "Liam R. Howlett" , Lorenzo Stoakes , Jann Horn , Yang Shi , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20241118214650.3667577-1-kaleshsingh@google.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/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoF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ntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <20241118214650.3667577-1-kaleshsingh@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 18.11.24 22:46, Kalesh Singh wrote: > Commit efa7df3e3bb5 ("mm: align larger anonymous mappings on THP > boundaries") updated __get_unmapped_area() to align the start address > for the VMA to a PMD boundary if CONFIG_TRANSPARENT_HUGEPAGE=y. > > It does this by effectively looking up a region that is of size, > request_size + PMD_SIZE, and aligning up the start to a PMD boundary. > > Commit 4ef9ad19e176 ("mm: huge_memory: don't force huge page alignment > on 32 bit") opted out of this for 32bit due to regressions in mmap base > randomization. > > Commit d4148aeab412 ("mm, mmap: limit THP alignment of anonymous > mappings to PMD-aligned sizes") restricted this to only mmap sizes that > are multiples of the PMD_SIZE due to reported regressions in some > performance benchmarks -- which seemed mostly due to the reduced spatial > locality of related mappings due to the forced PMD-alignment. > > Another unintended side effect has emerged: When a user specifies an mmap > hint address, the THP alignment logic modifies the behavior, potentially > ignoring the hint even if a sufficiently large gap exists at the requested > hint location. > > Example Scenario: > > Consider the following simplified virtual address (VA) space: > > ... > > 0x200000-0x400000 --- VMA A > 0x400000-0x600000 --- Hole > 0x600000-0x800000 --- VMA B > > ... > > A call to mmap() with hint=0x400000 and len=0x200000 behaves differently: > > - Before THP alignment: The requested region (size 0x200000) fits into > the gap at 0x400000, so the hint is respected. > > - After alignment: The logic searches for a region of size > 0x400000 (len + PMD_SIZE) starting at 0x400000. > This search fails due to the mapping at 0x600000 (VMA B), and the hint > is ignored, falling back to arch_get_unmapped_area[_topdown](). > > In general the hint is effectively ignored, if there is any > existing mapping in the below range: > > [mmap_hint + mmap_size, mmap_hint + mmap_size + PMD_SIZE) > > This changes the semantics of mmap hint; from ""Respect the hint if a > sufficiently large gap exists at the requested location" to "Respect the > hint only if an additional PMD-sized gap exists beyond the requested size". > > This has performance implications for allocators that allocate their heap > using mmap but try to keep it "as contiguous as possible" by using the > end of the exisiting heap as the address hint. With the new behavior > it's more likely to get a much less contiguous heap, adding extra > fragmentation and performance overhead. > > To restore the expected behavior; don't use thp_get_unmapped_area_vmflags() > when the user provided a hint address, for anonymous mappings. > > Note: As, Yang Shi, pointed out: the issue still remains for filesystems > which are using thp_get_unmapped_area() for their get_unmapped_area() op. > It is unclear what worklaods will regress for if we ignore THP alignment > when the hint address is provided for such file backed mappings -- so this > fix will be handled separately. > > Cc: Andrew Morton > Cc: Vlastimil Babka > Cc: Yang Shi > Cc: Rik van Riel > Cc: Ryan Roberts > Cc: Suren Baghdasaryan > Cc: Minchan Kim > Cc: Hans Boehm > Cc: Lokesh Gidra > Cc: > Fixes: efa7df3e3bb5 ("mm: align larger anonymous mappings on THP boundaries") > Signed-off-by: Kalesh Singh > Reviewed-by: Rik van Riel > Reviewed-by: Vlastimil Babka > --- LGTM. Hopefully that's the end of this story :) Reviewed-by: David Hildenbrand -- Cheers, David / dhildenb