Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp932036pxb; Wed, 3 Mar 2021 21:32:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJxpNLZ69dMrNG0pb5h2lAokDr18bydmypd/5jYz6RzRSvzp+j3EviHOPEUKf0XcUUoKahD0 X-Received: by 2002:a17:906:3395:: with SMTP id v21mr2381620eja.322.1614835977912; Wed, 03 Mar 2021 21:32:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614835977; cv=none; d=google.com; s=arc-20160816; b=PHP+oOty3JTG7pxbT3jZ8m8/NCFMGg43DbRUQJ/BzJ6Ty/jIRQZjn6LQgz5O7P/0g0 /i11E7mRLyCo+3FEWkFTcdVlJUjDjURctlPre/jpPxesLB+teeAsqKAdsMpO09yZALGJ i7qA+DA+ugmbhPuJGEWeh3NIHG/nE2FITecam6KQech0yrGvPMQm4RSQjC9ghnBpZp46 rCiJYnCk/yw6j3ZGYV4h7tdIbSVnjbXC84F73KahA8LPePchGq3JAbwkmFD3qqfC/GA8 1JAD4Vs4UYPIm49JkbWVQgNtEjGB8ifFQHPyJ+X1WLn2FMToaD6z6hzqk24kT/pLxqpP ZIFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :sender:dkim-signature; bh=9heSrccM4QtbO8zJbZROi2fke/pBPWI/6xjb8kl8EnA=; b=0LTdP8ROoibx9RGsLsoTxprEcu/dMLx3hxGJgnwBB9igqwPVaUOdl2eV/9iqrDNXmm O1beUm9lyUIbNFn60PB/o7KnNxPBBszmi9fMwkqpM7hTOeZUgPc2pdMPgJwqj5ME6ezO vWTPlkT1rFB+KnYeJZ77o/kdxNGj0l639g230Oe3zRPYBkfQ4RFwGwrv9CZHQpGRks8i UgG50yWH0BR5D99NK3AbvATXMhIZ47Q/d7yALJ9BPLElg0yxAyQqWQrfA39ne/ZFYUMg zTMwdMgHY9AOXe633w2rGf+po6c6jIhJe1PdLl5fbba5Yd8RY0GoI4dRT412YdzKlgJY Ufcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="v6/QDeRE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j23si15989915eje.581.2021.03.03.21.32.35; Wed, 03 Mar 2021 21:32:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="v6/QDeRE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381040AbhCBETt (ORCPT + 99 others); Mon, 1 Mar 2021 23:19:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344283AbhCBACS (ORCPT ); Mon, 1 Mar 2021 19:02:18 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11F3AC061756 for ; Mon, 1 Mar 2021 16:01:38 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id v62so20589172ybb.15 for ; Mon, 01 Mar 2021 16:01:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=9heSrccM4QtbO8zJbZROi2fke/pBPWI/6xjb8kl8EnA=; b=v6/QDeREsxB4ARFCeFWrSwJ2dSOaKDO4I9YTPff/uItNGTtUIPsya5PcsPffq9USJV GyLgJlAiJtpUdoBfsiCVqJ8PnpkRa85psOWf6na+KGzRfr2Lrk9fNewpTU5x6pczbof1 xnh7jFSPMCqUCA3rIJEHHdO9iQiZKpT/iXDIYNtVbOYVpbORcp+OEKp/seXIsX3DKu5z vz3jixxH+biRLNNZR5UwrHfpYr2uLeMroJEM1ECn5+/UPmTS5QfRMdLU9LU4k2ewYTsN 4RmHX1IZkJBxo51233WQAq/+zg+fU7F1yG06Tv4YSY9xxqIsE9C/ypSk8QzdibOfDWRq HqBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=9heSrccM4QtbO8zJbZROi2fke/pBPWI/6xjb8kl8EnA=; b=W1Kdjc4WRoDP+on2nMjzm5aMnvW+rwjo5mI9ijEC8IoCkVc8zBJCcpl7D4ohkwIhwO MNAF+g2Iam+pT7azqrYSvlW36zdvWwQiuVwqbxHew1znsgjWjm0rLhxH7/xtix/TNMRj BYlpiJ9FpAflFfNYUSFxU+RFiGTA8M/HMo+D/z5/lap6igv2LuuzIKd9HSlFIn4hDe5J rHxLGFleIsBziZIw/6SIj8sdVs7MtDsZJDg4QO06SX6urpy1CO9cai4SR2rErCbUYskG yUG2vofZYc3PEQFVtk5C0+UWW67oz5YvmnSrtRTkyMbj2KTmCycv92s3ryzKE72/kZvu 0gyQ== X-Gm-Message-State: AOAM533TIroRbBSTLwsJJa6XWyiEmKO7/Sp2U51V/H1/UfYusQdDy8iN PDifuaSkf0rVMbvlN191WB1V258LHKOuJWG4hRMr Sender: "axelrasmussen via sendgmr" X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:1998:8165:ca50:ab8d]) (user=axelrasmussen job=sendgmr) by 2002:a25:c0ca:: with SMTP id c193mr27567242ybf.74.1614643297301; Mon, 01 Mar 2021 16:01:37 -0800 (PST) Date: Mon, 1 Mar 2021 16:01:28 -0800 Message-Id: <20210302000133.272579-1-axelrasmussen@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH v2 0/5] userfaultfd: support minor fault handling for shmem From: Axel Rasmussen To: Alexander Viro , Andrea Arcangeli , Andrew Morton , Hugh Dickins , Jerome Glisse , Joe Perches , Lokesh Gidra , Mike Rapoport , Peter Xu , Shaohua Li , Shuah Khan , Wang Qing Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Axel Rasmussen , Brian Geffon , Cannon Matthews , "Dr . David Alan Gilbert" , David Rientjes , Michel Lespinasse , Mina Almasry , Oliver Upton Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Base ==== This series is based on top of my series which adds minor fault handling for hugetlbfs [1]. (And, therefore, it is based on 5.12-rc1 and Peter Xu's series for disabling huge pmd sharing as well.) [1] https://lore.kernel.org/linux-fsdevel/20210301222728.176417-1-axelrasmussen@google.com/T/#t Changelog ========= v1->v2: - For UFFDIO_CONTINUE, don't mess with page flags. Just use find_lock_page to get a locked page from the page cache, instead of doing __SetPageLocked. This fixes a VM_BUG_ON v1 hit when handling minor faults for THP-backed shmem (a tmpfs mounted with huge=always). Overview ======== See my original series linked above for a detailed overview of minor fault handling in general. The feature in this series works exactly like the hugetblfs version (from userspace's perspective). I'm sending this as a separate series because: - The original minor fault handling series has a full set of R-Bs, and seems close to being merged. So, it seems reasonable to start looking at this next step, which extends the basic functionality. - shmem is different enough that this series may require some additional work before it's ready, and I don't want to delay the original series unnecessarily by bundling them together. 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." Axel Rasmussen (5): userfaultfd: support minor fault handling 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 fs/userfaultfd.c | 6 +- include/linux/shmem_fs.h | 26 +- include/uapi/linux/userfaultfd.h | 4 +- mm/memory.c | 8 +- mm/shmem.c | 92 +++---- mm/userfaultfd.c | 27 +- tools/testing/selftests/vm/userfaultfd.c | 322 +++++++++++++++-------- 7 files changed, 295 insertions(+), 190 deletions(-) -- 2.30.1.766.gb4fecdf3b7-goog