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 557B535FF66 for ; Thu, 22 Jan 2026 18:00:08 +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=1769104821; cv=none; b=KP69RmeWOdQ0gePUTYkiMMAVg22GaVuYK2o7rULmsZZ39TMftsISzInGzIhBzpI1A9+KO0XOfECZDWYaAMSsrsZ0MTJe0TxthuTec624ZY9P9quo/1x4okIvA5S4w1ucl5/Lwh6C5URNS/GUdZpt4Vs7fUFxPjEwhC+e3HBSO5w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769104821; c=relaxed/simple; bh=OjA3HLzG1M2x2TrcfUcXoE1RQgPeJSDcIQZLH9zElHQ=; h=From:Message-ID:Date:MIME-Version:Subject:To:Cc:References: In-Reply-To:Content-Type; b=WWRnMTQRWHgSKfKc1MQSZmmrhKyaniG80n09RV69O0XXGn0FPi07kh0aGr3Kgkug52j0Cg8qYK5PzoMKo9cmhQqpSaWLeGtzs1KXe81upYUogwhZ8z9n9sAG6kPG1iENOvbAGWqUtsEIQ5griM++kKrZO8Vi3a2xjqgWs56xhGo= 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=AXO7VQL/; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=i23TyA0G; 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="AXO7VQL/"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="i23TyA0G" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769104803; 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; bh=+ZLWX7Ttit3Pt1qm85Tbi244EW7S3psWz/a7zbS1I90=; b=AXO7VQL/8nZoNsb5pJyNESuHmg+IEdjqQ5EK0liX1MSmSClbwzxQEGUPDzaHCeV+V71Tvc +Yo6CDEgCWt7BIiVcShd4jdKsMQMoDQGi23mg/8NrxqshlD/N22ZrOy+T3aHZyvVc1kZbe eETqfNcGw+wqK05+Mw6jWMHs5lmvCak= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-602-VlxtgH1DO7qFhIBrVJneQQ-1; Thu, 22 Jan 2026 13:00:01 -0500 X-MC-Unique: VlxtgH1DO7qFhIBrVJneQQ-1 X-Mimecast-MFC-AGG-ID: VlxtgH1DO7qFhIBrVJneQQ_1769104801 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-8c6a241b5cdso209013985a.1 for ; Thu, 22 Jan 2026 10:00:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1769104800; x=1769709600; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:user-agent:mime-version:date:message-id:from:from:to :cc:subject:date:message-id:reply-to; bh=+ZLWX7Ttit3Pt1qm85Tbi244EW7S3psWz/a7zbS1I90=; b=i23TyA0GR7TXLjYTm66vNNOE1imQ2wYbmDRyUWDRruGTZzYS/nGmb0Owo4dJqetlgy rbwRmV4NC309pVhti088rI5EwzUuEpTg9GOLpzfLeWCDbvHmdmn/mOlGpZOKBvhhvHli 0yJLctlkNh30NfRUmMo+09u3JHQHF9DIqhvNb2hGreWxRaG3NJHslOgFG0G5IbcTwr+v 2wiwD9XBPMwdCHpAYrj4arBT7n7REA51D/71gBqaKUbtsnMQcv5LslJk97xSJxHRm8Mv z+o/KDF4f87iQzhyxzrG4pLoDOOCXjOL+c/l/Ko1czANo8KT5ulsvuScFFaJWmwydvxU yMWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769104800; x=1769709600; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:user-agent:mime-version:date:message-id:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+ZLWX7Ttit3Pt1qm85Tbi244EW7S3psWz/a7zbS1I90=; b=L6L+QIN81moTsll767hEaPhUpesinEfruYh5R547E61E43jX/uIkUsosVkqe63qZUc b4IpJ0nRt2NHNwjIs6ZkX0IyjOhzE7eEW3StiOuqIeXr/hX34a+muVs5iJRqFj6Ghtec 5TAdPPsuw/xPucnI9EeeLuzWp+OMagwCk/s2mi80kOZDXMN8T/nmkiW4myYjoNAmA/Ps nqEP7rpoBQUQI/IYJNs+2OX4WhN4Kb/0dlta0gX81s0/LK0atW+urpCrRJEr6wl/mU6L CvJxHhLFV3Cyn/ahfHkmdGWs/kX0YloHCRjGIKm7BkfBrDdpgeFgpZ5thI+7cn5sdDEi lhOQ== X-Forwarded-Encrypted: i=1; AJvYcCVcvdfSj2LKq4azBwEA7Ymb9AVSau4MJxpGwZFPAcdGLPVjVTX8JZfX44wqC7mG5FgruzYzgx28AkaSSkw=@vger.kernel.org X-Gm-Message-State: AOJu0YwmF7mneTr/4cUoTpn9tOl2qbgpsaj7PiKOmA6lGbOwFLGXyj0w KrpauyY2vqzyx7zBQPSnIFbsxp1r7hInPCEOgauN0bsVdSjU+HuqlkJn2nyMM+OoeBSe/91M1pU aWn2vAg0d7Ffm9/R1MvzEJuMSXw2d6tz2OXxRUvnXRj50dFWpBMvGaZlu6csAzHau03uAiMCwyg == X-Gm-Gg: AZuq6aKewjvt0wJ/CNCPZQkkTiZerOU2D4xOAhHdj2XQS6+VhuvtCkVvL43dA9Fjo+W NJTO8PPBcbM5L2iOv39IqmNRyrgy7BVk4qXizaBiS9U9RDp5nMH2SKwbhEPMoYBoxA0VkV8Dmmk fSZl4kF+v98xFJ8o+B7KXQe/DrZSpshi37DHA++Gr42D4RArdeU4EobgPTB1aQdPUFO5GFBgLOb UZR7HFSBggRce5aDhWvnwjaS1HW6jl3++ZFlaEkxJVqFd5166CvkG//KIr9AB61AD4/3T0KLWxm JUU1yaaFqZB8OGiCLSB4F73G7YF1qb30vlwDoW0aRYQh/QHp3CjrjZ+ZCapNCVFW98m60K8kXTh qY9owjiQeJJ5yury8EgS+yf45bJPYORJnAwogrDYKwNRM+HOdg81ffZ6U X-Received: by 2002:a05:620a:1924:b0:89f:9693:2522 with SMTP id af79cd13be357-8c6e2e4ac7cmr34980985a.73.1769104800465; Thu, 22 Jan 2026 10:00:00 -0800 (PST) X-Received: by 2002:a05:620a:1924:b0:89f:9693:2522 with SMTP id af79cd13be357-8c6e2e4ac7cmr34977385a.73.1769104800080; Thu, 22 Jan 2026 10:00:00 -0800 (PST) Received: from ?IPV6:2601:188:c102:b180:1f8b:71d0:77b1:1f6e? ([2601:188:c102:b180:1f8b:71d0:77b1:1f6e]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8c6af506829sm1272959385a.37.2026.01.22.09.59.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Jan 2026 09:59:58 -0800 (PST) From: Waiman Long X-Google-Original-From: Waiman Long Message-ID: <0fcbb05f-fa7b-47a1-bd4a-d59f1e0ddc35@redhat.com> Date: Thu, 22 Jan 2026 12:59:57 -0500 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/mm_init: Don't call cond_resched() in deferred_init_memmap_chunk() if rcu_preempt_depth() set To: Sebastian Andrzej Siewior , "Paul E. McKenney" Cc: Waiman Long , Andrew Morton , Mike Rapoport , Clark Williams , Steven Rostedt , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, Wei Yang , David Hildenbrand References: <20260121191036.461389-1-longman@redhat.com> <20260121114330.6cd34b4732c7803f1720f0ba@linux-foundation.org> <0e385146-67a3-4fdd-b119-059caba8c5f0@redhat.com> <13d0b8b5-1ba7-4a3e-a686-13a7b993d471@paulmck-laptop> <20260122075747.uSLrSJez@linutronix.de> Content-Language: en-US In-Reply-To: <20260122075747.uSLrSJez@linutronix.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/22/26 2:57 AM, Sebastian Andrzej Siewior wrote: > On 2026-01-21 13:27:32 [-0800], Paul E. McKenney wrote: >>>>> --- a/mm/mm_init.c >>>>> +++ b/mm/mm_init.c >>>>> @@ -2085,7 +2085,12 @@ deferred_init_memmap_chunk(unsigned long start_pfn, unsigned long end_pfn, >>>>> spfn = chunk_end; >>>>> - if (irqs_disabled()) >>>>> + /* >>>>> + * pgdat_resize_lock() only disables irqs in non-RT >>>>> + * kernels but calls rcu_read_lock() in a PREEMPT_RT >>>>> + * kernel. >>>>> + */ >>>>> + if (irqs_disabled() || rcu_preempt_depth()) >>>>> touch_nmi_watchdog(); >>>> rcu_preempt_depth() seems a fairly internal low-level thing - it's >>>> rarely used. > If you acquire a lock from time to time and you pass a bool the let the > function below know whether scheduling is fine or not then it is > obvious. If you choose to check for symptoms of an acquired lock then > you have to use also the rarely used functions ;) > >>> That is true. Beside the scheduler, workqueue also use rcu_preempt_depth(). >>> This API is included in "include/linux/rcupdate.h" which is included >>> directly or indirectly by many kernel files. So even though it is rarely >>> used, but it is still a public API. >> It is a bit tricky, for example, given a kernel built with both >> CONFIG_PREEMPT_NONE=y and CONFIG_PREEMPT_DYNAMIC=y, it will never >> invoke touch_nmi_watchdog(), even if it really is in an RCU read-side >> critical section. This is because it was intended for lockdep-like use, >> where (for example) you don't want to complain about sleeping in an RCU >> read-side critical section unless you are 100% sure that you are in fact >> in an RCU read-side critical section. >> >> Maybe something like this? >> >> if (irqs_disabled() || !IS_ENABLED(CONFIG_PREEMPT_RCU) || rcu_preempt_depth()) >> touch_nmi_watchdog(); > I don't understand the PREEMPT_NONE+DYNAMIC reasoning. irqs_disabled() > should not be affected by this and rcu_preempt_depth() will be 0 for > !CONFIG_PREEMPT_RCU so I don't think this is required. > >> This would *always* invoke touch_nmi_watchdog() for such kernels, which >> might or might not be OK. >> >> I freely confesss that I am not sure which of these is appropriate in >> this setting. > What about a more straight forward and obvious approach? > > diff --git a/mm/mm_init.c b/mm/mm_init.c > index fc2a6f1e518f1..0b283fd48b282 100644 > --- a/mm/mm_init.c > +++ b/mm/mm_init.c > @@ -2059,7 +2059,7 @@ static unsigned long __init deferred_init_pages(struct zone *zone, > */ > static unsigned long __init > deferred_init_memmap_chunk(unsigned long start_pfn, unsigned long end_pfn, > - struct zone *zone) > + struct zone *zone, bool may_schedule) > { > int nid = zone_to_nid(zone); > unsigned long nr_pages = 0; > @@ -2085,10 +2085,10 @@ deferred_init_memmap_chunk(unsigned long start_pfn, unsigned long end_pfn, > > spfn = chunk_end; > > - if (irqs_disabled()) > - touch_nmi_watchdog(); > - else > + if (may_schedule) > cond_resched(); > + else > + touch_nmi_watchdog(); > } > } > > @@ -2101,7 +2101,7 @@ deferred_init_memmap_job(unsigned long start_pfn, unsigned long end_pfn, > { > struct zone *zone = arg; > > - deferred_init_memmap_chunk(start_pfn, end_pfn, zone); > + deferred_init_memmap_chunk(start_pfn, end_pfn, zone, true); > } > > static unsigned int __init > @@ -2216,7 +2216,7 @@ bool __init deferred_grow_zone(struct zone *zone, unsigned int order) > for (spfn = first_deferred_pfn, epfn = SECTION_ALIGN_UP(spfn + 1); > nr_pages < nr_pages_needed && spfn < zone_end_pfn(zone); > spfn = epfn, epfn += PAGES_PER_SECTION) { > - nr_pages += deferred_init_memmap_chunk(spfn, epfn, zone); > + nr_pages += deferred_init_memmap_chunk(spfn, epfn, zone, false); > } > > /* > > Wouldn't this work? Yes, I think that is the better approach. I will post a v3 with change as Mike has no objection to it. Thanks! Cheers, Longman