From patchwork Sun Aug 8 23:50:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hubbard X-Patchwork-Id: 12425161 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 019D5C4320A for ; Sun, 8 Aug 2021 23:50:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 874EE60F0F for ; Sun, 8 Aug 2021 23:50:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 874EE60F0F Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 1746E8D0002; Sun, 8 Aug 2021 19:50:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 124366B0073; Sun, 8 Aug 2021 19:50:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EDF838D0002; Sun, 8 Aug 2021 19:50:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0114.hostedemail.com [216.40.44.114]) by kanga.kvack.org (Postfix) with ESMTP id D2D4E6B0071 for ; Sun, 8 Aug 2021 19:50:25 -0400 (EDT) Received: from smtpin34.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8C18018EC0 for ; Sun, 8 Aug 2021 23:50:25 +0000 (UTC) X-FDA: 78453560010.34.893AD42 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2056.outbound.protection.outlook.com [40.107.236.56]) by imf21.hostedemail.com (Postfix) with ESMTP id 243C8D027FEC for ; Sun, 8 Aug 2021 23:50:24 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BHYOd/9kMRcXlzOSbX5CimsADyjsUBjocYOpcsQt5iVh7qVWnzjAhaUwebZ+oLOBfshauricZBIk+LcGJdfhGQ+/oqdqUE7lSfD+fGo9W6t3g0DwNJ30TEUvb/yiMFa/ucHcAlhpsTfLienM0GdwxSf3HAdrAvN2mAY8fV+NGv+/aQOjrFk4AZEcr6iTjJJL3KvyBdusW4ZhYjgpI09LGP0oj375J/Mu4OTg7OOzdNi+zx7Z5WKg025LrJSYyUPH/dfnXUZtzzRQiJ7zHnVS4q4cc0a4Vso+a/4unj1RtorkqFgFyknGTJstEPIV5FrZDNojAzHSkKy47/Km9prkbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+hnCcbovl2L9+z2bTv1WMkOZIiv+nDc+NeQkfcK5JaE=; b=UeOSdNVS8KiFkBcWZS2MuenDzqiayMjl53fBbPibiXQB8MTRK6BEIGjkYC9Y1/3fbVUgsouVwtFNOA+R7U7+ye+fnxWlkuHbWfrZXLgn8r9ldX2XgeVe75yXgsTSSRWOz/jkEtbTygpbxoBLXBVpd3kaByu+RHa16sZQTeb2bCT1d7y43whzK4o/X7hPytZmvI0vbtljIiU/4OTEMXqdvtJesFFhXhBiHbknMLtFqMJJlXZsyqhTm/ZWHYFIDHc9D7MOMHh3/EkMvTh/cqcmWnp4JM7V9L3sKVkV4mPONdWJBvNDwF6igHW/oxCvNFyaqyJA1oE9rWlaR/BtL443ag== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+hnCcbovl2L9+z2bTv1WMkOZIiv+nDc+NeQkfcK5JaE=; b=BrLDfex2m/TGGtrS4FCY22vbeNdpUAna8BlF3LHsoyPB6v34B8Hl+V9KlqAmjJb+njg/lxNDLEA53ZzoCS9Cv50Cu+MOVnIZZvpSGbtuNZKBKYtru95GnAhAsCiuKn8FY5ZR6loTljPEG7jrL7BF3mi78fSSKYo39zkCzVwF2FXIfvFosnK/X7pHEW48saEiCz0OHl9YjcR8ZBrh8lB0e9LnroNBIruFJ1MfQnQiEqA3iUnyQ8IP1DlzU+7BwrMver1/JRBHJdJ0SRXTyUhzv/YUj+JhY1YYAnNb/6DL0SKqArC8T96uwiQ20SeyonAuhh4Mu+3/SmUKPhttAnOrlw== Received: from DM5PR16CA0046.namprd16.prod.outlook.com (2603:10b6:4:15::32) by BL0PR12MB2418.namprd12.prod.outlook.com (2603:10b6:207:4d::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.18; Sun, 8 Aug 2021 23:50:23 +0000 Received: from DM6NAM11FT046.eop-nam11.prod.protection.outlook.com (2603:10b6:4:15:cafe::8) by DM5PR16CA0046.outlook.office365.com (2603:10b6:4:15::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.15 via Frontend Transport; Sun, 8 Aug 2021 23:50:23 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.35 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.35; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.35) by DM6NAM11FT046.mail.protection.outlook.com (10.13.172.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4394.16 via Frontend Transport; Sun, 8 Aug 2021 23:50:23 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sun, 8 Aug 2021 23:50:20 +0000 Received: from sandstorm.attlocal.net (172.20.187.5) by mail.nvidia.com (172.20.187.12) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sun, 8 Aug 2021 23:50:20 +0000 From: John Hubbard To: Andrew Morton , Matthew Wilcox CC: LKML , , John Hubbard Subject: [PATCH 1/3] mm/gup: documentation corrections for gup/pup Date: Sun, 8 Aug 2021 16:50:16 -0700 Message-ID: <20210808235018.1924918-2-jhubbard@nvidia.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210808235018.1924918-1-jhubbard@nvidia.com> References: <20210808235018.1924918-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: edaf858b-6fc8-4e59-63f7-08d95ac749f5 X-MS-TrafficTypeDiagnostic: BL0PR12MB2418: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: a/PC3vxeXTam3Df4g1Oz626L+MOXJ1e5sOU8tqESCw3PXLPSDOJhvqu0hS82uA0h31YTToL0dQSe5ZwtOfIEQLVT9kecvjg6fw7/Ji7ubO9rT7qkBAHgKb6GGRdX1uM1JLzYBpLhpG0oSbNVfK1HHlszruwMvUdTG7MDZ805MwHJV5ONK+qRCoAVCSUD5eUj7JJELk2VjrX45Ej8UhCpaWt/5NVwNLsx/056hGeD053zGaqolk9duo9EBduSKiV7oMZ6i8RqiQ2lYUYOdsBRQReF+IbFU0Jx7HNt/3B/lad/wksXIQvj1Z+he8q8oYBOvJZVfz9vgHOhKg6kyHG4MHdaWUDDlQ6B6SS3Ek1t2I+0qeHny3uzfRooeywHZmMjhbNjPbr4aBYPNojPTt0w6brqzMmk75ornwI4rNU461A3Ojda0rvqu2HWF/MkATppZdz92KEthIp73HoHb8yKt+25JllfiNFdl3FDiUk9c545FdZrzf4U8lG1qhW+vbrsudpfHNvBddUKA86SqZXDIW1PEyiK+pKMKbgPU1HTSLtmDP+g9MV9s+cI7WH6QL37uJs3Ft+Wpi67L7N4c2YVkiezP87OQnpBadRhh4cZuR5bDdAidBG4iE/tosUXP3O+F/EE9YmtMkSA221ZMblSx4BPz302TcdytXBSJf7xlg1BQvIdMQV6f3lFIfRr60cU6msvz3qR9PADyh3bRFvgTg== X-Forefront-Antispam-Report: CIP:216.228.112.35;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid02.nvidia.com;CAT:NONE;SFS:(4636009)(39860400002)(346002)(396003)(376002)(136003)(36840700001)(46966006)(110136005)(54906003)(2616005)(70586007)(186003)(4326008)(1076003)(107886003)(8676002)(47076005)(5660300002)(6666004)(426003)(478600001)(70206006)(356005)(8936002)(26005)(336012)(316002)(86362001)(36906005)(7636003)(82310400003)(36860700001)(36756003)(2906002)(82740400003)(83380400001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Aug 2021 23:50:23.4376 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: edaf858b-6fc8-4e59-63f7-08d95ac749f5 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.35];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT046.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB2418 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=BrLDfex2; spf=none (imf21.hostedemail.com: domain of jhubbard@nvidia.com has no SPF policy when checking 40.107.236.56) smtp.mailfrom=jhubbard@nvidia.com; dmarc=pass (policy=quarantine) header.from=nvidia.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 243C8D027FEC X-Stat-Signature: y7iqo89fu5jecty9a5zd33fb9gajxjj7 X-HE-Tag: 1628466624-37441 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: The documentation for try_grab_compound_head() and try_grab_page() has fallen a little out of date. Update and clarify a few points. Signed-off-by: John Hubbard --- mm/gup.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 77150624f77a..5cb18b62921c 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -103,8 +103,14 @@ static inline struct page *try_get_compound_head(struct page *page, int refs) * same time. (That's true throughout the get_user_pages*() and * pin_user_pages*() APIs.) Cases: * - * FOLL_GET: page's refcount will be incremented by 1. - * FOLL_PIN: page's refcount will be incremented by GUP_PIN_COUNTING_BIAS. + * FOLL_GET: page's refcount will be incremented by refs. + * + * FOLL_PIN on compound pages that are > two pages long: page's refcount will + * be incremented by refs, and page[2].hpage_pinned_refcount will be + * incremented by refs * GUP_PIN_COUNTING_BIAS. + * + * FOLL_PIN on normal pages, or compound pages that are two pages long: + * page's refcount will be incremented by refs * GUP_PIN_COUNTING_BIAS. * * Return: head page (with refcount appropriately incremented) for success, or * NULL upon failure. If neither FOLL_GET nor FOLL_PIN was set, that's @@ -143,6 +149,8 @@ __maybe_unused struct page *try_grab_compound_head(struct page *page, * * However, be sure to *also* increment the normal page refcount * field at least once, so that the page really is pinned. + * That's why the refcount from the earlier + * try_get_compound_head() is left intact. */ if (hpage_pincount_available(page)) hpage_pincount_add(page, refs); @@ -186,10 +194,8 @@ static void put_compound_head(struct page *page, int refs, unsigned int flags) * @flags: gup flags: these are the FOLL_* flag values. * * Either FOLL_PIN or FOLL_GET (or neither) may be set, but not both at the same - * time. Cases: - * - * FOLL_GET: page's refcount will be incremented by 1. - * FOLL_PIN: page's refcount will be incremented by GUP_PIN_COUNTING_BIAS. + * time. Cases: please see the try_grab_compound_head() documentation, with + * "refs=1". * * Return: true for success, or if no action was required (if neither FOLL_PIN * nor FOLL_GET was set, nothing is done). False for failure: FOLL_GET or From patchwork Sun Aug 8 23:50:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hubbard X-Patchwork-Id: 12425163 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 E1E12C432BE for ; Sun, 8 Aug 2021 23:50:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6FAA260F92 for ; Sun, 8 Aug 2021 23:50:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6FAA260F92 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id F2EF36B0071; Sun, 8 Aug 2021 19:50:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EB7CC8D0003; Sun, 8 Aug 2021 19:50:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D32436B0074; Sun, 8 Aug 2021 19:50:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0062.hostedemail.com [216.40.44.62]) by kanga.kvack.org (Postfix) with ESMTP id B79E16B0071 for ; Sun, 8 Aug 2021 19:50:30 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 5903B8249980 for ; Sun, 8 Aug 2021 23:50:30 +0000 (UTC) X-FDA: 78453560220.20.AFA7095 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2077.outbound.protection.outlook.com [40.107.243.77]) by imf05.hostedemail.com (Postfix) with ESMTP id D96805049E5A for ; Sun, 8 Aug 2021 23:50:29 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jwBGJtvXDERtJynNAKD9mWppTzBtn3uvklGLN5wMrpLFs9Tw3iLjRMlka8yLOkjVsyUbQWd3KgAjgw/TXYXRgR85GgRMuWdzOho6YBEsNXrCfku/gwZ9rj3YzUEO7Gk7bj74M92t1q23Uz5PXILDx80rdQ4/GQmbF1ZWuBwhYurqeWtQofTFbfBaprETCWvmxcVyhRhGB9tlqjCGX0DzxaoN6uS1tJVqRXVOI6fmUO2w1QD64rVICoahA4tGDdYS+gSwuLerCfXP7Hvxr94FCNhOzButN9aH1iBk2qD1CChXTnK5NUNcE/khvDfAS6h+fwTSjRzx12ywUtLzEur6yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pv139OQWFEXxn6Yvz4f7rKpx2Ju29ayURD9QNjFcssc=; b=PUosPLtanemu0CeiHk03GhPQu6ciX/UNVPzXq23zXKLMFSd/w+MNjNo3MQr76jv34YFpVHpg5Ij9CBMKq5HYUjILGE/VghYYxhERJ8W89uV4GEsMjXltu4+8D2NU7mmL8vhw6WAkwxcP4cV6r3xuafVOM4OXKVNUdvcTYh7rWYXH10qpwGZWu32jNUx+yo5nhDVHhVDlD2OD+rlukbLBdOai9OmuNQdIDP5W0bDw2SwsJwK8WSVw8gbSCCJJVr5siNDnSmiJvPLvv9j8JKTYcZDUEtwBSeLug2wqtK7UarKb/bRkDUNr/decu5XR5vCqKMFmTCMSuOD3+KotA7sRyQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pv139OQWFEXxn6Yvz4f7rKpx2Ju29ayURD9QNjFcssc=; b=rYgkVG5dfsTzvYzlleLunE/U0GJvcIPukmXYyS4P1zUJ2WnqoDcI1sIvLGeh2hkodegB3c0i4A9Z1RInJuGN6jIedW3JA/LeHSr/3d2P51WjmgSRJUMIH5o0Fz2frUQLk0FlMFalu7EObxmRG/QyBiKROKIBsNqPVCEzWvSK34WlCs/amTHjnurwCVIXptsIZHlZHqg1hBQXYAh531jF2YaiOZzLc7JlSCMkF40gDg0/qKXNouc+6S7SzYoP1HbEfLccLOjkNk9/cSwLkg75b0WXZee6xC9iTH3fvhtdf/G7CFBxmC1hc5mwiAdKhp8ORehkuZa7oiBaNucCA1T72g== Received: from DM5PR05CA0006.namprd05.prod.outlook.com (2603:10b6:3:d4::16) by BYAPR12MB4983.namprd12.prod.outlook.com (2603:10b6:a03:102::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.21; Sun, 8 Aug 2021 23:50:28 +0000 Received: from DM6NAM11FT056.eop-nam11.prod.protection.outlook.com (2603:10b6:3:d4:cafe::28) by DM5PR05CA0006.outlook.office365.com (2603:10b6:3:d4::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.5 via Frontend Transport; Sun, 8 Aug 2021 23:50:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.35 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.35; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.35) by DM6NAM11FT056.mail.protection.outlook.com (10.13.173.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4394.16 via Frontend Transport; Sun, 8 Aug 2021 23:50:27 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sun, 8 Aug 2021 23:50:23 +0000 Received: from sandstorm.attlocal.net (172.20.187.5) by mail.nvidia.com (172.20.187.12) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sun, 8 Aug 2021 23:50:23 +0000 From: John Hubbard To: Andrew Morton , Matthew Wilcox CC: LKML , , John Hubbard Subject: [PATCH 2/3] mm/gup: small refactoring: simplify try_grab_page() Date: Sun, 8 Aug 2021 16:50:17 -0700 Message-ID: <20210808235018.1924918-3-jhubbard@nvidia.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210808235018.1924918-1-jhubbard@nvidia.com> References: <20210808235018.1924918-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d125139b-1070-4410-ceab-08d95ac74c81 X-MS-TrafficTypeDiagnostic: BYAPR12MB4983: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FDUOwlYf4350A1x02h+zGBgVZd0HNpA9yPNvNab8cDNQaTYCr2M/mruiILvJG+Hi3Sf+9yjqPRXaVCVV5Yal37mdz0vES/SwY4Dscao5GRfTn48tOiEuYDh/78+yU5vYvnRJHwCSrzgwwKuGszW+j1sRXjwNyFSXmVY5IbaWlFpXSM+tvjOT+FOP73eRimWlgZ2QZuOaNqe4u8gEGcBzQu719rLQzzM5o3/KGcM0BNsLeLONArUrikZFTzMJDYdT1X2UEIteE+nxRudr8UDbwmFys682qlGll8mnqsZZwFziOeElkDj+6Znw+2meSZyYsJ6mz3fS7KJBfiLJSFO7S8xx7bkEVzh7Vav0Bvigl5EBgClkSbirTwE2hnEVNmuVmf9w5sunMgqnb8nSpsNIGw7q8hKdO/qrqWEuBro0HLtNA2Y3zxgs97zEqDymAMnL47SZ8yovLL39B17W5YpHgMYxWveZTc+v39MEuyuEhcDcNxZ3MPQGKqsULPbaSUwQXMBWiIrQlg4KDrcfwNQKegXzxL0ZVkscHvsrgYD+FAIJG+7WUQl9EqTcBHvP+4C+WV/W2mEVLmElEftOABuOqWwCjHX3JQGsvqxJ7CJqlMjAEg3HdQdD0e8v9twod7FfG4NEmlXWGMlXFlWeFqqO3Jn1wCwAqV21Tt4AxSLpRRIffQmg4YuFtF0KMWXOMZ5LG1lxhQSVpfNg0qJYe0O4vA== X-Forefront-Antispam-Report: CIP:216.228.112.35;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid02.nvidia.com;CAT:NONE;SFS:(4636009)(396003)(39860400002)(136003)(346002)(376002)(36840700001)(46966006)(4326008)(6666004)(8936002)(1076003)(47076005)(36756003)(36860700001)(2906002)(8676002)(478600001)(107886003)(82740400003)(26005)(110136005)(54906003)(70586007)(70206006)(336012)(83380400001)(186003)(356005)(82310400003)(426003)(2616005)(86362001)(7636003)(5660300002)(316002)(36906005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Aug 2021 23:50:27.6534 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d125139b-1070-4410-ceab-08d95ac74c81 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.35];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT056.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB4983 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D96805049E5A Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=rYgkVG5d; dmarc=pass (policy=quarantine) header.from=nvidia.com; spf=none (imf05.hostedemail.com: domain of jhubbard@nvidia.com has no SPF policy when checking 40.107.243.77) smtp.mailfrom=jhubbard@nvidia.com X-Stat-Signature: b5ygc6qxn8obddnj6p5cmwptqio15kq6 X-HE-Tag: 1628466629-126135 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: try_grab_page() does the same thing as try_grab_compound_head(..., refs=1, ...), just with a different API. So there is a lot of code duplication there. Change try_grab_page() to call try_grab_compound_head(), while keeping the API contract identical for callers. Signed-off-by: John Hubbard --- mm/gup.c | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 5cb18b62921c..4be6f060fa0b 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -203,33 +203,8 @@ static void put_compound_head(struct page *page, int refs, unsigned int flags) */ bool __must_check try_grab_page(struct page *page, unsigned int flags) { - WARN_ON_ONCE((flags & (FOLL_GET | FOLL_PIN)) == (FOLL_GET | FOLL_PIN)); - - if (flags & FOLL_GET) - return try_get_page(page); - else if (flags & FOLL_PIN) { - int refs = 1; - - page = compound_head(page); - - if (WARN_ON_ONCE(page_ref_count(page) <= 0)) - return false; - - if (hpage_pincount_available(page)) - hpage_pincount_add(page, 1); - else - refs = GUP_PIN_COUNTING_BIAS; - - /* - * Similar to try_grab_compound_head(): even if using the - * hpage_pincount_add/_sub() routines, be sure to - * *also* increment the normal page refcount field at least - * once, so that the page really is pinned. - */ - page_ref_add(page, refs); - - mod_node_page_state(page_pgdat(page), NR_FOLL_PIN_ACQUIRED, 1); - } + if (flags & (FOLL_GET | FOLL_PIN)) + return try_grab_compound_head(page, 1, flags) != NULL; return true; } From patchwork Sun Aug 8 23:50:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hubbard X-Patchwork-Id: 12425165 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 F086EC4338F for ; Sun, 8 Aug 2021 23:56:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8CEA260F11 for ; Sun, 8 Aug 2021 23:56:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8CEA260F11 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id E3D848D0003; Sun, 8 Aug 2021 19:56:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DEFC68D0002; Sun, 8 Aug 2021 19:56:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C8EF98D0003; Sun, 8 Aug 2021 19:56:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0133.hostedemail.com [216.40.44.133]) by kanga.kvack.org (Postfix) with ESMTP id ACF968D0002 for ; Sun, 8 Aug 2021 19:56:21 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3805F1AD8C for ; Sun, 8 Aug 2021 23:56:21 +0000 (UTC) X-FDA: 78453574962.25.A7E6B08 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2042.outbound.protection.outlook.com [40.107.243.42]) by imf02.hostedemail.com (Postfix) with ESMTP id D0B8770037B4 for ; Sun, 8 Aug 2021 23:56:20 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fSxh1SC1eWfNFxdVK+FA//j0T6MWtVAHQOo3XWMVgK8qobe38eUAou3ahAsAHlmfhcg3s7BVpnb7zeQPy559zrP6K627IxU/zNL1Rd44Mn9wY4mQ+HVYa4s6jsWTQNmBVlVuXTbvx58cwBkdvjGYC8Wpz93AgEg362u/Lfmf4V40exH7lGo1VTTbREXDCNdmhQZ5KrmyRYZGHdNJOVAL3lc6kSJXPy/w48MCAUNfMWoE14ewMfp76WiEb07ri1tEyFuqUkGtSnR6HD88Bu8GQfi9W8Ej8epFIgQa7PE4mGDXw8FqqwVdOHPb+JY3bZO9uFiJnLqr5Lojt+oBIHdZZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=S+hAT6FQWNFGwLsH49tB8X/14nP2g71qGXxVFtkgw4w=; b=af/GzKd+sY/twrr3ncETLW8WrBkj6j4uqOohOpuwEZQXpfGzv4MqjOAHQWCIhU4blnVD1ngjBvJLOjfzLNZ0F0a8Y0Xh79C6r10H2X6iJ049mgd6yh05HL5UDvP+kR6H1M2vu90L77++s27kHe/khZuhLu5DakFzV4WallIYlA9ipUV1ohujTYXQ7GroyEAmJ6+bNkv0ld58XhaO6Iv6ltQXXXVBzLAt5w+nOWv/mYRu883Uy4k+JdKlUrdjHcDqgBZKnfYE9VIih2DQtWOaozwEcDWV+Px36nkayg5UCx3ruGgtKgP1yHMSYg3m3pGzZK+77JrOE2m3/W+fqI5d3Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=S+hAT6FQWNFGwLsH49tB8X/14nP2g71qGXxVFtkgw4w=; b=QAjiZNJbUtAHiTAFVuF1e+F78m7qbSzXsdp9h1Rh4LTZqMk1EVmztQPS9tlC0CuJH5t/YB8yAIGcUFa2STc+U14tcMJL34csewzp17mFUwHU6c8fKLKwkDGU6ghT1lNTFl2tupFJmK4rqObjd4axQev/nFUE+57akykIuF+IvEabtCiexEeFh/NXtc2FbXX38PuY9k7TIapA5io3XPzH7ivsvVufc7Dk3K37TCdz0OEICCqMId5449i8eQZqAEz+JfrQonX2Hfs1zjmIZQAyNrjszYKW4tgesVdE0tWA06BeDI02875YE2IX4JTkMXkWn6uk12EPGQTtmVFOKjs2vw== Received: from MW4PR03CA0086.namprd03.prod.outlook.com (2603:10b6:303:b6::31) by MN2PR12MB4064.namprd12.prod.outlook.com (2603:10b6:208:1d3::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.16; Sun, 8 Aug 2021 23:56:19 +0000 Received: from CO1NAM11FT010.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b6:cafe::f5) by MW4PR03CA0086.outlook.office365.com (2603:10b6:303:b6::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.16 via Frontend Transport; Sun, 8 Aug 2021 23:56:19 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; linux-foundation.org; dkim=none (message not signed) header.d=none;linux-foundation.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.35 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.35; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.35) by CO1NAM11FT010.mail.protection.outlook.com (10.13.175.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4394.16 via Frontend Transport; Sun, 8 Aug 2021 23:56:19 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sun, 8 Aug 2021 23:56:18 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sun, 8 Aug 2021 23:50:26 +0000 Received: from sandstorm.attlocal.net (172.20.187.5) by mail.nvidia.com (172.20.187.12) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sun, 8 Aug 2021 23:50:26 +0000 From: John Hubbard To: Andrew Morton , Matthew Wilcox CC: LKML , , John Hubbard Subject: [PATCH 3/3] mm/gup: refactor and simplify try_get_page() Date: Sun, 8 Aug 2021 16:50:18 -0700 Message-ID: <20210808235018.1924918-4-jhubbard@nvidia.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210808235018.1924918-1-jhubbard@nvidia.com> References: <20210808235018.1924918-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c67cdf41-6ee7-4d3c-a6ea-08d95ac81e07 X-MS-TrafficTypeDiagnostic: MN2PR12MB4064: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jvoHdzl8g7E2qD6ggvVGggWwDiPoU9OvqstLB4WIHiKN8sqiXVL7Orajc1zY+0p7suBu3kHrFhewccIG0FA3ONt8cSdFdH8eNO7PsW3ubr1x5DyIHeOA52zDQa8N6q30w0mhGH3ysgmBsVu7ZPncUVNm9PHQjmrIodbRjhgZCoxnOtDAcKtNo3YrwIc4AagEeHG8YIND4kluJhnA2jrNMWyEodF6g3+iVvGoukP2ZyCpf5EpujvmuAjJSP9w8f87QDzA/b2jbfZKUPoDlWeYaR+L3BkVd8iaOkqMwIIwsZVNj/tAdA8DCwAh6jEO75vDJ0w65+ENYtBIY9R3DZ6tNdqueG4ZizrLzjfQcb771CUhB5HtQVRsDJH5Ff7hz8SyPWeldTYDBUpgoRUqcSWlOlZkd/Bn3hdzRamNMrzQOZBEpFlPPAIpWhP1A05dO2Zm+4JZnq8qlilKNyrL59NXFnvPIcKOixSWk2iBm8V9EbWIP4BginrQvCOrOtDC11evR2pqGHzXX5y3htrxk62mzN19p23r0kRHebNuLJxQMCh+A2jCU8sHe9+9ZuyhKkfJ36VwksoZQkZjgX0lK+5xD13aTYoOrd/Ai5oh5uuD+Jdu2OKNTf0AVH2DJWQZLRasuWfrIDrKUhRnm8R6MGrexsMEW+20FlRQOX26Bgp6kuKWhmVgX8AI/EcraQnkW4ewzrQWKogN/JFW3l1eyDQojg== X-Forefront-Antispam-Report: CIP:216.228.112.35;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid02.nvidia.com;CAT:NONE;SFS:(4636009)(396003)(376002)(346002)(39860400002)(136003)(36840700001)(46966006)(356005)(36756003)(83380400001)(82310400003)(8676002)(86362001)(7636003)(36860700001)(336012)(36906005)(478600001)(186003)(82740400003)(2906002)(316002)(110136005)(70586007)(70206006)(26005)(4326008)(8936002)(6666004)(54906003)(47076005)(5660300002)(1076003)(107886003)(426003)(2616005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Aug 2021 23:56:19.2383 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c67cdf41-6ee7-4d3c-a6ea-08d95ac81e07 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.35];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT010.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4064 Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=QAjiZNJb; spf=none (imf02.hostedemail.com: domain of jhubbard@nvidia.com has no SPF policy when checking 40.107.243.42) smtp.mailfrom=jhubbard@nvidia.com; dmarc=pass (policy=quarantine) header.from=nvidia.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: D0B8770037B4 X-Stat-Signature: 6hcducf8dddi3eqa3wrgcddz9b87uu7s X-HE-Tag: 1628466980-391028 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: try_get_page() is very similar to try_get_compound_head(), and in fact try_get_page() has fallen a little behind in terms of maintenance: try_get_compound_head() handles speculative page references more thoroughly. Change try_get_page() so that it is implemented in terms of try_get_compound_head(), but without changing try_get_page()'s API contract. Signed-off-by: John Hubbard --- include/linux/mm.h | 11 ++++++----- mm/gup.c | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index ce8fc0fd6d6e..92d3b37357d5 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1207,14 +1207,15 @@ bool __must_check try_grab_page(struct page *page, unsigned int flags); __maybe_unused struct page *try_grab_compound_head(struct page *page, int refs, unsigned int flags); +struct page *try_get_compound_head(struct page *page, int refs); +/* + * This has the same functionality as try_get_compound_head(), just with a + * slightly different API. + */ static inline __must_check bool try_get_page(struct page *page) { - page = compound_head(page); - if (WARN_ON_ONCE(page_ref_count(page) <= 0)) - return false; - page_ref_inc(page); - return true; + return try_get_compound_head(page, 1) != NULL; } /** diff --git a/mm/gup.c b/mm/gup.c index 4be6f060fa0b..ba75906ba7f7 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -66,7 +66,7 @@ static void put_page_refs(struct page *page, int refs) * Return the compound head page with ref appropriately incremented, * or NULL if that failed. */ -static inline struct page *try_get_compound_head(struct page *page, int refs) +struct page *try_get_compound_head(struct page *page, int refs) { struct page *head = compound_head(page);