From patchwork Sun Jun 19 23:34:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 12887048 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 5DD3CC43334 for ; Mon, 20 Jun 2022 07:09:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6C136B0071; Mon, 20 Jun 2022 03:09:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CF40C8E0002; Mon, 20 Jun 2022 03:09:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B703F8E0001; Mon, 20 Jun 2022 03:09:03 -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 A223E6B0071 for ; Mon, 20 Jun 2022 03:09:03 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 75560120A31 for ; Mon, 20 Jun 2022 07:09:03 +0000 (UTC) X-FDA: 79597737366.29.4396775 Received: from relay5.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by imf10.hostedemail.com (Postfix) with ESMTP id 55453C008A for ; Mon, 20 Jun 2022 07:09:02 +0000 (UTC) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id F17DB12022B for ; Mon, 20 Jun 2022 07:09:01 +0000 (UTC) X-FDA: 79597737282.26.4D6285E Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf04.hostedemail.com (Postfix) with ESMTP id 965504009D for ; Mon, 20 Jun 2022 07:09:01 +0000 (UTC) Received: by mail-pf1-f176.google.com with SMTP id w6so2256062pfw.5 for ; Mon, 20 Jun 2022 00:09:01 -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=D5Wmtg1eLhlBiqecPuU/uIWLafZici++4XTIxVBhT9U=; b=GMWsbSPz8oG1/in8aNDGQav5mB2spEWj56QzbMSTafDzcl0Yr/WuByHdvz58Qpb6N4 +udC5aNWd7l/L/e9eRzWm95g/FJtD2DBK7+Ufls1YLQUu3qpCLBO+ZNiaz3RiaoFkC/a m5mBQbg3Y8RF+qbCYUjJKFE91to/IPPUslY2CNDkP6SRdLOvC9M2k/5yFiuIJ/D57PDM k4FgYlQ/mNSRCCo4f5LJitoY75GjRLrKXLOguoDxc23HUmMmMYc9Kbz55dO7cBHJIFOL WuP5gjg2PwhlK+7PRfoI8H9XRJYWUHey9aQCShO7+QAoU7lqnhCEI/SFuT9pVq8BOBIH BxuA== 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=D5Wmtg1eLhlBiqecPuU/uIWLafZici++4XTIxVBhT9U=; b=ChIlSNDapQViuun3mdpk/HeUgdScOPq00jwi5HEN6Dvyq7vCzGvDJggBGIZjXwqIrD z/YZ+sXz2V5PvNmukIcVBG1aCnFtMr8kcLBKnJ664SDQUaOsfObKRIFvyyF4pODoXOL4 2WNkXY+fT7bQtE/du9kOqKBGCrZ5/tJ+0TwKZhso5X3BT9ERFpccqFyutQ0048f5yk6w 7BZZPtgK4gYm2N2GapmUm8uIHf90W3hmVwHBAb+YjCvAIJ59uboynUNkdDPwZbrVM/JE uIcXpPOw8NQqNBzMIz4rsm2JGjHJC+BarPfsoQBBaFDWEeiGx5FYRwUno4pvWLKG6Fs9 GBAQ== X-Gm-Message-State: AJIora9PO37QZzx5fmKCxgSQ6ulXUt3GEiufo8RyZd8y8vKDHcoZXw6K kLxRi8Yb7r4OQd6HNrbvOwLwn/UWK2zq/w== X-Google-Smtp-Source: AGRyM1vZR5UnXUIgrn9VMEER+jYjMz1LY23CZ9+/UFv2dUMiWfCQ9xja8U2ERl9jvbp164MK8Y5K5g== X-Received: by 2002:a05:6a00:2304:b0:4fa:7eb1:e855 with SMTP id h4-20020a056a00230400b004fa7eb1e855mr23400346pfh.14.1655708940137; Mon, 20 Jun 2022 00:09:00 -0700 (PDT) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id a8-20020a17090a6d8800b001e2ee0a9ac6sm9639773pjk.44.2022.06.20.00.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jun 2022 00:08:59 -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: [RFC PATCH v2 0/5] userfaultfd: support access/write hints Date: Sun, 19 Jun 2022 16:34:44 -0700 Message-Id: <20220619233449.181323-1-namit@vmware.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655708942; a=rsa-sha256; cv=none; b=rDQXbZTnGgz4bsuKp8uJDOp55QHJnVSW5MOef3U1e7Xj8B4hWrDVKoyd6VwF/Z6C+++vxO CltsyLsQh0EJu91UqxB+mhnIlyn1jF/psqeb04MLlJvBMBM8chGIL9ienTzUgoMHt5PyYV Jwx0MZY20KFVNItC7GXbi1L9IvrAO4o= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=GMWsbSPz; dmarc=pass (policy=none) header.from=gmail.com; spf=none (imf10.hostedemail.com: domain of MAILER-DAEMON@hostedemail.com has no SPF policy when checking 216.40.44.12) smtp.mailfrom=MAILER-DAEMON@hostedemail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655708942; 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=D5Wmtg1eLhlBiqecPuU/uIWLafZici++4XTIxVBhT9U=; b=2gqbh7xU4MqSIWIop9FUQNeTjvk8h38Xnjp+KQxC9uUjwZMheAnFSJPkESfSSQfeJcTgBg 0qybxy43mukTLkcM/TXRohwNzhVLIXaBeUY7P1fR9YxazqkEoAYyglnjP4kA0N4XTJvTk+ zTw5pyAEMRCimgkjsegUni/Bxz3tGxA= Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=GMWsbSPz; dmarc=pass (policy=none) header.from=gmail.com; spf=none (imf10.hostedemail.com: domain of MAILER-DAEMON@hostedemail.com has no SPF policy when checking 216.40.44.12) smtp.mailfrom=MAILER-DAEMON@hostedemail.com X-Stat-Signature: p53zdb43fy1mmkdmcfo57ddct99kegoi X-Rspamd-Queue-Id: 55453C008A X-Rspam-User: X-HE-Tag-Orig: 1655708941-45351 X-Rspamd-Server: rspam03 X-HE-Tag: 1655708942-828563 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. 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 copy/wp operations userfaultfd: introduce write-likely mode for copy/wp operations userfaultfd: zero access/write hints selftest/userfaultfd: test read/write hints fs/userfaultfd.c | 57 ++++++++--- include/linux/hugetlb.h | 4 +- include/linux/shmem_fs.h | 8 +- include/linux/userfaultfd_k.h | 25 +++-- include/uapi/linux/userfaultfd.h | 33 ++++++- mm/hugetlb.c | 6 +- mm/shmem.c | 9 +- mm/userfaultfd.c | 118 +++++++++++++++++------ tools/testing/selftests/vm/userfaultfd.c | 26 +++++ 9 files changed, 226 insertions(+), 60 deletions(-)