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 C97311E5706 for ; Mon, 20 Jan 2025 18:39:10 +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=1737398352; cv=none; b=k/e5sG5n77tmhNVe+qjsw/7Te/2FW/oh2TXqxNLclz50cl5ZmlOoRhWwlc4cMyWLDEZ7jwwLCQkG3VAp+yLc/EESCebIM0M8InVBL03VOxodcFM5cz4MszQ9KK+/LMx7DiqiWumet5FYCYzX43xirgHoL8OycBsoEzn66ufpb28= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737398352; c=relaxed/simple; bh=L0r6sL4lA9PBu3XCvYxVmZozgucEiMkEmT+jltmFVZc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=sTrwgeuiNh9UPl0WxMc/KAJebEDTE2uHebnTny3s4o2f4CRG3JNxqWSvrj6O/owWnkxvuIwwCJbSZn2YwwwWQg0atDdW/UsNjNTiBQPMjQZEwPa2EcNsj4ohN8i7A6pGK4hgQ7HWV/Zvr/Xdi8Dy9fHJlD0PBL4DZ4pgPHgGwNQ= 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=IznktO0J; 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="IznktO0J" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737398349; 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=EPw7ws0ZFAl6BpiaOxaiLWEV4yFXae5TxWsmQD8/JVo=; b=IznktO0JNkk1rFe1H208Tb8uckbFJLvq3+UcMGM5MOocXyh/llXAXB/J3D79Gcf86Ix805 6EcOoyFoUcmSipAMJPzVmJ37G16abfSqjncXBNsNpBjwUAfUJ/JkUWx7XCZZ4qESOpO2l9 D03TiJEhjwnCs6sKbYyAVZZpUK7h6oE= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-241-b9Wwf7diNOCoB0yvctpAGQ-1; Mon, 20 Jan 2025 13:39:08 -0500 X-MC-Unique: b9Wwf7diNOCoB0yvctpAGQ-1 X-Mimecast-MFC-AGG-ID: b9Wwf7diNOCoB0yvctpAGQ Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-385ded5e92aso2022136f8f.3 for ; Mon, 20 Jan 2025 10:39:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737398347; x=1738003147; 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=EPw7ws0ZFAl6BpiaOxaiLWEV4yFXae5TxWsmQD8/JVo=; b=KV+UENmxPXMW8i7HgU6TLNdpwoql6EfRk4e2h5fk2MZFhGfou/gf/D7UFOVOtMkdwM dzkDJYJ2tV79Tfc/sITK8F8aLkXgFbphxKa427XtkE7AAVTC19/2x4EBEGbQTMxCyKhw wqUhwIJu9y5G96hXxfTExDXfm5aTYzTyJhn+z0QH0iN0eV5QsMuTuTj/25zBLcJxsZDP Ov7asuWouYORJXmq3s9hPyTdQQWouP2Nx9Nvyikk/S94AQ5jwsz876VpmBeZ4w5R35Tw 06GHa3Z4j/7JS3LUxJnBQ0w3cDuCoGqYAz2+8uSOjzhGhGMvNMw3BktGGfVezkcYr7Aw RNHA== X-Gm-Message-State: AOJu0YwnzetCuNCVJdLloPf5LvQUVufUwdYNKV5f26x9v7A8Yd1Ztl7Z WxzcT53TyKY6isQwbbQzsVbj2HagvtR+wI0cg0dp4NHkg7sq9P/09jr2UDvm82Y0WJKcRNfK1p7 yOmc42K5PjUmprOTEj7ggA/2DbrV3Fv91LFqv4J1yakElqWm/EZuoBS9Aj93TJA== X-Gm-Gg: ASbGncvw3kA/RplAx/PLtvlXPyNWvHdrH0+CKP8jvQ2ECe2Bs1ONZbPt0g/yepU/cAU i7KTH9XagOGZWWnw+J/nm9/ym4HtbWhK7Gd8j4rWU5wc0sjbgYy6E2SShrSIYL129rej5j157ei mPLcbTkbXd0bqecuCNm5oGXNXRFD/X/rnyG6pXbjvZxmHk4NkLbi7ogbmSHOoRS1/psrDaWAPwN kSWsIp31LY1dT6f5nZXYktN39qZk+vA+dNxUkLPCUBPXTOnEqaOCqlQhPPSwG3fzhA6cHKkyQAd HRFQfgsr1G0eMAeva1VSjgia X-Received: by 2002:a05:6000:1864:b0:386:3328:6106 with SMTP id ffacd0b85a97d-38bf59e199cmr15090409f8f.35.1737398347171; Mon, 20 Jan 2025 10:39:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IG5NNUH70H31Q04HtApQ90vhk2LZKQPc06mJujxNhXoh/ci4GXQ+v3M4jqehn8K1lMsyNG2fQ== X-Received: by 2002:a05:6000:1864:b0:386:3328:6106 with SMTP id ffacd0b85a97d-38bf59e199cmr15090360f8f.35.1737398346728; Mon, 20 Jan 2025 10:39:06 -0800 (PST) Received: from [192.168.3.141] (p4ff23481.dip0.t-ipconnect.de. [79.242.52.129]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4389041f7e9sm152280785e9.23.2025.01.20.10.39.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Jan 2025 10:39:06 -0800 (PST) Message-ID: <95472249-44f6-4764-a5fa-fac834eb5a49@redhat.com> Date: Mon, 20 Jan 2025 19:39:03 +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: [RFC 00/11] khugepaged: mTHP support To: Ryan Roberts , Nico Pache Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, anshuman.khandual@arm.com, catalin.marinas@arm.com, cl@gentwo.org, vbabka@suse.cz, mhocko@suse.com, apopple@nvidia.com, dave.hansen@linux.intel.com, will@kernel.org, baohua@kernel.org, jack@suse.cz, srivatsa@csail.mit.edu, haowenchao22@gmail.com, hughd@google.com, aneesh.kumar@kernel.org, yang@os.amperecomputing.com, peterx@redhat.com, ioworker0@gmail.com, wangkefeng.wang@huawei.com, ziy@nvidia.com, jglisse@google.com, surenb@google.com, vishal.moola@gmail.com, zokeefe@google.com, zhengqi.arch@bytedance.com, jhubbard@nvidia.com, 21cnbao@gmail.com, willy@infradead.org, kirill.shutemov@linux.intel.com, aarcange@redhat.com, raquini@redhat.com, dev.jain@arm.com, sunnanyong@huawei.com, usamaarif642@gmail.com, audra@redhat.com, akpm@linux-foundation.org References: <20250108233128.14484-1-npache@redhat.com> <40a65c5e-af98-45f9-a254-7e054b44dc95@arm.com> <37375ace-5601-4d6c-9dac-d1c8268698e9@redhat.com> <0a318ea8-7836-405a-a033-f073efdc958f@arm.com> <8305ddf7-1ada-4a75-a2c3-385b530b25d4@redhat.com> <9bf875ad-3e31-464d-bccd-7c737a2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VoylWiBNknvQWBXS lQCWmavOT9sttGQXdPCC5ynI+1ymZC1ORZKANLnRAb0NH/UCzcsstw2TAkFnMEbo9Zu9w7Kv AxBQXWeXhJI9XQssfrf4Gusdqx8nPEpfOqCtbbwJMATbHyqLt7/oz/5deGuwxgb65pWIzufa N7eop7uh+6bezi+rugUI+w6DABEBAAHCwXwEGAEIACYCGwwWIQQb2cqtc1xMOkYN/MpN3hD3 AP+DWgUCXw7HsgUJEqkpoQAKCRBN3hD3AP+DWrrpD/4qS3dyVRxDcDHIlmguXjC1Q5tZTwNB boaBTPHSy/Nksu0eY7x6HfQJ3xajVH32Ms6t1trDQmPx2iP5+7iDsb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <9bf875ad-3e31-464d-bccd-7c737a2c53bc@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 20.01.25 17:27, Ryan Roberts wrote: > On 20/01/2025 13:56, David Hildenbrand wrote: >> On 20.01.25 14:37, Ryan Roberts wrote: >>> On 20/01/2025 12:54, David Hildenbrand wrote: >>>>>> I think the 1 problem that emerged during review of Dev's series, which we >>>>>> don't >>>>>> have a proper solution to yet, is the issue of "creep", where regions can be >>>>>> collapsed to progressively higher orders through iterative scans. At each >>>>>> collapse, the required thresholds (e.g. max_ptes_none) are met, and the >>>>>> collapse >>>>>> effectively adds more non-none ptes so the next scan will then collapse to >>>>>> even >>>>>> higher order. Does your solution suffer from this (theoretical/edge case) >>>>>> issue? >>>>>> If not, how did you solve? >>>>> >>>>> Yes sadly it suffers from the same issue. bringing max_ptes_none much >>>>> lower as a default would "help". >>>> >>>> Can we just keep it simple and only support max_ptes_none = 511 ("pagefault >>>> behavior" -- PMD_NR_PAGES - 1) or max_ptes_none = 0 ("deferred behavior") and >>>> document that the other weird configurations will make mTHP skip, because "weird >>>> and unexpetced" ? :) > > nit: Rather than values of max_ptes_none other than 0 and max making mTHP skip, > perhaps it's better to say we round to closest of 0 and max? Maybe. Rounding down always implies doing something not necessarily desired. In any case, I assume most setups just have the default values here ... :) > >>>> >>> >>> That sounds like a great simplification in principle! >> >> And certainly a much easier to start with :) >> >> If we ever get the request to support something else, maybe that's also where we >> can learn *why*, and what we would actually want to do with mTHP. >> >>> We would need to consider >>> the swap and shared tunables too though. Perhaps we can pull a similar trick >>> with those? >> >> Swapped and shared are a bit more challenging, because they are set to "/ 2" or >> "/ 8" heuristics. >> >> >> One simple starting point here is of course to say "when collapsing mTHP, all >> have to be unshared and all have to be swapped in", so to essentially ignore >> both tunables (in a memory friendly way, as if they are set to 0) for mTHP >> collapse and worry about that later, when really required. > > For swap, if we assume we start with the whole VMA swapped out, I think setting > max_ptes_swap to 0 could still cause the "creep" problem if faulting pages back > in sequentially? I guess that's creep due to faulting pattern though, so at > least it's not due to collapse. Doesn't feel ideal though. > > I'm not sure what the semantic of "shared" is? I'm guessing it's specifically > for private COWed pages, and khugepaged will trigger the COW on collapse? Yes. > So > again depending on the pattern of writes we could still end up with creep in a > similar way to swap? I think in regards of both "yes", so a simple starting point but not necessarily what we want long term. The creep is at least "not wasting more memory", because we don't collapse where PMD wouldn't have collapsed. After all, right now we don't collapse mTHP, now we would collapse mTHP in many scenarios, so we don't have to be perfect initially. Deriving stuff for small THP sizes when configured for PMD THP sizes is not easy to do right. > >> >> Two alternatives I discussed with Nico for these (not sure which is implemented >> here) is to calculate it proportionally to the folio order we are collapsing: > > You're only listing one option here... what's the other one you discussed? > Ah sorry, reshuffled it and then had to rush. The other thing I had in mind is to scan the whole PMD range, and discard skip the whole PMD range if it doesn't obey the max_ptes_* stuff. Not perfect, but will mean that we behave just like PMD collapse would, unless I am missing something. >> >> Assuming max_ptes_swap = 64 (PMD: 512 PTEs) and we are collapsing a 1 MiB mTHP >> (256 PTEs), 32 PTEs would be allowed to be swapped out. > > Yeah this is exactly what Dev's version is doing at the moment. But that's the > behaviour that leads to the "creep" problem. Right. -- Cheers, David / dhildenb