From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) (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 53CCF408628 for ; Wed, 22 Jul 2026 07:46:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784706403; cv=none; b=aA+XAdF1L5kaY5DxdbmPG/6dgvPJMjiFJvtN1y7oDywRc+gpKwDiF8n8OB2OV2C8qPyJ7tQJXvlocyAwk/GTtBlTBgnZ9b/iIBqO6neKYW4/lS7cPTEGevgCdYKVbvYLCQOaHfkY3JkMraYSPUX1gO1mZpiRtm9XAE+LzZ8d8LA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784706403; c=relaxed/simple; bh=8km61hXCK1e+E/W/GBTLHFbLqZyrvREToRV7FKT8vdc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qGBWj0TxNfP2YIuXJHf/LaJ7XIwllWA79XZaTkuB/imPaugDI78e7DaOrWZsVu5f1dKJ0eD19FiZ/2DO79Em0vFfznO+GeZsWSTpaRUwCgY2pb5gGKTYoqWoOKFgXBeYQeL4T7nrvX8R0QYhO5rJZZPRyDE25XP9fjX4sZg9NrM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Lmaxkazs; arc=none smtp.client-ip=95.215.58.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Lmaxkazs" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784706399; 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=qttBPexa381gB8dNrmOWiqVVVFWZcu8GPXP1TDIp7Lk=; b=Lmaxkazs20TZza7wu/lmnoBZ1YnLuTHIn+G7+G4oew2pjz+cx04LjlaGEv0QjH3XlMJQ7j Tbbdl4zS3EvPNX+y5fAREB+TFdMKxR3zE3kMfEsqrs4gfd5PUdfzYiDXo5/upHQ7lEmfC+ XTvSBZfKPTwXHgC6pTxIi4ok10T+VjU= From: Hongfu Li To: willy@infradead.org Cc: akpm@linux-foundation.org, david@kernel.org, hongfu.li@linux.dev, liam@infradead.org, lihongfu@kylinos.cn, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ljs@kernel.org, mhocko@suse.com, rppt@kernel.org, surenb@google.com, vbabka@kernel.org Subject: Re: [PATCH] mm/memory: use folio lock/ref helpers in do_swap_page Date: Wed, 22 Jul 2026 15:46:25 +0800 Message-ID: <20260722074625.33547-1-hongfu.li@linux.dev> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT > > From: Hongfu Li > > > > Replace page-level lock/ref operations with their folio equivalents > > in the device_private migration path of do_swap_page(). > > When I do folio conversions, I like to mention the actual advantage > of the patch. Here, I'd say something like ... > > mm: Use a folio in the softleaf_is_device_private path > > Use the folio APIs, replacing four calls to compound_head() with one. Many thanks for your patient guidance. I will update the commit message per your suggestion for v2. > > Introduce a local fault_folio to hold page_folio(vmf->page) to avoid > > repeated page_folio() invocations. > > > > Signed-off-by: Hongfu Li > > --- > > mm/memory.c | 11 +++++++---- > > 1 file changed, 7 insertions(+), 4 deletions(-) > > > > diff --git a/mm/memory.c b/mm/memory.c > > index d5e87624f692..bd27372a1052 100644 > > --- a/mm/memory.c > > +++ b/mm/memory.c > > @@ -4852,6 +4852,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > > vmf->page = softleaf_to_page(entry); > > ret = remove_device_exclusive_entry(vmf); > > } else if (softleaf_is_device_private(entry)) { > > + struct folio *fault_folio; > > You can just use the existing 'folio' variable. > > Although this function is far too long (400 lines! 14 function-scope > variables!) so I don't blame you for not noticing that. Pulling a > do_non_swap_page() out of it might be a kindness. Thanks, will drop the local fault_folio and reuse the existing folio variable. This change will be included in v2. Agreed that we can split out helpers from do_swap_page, and I will add a new patch for this refactoring in v2. > > if (vmf->flags & FAULT_FLAG_VMA_LOCK) { > > /* > > * migrate_to_ram is not yet ready to operate > > @@ -4863,6 +4865,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > > } > > > > vmf->page = softleaf_to_page(entry); > > + fault_folio = page_folio(vmf->page); > > vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, > > vmf->address, &vmf->ptl); > > if (unlikely(!vmf->pte || > > @@ -4874,15 +4877,15 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > > * Get a page reference while we know the page can't be > > * freed. > > You should also replace 'page' with 'folio' here. Pages don't have > refcounts, folios do. Right, I'll update the comment to "folio" to match. Will include in v2. Best regards, Hongfu