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 40074EEC0 for ; Thu, 4 Sep 2025 10:31:40 +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=1756981903; cv=none; b=LUNkXHRuNq1RgbcClE5hooJ7dP59Jwd3Nfbr9fAbrXO1YvcKDbqeXFQjIey33tMRHZq68dmwNswKbNZWoLNdZekXD/pP5FNpgVIVkUYxb1vc8cTDLfE5aUjam45rizTmpH+pKmQYPpdFh7JAWZgy1GDJduRynVo/9SSKnt/bRrs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756981903; c=relaxed/simple; bh=66nV7x9taXwzAR9J6YPlOauNzE3KaxTRy/9n9NnIgm4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=BpR6pQad+PamT+uJnQrBu7gnkStCHCi8mvX9xvFdue3XOCAeRBIPI23n1a6d/YnDHkgpV1QKxqXGDJbqJIbS2uVnbQIvJ3WGg+ncQBa1zM4z7rbKNFLAdu+mm8J0dfm7yxfkVddMhrYMSl5UpK1c7gZ+MTqFjfj/IlhV+CJBNvQ= 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=RhsNwnYC; arc=none smtp.client-ip=170.10.133.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="RhsNwnYC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756981900; 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=iNez6/M9s3PJsme5pRqUUeFXGJSz6E2jhwKDhn5HC94=; b=RhsNwnYCGzBHvYN8pP22ZsRcSgJZAc0zL7TWBBELNVKycHwWAOEPXJLy2InhpgpkjQZUYM u0U58TaoEiBmDdg/DVwkVUuHrvT2zFZWJWSkY+fWjdSoeMnKjLt0YeuPUhLQGylq//VHJ2 p4g1KNZ++W/vKEoQPikz1BJ0JxMVdSY= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-244-Z0yX6yQqMVWqsnNtXkFa9g-1; Thu, 04 Sep 2025 06:31:37 -0400 X-MC-Unique: Z0yX6yQqMVWqsnNtXkFa9g-1 X-Mimecast-MFC-AGG-ID: Z0yX6yQqMVWqsnNtXkFa9g_1756981897 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-45b80aecb97so7363375e9.3 for ; Thu, 04 Sep 2025 03:31:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756981896; x=1757586696; h=content-transfer-encoding:in-reply-to: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=iNez6/M9s3PJsme5pRqUUeFXGJSz6E2jhwKDhn5HC94=; b=ZEWzs8PEcjBLdZldexjWA8DyOT6eM2lcx7DR+j0xRqamhOl7HsY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 2002:a05:600c:1386:b0:45b:81ad:336 with SMTP id 5b1f17b1804b1-45b855340e4mr168285055e9.16.1756981896481; Thu, 04 Sep 2025 03:31:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG3MLtM5QDjEU/zOfZe3S/gDem/oxe78HJp4IABGPJ9GtWj8bc+E5LqhZjiV2Kjt/XWKXc5aQ== X-Received: by 2002:a05:600c:1386:b0:45b:81ad:336 with SMTP id 5b1f17b1804b1-45b855340e4mr168284645e9.16.1756981895992; Thu, 04 Sep 2025 03:31:35 -0700 (PDT) Received: from ?IPV6:2003:d8:2f25:1e00:ce4c:be3:97b3:6587? (p200300d82f251e00ce4c0be397b36587.dip0.t-ipconnect.de. [2003:d8:2f25:1e00:ce4c:be3:97b3:6587]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3d7ac825b88sm14277593f8f.7.2025.09.04.03.31.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Sep 2025 03:31:35 -0700 (PDT) Message-ID: <0ba60468-fc6d-4f07-a9ea-e16b8bcd5575@redhat.com> Date: Thu, 4 Sep 2025 12:31:34 +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] mm: tag kernel stack pages To: Matthew Wilcox Cc: "Vishal Moola (Oracle)" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton References: <20250820202029.1909925-1-vishal.moola@gmail.com> <96148baf-f008-449b-988b-ea4f07d18528@redhat.com> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacP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6Rg38yk3e EPcA/4NaBQJonNqrBQkmWAihAAoJEE3eEPcA/4NaKtMQALAJ8PzprBEXbXcEXwDKQu+P/vts IfUb1UNMfMV76BicGa5NCZnJNQASDP/+bFg6O3gx5NbhHHPeaWz/VxlOmYHokHodOvtL0WCC 8A5PEP8tOk6029Z+J+xUcMrJClNVFpzVvOpb1lCbhjwAV465Hy+NUSbbUiRxdzNQtLtgZzOV Zw7jxUCs4UUZLQTCuBpFgb15bBxYZ/BL9MbzxPxvfUQIPbnzQMcqtpUs21CMK2PdfCh5c4gS sDci6D5/ZIBw94UQWmGpM/O1ilGXde2ZzzGYl64glmccD8e87OnEgKnH3FbnJnT4iJchtSvx yJNi1+t0+qDti4m88+/9IuPqCKb6Stl+s2dnLtJNrjXBGJtsQG/sRpqsJz5x1/2nPJSRMsx9 5YfqbdrJSOFXDzZ8/r82HgQEtUvlSXNaXCa95ez0UkOG7+bDm2b3s0XahBQeLVCH0mw3RAQg r7xDAYKIrAwfHHmMTnBQDPJwVqxJjVNr7yBic4yfzVWGCGNE4DnOW0vcIeoyhy9vnIa3w1uZ 3iyY2Nsd7JxfKu1PRhCGwXzRw5TlfEsoRI7V9A8isUCoqE2Dzh3FvYHVeX4Us+bRL/oqareJ CIFqgYMyvHj7Q06kTKmauOe4Nf0l0qEkIuIzfoLJ3qr5UyXc2hLtWyT9Ir+lYlX9efqh7mOY qIws/H2t In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 02.09.25 21:52, Matthew Wilcox wrote: > On Thu, Aug 21, 2025 at 02:44:31PM +0200, David Hildenbrand wrote: >> On 20.08.25 22:20, Vishal Moola (Oracle) wrote: >>> Currently, we have no way to distinguish a kernel stack page from an >>> unidentified page. Being able to track this information can be >>> beneficial for optimizing kernel memory usage (i.e. analyzing >>> fragmentation, location etc.). Knowing a page is being used for a kernel >>> stack gives us more insight about pages that are certainly immovable and >>> important to kernel functionality. >> >> It's a very niche use case. Anything that's not clearly a folio or a special >> movable_ops page is certainly immovable. So we can identify pretty reliable >> what's movable and what's not. >> >> Happy to learn how you would want to use that knowledge to reduce >> fragmentation. :) >> >> So this reads a bit hand-wavy. > > I have a theory that we should always be attempting to do aligned > allocations if we can, falling back to individual allocations if > we can't. This is an attempt to gather some data to inform us whether > that theory is true, and to help us measure whether any effort we > take to improve that situation is effective. > > Eyeballing the output of tools/testing/page-types certainly lends > some credence to this. On x86-64 with its 16KiB stacks and 4KiB > page size, we often see four consecutive pages allocated as type > KernelStack, and as you'd expect only about 25% of the time are they > aligned to a 16KiB boundary. That is, at least 75% of the time they > prevent _two_ order-2 pages from being available. I assume, ideally, you'd also know whether all these stack pages belong to the same thread, not various ones, right? ("context" can matter as well) > > As you say, they're not movable. I'm not sure if it makes sense to > go to the effort of making them movable; it'd require interacting > with the scheduler (to prevent the task we're relocating from > being scheduled), and I don't think the realtime people would be > terribly keen on that idea. So that isn't one of the ideas we > have on the table for improving matters. Yeah, while possible I am also not sure if we always want that. > > Ideas we have been batting around: > > - Have kernel stacks try to do an order-N allocation and vmap() > the result, fall back to current implementation > - Have vmalloc try to do an order-N allocation, fall back down the > orders on failure to allocate > - Change the alloc_bulk implementation to do the order-N allocation > and fall back > > I'm sure other possibilities also exist. > >> staring at [1], we allocate from vmalloc, so I would assume that these will >> be vmalloc-typed pages in the future and we cannot change the type later. >> >> [1] https://kernelnewbies.org/MatthewWilcox/Memdescs > > I see the vmalloc subtype as being a "we don't know any better" type. I guess this could get nasty once we would have metadata assigned to the vmalloc allocations (struct vmdesc). > We could allocate another subtype of type 0 to mean "kernel stacks" > and have it be implicit that kernel stacks are allocated from vmalloc. Yes, that would work. > This would probably require that we have a vmalloc interface that lets us > specify a subtype, which I think is probably something we'd want anyway. vmalloc subtypes don't sound like a bad idea. > > I think it's fine to say "This doesn't add enough value to merge it > upstream". I will note one minor advantage which is that typing these > pages as PGTY_kstack today prevents them from being inadvertently mapped > to userspace (whether by malicious code or innocent bug). Yes, as raised elsewhere, if we can do this consistently today (stack -> PGTY_kstack), fine with me. -- Cheers David / dhildenb