From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 DEE9C32E696 for ; Wed, 22 Jul 2026 01:25:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784683535; cv=none; b=n8Zr75NHErOlbdTME+vZXHAZXqV5pWUXzxmfVrdRkOACXHJY4jxuNhHwbplCTtgxUPfqula/AxRv2oogYytRWjli56wlSfWdMr4DlOU08G/88nZqjbXTxfGlj9Zf0f2cVPaKXmPpKgBjea3vd17aJxReUw6ZlXWI1s36dznphBw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784683535; c=relaxed/simple; bh=SbMw77qsltaI7kaNOIFhv2BGvf2sk8PD5wS3gRWgEbc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Qc9QYryWzwNvN5nDW4Fj6WsX9HgeLbQsxXiHtHa/fRAtRJ3BFLlUW5BKjZ8dwzKEJCz25eHXHMtyRLqmuGpAhnCAiUmoHOaiEDh5Ynw8nuieyEmUZqO6aQDqjP3dhg41vSJ6MraejRmp7N92YWPn5hHHLvNAINJiFz2upXNiBIA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=AH1yMPga; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="AH1yMPga" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=36tslyDQzMK9DRsSYiP8yJ4Xvp1NbiX3KOlD9FuNW60=; b=AH1yMPgaYJ/ZlOAHjTj5SGmh7I QiQZPsy3nXrc4392q/ZquqOfl0aVU6Ko0rQVoORy2IY2z19Pu2dOb28emR3YziOcDADlBvESUkhfD 9HetugUAak+A0Ym3QtekcB/rKxtjmMFrIsuSAnenmbmB69NthJDJIAlMf52LY9WhJbJerg0s9CMJT iEl2eMZ8e3Y44hF3e76KUH9yxeug+o2lzVqtFe8ydtwycPlZ3URwk0wnMpC9H2Tcmh9c27F0qB8oc KlySH53LQHX7UBUGPzmzlWoSbub5hynL2VqhyqOxOlL4ApsJEHm9micWfNF3bq2BEF9rM62KWBHBk gd00kk0w==; Received: from willy by casper.infradead.org with local (Exim 4.99.1 #2 (Red Hat Linux)) id 1wmLi5-0000000ERcV-1Heb; Wed, 22 Jul 2026 01:25:21 +0000 Date: Wed, 22 Jul 2026 02:25:21 +0100 From: Matthew Wilcox To: Hongfu Li Cc: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, liam@infradead.org, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Hongfu Li Subject: Re: [PATCH] mm/memory: use folio lock/ref helpers in do_swap_page Message-ID: References: <20260721013347.65698-1-hongfu.li@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260721013347.65698-1-hongfu.li@linux.dev> On Tue, Jul 21, 2026 at 09:33:47AM +0800, Hongfu Li wrote: > 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. > 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. > 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.