From patchwork Thu Apr 15 18:47:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Rasmussen X-Patchwork-Id: 12205969 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-21.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D4B5C43460 for ; Thu, 15 Apr 2021 18:47:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D64826137D for ; Thu, 15 Apr 2021 18:47:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D64826137D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 485566B0036; Thu, 15 Apr 2021 14:47:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 422996B006C; Thu, 15 Apr 2021 14:47:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 29CAD6B0070; Thu, 15 Apr 2021 14:47:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0169.hostedemail.com [216.40.44.169]) by kanga.kvack.org (Postfix) with ESMTP id 0C1846B0036 for ; Thu, 15 Apr 2021 14:47:38 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 6D257362E for ; Thu, 15 Apr 2021 18:47:37 +0000 (UTC) X-FDA: 78035484954.37.EC5D701 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf14.hostedemail.com (Postfix) with ESMTP id 4AFF0C0007E7 for ; Thu, 15 Apr 2021 18:47:28 +0000 (UTC) Received: by mail-yb1-f202.google.com with SMTP id e185so3457740ybf.4 for ; Thu, 15 Apr 2021 11:47:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=HOv3LI0amuLnu16Azoij1WiD0ahUGLpZta25xI8mbb4=; b=K+sh8JarhAxis1EkzesQd7EqJyIE6gNyonS8n+ov71E2StwoJ8B2pEj16zjFHpwi1E 6ZAXgOWIG7qs+YTeFn5TiDMqbmrPXVBrmzi2XdQAiFUbT8uHoz5txjNNWW8uyU3J8lus On8DVQ2eOOh4iDqFWQAbUMCGlvMVGNByIOkjFT7OrsMo31nByw19h2IPOnHfowP614H0 56XU7arD5SCK6pNUkw+NXtNCVLWfltQxlouDjl4qsSmZLXSNNbfUSW5CVOq7Cr6YVHh9 XyMXJcn6JsBiQzG3cSNimz3DHSZ0uRHsh+jAsxeSvzJSp8ycAdNi5eVAogPRcnD46KBD sdqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=HOv3LI0amuLnu16Azoij1WiD0ahUGLpZta25xI8mbb4=; b=MB7ov1zs8Cl0G57kte3p74728eld6pAO+OsEUGBUM6ME+zd6LMoCjk15RBnJOHsqIh RnczBb5aAXt8XTxQQU3kI9QII5t/4wVNodxxawbvLG0UI5hDOcPUMjOWBI3x/FAh7HUN lPFn8sadyWh89VAWNufrau4S3vajOLqkrSoBE6fcnJYxcSTSUs7Wg/lE8mwgnLpkxqGv UCaWmi7j+4Vqi678QItbuPf1Utf1Lj8toQUX4AYXr9ANKi6zk+80GyGv3Uj4z7NVvx5G PPeDyMSAig9FZbV9+PeUkQFHq278rW96ktdyWcR+3/m9JBDMN51anUklbyrbVNFbOD0K jKDw== X-Gm-Message-State: AOAM531r1umBBX4GoDjwYBrGSkurbNq/rvrux02pl4ih8i6zKrbSHIaC 1PTpY7t0g8vUVeI3qel12BUMjgqihzRk4lHm/FdY X-Google-Smtp-Source: ABdhPJzoNSXv2urXx3peba3eorPfVQfJb4ZTqrlOnBXFac83aVKjuHsYFDHRRJKeqOVJqqs2DLnDqHPXoPg6+QsjU4Ji X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:21b1:6e5c:b371:7e3]) (user=axelrasmussen job=sendgmr) by 2002:a25:cc05:: with SMTP id l5mr6554359ybf.520.1618512455879; Thu, 15 Apr 2021 11:47:35 -0700 (PDT) Date: Thu, 15 Apr 2021 11:47:22 -0700 Message-Id: <20210415184732.3410521-1-axelrasmussen@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog Subject: [PATCH v3 00/10] userfaultfd: add minor fault handling for shmem From: Axel Rasmussen To: Alexander Viro , Andrea Arcangeli , Andrew Morton , Hugh Dickins , Jerome Glisse , Joe Perches , Lokesh Gidra , Mike Kravetz , Mike Rapoport , Peter Xu , Shaohua Li , Shuah Khan , Stephen Rothwell , Wang Qing Cc: linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Axel Rasmussen , Brian Geffon , "Dr . David Alan Gilbert" , Mina Almasry , Oliver Upton X-Stat-Signature: 5hsf3f7sfadrb4x73ipucb9hsxf141cc X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4AFF0C0007E7 Received-SPF: none (flex--axelrasmussen.bounces.google.com>: No applicable sender policy available) receiver=imf14; identity=mailfrom; envelope-from="<3R4p4YA0KCEgk7ov1k2w422oxqyyqvo.mywvsx47-wwu5kmu.y1q@flex--axelrasmussen.bounces.google.com>"; helo=mail-yb1-f202.google.com; client-ip=209.85.219.202 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618512448-31052 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: Base ==== This series is based on (and therefore should apply cleanly to) the tag "v5.12-rc7-mmots-2021-04-11-20-49", additionally with Peter's selftest cleanup series applied first: https://lore.kernel.org/patchwork/cover/1412450/ Changelog ========= v2->v3: - Picked up {Reviewed,Acked}-by's. - Reorder commits: introduce CONTINUE before MINOR registration. [Hugh, Peter] - Don't try to {unlock,put}_page an xarray value in shmem_getpage_gfp. [Hugh] - Move enum mcopy_atomic_mode forward declare out of CONFIG_HUGETLB_PAGE. [Hugh] - Keep mistakenly removed UFFD_USER_MODE_ONLY in selftest. [Peter] - Cleanup context management in self test (make clear implicit, remove unneeded return values now that we have err()). [Peter] - Correct dst_pte argument to dst_pmd in shmem_mcopy_atomic_pte macro. [Hugh] - Mention the new shmem support feature in documentation. [Hugh] v1->v2: - Pick up Reviewed-by's. - Don't swapin page when a minor fault occurs. Notice that it needs to be swapped in, and just immediately fire the minor fault. Let a future CONTINUE deal with swapping in the page. [Peter] - Clarify comment about i_size checks in mm/userfaultfd.c. [Peter] - Only forward declare once (out of #ifdef) in hugetlb.h. [Peter] Changes since [2]: - Squash the fixes ([2]) in with the original series ([1]). This makes reviewing easier, as we no longer have to sift through deltas undoing what we had done before. [Hugh, Peter] - Modify shmem_mcopy_atomic_pte() to use the new mcopy_atomic_install_ptes() helper, reducing code duplication. [Hugh] - Properly trigger handle_userfault() in the shmem_swapin_page() case. [Hugh] - Use shmem_getpage() instead of find_lock_page() to lookup the existing page in for continue. This properly deals with swapped-out pages. [Hugh] - Unconditionally pte_mkdirty() for anon memory (as before). [Peter] - Don't include userfaultfd_k.h in either hugetlb.h or shmem_fs.h. [Hugh] - Add comment for UFFD_FEATURE_MINOR_SHMEM (to match _HUGETLBFS). [Hugh] - Fix some small cleanup issues (parens, reworded conditionals, reduced plumbing of some parameters, simplify labels/gotos, ...). [Hugh, Peter] Overview ======== See the series which added minor faults for hugetlbfs [3] for a detailed overview of minor fault handling in general. This series adds the same support for shmem-backed areas. This series is structured as follows: - Commits 1 and 2 are cleanups. - Commits 3 and 4 implement the new feature (minor fault handling for shmem). - Commits 5, 6, 7, 8 update the userfaultfd selftest to exercise the feature. - Commit 9 is one final cleanup, modifying an existing code path to re-use a new helper we've introduced. We rely on the selftest to show that this change doesn't break anything. Use Case ======== In some cases it is useful to have VM memory backed by tmpfs instead of hugetlbfs. So, this feature will be used to support the same VM live migration use case described in my original series. Additionally, Android folks (Lokesh Gidra ) hope to optimize the Android Runtime garbage collector using this feature: "The plan is to use userfaultfd for concurrently compacting the heap. With this feature, the heap can be shared-mapped at another location where the GC-thread(s) could continue the compaction operation without the need to invoke userfault ioctl(UFFDIO_COPY) each time. OTOH, if and when Java threads get faults on the heap, UFFDIO_CONTINUE can be used to resume execution. Furthermore, this feature enables updating references in the 'non-moving' portion of the heap efficiently. Without this feature, uneccessary page copying (ioctl(UFFDIO_COPY)) would be required." [1] https://lore.kernel.org/patchwork/cover/1388144/ [2] https://lore.kernel.org/patchwork/patch/1408161/ [3] https://lore.kernel.org/linux-fsdevel/20210301222728.176417-1-axelrasmussen@google.com/T/#t Axel Rasmussen (10): userfaultfd/hugetlbfs: avoid including userfaultfd_k.h in hugetlb.h userfaultfd/shmem: combine shmem_{mcopy_atomic,mfill_zeropage}_pte userfaultfd/shmem: support UFFDIO_CONTINUE for shmem userfaultfd/shmem: support minor fault registration for shmem userfaultfd/selftests: use memfd_create for shmem test type userfaultfd/selftests: create alias mappings in the shmem test userfaultfd/selftests: reinitialize test context in each test userfaultfd/selftests: exercise minor fault handling shmem support userfaultfd/shmem: modify shmem_mcopy_atomic_pte to use install_ptes userfaultfd: update documentation to mention shmem minor faults Documentation/admin-guide/mm/userfaultfd.rst | 3 +- fs/userfaultfd.c | 6 +- include/linux/hugetlb.h | 4 +- include/linux/shmem_fs.h | 17 +- include/linux/userfaultfd_k.h | 5 + include/uapi/linux/userfaultfd.h | 7 +- mm/hugetlb.c | 1 + mm/memory.c | 8 +- mm/shmem.c | 114 +++----- mm/userfaultfd.c | 183 +++++++++---- tools/testing/selftests/vm/userfaultfd.c | 274 ++++++++++++------- 11 files changed, 371 insertions(+), 251 deletions(-) --- 2.31.1.368.gbe11c130af-goog