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 6AA2DC2D0CD for ; Wed, 21 May 2025 13:32:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 07C6C6B0099; Wed, 21 May 2025 09:32:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 02A4C6B009A; Wed, 21 May 2025 09:32:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E36D66B009B; Wed, 21 May 2025 09:32:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C886F6B0099 for ; Wed, 21 May 2025 09:32:12 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6E54514046D for ; Wed, 21 May 2025 13:32:12 +0000 (UTC) X-FDA: 83467003704.01.789FF5F Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf07.hostedemail.com (Postfix) with ESMTP id 1F17840014 for ; Wed, 21 May 2025 13:32:09 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=lNBfg775; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="jE/36a9A"; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="V/XrrZNn"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Nz8vuZpn; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf07.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1747834330; a=rsa-sha256; cv=none; b=rfOIIqbnogLrtztOJ8yAR8g3qtVrlqCEpMNMOcEe+Z7rkcRQ0XMCngBp0zPcv9YmShbmas Qmvddfk2LfF+CAm9oN2bL+FEzCgkjHz8lyQP1MaAhILG/HMGMcyRENnPgRtlcBsmhQowce aGRr38jsbNK51dZHjQ0RVrO4Ddoqxzg= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=lNBfg775; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="jE/36a9A"; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="V/XrrZNn"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Nz8vuZpn; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf07.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1747834330; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nJNiWFvwBFXo0EFgpeAs+JtNoelOy/ITO4unDPZL+PA=; b=HfeFi2mO/krTuTcRl6bo6TLrMbFrxmNCEioHIeTPpV4d4dWPnBlbIL2JGNuWLXtW4b772J iypATuMIG7bCjNkcT5GjrWPSSKCsqso5gJWhAENZR3J3P5FQL1Dbs8Brqbi43zp3dTNw0k SLC0xyJ4roPZa5xaysghE30zHoVh474= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 36507337F6; Wed, 21 May 2025 13:32:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1747834328; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=nJNiWFvwBFXo0EFgpeAs+JtNoelOy/ITO4unDPZL+PA=; b=lNBfg775/t9gNMm5eTRzzTW+sNb7tz7wp7yW0g0+8vqYxIGpP5uzlYcDYe+EGtO/65iGp9 kKBwMQda0hoeUNOgWGwfH7goYzVhe6H33d93aJE622DgddU6VA6rQt1DJrmURm4zjc026d j1djAVUFx7yggtTOkivvRs0GmQOrJPg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1747834328; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=nJNiWFvwBFXo0EFgpeAs+JtNoelOy/ITO4unDPZL+PA=; b=jE/36a9AfJT+XI34M073LiBW6Wr36u0PLwAPrb1XWDevJuGzjWRH6rtPs9SUnLUSlzhBaX VAWeRJYRSKAXwTDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1747834327; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=nJNiWFvwBFXo0EFgpeAs+JtNoelOy/ITO4unDPZL+PA=; b=V/XrrZNnxUQRLPH4davKNb79TiSS68XnxISaOTfSAJu4XuXpZKXYlIR1N9FtqlRgXCDrAV wWabWoF/kG86xTsV0fO6y/pF5goyoV/mtGMJB/rBNXil2Jz7VGMf6UtGnYhOUW7Obo9qQA t1Bg5q2X9ognBjdvmLtUc3LQj6wOWFg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1747834327; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=nJNiWFvwBFXo0EFgpeAs+JtNoelOy/ITO4unDPZL+PA=; b=Nz8vuZpnKjOZxTTrwd6Y4POPElKu5cEifobVkDd5d92Za41tHQVUloJOcimO7bSWmtIYF3 L9hQ3GMPfIcTyfAA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id E634013888; Wed, 21 May 2025 13:32:06 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id xy1hN9bVLWi2BQAAD6G6ig (envelope-from ); Wed, 21 May 2025 13:32:06 +0000 Date: Wed, 21 May 2025 15:32:05 +0200 From: Oscar Salvador To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, virtualization@lists.linux.dev, "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , Eugenio =?iso-8859-1?Q?P=E9rez?= , Andrew Morton , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , "Matthew Wilcox (Oracle)" Subject: Re: [PATCH v2 1/1] mm/memory_hotplug: PG_offline_skippable for offlining memory blocks with PageOffline pages Message-ID: References: <20250520164216.866543-1-david@redhat.com> <20250520164216.866543-2-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250520164216.866543-2-david@redhat.com> X-Rspamd-Action: no action X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 1F17840014 X-Rspam-User: X-Stat-Signature: kurdrio9m1c1d8ij3sxoipde6px63d1f X-HE-Tag: 1747834329-288442 X-HE-Meta: U2F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yGo9DAYOlf12WH9nl10uySUzbMHcSgcI2ABAu3c9sizhoMUotLRzC//3J2Z4pxWZnT/7PiCAInpliRzUj66Y0gB2GcdXycRcPH98ASbuxoldKFKgwf824bxQo7ZXOJn0iU7zf0U8mCdARnFXkOmR142n0wbwr//RBNrkQK6HYLJMzqrkONHeY8C8RW4uWAMtVros1MHnfhAwmF1OnSVi6uhME+Jzimqn6fsS5q15Yfsb5MlCXC237ppblzeSTzpCr960EHLzTClrb0So0T3qSLYBo= 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 Tue, May 20, 2025 at 06:42:11PM +0200, David Hildenbrand wrote: > A long-term goal is supporting frozen PageOffline pages, and later > PageOffline pages that don't have a refcount at all. Some more work for > that is needed -- in particular around non-folio page migration and > memory ballooning drivers -- but let's start by handling PageOffline pages > that can be skipped during memory offlining differently. > > Note that PageOffline is used to mark pages that are logically offline > in an otherwise online memory block (e.g., 128 MiB). If a memory > block is offline, the memmap is considered compeltely uninitialized > and stale (see pfn_to_online_page()). > > Let's introduce a PageOffline specific page flag (PG_offline_skippable) > that for now reuses PG_owner_2. In the memdesc future, it will be one of > a small number of per-memdesc flags stored alongside the type. > > By setting PG_offline_skippable, a driver indicates that it can > restore the PageOffline state of these specific pages when re-onlining a > memory block: it knows that these pages are supposed to be PageOffline() > without the information in the vmemmap, so it can filter them out and > not expose them to the buddy -> they stay PageOffline(). > > While PG_offline_offlineable might be clearer, it is also super > confusing. Alternatives (PG_offline_sticky?) also don't quite feel right. > So let's use "skippable" for now. > > The flag is not supposed to be used for movable PageOffline pages as > used for balloon compaction; movable PageOffline() pages can simply be > migrated during the memory offlining stage, turning the migration > destination page PageOffline() and turning the migration source page > into a free buddy page. > > Let's convert the single user from our MEM_GOING_OFFLINE approach > to the new PG_offline_skippable approach: virtio-mem. Fortunately, > this simplifies the code quite a lot. The only corner case we have to > take care of is when force-unloading the virtio-mem driver: we have to > prevent partially-plugged memory blocks from getting offlined by > clearing PG_offline_skippable again. > > What if someone decides to grab a reference on these pages although they > really shouldn't? After all, we'll now keep the refcount at 1 (until we > can properly stop using the refcount completely). > > Well, less worse things will happen than would currently: currently, > if someone would grab a reference to these pages, in MEM_GOING_OFFLINE > we would run into the > if (WARN_ON(!page_ref_dec_and_test(page))) > dump_page(page, "fake-offline page referenced"); > > And once that unexpected reference would get dropped, we would end up > freeing that page to the buddy: ouch. > > Now, we'll allow for offlining that memory, and when that unexpected > reference would get dropped, we would not end up freeing that page to > the buddy. Once we have frozen PageOffline() pages, it will all get a > lot cleaner. > > Note that we didn't see the existing WARN_ON so far, because nobody > should ever be referencing such pages. > > An alternative might be to have another callback chain from memory hotplug > code, where a driver that owns that page could agree to skip the > PageOffline() page. However, we would have to repeatedly issue these > callbacks for individual PageOffline() pages, which does not sound > compelling. As we have spare bits, let's use this simpler approach for > now. > > Acked-by: Zi Yan > Signed-off-by: David Hildenbrand Hi David, sorry for jumping in late > @@ -1157,6 +1083,7 @@ static void virtio_mem_set_fake_offline(unsigned long pfn, > SetPageDirty(page); > else > __SetPageOffline(page); > + __SetPageOfflineSkippable(page); > VM_WARN_ON_ONCE(!PageOffline(page)); I think I am having some issues understanding this, let me see if I get it. - virtio-mem defines PageOffline pages, which are logically-offlined pages within an onlined memory-block - PageOffline pages have a refcount of '0' once they are properly initialized, meaning that refcount > 0 implies somebody is holding a refcount and that should not really happen - logically-offline pages belonging to onlined memory-blocks are marked PageDirty, while logically-offlined pages we allocated via alloc_contig_range are marked PageOffline (I am getting a bit lost between fake-online, fake-offline, my fault) - If we want to release logically-offline pages belonging to an onlined memory-block, we ClearDirty them and be done - If we want to release logically-offlined pages belonging we allocated via alloc_contig_range, we clear PageOffline and be done - PageOfflineSkipabble are unmovable PageOffline pages, which cannot be migrated? - So for a PageOffline to be able to be migrated away must be Movable or marked PageOfflineSkipabble, making do_migrate_range ignore it - PageOfflineSkipabble will be marked PageOffline upon re-onlining? Will still be marked as PageOfflineSkipabble? > + > + /* > + * Only PageOffline() pages that are marked "skippable" cannot > + * be migrated but can be skipped when offlining. See It is probably me, and nevermind the comment but I somehow find "PageOfflineSkipabble are not migrated but skipped when offlining" a bit easier. -- Oscar Salvador SUSE Labs