From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (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 EAF60372045 for ; Wed, 29 Jul 2026 03:04:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=96.67.55.147 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785294258; cv=none; b=hlbTnsc5r9JwC2bdh/nJUn5y62p9sxD4ggriGr1geGr3X3F/JX4pN0/LbU0/apWzsBjEm2vEQsX4InDahkm45yNPxdt0BmS12LFpPAM0kNtNlEFXq/FvATU9UbCyWy/pwDDB0VoOZCVuOkEChzlPkf4GDQlhFY9/n1ub4/9xCpo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785294258; c=relaxed/simple; bh=YHJz4Ht7G8I0qF52s9KqH3nYHgOx4m92nEKKjmaGcsQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=GtgTPnfAnxkCJyma94NAUyXIduA58DL05bdw7DFCwAQjDq/8Yd7rAb9PIL+anfqEOrHwXhSIx6DUHKn87gp4uZM8jArv+ixubXbqnAC32lqP330AIWOisWQNCmIbNo/Q8bpaYVJVOhRF/iKxvW//aN4nxT0dBEnlZqOQ0yCGWmA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=surriel.com; spf=pass smtp.mailfrom=surriel.com; dkim=pass (2048-bit key) header.d=surriel.com header.i=@surriel.com header.b=Mt6wKT3u; arc=none smtp.client-ip=96.67.55.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=surriel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=surriel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=surriel.com header.i=@surriel.com header.b="Mt6wKT3u" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=surriel.com ; s=mail; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=uAp8TPXhJPKqj3Jc2wCbwH1PXdxv3Tg+ZGuEgVhC6ZI=; b=Mt6wKT3uBOGbWaiKfaex8a8E6d vsRF8RqiFxnDs4fOoYTeQGJOPye5nr2FrImDER/mv9O2wXbYgqkcUSzq5+Nlp/9e3THhzGXofPWqj LxqfBLTMaOQ4LAtKJyu4uF6uABwjgV6fgYrdRIFg74rzmgxvBY9vZqs8g31N+os8q/qORqW6f+WO5 lzNLq+64FPa+nivY4TtY0SHc39hBKlAxniNXO7lBZEtZokeyZPjKdqCpdFJx40URw9fZYZXKbP9/m vcjJscHKCWFYQdtdJzyaAXtrfSu9X1a+OVg3iQIum9XMx2gzu3G9HNvtfYUDTPsD5ho9Gw+Tg8zP0 IZiKPXNg==; Received: from fangorn.home.surriel.com ([10.0.13.7]) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1wouZ2-000000004ml-0DCg; Tue, 28 Jul 2026 23:02:36 -0400 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: Rik van Riel , Andrew Morton , linux-mm@kvack.org, Dave Hansen , Peter Zijlstra , Suren Baghdasaryan , Lorenzo Stoakes , Vlastimil Babka , David Hildenbrand , "Liam R. Howlett" , Mike Rapoport , Michal Hocko , Jason Gunthorpe , John Hubbard , Peter Xu , Matthew Wilcox , Usama Arif , kernel-team@meta.com Subject: [PATCH 0/2] mm/gup: batch PTE-mapped large folios in follow_page_mask() Date: Tue, 28 Jul 2026 23:02:32 -0400 Message-ID: <20260729030234.2063885-1-riel@surriel.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit follow_page_mask() reports the size of the page it found with a page_mask: a bitmask of the enclosing naturally-aligned huge page. That form can only describe a power-of-two block aligned to its own size, so a PTE-mapped large folio (mTHP) is walked one page at a time even though it maps a contiguous run, while the PMD/PUD-mapped cases already return their whole mapping in one step. Patch 1 replaces the page_mask output with nr_pages (a plain count) and adds an @end argument bounding the walk, with no functional change: the huge PMD/PUD paths report the same stride as before, just as a count. Patch 2 uses the new interface to batch the PTE case: follow_pte_batch() counts consecutive present PTEs that map consecutive pages of the same folio with a uniform write bit, bounded by the page table, @end, the VMA, and the folio itself, then follow_page_pte() hands the whole run back in one call. Measured with mm/gup_test.c (PIN_LONGTERM_BENCHMARK, the slow pin_user_pages() path) on a 256 MB MADV_HUGEPAGE anonymous region in a 4 CPU VM, median get time over 16 iterations. Each folio size was confirmed through the per-size anon_fault_alloc counters (4096 folios for 64 kB, 128 for 2 MB): gup_test -L -m 256 -n 65536 -r 16 -t before after 64 kB mTHP 3140 us 412 us (7.6x) 2 MB THP (control) 78 us 76 us 4 kB base (control) 3010 us 3042 us The PMD-mapped 2 MB THP already returns the whole mapping in one step, so it stays fast and unchanged. The 4 kB baseline shows the per-page walk cost that the 64 kB case paid before this change; only the PTE-mapped large folio case improves. Both patches apply standalone against mm-unstable; no other series is required. Rik van Riel (2): mm/gup: pass an end address to follow_page_mask() and return a page count mm/gup: batch contiguous PTE-mapped large folios in follow_page_mask() mm/gup.c | 139 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 97 insertions(+), 42 deletions(-) base-commit: 7368ccdeff50c27809d3a8276c85bae7e402c96c --- Cc: Andrew Morton Cc: linux-mm@kvack.org To: linux-kernel@vger.kernel.org Cc: Dave Hansen Cc: Peter Zijlstra Cc: Suren Baghdasaryan Cc: Lorenzo Stoakes Cc: Vlastimil Babka Cc: David Hildenbrand Cc: "Liam R. Howlett" Cc: Mike Rapoport Cc: Michal Hocko Cc: Jason Gunthorpe Cc: John Hubbard Cc: Peter Xu Cc: Matthew Wilcox Cc: Usama Arif Cc: Rik van Riel Cc: kernel-team@meta.com -- 2.53.0-Meta