From patchwork Thu Feb 4 20:24:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 12068621 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,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 2CB89C433E6 for ; Thu, 4 Feb 2021 20:25:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9CD9964F45 for ; Thu, 4 Feb 2021 20:25:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9CD9964F45 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 272936B006E; Thu, 4 Feb 2021 15:25:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1FBCB6B0071; Thu, 4 Feb 2021 15:25:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 09F3D6B0072; Thu, 4 Feb 2021 15:25:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0219.hostedemail.com [216.40.44.219]) by kanga.kvack.org (Postfix) with ESMTP id E295E6B006E for ; Thu, 4 Feb 2021 15:25:21 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id A7F77180AD81D for ; Thu, 4 Feb 2021 20:25:21 +0000 (UTC) X-FDA: 77781715242.09.doll95_3214ca4275df Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id 8C8CB180AD82F for ; Thu, 4 Feb 2021 20:25:21 +0000 (UTC) X-HE-Tag: doll95_3214ca4275df X-Filterd-Recvd-Size: 12937 Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Thu, 4 Feb 2021 20:25:20 +0000 (UTC) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 114KJi0r094824; Thu, 4 Feb 2021 20:25:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=Mg0EG9jyZ1sq9/BmNNBYOGVTgJOCH8UybdaYtPghJi4=; b=uETIJsmVeP1ZhmOSx6f66dBJQn0GASXvhLqYnh44TkX06zDiw0EBRvU9wxVjRvvth49A flbLXk0Oa5uGCycx9zwl8YujVsuE0Wq4ec1PW/Zh2p2yrLkeISv3xlXgrmgl0SuXAomz Z/SeMmChLqssClrTCIEjiRCaOzUs4e6MS/mT1ZDG6HluFE2p7V6MfzNX6E6Fqs90zC5h MdttitkiacopP61mHCCRE34Y/79YCfi2mKPssEvQTWQaYRHjQdwMZmplPTH1LhmenGJT dNnZbGJHSC3lfNUA3WzFyiY8BSfN9hoelgndb/h4SHRzEv3ITwlaebDHmU34Q/wnCytn 6A== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 36cydm71xr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 04 Feb 2021 20:25:17 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 114KF6Kn155762; Thu, 4 Feb 2021 20:25:17 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2176.outbound.protection.outlook.com [104.47.57.176]) by aserp3020.oracle.com with ESMTP id 36dhc369ty-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 04 Feb 2021 20:25:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PwwWHI+DtPvF0hBkxhkwq1IOs8F52IxRnUtTw/0CjMh4GADjI0mgYHC7wdv4c9VKkPjAdntGT8yG01KXEHw/XwrJvd7oR7+7ZxQ3qXHDeRY6n4MlyuSWGrC0Va8ASMZKVb37GQdfSwcqh3eOFnYli/ogXqOWn4edJ0AXBmflOIUPixhkJwHrDuO4Oc41dejCgEMZGWhqJ7ivNsXptwUIH1aRkVENi3WpnXa+Ghum+3XzNF+xelh7O1qDvygqsAXf4hOR7o44EmV0LDZkmW2MPdBIYZCzGedHUWN1i5/4MYCVoOnY/NWwzFVY85qAG9Um2z4x0D9uCz6PzwBq3j73+g== 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=Mg0EG9jyZ1sq9/BmNNBYOGVTgJOCH8UybdaYtPghJi4=; b=bVwTp7qqwXAMqR6fu0g44uWW6AQMbkf64TH9zcXm4Uw2l8otirlEHAtnX6AOvNnSXEFmqKDr4Uf3sMaxu+rYU4BMEa2sUNYvdDtIbHL2LTUrD0K21IC10xEgnDAk2m7hBfYJauZW795fOz+vqa1Ay4GM4nxGUpWsqESbooqkP1z+xAXhRU3J1fFKy0IRTMvhnrHBgJzHyKBvmjJU/P9Ar+W0kOeqYD5kFtrG0gKNlWGEgKPp7H4jsvmU8zWcN7guipQPonkgP6R0T2Hfd/5hZejLKRQqyv4ts1HyEVHMIfPD/+wRJdb1R6aVN80VNEDYkvoihuu8y2hrw5hk58jGlA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Mg0EG9jyZ1sq9/BmNNBYOGVTgJOCH8UybdaYtPghJi4=; b=lhzX4tyz6elSWDbxAnnrqIsMVj1KKi4tcQuNq2RfZZYF3+ZQoOnWYCQX5oIrhOxHTKYKW7wdyGj2aN9ZviFUaJbeA/EgSTRojEn6sf1g2b5P/CHvTHIK7jtDxnodJq5qgi23HbPveXi/tbQY85NQchgrKOnv+G7dV1p6NcDluY0= Authentication-Results: kvack.org; dkim=none (message not signed) header.d=none;kvack.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB3077.namprd10.prod.outlook.com (2603:10b6:a03:8c::12) by SJ0PR10MB4590.namprd10.prod.outlook.com (2603:10b6:a03:2d1::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.20; Thu, 4 Feb 2021 20:25:15 +0000 Received: from BYAPR10MB3077.namprd10.prod.outlook.com ([fe80::74a8:8649:e20b:d571]) by BYAPR10MB3077.namprd10.prod.outlook.com ([fe80::74a8:8649:e20b:d571%7]) with mapi id 15.20.3805.024; Thu, 4 Feb 2021 20:25:15 +0000 From: Joao Martins To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Andrew Morton , Jason Gunthorpe , Doug Ledford , John Hubbard , Matthew Wilcox , Joao Martins Subject: [PATCH v2 2/4] mm/gup: decrement head page once for group of subpages Date: Thu, 4 Feb 2021 20:24:58 +0000 Message-Id: <20210204202500.26474-3-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210204202500.26474-1-joao.m.martins@oracle.com> References: <20210204202500.26474-1-joao.m.martins@oracle.com> X-Originating-IP: [94.61.1.144] X-ClientProxiedBy: LO2P123CA0104.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:139::19) To BYAPR10MB3077.namprd10.prod.outlook.com (2603:10b6:a03:8c::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from paddy.uk.oracle.com (94.61.1.144) by LO2P123CA0104.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:139::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.3825.21 via Frontend Transport; Thu, 4 Feb 2021 20:25:13 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 591bc5d8-446a-4b84-381b-08d8c94afb1f X-MS-TrafficTypeDiagnostic: SJ0PR10MB4590: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VzZFmrYx8iaUxMHD8ZPjVkv4IO68S9G7x1v26dsKFCQBJYWRKUFmyRxnpbtq3wsfOwDTNZEXVNTYuvz3ozBREleDZ1XRfQ40aICF8+qAPfhnWFxIxGJdbpgQV4eOAz4Ks09Qzghda+HR3nL9bNZlpel+16wa5l/ugPBmCw2w124B7WCQZ1dg1cOcS9pT5KXDopUDUQ9tIk1P5xj+A/lKA2uzJMewFIPgdefGNF5zE7rvSXhZRRDLNJ+/dbyu9qqqQGzmv7+Arg1jcjOTdkp4Q0Jb5tzJGQUqUJZ6Ubt9FbiE8Bd1MlWRNEj8vuywsrhz5ydLOilb3MHjuZFi2UBtSjlHJ7TdYqXVBixizLE1xbKXRgVC/g78A/Z0E7u8oKVOTO06tAQM4vGdYAvn8xuo/+vY0Xsn/RV3WfaTP1nOF9uEitk8TSWcMvRTEY/PBtxmDOEqvo6YbRDsUUCqMzfOv7rrRcJlyElrJcp8eO7ex/DzG0+SYzEImaMkI0WSq/9L/d859g7nHvFRzJ02VoDOfg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3077.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(39860400002)(346002)(396003)(366004)(376002)(136003)(52116002)(7696005)(26005)(2906002)(16526019)(66476007)(186003)(66556008)(478600001)(103116003)(316002)(6486002)(66946007)(956004)(54906003)(86362001)(5660300002)(1076003)(8936002)(83380400001)(107886003)(36756003)(4326008)(6666004)(2616005)(6916009)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: svZl6ozDJnxKppplU2Xj+CdHRf1s9sVexj3nCSzgz1dV5cl37RMnjruCxcUc1UKaTSlxNDdy9+TF6TlMIPAG8RIOR3JKVoJb5kd3SnKtimrYMc30QOZ46OEypP03fVy8rbwc/jfUuiHZ6d6AMX7C83w06anGFHpMEaLe0ixd7ww9nZMhJdM52WNwH6pva2LYm7VWs1wYsasKaYJ2mDk5FgoCixqaxIn6gXc6RwW1sa6xGa4szlvk7hsg6alpOl3w5x4RKtJrbk4aQ4Zn7ZXO9THEQNptQQL7sVq5JRLjemPgWlantCU8fAa4FgyQsrMsH067+qhwj3eBFjrZfHWhZvTVYBijxsJ0hJzcMXcIaLxMeqw2MEK13fjShF4DPtse0FxApwCRS3dZEzw8JkYJQrlXiXuFw/8weMEJu5t4cJAFqAT+nwm9DTp7DRgGKH57FWnHkzib+ly/RO4smN4IM1cgSdbpp7lXjX0OoRJ412w0Z7Qg+MP2z/s1qKh2XUeKcpnHvNgfj5w9+0cCKCA0FeD8HSqq18y8ti5X1zq+YIEOc/+4VK1/i2+q6zBROZotEDgGlb/5i0e+wh2Ept2LUMdwKQppi6gp9iFh5vn9TnGD+tkgi3ysltRnkSCwhxbU/itTYuXb4/z9jw1UqjQguBYJzddb5c0yn+lTC88Vy855P0mj32cghOnNxax2GGW6iJUdm7HHw3rX0YNuI+Vrm9FerSEfmMy41NMeSfPf+yMQ4HBMSPlISuS5DT93a9vps3ji10cq8T+ljFEbHJbN5WyNoxRHFgjAOsa35cLp0Zbz4jMfj+OFmC7W+gkcRyQKpRrz1YzM6mO5pT292WBzGt0TteX0PsMpn+BXASjFmjfSROyDku+yR161JfRVoXsoeu/um0ltbekvAZbq6CjLf0BRlz144ZcXoNnyxc8fCyLdmM4I3qGNzmZxLn7DPmIscJqy7hJj4xpWeOkz52tzsz/8iyOSiMa5WyfoQq82tQsoDoJXpq/BnAh42s9v2i7PnPjr4kup8kWDHWLZ+yUAfpRyw8ZjpG3uZNnfG8MEiS/oaoJ0Ky+7wDhcsUhSX1Vs X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 591bc5d8-446a-4b84-381b-08d8c94afb1f X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3077.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2021 20:25:15.2354 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jxlLFD8qzSXD3HFipxxcKvc8aoQYXWpX438mWK7bsalqDckNrsF2U/2cINMCA9w4FJj4T4S0wbrhG0xEwj8EgCbneHi0LxxMSdpY/z+iobA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4590 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9885 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 adultscore=0 suspectscore=0 spamscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102040124 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9885 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 adultscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 clxscore=1015 spamscore=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102040124 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: Rather than decrementing the head page refcount one by one, we walk the page array and checking which belong to the same compound_head. Later on we decrement the calculated amount of references in a single write to the head page. To that end switch to for_each_compound_head() does most of the work. set_page_dirty() needs no adjustment as it's a nop for non-dirty head pages and it doesn't operate on tail pages. This considerably improves unpinning of pages with THP and hugetlbfs: - THP gup_test -t -m 16384 -r 10 [-L|-a] -S -n 512 -w PIN_LONGTERM_BENCHMARK (put values): ~87.6k us -> ~23.2k us - 16G with 1G huge page size gup_test -f /mnt/huge/file -m 16384 -r 10 [-L|-a] -S -n 512 -w PIN_LONGTERM_BENCHMARK: (put values): ~87.6k us -> ~27.5k us Signed-off-by: Joao Martins Reviewed-by: John Hubbard --- mm/gup.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index d1549c61c2f6..5a3dd235017a 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -270,20 +270,15 @@ void unpin_user_pages_dirty_lock(struct page **pages, unsigned long npages, bool make_dirty) { unsigned long index; - - /* - * TODO: this can be optimized for huge pages: if a series of pages is - * physically contiguous and part of the same compound page, then a - * single operation to the head page should suffice. - */ + struct page *head; + unsigned int ntails; if (!make_dirty) { unpin_user_pages(pages, npages); return; } - for (index = 0; index < npages; index++) { - struct page *page = compound_head(pages[index]); + for_each_compound_head(index, pages, npages, head, ntails) { /* * Checking PageDirty at this point may race with * clear_page_dirty_for_io(), but that's OK. Two key @@ -304,9 +299,9 @@ void unpin_user_pages_dirty_lock(struct page **pages, unsigned long npages, * written back, so it gets written back again in the * next writeback cycle. This is harmless. */ - if (!PageDirty(page)) - set_page_dirty_lock(page); - unpin_user_page(page); + if (!PageDirty(head)) + set_page_dirty_lock(head); + put_compound_head(head, ntails, FOLL_PIN); } } EXPORT_SYMBOL(unpin_user_pages_dirty_lock); @@ -323,6 +318,8 @@ EXPORT_SYMBOL(unpin_user_pages_dirty_lock); void unpin_user_pages(struct page **pages, unsigned long npages) { unsigned long index; + struct page *head; + unsigned int ntails; /* * If this WARN_ON() fires, then the system *might* be leaking pages (by @@ -331,13 +328,9 @@ void unpin_user_pages(struct page **pages, unsigned long npages) */ if (WARN_ON(IS_ERR_VALUE(npages))) return; - /* - * TODO: this can be optimized for huge pages: if a series of pages is - * physically contiguous and part of the same compound page, then a - * single operation to the head page should suffice. - */ - for (index = 0; index < npages; index++) - unpin_user_page(pages[index]); + + for_each_compound_head(index, pages, npages, head, ntails) + put_compound_head(head, ntails, FOLL_PIN); } EXPORT_SYMBOL(unpin_user_pages);