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 37D64C3DA6D for ; Fri, 23 May 2025 09:20:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ADBE76B00D1; Fri, 23 May 2025 05:20:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A8C6B6B00D2; Fri, 23 May 2025 05:20:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 953D16B00D3; Fri, 23 May 2025 05:20:41 -0400 (EDT) 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 74AD56B00D1 for ; Fri, 23 May 2025 05:20:41 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D6417121DE5 for ; Fri, 23 May 2025 09:20:40 +0000 (UTC) X-FDA: 83473627440.19.29CE3D1 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf12.hostedemail.com (Postfix) with ESMTP id CA8FD4000A for ; Fri, 23 May 2025 09:20:38 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=YN0IA3On; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=cBR3AZxY; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=YN0IA3On; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=cBR3AZxY; spf=pass (imf12.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1747992039; 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=HhocMSSXD2Ob4YbeI+06yEIZuiMpJcrclTZN4rAvaTA=; b=FuDfPZRsTMG0XrGpzQkZr+wGFi0DIre5WLHKc+tV8HZVor/ZyYl8pnbrj6QbPMtMQe8+Gh ukFfAUvBKIrVZjKoI0fRS5uozZEUEBHsd+ryuiQdYMcwjVFsN81Mo0oz2EDWZ0sgzYQkop QQ//6ArOM2URg9sGAD3O97elq+bm39o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1747992039; a=rsa-sha256; cv=none; b=ry3Tqzd9g5masbeCJ1meayX9P8gqQib3b7APBZEUkyOBVkvpbbtD7O6RybUBJAyBF3D0z3 HIweScOrHFXGuKpgEShlnscK2ka3lJaA0WHahiviNq4HGwyX+NdD0YwWLO2cP/WcyRqUTE p9yUo9uMbBhEwGRPIe/huyzx14Kc+eU= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=YN0IA3On; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=cBR3AZxY; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=YN0IA3On; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=cBR3AZxY; spf=pass (imf12.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de 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-out2.suse.de (Postfix) with ESMTPS id 52AB21F821; Fri, 23 May 2025 09:20:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1747992037; 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=HhocMSSXD2Ob4YbeI+06yEIZuiMpJcrclTZN4rAvaTA=; b=YN0IA3OnH294PXpXi5dDe00kzw9uu8MzxlzJIvvIMeAdWoZoHcJjpDqTzW7DGsgNUeWcOY l7CxoxCrx05CHkag6MSt2bg+6w5w72IqBq4i9LC2zk6D+yqQ9GRzmmvIM+nWpnsz8siHe9 ByI9YP/xomosUoLSK+5I96RpDViYEyo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1747992037; 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=HhocMSSXD2Ob4YbeI+06yEIZuiMpJcrclTZN4rAvaTA=; b=cBR3AZxYlhc0linbdmpXVLkmWYbFS3BRxGGCGZ6LxeHg7U9Jk0E4DNj+m90tV5Fe7bapOD VocegoYBxStLaLCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1747992037; 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=HhocMSSXD2Ob4YbeI+06yEIZuiMpJcrclTZN4rAvaTA=; b=YN0IA3OnH294PXpXi5dDe00kzw9uu8MzxlzJIvvIMeAdWoZoHcJjpDqTzW7DGsgNUeWcOY l7CxoxCrx05CHkag6MSt2bg+6w5w72IqBq4i9LC2zk6D+yqQ9GRzmmvIM+nWpnsz8siHe9 ByI9YP/xomosUoLSK+5I96RpDViYEyo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1747992037; 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=HhocMSSXD2Ob4YbeI+06yEIZuiMpJcrclTZN4rAvaTA=; b=cBR3AZxYlhc0linbdmpXVLkmWYbFS3BRxGGCGZ6LxeHg7U9Jk0E4DNj+m90tV5Fe7bapOD VocegoYBxStLaLCA== 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 691E2137B8; Fri, 23 May 2025 09:20:36 +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 q32/FuQ9MGjqPQAAD6G6ig (envelope-from ); Fri, 23 May 2025 09:20:36 +0000 Date: Fri, 23 May 2025 11:20:34 +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: rspam06 X-Rspamd-Queue-Id: CA8FD4000A X-Stat-Signature: akg43x7qypj9nd8tx71wcrczgfr33jht X-Rspam-User: X-HE-Tag: 1747992038-398333 X-HE-Meta: U2FsdGVkX19/+foBHVHv99N8aLRaBDMZ3fjQ+sCWdlfc2MXnQ9lQEhsYy1eZwwphyfT8oh822CIw5fCnaaJP9TX3jouW/+3BoP3Tur5i85ycWE+/TEr1j7q+RUTV7h2MCUQe/i2Fou2ZD0qURUwirxqsybFVOPHAxBUHhBC32Oxz4BTL3etv4gzvnrhJDCKDUB5lcyGhxhL/5zPnJ5YXH2vjd9bBwaKFCnx972ZdupnEwZJIAVTmIYSKhP0u90pKkqrx0/TzpVIyrgZKyftPF3wIrQTn7Y+cl/B9GIv1a/1E5hTBvsQtTZ7nhdmTTZLI4eagTlrtGGBMyOVeb+/JW/1sBprM/WaUR3lS17D75SfT+VFUUqyVOoh7wO3aslbhTNqCWNOnRbL/mB3fkakvOcc5BkYgI9jB7ofz8+fpghxPRyJ09wH8aG8dEFbRrwYkSZg1IZc2UychRD7cTszb+ol3BQ2FFjYaegYQbNLZzxUg6PsBAjRa4rH2QC+yHuUqxHnCOMyekRJHPiNJTtsvm6A/9+5Fqiny6jFbS3iOoBuNQtIRke+tHwCafASdduBTQX8+UdcHpwePxVUh2DOAGQROLwoWCEuGf/nuelpSLkwKoUXP6dqURoE4x97UvfimkVDbB83egvuOzNHepm7jG35csWW6AIkNpv7JrfCeuP9JdugigQVTc0DG2duYL5YmU/aH0ZR4PdYCFNSpj+7xbgQxvNxUIHTjwT+WGSTrK4GAkBPFK3JMHC8CfowinmhtHOjqqS36WYte4UTo5E4OVuPcKxVjp9lDfi2Ptlf56H7/geZNsFUC9bWVav5VIPGmml8x2+SqMh1z2rYTOMecPcj7sstOdx15KX6mLK2q3tZrDkXkB2nWAUtsjvBmd9e1mUb72hBjWPS/P/wvk9h1EiPec7gaeEPTHjc2kDG7dHLxDp/LAQuy3TlisYJtAYqOYe+YqS4CIHxHGLsoBli 0AQ== 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 Acked-by: Oscar Salvador -- Oscar Salvador SUSE Labs