From patchwork Fri Apr 9 20:52:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12195069 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.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 71B38C433ED for ; Fri, 9 Apr 2021 20:53:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 03B5860FEE for ; Fri, 9 Apr 2021 20:53:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 03B5860FEE 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 347E06B006E; Fri, 9 Apr 2021 16:53:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 20CCB6B0070; Fri, 9 Apr 2021 16:53:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F03866B0071; Fri, 9 Apr 2021 16:53:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0112.hostedemail.com [216.40.44.112]) by kanga.kvack.org (Postfix) with ESMTP id D50296B006E for ; Fri, 9 Apr 2021 16:53:29 -0400 (EDT) Received: from smtpin33.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 9DB27BF04 for ; Fri, 9 Apr 2021 20:53:29 +0000 (UTC) X-FDA: 78014029338.33.AC52F9F Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) by imf20.hostedemail.com (Postfix) with ESMTP id 8E929DC for ; Fri, 9 Apr 2021 20:53:25 +0000 (UTC) Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 139KnFTX070792; Fri, 9 Apr 2021 20:53:13 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-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=3wVwMkjo2Ou9kKq/aTmPNbq1CAbDNjcVaM/Z5DzD+p0=; b=tsVhhosUSqicg3YAkNr7WgXS1uaD4D4+9Ylz047t/HKT4Tjlj5knBZsQJHFz5ps0/KyO Z+8qoit9HPVkLk2erj0HwAvIDlJIcyotJvDxpDuuZstqQ7Dayzadq1m/cB/3I3jSEpvi mvfkpQinsB3rGnlHs1lE1+m5nYVmtH7QLTyACgHCfwMqHcY6wQSM3FuoqoHQ4FjZqi5k k+qew084BGAEPnofwzw33NteS1XZxYzHEQeM/coflJhuXWT7XksHq1UiYwWsLkDHRtzk W3sIsM2TeFrsYEJV+rHH49DjbqqRvwfdO5579d/7TUy1Y8fxRjFlX5s0vQKLDBfV2qlT nw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 37rvasaq54-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 09 Apr 2021 20:53:13 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 139KjFUd022483; Fri, 9 Apr 2021 20:53:13 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2109.outbound.protection.outlook.com [104.47.70.109]) by userp3020.oracle.com with ESMTP id 37rvb30bvh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 09 Apr 2021 20:53:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FOZSjEPmv3x+pheCnpqroz92279rDUgNpKr1vc/Zn1zNKmruZUvfX+M+TTy+r61JnE7DHM0PsUOrTepHUOFrCN7h3Ovzq0wP6trMOfdT46Xiw5tDLyfvDPHtHjPRBt4MtV2JuUbcx7TTqyUbQp9Zy8YRJqgzHhd7lDbkYSMmecGqC8Eqslce4GjL/rZWo9Uj/BnW8AZDkdAjrGTx7TORfaPOjsRBIzck/TZFwB5cP0nJCTKOfbGDpoVTgszz/Z62rYrNsMJBK0TLpHCdQ2qlWnN2zCU5UHpFe7enwD78nPy3AAvmZpHAxtw7Mu5AgRlQQQHwMhJBMIRRG3GuwPxhKQ== 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=3wVwMkjo2Ou9kKq/aTmPNbq1CAbDNjcVaM/Z5DzD+p0=; b=XopASjQcXfAd2JKynu6FUq0NjVKse7yal1AM8Bh2EizfD5vJo/lqB4PgRfuVNTV5Cpm4vLskKJ6oMZH46wBUs3JRRMZWGMA5CIG2ecXKejuGI5awtil65yt2wPyo7RTlDTXBdA6k688+H1kIO8bNZZDx0j2/yas4SjvS8V+BOHxlPFQYwB2dOIPpEdxpRPH33VqFQErWA1QUIxPsr5DIgi3WL6FtglTB/g2XGcGOI+I+yeoAfK4GSAh5VqoHBPQvt2/T1LW9qdKzDnnxt3sp/yOjjqgCuRiQh/IN50BucuZnx94NiYgCsL/TxG7/wFqXD+WUP3hTjOmF81QQ1jCG9Q== 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=3wVwMkjo2Ou9kKq/aTmPNbq1CAbDNjcVaM/Z5DzD+p0=; b=kxDNDSQ+l6v7km9VrUReji03Zsr2hTTQM7yyxktCnUPwBHUHVIroqYCCHAMI5USA9wuWFdnz4gIL7EAZA7TJXtoT95I91D12CRW6sWg1OVM1RGUwDqc8pf//C2rdiRllFeNxKXL3d57eOXBTntS66dFlWrfHgtTCxG1GurWiP0U= Authentication-Results: kvack.org; dkim=none (message not signed) header.d=none;kvack.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by BY5PR10MB3972.namprd10.prod.outlook.com (2603:10b6:a03:1b6::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.32; Fri, 9 Apr 2021 20:53:10 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee%7]) with mapi id 15.20.4020.018; Fri, 9 Apr 2021 20:53:10 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Roman Gushchin , Michal Hocko , Shakeel Butt , Oscar Salvador , David Hildenbrand , Muchun Song , David Rientjes , Miaohe Lin , Peter Zijlstra , Matthew Wilcox , HORIGUCHI NAOYA , "Aneesh Kumar K . V" , Waiman Long , Peter Xu , Mina Almasry , Hillf Danton , Joonsoo Kim , Barry Song , Will Deacon , Mike Kravetz Subject: [PATCH v5 1/8] mm/cma: change cma mutex to irq safe spinlock Date: Fri, 9 Apr 2021 13:52:47 -0700 Message-Id: <20210409205254.242291-2-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210409205254.242291-1-mike.kravetz@oracle.com> References: <20210409205254.242291-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: CO1PR15CA0050.namprd15.prod.outlook.com (2603:10b6:101:1f::18) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from monkey.oracle.com (50.38.35.18) by CO1PR15CA0050.namprd15.prod.outlook.com (2603:10b6:101:1f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Fri, 9 Apr 2021 20:53:09 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9059c936-73f6-4183-4ac5-08d8fb997c26 X-MS-TrafficTypeDiagnostic: BY5PR10MB3972: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JF/qh+Q4bjjvgbnH7VL7hPHQhAkg2oDOxmiWLrC0//5jCZYm3SaRmmMdfxEXRjAqx53cHRo5Wk/d0GD1ayc7/XZIXwVSeRSUnb9VPnM5moqpZWpTvcN89QJHE4Tlz70+m1avfwYSHOcHKuaxPj77J5Ej+takRFBVU7mpCmrkEnzY0XrXeQwvA6Hqii1NDgJfTYjYaoHUT5+wVGcGfmgIyuPAo0ECRCZBqZ61XCf50HYSf9NWFn90dzdivVFi6xDKdYG/0vrG+jk4HS6IotMRkGssMWJFhI9Ra0H1yXZKsJgmlXU9SK5MwzEfPJhjVJ3uZwKu3ZFRxfYgOqsYj91/X1tvATnS0dYKN+xy1qPrM6b3wcH+js4+3QAhSHnhGo9toZbQYzDTWcLSV4/WfqWGWUVa1mZjqf+2JPPTZJ/FIBC6c2LCfn2o+aJapSPwbNO9Ax9idt6QPSxaahDLvpnAzvcewALZ+FB9xUZHrM2yzI6/C5iUYIK8sHOKU33hAKq5145fwo0vKb7OaQpO8dzs0w8Tajgkk03dikyqqRCFf/1JAULk14tHLFIZgt3rDU32MGQ25WZrqjj9eqc6Fc2KjlXs86WN00BILNI0eezdUb6Rax6rg/FVk0TH6lrvTWevwYV8BXj65FWKK/zgOOOSeJebZVEOQtW3/aGKILAVSIjhCdHNKwiU/OMvkHF9U+GK X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(346002)(396003)(376002)(366004)(136003)(39860400002)(38100700001)(5660300002)(66946007)(7416002)(956004)(6486002)(83380400001)(66556008)(8936002)(66476007)(4326008)(316002)(6666004)(6916009)(54906003)(44832011)(7696005)(2906002)(478600001)(1076003)(52116002)(16526019)(38350700001)(107886003)(36756003)(26005)(86362001)(8676002)(186003)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: ne+pma5PdNP5YpcsVI8N/TQIvabIF9NDZIT0k3lOEYYmTSwqp9twZOSdW0em20iZXI/HqLPkbHsT7eC26qBtSapRZndPOOQD9UtZGRGORsbAdfbJ11IUyiGPq4SQYFncvcJhpd3qvwTyUtW4IJyGBegvk0Gg93KwWCdfTgVzWSkBECVnaXcjNlftNKXxFB3W7iCtkLR5Aru3tnBlknT6VDHP9QtPig/DNLSv6fFNPoSsX8E7+GX5puVZHsR4XC4VohYpgzQTOlrPBaVMhz7f/fON0waPcMYsjC2WhpJ2RdA4oQIKBRQd39Uia5IshIU1H/VAAzuO0WtydVD4QwlV6nOwzuj57aGQ7T0OIKbP5e9cEuqyz58PbqWQwKRb5SB8l4T6YeVkVAF2w2rcyk6r+THIyNojorzY0DEWqDgZwMMIRVvW2z28wrFTHUjMqXOMxF4vdJ9VveZquwDzVZMPeryG1hB7lyfggoSUrCP///CPGQHB6GVknR48HfubigqLwe59wTJ+CNEZWkdCMjnKWNUXl6FQ6ZiVVS2t6p5mhlew9e90gzbxZfLxfUOnF5ufll+kEjikHa8Qo4mLSZBs4Cfk/P5aw80Ztn2cyCf11CbwfAbqj6jEZmKEmt93lCCi/UMHH7ZIhghCoz6wxOVS4XMVKTbMm4NjBzM8XnEIDMkEOitj/s1kYTMg/on5CjViQpat5gjSFDqV0PS+BR+zyRVRCEeqSsfJWwoeaA6iNEbhsTx1wwhTiNtYenZvVGVc9ymCf8GPiuJa98K7aGHhSBHcWUVRO9FovDIQ94NAdafYmoH9O7P0QXDATUlxdTTvNkVcukGvYe4aaF01HruyY8dfxxVHd4/c1I9qi/TPAciEyAaoIRCO/D43OghUA7NZfbzR0/4s17ajSz9eWQznRYlkU2zV6WUkvPKU4yhN1HmUybMKAgrpoH4/t82H/L6fmJkCphiKR0rcaMqPEd2HqedFfUxueMT4VmdeP7Cd6AOrefBNfQG//sKs9H7fdYN4jLSNnOqBkKTV4FAhdJ4BrFAHEy6e18O6m8zJL4E/U7JJz5b5Ozi3Vqr2rRiLTZoaTfbSWutgb7N/8dVf/I7E8xyappeZCpQatB8D3hW94lwEhOBgzCJXpxpAixBj+7eQjnZIJLtEZ68kzEv60T9nhQhk90KMqwLNTivhwvwaxY0Lj5RF+mA0JL6d9iQeaJFULprmpk/eadF7nM/0gBkO7EhYd+J57I/g6SYvRVhFenJOs8cJch8KpQ7Sio2BCKPhvj3lwEjp9a6HjOkYHfzqaQRzM6D/Uq5v0OLBbw7cbSAv/2qhYSDV4BtwDnWuwshp X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9059c936-73f6-4183-4ac5-08d8fb997c26 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2021 20:53:10.7055 (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: PNv7sxrtZittZ3xDiNlXhL0elAzCKwCFnyqdAzHw38kZEQh0W0XAnw3NM2T8h2Sow2HDn5s/P2Qo8VrculRoPA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB3972 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9949 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 adultscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104090152 X-Proofpoint-GUID: Z10HSZcqLFaat_LyEweLj1nZ3RuCTB_e X-Proofpoint-ORIG-GUID: Z10HSZcqLFaat_LyEweLj1nZ3RuCTB_e X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9949 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 adultscore=0 priorityscore=1501 malwarescore=0 mlxlogscore=999 clxscore=1015 bulkscore=0 mlxscore=0 phishscore=0 spamscore=0 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104090152 X-Stat-Signature: uqbr7dyw1of6k9eikyfkniyh73bz791n X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8E929DC Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf20; identity=mailfrom; envelope-from=""; helo=userp2120.oracle.com; client-ip=156.151.31.85 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618001605-537170 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: cma_release is currently a sleepable operatation because the bitmap manipulation is protected by cma->lock mutex. Hugetlb code which relies on cma_release for CMA backed (giga) hugetlb pages, however, needs to be irq safe. The lock doesn't protect any sleepable operation so it can be changed to a (irq aware) spin lock. The bitmap processing should be quite fast in typical case but if cma sizes grow to TB then we will likely need to replace the lock by a more optimized bitmap implementation. Signed-off-by: Mike Kravetz Acked-by: Michal Hocko Reviewed-by: David Hildenbrand Acked-by: Roman Gushchin --- mm/cma.c | 18 +++++++++--------- mm/cma.h | 2 +- mm/cma_debug.c | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/mm/cma.c b/mm/cma.c index f3bca4178c7f..995e15480937 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -83,13 +82,14 @@ static void cma_clear_bitmap(struct cma *cma, unsigned long pfn, unsigned long count) { unsigned long bitmap_no, bitmap_count; + unsigned long flags; bitmap_no = (pfn - cma->base_pfn) >> cma->order_per_bit; bitmap_count = cma_bitmap_pages_to_bits(cma, count); - mutex_lock(&cma->lock); + spin_lock_irqsave(&cma->lock, flags); bitmap_clear(cma->bitmap, bitmap_no, bitmap_count); - mutex_unlock(&cma->lock); + spin_unlock_irqrestore(&cma->lock, flags); } static void __init cma_activate_area(struct cma *cma) @@ -118,7 +118,7 @@ static void __init cma_activate_area(struct cma *cma) pfn += pageblock_nr_pages) init_cma_reserved_pageblock(pfn_to_page(pfn)); - mutex_init(&cma->lock); + spin_lock_init(&cma->lock); #ifdef CONFIG_CMA_DEBUGFS INIT_HLIST_HEAD(&cma->mem_head); @@ -392,7 +392,7 @@ static void cma_debug_show_areas(struct cma *cma) unsigned long nr_part, nr_total = 0; unsigned long nbits = cma_bitmap_maxno(cma); - mutex_lock(&cma->lock); + spin_lock_irq(&cma->lock); pr_info("number of available pages: "); for (;;) { next_zero_bit = find_next_zero_bit(cma->bitmap, nbits, start); @@ -407,7 +407,7 @@ static void cma_debug_show_areas(struct cma *cma) start = next_zero_bit + nr_zero; } pr_cont("=> %lu free of %lu total pages\n", nr_total, cma->count); - mutex_unlock(&cma->lock); + spin_unlock_irq(&cma->lock); } #else static inline void cma_debug_show_areas(struct cma *cma) { } @@ -454,12 +454,12 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, goto out; for (;;) { - mutex_lock(&cma->lock); + spin_lock_irq(&cma->lock); bitmap_no = bitmap_find_next_zero_area_off(cma->bitmap, bitmap_maxno, start, bitmap_count, mask, offset); if (bitmap_no >= bitmap_maxno) { - mutex_unlock(&cma->lock); + spin_unlock_irq(&cma->lock); break; } bitmap_set(cma->bitmap, bitmap_no, bitmap_count); @@ -468,7 +468,7 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, * our exclusive use. If the migration fails we will take the * lock again and unmark it. */ - mutex_unlock(&cma->lock); + spin_unlock_irq(&cma->lock); pfn = cma->base_pfn + (bitmap_no << cma->order_per_bit); ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA, diff --git a/mm/cma.h b/mm/cma.h index 68ffad4e430d..2c775877eae2 100644 --- a/mm/cma.h +++ b/mm/cma.h @@ -15,7 +15,7 @@ struct cma { unsigned long count; unsigned long *bitmap; unsigned int order_per_bit; /* Order of pages represented by one bit */ - struct mutex lock; + spinlock_t lock; #ifdef CONFIG_CMA_DEBUGFS struct hlist_head mem_head; spinlock_t mem_head_lock; diff --git a/mm/cma_debug.c b/mm/cma_debug.c index d5bf8aa34fdc..2e7704955f4f 100644 --- a/mm/cma_debug.c +++ b/mm/cma_debug.c @@ -36,10 +36,10 @@ static int cma_used_get(void *data, u64 *val) struct cma *cma = data; unsigned long used; - mutex_lock(&cma->lock); + spin_lock_irq(&cma->lock); /* pages counter is smaller than sizeof(int) */ used = bitmap_weight(cma->bitmap, (int)cma_bitmap_maxno(cma)); - mutex_unlock(&cma->lock); + spin_unlock_irq(&cma->lock); *val = (u64)used << cma->order_per_bit; return 0; @@ -53,7 +53,7 @@ static int cma_maxchunk_get(void *data, u64 *val) unsigned long start, end = 0; unsigned long bitmap_maxno = cma_bitmap_maxno(cma); - mutex_lock(&cma->lock); + spin_lock_irq(&cma->lock); for (;;) { start = find_next_zero_bit(cma->bitmap, bitmap_maxno, end); if (start >= bitmap_maxno) @@ -61,7 +61,7 @@ static int cma_maxchunk_get(void *data, u64 *val) end = find_next_bit(cma->bitmap, bitmap_maxno, start); maxchunk = max(end - start, maxchunk); } - mutex_unlock(&cma->lock); + spin_unlock_irq(&cma->lock); *val = (u64)maxchunk << cma->order_per_bit; return 0; From patchwork Fri Apr 9 20:52:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12195071 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.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 837F1C433B4 for ; Fri, 9 Apr 2021 20:53:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 11DA861108 for ; Fri, 9 Apr 2021 20:53:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 11DA861108 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 A00196B0070; Fri, 9 Apr 2021 16:53:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 95F986B0071; Fri, 9 Apr 2021 16:53:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 763A56B0072; Fri, 9 Apr 2021 16:53:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0204.hostedemail.com [216.40.44.204]) by kanga.kvack.org (Postfix) with ESMTP id 4744B6B0070 for ; Fri, 9 Apr 2021 16:53:32 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 03557AF68 for ; Fri, 9 Apr 2021 20:53:32 +0000 (UTC) X-FDA: 78014029464.29.5D00334 Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by imf10.hostedemail.com (Postfix) with ESMTP id 882DA40002D3 for ; Fri, 9 Apr 2021 20:53:27 +0000 (UTC) Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 139KoYvq128542; Fri, 9 Apr 2021 20:53:16 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-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=bt9Rgw2Wi1977yVo8yxhNFJ9syZSk12iVGxQE7xzr7g=; b=DOCtLnHK9Kraut3bf6SOVVcIIZpL6hhxF/kSj4ENTxQMElv5un242vrtBLz0Nii1x2Bm 1zfufmryfWUVgxkigoeMyg/21vfQSuYEZSklUIoSp1ExTZ87UqY41Peeh8XFPI269eEP W1ZQB15A4RcyfkoXFGx0uz8mMckkp7Ptg/KLW28amdOOrVR2PcPwBRjZr+qOleEkdn24 HbQtG4RQQLOYgVgSH6lXcISAjOvpulhez0OO4zonEP19xwZ/VL5+CyJfgEJpCnFZpGff ozeTNub16BLgM9LorlGXST+gRxJabSmojx0MM5KUUNXUcVh6NhkEjAFGZ/oqjous6lXQ vw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 37rva6apk7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 09 Apr 2021 20:53:16 +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 139KjSfU174393; Fri, 9 Apr 2021 20:53:15 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2101.outbound.protection.outlook.com [104.47.70.101]) by aserp3020.oracle.com with ESMTP id 37rvb71qjn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 09 Apr 2021 20:53:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ihnz3nX559IqwtZLMlfUkRtMDDvQBExiyrX3g8dEhnRJSvPR76o2JDU8E0DLUeAKn6EOVQ9MHTyIbyHJ+t/3wC9HJ9ICzuwBfXH+GDUIXJogPXgsTUcbCfRXl5Deb/o6xBAbgy15WuC4sn1Ec5eRvVwwExx4P6M83iXRMWPHutBqxT+fmyu1gsNm1Jj5CAN0AdUXJ57Cy9g0fCxN4ka0VkC6QKEaE60Txve95+NYt6/BvNVsmn7LesDMB+esC0UeBpv/8Z26Ogrwi0qkc6ou7QW26nuetsT2TD2I5HtngbGZ9hb+T2up/dIJkTEUKwgNZHLJRAhBVYNkqsujDkVH+w== 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=bt9Rgw2Wi1977yVo8yxhNFJ9syZSk12iVGxQE7xzr7g=; b=TQPYeWQEmwUvPuZefaxATnUuJtsRrb+rx54WRUBRRwpN/WAtTQZXB4QbM7KOCHo9R2nbm3w6j6jhnYg+UfR+mYIAOwPOaQ7HHOGH7rZOggz70WHClwYCBm779nnpFELrdyd/PdkAYPivV8Xady+hJfXA6ntBvru6dE9B2i/Dg+tbd9oHPYzJeAEKzhcq3RW9gHlmkPVYz1ywRYQIVtWDqXgI65SZ71otvMhc45a827DT7Mi1qFKWvswXuzeXxtIW9c1MlBMFrFvZgFLCGJOc4VblM4H5YzJ42WpnmFfB+OrYZ5WzoSfzOJdtXKLyixXEgpqeeIF9R3e7IQTNbAUpTw== 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=bt9Rgw2Wi1977yVo8yxhNFJ9syZSk12iVGxQE7xzr7g=; b=BNp8vIwiGZw8JFXBo7MxLadHzDoWONpBFQ1Nvl3TSWjzQoGcEtBgGzcnYO7zfuYc+9jdnqQkk0Q/IQziTKylAV2Z9Qfa0/Jke13HlzBtCbK15J/HMTpDcYuDx26wDK2WgDzfTfNO02Lsgb+4uxqyFLP9drgMvt+byq+xzZxPImc= Authentication-Results: kvack.org; dkim=none (message not signed) header.d=none;kvack.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by BY5PR10MB3972.namprd10.prod.outlook.com (2603:10b6:a03:1b6::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.32; Fri, 9 Apr 2021 20:53:13 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee%7]) with mapi id 15.20.4020.018; Fri, 9 Apr 2021 20:53:13 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Roman Gushchin , Michal Hocko , Shakeel Butt , Oscar Salvador , David Hildenbrand , Muchun Song , David Rientjes , Miaohe Lin , Peter Zijlstra , Matthew Wilcox , HORIGUCHI NAOYA , "Aneesh Kumar K . V" , Waiman Long , Peter Xu , Mina Almasry , Hillf Danton , Joonsoo Kim , Barry Song , Will Deacon , Mike Kravetz Subject: [PATCH v5 2/8] hugetlb: no need to drop hugetlb_lock to call cma_release Date: Fri, 9 Apr 2021 13:52:48 -0700 Message-Id: <20210409205254.242291-3-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210409205254.242291-1-mike.kravetz@oracle.com> References: <20210409205254.242291-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: CO1PR15CA0050.namprd15.prod.outlook.com (2603:10b6:101:1f::18) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from monkey.oracle.com (50.38.35.18) by CO1PR15CA0050.namprd15.prod.outlook.com (2603:10b6:101:1f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Fri, 9 Apr 2021 20:53:12 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 758335e7-909d-4e1e-ee17-08d8fb997da2 X-MS-TrafficTypeDiagnostic: BY5PR10MB3972: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FWFcgWBTToIP1DTNhdDflvAjfcrigng0wEZa/MTZR5ifLJyB3aD6c5EuPNKHI8iGYk/WI4qXyrCGOATYfu9X5nOjaK61g/PsbzS7mVmTVfnOdagcchqtCPrG1JL4l+NXAAT2QYw41JIHpbGkSxXVGWHUOysrPjN6ZpQs2JOxY1uSUhEytWOKJfok4+MmlKgROdAB3BZUr+eDcKBPayZFpcV4URZszleusZDEeemUoVbvXrjRxiq8JeDBiOAphEnRNCuqDnVQcggUaej0abBgiwRm605VOSOqP8SaJW5gQpEezJXjEixba/xNJmbQhTtk0OsSax3DMBqgKBeZ1migRXXU22q0Zi2i8bIlEOvxYr0vZiVRNRY8eXtfX4I7mEGwyXK8BzTeTw7hiFd8CT3h0guAVjUmn7mELl3DynqKYfxKbTQz+1dKB48F1ho+SBy9WS34D9jBmmevCpPo9LUXvT2zDz8uT2Edov5BfBmXG/Qm3h5OFq3qHC2zmeYgJ4tcwiUnUxrkHZFVdXAVEuqoYcF7qWN2/m1lz0kic9rLgpu829b2q9NdH9eaKwrDWrJBwtPpXZCdSVPKvsiLfcZlm9wC0vg+oGYUmpFrB/p3lVn4kpo/5hHc+jDO+ASSD/U+ol1P1USqB5XOmJFnQioRaRIhx1WDz7E62g8LQvtSziLR0hJM3g1pPIuxE9OAYmH9 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(346002)(396003)(376002)(366004)(136003)(39860400002)(38100700001)(5660300002)(66946007)(7416002)(956004)(6486002)(83380400001)(66556008)(8936002)(66476007)(4326008)(316002)(6666004)(6916009)(54906003)(44832011)(7696005)(2906002)(478600001)(1076003)(52116002)(16526019)(38350700001)(107886003)(36756003)(26005)(86362001)(8676002)(186003)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: tZEu7sr7r4Li06yIIrpnLJVXvm/pk7nImDQ/JlkW0IFzzbAQIjAMCIM1VIkL1XXY60cpxi9ZSGDahLo7n9NQiwdQe3EkwsSJrfKkG3slx9STfGr/S9+IsX7DRcK5I/wK/nQa7nYi2jDGkMRmkk1oPzIFYIQcHA/m1dRbFw1JpzrrWsNfSxOqqPAPfgupHqAydt0wYANz6J/tzcw0I/AqpVvwUaSE8f0hP7J5iWCUfCgVdYOufgpjixIKDB6rnqolivFTwmPQ+EIPRPQ0faurK5Mrlzo3tj0QMDqrzHoT4k4woaT7HE1yw87GO2zNXVHZlAltkKeQk/BQ1d4Im797F3305kwnoA7EEkSImmoJSqPycIlz50J4GlRq6M0H1WI/FGX7bzzgg7Jl44i+dDyHTng7ao3me/wLnHikOZyU/sQPaxJzKKIg0tU4/448UQQXiG/bpqhYnHX7BZYGeXBiF1W82nIT4effbfsj6Em3lwl5hj4afs1hz/kcXn56XmIVqdXHmT8gwE6qDBXgAO3lg6NcA4Lbopz3DrZSJaKKPteB2qsKFQqSLPRab+utCBso0Dha60mASZM2YCDSEAlkQyQ4HsEWNbl8ZC+raGmYg3PU34JyuG6B41KV3pNCHRfx474Oq3vKgSyoiyAP0i9Up8OaaQERFst2RdlXyng5oiUHcI5PCzmaJnWqGi20ROeQMbaAv55YDLLz6wd+QkxLBVmj1Ejf5DBGGBXCdj0YAfdtwp860CTSg3fChTY7/rQ0G4X680IYrJEe+c/y6du1drzXFdsUnZezcEM/n56E3B7QB/pTuBt6FvJs2ityK2zzS5Q3k/7YjI3jnefyEByLbxg1gOJxUTK52TuECM5Hq5/sYTC+E9wvucs3Hdd2+HNGY3u72iTl0ms0qin6zs3apKmk6tlCITsddqELDEkg/Z4nfWr/lKoJY5ZatD2UjnsjUeLXWBF58abOIxc5fcur4B5a7ihcAIAUlPIjLDejVDYhabnBsyUVw2PkdnW0Mk9vBEQ1zb7LoqRr6tPUgfz3SyxCOblcfihEn0PKEEvYBPpM9TKe3RCZtyKuE1C9Iq7lz7Dz4MgZQ5h6jq3TjZ8ulhxPg1gC5GwGOuVI1fPvrqFAHbnYBuJ+G8yfHfFcE1uRxg3HrlzyoQF43nTTbo0hBk/KoLQGxNidet+QSqLmBULNYtDDORorT8omL9JtbyFokkDKvEiPaqaNQaQplnFrkqyWkxuYHtp3VAI7JsG7iwI26WHwBgNX+R9/cVBT3I8y6hG32gGvp4muCiBTaiATNrCSBXJV0mPRNVPN4amqrv3oNzGohn14fszfRmtKd/e+ X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 758335e7-909d-4e1e-ee17-08d8fb997da2 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2021 20:53:13.1588 (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: rPp/PjwDavGe/df5pzBVlGsvM8Zn5gX9InAesxBZ19VGpKwGNQ2UMbmgTCXiQ6k7kk5CRcOgeXgy9VidXYQHDA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB3972 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9949 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 suspectscore=0 adultscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104090152 X-Proofpoint-GUID: X_rOirQhibz4gh813l9hcsas-iZuZMDq X-Proofpoint-ORIG-GUID: X_rOirQhibz4gh813l9hcsas-iZuZMDq X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9949 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 suspectscore=0 adultscore=0 mlxlogscore=999 bulkscore=0 priorityscore=1501 impostorscore=0 phishscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104090152 X-Rspamd-Queue-Id: 882DA40002D3 X-Stat-Signature: 43zrticxko4aegnip3o65mbac6meky9n X-Rspamd-Server: rspam02 Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf10; identity=mailfrom; envelope-from=""; helo=userp2130.oracle.com; client-ip=156.151.31.86 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618001607-328842 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: Now that cma_release is non-blocking and irq safe, there is no need to drop hugetlb_lock before calling. Signed-off-by: Mike Kravetz Acked-by: Roman Gushchin Acked-by: Michal Hocko Reviewed-by: Oscar Salvador Reviewed-by: David Hildenbrand --- mm/hugetlb.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 07a95b8623ee..3a10b96a2124 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1348,14 +1348,8 @@ static void update_and_free_page(struct hstate *h, struct page *page) set_compound_page_dtor(page, NULL_COMPOUND_DTOR); set_page_refcounted(page); if (hstate_is_gigantic(h)) { - /* - * Temporarily drop the hugetlb_lock, because - * we might block in free_gigantic_page(). - */ - spin_unlock(&hugetlb_lock); destroy_compound_gigantic_page(page, huge_page_order(h)); free_gigantic_page(page, huge_page_order(h)); - spin_lock(&hugetlb_lock); } else { __free_pages(page, huge_page_order(h)); } From patchwork Fri Apr 9 20:52:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12195073 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.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 83451C433ED for ; Fri, 9 Apr 2021 20:53:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F3F82610E7 for ; Fri, 9 Apr 2021 20:53:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F3F82610E7 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 67AE66B0071; Fri, 9 Apr 2021 16:53:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 62D7F6B0072; Fri, 9 Apr 2021 16:53:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 31E306B0073; Fri, 9 Apr 2021 16:53:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0212.hostedemail.com [216.40.44.212]) by kanga.kvack.org (Postfix) with ESMTP id 085666B0071 for ; Fri, 9 Apr 2021 16:53:34 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id C07D7BBCE for ; Fri, 9 Apr 2021 20:53:33 +0000 (UTC) X-FDA: 78014029506.37.5402D52 Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) by imf30.hostedemail.com (Postfix) with ESMTP id E0AE9E000115 for ; Fri, 9 Apr 2021 20:53:25 +0000 (UTC) Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 139Ko0uE029060; Fri, 9 Apr 2021 20:53:19 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-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=h417aWzw347MnoAPkccllHqg7trnRDLqcpBc0czHGzE=; b=pf4VdaNqJoUF/jjKpDp/pVxcUuYke+H5LIUicZG6DuyoyxVPcQUEBEA5YBsR5OBeB8Rb AEAbbCkP+7qVvE5f7keaj3k97FSMrz6ZE5ZZvp/F3GS1Rhle/bya48cqbTwexgZGzyha ly6n+duYgHCEcWUd5W89dJLKarMRAPr8+RNrTq6Pi+C0jTgE4DI+mN8siumS+eHFIEOU u86gHPVlLOeMU9sBb2dxajfXZEy/xVpoWDMeU9PT0YROnK6EgCTdoC1GDt1OszfdqglN E/heRqmourU32WBR18ztDcQoHQqlG0bl0iVmYZs9yASamdzSAeCKnOIxGaPpcPZdVbu/ hw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2130.oracle.com with ESMTP id 37rvawaqaw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 09 Apr 2021 20:53:18 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 139KjFEV022496; Fri, 9 Apr 2021 20:53:18 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2103.outbound.protection.outlook.com [104.47.70.103]) by userp3020.oracle.com with ESMTP id 37rvb30bx4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 09 Apr 2021 20:53:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RDDCYMSzZ6DglqWQt2AI6yZB+6fzE8vCl6j6UKOM2mujWTEKP1FTG94hNJt3Uy2j6aM1bAbAFUfYe7jE9R8OXOnyPIKmhZv02/OntZFs5Nfjc58yerKJlmkLCg6r49ObclYRxxmb6ViTBpcs7SCb5fZkIhIR2EOhlfETzpU0+KWxt0dmHD7TPgz6Z7+FR+twlhBb2DF7M9Hs0tFfMvM5ACTRrnn974TxgyWEaw4MLOs1q3u1ljd/lYyDcvklIgjdvq8jR7TGNfE5I7ReiaFUmqrzMVRf3aukYuG3M9boGfeLuLHX7SNuvqWO5z4In+b/GFmT3CO78FqRAHSEn4xpdg== 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=h417aWzw347MnoAPkccllHqg7trnRDLqcpBc0czHGzE=; b=QG251vEz0Lm2TlirgQtSDn1Q/rDFutE+Mw51jMTl/FLfHri0qyBS2aOujsyLKVezI+TlRsiZDmr7ziJImdTNmRQ+iX739ZWoeyhQCbBL64zzDdwCkeh1K+MJnkc3w9Jk5DoU2ErVgapYMBSI7lbnb5K7996nVxXIVAkwCMXhj2xbt/PP+EYbLAamNoBihyrNWNmtLZV1UtbtL5nJ8/QI/7lOdZ1P9+0C0ULmpISa2qn8rfdl2pM2tyazREDcRwotPP7aI4HC2avdRN7Sh5Q/L7fZ+PWuplYxJ+X1ElnPFuV8GQ7E8s409jh0DhZEmsNzKMhlcQ4p9nCD5SNwUGfaIA== 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=h417aWzw347MnoAPkccllHqg7trnRDLqcpBc0czHGzE=; b=HyehORepqLjRmR1hrl2bsDFoI2RGjc7/1JQ7RtoS5tozmz0IA8S6jxJg0M+VN7r5heHHEn5VtjV7M34oJRPsgUFCKXrIKAc8OoGIs+goxIIvI/0T/hARfqjdvC21xwpobrwxIb6TcSiQg6Wab03KFW3im1Bd6sUKvMi/0nkqYR0= Authentication-Results: kvack.org; dkim=none (message not signed) header.d=none;kvack.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by BY5PR10MB3972.namprd10.prod.outlook.com (2603:10b6:a03:1b6::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.32; Fri, 9 Apr 2021 20:53:15 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee%7]) with mapi id 15.20.4020.018; Fri, 9 Apr 2021 20:53:15 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Roman Gushchin , Michal Hocko , Shakeel Butt , Oscar Salvador , David Hildenbrand , Muchun Song , David Rientjes , Miaohe Lin , Peter Zijlstra , Matthew Wilcox , HORIGUCHI NAOYA , "Aneesh Kumar K . V" , Waiman Long , Peter Xu , Mina Almasry , Hillf Danton , Joonsoo Kim , Barry Song , Will Deacon , Mike Kravetz Subject: [PATCH v5 3/8] hugetlb: add per-hstate mutex to synchronize user adjustments Date: Fri, 9 Apr 2021 13:52:49 -0700 Message-Id: <20210409205254.242291-4-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210409205254.242291-1-mike.kravetz@oracle.com> References: <20210409205254.242291-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: CO1PR15CA0050.namprd15.prod.outlook.com (2603:10b6:101:1f::18) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from monkey.oracle.com (50.38.35.18) by CO1PR15CA0050.namprd15.prod.outlook.com (2603:10b6:101:1f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Fri, 9 Apr 2021 20:53:14 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1e61f71d-7df2-4afe-1dbe-08d8fb997ee2 X-MS-TrafficTypeDiagnostic: BY5PR10MB3972: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: q+6wQENXQDO5DivC+Y08eXVi4YUzPnMDvpido6i0dWoa+W3GXEL5sVUnZXkq7yn6euYvjhseH5kKHJDqLRKyxoEw8QcK2tohXIXac147+u4U9tbeQSV1u9QS/qht1kPJ8s923qO3qEGrHmVSbKCUui+0NN04ukY7s/zb/S2zhEqgzMQpok23KJoxonGrS3zC/DSEdrp9HJpNA9Vtyu84sp+re95HJ1lZoy6Xbt3DwoJ0ycK/oIvi9Y7b9GHNgvpqtH5nhEjRA+JrmSY1aIpeVDrbnXIFwsPoSNEft/LWlCz/A8qIKJiRSNM9Qj7nwM4Uhpg5DYvel8uwOkSM7aTgExj1SZJqqNyoiTU8xz3PE/2wMCpeI2SFYHoMCEDz//KXjn4kYyNmrNS/BvY3OLzqfGYJKn0jHZCx8DGucNateYnWhdqKKEUoGbYB5XG8B22bKoGIb7DfYdRlSUfs6BWGfqgaCwqAcUPPmvHlJ+NwrKJ0yZJkW0IxgjxYDlaOII/yIFmFWEy+CDOQaK6C5E7i7zVcZPtn6p2CAfgsb58Bytuu9gcd9JffC/gSM+XvGJrXFnSZ4rDAwjaDl3+t/E5qZ9NaKVhr1YKfLVXMijMzfDyFHJfxmdX0UR0vWm4C95d7ygF2hBDk7K4Opf69D/iWftEffs2cRYEJ5paVBHHX7uukYQk0h4BxvuIYsw7aYPen X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(346002)(396003)(376002)(366004)(136003)(39860400002)(38100700001)(5660300002)(66946007)(7416002)(956004)(6486002)(83380400001)(66556008)(8936002)(66476007)(4326008)(316002)(6666004)(6916009)(54906003)(44832011)(7696005)(2906002)(478600001)(1076003)(52116002)(16526019)(38350700001)(107886003)(36756003)(26005)(86362001)(8676002)(186003)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: gyGadv5lIE8arTMxqZvAVSeZCmHHJCEm7sjv8QSdVeWQ2McxTvOLSbIJKMddU7WdMoTJIO4n0uIeCDqb/wlx3UlhYzecxY4xvB1MKKyE0Ho2OU4JTQ2ao8//31rVfeGTJV8J+QnTIbkJLBNed2oBI2ZJmtq3oyMUzL0GMtBISU/lfOdAkWUMawvWQnIC23TaQDhXw+Wa/vtdiDPoFniUyC7XyM+9dMPimMVXP1N7zByFWepaiolFyj/bfMWG1t/1F+a+9H6UD0ClLqIxQDheMhHVYwqKB+DZVgmPbR8aLaMmsR/F+gMb4ML0WhzdZoxTDXef/z+bI0eLCw74dZkZcg6iOV8zQHAL9KVD57NScIpiacvfAnCvJboRt/CTy+cM5+4P9cupcuuNPCp/yMQjT41iHF1lQPGe2U0KDlwtTcOLqLnMw0n3HolcEGWrqGDWkB8iwHVIbfIL1dfnIPFdn886Ja+6R0exNp+/h8pGHA6uwqYckHk0IyC/J96+TNJswplyEwRcV2j1b0ZFh1aNM/qN55Ufv8vAx7o6RzjIT1WPijzjUpLqt4hW9q2oGfp0Mv+GLYaUk7xeBuHJ7DKdawZs6u/c93QaC0zEMZnOmg2MF1nVGJmlEcBc77XLRrjCrfbKHCtRM2ojXDojMQloIoa1LzDAnGheSh2OOJmuTl5FzTtYGuuo5TL8JTmynm7ZblCNlNYqqi6AUBy6T/b0G45BfmWE9qQHn5EJHINirlJSDgID+ElFIUvv3YanU8ii5bg8EKMGvpPIIFUewMr7ckNz5nQa+WkYMKrvfbd+9r/Al+0FLC6+/9G0qbWx6dhbzYkJNeAnVdBJeUMWDhdg/lyKt0s5Pyu+AQ85sfby2DK6Vs9zIG4SeqK8f0ZeYrpdhgSNXk7P/kUQxiZJpAMzXTrMtgq9ggVAwMevJhRKT+uzIbf4Pp/Luv7p1pjHuDKbbHyftqo5Y2BgLluZcNu+zzWhpR0OfZGse/eMz2dDX+OUnRmlXtUybVWTo64uR/aWKL8GMQUD8MSL2kTnqYMtJYGqwO3WRBcGdnbpyDQZ/GtEq+f8OzUnD6MqLA6h5wmgujsWs8Tp32GwGdhNJ+A/xbUBlqRcs7D2W+ags4oKkaw83W2yP6YZCraatW4IZu2Qp7p5C05lssayFZJ98TurRvJjzAcLk8+bd1LUI1NwOjPkFMI5UuTAMdg5+RmrEjGu+LhYNDf1R9Pk32NZeBkf4O5gi0BH1fVfRT9iGgv2OWiIOdP6h++RFPjdM1x3uq4lQ5RlmiGhq2XBUJy5uZkYlYE120u2wR/XLApVcUwtV8upKUBi0VzUFeEz3ugHz3Au X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1e61f71d-7df2-4afe-1dbe-08d8fb997ee2 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2021 20:53:15.2496 (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: +Ooylu10KebcAtjfawTLJxsPV9KxiKRt2HJB+mtJWuuLCJWhKv8Y55PJFYvr711sG0aQVpgr3jvxETwD4k+zOw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB3972 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9949 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 adultscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104090152 X-Proofpoint-ORIG-GUID: r58iJwuVxoXUsz89nLFGlRqm4XccczSY X-Proofpoint-GUID: r58iJwuVxoXUsz89nLFGlRqm4XccczSY X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9949 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 phishscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 mlxscore=0 bulkscore=0 impostorscore=0 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104090152 X-Rspamd-Queue-Id: E0AE9E000115 X-Stat-Signature: c883rwauf6dx4jfrk51ueegqf6yg1hxq X-Rspamd-Server: rspam02 Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf30; identity=mailfrom; envelope-from=""; helo=aserp2130.oracle.com; client-ip=141.146.126.79 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618001605-541824 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 helper routine hstate_next_node_to_alloc accesses and modifies the hstate variable next_nid_to_alloc. The helper is used by the routines alloc_pool_huge_page and adjust_pool_surplus. adjust_pool_surplus is called with hugetlb_lock held. However, alloc_pool_huge_page can not be called with the hugetlb lock held as it will call the page allocator. Two instances of alloc_pool_huge_page could be run in parallel or alloc_pool_huge_page could run in parallel with adjust_pool_surplus which may result in the variable next_nid_to_alloc becoming invalid for the caller and pages being allocated on the wrong node. Both alloc_pool_huge_page and adjust_pool_surplus are only called from the routine set_max_huge_pages after boot. set_max_huge_pages is only called as the reusult of a user writing to the proc/sysfs nr_hugepages, or nr_hugepages_mempolicy file to adjust the number of hugetlb pages. It makes little sense to allow multiple adjustment to the number of hugetlb pages in parallel. Add a mutex to the hstate and use it to only allow one hugetlb page adjustment at a time. This will synchronize modifications to the next_nid_to_alloc variable. Signed-off-by: Mike Kravetz Acked-by: Michal Hocko Reviewed-by: Oscar Salvador Reviewed-by: Miaohe Lin Reviewed-by: Muchun Song Reviewed-by: David Hildenbrand --- include/linux/hugetlb.h | 1 + mm/hugetlb.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index a7f7d5f328dc..09f1fd12a6fa 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -566,6 +566,7 @@ HPAGEFLAG(Freed, freed) #define HSTATE_NAME_LEN 32 /* Defines one hugetlb page size */ struct hstate { + struct mutex resize_lock; int next_nid_to_alloc; int next_nid_to_free; unsigned int order; diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 3a10b96a2124..c8799a480784 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2615,6 +2615,11 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid, else return -ENOMEM; + /* + * resize_lock mutex prevents concurrent adjustments to number of + * pages in hstate via the proc/sysfs interfaces. + */ + mutex_lock(&h->resize_lock); spin_lock(&hugetlb_lock); /* @@ -2647,6 +2652,7 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid, if (hstate_is_gigantic(h) && !IS_ENABLED(CONFIG_CONTIG_ALLOC)) { if (count > persistent_huge_pages(h)) { spin_unlock(&hugetlb_lock); + mutex_unlock(&h->resize_lock); NODEMASK_FREE(node_alloc_noretry); return -EINVAL; } @@ -2721,6 +2727,7 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid, out: h->max_huge_pages = persistent_huge_pages(h); spin_unlock(&hugetlb_lock); + mutex_unlock(&h->resize_lock); NODEMASK_FREE(node_alloc_noretry); @@ -3208,6 +3215,7 @@ void __init hugetlb_add_hstate(unsigned int order) BUG_ON(hugetlb_max_hstate >= HUGE_MAX_HSTATE); BUG_ON(order == 0); h = &hstates[hugetlb_max_hstate++]; + mutex_init(&h->resize_lock); h->order = order; h->mask = ~(huge_page_size(h) - 1); for (i = 0; i < MAX_NUMNODES; ++i) From patchwork Fri Apr 9 20:52:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12195075 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.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 8B70AC433B4 for ; Fri, 9 Apr 2021 20:53:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 26F2F610E7 for ; Fri, 9 Apr 2021 20:53:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 26F2F610E7 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 DCC596B0072; Fri, 9 Apr 2021 16:53:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D57AA6B0073; Fri, 9 Apr 2021 16:53:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ABFE26B0074; Fri, 9 Apr 2021 16:53:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0149.hostedemail.com [216.40.44.149]) by kanga.kvack.org (Postfix) with ESMTP id 7C69A6B0072 for ; Fri, 9 Apr 2021 16:53:35 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 4114C18014EC4 for ; Fri, 9 Apr 2021 20:53:35 +0000 (UTC) X-FDA: 78014029590.06.C24140D Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by imf02.hostedemail.com (Postfix) with ESMTP id B01DB40002D3 for ; Fri, 9 Apr 2021 20:53:23 +0000 (UTC) Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 139Knf7h127832; Fri, 9 Apr 2021 20:53:19 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-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=1L9TwhsBA2v6El6t2CvKm6wFKzwQGGXKgiuMf5bHZEU=; b=Ji+3YRIXB+0ed59Sp95YBBOFGaib2lYum9eNjkOgMg9FiaEWvJoDHoqImiXvslrAfOk5 pyMV3IV1d9lSw6FMpy32TWgwZVPAb7ErYkPdjDBpNVgH5XcmZh5P9QyumzNeN3SY7Z2H uDD/hrX+2VZHcmoeZr64k5PX6tiH1BTuqlht4LDbhPKJDu5dDNjFvluyChsNstHBtbEV zFZu0IZyxaGY1xbzs/OYAwI5hby5ZDQHhx63bU2Gm2xPUJefc/lxqZpK7K51wZZz75IR x+ioeEU16aNgw8wvcWKipFPDOJMbXkUYfJjLLCLyFnf2sSGSoy7S9HwGrBSIEnz8XiQ+ rg== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 37rva6apka-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 09 Apr 2021 20:53:19 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 139KjFEX022496; Fri, 9 Apr 2021 20:53:19 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2103.outbound.protection.outlook.com [104.47.70.103]) by userp3020.oracle.com with ESMTP id 37rvb30bx4-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 09 Apr 2021 20:53:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jE7ECFMrhReICepoXYJBwjuszCZYMOFOGleOX8DviAHkU5BypYkTFMUZ+l9EvFPb5ArybaI+/5O08rXYnXENbcUbc3pb9E8g+MhyGrmlvNg4c43rK9YiK+AkkSljFvQlrG31Guzm9EisavmXlTVmGvmddANa3J2Wd6kl9/EWCbmf1XhUNoO3NTJiopgiL91Qw5nKyHZaNSXoFps0rx74hu6qqM3rGqDhJdTj5Y1Kaj6kDFKDwU+/Oq+6DY3MVBpti73HRQMCG4OKHmjmNtysbuynAxcIBgAREi3pDpZ/ZJRhNg9/C9V/9LifqCd4Zkp2Ad4dCpywzp/dhhBHQqU3Bw== 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=1L9TwhsBA2v6El6t2CvKm6wFKzwQGGXKgiuMf5bHZEU=; b=f4fIUHup2GGwb4wzR972oRhwyCxDlvtwRQJSJyw9Uf7ZsLaZ9HFObjpZZtPMwPyxd1VFYqV3Z0qoGXXlA/YVSXzYi5qo1dbwfWRO7gWRLps9qnG0WsqYK9+H0D/OvLIhXNb3jtiSCFBcAaLdLXiwm3a3doAgAgKu/qzEBrFL0WCwpUSWfk0h+K+i+zCmYSBKRGEzLqL1mDuAbX57N7jlBPIgpcvxDcJqvKr3xoZUMq8TUMgj2IA62gMFcqPgFvxCR7XMmoaObzoWLrSv4S8ZUWIuOKddh+2+MqpM8DMsLyaqnlmc58xb4wxL67VPFdJYZiDb8iMAGrYuNfPHOQYOvw== 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=1L9TwhsBA2v6El6t2CvKm6wFKzwQGGXKgiuMf5bHZEU=; b=KcnFbilCdpUn0npJp69+dTb/O776f6O2yKHfcmevhCpP+K465rTNf+tG7T2ytLJ7ydtdTZFD5Zp63ho0wrYopEEj0AXeo1H4BPdsuTaHG2QFAFkCBwehAWPvwy6xdfIzbrMVZ+dcN3aqbfBSYzVzMpFLBSxsEfbOON2nhxKxbEw= Authentication-Results: kvack.org; dkim=none (message not signed) header.d=none;kvack.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by BY5PR10MB3972.namprd10.prod.outlook.com (2603:10b6:a03:1b6::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.32; Fri, 9 Apr 2021 20:53:17 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee%7]) with mapi id 15.20.4020.018; Fri, 9 Apr 2021 20:53:17 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Roman Gushchin , Michal Hocko , Shakeel Butt , Oscar Salvador , David Hildenbrand , Muchun Song , David Rientjes , Miaohe Lin , Peter Zijlstra , Matthew Wilcox , HORIGUCHI NAOYA , "Aneesh Kumar K . V" , Waiman Long , Peter Xu , Mina Almasry , Hillf Danton , Joonsoo Kim , Barry Song , Will Deacon , Mike Kravetz Subject: [PATCH v5 4/8] hugetlb: create remove_hugetlb_page() to separate functionality Date: Fri, 9 Apr 2021 13:52:50 -0700 Message-Id: <20210409205254.242291-5-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210409205254.242291-1-mike.kravetz@oracle.com> References: <20210409205254.242291-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: CO1PR15CA0050.namprd15.prod.outlook.com (2603:10b6:101:1f::18) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from monkey.oracle.com (50.38.35.18) by CO1PR15CA0050.namprd15.prod.outlook.com (2603:10b6:101:1f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Fri, 9 Apr 2021 20:53:16 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 705f21d4-ebbc-43c0-9094-08d8fb99800c X-MS-TrafficTypeDiagnostic: BY5PR10MB3972: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1169; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TjsNdynHYMIhMkmedTmsw0S2ccO+2pxzGmXMnzIm119bsEO51RwEukKrAkKN8l3p4KXyN47idaLYQ5sHEc+DV8RjJ0+5WfmWS1wCCqBA9vxIBwlJs236QRvLn5T7nEB1nMjdfeNmKyBU4ML/oHlmiOzRuTErTlBZRGCh7eGkmT1uM9JKkNNaUhRopBcOokCgznHrCY3xxVnsDldqfUpmdhyVYA0wnPDeX1roaBlSaYPA30TANFbJTG/A27oGmKfVLK9oytqmQGfZBZJO8IVPH69BWYSkuyV+4QhCK4zzMtLoSUrKZFH1tClkO8ngSRUEo2fPghWV0OGCRFJ/7tdzL0QIyRo0w1LGo97M3zOgEjUOIyFdN3f/Zmj4hBYrbosOaddpwPZRWAQ3VET4oiryhMwVtBk8+DTmXD9t7eUasNNXLLujL3bhqM4lqTUSRTCqY8v300O0xpBFJW21gkZeneHjvqPidFdHVl5sC3EG7bMfCUkJ+7njA6vQEdpV+W0JY4hY0YaJOnus+qN748xscsUG30gAt22QbIgmmJ5eg+kOsRPxNw2uukxIBdFQENhbn109sFPHd6llInKwpC+2dNImrK04e3XmBT69iChTIOMNsqIwmqrvlOcY+t4L7ZzahBp/OSoXn0qxSNCC1/35fI5QF8/rE+tb2xJjFJjNB1zHDasD5M9r/p5jTvuUaxcA X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(346002)(396003)(376002)(366004)(136003)(39860400002)(38100700001)(5660300002)(66946007)(7416002)(956004)(6486002)(83380400001)(66556008)(8936002)(66476007)(4326008)(316002)(6666004)(6916009)(54906003)(44832011)(7696005)(2906002)(478600001)(1076003)(52116002)(16526019)(38350700001)(107886003)(36756003)(26005)(86362001)(8676002)(186003)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: zwVXDXeahgFKmv6x6AuzfJCbt2u0PuaaqLdivBX+S8QxDb/iaF9P3rlCILU9N8Q7FKQ/uveloB15/73HtBep44UIUwiSVbzkis8yTLEMTnUwXsGMb9DDQk//blOjumG0z+QGfxZU3Q7y0nbvZIftLaooxHXsI0vyiof1E9POgwoP29c+OLw+v3NrXHJ9X6O1agM+QWHlDYRH+xaAt064LimaaqRUM1u8vpGRXJrSkfrqwnTlp03u4Unm8SVYpgIVSe4HbYt+44w5AJ2C3Haj8ylireXSbeawp8TiGs/MpSitfSi/r0RMxTep0dmdLzvr6zvXe24dhI6i6CtWH3AChaxHNKSn9CYD2lcj2EqOF5kxg1GhfuFSC3a1n65L5n7uvSDAkT5FxJwD1WHFZ7ijt+Ativof81ioAzacPjiGWlq1xfB9VnL+9YtmJdF0n6a2mHQTmQEAn9PTsL0SR+eNredfWTzbtyXcQsdFCp6MoYsLiRw/ut8iF5/pUokOZq+LIUhmNleEWhV5vHx0iWyDmYMugrS5diRHABpxecSSxYaPquAKLMT4/0fdTr4vOYCedPuQLFZnFadA0RzmX70fWV9hBITLJINNLuYU9tehfBpnyw/jIVllMuFFhuMHIFGZvl79Dxk81CZbQ+LqY0U7RqcRgovOK1Oktyw5ZQUTgll9YOX14nHMHIFU0nkuEkldg90YR3jAsQvUzG9oUrMeQIz3E9I0EVHtKBYOpAz5hKsO+/hSmKDbZdG8dcoC9KQjZT2jffhxJEHn/ZO9gBLrgdhe57Qb3Nf/ngKArSw/7c0DKNmVxOPHZ4d8JOaE1gIRg/Ks93YRP/CsZzWN2N0J3s87I2FnS6Z9SVsBG+Sa7iNMBnQmFO3A2vDhnklHH5rjJvP5TO5T0PoVBauOBwMX/0agC9R77/DkfmL2ntXDyD4zO0wwfvFGLwkoN9fkb6JOAzn5D5SieYh5Oji5efZm5nWIqG63s6ZxuYghIeT/MWRn/gYK0d9a+pOsWL+m1auBKmy1KtPzbZtOUj8k2b1y5ICbaPAw3qwDeOWims9iZsZcBiEZT00oE16PflOyUN/K+QK96Q00lCLPcr57P6wlfVMHpsdCA+Ppet/hKuqdEcNw9iWPpQXcBN3e2NNEjKKHcuZxstLdZ2ktEAoAAQSY72cAK4PTvQu7lKLr1q6aDYi4KzdZocNAz+dCNkTBSo8iMWy/iXOrA1u5MaNIPA2xtibs/U6JpqqOq6sVxDuOi4B++7epWXR7sD1vw8OMu0ccVIlj5oA4qhVOV/O7Tzfwi1Y/wyTjStBFx35cBjvPmSr7Yu6rTmtx3KckZYWuwE+/ X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 705f21d4-ebbc-43c0-9094-08d8fb99800c X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2021 20:53:17.1791 (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: 8/6zkBB878cMXYRc4lbNPAdKYdcWZNPQROJaOCPMatJToLo2FMP989JCAGYXY2ILZqMspFnSqSYOsjH2BjbDyg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB3972 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9949 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 adultscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104090152 X-Proofpoint-GUID: pQWPBP5n8a82B3gIMuRWlF3Rn2ymmEL4 X-Proofpoint-ORIG-GUID: pQWPBP5n8a82B3gIMuRWlF3Rn2ymmEL4 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9949 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 suspectscore=0 adultscore=0 mlxlogscore=999 bulkscore=0 priorityscore=1501 impostorscore=0 phishscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104090152 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: B01DB40002D3 X-Stat-Signature: x8n1utg1r3m7w1r1tuia74zsfrkcax4m Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf02; identity=mailfrom; envelope-from=""; helo=userp2130.oracle.com; client-ip=156.151.31.86 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618001603-889128 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 new remove_hugetlb_page() routine is designed to remove a hugetlb page from hugetlbfs processing. It will remove the page from the active or free list, update global counters and set the compound page destructor to NULL so that PageHuge() will return false for the 'page'. After this call, the 'page' can be treated as a normal compound page or a collection of base size pages. update_and_free_page no longer decrements h->nr_huge_pages{_node} as this is performed in remove_hugetlb_page. The only functionality performed by update_and_free_page is to free the base pages to the lower level allocators. update_and_free_page is typically called after remove_hugetlb_page. remove_hugetlb_page is to be called with the hugetlb_lock held. Creating this routine and separating functionality is in preparation for restructuring code to reduce lock hold times. This commit should not introduce any changes to functionality. Signed-off-by: Mike Kravetz Acked-by: Michal Hocko Reviewed-by: Miaohe Lin Reviewed-by: Muchun Song Reviewed-by: Oscar Salvador --- mm/hugetlb.c | 65 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index c8799a480784..773081709916 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1326,6 +1326,41 @@ static inline void destroy_compound_gigantic_page(struct page *page, unsigned int order) { } #endif +/* + * Remove hugetlb page from lists, and update dtor so that page appears + * as just a compound page. A reference is held on the page. + * + * Must be called with hugetlb lock held. + */ +static void remove_hugetlb_page(struct hstate *h, struct page *page, + bool adjust_surplus) +{ + int nid = page_to_nid(page); + + VM_BUG_ON_PAGE(hugetlb_cgroup_from_page(page), page); + VM_BUG_ON_PAGE(hugetlb_cgroup_from_page_rsvd(page), page); + + if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported()) + return; + + list_del(&page->lru); + + if (HPageFreed(page)) { + h->free_huge_pages--; + h->free_huge_pages_node[nid]--; + } + if (adjust_surplus) { + h->surplus_huge_pages--; + h->surplus_huge_pages_node[nid]--; + } + + set_page_refcounted(page); + set_compound_page_dtor(page, NULL_COMPOUND_DTOR); + + h->nr_huge_pages--; + h->nr_huge_pages_node[nid]--; +} + static void update_and_free_page(struct hstate *h, struct page *page) { int i; @@ -1334,8 +1369,6 @@ static void update_and_free_page(struct hstate *h, struct page *page) if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported()) return; - h->nr_huge_pages--; - h->nr_huge_pages_node[page_to_nid(page)]--; for (i = 0; i < pages_per_huge_page(h); i++, subpage = mem_map_next(subpage, page, i)) { subpage->flags &= ~(1 << PG_locked | 1 << PG_error | @@ -1343,10 +1376,6 @@ static void update_and_free_page(struct hstate *h, struct page *page) 1 << PG_active | 1 << PG_private | 1 << PG_writeback); } - VM_BUG_ON_PAGE(hugetlb_cgroup_from_page(page), page); - VM_BUG_ON_PAGE(hugetlb_cgroup_from_page_rsvd(page), page); - set_compound_page_dtor(page, NULL_COMPOUND_DTOR); - set_page_refcounted(page); if (hstate_is_gigantic(h)) { destroy_compound_gigantic_page(page, huge_page_order(h)); free_gigantic_page(page, huge_page_order(h)); @@ -1414,15 +1443,12 @@ static void __free_huge_page(struct page *page) h->resv_huge_pages++; if (HPageTemporary(page)) { - list_del(&page->lru); - ClearHPageTemporary(page); + remove_hugetlb_page(h, page, false); update_and_free_page(h, page); } else if (h->surplus_huge_pages_node[nid]) { /* remove the page from active list */ - list_del(&page->lru); + remove_hugetlb_page(h, page, true); update_and_free_page(h, page); - h->surplus_huge_pages--; - h->surplus_huge_pages_node[nid]--; } else { arch_clear_hugepage_flags(page); enqueue_huge_page(h, page); @@ -1707,13 +1733,7 @@ static int free_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed, struct page *page = list_entry(h->hugepage_freelists[node].next, struct page, lru); - list_del(&page->lru); - h->free_huge_pages--; - h->free_huge_pages_node[node]--; - if (acct_surplus) { - h->surplus_huge_pages--; - h->surplus_huge_pages_node[node]--; - } + remove_hugetlb_page(h, page, acct_surplus); update_and_free_page(h, page); ret = 1; break; @@ -1751,7 +1771,6 @@ int dissolve_free_huge_page(struct page *page) if (!page_count(page)) { struct page *head = compound_head(page); struct hstate *h = page_hstate(head); - int nid = page_to_nid(head); if (h->free_huge_pages - h->resv_huge_pages == 0) goto out; @@ -1782,9 +1801,7 @@ int dissolve_free_huge_page(struct page *page) SetPageHWPoison(page); ClearPageHWPoison(head); } - list_del(&head->lru); - h->free_huge_pages--; - h->free_huge_pages_node[nid]--; + remove_hugetlb_page(h, page, false); h->max_huge_pages--; update_and_free_page(h, head); rc = 0; @@ -2552,10 +2569,8 @@ static void try_to_free_low(struct hstate *h, unsigned long count, return; if (PageHighMem(page)) continue; - list_del(&page->lru); + remove_hugetlb_page(h, page, false); update_and_free_page(h, page); - h->free_huge_pages--; - h->free_huge_pages_node[page_to_nid(page)]--; } } } From patchwork Fri Apr 9 20:52:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12195077 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.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 1A4C9C433B4 for ; Fri, 9 Apr 2021 20:53:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B505F610E7 for ; Fri, 9 Apr 2021 20:53:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B505F610E7 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 540F16B0073; Fri, 9 Apr 2021 16:53:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A4B76B0074; Fri, 9 Apr 2021 16:53:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 196F56B0075; Fri, 9 Apr 2021 16:53:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0099.hostedemail.com [216.40.44.99]) by kanga.kvack.org (Postfix) with ESMTP id E91D76B0073 for ; Fri, 9 Apr 2021 16:53:38 -0400 (EDT) Received: from smtpin35.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id AC11D1803F7BD for ; Fri, 9 Apr 2021 20:53:38 +0000 (UTC) X-FDA: 78014029716.35.D0464A7 Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) by imf29.hostedemail.com (Postfix) with ESMTP id 53B5DDC for ; Fri, 9 Apr 2021 20:53:36 +0000 (UTC) Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 139Ko0Sa071231; Fri, 9 Apr 2021 20:53:23 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-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=MvjokJjB5zUDCnakgLH/9HBYHTsYx5V0OJeMIP8CtOc=; b=KYau4RiYbWW7ty2QuZrqYSEIVixaxLF1ewXkYVLEHHEjqSPblYZd3rvr1Q7YHz++feMR bD09I8uXGmueWq1cAspguPl7vA78VP2YoVL7Kf42xtE8UhsuItLbj45eM12dQppAH8gu X6A+UgtgVaCH0YXQGur1qRYeui6cGnLvUxTSSeW9D03I7p4/wrmyXn7JmQXA50g68esW ZIelC1jyi/VSRlhlkK8hsMLsrVZQp4QUOvjExkFQEAVN1R1kA7PvUDsCCKDqV/Kt8gj6 fH2bCl6kWTKcgjvvIdAqZM7XusEVhuY+4Q1Q6uO99bZlYJ28V7Vt9sMH1uKMFZiwGX4I IA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 37rvasaq5e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 09 Apr 2021 20:53:23 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 139Kk7bU035297; Fri, 9 Apr 2021 20:53:23 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2106.outbound.protection.outlook.com [104.47.70.106]) by userp3030.oracle.com with ESMTP id 37rvbhfka6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 09 Apr 2021 20:53:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IoHNo+gLPuk8OAFojA888bLPsf35Z8io3/e/5Z1ANqYrXuo4aYpFT/jF3TdWxMV4MW0i5mE0sNrG7nrsY7Y01ZouA90RrnbAeqPGGjYqVXX7czlnyAbkFvTQ0kB+2F+9sKLPgVa+qBL5QFWJ1k0bjNdjIq+U1USVI6BqHKeWmK38EOM97XxyrnRDyu6GTChvrVvWKoM31NLwZUmHVIwZqNYP5hT8pBTUAsukQMTGlaLVAOwocE3GoV/uZH0ZZiEKkVhiejNu4DWd5a15o/l4XtxC7SHz+z0xFo4X9kE1uFM+AJFte6on/V/iRxoUpIWOjtQClzY0Zlw4bQ5xO0qyXQ== 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=MvjokJjB5zUDCnakgLH/9HBYHTsYx5V0OJeMIP8CtOc=; b=WOjOQ2b6i+MgMioGd0QUT0uVm+F/Vb2FrhzESqajsd8sh85MEtcQ7A/9CzMsMVO9Dd2kbS10bAi/cKDGYEctpf+kkAC4KUqKgpe9zI5mEoUmjKJH0oyBFqyN5B5zXAizJ+nfplOa1ZcI59wd4k1T/PQy5/FCVkhVQTe/lVIPGejZ/jTRgsMQ1xAB2KAfpiSvhu28NLVpBFIPh8gT4yNga7DMuRX/P9lYZj/4qjbzHwAQC9IKAQemh28205dZPqAV2rOM+pZHoZHyTBUyuItYK1fz/q7f+XM/WAemBqpqM+nV7iZYbOl6n9Y1/yFlNauPg/TzrQnDF1bn9sTW7Iz+eQ== 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=MvjokJjB5zUDCnakgLH/9HBYHTsYx5V0OJeMIP8CtOc=; b=ogkvUpeekZzJ7GxsrplWdVBQMiOwNZMTlyJ31g2Xrg0nT1ccUksodnmlAWk3iSvGMhkomA6xdNMAoqzbndhuIT4oZJuKxnttwzdpXJbekg0pzSp5HI3iXZqtiQirdXrCucmL5nxxWFCWoHatmXP9inXYZglehsAQQOsRX+w+OOE= Authentication-Results: kvack.org; dkim=none (message not signed) header.d=none;kvack.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by BY5PR10MB3972.namprd10.prod.outlook.com (2603:10b6:a03:1b6::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.32; Fri, 9 Apr 2021 20:53:20 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee%7]) with mapi id 15.20.4020.018; Fri, 9 Apr 2021 20:53:20 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Roman Gushchin , Michal Hocko , Shakeel Butt , Oscar Salvador , David Hildenbrand , Muchun Song , David Rientjes , Miaohe Lin , Peter Zijlstra , Matthew Wilcox , HORIGUCHI NAOYA , "Aneesh Kumar K . V" , Waiman Long , Peter Xu , Mina Almasry , Hillf Danton , Joonsoo Kim , Barry Song , Will Deacon , Mike Kravetz Subject: [PATCH v5 5/8] hugetlb: call update_and_free_page without hugetlb_lock Date: Fri, 9 Apr 2021 13:52:51 -0700 Message-Id: <20210409205254.242291-6-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210409205254.242291-1-mike.kravetz@oracle.com> References: <20210409205254.242291-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: CO1PR15CA0050.namprd15.prod.outlook.com (2603:10b6:101:1f::18) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from monkey.oracle.com (50.38.35.18) by CO1PR15CA0050.namprd15.prod.outlook.com (2603:10b6:101:1f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Fri, 9 Apr 2021 20:53:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 40c6e501-ec51-4749-b8cd-08d8fb9981df X-MS-TrafficTypeDiagnostic: BY5PR10MB3972: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cpKiv2QDPftwgNTrTU9uxp/NGzVkhKl1dVQ7nF2Yrd/Xepn4FxU48jG4bxD6hrtR9w89Sq7bACttA/eGpm1QNLL2Cyf5H7R0E7viZ5vgOMvvG9jSLmjD5uNJcJqOv3DqazpxIf5XpPdwRiv5xns5gNwibw8HgcoNk2G6NfcmFofZBdgks3dttWc2SH1s+JuvG/skERAmiwWy01jx03bmArAsRbhxjVqWiej3Zc6itkBuBuy5ggKmkzF0fzedtguuj/OHkX6QFS8KYQYBm1mvZP4dLbOaS6Dnf+9DPg7wbi5p0QU/SycY7oGtII2neWr4NV3Tl8HSxpNYxt8ziM/9kJSFU88bhW3juksC58JAdD5CIkvc3zru56bKpzLBTGkc7EdwLJgo5bmcKyRvfBbVcQw5h+oja0xrWuo2l2JvzZ7hYH9mFFUo6b2o3jkSgRj+ZWEaC22/diYED0nInmoZM7xQBAQ2tPcw/6UPuFiRAMHH5lHos1oNh55Z3u+mQxSez82NJNm91S62uhD6yDxCl2iWxmicluIGJJMy1cVJ0+14TlbwQBtPm+J/TtjaOf7Lx9YiU/haaP6I3u/jiCRYMEIB+d79rP7t7IoVSz9Hoxa5cnQFLogbxqPLpDu5CT/LbVmkeygxHqomYzu0tmKbvru68CMq82BuxVSigoPvDgiEUhdyIIT98BcgA8NEBR/j X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(346002)(396003)(376002)(366004)(136003)(39860400002)(38100700001)(5660300002)(66946007)(7416002)(956004)(6486002)(83380400001)(66556008)(8936002)(66476007)(4326008)(316002)(6666004)(6916009)(54906003)(44832011)(7696005)(2906002)(478600001)(1076003)(52116002)(16526019)(38350700001)(107886003)(36756003)(26005)(86362001)(8676002)(15650500001)(186003)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 1flSoQq2hbkP4I8jT65vNs9Mqrm295Whx1sTujRAu/oVggbT0VINq9PjFrxBxLI75M/gT8SkxaFdSJpV7cZ6WUicse3jKnav2vWordXSLOKpep7H8EGdu+xOqlb0u55Or9jCBUWjMTWPZ6a2go3GM10pflmTF5kLog8fW96nBu7gdzrFx0S7R6PR7vZlelkBCiY863y/7Eako2o5XUvGCjx+IuFyjIbJgACMvYVChrPpRFT1FwodiJLmdEbZZZmh+p4zuiER+6KI3FhveSJZZnj6bb18oKPxcD6q2XnqJGN1B8rSCbvCla4QHmRJJSJTHW+0zWXXHlyZdndtXOfRgWp5593jt+jyqkzUBxKmlklXPEaRgUoY/hEmb4U0tRb/Ds0RRmYxQDjJ82nXgEXgbRPgVjbHL+tuQ6iVuQRZECM+RKPsSUKxSMdrZcen3JgVKkcAzdxXiSGac1H2ka3TGfeonjLqAx+CyTzfrQseLMpWblYLW4JykNsh/QqW2j+K1yJZOSMJPGP1AQcw7sspORoBsNZaXajBcxZaB0F2wXpCGkuNIqRYR9F83b+XuuM1DNUfvJoVa/xQmNDjgMIx0eeR2NAi5gGty5mgETXfRpvYdDGEF4Lj5RUfLw08B790qFvUYOUdEUYzuoCumJQXNACJMz9blR23e1qaaM2zXoQJc/M9CeBBykBirkUU/TDRazWUHguHP1m/8wfd37SxqC7EpRoefi3bzjqYBN9K63FbChzXf3gWjqANPIh/eKqicv9ehIOMPSCnpsjqJ/PifkLdwLR/kWib7AFglTzrmPCBKW2mfHgnuuD/7ow2a2s+/Z0ahLbAqeSOYLlqGre/bQKnlxCXC3Y8oRN/DTSZRUSPWb5jBktPtGyQV0seNzeTUVLJhJp+qC/RL7bAaBzoS4l1oQztl60LdeHGXU/JXMaPMnMKZkE2tJUpRqjZudzplqeRXbYTdowMj54vkwzjgEjBVpUm902C0JTgkfEOacMawBfotlDYqaVBaT7SrVa8Ug4BcRNaHEEFUmyUPrPYyrODkqeF3GzHhus2h2bDzbHiHryciMKHLL0G2ooJcoZBzzytL6wfNWy/sEwljOL3CRIZyb33RgyyhrrHfoC2IeM0KuWrjSfz1z7uqcbUv2RTngZj7qaZjZ0Wnt1yQ5+mWvOwUZx4DqhOWiEGUyiHA7sSZkmtcM8qtTl3lxh32ziHz/XSNv0lqSfxIVqTz7Ekwm8mXNIC1GaKCSdiWwqOuo9ZJ67TdxeSwOWO2pNDY3fVmKmS28mi7Bo77H+9MZmiVbgeEhVClUmE04oQt0eRly0eM0RV1+OliMcFcLNkLXNm X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 40c6e501-ec51-4749-b8cd-08d8fb9981df X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2021 20:53:20.3676 (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: Wk95DeSFYZti1J3BB1kuQnVs/FhPTOBTAluocKvZ780734Z+zvsKOJZpzpotuPOXPhH/8PfRQl/vCikK0BMbtw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB3972 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9949 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 suspectscore=0 phishscore=0 malwarescore=0 mlxscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104090152 X-Proofpoint-GUID: dsw42Kb5Yo_A70BiTmg2sTGaq3Jv91yV X-Proofpoint-ORIG-GUID: dsw42Kb5Yo_A70BiTmg2sTGaq3Jv91yV X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9949 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 adultscore=0 priorityscore=1501 malwarescore=0 mlxlogscore=999 clxscore=1015 bulkscore=0 mlxscore=0 phishscore=0 spamscore=0 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104090152 X-Rspamd-Queue-Id: 53B5DDC X-Stat-Signature: enqu73rxyjioyumpnwzb4mo8piqad7b6 X-Rspamd-Server: rspam02 Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf29; identity=mailfrom; envelope-from=""; helo=userp2120.oracle.com; client-ip=156.151.31.85 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618001616-634283 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: With the introduction of remove_hugetlb_page(), there is no need for update_and_free_page to hold the hugetlb lock. Change all callers to drop the lock before calling. With additional code modifications, this will allow loops which decrease the huge page pool to drop the hugetlb_lock with each page to reduce long hold times. The ugly unlock/lock cycle in free_pool_huge_page will be removed in a subsequent patch which restructures free_pool_huge_page. Signed-off-by: Mike Kravetz Acked-by: Michal Hocko Reviewed-by: Muchun Song Reviewed-by: Miaohe Lin Reviewed-by: Oscar Salvador --- mm/hugetlb.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 773081709916..d3e5e49bf687 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1444,16 +1444,18 @@ static void __free_huge_page(struct page *page) if (HPageTemporary(page)) { remove_hugetlb_page(h, page, false); + spin_unlock(&hugetlb_lock); update_and_free_page(h, page); } else if (h->surplus_huge_pages_node[nid]) { /* remove the page from active list */ remove_hugetlb_page(h, page, true); + spin_unlock(&hugetlb_lock); update_and_free_page(h, page); } else { arch_clear_hugepage_flags(page); enqueue_huge_page(h, page); + spin_unlock(&hugetlb_lock); } - spin_unlock(&hugetlb_lock); } /* @@ -1734,7 +1736,13 @@ static int free_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed, list_entry(h->hugepage_freelists[node].next, struct page, lru); remove_hugetlb_page(h, page, acct_surplus); + /* + * unlock/lock around update_and_free_page is temporary + * and will be removed with subsequent patch. + */ + spin_unlock(&hugetlb_lock); update_and_free_page(h, page); + spin_lock(&hugetlb_lock); ret = 1; break; } @@ -1803,8 +1811,9 @@ int dissolve_free_huge_page(struct page *page) } remove_hugetlb_page(h, page, false); h->max_huge_pages--; + spin_unlock(&hugetlb_lock); update_and_free_page(h, head); - rc = 0; + return 0; } out: spin_unlock(&hugetlb_lock); @@ -2557,22 +2566,34 @@ static void try_to_free_low(struct hstate *h, unsigned long count, nodemask_t *nodes_allowed) { int i; + struct page *page, *next; + LIST_HEAD(page_list); if (hstate_is_gigantic(h)) return; + /* + * Collect pages to be freed on a list, and free after dropping lock + */ for_each_node_mask(i, *nodes_allowed) { - struct page *page, *next; struct list_head *freel = &h->hugepage_freelists[i]; list_for_each_entry_safe(page, next, freel, lru) { if (count >= h->nr_huge_pages) - return; + goto out; if (PageHighMem(page)) continue; remove_hugetlb_page(h, page, false); - update_and_free_page(h, page); + list_add(&page->lru, &page_list); } } + +out: + spin_unlock(&hugetlb_lock); + list_for_each_entry_safe(page, next, &page_list, lru) { + update_and_free_page(h, page); + cond_resched(); + } + spin_lock(&hugetlb_lock); } #else static inline void try_to_free_low(struct hstate *h, unsigned long count, From patchwork Fri Apr 9 20:52:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12195079 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.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 607A0C43460 for ; Fri, 9 Apr 2021 20:53:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CCE23610E7 for ; Fri, 9 Apr 2021 20:53:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CCE23610E7 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 1BFC66B0074; Fri, 9 Apr 2021 16:53:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 174046B0075; Fri, 9 Apr 2021 16:53:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F04DA6B0078; Fri, 9 Apr 2021 16:53:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0125.hostedemail.com [216.40.44.125]) by kanga.kvack.org (Postfix) with ESMTP id BEAC06B0074 for ; Fri, 9 Apr 2021 16:53:40 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 814D41802BE03 for ; Fri, 9 Apr 2021 20:53:40 +0000 (UTC) X-FDA: 78014029800.10.1444D9F Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by imf15.hostedemail.com (Postfix) with ESMTP id AA862A000147 for ; Fri, 9 Apr 2021 20:53:38 +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 139KoO7L167119; Fri, 9 Apr 2021 20:53:25 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-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=/cs++IFL2HEM2BnhtMJRQEt6gwqxu4GmDQow6+W7nz0=; b=QRubzLQ3hE8bOYhNxIhwlC2mQt/IiQn5v/oUhn3PBRx02cmY5k9yA17wjpdoKsraVjpc /8X6Cb+GtwsUufEXTRmGjBqS+kS6vnEYii5Ha/1CFpjwoaFTaBosSeGXACNKFqN7MZ/U ApSlpNCGJKMOjnGbhKhc0ipb9u2ZF/hwHIFyTso0kWBIIvXi+UcUIo5S3glY7+/Hotgu emjGfvBcTl/xx8+MBBDl2YOkNQrZ4hHwUnInFMpeJv/nAAiRpdulT/79bNsdLGtpv4Md 17lL4X8ySqLkH63KDEfo6fVgiXa7YxN+/G5pHIRRke9/GtZEJ+LukH9G/EkaF0sUFHdE xg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 37rvagjqf0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 09 Apr 2021 20:53:25 +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 139KjS6D174400; Fri, 9 Apr 2021 20:53:25 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2104.outbound.protection.outlook.com [104.47.70.104]) by aserp3020.oracle.com with ESMTP id 37rvb71qqf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 09 Apr 2021 20:53:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ExWseDeAbLk2g04rm7udU1Rz47gkB60G1GOO8aoaQMlB7aQymMD5Wm8p4krGz1u0EX4pdG24fXVReAxYqy1Fw56VQli4h5fgeFoSFb9vM32QHpze1rKkKJCk9VydIXpfCo1nCEHFWGJpQXUP05OLfNIM8Lb9PVeJkGKOZJnF989EVdisSuxP0/Q1w027GRMHnWpTbSXPPVDhPR5b4aTTl/01fFbC5+VBn+1mdNcGenC6EHaMIw8sJv1oONHiBtU7BTrSzuBnHK74b9ZGv6wd1hX6sB3vyT9UotnaZpsWytCn5iLJgY4d2AKSMpaF8GyZDEcorTpM63MWOqvVwJmdBg== 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=/cs++IFL2HEM2BnhtMJRQEt6gwqxu4GmDQow6+W7nz0=; b=gs7W6zSDW8S2Dt9iUD7PTmke9L/734XrhhL7ElS1QVPzPpLHcu2LATSKTTIW57cJ8dqXav3ssKr7LTGUjCvZDqbagLudSLa3eX6UCHEF6y1sdH8Ji0irSqsIJFlMV0f7zl/K2JVTE9btCoApmkR+lJAHng9AulA/u8zHfCYXvRNRM4QvwfojDP0gP8a3iulY5FjoxAsimYr/wrOuLRHVGK3CfyJOVg+5nFLV0fI2xGQvwYPhs69taBZBb0tn0dMtw/SHMX8tWNtb51IjnrmdlPAJU+5+sQnRU9Ez0ktukTj3jnxIkTLfNmqCk6wluc4MMGMlmkq5pWeRtogUg41c7w== 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=/cs++IFL2HEM2BnhtMJRQEt6gwqxu4GmDQow6+W7nz0=; b=kvH4jE0dqEIdJj8omdpvWFFRGZfRRr9ToWeVoHuXStQ5I+1iclX/N0TSx0VA5URw5ZYeINQZrx/VswHhdB326zG0RBz8OeAcOpeAAjCd0FROkPsR5GIseXKRaoDNPgKgmnBuAYrL2vhvZmJX0et+tJULf6aBsmKq7IwZTYSZKT0= Authentication-Results: kvack.org; dkim=none (message not signed) header.d=none;kvack.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by BY5PR10MB3972.namprd10.prod.outlook.com (2603:10b6:a03:1b6::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.32; Fri, 9 Apr 2021 20:53:22 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee%7]) with mapi id 15.20.4020.018; Fri, 9 Apr 2021 20:53:22 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Roman Gushchin , Michal Hocko , Shakeel Butt , Oscar Salvador , David Hildenbrand , Muchun Song , David Rientjes , Miaohe Lin , Peter Zijlstra , Matthew Wilcox , HORIGUCHI NAOYA , "Aneesh Kumar K . V" , Waiman Long , Peter Xu , Mina Almasry , Hillf Danton , Joonsoo Kim , Barry Song , Will Deacon , Mike Kravetz Subject: [PATCH v5 6/8] hugetlb: change free_pool_huge_page to remove_pool_huge_page Date: Fri, 9 Apr 2021 13:52:52 -0700 Message-Id: <20210409205254.242291-7-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210409205254.242291-1-mike.kravetz@oracle.com> References: <20210409205254.242291-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: CO1PR15CA0050.namprd15.prod.outlook.com (2603:10b6:101:1f::18) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from monkey.oracle.com (50.38.35.18) by CO1PR15CA0050.namprd15.prod.outlook.com (2603:10b6:101:1f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Fri, 9 Apr 2021 20:53:21 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5eaddcd4-fc7e-41f6-4c58-08d8fb998367 X-MS-TrafficTypeDiagnostic: BY5PR10MB3972: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kNh6k9Ul+T7APtIiIJKFV4IKDCkYoithnKLqYdMoHRlIjF1e9JBChdBCLCsayKid7YAyvpD89rAycU6A9ge0am9C0pD3hkzuvMmKSF5Kbb1qeKWO07FT04QOB5uDCgyzut9E+ngF7+Vxg1ZADAlVvW3GgTjGXuieX8FijQDfiTVvojDeNmuIVHTHdZZMsYGP2yllO4/zFo9FGYUCjtyWGDXKFx7kcGgE/6CnaOC9DH15SOg88iCVt6Ng5EEOue8ovMFJAMfi5QvzMPHoTwPBDt4RjFRfrMlmrinW2RWGml6EXH3bh99gUT5pO+zDmE28xOFIGYal4hgms2v3rTvcQg+WGSgYXPfq3qMI3zy9vpAqyMfvfqmoctETRbM5e0hyASEt6G7YsUp6gp9GPe5ivXJnMsEUTTNrSPoBGmyhgW1yvEz5YLMX8TfAS99XLKer+xsnH3JeQRKAnB+eHvk7FWgkXDue5yrxe01hE7adzhb7Q8O6IhGIGlirw2a16pj97rI1RW9LrdjLkxQpx0YdqqLrjDJyEFGS8JOxRqfgL+isWYGFjRpNHqzwO74MaMEA89PsIx+NHaj+J5CtxqH5antVTgZCt2XWFmCsjRfrHtCCHHa0ApZspA/Ch9A8XmRuo599VRuFY4ueLGkFOi+1mJsUB9ik+tWtZThq/tVqOK8oyktWIN7OtEtW4C4v2nCupm25YB+om4urkkDOz5Ra4w== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(346002)(396003)(376002)(366004)(136003)(39860400002)(38100700001)(5660300002)(66946007)(7416002)(956004)(6486002)(83380400001)(66556008)(8936002)(66476007)(4326008)(316002)(6666004)(6916009)(54906003)(44832011)(7696005)(2906002)(478600001)(1076003)(52116002)(16526019)(38350700001)(107886003)(36756003)(26005)(86362001)(8676002)(186003)(2616005)(14583001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: AhQZuOfGR7VPtTP3eVgFn3GiECvSztMLcWnj75ntaB89Gc0KHAiHOAKXwr7CACOcChkWQ1C/x2OdIiWM/jyqk33Gh20ez1rNOZzcaw610hYo+jGKU9JOWLPtGr3GClyfma+x52Ap+c102938jUFKwiDwZo2OWc41a2sxHxb57clfrY2iZBQitz/DwkPKMwtWanFblSX7bfGA7JbxBEwKKmGXmYM5W/eJTomxvdqNUlKMoYubJdTyuEcYvYtUiAWjYtkXVnR9txwosKh/LkyqJXtaEZ0vMALnENudZ0uKJi7TYKYe2DcPvz9uAKIlan1dDjoWBMvqBB4+/c1XyStmEzVmbC8pTdFF1tLsRLtSaheZ/lVhgNW14J169m98lLbV549ZFEjWEmo++oOXQtktN+2grCG1JRBAAJkb0rVOhhw+YvR1vDZn5BJuPPDhSt6i8dfvb5h0MpnB3D4dtZ4Vexkn+v8tLHeZkifu5U/E4lUAie+cL+chqSWXBJdx0NDgXzA8PxVXFdRTnvyGEo1hXNFkOux21gQdkqPbbNWABWcxGwA3M+MivS8R0rJiBdPiSy7EO23YoxpQ/D9xvDNCw7WtanXgfo35iOVxKqkojayvvOQdOnzI3RzWPDU49qtvNAvMZvJKcZzNJdhAKdKx1L8iWulMeLKKvro92N5+e352dho9f6Ks1SWaipe9ytY3x7I9D+ns6Qu/GP7eLOPeVsfmnAQamnqsHQvzVNzGTNbmNOHd6N/unZ1GNrCDb3vjgJ34ezrhFaHhe6xlzCk/4Viw1Ioeo1kWmK221lU7NusHnrnfQ5opJJ8nmyLeVutqFMKPohl5yqvUuvSW1JnYdcDX2cpDyO1oq7NKvHUmt9eJ+SaG74duBxVKGLd7owk2EfMB4Y+2kEQhKtUdGRZuLThuqknP/BaUg2aB9rNdyenyUPd8g5dInPQZZwxvEdP1+dQ/sAIM5wS5VhTJlM9MXUJ7XC+/3nmOcSrV79yXHvo4Vey/ypY/W+NLHP3mbjwGgAw8mCfO+WT4q9p8+Pz7hUo2a5J+PhvoaRJdEi1yVJ2DB/TaI0xHKkH9MwGc9m2ciT9WzZenpdexGjWg+MTFLZw4lPLuPvn+RKkArfsspJ32cUifqwmJ3iPQK8lGYBqbCpCqpYEFF5bgMYi10wf+03eIN7JX0h5p2v+MqsD28D4QdlInSY0AZw7HiulAMBzLKqigyZweuB6owxePcq9oiZZEq6T/Wy2A8TY1bk4E23Q0br/yru7vvrMmqwoNByh8vSrDCAHXidWbkDDTvieekGszSG9ptYO6oSComzdDOUzCuwNj+zKZDu+tC/X43MrB X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5eaddcd4-fc7e-41f6-4c58-08d8fb998367 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2021 20:53:22.7432 (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: avFg+av8zXl++mzhSjeonN+JoiLP9SkERXMnmgwOuxTSC9P/OkXai52AJ2lo/KGdZRzD/WAxjuYIIBYzXQTxiQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB3972 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9949 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 suspectscore=0 adultscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104090152 X-Proofpoint-GUID: _IeZHdSqDomymu_QdHcFTmtyIdYu8bpE X-Proofpoint-ORIG-GUID: _IeZHdSqDomymu_QdHcFTmtyIdYu8bpE X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9949 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 mlxlogscore=999 suspectscore=0 spamscore=0 phishscore=0 clxscore=1015 bulkscore=0 mlxscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104090152 X-Stat-Signature: 68bqx81yg7ttomqwqnb1xzd9pce7pu4y X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: AA862A000147 Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf15; identity=mailfrom; envelope-from=""; helo=aserp2120.oracle.com; client-ip=141.146.126.78 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618001618-491439 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: free_pool_huge_page was called with hugetlb_lock held. It would remove a hugetlb page, and then free the corresponding pages to the lower level allocators such as buddy. free_pool_huge_page was called in a loop to remove hugetlb pages and these loops could hold the hugetlb_lock for a considerable time. Create new routine remove_pool_huge_page to replace free_pool_huge_page. remove_pool_huge_page will remove the hugetlb page, and it must be called with the hugetlb_lock held. It will return the removed page and it is the responsibility of the caller to free the page to the lower level allocators. The hugetlb_lock is dropped before freeing to these allocators which results in shorter lock hold times. Add new helper routine to call update_and_free_page for a list of pages. Note: Some changes to the routine return_unused_surplus_pages are in need of explanation. Commit e5bbc8a6c992 ("mm/hugetlb.c: fix reservation race when freeing surplus pages") modified this routine to address a race which could occur when dropping the hugetlb_lock in the loop that removes pool pages. Accounting changes introduced in that commit were subtle and took some thought to understand. This commit removes the cond_resched_lock() and the potential race. Therefore, remove the subtle code and restore the more straight forward accounting effectively reverting the commit. Signed-off-by: Mike Kravetz Reviewed-by: Muchun Song Acked-by: Michal Hocko Reviewed-by: Oscar Salvador --- mm/hugetlb.c | 93 ++++++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 42 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index d3e5e49bf687..d4872303a76a 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1204,7 +1204,7 @@ static int hstate_next_node_to_alloc(struct hstate *h, } /* - * helper for free_pool_huge_page() - return the previously saved + * helper for remove_pool_huge_page() - return the previously saved * node ["this node"] from which to free a huge page. Advance the * next node id whether or not we find a free huge page to free so * that the next attempt to free addresses the next node. @@ -1384,6 +1384,16 @@ static void update_and_free_page(struct hstate *h, struct page *page) } } +static void update_and_free_pages_bulk(struct hstate *h, struct list_head *list) +{ + struct page *page, *t_page; + + list_for_each_entry_safe(page, t_page, list, lru) { + update_and_free_page(h, page); + cond_resched(); + } +} + struct hstate *size_to_hstate(unsigned long size) { struct hstate *h; @@ -1714,16 +1724,18 @@ static int alloc_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed, } /* - * Free huge page from pool from next node to free. - * Attempt to keep persistent huge pages more or less - * balanced over allowed nodes. + * Remove huge page from pool from next node to free. Attempt to keep + * persistent huge pages more or less balanced over allowed nodes. + * This routine only 'removes' the hugetlb page. The caller must make + * an additional call to free the page to low level allocators. * Called with hugetlb_lock locked. */ -static int free_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed, - bool acct_surplus) +static struct page *remove_pool_huge_page(struct hstate *h, + nodemask_t *nodes_allowed, + bool acct_surplus) { int nr_nodes, node; - int ret = 0; + struct page *page = NULL; for_each_node_mask_to_free(h, nr_nodes, node, nodes_allowed) { /* @@ -1732,23 +1744,14 @@ static int free_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed, */ if ((!acct_surplus || h->surplus_huge_pages_node[node]) && !list_empty(&h->hugepage_freelists[node])) { - struct page *page = - list_entry(h->hugepage_freelists[node].next, + page = list_entry(h->hugepage_freelists[node].next, struct page, lru); remove_hugetlb_page(h, page, acct_surplus); - /* - * unlock/lock around update_and_free_page is temporary - * and will be removed with subsequent patch. - */ - spin_unlock(&hugetlb_lock); - update_and_free_page(h, page); - spin_lock(&hugetlb_lock); - ret = 1; break; } } - return ret; + return page; } /* @@ -2068,17 +2071,16 @@ static int gather_surplus_pages(struct hstate *h, long delta) * to the associated reservation map. * 2) Free any unused surplus pages that may have been allocated to satisfy * the reservation. As many as unused_resv_pages may be freed. - * - * Called with hugetlb_lock held. However, the lock could be dropped (and - * reacquired) during calls to cond_resched_lock. Whenever dropping the lock, - * we must make sure nobody else can claim pages we are in the process of - * freeing. Do this by ensuring resv_huge_page always is greater than the - * number of huge pages we plan to free when dropping the lock. */ static void return_unused_surplus_pages(struct hstate *h, unsigned long unused_resv_pages) { unsigned long nr_pages; + struct page *page; + LIST_HEAD(page_list); + + /* Uncommit the reservation */ + h->resv_huge_pages -= unused_resv_pages; /* Cannot return gigantic pages currently */ if (hstate_is_gigantic(h)) @@ -2095,24 +2097,21 @@ static void return_unused_surplus_pages(struct hstate *h, * evenly across all nodes with memory. Iterate across these nodes * until we can no longer free unreserved surplus pages. This occurs * when the nodes with surplus pages have no free pages. - * free_pool_huge_page() will balance the freed pages across the + * remove_pool_huge_page() will balance the freed pages across the * on-line nodes with memory and will handle the hstate accounting. - * - * Note that we decrement resv_huge_pages as we free the pages. If - * we drop the lock, resv_huge_pages will still be sufficiently large - * to cover subsequent pages we may free. */ while (nr_pages--) { - h->resv_huge_pages--; - unused_resv_pages--; - if (!free_pool_huge_page(h, &node_states[N_MEMORY], 1)) + page = remove_pool_huge_page(h, &node_states[N_MEMORY], 1); + if (!page) goto out; - cond_resched_lock(&hugetlb_lock); + + list_add(&page->lru, &page_list); } out: - /* Fully uncommit the reservation */ - h->resv_huge_pages -= unused_resv_pages; + spin_unlock(&hugetlb_lock); + update_and_free_pages_bulk(h, &page_list); + spin_lock(&hugetlb_lock); } @@ -2566,7 +2565,6 @@ static void try_to_free_low(struct hstate *h, unsigned long count, nodemask_t *nodes_allowed) { int i; - struct page *page, *next; LIST_HEAD(page_list); if (hstate_is_gigantic(h)) @@ -2576,6 +2574,7 @@ static void try_to_free_low(struct hstate *h, unsigned long count, * Collect pages to be freed on a list, and free after dropping lock */ for_each_node_mask(i, *nodes_allowed) { + struct page *page, *next; struct list_head *freel = &h->hugepage_freelists[i]; list_for_each_entry_safe(page, next, freel, lru) { if (count >= h->nr_huge_pages) @@ -2589,10 +2588,7 @@ static void try_to_free_low(struct hstate *h, unsigned long count, out: spin_unlock(&hugetlb_lock); - list_for_each_entry_safe(page, next, &page_list, lru) { - update_and_free_page(h, page); - cond_resched(); - } + update_and_free_pages_bulk(h, &page_list); spin_lock(&hugetlb_lock); } #else @@ -2639,6 +2635,8 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid, nodemask_t *nodes_allowed) { unsigned long min_count, ret; + struct page *page; + LIST_HEAD(page_list); NODEMASK_ALLOC(nodemask_t, node_alloc_noretry, GFP_KERNEL); /* @@ -2751,11 +2749,22 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid, min_count = h->resv_huge_pages + h->nr_huge_pages - h->free_huge_pages; min_count = max(count, min_count); try_to_free_low(h, min_count, nodes_allowed); + + /* + * Collect pages to be removed on list without dropping lock + */ while (min_count < persistent_huge_pages(h)) { - if (!free_pool_huge_page(h, nodes_allowed, 0)) + page = remove_pool_huge_page(h, nodes_allowed, 0); + if (!page) break; - cond_resched_lock(&hugetlb_lock); + + list_add(&page->lru, &page_list); } + /* free the pages after dropping lock */ + spin_unlock(&hugetlb_lock); + update_and_free_pages_bulk(h, &page_list); + spin_lock(&hugetlb_lock); + while (count < persistent_huge_pages(h)) { if (!adjust_pool_surplus(h, nodes_allowed, 1)) break; From patchwork Fri Apr 9 20:52:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12195083 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.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 24138C433ED for ; Fri, 9 Apr 2021 20:53:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A5C83610E7 for ; Fri, 9 Apr 2021 20:53:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A5C83610E7 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 407576B0078; Fri, 9 Apr 2021 16:53:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BA5A6B007B; Fri, 9 Apr 2021 16:53:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1BDC56B007D; Fri, 9 Apr 2021 16:53:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0037.hostedemail.com [216.40.44.37]) by kanga.kvack.org (Postfix) with ESMTP id E79846B0078 for ; Fri, 9 Apr 2021 16:53:46 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 9F87D1802914A for ; Fri, 9 Apr 2021 20:53:46 +0000 (UTC) X-FDA: 78014030052.19.810048D Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) by imf22.hostedemail.com (Postfix) with ESMTP id 3EDA9C0007D3 for ; Fri, 9 Apr 2021 20:53:43 +0000 (UTC) Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 139KnTOu070833; Fri, 9 Apr 2021 20:53:28 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-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=trx4TZTciQVbJ/A4mmJ0yuGcB7ADXR5lguIkSPVO61s=; b=XtdkxyQFNBYgmbulmcJto4QcrS6nGk9ZnKNh/VxjLYPr8rE7tnueizTCRwxtj0z6j7s2 t3OEwOVDU6EBbJB+t3XHC5SA085oX98A7u9o4c7MDUknRI39RCUIRp40Mb2E6rYEvAiW DfO0ODPz6Z4fPMdtGNC0PfpD/XQzs5DjtGcwzjk9fzSfC9nFScsXMTnuCs6Ld9xpmLGy bpsJBbb+ZZGqnQf2AAfTSeRHAMGDXEBgs/u6FKZKTXL8NI0uLAAjZTJV8OvX3elQyWwh 1i8EbYbO4lm5HH88ba4q+ctmhm5QTLgnaRb5tU8xoU8GbfZ7oZWtRA3cdbMnLr3yVYK5 FQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 37rvasaq5h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 09 Apr 2021 20:53:28 +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 139KjRee174341; Fri, 9 Apr 2021 20:53:27 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2102.outbound.protection.outlook.com [104.47.70.102]) by aserp3020.oracle.com with ESMTP id 37rvb71qrk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 09 Apr 2021 20:53:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pfb13TDqrFm+WB74lzILBhf3JzP/fBu1t35li0ABTanQUIqy7FaWqATSEiLgLykwUb5ncLpiRjgfaYJX/n4hEbUf6WM4497CsxpRDLQ6gTXecmQ5F2YCuzuJ2WxthkXXVq/l1V11+3Rb5tiqERybtx0FwmPHDJrlqpKhZiqBX9lHU4bG/F9GUZEoA4A2EyoyC2OdwjW3aRdK39zNtqxpRKjazbfs5PI1DgMNYwrw7sGidSj3FqbI/2vWoNZovlKv7uWegOl8mSKm4sIalbiaf8hBACR4323HWYsrMHAPLiahai7YYLMK9NPpL7AIrNVUmL1V/0mVFeFdaq7a6xgsFQ== 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=trx4TZTciQVbJ/A4mmJ0yuGcB7ADXR5lguIkSPVO61s=; b=KKl5Vd8vf3j7vo8uXZ3/GI1Z0cFMcx9IXOJUkaBJlH/LZfeth7Djs8nNUxj3TZ+cUro0mUBPN8dquZpOkI431qKyZEdGcQszTuT02jQKzMX0XuDTw9hY+vDojf1bxnO0lDvreV3EI/Vy8wQdkQhFvrqyiVXEorb5hfVDZoCqYdNWJ0iYp4XzKV/M1xK+jkGB+fhko+/3QH3ylJAFWiF5ltnrLDhYIT1Xo+3aR/2FAoYr6uIYhdovz9oYEpo5nOSr/2BIbyMewcc7AwiyncmEjpErfYAg61B3Dtq80SP/I7xjRhjGNrM/ZCyS0ajroQKeIOGDgLr+kT0lCLpFfAJ7ig== 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=trx4TZTciQVbJ/A4mmJ0yuGcB7ADXR5lguIkSPVO61s=; b=Q+k4PrgDYeEvcSN1AX/TZQ6tRXJUp0AKjwFQqudk7RctfmGo1RV4sB/WTrNit3GsjTNaQg5vg9EamxUA9QFEIzwdofZdlGwbnfrB0DdUHE6EyTWPAQU6OTzDfjYSSr2HUBw99BmTxU2RT1mC+RRUeDcNgWvGl5QybRmEfpseOi4= Authentication-Results: kvack.org; dkim=none (message not signed) header.d=none;kvack.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by BY5PR10MB3972.namprd10.prod.outlook.com (2603:10b6:a03:1b6::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.32; Fri, 9 Apr 2021 20:53:25 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee%7]) with mapi id 15.20.4020.018; Fri, 9 Apr 2021 20:53:25 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Roman Gushchin , Michal Hocko , Shakeel Butt , Oscar Salvador , David Hildenbrand , Muchun Song , David Rientjes , Miaohe Lin , Peter Zijlstra , Matthew Wilcox , HORIGUCHI NAOYA , "Aneesh Kumar K . V" , Waiman Long , Peter Xu , Mina Almasry , Hillf Danton , Joonsoo Kim , Barry Song , Will Deacon , Mike Kravetz Subject: [PATCH v5 7/8] hugetlb: make free_huge_page irq safe Date: Fri, 9 Apr 2021 13:52:53 -0700 Message-Id: <20210409205254.242291-8-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210409205254.242291-1-mike.kravetz@oracle.com> References: <20210409205254.242291-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: CO1PR15CA0050.namprd15.prod.outlook.com (2603:10b6:101:1f::18) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from monkey.oracle.com (50.38.35.18) by CO1PR15CA0050.namprd15.prod.outlook.com (2603:10b6:101:1f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Fri, 9 Apr 2021 20:53:23 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3fb94e87-445b-4cf1-3789-08d8fb99849d X-MS-TrafficTypeDiagnostic: BY5PR10MB3972: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1728; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: z25hQZaU99pUY7c1877YgG7vzLcRbLRHxz9VFwjkb76yuYGEkhqQ699EafKa0LDNyA50jihqth5wHV87tSuj3t6SBuWjh5sJqBn7w6cCqAlq45K9DokV18Cxec2vAonTZsfmm8+xClEiYS74uf/G8uD6VT11Omg4zTG27K7P8Ws2w2wsQruSVdXVhIyQfHTVNewV99OkBHsEmU4mfAvG+ZVpwkX4kpZj1sygP2mpBppKoyLhijZMkf28FUxZzk+ejveG3X/NYUauCtmOQHRuy1Sx2zB6AW4TRNMa8JM21WDRDro2wE4/n3dLooMGzhi4sX4pNSbFMPxRKu8KDSNZJN6g9aYk/jlSz9qnsqjqOZptHup+vK3EgL8242H2mMYq/citNA/Z+VHxkeAUDOhVzuzx9rgq+BzlixPel/l9ydlFmTu+3gf5+wC3DTqo0ln4MKZGeUymy7fV7QgBdoRqH1T5x7Yh8VewqJGafLdThhyxNX15+kQXF7X2ubbKF8VcMZnQlbpL7DHeVCdcF2kTYjZ95OHkDHMpNc4IMI+IPugzk/wR1upCo5aaOWCVNlCb7HLwT0OLHtbtjJy0SmoVu5m5gXP4zcTxD8C5ZsGtz/l+vdMQeJ75XknMXrHmnJcGZ84HE7hlFZ6igqReNaB62olxIILkR38qcmMFoz2d6J52migOQbzTOai4CRB9LNbSZHu5AWrkdHwCy6X6kGSxkZ0aX0Vjk4eUuxPYgHSRm1uApcYtBETT9jZP9D2XaRyPAWJuG14fnu8aG+x9iYNswZP2B9PFAfUJX4bPZnL8w98= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(346002)(396003)(376002)(366004)(136003)(39860400002)(38100700001)(5660300002)(66946007)(7416002)(956004)(6486002)(83380400001)(66556008)(966005)(8936002)(30864003)(66476007)(4326008)(316002)(6666004)(6916009)(54906003)(44832011)(7696005)(2906002)(478600001)(1076003)(52116002)(16526019)(38350700001)(107886003)(36756003)(26005)(86362001)(8676002)(186003)(2616005)(14583001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: jUmRA3EuV2+mR61nLQnVboIQScMSO3knkTkcb6fzZdd/bI1PsgwhtTou2pv7budQEwxurfpqGL3mk/+LzRIBM2MQjTGUNh0dehYqtYWw1oV4tiwA5YJQ4M+WA9H0bXIkNfJlh3hUC8RuVzU80dWPSg84SsHNY78/uexFDx+UWa1aXGkwo1POYLANCNscmpfUP5xXxqgKcXXXIqFcgfebDk6pNBgKFz7SatDGbFVm7iaOHCTDKHMstDMCsyyT76Cl/S0mzf/HuH4k3a/2zrzeQQiuOC3eXXY7JSU3DVHbndbEsfgX4P33kK46yYDSZx46xAJjxNAeh7/RajXz0tbK8s+YufMo4cM6OKyE4PNoz08Y5eL8EaxRxQzJFidxAUEalRqHNFwnVBXmkQzSjOsCcmIgBBegJuQyyz/uHWyUPBTvgdepQoZFPA32osCqVgcjrKPqUj1CnICNRp+1HGpvIhBC8MzTqcoWmZB4rlahkmy6OrJabQn+Tf5PcQg9BbGpFfmE/c1KOo6v82y+f6kpnJ3ELQOA3Dg9XoZksRnCLeJixenQB0C3gOBqhfd2m5bEzkc843m3BsDXnxs8DcwoimULdO0hv63cElMhEruh3mm7Bo9X0rxRA7sSXqCRsFT1WCsuBujslStmDxPj17OLfGihmmvSW4J5UISOk1DW7iuAefTvyqm8MD97vE5XPOJvejqWEePFWCXIt46wuPnt0ILDVo6vsstqr5SsG5ouGEPMeELtjL7snYI1GixxnOwbspOGzf+6m5NizmoQtJgCDt4ebd9+og1YqoI3186I80/gK9+kIlSzEshROPnhwk6jvVrnLC9q67aWjCb47dadaTN3SENrPpkP2uMyJ3apRYRhQmwUsFkt38mQv7w+3mkFPy8ovVTgQrKRQPgWnEH1TX9ztbb0XZ81EDm6fKe32j+tkD+eY5hy/Y6aM+Mz4h1CcNk0EKMbDxdsSCZOGv+9FXf2CMCy+gx4PmrzivY1hc/y/UMl+1uymbZN5kbbITKvuBbUZvT8VJWVZadPxJuU81vtN8u1jKxdEkXO0SpiWo2SFhEClm1iWFcCXSHCyesMjfxVCSlvX4mBYnyfiI40jWloOO2ACdX439Rot7iPFHcp8FvPqYW5aSartZvUp86XN9GODFZnnxTDb6Pv+G2m+wvJIUtjEv0x48qcbcVoCVyYk6ufQyXecU4M9Xwecs4rhZJ/1l+xf3UI0VnS4EsZ35WKa110Qvr52wjDOChDkSIdT/ru+XSs/50KTj2XC2pA6XFzWkbPKpHH0S9bLys8Fp0YsQTxfy/aqPJtv0jcB7SLl9YhUby02cNCVoIMB0Vm X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3fb94e87-445b-4cf1-3789-08d8fb99849d X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2021 20:53:24.8942 (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: 5L1bbRsdhU5kOr1HMXRSNMGJ2Li+BHmlaG1jJQ7Q9RB4OP+PY3PFLplqyUcSQvRtnPJsFkNES7e4Zgv/rn/4Jg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB3972 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9949 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 suspectscore=0 adultscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104090152 X-Proofpoint-GUID: v5ygzdZFdejTAG4-ef7-cDgrnfrn5tTy X-Proofpoint-ORIG-GUID: v5ygzdZFdejTAG4-ef7-cDgrnfrn5tTy X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9949 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 adultscore=0 priorityscore=1501 malwarescore=0 mlxlogscore=999 clxscore=1015 bulkscore=0 mlxscore=0 phishscore=0 spamscore=0 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104090152 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 3EDA9C0007D3 X-Stat-Signature: ughbdwa6ew58ebszsffsem4141ho837t Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf22; identity=mailfrom; envelope-from=""; helo=userp2120.oracle.com; client-ip=156.151.31.85 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618001623-698904 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: Commit c77c0a8ac4c5 ("mm/hugetlb: defer freeing of huge pages if in non-task context") was added to address the issue of free_huge_page being called from irq context. That commit hands off free_huge_page processing to a workqueue if !in_task. However, this doesn't cover all the cases as pointed out by 0day bot lockdep report [1]. : Possible interrupt unsafe locking scenario: : : CPU0 CPU1 : ---- ---- : lock(hugetlb_lock); : local_irq_disable(); : lock(slock-AF_INET); : lock(hugetlb_lock); : : lock(slock-AF_INET); Shakeel has later explained that this is very likely TCP TX zerocopy from hugetlb pages scenario when the networking code drops a last reference to hugetlb page while having IRQ disabled. Hugetlb freeing path doesn't disable IRQ while holding hugetlb_lock so a lock dependency chain can lead to a deadlock. This commit addresses the issue by doing the following: - Make hugetlb_lock irq safe. This is mostly a simple process of changing spin_*lock calls to spin_*lock_irq* calls. - Make subpool lock irq safe in a similar manner. - Revert the !in_task check and workqueue handoff. [1] https://lore.kernel.org/linux-mm/000000000000f1c03b05bc43aadc@google.com/ Signed-off-by: Mike Kravetz Acked-by: Michal Hocko Reviewed-by: Muchun Song Reviewed-by: Oscar Salvador --- mm/hugetlb.c | 169 +++++++++++++++++--------------------------- mm/hugetlb_cgroup.c | 8 +-- 2 files changed, 67 insertions(+), 110 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index d4872303a76a..049ca0bccfcc 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -93,9 +93,10 @@ static inline bool subpool_is_free(struct hugepage_subpool *spool) return true; } -static inline void unlock_or_release_subpool(struct hugepage_subpool *spool) +static inline void unlock_or_release_subpool(struct hugepage_subpool *spool, + unsigned long irq_flags) { - spin_unlock(&spool->lock); + spin_unlock_irqrestore(&spool->lock, irq_flags); /* If no pages are used, and no other handles to the subpool * remain, give up any reservations based on minimum size and @@ -134,10 +135,12 @@ struct hugepage_subpool *hugepage_new_subpool(struct hstate *h, long max_hpages, void hugepage_put_subpool(struct hugepage_subpool *spool) { - spin_lock(&spool->lock); + unsigned long flags; + + spin_lock_irqsave(&spool->lock, flags); BUG_ON(!spool->count); spool->count--; - unlock_or_release_subpool(spool); + unlock_or_release_subpool(spool, flags); } /* @@ -156,7 +159,7 @@ static long hugepage_subpool_get_pages(struct hugepage_subpool *spool, if (!spool) return ret; - spin_lock(&spool->lock); + spin_lock_irq(&spool->lock); if (spool->max_hpages != -1) { /* maximum size accounting */ if ((spool->used_hpages + delta) <= spool->max_hpages) @@ -183,7 +186,7 @@ static long hugepage_subpool_get_pages(struct hugepage_subpool *spool, } unlock_ret: - spin_unlock(&spool->lock); + spin_unlock_irq(&spool->lock); return ret; } @@ -197,11 +200,12 @@ static long hugepage_subpool_put_pages(struct hugepage_subpool *spool, long delta) { long ret = delta; + unsigned long flags; if (!spool) return delta; - spin_lock(&spool->lock); + spin_lock_irqsave(&spool->lock, flags); if (spool->max_hpages != -1) /* maximum size accounting */ spool->used_hpages -= delta; @@ -222,7 +226,7 @@ static long hugepage_subpool_put_pages(struct hugepage_subpool *spool, * If hugetlbfs_put_super couldn't free spool due to an outstanding * quota reference, free it now. */ - unlock_or_release_subpool(spool); + unlock_or_release_subpool(spool, flags); return ret; } @@ -1405,7 +1409,7 @@ struct hstate *size_to_hstate(unsigned long size) return NULL; } -static void __free_huge_page(struct page *page) +void free_huge_page(struct page *page) { /* * Can't pass hstate in here because it is called from the @@ -1415,6 +1419,7 @@ static void __free_huge_page(struct page *page) int nid = page_to_nid(page); struct hugepage_subpool *spool = hugetlb_page_subpool(page); bool restore_reserve; + unsigned long flags; VM_BUG_ON_PAGE(page_count(page), page); VM_BUG_ON_PAGE(page_mapcount(page), page); @@ -1443,7 +1448,7 @@ static void __free_huge_page(struct page *page) restore_reserve = true; } - spin_lock(&hugetlb_lock); + spin_lock_irqsave(&hugetlb_lock, flags); ClearHPageMigratable(page); hugetlb_cgroup_uncharge_page(hstate_index(h), pages_per_huge_page(h), page); @@ -1454,66 +1459,18 @@ static void __free_huge_page(struct page *page) if (HPageTemporary(page)) { remove_hugetlb_page(h, page, false); - spin_unlock(&hugetlb_lock); + spin_unlock_irqrestore(&hugetlb_lock, flags); update_and_free_page(h, page); } else if (h->surplus_huge_pages_node[nid]) { /* remove the page from active list */ remove_hugetlb_page(h, page, true); - spin_unlock(&hugetlb_lock); + spin_unlock_irqrestore(&hugetlb_lock, flags); update_and_free_page(h, page); } else { arch_clear_hugepage_flags(page); enqueue_huge_page(h, page); - spin_unlock(&hugetlb_lock); - } -} - -/* - * As free_huge_page() can be called from a non-task context, we have - * to defer the actual freeing in a workqueue to prevent potential - * hugetlb_lock deadlock. - * - * free_hpage_workfn() locklessly retrieves the linked list of pages to - * be freed and frees them one-by-one. As the page->mapping pointer is - * going to be cleared in __free_huge_page() anyway, it is reused as the - * llist_node structure of a lockless linked list of huge pages to be freed. - */ -static LLIST_HEAD(hpage_freelist); - -static void free_hpage_workfn(struct work_struct *work) -{ - struct llist_node *node; - struct page *page; - - node = llist_del_all(&hpage_freelist); - - while (node) { - page = container_of((struct address_space **)node, - struct page, mapping); - node = node->next; - __free_huge_page(page); - } -} -static DECLARE_WORK(free_hpage_work, free_hpage_workfn); - -void free_huge_page(struct page *page) -{ - /* - * Defer freeing if in non-task context to avoid hugetlb_lock deadlock. - */ - if (!in_task()) { - /* - * Only call schedule_work() if hpage_freelist is previously - * empty. Otherwise, schedule_work() had been called but the - * workfn hasn't retrieved the list yet. - */ - if (llist_add((struct llist_node *)&page->mapping, - &hpage_freelist)) - schedule_work(&free_hpage_work); - return; + spin_unlock_irqrestore(&hugetlb_lock, flags); } - - __free_huge_page(page); } static void prep_new_huge_page(struct hstate *h, struct page *page, int nid) @@ -1523,11 +1480,11 @@ static void prep_new_huge_page(struct hstate *h, struct page *page, int nid) hugetlb_set_page_subpool(page, NULL); set_hugetlb_cgroup(page, NULL); set_hugetlb_cgroup_rsvd(page, NULL); - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); h->nr_huge_pages++; h->nr_huge_pages_node[nid]++; ClearHPageFreed(page); - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); } static void prep_compound_gigantic_page(struct page *page, unsigned int order) @@ -1773,7 +1730,7 @@ int dissolve_free_huge_page(struct page *page) if (!PageHuge(page)) return 0; - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); if (!PageHuge(page)) { rc = 0; goto out; @@ -1790,7 +1747,7 @@ int dissolve_free_huge_page(struct page *page) * when it is dissolved. */ if (unlikely(!HPageFreed(head))) { - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); cond_resched(); /* @@ -1814,12 +1771,12 @@ int dissolve_free_huge_page(struct page *page) } remove_hugetlb_page(h, page, false); h->max_huge_pages--; - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); update_and_free_page(h, head); return 0; } out: - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); return rc; } @@ -1861,16 +1818,16 @@ static struct page *alloc_surplus_huge_page(struct hstate *h, gfp_t gfp_mask, if (hstate_is_gigantic(h)) return NULL; - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); if (h->surplus_huge_pages >= h->nr_overcommit_huge_pages) goto out_unlock; - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); page = alloc_fresh_huge_page(h, gfp_mask, nid, nmask, NULL); if (!page) return NULL; - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); /* * We could have raced with the pool size change. * Double check that and simply deallocate the new page @@ -1880,7 +1837,7 @@ static struct page *alloc_surplus_huge_page(struct hstate *h, gfp_t gfp_mask, */ if (h->surplus_huge_pages >= h->nr_overcommit_huge_pages) { SetHPageTemporary(page); - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); put_page(page); return NULL; } else { @@ -1889,7 +1846,7 @@ static struct page *alloc_surplus_huge_page(struct hstate *h, gfp_t gfp_mask, } out_unlock: - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); return page; } @@ -1939,17 +1896,17 @@ struct page *alloc_buddy_huge_page_with_mpol(struct hstate *h, struct page *alloc_huge_page_nodemask(struct hstate *h, int preferred_nid, nodemask_t *nmask, gfp_t gfp_mask) { - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); if (h->free_huge_pages - h->resv_huge_pages > 0) { struct page *page; page = dequeue_huge_page_nodemask(h, gfp_mask, preferred_nid, nmask); if (page) { - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); return page; } } - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); return alloc_migrate_huge_page(h, gfp_mask, preferred_nid, nmask); } @@ -1997,7 +1954,7 @@ static int gather_surplus_pages(struct hstate *h, long delta) ret = -ENOMEM; retry: - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); for (i = 0; i < needed; i++) { page = alloc_surplus_huge_page(h, htlb_alloc_mask(h), NUMA_NO_NODE, NULL); @@ -2014,7 +1971,7 @@ static int gather_surplus_pages(struct hstate *h, long delta) * After retaking hugetlb_lock, we need to recalculate 'needed' * because either resv_huge_pages or free_huge_pages may have changed. */ - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); needed = (h->resv_huge_pages + delta) - (h->free_huge_pages + allocated); if (needed > 0) { @@ -2054,12 +2011,12 @@ static int gather_surplus_pages(struct hstate *h, long delta) enqueue_huge_page(h, page); } free: - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); /* Free unnecessary surplus pages to the buddy allocator */ list_for_each_entry_safe(page, tmp, &surplus_list, lru) put_page(page); - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); return ret; } @@ -2109,9 +2066,9 @@ static void return_unused_surplus_pages(struct hstate *h, } out: - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); update_and_free_pages_bulk(h, &page_list); - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); } @@ -2346,7 +2303,7 @@ struct page *alloc_huge_page(struct vm_area_struct *vma, if (ret) goto out_uncharge_cgroup_reservation; - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); /* * glb_chg is passed to indicate whether or not a page must be taken * from the global free pool (global change). gbl_chg == 0 indicates @@ -2354,7 +2311,7 @@ struct page *alloc_huge_page(struct vm_area_struct *vma, */ page = dequeue_huge_page_vma(h, vma, addr, avoid_reserve, gbl_chg); if (!page) { - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); page = alloc_buddy_huge_page_with_mpol(h, vma, addr); if (!page) goto out_uncharge_cgroup; @@ -2362,7 +2319,7 @@ struct page *alloc_huge_page(struct vm_area_struct *vma, SetHPageRestoreReserve(page); h->resv_huge_pages--; } - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); list_add(&page->lru, &h->hugepage_activelist); /* Fall through */ } @@ -2375,7 +2332,7 @@ struct page *alloc_huge_page(struct vm_area_struct *vma, h_cg, page); } - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); hugetlb_set_page_subpool(page, spool); @@ -2587,9 +2544,9 @@ static void try_to_free_low(struct hstate *h, unsigned long count, } out: - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); update_and_free_pages_bulk(h, &page_list); - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); } #else static inline void try_to_free_low(struct hstate *h, unsigned long count, @@ -2654,7 +2611,7 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid, * pages in hstate via the proc/sysfs interfaces. */ mutex_lock(&h->resize_lock); - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); /* * Check for a node specific request. @@ -2685,7 +2642,7 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid, */ if (hstate_is_gigantic(h) && !IS_ENABLED(CONFIG_CONTIG_ALLOC)) { if (count > persistent_huge_pages(h)) { - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); mutex_unlock(&h->resize_lock); NODEMASK_FREE(node_alloc_noretry); return -EINVAL; @@ -2715,14 +2672,14 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid, * page, free_huge_page will handle it by freeing the page * and reducing the surplus. */ - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); /* yield cpu to avoid soft lockup */ cond_resched(); ret = alloc_pool_huge_page(h, nodes_allowed, node_alloc_noretry); - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); if (!ret) goto out; @@ -2761,9 +2718,9 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid, list_add(&page->lru, &page_list); } /* free the pages after dropping lock */ - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); update_and_free_pages_bulk(h, &page_list); - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); while (count < persistent_huge_pages(h)) { if (!adjust_pool_surplus(h, nodes_allowed, 1)) @@ -2771,7 +2728,7 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid, } out: h->max_huge_pages = persistent_huge_pages(h); - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); mutex_unlock(&h->resize_lock); NODEMASK_FREE(node_alloc_noretry); @@ -2927,9 +2884,9 @@ static ssize_t nr_overcommit_hugepages_store(struct kobject *kobj, if (err) return err; - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); h->nr_overcommit_huge_pages = input; - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); return count; } @@ -3516,9 +3473,9 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write, goto out; if (write) { - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); h->nr_overcommit_huge_pages = tmp; - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); } out: return ret; @@ -3614,7 +3571,7 @@ static int hugetlb_acct_memory(struct hstate *h, long delta) if (!delta) return 0; - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); /* * When cpuset is configured, it breaks the strict hugetlb page * reservation as the accounting is done on a global variable. Such @@ -3653,7 +3610,7 @@ static int hugetlb_acct_memory(struct hstate *h, long delta) return_unused_surplus_pages(h, (unsigned long) -delta); out: - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); return ret; } @@ -5717,7 +5674,7 @@ bool isolate_huge_page(struct page *page, struct list_head *list) { bool ret = true; - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); if (!PageHeadHuge(page) || !HPageMigratable(page) || !get_page_unless_zero(page)) { @@ -5727,16 +5684,16 @@ bool isolate_huge_page(struct page *page, struct list_head *list) ClearHPageMigratable(page); list_move_tail(&page->lru, list); unlock: - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); return ret; } void putback_active_hugepage(struct page *page) { - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); SetHPageMigratable(page); list_move_tail(&page->lru, &(page_hstate(page))->hugepage_activelist); - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); put_page(page); } @@ -5770,12 +5727,12 @@ void move_hugetlb_state(struct page *oldpage, struct page *newpage, int reason) */ if (new_nid == old_nid) return; - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); if (h->surplus_huge_pages_node[old_nid]) { h->surplus_huge_pages_node[old_nid]--; h->surplus_huge_pages_node[new_nid]++; } - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); } } diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c index 726b85f4f303..5383023d0cca 100644 --- a/mm/hugetlb_cgroup.c +++ b/mm/hugetlb_cgroup.c @@ -204,11 +204,11 @@ static void hugetlb_cgroup_css_offline(struct cgroup_subsys_state *css) do { idx = 0; for_each_hstate(h) { - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); list_for_each_entry(page, &h->hugepage_activelist, lru) hugetlb_cgroup_move_parent(idx, h_cg, page); - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); idx++; } cond_resched(); @@ -784,7 +784,7 @@ void hugetlb_cgroup_migrate(struct page *oldhpage, struct page *newhpage) if (hugetlb_cgroup_disabled()) return; - spin_lock(&hugetlb_lock); + spin_lock_irq(&hugetlb_lock); h_cg = hugetlb_cgroup_from_page(oldhpage); h_cg_rsvd = hugetlb_cgroup_from_page_rsvd(oldhpage); set_hugetlb_cgroup(oldhpage, NULL); @@ -794,7 +794,7 @@ void hugetlb_cgroup_migrate(struct page *oldhpage, struct page *newhpage) set_hugetlb_cgroup(newhpage, h_cg); set_hugetlb_cgroup_rsvd(newhpage, h_cg_rsvd); list_move(&newhpage->lru, &h->hugepage_activelist); - spin_unlock(&hugetlb_lock); + spin_unlock_irq(&hugetlb_lock); return; } From patchwork Fri Apr 9 20:52:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12195081 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.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 075ACC433ED for ; Fri, 9 Apr 2021 20:53:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A29E8610E7 for ; Fri, 9 Apr 2021 20:53:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A29E8610E7 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 455D96B0075; Fri, 9 Apr 2021 16:53:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 406856B0078; Fri, 9 Apr 2021 16:53:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E2AA6B007B; Fri, 9 Apr 2021 16:53:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0228.hostedemail.com [216.40.44.228]) by kanga.kvack.org (Postfix) with ESMTP id 0220A6B0075 for ; Fri, 9 Apr 2021 16:53:44 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id C1930BF0A for ; Fri, 9 Apr 2021 20:53:44 +0000 (UTC) X-FDA: 78014029968.12.36202FB Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) by imf26.hostedemail.com (Postfix) with ESMTP id 19DBD40002D2 for ; Fri, 9 Apr 2021 20:53:39 +0000 (UTC) Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 139KnFd7028850; Fri, 9 Apr 2021 20:53:29 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-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=KFsTE2vrECjTbvsLeSvgSWewsuDLc2psH6Wi8Zq6GX0=; b=bdCLvTDkwnT2gkxHrV/rx6N6JOkiT6K82v6hnBI/8gF/suiSb22M/640DKc44wlI1zyg fyR85ZLR8t353UGIbdipAhG1HByNzLKTA1GULTWLVQzdq7y63VJndJGEFyOiSz0dKgYI 973dHMly9Ec/2op0MPhk7fODlz7HUNk2PQW7rW9SOvov3/IKz06v1n6UpR18c+NGX6hc /pVGBv3zXpUDSvJeYPkImMJ91FfmuaeTA1FQeWCfUA61mxpdnrwPNyZoB1UrdxxpSDaJ 8Gr/gmJvZo/xoBlhP3D+TK0I+4tsCxZXsVJULg5K0CtORUG7dTjW/ARwBd4+X/rkBfRy dg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2130.oracle.com with ESMTP id 37rvawaqb7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 09 Apr 2021 20:53:29 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 139KkEYQ178858; Fri, 9 Apr 2021 20:53:29 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2048.outbound.protection.outlook.com [104.47.56.48]) by aserp3030.oracle.com with ESMTP id 37rvbj1prb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 09 Apr 2021 20:53:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Mq+zzwwjgZ/unbmpKVAKWnkIbQJ2/1ybWlSZ3YTjEn/5TDouNWS+0DttqdYGc7zn8RzCnjO+4b+Gql37NcuvDo/mHkgoXV3Avkr1qzPlDHRcv0X4mvbWOR10J22IQjg4zPJYWNKK2oARnCNncxZcdq4IS5r22P97rsrnPs4H7nGUN1/6k3iQWVtZBU4jhWtNkG+MeLadpq1D0fz054wu/HbWtVzIJRL4Arf6WVZoVf08Cpo2DR1ejlYIs8C6e5yr4HK654TPTOtc5mGh+vwsb6SzgTRZ+q7b4kiK0VKMyEYKDVU5rwhu2DWKZn9IZsLKE9ErpQTL4O7GX1nz63kNyw== 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=KFsTE2vrECjTbvsLeSvgSWewsuDLc2psH6Wi8Zq6GX0=; b=Wk2U3chVzi1/ryDo/4VsaP4Pu9bmb3ibN3/cmfnPYIaSNLZqH3kTDR0Ljo7UuhUe6hVgNqK8y9OcTQFJ+7xNRYFIk5t2EZkU5sa1Kk9f4E2VTHEY0rcNEjP0qPkKHLe4YqVnkTTBlsy723c2RWm6OE+VF3QOSkh3zQsXcpPOPkb1w91DKiHyNZVwNUvsiwA5wAVRpx1dmMEkSAuRtOiDf3Y3I0r5w67vurejbzJCKi/5/QemTJVNOdoUt654oMamgXY8VTx1PvT3xs3BBgqVh1SPle35zyv6TSM2p7+BH2dNtX3qsZ4jBJ4KVPPqEos6uTKzq9b+T90ko5RxXjdfQg== 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=KFsTE2vrECjTbvsLeSvgSWewsuDLc2psH6Wi8Zq6GX0=; b=oHUhXfS3Xwx7OtuFSMepKrsPNlNmxF4C1VRXqVHEocbDXEh5IiSD761AzaATFcZDW6E+zegyYa6zZjdUomYUVx4TthNvPrTi56n98wIExWH+8sA+kHGph48MjJF4gzjf8vDNjZyaM8mvWwe3ANeSn0QUvVlCM6Vca5L1pupIx7E= Authentication-Results: kvack.org; dkim=none (message not signed) header.d=none;kvack.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by BY5PR10MB3988.namprd10.prod.outlook.com (2603:10b6:a03:1b1::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17; Fri, 9 Apr 2021 20:53:27 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee%7]) with mapi id 15.20.4020.018; Fri, 9 Apr 2021 20:53:27 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Roman Gushchin , Michal Hocko , Shakeel Butt , Oscar Salvador , David Hildenbrand , Muchun Song , David Rientjes , Miaohe Lin , Peter Zijlstra , Matthew Wilcox , HORIGUCHI NAOYA , "Aneesh Kumar K . V" , Waiman Long , Peter Xu , Mina Almasry , Hillf Danton , Joonsoo Kim , Barry Song , Will Deacon , Mike Kravetz Subject: [PATCH v5 8/8] hugetlb: add lockdep_assert_held() calls for hugetlb_lock Date: Fri, 9 Apr 2021 13:52:54 -0700 Message-Id: <20210409205254.242291-9-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210409205254.242291-1-mike.kravetz@oracle.com> References: <20210409205254.242291-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: CO1PR15CA0050.namprd15.prod.outlook.com (2603:10b6:101:1f::18) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from monkey.oracle.com (50.38.35.18) by CO1PR15CA0050.namprd15.prod.outlook.com (2603:10b6:101:1f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Fri, 9 Apr 2021 20:53:26 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2d0f73a3-cb30-4cc4-19d2-08d8fb9985e8 X-MS-TrafficTypeDiagnostic: BY5PR10MB3988: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mJzPSjCD50aoYXzHsexL4mLJFXXl3DIdFB8Hl8+3/UEpCJS5P1IQgkvms4DX44nq84lN3gE6+CRxKFdfcGW44C7561XNkURh+nMqltPXucxzVfftVoVBvEnBN662OvQpC+jmzchQfhq63LotKv+/4oDemF01HnBPdQkFR/Kt5ry5NYg3ElHn0hYaUadABgWPhyxgcKLay8ESjVwzRrlHNKBPXV2Q57/VRY/jdZ8RqpYQuMVuoeuMYYlXt68/N7WG3N3GoE9hef/UdAWRqoQKZ9ox/mtsUeshQ62PvORqkq/yQ9PWWsitaHpUCln7358pSqkm2Ejxmm+rAqge7s9URJx1QPiET8OntMU6h0QT10D64ugizmbCb8yKje4NXSRw4gODdxaBsIFr9Besn7HdVUY2XoTAjur68Z9g4Iv9duBbuho8lSA4Z4labJmYTKH+3Izl1ATfkpmHwt3lcn6JjnLoxNM+ghe3p4ouIWRQLWlmjqiYT4uqjhk0dVJVnlFzcS9tNXRmS23u5kUF/XcZymBaAjnyiKnJcyZIMPNGNrC98IAeo/MSZSaC8X6vp0b58IdoVErLESbScfgWBcMGWsB5q7ZWv6AS1RY+lkcfkYqGzDrnZnEC4Mq/80EGETaJ0clwCoFuxiL13diBPbW2EiN93v85omFjX3VoRjOmM6JUnOwAm1d6s5uUTmq4YRzs X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(376002)(346002)(396003)(136003)(366004)(39860400002)(7416002)(478600001)(8936002)(107886003)(83380400001)(36756003)(956004)(6486002)(52116002)(8676002)(2616005)(44832011)(4326008)(38100700001)(38350700001)(2906002)(86362001)(66946007)(26005)(66556008)(7696005)(16526019)(6666004)(186003)(316002)(1076003)(6916009)(54906003)(5660300002)(66476007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: cyRA/lTHwt/ZUdGIrnmjgdTbz1rkN9ZCzUMx8EHZjMcbmFUiaQwZaSXFtdMpbJhWKBhqm8J1s3oXxOzmuhTEpNrVyFXzj8I0B5kNFcw19shCsKgUVAeoWYZAtrW3RJ7MC1PZVoXw3DUCyrqlCuul4uVRVvQ6of8u5aHqA7JXgKLxgNIsEx3dMoexMaSlAgTYUp+TjmkwPoKq7xHD9qgo/I21EWHXJ/Yp+5wySVcpeoydMgUBddSGrzWmRW5C5P1nCVcKO53SkfKrw1OWgonXnXep/Y4DhidoJaulqkmDD9tXTIdPDueupr0qM0B27sqCarV7tNKe7SZ+l4l77eRyHPuWlKal5HGCknmxr6CBadfrvyAL3ILWHkDJJHDOZq5VvDlz2E8EkKTAkK7OHM54rVeaPEVir7Ia5Z0nUc67H0U2kkLvzz8XSvsU8vkaGR6Xr2dZ5zoMNd0u6TLWfu0CHRDDH7URk/pBobQc5G+MUrmSEQKJsgdxjO3oZ8IUpORuYLGuPVML0xrqNdUGekqjg/PR5eDfILZ3vHp4QBF38C6+DWybrFVNKRrbbuolz5yh6kYeMkrCvD7CTQ9TVKCeu0f4iAsX12hw/k6OoJaHUm1PnR46MFSEA8K8zZwaIPWCU3ZKnmjNTwfhIuN+VkAqiPoLqwiiXXx6qA5nq614EwPfCGxEcMiyIqsd4tAP7xxHykOOhtRI86MU/UY6OgYNn+cQB22nnIgSXEq8aEtftcRFPnYVNIJNvDG9bmMZK4M7d9wrpzvTbobuhl4pQuhnxE0yXWlqx3RFiu+GxtHtTxY9Tc9veNth73a+FzGghF+gcwAp3w1hp25NGgjco+amp3glnqxVu4CvQkSggUSj6Ke27PpiKK3NjgnayoFsjBWz+bHjfOaMxggsoL89zDdvD2yVSCeqQ8FvE1nPGyyQ0xInL6tgKgkxKcxMKoxkD4T6g3+aTy9Zt6Qa1M9/wvfpUThgigM+Nf8ixSf+a1290eaoggXanh1g35WowHNQLmEMhmBE2jxZLImZdDdhFbMEY/pG30kHSfbALPcqiDuNquoKcCYj5JwFLuLlbRi145TGaiw4RF8emJRBwkOZVHTDkXl7jPqDMIQyRYifvYWDh79K3THe9x6ejl4vAKFc5esNS9X5NVEdMAI2+UeIeVhY6GGK7mS4DY5/9G9Y4dUTfyxuaehz84RC6UDIHwxUGfc8nLwy5Lu5ee3E3usy6aTz4aB40Au/YrnWUDzsxO2s23hXSgPQiFDT4yPqJeEXDy4/YRiKlhS9N/TFF1VE+2PEBOhCxcKX6jBMNzq9SlpMbLV3waZ7vnm8XKWa88zCqwSk X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2d0f73a3-cb30-4cc4-19d2-08d8fb9985e8 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2021 20:53:26.9771 (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: 3Lc1KW/iyas++eVDh/ESSZxRaQRzFVlw0BaHgUHtTYBNLCo/dacUiK/uw1KMQpeTGgyQkupq+Kfuz2gO6SYAAA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB3988 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9949 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 phishscore=0 spamscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104090152 X-Proofpoint-ORIG-GUID: kzBVHzZqU5QGTFo6kwtiGUmyHpnJ3dXw X-Proofpoint-GUID: kzBVHzZqU5QGTFo6kwtiGUmyHpnJ3dXw X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9949 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 phishscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 mlxscore=0 bulkscore=0 impostorscore=0 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104090152 X-Rspamd-Queue-Id: 19DBD40002D2 X-Stat-Signature: 3mxaraimgm5n49fw9b5t4s1nf5wtzdx5 X-Rspamd-Server: rspam02 Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf26; identity=mailfrom; envelope-from=""; helo=aserp2130.oracle.com; client-ip=141.146.126.79 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618001619-274638 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: After making hugetlb lock irq safe and separating some functionality done under the lock, add some lockdep_assert_held to help verify locking. Signed-off-by: Mike Kravetz Acked-by: Michal Hocko Reviewed-by: Miaohe Lin Reviewed-by: Muchun Song Reviewed-by: Oscar Salvador --- mm/hugetlb.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 049ca0bccfcc..5cf2b7e5ca50 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1062,6 +1062,8 @@ static bool vma_has_reserves(struct vm_area_struct *vma, long chg) static void enqueue_huge_page(struct hstate *h, struct page *page) { int nid = page_to_nid(page); + + lockdep_assert_held(&hugetlb_lock); list_move(&page->lru, &h->hugepage_freelists[nid]); h->free_huge_pages++; h->free_huge_pages_node[nid]++; @@ -1073,6 +1075,7 @@ static struct page *dequeue_huge_page_node_exact(struct hstate *h, int nid) struct page *page; bool pin = !!(current->flags & PF_MEMALLOC_PIN); + lockdep_assert_held(&hugetlb_lock); list_for_each_entry(page, &h->hugepage_freelists[nid], lru) { if (pin && !is_pinnable_page(page)) continue; @@ -1344,6 +1347,7 @@ static void remove_hugetlb_page(struct hstate *h, struct page *page, VM_BUG_ON_PAGE(hugetlb_cgroup_from_page(page), page); VM_BUG_ON_PAGE(hugetlb_cgroup_from_page_rsvd(page), page); + lockdep_assert_held(&hugetlb_lock); if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported()) return; @@ -1694,6 +1698,7 @@ static struct page *remove_pool_huge_page(struct hstate *h, int nr_nodes, node; struct page *page = NULL; + lockdep_assert_held(&hugetlb_lock); for_each_node_mask_to_free(h, nr_nodes, node, nodes_allowed) { /* * If we're returning unused surplus pages, only examine @@ -1943,6 +1948,7 @@ static int gather_surplus_pages(struct hstate *h, long delta) long needed, allocated; bool alloc_ok = true; + lockdep_assert_held(&hugetlb_lock); needed = (h->resv_huge_pages + delta) - h->free_huge_pages; if (needed <= 0) { h->resv_huge_pages += delta; @@ -2036,6 +2042,7 @@ static void return_unused_surplus_pages(struct hstate *h, struct page *page; LIST_HEAD(page_list); + lockdep_assert_held(&hugetlb_lock); /* Uncommit the reservation */ h->resv_huge_pages -= unused_resv_pages; @@ -2524,6 +2531,7 @@ static void try_to_free_low(struct hstate *h, unsigned long count, int i; LIST_HEAD(page_list); + lockdep_assert_held(&hugetlb_lock); if (hstate_is_gigantic(h)) return; @@ -2565,6 +2573,7 @@ static int adjust_pool_surplus(struct hstate *h, nodemask_t *nodes_allowed, { int nr_nodes, node; + lockdep_assert_held(&hugetlb_lock); VM_BUG_ON(delta != -1 && delta != 1); if (delta < 0) {