Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1173686lqt; Fri, 7 Jun 2024 09:58:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVGhSy8S0KCF/krb/eRY+BrfeddqFP2I9ys1tkPJZGduUwRTjB6r4B7SZ6ndNdSueY8rHbupwkLyLKfKS1wvDLQZ5vl1lQL8/Tl4BmnJQ== X-Google-Smtp-Source: AGHT+IHx99HNk7AP49qa/4QMwkrIl60Bbfk9RtstBCwZgoDosY3GtoYqZoixCPQBt4HPMCfaYRMQ X-Received: by 2002:a17:902:c408:b0:1f4:7713:8f6 with SMTP id d9443c01a7336-1f6d0388ea1mr36916135ad.52.1717779484922; Fri, 07 Jun 2024 09:58:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717779484; cv=pass; d=google.com; s=arc-20160816; b=hZD3a3koaQK3qRyz6FZcniYIzqfWzS6twrUmMjOqAFiZ70FD4KOxGihVRR9ihSk8BT zFjl1vXt0mjMCaABdbI0trGKcGFo2xVl0LKCr/8jqpejMnxSXSE4XxyLjhQMefXz7TJ4 8lLXTEwdLXpb1rhmfuycI1i2S+XCDWDdBQpHJe7QQ0oCWCYISE/DHxed3gkWAYU/dCl5 CMiy6zDNP2t4XUYI4QCuH2ULbaqJ3cE+87VMGT3i3xkZhnTHL6/YZgN3/6qK/sfN5oxq ihAadA8/PuOYKoqzEUAkMFxzUUtgKl5+eNkFtRy0rDPOMMWCWiVumIUrS67LM5Qh4J97 dH4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=/8vmPr/U3SOxUzw+yKkrbrSVi4WiBXuKae4RE7ZMD7A=; fh=Q13L15yRg+g+ED66ZQ/XhNZdHk7dpssrcU8iAkW04mg=; b=SvuRrO71C5rciUdCxNMVGxfCRB2KT8tIYw+YFWEGDUAwcpTfdEnUEunjA6MaXQsf6i 1jLv2r76FqDeaMwckGQwgkdPU/xEXYNCxnHy4RSbHTNgtEbzYCNuAul+i1j3fF3GBwIE 6wS7SA0dICArbzRByJRhXK056Vu+cdO717J9aZvTHRSeBDUJubKqn1CUyujZjgJ6WeRN duP/n23n3kjR0YyVIwDPzbgkneRhaMRQfEbDMNZi+RD8pELOETsA3SWY5NxUBQ0JW9xC X+VjZjFoclXrSk7rWaQJTGhEKeoKH9gXFQUrqMs4qSQ0wXdKbSamWy01yVbTNYrj/HS7 Oh+g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=iUJ7gdfq; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-206516-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206516-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f6bd7d2f73si33351465ad.269.2024.06.07.09.58.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 09:58:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206516-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=iUJ7gdfq; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-206516-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206516-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D537FB21F6C for ; Fri, 7 Jun 2024 16:56:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2F3B719AA6A; Fri, 7 Jun 2024 16:56:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="iUJ7gdfq" Received: from mail-vs1-f54.google.com (mail-vs1-f54.google.com [209.85.217.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A477F33CFC for ; Fri, 7 Jun 2024 16:56:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717779370; cv=none; b=rpa8Kewds4D9ZtJ1LgPh4pRCN5Er6bk4Vrb5HruQrKndcTCXS/yqelu+limbYULne7x+Bc3kN7MEYxK4g10BtjtiaVUUo00ZPu4y5xMxxDlbUpi1ABHnjTGtRne9KX0k//JAdV7TcbzN0DGHQEdT1Pp7N3Z1wHae8sZpwCWKur0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717779370; c=relaxed/simple; bh=//VRgtR0iJfllvqKbgu++TYLbcb8G0oSib5a9u4MhOI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=FbvIkMOKTYV6QLIql9X09aa264jbQUFT19druGl7eucHMjj3QPfklOXTVHJEoXRoijlTz+6LjbfyA0fxme55PS6Yw2tZ0e8pqdqNpLdJR+RnVvRkdZLcysgoEz6kwSLDsAeKR4xLuLuoTUV7tHDo93qTP31iEZR2/zh5+q6zREY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=iUJ7gdfq; arc=none smtp.client-ip=209.85.217.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-vs1-f54.google.com with SMTP id ada2fe7eead31-48bdcecf6efso846267137.3 for ; Fri, 07 Jun 2024 09:56:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717779367; x=1718384167; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=/8vmPr/U3SOxUzw+yKkrbrSVi4WiBXuKae4RE7ZMD7A=; b=iUJ7gdfq9znnyn3tXnCKwPBQ/gdj3rwU+xR48N7y2sTkhBnYDkikWyJy2JULT/EwbM xco5ryJlb5NDV/i33KKSGap6Sgoa9GOpvs4lpSl5E0QAckhqpIZizsDz87dzgXw8uvB0 TbrUjdtJyAynuu0NH55Gm+i3n0w3iHzZiELQa8G32GiVPEieIiksBjj6LxHjhKSVVS+W hBRv5qrIrBn4i0F8U3hEjfaehYPtXAX7mEkxE25gAcPYWJn3FSdoEXpoQ/7RwhfHD6yM iPUKHywHahmMyah4giO2S271fcp+Uk0fGBo3MjsYqUyNYbJXSk5y+Rzpc4YHS6aFMD6c OTkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717779367; x=1718384167; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/8vmPr/U3SOxUzw+yKkrbrSVi4WiBXuKae4RE7ZMD7A=; b=w6YVyM30R20YxW7anIOjPwsgoN+tYVh2UQXPMXs8f9QJTfxjj0eJqpKdED6iPsC0+D Ju47YQXLHBBhvQJx06AeGgPRr2FXoLDD2HrysH0inpCgSxB8P1ffDeo1ZDDS5/Ej1j2z eqKotqy84XY/TqTjIOCIpIVjG7fdQDF5bFJcIesxFHdtFTBiMzrNoUwhrXLj5WlgMKhU 0wAoGJ67aNtHo5L3gdYr9kh08dOZl1qATeoo5oxXVi2lwwRvT9snwvfB8H5Wpa067czp 6Di90jPt9bh6nWpeqpj+N2mnyMk+lVvJw/jRJaxQx/ZaSoj5odRFjQbarCnn5ZwFw2+2 WGrQ== X-Forwarded-Encrypted: i=1; AJvYcCUVoEquFSWtHpO2J3Q4FVnlJIq9ARbTsN4k6JhJLi+0CrtcTcGXIA3y6hb1aD+r0S80E4kPKHkmye9yfKZW4q7woFFCVTxJy/eGaFzg X-Gm-Message-State: AOJu0YzKnK9pkgkH+Jn+H2/K3rD9jKXP0lh7VSCAp5oq5ChiZQb1U8xb c9zVTREbLpVxlyDg469t7n9vNx1Wvx2ZyBgwkH7JG4TtzpM7ApHWicTn5OnuyPIVABs10I4hPT0 U3VmHX0RW45pfXMIhFQ5NV4aPWMSAnscylH1T X-Received: by 2002:a05:6102:17cd:b0:48c:526:8ae with SMTP id ada2fe7eead31-48c2752821emr3455949137.2.1717779367409; Fri, 07 Jun 2024 09:56:07 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240113094436.2506396-1-sunnanyong@huawei.com> <20240207111252.GA22167@willie-the-truck> <20240207121125.GA22234@willie-the-truck> <908066c7-b749-4f95-b006-ce9b5bd1a909@oracle.com> <917FFC7F-0615-44DD-90EE-9F85F8EA9974@linux.dev> In-Reply-To: From: Frank van der Linden Date: Fri, 7 Jun 2024 09:55:55 -0700 Message-ID: Subject: Re: [PATCH v3 0/3] A Solution to Re-enable hugetlb vmemmap optimize To: David Hildenbrand Cc: Yu Zhao , Muchun Song , Matthew Wilcox , Jane Chu , Will Deacon , Nanyong Sun , Catalin Marinas , akpm@linux-foundation.org, anshuman.khandual@arm.com, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I had an offline discussion with Yu on this, and he pointed out something I hadn't realized: the x86 cmpxchg instruction always produces a write cycle, even if it doesn't modify the data - it just writes back the original data in that case. So, get_page_unless_zero will always produce a fault on RO mapped page structures on x86. Maybe this was obvious to other people, but I didn't see it explicitly mentioned, so I figured I'd add the datapoint. - Frank On Thu, Jun 6, 2024 at 1:30=E2=80=AFAM David Hildenbrand = wrote: > > >> Additionally, we also should alter RO permission of those 7 tail pages > >> to RW to avoid panic(). > > > > We can use RCU, which IMO is a better choice, as the following: > > > > get_page_unless_zero() > > { > > int rc =3D false; > > > > rcu_read_lock(); > > > > if (page_is_fake_head(page) || !page_ref_count(page)) { > > smp_mb(); // implied by atomic_add_unless() > > goto unlock; > > } > > > > rc =3D page_ref_add_unless(); > > > > unlock: > > rcu_read_unlock(); > > > > return rc; > > } > > > > And on the HVO/de-HOV sides: > > > > folio_ref_unfreeze(); > > synchronize_rcu(); > > HVO/de-HVO; > > > > I think this is a lot better than making tail page metadata RW because: > > 1. it helps debug, IMO, a lot; > > 2. I don't think HVO is the only one that needs this. > > > > David (we missed you in today's THP meeting), > > Sorry, I had a private meeting conflict :) > > > > > Please correct me if I'm wrong -- I think virtio-mem also suffers from > > the same problem when freeing offlined struct page, since I wasn't > > able to find anything that would prevent a **speculative** struct page > > walker from trying to access struct pages belonging to pages being > > concurrently offlined. > > virtio-mem does currently not yet optimize fake-offlined memory like HVO > would. So the only way we really remove "struct page" metadata is by > actually offlining+removing a complete Linux memory block, like ordinary > memory hotunplug would. > > It might be an interesting project to optimize "struct page" metadata > consumption for fake-offlined memory chunks within an online Linux > memory block. > > The biggest challenge might be interaction with memory hotplug, which > requires all "struct page" metadata to be allocated. So that would make > cases where virtio-mem hot-plugs a Linux memory block but keeps parts of > it fake-offline a bit more problematic to handle . > > In a world with memdesc this might all be nicer to handle I think :) > > > There is one possible interaction between virtio-mem and speculative > page references: all fake-offline chunks in a Linux memory block do have > on each page a refcount of 1 and PageOffline() set. When actually > offlining the Linux memory block to remove it, virtio-mem will drop that > reference during MEM_GOING_OFFLINE, such that memory offlining can > proceed (seeing refcount=3D=3D0 and PageOffline()). > > In virtio_mem_fake_offline_going_offline() we have: > > if (WARN_ON(!page_ref_dec_and_test(page))) > dump_page(page, "fake-offline page referenced"); > > which would trigger on a speculative reference. > > We never saw that trigger so far because quite a long time must have > passed ever since a page might have been part of the page cache / page > tables, before virtio-mem fake-offlined it (using alloc_contig_range()) > and the Linux memory block actually gets offlined. > > But yes, RCU (e.g., on the memory offlining path) would likely be the > right approach to make sure GUP-fast and the pagecache will no longer > grab this page by accident. > > > > > If this is true, we might want to map a "zero struct page" rather than > > leave a hole in vmemmap when offlining pages. And the logic on the hot > > removal side would be similar to that of HVO. > > Once virtio-mem would do something like HVO, yes. Right now virtio-mem > only removes struct-page metadata by removing/unplugging its owned Linux > memory blocks once they are fully "logically offline". > > -- > Cheers, > > David / dhildenb >