From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 976E7C282D1 for ; Mon, 3 Mar 2025 17:06:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 10D48280023; Mon, 3 Mar 2025 12:06:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0BD9428001E; Mon, 3 Mar 2025 12:06:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E795E280023; Mon, 3 Mar 2025 12:06:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C4DBF28001E for ; Mon, 3 Mar 2025 12:06:21 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 22A49B4A8E for ; Mon, 3 Mar 2025 17:06:21 +0000 (UTC) X-FDA: 83180868162.07.2EE1377 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf07.hostedemail.com (Postfix) with ESMTP id F03224002D for ; Mon, 3 Mar 2025 17:06:17 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GYBMXIi1; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741021578; a=rsa-sha256; cv=none; b=UpGE5ipfttmWfp1BRioMCJ4M79VNRuk30dn3/sDfwf6Z13LVJZTREqZ0AE6xXx0c/8KYwj MLzRVANpNv+0rPGxaY26ZkGHXSgovica/YTJuuHZrRmsUCIT83I3tqMexF4FhlcDEkv1dt o4MpIyZQyw7B1QzqcB/UV6sqIjYmPXw= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GYBMXIi1; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741021578; h=from:from:sender: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:dkim-signature; bh=gsS4uQGU3Fy152pH6WRF0p0WuZMpxXSqYsWQZibR72E=; b=xLl5wfjUPUClJfjs+J16IBSFQ5zywpPpPIscqIhBiKDlv3uEou8qb/Y8pqvZX4oe0HTbyA L6J8YOoTSUFpPF50pe0LSx9+6Mpetu+ktybR5eTKi/h/QHULzHquaoEFAU1UJkOgBdhqdZ OKUuS7AW4csgFxNQ6cDKddGgWegpIPU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741021576; 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=gsS4uQGU3Fy152pH6WRF0p0WuZMpxXSqYsWQZibR72E=; b=GYBMXIi10hTFIiLKm9ap1WMUROdsOqjouxmchrFHsF8zE8f1lTqugCRzb4fcbTYtNmofEq b3sEaezYiD8RSa67AeP0MsyQwizqHyXsTJP2NHRhzHU3dykw9pkO5HsnKLUhKn/IJBK0yA ZDJqlP1SRlu/yzVLr4UalWU1uA2jTDU= 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-687-6-cQyjqhNumcuVDveOEtzw-1; Mon, 03 Mar 2025 12:06:15 -0500 X-MC-Unique: 6-cQyjqhNumcuVDveOEtzw-1 X-Mimecast-MFC-AGG-ID: 6-cQyjqhNumcuVDveOEtzw_1741021574 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4393e89e910so26296365e9.0 for ; Mon, 03 Mar 2025 09:06:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741021574; x=1741626374; 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=gsS4uQGU3Fy152pH6WRF0p0WuZMpxXSqYsWQZibR72E=; b=U4Wd4jywVuAUhytnSuEzqauxeOTH9MBpK6fXbL7aFNU9U6BqQJUKqKQLUmzfD5FNEN 503DjdfQZY05mKORfgCuSehHBJ41kJB3/ZsKBaf0Pw3hUZ+ZYFTR0zE4JvhNjSBArxYH 5c39wc4B4gOz6GkbnzcPmI3EN3SVaN3tUfDVKb9OktvHDd0Fvm6KQbKYJBREYAq+3IHC vxypEU0ZWJ1oe2stRwRX+CNYnwG+QrHrM4wKoLsHj0+NYWSzGImwpa3ozfolieXccTrZ v8lnjU93/hTK/uklpzw6qGEYSmRtTOiMi96FC0ufl0VngRHA1QkGYvKLK31cnJ2A3M9A bxTQ== X-Forwarded-Encrypted: i=1; AJvYcCU7s0xYOMHJPOFD+sbZVIyEzWTEWBNaww63VAON6KtViijC3n5bqBRKDmEreCUmGOJV/s4KVoZ+RQ==@kvack.org X-Gm-Message-State: AOJu0Ywt6SFbCg2rfC/nVSe3vWehQOIY1llJ2zUaOfBeqAVOHxb3LoRN JyuWGguSLumEzWwI6VLsgsCtAtXrSydBO+yKAQnzM1kziqPvHrd2kZl6QU6VjEGObIYRq3FHXhZ i6ctqalSewtB/rUaKQs/sZss3+kruw5kK7t/UVWALFFsJakZ+ X-Gm-Gg: ASbGncvebt24EiBlYevmmEHxAiQSERSa9PuOY6SAyoJNCuRYHJZUooY8vxfHOVp8N8e 8VuWLZ3+1DNFPaB8/r7uUe3Bni4oNVnZ8BbrDtk/RpYnKB/Vt/NeCE2OIwYt7zO7axCIDlYD9nl y4cywVWmofkUI1bVBYRN03wjBkV2t/VbWX+MXbPSmPPkSBIW2Os+A5P6uigKDsP5SVnJmX1eDZE c23QgNFlfAPOYaj8kciE9equqgh/0XwEgk0kqJQjej9eziVH60PkRqs8Scv1ZiGXSKoIe+v02hx zQscw//aDewEBfqiM8Pz1BdzXUPzF73JIUPTxKJtS8r3CxhGULRmzFCwWZRAUxwBVrljPMqMZI7 gmuRmh7AqfbWRZr9KiqjIOncSwMyt9/Cp+doIbai0mHU= X-Received: by 2002:a05:600c:1c25:b0:439:8340:637 with SMTP id 5b1f17b1804b1-43ba6774ba2mr129021695e9.30.1741021574164; Mon, 03 Mar 2025 09:06:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IEYKD9yl9YKCpImv3triscGudcEtqinsDcILauuZwD8gm0vEC6r2GYlBRImMLzOgn3spwnAMw== X-Received: by 2002:a05:600c:1c25:b0:439:8340:637 with SMTP id 5b1f17b1804b1-43ba6774ba2mr129021215e9.30.1741021573727; Mon, 03 Mar 2025 09:06:13 -0800 (PST) Received: from ?IPV6:2003:cb:c734:9600:af27:4326:a216:2bfb? (p200300cbc7349600af274326a2162bfb.dip0.t-ipconnect.de. [2003:cb:c734:9600:af27:4326:a216:2bfb]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e47a6d17sm14822253f8f.28.2025.03.03.09.06.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 03 Mar 2025 09:06:13 -0800 (PST) Message-ID: <0f120624-3ae9-4273-b349-b10d813a4e65@redhat.com> Date: Mon, 3 Mar 2025 18:06:12 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] mm/page_alloc: Add lockdep assertion for pageblock type change To: Brendan Jackman Cc: Andrew Morton , Oscar Salvador , Johannes Weiner , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20250303-pageblock-lockdep-v2-1-3fc0c37e9532@google.com> <4d0f0bca-3096-4fb4-9e8b-d4dcdf7eeb92@redhat.com> <3e66875e-a4d5-4802-85b3-f873b0aa3b06@redhat.com> From: David Hildenbrand 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 B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABzSREYXZpZCBIaWx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MgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 6Kks0FrEUpmkll54tG3_KR85hINVCWwzDOFn1tzhIxI_1741021574 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: F03224002D X-Stat-Signature: i7owu9xjgjztgrhmb7t18shffypxrug3 X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1741021577-880908 X-HE-Meta: U2FsdGVkX19OsAnUwbxyufwdUYRCM1M6Us1EywgUP/iwYoMzyYQ7HlEsXHE3aQeq02S49ThWZfs8QhgZH5R1FXGH+zcDoRQVVNYjowxIN/G7rY38yL3SGkBJ12DjOJhuNGM2Qf5VBhQ0LzHUDhoGC+X3Yv8Q/dvRpFn6Tqt48LNDwbWH4Fxtx6hvMFG/Esm2kPLRHF0rfOTm5QM9kp2hPjfcziT3XWnjyNUlw+34NOjmLOVxv8pty8LXs2fMOvyzkajSr2q10jthpt2xKoKvgP+IlFMZfVEeXUu425v4ieVvYHniYjVv84mJOe6XkdrRPE2TFhhXCEMbzIVbiFi/zm/z4nxyq1OrndeYA8wxJCgQQ213jGrzBdejnQus97ClHE4GSC4jVaPTOA2uKJpfcbcX1FLbsIwosBkqc+TVOGZew8r87Vy3kLT0G0LqMz9K+vdzENZvsAm2E+B8uKK3SmissZDop4YI7xFQYrlJLCYWiZARB4yqOXMrJ9wNgFb1ffVY2tF2zTQ5vp8nzIWLzpmZOgPkF9jjFcthicWI9672zvY36K7VGvc9KrgkznT8a+Seg+aQYyeDYGb9HMNrrqIoiDc8txjX0NhVTvbRpGX/QSvEaPiD76oDxFxsT5xoChI+l4TLLxCtpvxvbkeokba+kNQK1PFlUXNn3QtzrpOKVQvuHxlJv3RSl0uuyhQMUjQB7yIdeCaMSGWZ+7glf31CvuoO1FS2w6I9YNrrNHig2vsuKwvcztKuV/Uz2eNZEcvixdkwmvPyOcA/GhFKK1HUMtYhkQCNdJPKCRW5o5QoWxS2bOtDCpRBlQafmdTnOSSILMQIV3rkDJn7ESiE/NwiefYoyi/UZDiUNtmJrUd0CcpDL25FLipLbKQWWrRiinu0UjbFetJKILWGaBtKGWmeSKe+bg1OCV3wYg5xukATt621ObrQtwFLNxMbDwbCUcmYdr/KTJi2HgpT6d9 dJLmlWO2 PDDywmzeTRiGL8kK0D36lzhqpNEXPCSSEgfY9R8Hh36SaNSE1kEcpgk/4BOVa76Rmw1cuP5IPoR2eo19yB6hCLs9Bsap9f7dcmAwifTHP1TbB0O5I7FSrQRA6rMqV+/qNddSDZDGXg/qsUHvgOfX+Z+6vzhrcRoclzDzymAigWdrSXRY75ByhptES88+86hfT4vCcDmXdMjLn/Tl3MUXBoRztzuiHkrGAicM8rpVRUiszdZFE9HpqTuR1biRkLeZbjG8zGXIS79L+xgkyfSYWfqB224JgxObG93jh3dYIUaUzBkUArxoyyHD9tCZ2wnIFfjcf1Ud+xFLRuIYPst7DVQP26xAb3rPT+hQ8I1LNrC6I3S2h4Dsh9pzlNfo5KCNOofDIBQLVlvddPgWCGRGQgqbo03x4BBduZBoiuVDltt7WtiyxUvy8qJww7sBc08Hm34f6 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 03.03.25 17:00, Brendan Jackman wrote: > On Mon, Mar 03, 2025 at 03:06:54PM +0100, David Hildenbrand wrote: >> On 03.03.25 14:55, Brendan Jackman wrote: >>> On Mon, Mar 03, 2025 at 02:11:23PM +0100, David Hildenbrand wrote: >>>> On 03.03.25 13:13, Brendan Jackman wrote: >>>>> Since the migratetype hygiene patches [0], the locking here is >>>>> a bit more formalised. >>>>> >>>>> For other stuff, it's pretty obvious that it would be protected by the >>>>> zone lock. But it didn't seem totally self-evident that it should >>>>> protect the pageblock type. So it seems particularly helpful to have it >>>>> written in the code. >>>> >>>> [...] >>>> >>>>> + >>>>> u64 max_mem_size = U64_MAX; >>>>> /* add this memory to iomem resource */ >>>>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c >>>>> index 579789600a3c7bfb7b0d847d51af702a9d4b139a..1ed21179676d05c66f77f9dbebf88e36bbe402e9 100644 >>>>> --- a/mm/page_alloc.c >>>>> +++ b/mm/page_alloc.c >>>>> @@ -417,6 +417,10 @@ void set_pfnblock_flags_mask(struct page *page, unsigned long flags, >>>>> void set_pageblock_migratetype(struct page *page, int migratetype) >>>>> { >>>>> + lockdep_assert_once(system_state == SYSTEM_BOOTING || >>>>> + in_mem_hotplug() || >>>>> + lockdep_is_held(&page_zone(page)->lock)); >>>>> + >>>> >>>> I assume the call chain on the memory hotplug path is mostly >>>> >>>> move_pfn_range_to_zone()->memmap_init_range()->set_pageblock_migratetype() >>>> >>>> either when onlining a memory block, or from pagemap_range() while holding >>>> the hotplug lock. >>>> >>>> But there is also the memmap_init_zone_device()->memmap_init_compound()->__init_zone_device_page()->set_pageblock_migratetype() >>>> one, called from pagemap_range() *without* holding the hotplug lock, and you >>>> assertion would be missing that. >>>> >>>> I'm not too happy about that assertion in general. >>> >>> Hmm, thanks for pointing that out. >>> >>> I guess if we really wanted the assertion the approach would be to >>> replace in_mem_hotplug() with some more fine-grained logic about the >>> state of the pageblock? But that seems like it would require rework >>> that isn't really justified. >> >> I was wondering if we could just grab the zone lock while initializing, then >> assert that we either hold that or are in boot. > > Would that be because you want to avoid creating in_mem_hotplug()? Or > is it more about just simplifying the synchronization in general? A little bit of both. The question is if lockless resizing of the zone range today is a bug or a feature :) I'm not aware of any known side-effects of that, but if we could add locking without causing noticeable overheads, that would certainly be easiest ... > > FWIW I don't think the in_mem_hotplug() is really that bad in the > assertion, it feels natural to me that memory hotplug would be an > exception to the locking rules in the same way that startup would be. > >> In move_pfn_range_to_zone() it should likely not cause too much harm, and we >> could just grab it around all zone modification stuff. >> >> memmap_init_zone_device() might take longer and be more problematic. >> >> But I am not sure why memmap_init_zone_device() would have to set the >> migratetype at all? Because migratetype is a buddy concept, and >> ZONE_DEVICE does not interact with the buddy to that degree. >> >> The comment in __init_zone_device_page states: >> >> "Mark the block movable so that blocks are reserved for movable at >> startup. This will force kernel allocations to reserve their blocks >> rather than leaking throughout the address space during boot when >> many long-lived kernel allocations are made." > > Uh, yeah I was pretty mystified by that. It would certainly be nice if > we can just get rid of this modification path. > >> But that just dates back to 966cf44f637e where we copy-pasted that code. >> >> So I wonder if we could just >> >> diff --git a/mm/mm_init.c b/mm/mm_init.c >> index 57933683ed0d1..b95f545846e6e 100644 >> --- a/mm/mm_init.c >> +++ b/mm/mm_init.c >> @@ -1002,19 +1002,11 @@ static void __ref __init_zone_device_page(struct page *page, unsigned long pfn, >> page->zone_device_data = NULL; >> /* >> - * Mark the block movable so that blocks are reserved for >> - * movable at startup. This will force kernel allocations >> - * to reserve their blocks rather than leaking throughout >> - * the address space during boot when many long-lived >> - * kernel allocations are made. >> - * >> - * Please note that MEMINIT_HOTPLUG path doesn't clear memmap >> - * because this is done early in section_activate() >> + * Note that we leave pageblock migratetypes uninitialized, because >> + * they don't apply to ZONE_DEVICE. >> */ >> - if (pageblock_aligned(pfn)) { >> - set_pageblock_migratetype(page, MIGRATE_MOVABLE); >> + if (pageblock_aligned(pfn)) >> cond_resched(); >> - } >> /* >> * ZONE_DEVICE pages other than MEMORY_TYPE_GENERIC are released > > memory-model.rst says: > >> Since the >> page reference count never drops below 1 the page is never tracked as >> free memory and the page's `struct list_head lru` space is repurposed >> for back referencing to the host device / driver that mapped the memory. That comment will be stale soon. In general, ZONE_DEVICE refcounts can drop to 0, but they will never go to the buddy, but will get intercepted on the freeing path. > > And this code seems to assume that the whole pageblock is part of the > ZONE_DEVICE dance, it would certainly make sense to me... Sorry, I didn't get your final conclusion: do you thing we don't have to initialize the migratetype, or do you think there is reason to still do it? -- Cheers, David / dhildenb