From patchwork Mon Jul 18 11:47:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 12921632 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 82348C43334 for ; Mon, 18 Jul 2022 19:22:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CFCE26B0072; Mon, 18 Jul 2022 15:22:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CAAA78E0001; Mon, 18 Jul 2022 15:22:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B71EE6B0074; Mon, 18 Jul 2022 15:22:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A3ED66B0072 for ; Mon, 18 Jul 2022 15:22:38 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6A71D337D1 for ; Mon, 18 Jul 2022 19:22:38 +0000 (UTC) X-FDA: 79701192396.25.9598CE7 Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by imf15.hostedemail.com (Postfix) with ESMTP id F0CFFA0075 for ; Mon, 18 Jul 2022 19:22:37 +0000 (UTC) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 9E9EE805B1 for ; Mon, 18 Jul 2022 19:22:37 +0000 (UTC) X-FDA: 79701192354.13.3A6A5C5 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf13.hostedemail.com (Postfix) with ESMTP id 316DD20090 for ; Mon, 18 Jul 2022 19:22:37 +0000 (UTC) Received: by mail-pl1-f181.google.com with SMTP id q5so9930849plr.11 for ; Mon, 18 Jul 2022 12:22:36 -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=RCEtsN+wPhwFwQceExmlW6nYZCLuK1dzKM6XAyTJivI=; b=h9M0qzRxVhFn4LdeL6Maryn/MtIrbPa0EY/+jd60hdWmSBsudObnnbdaPYBymLM7IA Yesyrg61iVtau/mb7Cn/HoGcK/ci090RQKSs7zJf9Q2icF73d3nWCI59EL4dWO4oXGC/ yxuvnGNI0BJI7MC1A/pUhOC1yQ0QXgxvdBgQi0DvMtUxddR0uaCIaTre/Tg+lsybs+Ue zUP2/DvfZZNoukQSif71wN+UQKLW731R30YkBbr30LVyGWDXhzdQXlK+qaLM4VSPkkIz CNbAhGhUBy9mYqc+ml51TpzaDrEgHASzVYJp/e/TpsGkVqiqKy4JYhdUj/W9DkTJGWZp CUTg== 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=RCEtsN+wPhwFwQceExmlW6nYZCLuK1dzKM6XAyTJivI=; b=rdlaRcM/wEZqw8uwKKX13Wgql1Nr13SWwzPbM2dRa1Y0r63JhfJbWW+iuqLB9K5vNo elTXDboeBseuGSpvqMPtQEAYA0BFZ41KVqd4tNbI79B2IM7wGOUSwXn8M/Ddn0Xw8vQi 0VkyqBsFl+n824IKlFNAncqCdq7Ey/OCMO0MhxIWMk9ir4Z3SzwMKRHPMwMIjsFil6Mb l0IsBjk85XubMkTR9s9aZaKWPG++OM8wXWBR87w4raqD+QjPcXN5glCCyhfSm1hfe5va lZeZ0+xyHK+VGH8VSPRMuIm+Xk9gMXlgG7RxYdt/dYy8adBaipBsn1i0S9e4YmLv1H/b z7eg== X-Gm-Message-State: AJIora9dRoyh6r7E9hnzAYOWZ38iJWfz2z7L8yNy2KZL7v9guXlxFAsq VaFNPjf1nl62PGQkeZFDL031ay0zlv0= X-Google-Smtp-Source: AGRyM1vDVPdkNkjWkVgPIx1B7ybvpaY53FRySy3V/9/h6tDfBH//Y8qVr2bjPxyCDsctJdVUccVM+g== X-Received: by 2002:a17:902:ea07:b0:16c:1efb:916e with SMTP id s7-20020a170902ea0700b0016c1efb916emr29499358plg.25.1658172155639; Mon, 18 Jul 2022 12:22:35 -0700 (PDT) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id g9-20020a625209000000b0051bc5f4df1csm9613570pfb.154.2022.07.18.12.22.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 12:22:35 -0700 (PDT) From: Nadav Amit X-Google-Original-From: Nadav Amit To: linux-mm@kvack.org Cc: Andrew Morton , Nadav Amit , Mike Kravetz , Hugh Dickins , Axel Rasmussen , Peter Xu , David Hildenbrand , Mike Rapoport Subject: [PATCH v2 0/5] userfaultfd: support access/write hints Date: Mon, 18 Jul 2022 04:47:43 -0700 Message-Id: <20220718114748.2623-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=1658172158; 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=RCEtsN+wPhwFwQceExmlW6nYZCLuK1dzKM6XAyTJivI=; b=uR1IVbYuA+jeer5sA5WYiOk7MTpTiwfe/VsQnfsG+eHeGN2kNndiuGvnlMnG/0ioLOlsYI JZSkQ2zKBcm2q3LT+KBnJ3FGaGVJlPXkkeqdPpD4T3A3Ncdiz8nDKNuY7afMExEdVhx1KY AqL38VsRPKHTJ5lvaEy7CFujYHYpV3w= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=h9M0qzRx; spf=none (imf15.hostedemail.com: domain of MAILER-DAEMON@hostedemail.com has no SPF policy when checking 216.40.44.16) 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=1658172158; a=rsa-sha256; cv=none; b=YFlEI1l7ZX6FAU4yJbKjO6G3XCLlrqdRYsUcBhzA7PYGEKoXzl60ee9vsVF75+g0xP8f8e MPk62XmJE+yqU6DXNtSdJ8HBWrCn82rumdWGXlcXfaM4FCaPHAasQBggUnqCyHCrF1/l2/ 9VPQj36aiy2qBA6PIdy1WnV8A7vwQpY= X-Stat-Signature: hxybixwqn7ai1km1yp7pf9uozn5okyng X-Rspamd-Queue-Id: F0CFFA0075 X-HE-Tag-Orig: 1658172157-471061 X-Rspamd-Server: rspam02 X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=h9M0qzRx; spf=none (imf15.hostedemail.com: domain of MAILER-DAEMON@hostedemail.com has no SPF policy when checking 216.40.44.16) smtp.mailfrom=MAILER-DAEMON@hostedemail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1658172157-457485 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 This patch-set introduces access/write hints for userfaultfd. Unlike the previous versions, the use of these hints in this version is limited. Yet, in order to keep introducing new features again and again, hints are introduced for all of uffd related ioctls. The access-hint is currently used to set the young bit, similarly to do_set_pte(). This has no effect on x86, but may on arm64. When a write-hint is provided on zeropage ioctl, a clear page is allocated instead of mapping the zero-page. Future patches would use the write-hint to decide whether to map the writable pages on write-(un)protect ioctl. 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. v1 -> v2: * Leave dirty-bit as it was before [Peter Xu] 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 | 77 ++++++++++++++-- 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 | 3 +- mm/internal.h | 13 +++ mm/memory.c | 12 --- mm/shmem.c | 6 +- mm/userfaultfd.c | 103 +++++++++++++++------- tools/testing/selftests/vm/run_vmtests.sh | 16 ++-- tools/testing/selftests/vm/userfaultfd.c | 54 +++++++++++- 12 files changed, 275 insertions(+), 78 deletions(-) Acked-by: Peter Xu Reviewed-by: David Hildenbrand Acked-by: Mike Rapoport