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 BF38825A631 for ; Tue, 1 Jul 2025 07:58:16 +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=1751356699; cv=none; b=fVSXHCPZ/Tyyj1t2Xc1juHKPL76y3+08Burb7oGYkrdfFUrTuBBixUIWayC/NpEjTqsWfCLLzj0hexF1gl6pnPHYm+/GfCOus4Lsf1BDCvCz97sqAMFHxVg70mRmxntBCsyFt0wFXNiW747wQE5uN/c4Ifrp1sC6IxXbiKPtLvU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751356699; c=relaxed/simple; bh=EkxLnWK+KNQPvO+XPa/qISs0wqev8VlQsQoVXc69XRA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=uWSCXwRQdXiycuL2F57QM6ZVQ+9IknlAtL2PLOtHE6/5jYC4nH9IoFozM28ffUXhD//LiHXFzWuzDEWO6wy1EVsxtdrKNkaEfGL4XysQ1i64uOC2hHlqVpy4DY/eUa/5l45DCgIDjJloon+D9JDUi99l4qdQINsRpMU9WSq0QbQ= 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=Tvp18pRn; 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="Tvp18pRn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751356695; 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:autocrypt:autocrypt; bh=/Feq4JYZa9imSCNgZMBn1vPhrRu0fqByvVFyCsbFbfo=; b=Tvp18pRnrfrSiRzNfZY2JgzOhWD4f4I9MS20zJ0FzVOOPWoXG1aDk7mkWfgg2qiDJ5KZkv yaSHQQCvo5Nx7z7z9t8Cc28R++wH974c7XRTXd8/g3NyOwp8GrkSScA2nTKD7h/YhIGnER 12kccKaHYw1oFGhJYghMXwfltuRymAw= 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-479-9BV7TNUrP-yhTxiP7vl27Q-1; Tue, 01 Jul 2025 03:58:14 -0400 X-MC-Unique: 9BV7TNUrP-yhTxiP7vl27Q-1 X-Mimecast-MFC-AGG-ID: 9BV7TNUrP-yhTxiP7vl27Q_1751356693 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3a4eb6fcd88so2235827f8f.1 for ; Tue, 01 Jul 2025 00:58:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751356693; x=1751961493; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=/Feq4JYZa9imSCNgZMBn1vPhrRu0fqByvVFyCsbFbfo=; b=J4bZAbeu8PGKKFhkc8yPv2oQWtXSByL9SIcAnlciIEUutiJEulr6IFIYkxiVW21Np5 8EK6ywB5o4fd6nCgCyLNqxvGdVkUrSR287MXFVXxys1br5AxV7f0GCDkoGqRwIUwKzqF YaRXnQ+gA4QzFuSN6h4pMiM+lMfh8bi1yMQr899XH3nLkDcjPKqKSSPchNu8XprIMO0Q JbyscwRDjnhSewEdc5pQqiAsrzTq+vL/CiRGairWIzaUhvG3LclpwSwyYscv/38olIBz bkir+UsWz+Cd4y9x4BmMZmuPAmUhbN6WfkoxRig0+NpxL5I6aQdd3SaZ3JfPd8r64+3Q frcQ== X-Forwarded-Encrypted: i=1; AJvYcCWc1eVIXLNalrPKRYRHOr1aEu0eki+zBe4ttnZbIjhHd1slpPVC0KptSDh9krjD6K1qId+3DnE9lJM=@vger.kernel.org X-Gm-Message-State: AOJu0YyRZHz9+mDSSF8jWLkCVS0j4dxj0/wvxHXlVYM3ejtzqa0y3V+Q Cj7wKKsoAbrIpIdIG+7NRXrLD582YgzsIOBFScoJluNCA4EI3k8IX3KErnmRTRSPchNyzsDLshf PVQutSekzZhniHXiA2QcAauLjfFZv/9OPxmNJs0UWhkTY3qlU9I0MaJrkWGqVaA== X-Gm-Gg: ASbGncuV06mmqIgJdytWN8rH5ShN4fv3lb4aEmQUFiuSt6ecgCplbACc9J4rvsSLvA8 6/pKFSDKDHtMgTbkQuMhzOF596LZVRUEEPNXPiMUT3lHLr6gZnAs2hIR4edNNmQWPB3vOx17bJs XQ6RRGq5gxVbXIIED3VdF/MyAs7yEucJN3EWk2amyOjBVA8MdOMdcRlQIzYV5SecFA+454fn+YP hTCSftd319WsdbPzbu1eapP5X2dRF+7GDzda20vwBsyb1Czz7AacRLqEEHx9UnXMdtujRnEbIQu jaR7X7XRY4py5bEc/C1/cXoucB8a/iVCqGcXb16ESQJsgivSNccZFMZx9LnQXgfTn6nR4Je78FR Cq5ZOBNHgZ1VH94M4D1rFdzzIsuhXptLKifG38PDonb0PYO0mrg== X-Received: by 2002:a05:6000:64b:b0:3a6:d5fd:4687 with SMTP id ffacd0b85a97d-3a8f482bd31mr13154737f8f.18.1751356693308; Tue, 01 Jul 2025 00:58:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGjMbemhkIZeoSup+OwONMSvz50yZg2K0dN6tNDQHYUqndeAp7nP+ltTQxgNLFcEg/amFhAAA== X-Received: by 2002:a05:6000:64b:b0:3a6:d5fd:4687 with SMTP id ffacd0b85a97d-3a8f482bd31mr13154650f8f.18.1751356692689; Tue, 01 Jul 2025 00:58:12 -0700 (PDT) Received: from ?IPV6:2003:d8:2f18:7500:202e:b0f1:76d6:f9af? (p200300d82f187500202eb0f176d6f9af.dip0.t-ipconnect.de. [2003:d8:2f18:7500:202e:b0f1:76d6:f9af]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a88c7e72c1sm12366971f8f.1.2025.07.01.00.58.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Jul 2025 00:58:11 -0700 (PDT) Message-ID: <277e094d-b159-411f-940d-13b62493f6c5@redhat.com> Date: Tue, 1 Jul 2025 09:58:09 +0200 Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 02/29] mm/balloon_compaction: convert balloon_page_delete() to balloon_page_finalize() To: Lorenzo Stoakes Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, virtualization@lists.linux.dev, linux-fsdevel@vger.kernel.org, Andrew Morton , Jonathan Corbet , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Jerrin Shaji George , Arnd Bergmann , Greg Kroah-Hartman , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?UTF-8?Q?Eugenio_P=C3=A9rez?= , Alexander Viro , Christian Brauner , Jan Kara , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , "Matthew Wilcox (Oracle)" , Minchan Kim , Sergey Senozhatsky , Brendan Jackman , Johannes Weiner , Jason Gunthorpe , John Hubbard , Peter Xu , Xu Xin , Chengming Zhou , Miaohe Lin , Naoya Horiguchi , Oscar Salvador , Rik van Riel , Harry Yoo , Qi Zheng , Shakeel Butt References: <20250630130011.330477-1-david@redhat.com> <20250630130011.330477-3-david@redhat.com> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABzSREYXZpZCBIaWxk ZW5icmFuZCA8ZGF2aWRAcmVkaGF0LmNvb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DHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 30.06.25 17:15, Lorenzo Stoakes wrote: > On Mon, Jun 30, 2025 at 02:59:43PM +0200, David Hildenbrand wrote: >> Let's move the removal of the page from the balloon list into the single >> caller, to remove the dependency on the PG_isolated flag and clarify >> locking requirements. >> >> We'll shuffle the operations a bit such that they logically make more sense >> (e.g., remove from the list before clearing flags). >> >> In balloon migration functions we can now move the balloon_page_finalize() >> out of the balloon lock and perform the finalization just before dropping >> the balloon reference. >> >> Document that the page lock is currently required when modifying the >> movability aspects of a page; hopefully we can soon decouple this from the >> page lock. >> >> Signed-off-by: David Hildenbrand >> --- >> arch/powerpc/platforms/pseries/cmm.c | 2 +- >> drivers/misc/vmw_balloon.c | 3 +- >> drivers/virtio/virtio_balloon.c | 4 +-- >> include/linux/balloon_compaction.h | 43 +++++++++++----------------- >> mm/balloon_compaction.c | 3 +- >> 5 files changed, 21 insertions(+), 34 deletions(-) >> >> diff --git a/arch/powerpc/platforms/pseries/cmm.c b/arch/powerpc/platforms/pseries/cmm.c >> index 5f4037c1d7fe8..5e0a718d1be7b 100644 >> --- a/arch/powerpc/platforms/pseries/cmm.c >> +++ b/arch/powerpc/platforms/pseries/cmm.c >> @@ -532,7 +532,6 @@ static int cmm_migratepage(struct balloon_dev_info *b_dev_info, >> >> spin_lock_irqsave(&b_dev_info->pages_lock, flags); >> balloon_page_insert(b_dev_info, newpage); >> - balloon_page_delete(page); > Hi Lorenzo, as always, thanks for the detailed review! > We seem to just be removing this and not replacing with finalize, is this right? See below. > >> b_dev_info->isolated_pages--; >> spin_unlock_irqrestore(&b_dev_info->pages_lock, flags); >> >> @@ -542,6 +541,7 @@ static int cmm_migratepage(struct balloon_dev_info *b_dev_info, >> */ >> plpar_page_set_active(page); >> >> + balloon_page_finalize(page); ^ here it is, next to the put_page() just like for the other cases. Or did you mean something else? >> /* balloon page list reference */ >> put_page(page); >> >> diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c >> index c817d8c216413..6653fc53c951c 100644 >> --- a/drivers/misc/vmw_balloon.c >> +++ b/drivers/misc/vmw_balloon.c >> @@ -1778,8 +1778,7 @@ static int vmballoon_migratepage(struct balloon_dev_info *b_dev_info, >> * @pages_lock . We keep holding @comm_lock since we will need it in a >> * second. >> */ >> - balloon_page_delete(page); >> - >> + balloon_page_finalize(page); >> put_page(page); >> [...] >> -/* >> - * balloon_page_delete - delete a page from balloon's page list and clear >> - * the page->private assignement accordingly. >> - * @page : page to be released from balloon's page list >> - * >> - * Caller must ensure the page is locked and the spin_lock protecting balloon >> - * pages list is held before deleting a page from the balloon device. >> - */ >> -static inline void balloon_page_delete(struct page *page) >> -{ >> - __ClearPageOffline(page); >> - __ClearPageMovable(page); >> - set_page_private(page, 0); >> - /* >> - * No touch page.lru field once @page has been isolated >> - * because VM is using the field. >> - */ >> - if (!PageIsolated(page)) >> - list_del(&page->lru); > > I don't see this check elsewhere, is it because, as per the 1/xx of this series, > because by the time we do the finalize balloon_page_delete() was used on two paths 1) Removing a page from the balloon for deflation through balloon_page_list_dequeue() 2) Removing an isolated page from the balloon for migration in the per-driver migration handlers. Isolated pages were already removed from the balloon list during ... isolation. With this change, 1) does the list_del(&page->lru) manually and 2) only calls balloon_page_finalize(). During 1) the same reasoning as in 1/xx applies: isolated pages cannot be in the balloon list. > >> -} >> - >> /* >> * balloon_page_device - get the b_dev_info descriptor for the balloon device >> * that enqueues the given page. >> @@ -141,12 +120,6 @@ static inline void balloon_page_insert(struct balloon_dev_info *balloon, >> list_add(&page->lru, &balloon->pages); >> } >> >> -static inline void balloon_page_delete(struct page *page) >> -{ >> - __ClearPageOffline(page); >> - list_del(&page->lru); >> -} >> - >> static inline gfp_t balloon_mapping_gfp_mask(void) >> { >> return GFP_HIGHUSER; >> @@ -154,6 +127,22 @@ static inline gfp_t balloon_mapping_gfp_mask(void) >> >> #endif /* CONFIG_BALLOON_COMPACTION */ >> >> +/* >> + * balloon_page_finalize - prepare a balloon page that was removed from the >> + * balloon list for release to the page allocator >> + * @page: page to be released to the page allocator >> + * >> + * Caller must ensure that the page is locked. > > Can we assert this? We could, but I'm planning on removing the page lock next (see patch description), so not too keen to create more code around that. Maybe mention that the balloon lock should not be held? Not a limitation. It could be called with it, just not a requirement today. I suspect that once we remove the page lock, that we might use the balloon lock and rework balloon_page_migrate() to take the lock. TBD. > >> + */ >> +static inline void balloon_page_finalize(struct page *page) >> +{ >> + if (IS_ENABLED(CONFIG_BALLOON_COMPACTION)) { >> + __ClearPageMovable(page); >> + set_page_private(page, 0); >> + } > > Why do we check this? Is this function called from anywhere where that config won't be set? Sure. balloon_page_list_dequeue() is called from balloon_page_dequeue(), which resides outside the CONFIG_BALLOON_COMPACTION ifdef in mm/balloon_compaction.c. At some point (not in this series) we should probably rename balloon_compaction.c -> balloon.c To match CONFIG_MEMORY_BALLOON. Because the compaction part is just one extra bit in there. (an important one, but still, you can use the balloon infrastructure without compaction/page migration) -- Cheers, David / dhildenb