From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1D45C636CC for ; Wed, 8 Feb 2023 00:36:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E7A456B0078; Tue, 7 Feb 2023 19:36:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E2A3D6B007B; Tue, 7 Feb 2023 19:36:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF2256B007D; Tue, 7 Feb 2023 19:36:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C049F6B0078 for ; Tue, 7 Feb 2023 19:36:10 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 77344C0884 for ; Wed, 8 Feb 2023 00:36:10 +0000 (UTC) X-FDA: 80442257700.09.DC6FD6A Received: from mail-vs1-f51.google.com (mail-vs1-f51.google.com [209.85.217.51]) by imf01.hostedemail.com (Postfix) with ESMTP id C852A40013 for ; Wed, 8 Feb 2023 00:36:08 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=CE3PvRA9; spf=pass (imf01.hostedemail.com: domain of jthoughton@google.com designates 209.85.217.51 as permitted sender) smtp.mailfrom=jthoughton@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675816568; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=v7ujK7a9FENmlSmTH8+xS3B7GM+pD1VfdtdTiY5yUFg=; b=3/HYugJsliy9P97CLVTtNyn6pYhi6I0Z2t3venVUIurwrDSOn18Dqv83zWSkccFFzQKaYq qisZSlGryAqOKrZv9s/bV2Mp3aUpX/8wrOEZrtogBf7xJx9Iv2SeD7s37PE1HpsWuQDubU hTtkdkwMKZ4t2rRHmQhc+CJSBK++kFc= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=CE3PvRA9; spf=pass (imf01.hostedemail.com: domain of jthoughton@google.com designates 209.85.217.51 as permitted sender) smtp.mailfrom=jthoughton@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675816568; a=rsa-sha256; cv=none; b=yE5vzYTUOkBXq05ATmmWFVXpaotCFcnKJka8cPC+K+6boG2c9LcE8ZN2eCDfmozlGE0kU1 uH6kXAndj3MtuxeH62lVPl4NeDZv3JZKewIRvKZbJ1/HK6vGBApjJSlIGzumVU1iusLFn2 +ktVyvkLHhRRZGgR9my0q4o5BE4nEAk= Received: by mail-vs1-f51.google.com with SMTP id h19so18161202vsv.13 for ; Tue, 07 Feb 2023 16:36:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=v7ujK7a9FENmlSmTH8+xS3B7GM+pD1VfdtdTiY5yUFg=; b=CE3PvRA9Kir3gEaGFVyK6jm51X/YmaGKx5d8R2x2mtP0RFL7Z4oqM2fM/tNvh6zqCp XAM/6ysl9tGsBjPMxDUUQZQZa0ATiD3mDzwF+JE+yI4qZgZoJdy6Nbait4rZIeyfyE96 +HbKpnhAN/eOtDKAdQ2695VC23KmcS2y0Kf3vPMyEGnpNjIG9MbwPWvHa1ehhmtmdYXP Wo1KDjsrCutHwjRUkwi9047nGT5kKBSmwri2VkflZPTfSnaCorAV9b6S7gQnxPD+1362 va5FrksL9YyWlycDcqI4vU89WzgS38IKBKQTO6Kcl8JZY/5z0oZJhbIBlri0+pagL10l GDZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=v7ujK7a9FENmlSmTH8+xS3B7GM+pD1VfdtdTiY5yUFg=; b=26YtKodJlbkyZl5F1+oZgEfznaHG1CeUcMq9h7QxcIwrghFlN5Kj/S2fKfgW8G0ORN rkIfsN08viwbMXMtz9RjyVYu3gznjs1FOORipR6+6HKQWQILO5oZf9Y6ac8b1YxrlOjK inS+GanxItD9VuabynqQk1LTsel2rnffgYxW50ST/Qhsk42bLsnk2bdS2wLIYObLIptW 7RS6wFkyz1yzCapo7x7CV8b9FmvCZdRY/OFsu8ZVcXzOCAJR6oMWXJlEG74p1Go4NnLf AxrOxSpN4myvLv3h9AFace4VL5MbsDZaK6UhYVV7tSuffl3LGJ/ogZBr7sM+mVenlrTD 4/SA== X-Gm-Message-State: AO0yUKUpssk/Dawm9h4iWRAnqVN70AtU8HYZ+I+UoDVpXOGx4QNd+aZk DmzzpWOMpgIzZerPRiYbaM6eIFba3cvH8v1Rm86otg== X-Google-Smtp-Source: AK7set8GsOo3x3cjAqM0P3U5c1oUp939obeuXOavLISr2sddIHEkEmOwV8VxTCw8GZIJXpXoKfVMcTffWireunmh8Yc= X-Received: by 2002:a05:6102:304e:b0:3fc:58d:f90f with SMTP id w14-20020a056102304e00b003fc058df90fmr1391418vsa.60.1675816567844; Tue, 07 Feb 2023 16:36:07 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: James Houghton Date: Tue, 7 Feb 2023 16:35:30 -0800 Message-ID: Subject: Re: Folio mapcount To: Matthew Wilcox Cc: linux-mm@kvack.org, Vishal Moola , Hugh Dickins , Rik van Riel , David Hildenbrand , "Yin, Fengwei" Content-Type: text/plain; charset="UTF-8" X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 131s7586d38wp1sizemkhhmwger3ye77 X-Rspamd-Queue-Id: C852A40013 X-HE-Tag: 1675816568-712925 X-HE-Meta: U2FsdGVkX1+aqn+Ln+qTl9yM6yRUQV6XQu8ZX8qfdwE05XW+nItc4o5tRy8v1rRS4DPB/QJMaw46g4br0m3hQRMUxuSqFq9aUAkRr2d99ZaJ9tfX0CoOqb8umgANe62CmuEiWLYF+62d9MukEsfMgSMRUcKybq1qvyFbNb4nreegg1trHNeUgcleIakU8apqA7Xc+/V5BZjdYFSGVUbPoVSo/bdRNjyWa7ryl4g7uI5+lURR2W0Ln8AXjgSZvsUBw/aXujOPZVRmXs1rPWZvSy9C2/FrOIgkRRohiygy/NXBkIWtqvIefE7EFlR3QpxzzAZu5PK6vrjMJnAh/SCdlh8A16YrYnyjhLqyunHkMX157x+KOMS35siZwRZ87iO8enn/DKC3mzWIJFKzdmIG3FfpK3tBdZ4XZahgZmrJklCVKZr/Lkp2Pnn51z/kSVGe5YXqJPHj/G1+W/TCsMeqb94jSs6cY6AqoRdFZQgjXvEaQXp4tQr7yf7FRWd9NGGKKDcZJvwBJw84LSvLLTnUz6i088tZaQm8oC5fJ6bclOyaWHhD5BAxQmUnxvhNtoj60d59sWZUjVsVaOHy/BXsgyEhCjiQOW7cxe/y1z3jlnuBz0y9nShlNLd3IBS8k0ZtuOehkilWSPrin/TCtKj0E8Cd3i22VQq77aPmEhKiOY1vu7J83KZV/7qa/wsU130mMe2mO1cmCXfb0MFr9l3tAzhp8fYeqULgP6tIp23L4lGJy5xqDJu2uVvZulI9x5Kzpg3HIdZDnMdzrrUZoBhVk62Jnsn3/0ZdUygipQB34cN36oVy36pDczQtoxgD1Er9iTevrbagWZ4akzSkupMTt3MI7dCBTxbkfKpNUTsq35NpV2JlU8aB1T3Tk0FdNDla6qAj9FGuC8WOoVH59DUf5q0+Ic9ow1gph/djr5UTYG9jYj6EGL+FYfBRfXz5wCenILOwSdwHcAUFhD1AAer 8bdahOew HtyhcHX/SvRO3qJe9WkbVrzhG0ea1iydRpXHKHCFIOTjAd40U+Zm6RJgNZKbewz05zrU9R0qdAqbGQ02pFXU+b1T0AqWyfHQ/yAr93xs1oJst3/zEoEWu6fRbi66ZzbouJKQahe+KI9oBcJeSCtuud9GHfCQxmwP7BEndE8kpqyQcb9uHtFZ6lp6FKImpiF87exUWVN/CWj2q8Fj/nkEknPKWQWTWyfKEUBXGS2fqxs2q+R9pONTK4P39lZlbYpJmhKwHTEnLzpSgDtR+WpYVZQBCUfpkUDGuKD7sbXsUHYMIa5I5FenPc4RHH8HN7Phic7+FxpPFfMhLhcWCc6RoWb6djAFqQA5Wg2SVs1iNh45ih+RRpQcu+E4lNg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Feb 7, 2023 at 3:35 PM Matthew Wilcox wrote: > > On Tue, Feb 07, 2023 at 03:27:07PM -0800, James Houghton wrote: > > So page_vma_mapped_walk() might have to walk up to HPAGE_PMD_NR-ish > > PTEs (if we find a bunch of pte_none() PTEs). Just curious, could that > > be any slower than what we currently do (like, incrementing up to > > HPAGE_PMD_NR-ish subpage mapcounts)? Or is it not a concern? > > I think it's faster. Both of these operations work on folio_nr_pages() > entries ... but a page table is 8 bytes and a struct page is 64 bytes. > From a CPU prefetching point of view, they're both linear scans, but > PTEs are 8 times denser. > > The other factor to consider is how often we do each of these operations. > Mapping a folio happens ~once per call to mmap() (even though it's delayed > until page fault time). Querying folio_total_mapcount() happens ... less > often, I think? Both are going to be quite rare since generally we map > the entire folio at once. Maybe this is a case where we would see a regression: doing PAGE_SIZE UFFDIO_CONTINUEs on a THP. Worst case, go from the end of the THP to the beginning (ending up with a PTE-mapped THP at the end). For the i'th PTE we map / i'th UFFDIO_CONTINUE, we have to check `folio_nr_pages() - i` PTEs (for most of the iterations anyway). Seems like this scales with the square of the size of the folio, so this approach would be kind of a non-starter for HugeTLB (with high-granularity mapping), I think. This example isn't completely contrived: if we did post-copy live migration with userfaultfd, we might end up doing something like this. I'm curious what you think. :) - James