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 59F4E3D9033; Fri, 27 Feb 2026 05:31:56 +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=1772170321; cv=none; b=bhm8MwX08Rvu4JR4qrU3ADqfQ+7i9f+DCamT+ETUar7cfQwNYhniWW8guSriiZ+BVrjz8ehmHbYRCM7xrLhOyIxFWGBIl4zI0zEQIx2KWtTkRNb3zdcP8qdLeq4VHPF+JCyYC+84JRc31TZ/i7iH6FynsPB0n29bWFO+h5G4I84= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772170321; c=relaxed/simple; bh=JJJ/bYbNkDac/ehT2CwP9hIwHMml0HxDYqNBjEG8e60=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PJbdzBwqPP+tGWZJlz+/+lpd6d+Wm0CLF8CI75E0u/LyQQBMBQSBsfJ9PICUb01zd40BK3/qymXzkx7+yyFyS987DbjVP0bvCTPeE4F69HhWW4if1OVD73BTm8jC4Cbv8fZtHfkrSNONjE1CSQI/MzWZb7H2vz0kaqQzjVrVafg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=QoQW8FIZ; 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=none 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="QoQW8FIZ" 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=FdI6HWq7bYS4a7NgUV29xJjFEF3QDoxmr5mq72kvj4s=; b=QoQW8FIZjigY7J+JkTU/Wl3Na5 nL5dUjUVCoo21EvVW+az6uYqbCgt35JTky8ZJdW6Y/Ul1n7OlfpPsgc4S8nd2EO5Z9VtzILUjGGlV un+w6LmB6CgEeNLUSoWMVgMdB7SD5k78M184KJdDYJqtNrPsx0Ra6fK3EM8UHG0K2xWPHp4lH3Kxe fHK7Icq8qlLldjY6GvHZ7oWTwFEWCJmWotARFy6rsGEwXQRXqYi5phWN1Zcq886gJFhRfgkx96Wio 5HMt2/pzCGhXOz5SYMD6Ywk/fQfakIpYTrunRcNnSHocvyQUQo69ESCIQov85L36TubL1qODJUGRT L5fhs3Rg==; Received: from willy by casper.infradead.org with local (Exim 4.98.2 #2 (Red Hat Linux)) id 1vvqRu-0000000443b-2Uxl; Fri, 27 Feb 2026 05:31:38 +0000 Date: Fri, 27 Feb 2026 05:31:38 +0000 From: Matthew Wilcox To: Pankaj Raghav Cc: Suren Baghdasaryan , Mike Rapoport , David Hildenbrand , Ryan Roberts , Michal Hocko , Lance Yang , Lorenzo Stoakes , Baolin Wang , Dev Jain , Barry Song , Andrew Morton , Nico Pache , Zi Yan , Vlastimil Babka , "Liam R . Howlett" , Jens Axboe , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, mcgrof@kernel.org, gost.dev@samsung.com, kernel@pankajraghav.com, tytso@mit.edu Subject: Re: [RFC v2 0/3] Decoupling large folios dependency on THP Message-ID: References: <20251206030858.1418814-1-p.raghav@samsung.com> 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: <20251206030858.1418814-1-p.raghav@samsung.com> On Sat, Dec 06, 2025 at 04:08:55AM +0100, Pankaj Raghav wrote: > There are multiple solutions to solve this problem and this is one of > them with minimal changes. I plan on discussing possible other solutions > at the talk. Here's an argument. The one remaining caller of add_to_page_cache_lru() is ramfs_nommu_expand_for_mapping(). Attached is a patch which eliminates it ... but it doesn't compile because folio_split() is undefined on nommu. So either we need to reimplement all the good stuff that folio_split() does for us, or we need to make folio_split() available on nommu. fs/ramfs/file-nommu.c | 53 ++++++++++++++++---------------------------------- 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/fs/ramfs/file-nommu.c b/fs/ramfs/file-nommu.c index 0f8e838ece07..dd789e161720 100644 --- a/fs/ramfs/file-nommu.c +++ b/fs/ramfs/file-nommu.c @@ -61,8 +61,8 @@ const struct inode_operations ramfs_file_inode_operations = { */ int ramfs_nommu_expand_for_mapping(struct inode *inode, size_t newsize) { - unsigned long npages, xpages, loop; - struct page *pages; + unsigned long npages; + struct folio *folio; unsigned order; void *data; int ret; @@ -79,49 +79,30 @@ int ramfs_nommu_expand_for_mapping(struct inode *inode, size_t newsize) i_size_write(inode, newsize); - /* allocate enough contiguous pages to be able to satisfy the - * request */ - pages = alloc_pages(gfp, order); - if (!pages) + folio = folio_alloc(gfp, order); + if (!folio) return -ENOMEM; - /* split the high-order page into an array of single pages */ - xpages = 1UL << order; - npages = (newsize + PAGE_SIZE - 1) >> PAGE_SHIFT; - - split_page(pages, order); - - /* trim off any pages we don't actually require */ - for (loop = npages; loop < xpages; loop++) - __free_page(pages + loop); + ret = filemap_add_folio(inode->i_mapping, folio, 0, gfp); + if (ret < 0) + goto out; /* clear the memory we allocated */ + npages = (newsize + PAGE_SIZE - 1) >> PAGE_SHIFT; newsize = PAGE_SIZE * npages; - data = page_address(pages); + data = folio_address(folio); memset(data, 0, newsize); - /* attach all the pages to the inode's address space */ - for (loop = 0; loop < npages; loop++) { - struct page *page = pages + loop; - - ret = add_to_page_cache_lru(page, inode->i_mapping, loop, - gfp); - if (ret < 0) - goto add_error; - - /* prevent the page from being discarded on memory pressure */ - SetPageDirty(page); - SetPageUptodate(page); - - unlock_page(page); - put_page(page); - } + folio_mark_dirty(folio); + folio_mark_uptodate(folio); - return 0; + /* trim off any pages we don't actually require */ + if (!is_power_of_2(npages)) + folio_split(folio, 0, folio_page(folio, npages), NULL); + folio_unlock(folio); -add_error: - while (loop < npages) - __free_page(pages + loop++); +out: + folio_put(folio); return ret; }