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 E5F9C2F362F for ; Thu, 21 Aug 2025 20:07:36 +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=1755806859; cv=none; b=RmqsZpSU2hVmF9dlaOaRSg7yVWK8kARmsQhG9aZa6ZsdU/tOOaaSA4tfFzkKQSCCfFd/1H8l3aq1hGniFKNOy5kMxDN45bzZ4Pkf0scbpPjkJkvN6jMHZT5N52lEnxTAVbej8JRPoysjP5oGjxB8W1RD0e7bDqk9PnEAWSFnixY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755806859; c=relaxed/simple; bh=+tsaq0kMmRCBgLfPZThux65EZrTtOKARiF8G7W5lNZE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qd28tKxyozM8amxr33A0YbptU88Wrh4/3I+4pW2ljUKaGkHjyhuxhV4LySZj/EVOPSRIVP86H1D/Go+96Rk7/NdqJ3YJQwmjPnIj/71yGkz0LS+LEIk9r0N2b8TygeqdgUFCsNbl0GaZFDAsrswpqFbaThOE0nbZHDe138a5hb0= 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=cTnGCs3U; arc=none smtp.client-ip=170.10.129.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="cTnGCs3U" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755806855; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r/kmddABpvZJu5K+QD662cz6jOGE1r8xokeQdlRgepQ=; b=cTnGCs3UqgoM2qDpp2bN0hwiGC7IW2T4kVwaj2WxfD46f+BGp/uVjeodqi8sddHs6S5T0D cQ4FdgpiQfdbJBz1Jtn8inWWcpurU68jRYcbSUXfdsXyamSI83MugkrRX/0r54YVM2LQpj bLnbFCuqHJOG2+Tuzqm6dNZhzI8MRb0= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-391-IJiE8aNqM-qyAgUVvyZfGA-1; Thu, 21 Aug 2025 16:07:33 -0400 X-MC-Unique: IJiE8aNqM-qyAgUVvyZfGA-1 X-Mimecast-MFC-AGG-ID: IJiE8aNqM-qyAgUVvyZfGA_1755806853 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3c584459d02so247172f8f.0 for ; Thu, 21 Aug 2025 13:07:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755806852; x=1756411652; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r/kmddABpvZJu5K+QD662cz6jOGE1r8xokeQdlRgepQ=; b=PUbjt+Y6eFlGCf/rO9j6Yd/bixFSX1GVa764MP6Z6WBOYrKu1tw6Wrv/zYMuO/jfLa JxsjuIx6XO55ghA03VJcMh1eyXgOTzl8LQCUwwp+MQfn14dTdIcYzQM0lmM6O40qfSVD lXLIBcPTpp5BZxW1/a29eX0jsIjUKyg+hK9Q0wAfGps7beXyBKfueM6q7im0cBEoyTgF qEat///YWW530g39YTh3iX5tTKNm5ZwgQD0tRnztHHLSnORYoW+EcT24ii/dNO0HchS+ 3TWalsem+/hvZbQTOUradRLiJQUOTndvMLXbNjEJxLlC/b6DI2mJmY+MVm5JmmSv/Pyx YmHw== X-Forwarded-Encrypted: i=1; AJvYcCW0C1U35AWYKzFydqs5vbepK8/084MLlWOOz6Dj6DMkNf4/IuRV1hblNKn+Xm+WklSAuKHzToDjUQ==@vger.kernel.org X-Gm-Message-State: AOJu0Ywixba4li1CFiTlZiVE6l4VZSfO/q8d74RYjhLhB8wNt9wHUgVH h38nV6+3ScEYeyhB5/wR6RzH6TzHVZLV9Syds+BTKs0u9HO+uRa4pALiVMati0KYfENPgeTTBje PFJq/6cocUQJrFWwBDjUwopMfgOM/0raKgWB2GC6cq7ualWN/FWM/6gHcWZ3D X-Gm-Gg: ASbGnctS5bXM16EJQdCm/13mLCTNOLoNFgz95B/fq9MO7rcdnoI3rluJa7rM7WadpUC lFQ+LxQ7aV83sVMVRhNx1HhTzC53CkHRzzEDSxo/fS3IZLzmXLX4UI/E743Pd3QxWNB0WA762Z0 4jafGN7qPnUXsz7tqMzojTXRi6gPZX8Q7Bfq5tefIMcLxxjrNSp2FecldKEl03jKRZe3vXY3htI /bwTqe4F4LynPi0t921lku7wjEv5BzPrkOEZIfFgFDHuSlpsUFkcBS9Clhf2HnmI39Gpue/Evon odAa0iGZFPZSHj/6RJA/5ewYg4TG0zeWrJcKz9TnmPSW4N2JdtwXKl1YjwC7zQuVJbu1sQ1jzqD 5Jo+777KkiLw6yr2PIBhgdg== X-Received: by 2002:a05:6000:2dc7:b0:3b9:15eb:6464 with SMTP id ffacd0b85a97d-3c5daefa9e0mr244709f8f.15.1755806852619; Thu, 21 Aug 2025 13:07:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHbqF8V2lF/CygktHxSJZNB7+pmyneW6nxhnLwTxWefpTwvecQ9FG1LkYH8lxi0WUYYPrMQFQ== X-Received: by 2002:a05:6000:2dc7:b0:3b9:15eb:6464 with SMTP id ffacd0b85a97d-3c5daefa9e0mr244660f8f.15.1755806852102; Thu, 21 Aug 2025 13:07:32 -0700 (PDT) Received: from localhost (p200300d82f26ba0008036ec5991806fd.dip0.t-ipconnect.de. [2003:d8:2f26:ba00:803:6ec5:9918:6fd]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-3c077789c92sm12629958f8f.52.2025.08.21.13.07.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Aug 2025 13:07:31 -0700 (PDT) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: David Hildenbrand , Alexander Potapenko , Andrew Morton , Brendan Jackman , Christoph Lameter , Dennis Zhou , Dmitry Vyukov , dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, iommu@lists.linux.dev, io-uring@vger.kernel.org, Jason Gunthorpe , Jens Axboe , Johannes Weiner , John Hubbard , kasan-dev@googlegroups.com, kvm@vger.kernel.org, "Liam R. Howlett" , Linus Torvalds , linux-arm-kernel@axis.com, linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-ide@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mips@vger.kernel.org, linux-mmc@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org, Lorenzo Stoakes , Marco Elver , Marek Szyprowski , Michal Hocko , Mike Rapoport , Muchun Song , netdev@vger.kernel.org, Oscar Salvador , Peter Xu , Robin Murphy , Suren Baghdasaryan , Tejun Heo , virtualization@lists.linux.dev, Vlastimil Babka , wireguard@lists.zx2c4.com, x86@kernel.org, Zi Yan Subject: [PATCH RFC 09/35] mm/mm_init: make memmap_init_compound() look more like prep_compound_page() Date: Thu, 21 Aug 2025 22:06:35 +0200 Message-ID: <20250821200701.1329277-10-david@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250821200701.1329277-1-david@redhat.com> References: <20250821200701.1329277-1-david@redhat.com> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Grepping for "prep_compound_page" leaves on clueless how devdax gets its compound pages initialized. Let's add a comment that might help finding this open-coded prep_compound_page() initialization more easily. Further, let's be less smart about the ordering of initialization and just perform the prep_compound_head() call after all tail pages were initialized: just like prep_compound_page() does. No need for a lengthy comment then: again, just like prep_compound_page(). Note that prep_compound_head() already does initialize stuff in page[2] through prep_compound_head() that successive tail page initialization will overwrite: _deferred_list, and on 32bit _entire_mapcount and _pincount. Very likely 32bit does not apply, and likely nobody ever ends up testing whether the _deferred_list is empty. So it shouldn't be a fix at this point, but certainly something to clean up. Signed-off-by: David Hildenbrand --- mm/mm_init.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/mm/mm_init.c b/mm/mm_init.c index 5c21b3af216b2..708466c5b2cc9 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1091,6 +1091,10 @@ static void __ref memmap_init_compound(struct page *head, unsigned long pfn, end_pfn = head_pfn + nr_pages; unsigned int order = pgmap->vmemmap_shift; + /* + * This is an open-coded prep_compound_page() whereby we avoid + * walking pages twice by initializing them in the same go. + */ __SetPageHead(head); for (pfn = head_pfn + 1; pfn < end_pfn; pfn++) { struct page *page = pfn_to_page(pfn); @@ -1098,15 +1102,8 @@ static void __ref memmap_init_compound(struct page *head, __init_zone_device_page(page, pfn, zone_idx, nid, pgmap); prep_compound_tail(head, pfn - head_pfn); set_page_count(page, 0); - - /* - * The first tail page stores important compound page info. - * Call prep_compound_head() after the first tail page has - * been initialized, to not have the data overwritten. - */ - if (pfn == head_pfn + 1) - prep_compound_head(head, order); } + prep_compound_head(head, order); } void __ref memmap_init_zone_device(struct zone *zone, -- 2.50.1