From patchwork Wed Jun 22 18:50:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 12891714 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 0E075C43334 for ; Thu, 23 Jun 2022 02:25:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 85AEC8E0109; Wed, 22 Jun 2022 22:25:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 80AF28E00FA; Wed, 22 Jun 2022 22:25:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D1FF8E0109; Wed, 22 Jun 2022 22:25:53 -0400 (EDT) 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 58DE98E00FA for ; Wed, 22 Jun 2022 22:25:53 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 2E70A8116C for ; Thu, 23 Jun 2022 02:25:53 +0000 (UTC) X-FDA: 79607910186.25.CC32C76 Received: from relay5.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by imf26.hostedemail.com (Postfix) with ESMTP id BD80D14000B for ; Thu, 23 Jun 2022 02:25:52 +0000 (UTC) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 70D9C1211F1 for ; Thu, 23 Jun 2022 02:25:52 +0000 (UTC) X-FDA: 79607910144.16.3313289 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by imf18.hostedemail.com (Postfix) with ESMTP id 1D3EF1C0024 for ; Thu, 23 Jun 2022 02:25:51 +0000 (UTC) Received: by mail-pj1-f52.google.com with SMTP id f16so16155428pjj.1 for ; Wed, 22 Jun 2022 19:25:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8bGSOHdb9/+Ug6kLt65798jvUVNnMQ5Xsqru+RzT0io=; b=kp3UEWl30E7imOOWjGg1pRdY7pp+a8nf4atW6Hqw7ZtOH4BCEOowEQllbRfEU59/dq WWABvwoBnokE6Ac13eu4QRcytFJp9wDSqlRYwW3R6JYlY2hsYdiBA7wNLRrhJVBekVL6 i4pCVdsSMlio7j7SEaA/M/SjRZC7CPEHslI32S2ROUEmAkbiShQk4pYZSzUQExAQWM1C KEH5efP/MrFYW2YWy+BDPbqMjjYSrV30/XPPXlx5pI5A5mC63B0T0Wqx9GBL6cWgh8QR MTnO98XhYdCh+lYjGPnIH7zCNIUP9fGhQtrwEFmzPQnB/ZxQ8U4jsyfum8FxquyZYEMi TesQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8bGSOHdb9/+Ug6kLt65798jvUVNnMQ5Xsqru+RzT0io=; b=N9hlCo3LlVb1Ybx73vwJhzPrAU0ErSTA8FikKcrqBri0vU22E97qCDVniTeBs9D0YO w8ahJa9u411CH2OiaAdcGzPbFfUWoGnP2D+59HOI1S34wi3z4Ey2s8453qkFwBRzDDQS 9eOy8r1NAU1sOOgU3cQ+uswTZWN9+r6dsFQh6dsJieKy3HTAoFRKmI/b5mLlTf4JL3pg Aaf2GDNHL+9TIW0CUUIk0kYatKT8cd3cNXQAMKRuTc+TjHNtE3jz88Hh5Snpp3v3309R g7z9Y3+lwKNu5K5PsCO97X+ZUXp/bTgCDfyvkzIYIRw5OkZz9mmwfPct1XRBKsFyPKkh iQUg== X-Gm-Message-State: AJIora+0bX+ZmnC5RQqhZXdh82iQA9Z3Nnx1/G/uoadyc87X2UYYOuGL JGPjf30VZXS2YZpKU/oaHLxVIuZxfjauXA== X-Google-Smtp-Source: AGRyM1vUyt8fPXnkBrrAsEMsW3E9ilCVEKtbb+JFUQM9Z/wPZ8W/U89l0eGjwDVxZELWSEjQBHNQ/w== X-Received: by 2002:a17:90b:1644:b0:1ec:e6d4:7931 with SMTP id il4-20020a17090b164400b001ece6d47931mr1517264pjb.105.1655951150651; Wed, 22 Jun 2022 19:25:50 -0700 (PDT) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id ik10-20020a170902ab0a00b001617541c94fsm13423998plb.60.2022.06.22.19.25.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jun 2022 19:25:50 -0700 (PDT) From: Nadav Amit X-Google-Original-From: Nadav Amit To: linux-mm@kvack.org Cc: Nadav Amit , Mike Kravetz , Hugh Dickins , Andrew Morton , Axel Rasmussen , Peter Xu , David Hildenbrand , Mike Rapoport Subject: [PATCH v1 0/5] userfaultfd: support access/write hints Date: Wed, 22 Jun 2022 11:50:33 -0700 Message-Id: <20220622185038.71740-1-namit@vmware.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655951152; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=8bGSOHdb9/+Ug6kLt65798jvUVNnMQ5Xsqru+RzT0io=; b=LJlBM7b4yT2zPPbBpAcwfB9QYPljVxmTY6N6ujgR5RRrtOWpqmqcY6C8k+QPbN/lr2jcfE v/Oo5KB1HT5vtV/5bWmPbuSZfxjZ7y9Cg3ffRTi6dkU9v8agv5nkcxmpyAMuHD2kjTvDvQ jImHoHrVzh2rxEbPFv7FXUcT4qOCN/8= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=kp3UEWl3; spf=none (imf26.hostedemail.com: domain of MAILER-DAEMON@hostedemail.com has no SPF policy when checking 216.40.44.10) smtp.mailfrom=MAILER-DAEMON@hostedemail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655951152; a=rsa-sha256; cv=none; b=WRqF8AVbZfQ7nsnP6g2FmZCeGcePc20v6loI7LU8Bsv11wHmgseNpasihiAgMsCRiYJf8g DvFRCKux1jLvn/oOPU/bc1l+BUTQKV3JtLfKodfmmCWiGxWCF1h/Zx0mR7Sec690cKIUTy qQtrJcFBmLiMZ4ivpEosMLN1fXDh8uk= X-Rspamd-Queue-Id: BD80D14000B X-HE-Tag-Orig: 1655951151-192491 Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=kp3UEWl3; spf=none (imf26.hostedemail.com: domain of MAILER-DAEMON@hostedemail.com has no SPF policy when checking 216.40.44.10) smtp.mailfrom=MAILER-DAEMON@hostedemail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Stat-Signature: kpdr68pnyb1msjmske4n6ms4dzgijgkt X-Rspamd-Server: rspam04 X-HE-Tag: 1655951152-996570 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: From: Nadav Amit Setting the access-bit and dirty-bit introduces a tradeoff. When the bit is set access/write is faster, but memory reclamation might be slower. Currently, in the common userfaultfd cases the access-bit is not set on and the dirty-bit is set. This is a questionable behavior. Allow userspace to control this behavior through hints access- and write-likely hints. These hints are used to control access- and dirty-bits. For zero-pages that with write-likely hint, allocate a clear page instead of mapping the zero-page. RFCv2 -> v1: * Adding hints to zeropage and continue * Fixing other issues pointed by David H. & Peter Xu * Adding tests to ./run_vmtests.sh Cc: Mike Kravetz Cc: Hugh Dickins Cc: Andrew Morton Cc: Axel Rasmussen Cc: Peter Xu Cc: David Hildenbrand Cc: Mike Rapoport Nadav Amit (5): userfaultfd: introduce uffd_flags userfaultfd: introduce access-likely mode for common operations userfaultfd: introduce write-likely mode for uffd operations userfaultfd: zero access/write hints selftest/userfaultfd: test read/write hints fs/userfaultfd.c | 56 +++++++++-- include/linux/hugetlb.h | 4 +- include/linux/shmem_fs.h | 8 +- include/linux/userfaultfd_k.h | 26 +++-- include/uapi/linux/userfaultfd.h | 31 +++++- mm/hugetlb.c | 6 +- mm/shmem.c | 9 +- mm/userfaultfd.c | 117 ++++++++++++++++------ tools/testing/selftests/vm/run_vmtests.sh | 23 ++--- tools/testing/selftests/vm/userfaultfd.c | 32 ++++++ 10 files changed, 239 insertions(+), 73 deletions(-)