From patchwork Wed Mar 31 03:41:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12174299 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=-13.8 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, UNWANTED_LANGUAGE_BODY,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 E41C9C433DB for ; Wed, 31 Mar 2021 03:42:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5BAF161954 for ; Wed, 31 Mar 2021 03:42:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5BAF161954 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 E67A26B0085; Tue, 30 Mar 2021 23:42:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D77326B0083; Tue, 30 Mar 2021 23:42:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A465A6B0085; Tue, 30 Mar 2021 23:42:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0024.hostedemail.com [216.40.44.24]) by kanga.kvack.org (Postfix) with ESMTP id 82F666B0082 for ; Tue, 30 Mar 2021 23:42:33 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 4BCB91DE7 for ; Wed, 31 Mar 2021 03:42:33 +0000 (UTC) X-FDA: 77978772186.10.0F117ED Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by imf19.hostedemail.com (Postfix) with ESMTP id 57D6490009EA for ; Wed, 31 Mar 2021 03:42:32 +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 12V3ejIx182875; Wed, 31 Mar 2021 03:42:05 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=OKPBngNAFI9bp85dSsVhMD8GLSrYA03jpGeJ0VDnCJQ=; b=h4YgtXjJA7s1y9iOpNkWpbbyC3S83VkPXvaE86rj+TIT9U+glSI+zuf5GjNymfsPRxSI cWde9C8M9Sf/eQKwWjVSj/qdlLBJg6J0F6PWPO2T9eQHIT0daqLIGQr1IGkAlrsxACEW eBVeGMjeuj+VyA5+s71L+/bRHF6O3v6Eo456kn45YJ7nXHTmJVm6KnNXN8WUMlRiGaxx dCJOpLvDmqYTdxNbRELFhiVlc73SSGGEktEJa0THcfikI47MxHnXAjjNM+pGRnT3fp/A 9mKrSnMTYcmO3rv71QNe1E7mAEz0rAzsuQPs7u0MkCSIkTB9G3+C60y9fyu1mymma2ZO SQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 37mabqrsa5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 Mar 2021 03:42:05 +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 12V3fWvs086212; Wed, 31 Mar 2021 03:42:04 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2044.outbound.protection.outlook.com [104.47.66.44]) by userp3030.oracle.com with ESMTP id 37mabkmmfp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 Mar 2021 03:42:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AAAqAF86bFIiWSqUTYJII66pGMfTjeGjsNUYvo2zBJCHO1h7Qnzns8lnSVtAj3muBuEhgwQPQJ/yely0g9CVPBYIhupYFmYuScHyc2Y+IAL35+zdzw80EIHnB+71kFEaIfuxoPTItMPems0UtUBWDqXpdnzg65Xza/YqjOcF8MoMsr6+9TLVzDaoK7PRZLO2eqzgPzIRu/oh1XWf0LW/3EG+XjJ22H/Pz3U5qNWUXeqOr3klrDMd/D6JXduyXHMdEUseFTikImZf6zqC2kDlS88fXce59d5G//NV5sOuIKFeNwBm98dFNrFhBn3H07KS1+XTvEQazLNo5mEqiwti7A== 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=OKPBngNAFI9bp85dSsVhMD8GLSrYA03jpGeJ0VDnCJQ=; b=m0z+Wow87pfBZVtlF3mBwK0+RVsDhajJMgjNRl2g1mdDzkSeA8/TlpfCN0E6D7Q+pPyQjunZY4jIiBLmIpletZ/+Gy5T0dsi786nFtXaajhEK8m0aQyEcrG7Et3O7+QMUbzIlE8Zb1Vi3ifayRdcfMqvy3px8rNhzw0ZrvT5B1u2+3raOeVUWUOhpcah7cy+bvf8v1yXaXpUYIE6s74sceL5cGj/YpiFUubRj/grumb4f4Vq0NMtQJDXxq31wdcIgoSPade7NnaYPzYYLe3+13F2AG8dIfT+f9dRQ5ntFh6IyX4LXde1tTFqUil8NIFVqL8UEiy3TGEYtlREO/uwlA== 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=OKPBngNAFI9bp85dSsVhMD8GLSrYA03jpGeJ0VDnCJQ=; b=bdNR5hz9gIXebZj/Vi/MIqbhEEcc1xs5xRd/8GAoxOWLLQwDrxIUcI0VUBkY4jeMtH2flA2WRIOos62qT/UU/jVpvNuyFFePWoX5RmltmmmKZA+ViFvKvqbcVHsUzzS2IN4YTcxWSoQl5L1JsnMxZLPFksl90ndsTzVoMBxnhpU= 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 SJ0PR10MB4462.namprd10.prod.outlook.com (2603:10b6:a03:2d7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.26; Wed, 31 Mar 2021 03:42:02 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee%8]) with mapi id 15.20.3977.033; Wed, 31 Mar 2021 03:42:02 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org 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 , Andrew Morton , Mike Kravetz Subject: [PATCH v3 1/8] mm/cma: change cma mutex to irq safe spinlock Date: Tue, 30 Mar 2021 20:41:41 -0700 Message-Id: <20210331034148.112624-2-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210331034148.112624-1-mike.kravetz@oracle.com> References: <20210331034148.112624-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: CO2PR04CA0202.namprd04.prod.outlook.com (2603:10b6:104:5::32) 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 CO2PR04CA0202.namprd04.prod.outlook.com (2603:10b6:104:5::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.26 via Frontend Transport; Wed, 31 Mar 2021 03:42:01 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1246689c-768e-47d5-24fc-08d8f3f6f208 X-MS-TrafficTypeDiagnostic: SJ0PR10MB4462: 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: wjbPsn19X6Nk/ohvEiAoEPkuDrdjoXs/kXWH6yr4QHk7NgO50WMXYtoxxD0Vlzc/Y6lrNOzRtX5yqJhzAMj9h92nAtOf7nhg6YqpYBYzhez0VC7s8oDi80I15iw5zNITO9r51FIYcqEIBi44VIhcMkGHouJn8AHLryNwhKwcETu93YHBEkBMuIHNfQHpCVLMthnp5sj0iRe05KXcuyYEX+4WlaHXuxxaJ7AgXcf9K+MBiJV2TlYKpy7bbXTF907M3gjr8pzUoqCZj2pF0T6JOkZtIusFxU+KmJ9w8eZwqxL1tGi4NPbvXera/bwNZc1YNulO4WoxvTGFCE0luc31y5RA6wwoSofosX+5Veyix+kq1//C1nyh1jF/yEdXmrv/0CqejXJ7LqIByEA8GNW1Z8tgRj4pPAr/sp5gX0WLJBz9tqSkBbtP8hckiS3dovYfAK3okkaC/d7cNu6HdA2sbExd+lsDLEHaU34VimCJiP/Cao0InfGinPhhHBdyTNrEXMwAt44cjxeFbKrKiXbMZ8rQGRc5jTfr0xGSaafSEZa1x1v43E64IzLZjm1+8beBtISNw1CeIt9ED5xjISPYNv0AAKu1cdODPVwH4+SUGCkuSejtMvmhVREp02RQRjhAeEkdi/aGD9dsudyDdD1mmw== 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:(39860400002)(376002)(396003)(346002)(136003)(366004)(86362001)(36756003)(83380400001)(316002)(52116002)(7696005)(66946007)(54906003)(66476007)(66556008)(44832011)(7416002)(4326008)(8676002)(1076003)(8936002)(6666004)(956004)(2616005)(16526019)(6486002)(26005)(107886003)(2906002)(5660300002)(478600001)(38100700001)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: JQ66oRvArpKqmDc1YbRP8ckCKC2GAm8j58LSpaezTw+QriT9DDqApjMC3G3hunVifX8B/uoHjq8kHGhLuGWq3PYDKw5lwRE9XerTaO+7ZVumw6FLqD3ryputLYgNO/RVX94tC8sWRtxMZQjQ7FskDZ1p2ndvNoTkofTgxEMSwOdIQLXmRjrRVYXpFNhbQBoXO3244D8G8kLbr6DrzlB8NQNPm20mu03xy4uLDDlRCWqvA+2rFYq/aF2crTZPMQweL3b/5rnyP/9h3schLfLS34ZvgvWuJ7zsOdYitFBxssaWXE5LTJg110omy6OCIf4IkxsrUTAojZPzF4vR+nWRlCLpz9z0pQbx3h0thEonHt+aKszNFVQFmVNP1fdwtMs91hb8/bpaYYYSle4NQTqIOQHGYqr6Bj2yIhVyo8bQQDdw8HbiSmH6TX2uyzF0CJOkWzFWwF5qSAa/EBwSY6mx6B64bBoJZpV4agNie/Gd0yTTkMxE8uPYqqsLL1GBuY9DkgW6SQySarEUiajUOJK1B7SezzgWp27So/QK/oe4PgwZkBlEwSViW9MpmNVIHd746Na716hADkVJXvhzSiH7CD/IhhDbMup07CSYLLQgCIF+UjeEN9IhJGAtlxwg20Z3IQhm31kTZ1OzcMmMrAUlyU69qIbOWlF+5VLOritw4McuoH9Egl388wqiLcFGLIpzuXEY0wej83Tt1iIXU+hL4DTSAqd7trdfsYAbsm58Jmaq2dKSNvJY7BTGw1wTv3jY6JzsToIlosAEoeKqi17UNGwG7HLjv7X/Ljs889Et58GcZXLrVtNcYZE31XklC8AQOD9mLIRVwLJPEfJnx558cfo1a6VVewpn0SQrACZll5hGyUBR0IFPNKZ/+kJj+c5I/B0tbLBcwX6qEFoGpIlDUz6mh26bbg0FNXgAF6c1//XcioP1q5OjeRGQMPCt64GnyxglvVJOb6/fMvsAUJVpQva9J+wr7t4HTP/k2xCZMlMkdSyizYz3iO009UJ5kskXRMAfcsgT1ouXWhekitbttGLJ5LaLv+1ep94Bj8cNh+vcsj4ccOveV9CLvpiSL+Z6UKLTFITUARD+9ihOgdOPnzoTkEJXXVx0G9RPN12BUWrfKS7noW4T5CqOmYxbKvm+djrDzHGWnteXnWkcXsLl1iDEehx8J0ABBwrcbxorjGUcSNQw/8K3cxmPWEgItoZoznTeezJ3DA3qwYEhKsfqhMmjYrHJKGGgLzfVxwddqvA64eKqH4zSn0Tc0zC2Cw+gtpv3gUpo0aCVmW+BUQVhwwzbzpZZ7FWL8aPr+jXgoU/fq5fEBexjRL0BhUHKThYY X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1246689c-768e-47d5-24fc-08d8f3f6f208 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2021 03:42:02.3040 (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: yNfaJWZRwVGsw+mNTYtQ+Keg5C1Rhxunu0n4DEfJ3eVq3MsDm8/KnJ6/p32QqxTrsGRJG/VoGl0Wsqi2URXj9w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4462 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9939 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 suspectscore=0 spamscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103300000 definitions=main-2103310025 X-Proofpoint-ORIG-GUID: nJqyqWqNEzGgO6AEp289d01-BtCyqTdk X-Proofpoint-GUID: nJqyqWqNEzGgO6AEp289d01-BtCyqTdk X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9939 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 suspectscore=0 adultscore=0 mlxscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103300000 definitions=main-2103310025 X-Stat-Signature: pk6cbt5gun1q5g4emikkr4sfsk3qtg63 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 57D6490009EA Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf19; identity=mailfrom; envelope-from=""; helo=aserp2120.oracle.com; client-ip=141.146.126.78 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617162152-826900 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 --- 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 b2393b892d3b..2380f2571eb5 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 int 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, size_t count, unsigned int align, 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, size_t count, unsigned int align, * 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 Wed Mar 31 03:41:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12174295 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8175DC433DB for ; Wed, 31 Mar 2021 03:42:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1C45F61962 for ; Wed, 31 Mar 2021 03:42:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1C45F61962 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 981626B007E; Tue, 30 Mar 2021 23:42:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9588F6B0081; Tue, 30 Mar 2021 23:42:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 75E6E6B0083; Tue, 30 Mar 2021 23:42:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0170.hostedemail.com [216.40.44.170]) by kanga.kvack.org (Postfix) with ESMTP id 597726B007E for ; Tue, 30 Mar 2021 23:42:32 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 040C0181AEF3F for ; Wed, 31 Mar 2021 03:42:32 +0000 (UTC) X-FDA: 77978772144.28.731AE3D Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) by imf07.hostedemail.com (Postfix) with ESMTP id 11093A00038A for ; Wed, 31 Mar 2021 03:42:30 +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 12V3f8Q9038105; Wed, 31 Mar 2021 03:42:08 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=ztO9NuDcGbIfIeVAyvt8JiBahWGkgMKLgC08KIhDAXk=; b=GnOEHHEg2sXW/vYn+00d9w51axfBEdhNJXiEh7YjDaLHVOBHWDaWN7rnBjZjZ2LvUbjh nE96PB7zHrseVC9SG2TKRw+SkdlZwBfVwiQ3DnwL2D9BE0VZMbe6dURnl442xscqvlrb jr2oQtB9iUqRdUfUSbMJbNIyxur3f1yu7DANIq7OWdfwocvWLayXw4v5IwCdCHX9hydD K4EjuAkRtwuqg9z/MnOFWgm68Wqdm7G04LcTvU+OhwoNe5pvb6Tjon3Dwgs/8q6932Ie 5dKJ4VQPC+YAdY8qXyg4GRJcYB/BXcBbO4k2KTAZ5ULa3ANgcjye9PSGso6AooOtTFXk gA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 37mab3gsm3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 Mar 2021 03:42:07 +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 12V3eprx182355; Wed, 31 Mar 2021 03:42:07 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2044.outbound.protection.outlook.com [104.47.66.44]) by aserp3020.oracle.com with ESMTP id 37mac84eag-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 Mar 2021 03:42:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FbmcvzwEXZNZSgE1wifRCdc0d7IRxQ8hsL7knoTsHqOLJIjsXKNMSe5lWBb/9n8AkBXK6JOicwKM4u/VyKWkFnUmrEDaqMKoplLhSsdti0ciYz5RxGB1XakL91qS1fHIAhqrgEcYJOY8DvYN6EkTX00fT56wXJfG3/vHuhFUM2Y3BKyBbCE4HqP8YVUBqJUawpDe6WitdeeRO1k2NW26lZYv2uksGGRvCgDkq8phFJj2FBnZPEKda+l0lDrHKabNtPN5HwTlridgrejve0PZmsx/0vq5nQ5J6g5EyGGjYHPIbMFqTlsdSp7NCniFsMbW0f9Ivo/f631mN94WBTllsw== 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=ztO9NuDcGbIfIeVAyvt8JiBahWGkgMKLgC08KIhDAXk=; b=EU9musQ1mIR+G4kFt5vhE4shG65mi8XBP3cHJRwSI+KcBnw1AWTGttkZNPl9p5w80NFTWVC+WSbpUbtkCgCOn8wBzTDei1KPlx4zHhLARcusuNpAVV+06EjBJtS9JDS8nf/3lMeWcIMOGuRTQ8xTxVvnz7h2IMklF7ALCndhw+AIRH0H0O9aDP+Lo6hqFNYo4MVxbpa+EnnVImRQ61n49KcorAK7KJ+yRFJ6CdkgwlRPdi4gEHn3O1zP3tkMZ3T/F5GW2b+g2jLIEXQ0tWoCSAapspdK/td1MpqRnE6eslHqYj9Apy6ASGjCeiyU5uHKxnVlmjBUqNSs7l66SxyZRQ== 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=ztO9NuDcGbIfIeVAyvt8JiBahWGkgMKLgC08KIhDAXk=; b=Q3Fk0aKnhgM8uevwT/UoD9TROiJcPdDxPbteCj7+YN+zVt2SjuDGcLNXx7zSKWqVRIz3CDGCdideRt1xRrIgmforONu/mnMrU21xijs3Wra/OngfdJSU7/B4D9MM8/yk9uCAcmnwZaOPelir0wbunmu8zNZpir1TOvAQm9ofdF8= 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 SJ0PR10MB4462.namprd10.prod.outlook.com (2603:10b6:a03:2d7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.26; Wed, 31 Mar 2021 03:42:04 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee%8]) with mapi id 15.20.3977.033; Wed, 31 Mar 2021 03:42:04 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org 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 , Andrew Morton , Mike Kravetz Subject: [PATCH v3 2/8] hugetlb: no need to drop hugetlb_lock to call cma_release Date: Tue, 30 Mar 2021 20:41:42 -0700 Message-Id: <20210331034148.112624-3-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210331034148.112624-1-mike.kravetz@oracle.com> References: <20210331034148.112624-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: CO2PR04CA0202.namprd04.prod.outlook.com (2603:10b6:104:5::32) 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 CO2PR04CA0202.namprd04.prod.outlook.com (2603:10b6:104:5::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.26 via Frontend Transport; Wed, 31 Mar 2021 03:42:03 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4180fee8-e192-4fc2-7967-08d8f3f6f366 X-MS-TrafficTypeDiagnostic: SJ0PR10MB4462: 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: D8pSo8W4M376yGgAI5oETEcCDYTZGPcTvZ3J82gA2HAeHyPdGe58KFUEEqa/RroKDrVkv0lXaToVPB7MFEZ3417toyLZXDpVIaCYDuwx+EhMj5g9r7nlbObfNezFlquKJOiiN8+9RoBDvZTlRmKw/XOzToMT23Wv8GqinChlnaFxIVq560AhnMHsIgNhhDbi1GZXTqWvN8IH/ptfcvJ3Wp1TCGk4CclHo358gK/yPyD/wKdIUEwRA08LBodQCxBhfLsDPBZRO0K9FGJQG6dg5xA0eBY09lZreDcU5piicbM3JAjRHVNK8C6VT2meb9hMRJpqxAlc1+zpGdFY+ZArPRLljfnTU2nHsDPZY81nZCwu+WT1XxQ0Z32hivx/6Fic+aK6lmOHuGXA2heSF/7q46BxNqDZwd9IaDvq4/VJLRCt0n0oZ4X2cDT7YmxhnaJ2lL78G7aSLy7gau0LYBPsqP47IyUTUAfScfOBf6oisiqeeja6c0yoVShgVNNWW0aZIObLiNs4XGJ76aPtbP/h4p3Z8Gtrpc/YPTvosj+AEyCqubzt3IbeakZDgrf2RNSQ0YaHEqtmzAev0R3OU2oJNgGPRCvFuGIoi+uztQFiG10i8vK7KY0rYwKOkDERYQHRChz4DF1+TlhRyzkMPpzY1g== 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:(39860400002)(376002)(396003)(346002)(136003)(366004)(86362001)(36756003)(83380400001)(316002)(52116002)(7696005)(66946007)(54906003)(66476007)(66556008)(44832011)(7416002)(4326008)(8676002)(1076003)(8936002)(4744005)(6666004)(956004)(2616005)(16526019)(6486002)(26005)(107886003)(2906002)(5660300002)(478600001)(38100700001)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: uUxfLbKlJjRl4YCsLFvDP5ZG/0PkeYARZ2gLMxORXUTb+YwxBW6SnGeQ5kxX1Sjdzv/q6Ahp18SB5sUwk6C5jFuf93IZG2RsrUIkbRPQv/MQ9Qcepb9fTK39U2uhHHxCe/cYN1bg9jAZibNTA/dhDXn9m+UFNwzj2wUJNG+TC47PwxrE19lwGolD8Gr0EO++YlbOQO9DoY3vqvzWxENuoxH5/kCQz7OUvFRGKxT+8OHZf4Lqzc6Ntv2PXO2hsNW+XzM+Pn5nSd/MDMh1X4/L2qySQb5k7U+EEt0giJeuxDReIUoxNJ8kij81pqFXdHZKq75deNt9XvmcDiKOGY+BkyGRo6i7oeX7qCDlVbz4Nai6KBUsEkZjavEio88pn0qSrua7FDIfrx1RsXPkflJxdUGm5xqpa34tB9ORTXsBrvNOHFN2thtpCiRSyWrEZnOyGYe3fwqZMJIgxhvOJ1UGE8i5V30/LWGMerF49go07NFRPxOwauYn6VMlRcZ/otwrGsjNETS8853+a/mYp35wAJ/6J6nqnnmcddsCRnrH4zqum7C2puxM9xk60dI/rDfcwZnx4sIOKfiMbgyiD0Qhu/ABArsi3w3kd8DuqO05LVvEEM116yLxVqTMgMx4G96WSsDeWwM/oDgVRCfX+sEu2PnilC93qHCMDGAHKSENX7iEyucxSmlge8vkLVEzC+wnqbEOzwwSWw9GOuI9NZQrGpiCyIcg5KngkVeEvqwHfjPjfDxILo2fJufvUaKwqaAo9H9zVre4hVBr4VfWoGQota+r9dfyOwrh/gSe5Iz+xQn6JzZ5NqGR4LN0bL6vhsBRaGYXNua+ny1frbYrZoYRJlaLBBrPxpFm2pg8WiYOkMG3RiGBVIvvg8KZm9sUraZHSjllGlNGMMmg3122vq94ELZ+NXmnufKWiSL8QQCSzqdOUXTa6zG01eFvNr2TOluUZkmYXGfzUteYl5ulF5DZdpYyJVHQfZ7TIg6J1nI2l9CzwD1/Muo7IdsioLO5KPkpSet/AY25LIcKmNZ063HohKDBQ059qJIP2B5oJyPrpd2H+efhyVUDNtimUKBpTogLY6kaH42nMFgaqVTaWXBKUvthEIn7I8+8GW/Yc07Kg6HOZXCr9EKuLurGZRkyJLrnNGPxj5buGBW4sjNOXFZB1A9LnlIfwFoPASEdjX6CpczLGs1WaoMAI+0UaLiQWwdcbZNgLu94rnsTOTPiOhumzLyZ3CQZRGQVqwK7qqt+RNs+91Wsro2S3hDxT+JSr2jI7zTA8MGYuEu7M/emij3cRzwSTAKs+nWsNEfuRvJRgwiM+nShDnGlh3HMgJv3qO+C X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4180fee8-e192-4fc2-7967-08d8f3f6f366 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2021 03:42:04.6348 (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: pnj9NA6YUqNCIFlOzpPpn6r5UWt9mQbovdquy3Mgl0r4/0S90ft0uFP5Mb1WGep/blnWym05gYT2YTjH9wI5RA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4462 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9939 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 mlxscore=0 adultscore=0 spamscore=0 malwarescore=0 phishscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103300000 definitions=main-2103310025 X-Proofpoint-ORIG-GUID: n4CrRllyLjYg16eA8R0Ep51D5dLrEg8J X-Proofpoint-GUID: n4CrRllyLjYg16eA8R0Ep51D5dLrEg8J X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9939 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 lowpriorityscore=0 spamscore=0 priorityscore=1501 phishscore=0 malwarescore=0 suspectscore=0 clxscore=1015 impostorscore=0 adultscore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103300000 definitions=main-2103310025 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 11093A00038A X-Stat-Signature: tdcimo4of35w6x9gzxx48fx1i4fxoa8d Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf07; identity=mailfrom; envelope-from=""; helo=userp2120.oracle.com; client-ip=156.151.31.85 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617162150-487651 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 --- mm/hugetlb.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 3c3e4baa4156..1d62f0492e7b 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1353,14 +1353,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 Wed Mar 31 03:41:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12174297 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B2B2C433C1 for ; Wed, 31 Mar 2021 03:42:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3A0EC619BD for ; Wed, 31 Mar 2021 03:42:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3A0EC619BD 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 C24C26B0081; Tue, 30 Mar 2021 23:42:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BA1106B0085; Tue, 30 Mar 2021 23:42:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8BC0C6B0082; Tue, 30 Mar 2021 23:42:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0121.hostedemail.com [216.40.44.121]) by kanga.kvack.org (Postfix) with ESMTP id 65E8F6B0081 for ; Tue, 30 Mar 2021 23:42:32 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 0B384181AF5C1 for ; Wed, 31 Mar 2021 03:42:32 +0000 (UTC) X-FDA: 77978772144.23.14B9631 Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) by imf14.hostedemail.com (Postfix) with ESMTP id 2A927C0001EE for ; Wed, 31 Mar 2021 03:42:29 +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 12V3erQW038054; Wed, 31 Mar 2021 03:42:10 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=M3ZNCNlNGxs+XGnmLc2aGc0QhYl50TNtgEytgMXfYic=; b=EzCabx51gdd9v+ZAgv4BKOG1G32MxCI6fIgS3M9OdsqMoIH+vAd+Ra6cy9puTVE6KHP4 y7O1v2Lt/iaPrQTJoYXE96ojdM7bp9AYVxz255zej4qDuJuNMIiymVeeec0nF4maASKf NghsGUcCGFOa7F7LwQYM3NSMtV8N7X3DiPSkS5Q7OMZg6tuP/OPM4ijvAL4MvpzAtDlU uArzytbvoitkc7YAyt00pXoTg/Tx0QBLnOt0OoaxpXO9jqBeXSaUlaXQWkRMKLLc6b4C o5ycEz9iy6FzRzN/xByK6bH4YXq4n+e+gSejEWBPHiwpONUghC0mPP9/okIwxKTVF947 NA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 37mab3gsm5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 Mar 2021 03:42:09 +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 12V3epQs182432; Wed, 31 Mar 2021 03:42:09 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by aserp3020.oracle.com with ESMTP id 37mac84ebd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 Mar 2021 03:42:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OxaUfLjR1brT2UL28Ymg2GcE9AsqNZLEuR2YRV+nDs0A7oxU1Jg2aLKZ76DZ3YGUewmW6NfRG9b2SWVi1llPKHXBXyXoI1zYWjacNNDSID/ixBvorRA7GeyOjnJuFuTliLj9TTLLpLlx7e3B4l6NffiO7I8PTdjN4cOHTGUo2EebZiXSHatPOlvLFptV+rqiB/83Z1D43JbnHaNR/2wFwRxlNIG0++flhFXohMxaNNXw8nKS9X3zjtE/HA2gOavUvfYOzTCEcvsyKFThvm7lVtEBsCetA7h4O5VK1mnHi5c6vXLzdco4W8HeK9eRA6z9PN2P9nyurXzJ+DR/wC58kw== 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=M3ZNCNlNGxs+XGnmLc2aGc0QhYl50TNtgEytgMXfYic=; b=cQFKVN5u1zUgtrrguN7vGQMY8TrT8inltJjaKECF4PgwjPLGRDuuUrFZgpkAa1Ol5Cu8F8eD318CLIcZccP6oT9njAgYTN46Ai2tIJfbuKAsDdcYAmdr+nNRYJTPv+03z1NBMlPSJDzTr7m35p6HyP6tYqFUYXoc+daLVO8OadS18sgTNTuEBnxDXfg0/hwJMQG7eVDDAeCgMa7WUNCJgnE7Y43twbgMhcRLBAYmknJwIKD0rVIGGxVMCT8trVLaw7g990RLeK3pN/ECc/mbUXCWCErvEJieIN2Fz4ykFZDYgVVloSyTsaEOzJHwxJ2PrkbPAlEH9hM/d1KtRnMeTw== 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=M3ZNCNlNGxs+XGnmLc2aGc0QhYl50TNtgEytgMXfYic=; b=sX/d4hqmJsyk3VOE8n5YkLAi/ckRSqgPJr880ulBEklj9n+kLc7hpggzwfPxnm+s85EmFLESFoYDHxA7hQsLwN45uOMVloa6vwXH32Q7QshylRYaAMBE0A4+DnuQpHNlxMkyIlfrcHwyDl2bFsAr75TrRowfIXXefNlHGe3c9bU= 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 SJ0PR10MB4462.namprd10.prod.outlook.com (2603:10b6:a03:2d7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.26; Wed, 31 Mar 2021 03:42:06 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee%8]) with mapi id 15.20.3977.033; Wed, 31 Mar 2021 03:42:06 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org 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 , Andrew Morton , Mike Kravetz Subject: [PATCH v3 3/8] hugetlb: add per-hstate mutex to synchronize user adjustments Date: Tue, 30 Mar 2021 20:41:43 -0700 Message-Id: <20210331034148.112624-4-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210331034148.112624-1-mike.kravetz@oracle.com> References: <20210331034148.112624-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: CO2PR04CA0202.namprd04.prod.outlook.com (2603:10b6:104:5::32) 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 CO2PR04CA0202.namprd04.prod.outlook.com (2603:10b6:104:5::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.26 via Frontend Transport; Wed, 31 Mar 2021 03:42:05 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1c77e76e-5d06-477d-4196-08d8f3f6f4ad X-MS-TrafficTypeDiagnostic: SJ0PR10MB4462: 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: ItV6EKuNXxkig8sRY0h2nPrmkeDz6Hy1tSVCBW7MvCkh3sov8Be2oEW+zmOs7gWFSrfDGfUdkC8YvVct+4k0h2yxF5TQH25iTNR00ARvhNukmQnG7klHk44G/jOjUSiqdztlBdq8ohIbNrxl3ratMw1S+ZITu+zq1ULrbvsD23mZuRFgdNQy01AR6dMuUokaTI6AQ50Jc8wlHcIS3FpCF8QA3Z39ZabpWgdP8BGDACDibL075k34Td+Cv+Pzd5G33xjiVc/4kLbTECVKEUHAd+UEQxWNZBjidaRiYbBwokHqMPSBS2DmQEIQIAKfwfm/E3LV72JxmFLwJU0jzq9LlwayEPFLtyAW5BsAVJEeOWdS9NwrDHYjlX11jacpytQN56HfyRtqQdmQnvhKea1stLX/hIaIlC1FHwgPzaIjzloYZNE29tDGtk1OXoC6eit/6HieB4fZEWYOpa83HGU/E1iaOyj55cwoZAdqnzsLa6FgbwFg8ZlEtN1IpOQJYPItMxBCDDbCx2lhR3H7AUPY634XSjxIiILIZYfKUzS4fUcVd9/7YDfp2bIQemTBxq6SO4HOXZBqOmg9gWz5r7CSjson/ypwMX4eH2lHTvPDOsIeuyA4mBK7Mmx1lkwkNqJA//FSW4Yqyvlb/X8h1tStQA== 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:(39860400002)(376002)(396003)(346002)(136003)(366004)(86362001)(36756003)(83380400001)(316002)(52116002)(7696005)(66946007)(54906003)(66476007)(66556008)(44832011)(7416002)(4326008)(8676002)(1076003)(8936002)(6666004)(956004)(2616005)(16526019)(6486002)(26005)(107886003)(2906002)(5660300002)(478600001)(38100700001)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: imOB6C6oqxTzNjm5K7IFpoZPOlW+0dhbcS/r8/2g/fqXmhawVbJ/N2MJUPAKygBulUSO8ojJToI130HPEdRQ/hgWJJcLAWXsQawwhcO04X4YvpAuiY2lsPLnh94DWVHZNbfkNOCluFwmAFab0qz3gNxZskzGhvwPSt7nOu4kdy5nf9A/zATcnromc5vO0scT/sOlT8wBNO3BLhkdBPtTtlXQP8EmLi081PzCGfilzV1ZtRldin79tTujS5U6aEG7VhUcxSj4ceqFNVJgRrGXhgAr9FokT+B4e8zzm0TmQ16jEc4+3I/i4U12W0RLL1Rsjll+CCdE9loqzGE+ajq7FgjMIMEOIzH8LPZJjmfW7hUDEBdL/owvDehKw5bmU6bdz8GjXridSuXgzv5D4rxaff04Oi3trPoSYA1p0OoF2SBfxMuFbwCtTnMyxvSLe3Wr9nWXzucxgFnmvamyUz3CcK3RJNCDAQ9+FDJvoWW/FHTlG2diITgXHLBoDZRt6sSaT065wRoQPO5HwuwGiS/ximWvIWUgviStStkMY9g6zAT7+RFz9/iEHfcXbhhzSn3MxyYJJDUQoB0N4S3Ug0S3QZ88szvFeW/aT2EF2eyBZEcvyJVgjwHYWU6F8C4Ux4zlT2lRQjIgnd7PyvgC2MwlHLwvNGmrpa5b9jocua0dShcweeQV+k3q3aDj+eP5Bly6Uamf8t+Dd9DQhUwbeCa/u7OmYcLAhXcUyz/OOsc9nnR4AcED4IhGKdxyN9mO66DsZciVA3IssLd/qc8fAbYUsfbwacD1TshNHabnquXdgGErEcGM9nm3vQUZQb98nvq/ARk+zuNtQeI9gymwJHMc1yGqGPh5TdVziGNA4CcfH2sgijiuL4tyTFHQIfDNs1BvzRJWgxZkUJGSl+1FugICRHdXneb56qc++kuMrqCMuaEbiAAxQl3bWSYpSjyNQcGZHxeFBQ2iWAg4HFbbTQDvaYy5+2YKnIjWP1Gr4v82n+oF2mZLqz21rFDN1THxV8aC3J1IJMJbcVQDVlx1jKdTEH+6vXqvlk70M1uoOTMIhdLOsUWSRIm0e2fm2v4lFvke/FQKMFAVhFgb2kOjIVSep9UR5CIsX8oqgT0sfr86G9xmw6MDh6z7/aQ8h761489R9NZ9l/JL0JOrAK74nx+oFW1o6vZLhK4ldPWbY6tkPei6fzzbqUgw0LWmuMLjarEjs7VOUuYd7MpqR3D9RJIRuxCWvLos6hooQqnZwTZpuCK0AMG7oZJj9Zlin8vpKpnBVQQObOSSc0RYLsgyLQ/7+PxlW2MNJ2DroFYySmNJU9+uPzLnWKFCGjdUpXj5/J+v X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1c77e76e-5d06-477d-4196-08d8f3f6f4ad X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2021 03:42:06.7216 (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: vx3a/45tvBLh9eU4lm6O9Y2OwGfPUCYAmHyXVO9RBTVsIC1hwCz4tDnHR0piXD/yAHc5I3N2DLe4vNOQC5xo1w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4462 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9939 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 mlxscore=0 adultscore=0 spamscore=0 malwarescore=0 phishscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103300000 definitions=main-2103310025 X-Proofpoint-ORIG-GUID: ZXZ5AQtMyxMn5w28XE_xWA-JDrYb745n X-Proofpoint-GUID: ZXZ5AQtMyxMn5w28XE_xWA-JDrYb745n X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9939 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 lowpriorityscore=0 spamscore=0 priorityscore=1501 phishscore=0 malwarescore=0 suspectscore=0 clxscore=1015 impostorscore=0 adultscore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103300000 definitions=main-2103310025 X-Stat-Signature: 7z7ozdbyemr6q9hfxqfnceznc1bt99c1 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 2A927C0001EE Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf14; identity=mailfrom; envelope-from=""; helo=userp2120.oracle.com; client-ip=156.151.31.85 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617162149-687028 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 --- 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 d9b78e82652f..b92f25ccef58 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 1d62f0492e7b..8497a3598c86 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2730,6 +2730,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); /* @@ -2762,6 +2767,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; } @@ -2836,6 +2842,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); @@ -3323,6 +3330,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 Wed Mar 31 03:41:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12174305 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5750DC433DB for ; Wed, 31 Mar 2021 03:42:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C8F4A61954 for ; Wed, 31 Mar 2021 03:42:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C8F4A61954 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 714886B0087; Tue, 30 Mar 2021 23:42:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 676FF6B008A; Tue, 30 Mar 2021 23:42:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B5086B0089; Tue, 30 Mar 2021 23:42:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0226.hostedemail.com [216.40.44.226]) by kanga.kvack.org (Postfix) with ESMTP id 1C6AC6B0087 for ; Tue, 30 Mar 2021 23:42:35 -0400 (EDT) Received: from smtpin39.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id CB832181AEF3F for ; Wed, 31 Mar 2021 03:42:34 +0000 (UTC) X-FDA: 77978772228.39.59C54C4 Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by imf19.hostedemail.com (Postfix) with ESMTP id E192E90009DE for ; Wed, 31 Mar 2021 03:42:33 +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 12V3fdSQ001603; Wed, 31 Mar 2021 03:42:12 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=7XROPzrFGkucbYlToRA9exFdiYfTr5yDZyzXfAg591c=; b=XO91rhECBlZ4sJE9BGLwXKbATaM3qjN9AXdXXJyLG3TvPeA0EK21Z5gcDvwAzN6PheRH YMC1VoSt91lyanZCVVXSm2TTOPexngUvZALYYAeil9rrIsB0LrKj5mXM03koNt5CrC4c kNkYDTLuHtiOelEqwFufNdO7A7cagrzqyueQMRU9zd/7OD/7gm9JePp4Xhuzc5VwZbnK knIv2eMUtbevH866Q8+je2loD3f5+j2at1IAqwIuKBkcmYlVALo2BHW0dAE6EGp04E+x pqO9xelIfJ35OmaGhvRND3LagEAh58nisqM0833/eRotSgMVYfPeSi+mFDBNXFEcZaB0 lQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 37mad9rs08-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 Mar 2021 03:42:12 +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 12V3ddFp121881; Wed, 31 Mar 2021 03:42:11 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2047.outbound.protection.outlook.com [104.47.66.47]) by aserp3030.oracle.com with ESMTP id 37mabnuyq7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 Mar 2021 03:42:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T32bgmlwne/LksMAzagLed48daz4fWxc9oOt8troCtJUUlFe45mySONtwDYfpta/GvuSSbK2y43WTq3npHDLpy1NDtU98Naz+OHPLUfYKZO5ha8GQLvC73WG6bKGvIeBOTjA+O6+C8bG9xYvEb+23GD94cb52WrQt1VKS1ayXD1vf0AF2N2EzAlmGay4MmPG9QvSPReBOQSDU4UAKssIITpTaKUVQhzxdqzVUPpB5wTcfdredwdNN5zKEoWZS7X1l+fyWIpJVkauTchBDu0hD4J15O08yd+pxaeVJ4fRVxCyCNAitUlSrUfyJiEVc0QxASftpa6Jzm+5FJS4ewrqtQ== 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=7XROPzrFGkucbYlToRA9exFdiYfTr5yDZyzXfAg591c=; b=TWqEGhN+bbwBM0CgcfYwYk1IgNPi4OcdqVV5QqTy936UxaPNT5gyauBJQnkPXGwZ5a20kdW8nwV8fbIu8zU4zxcNtxvUVMn2rcKXE1jzWD+4rf25TqzpFaOCwuN2f/xtqNNuyySYZmdu5vD3S6qWhJUGlS+URqi7WhSExPVBTLe+BDEY97GV8SC/NsJtOFOcONcvP0Z3zAVHL2JBCQ+toMVvQjNhqgjs5OPaj1hkJ8t2yWcOInvdjf6pc0hVUnY1gCbDZeoBzzB2H/sQWsSp09b680eJ9i4k4Vq++EI+/50bWyEx0uaWmyfgBydf6q3yKOqei4r4muPBs2D1k6fzaw== 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=7XROPzrFGkucbYlToRA9exFdiYfTr5yDZyzXfAg591c=; b=cnGPmrNP6QqvwzcFsENKgF+n5j7JNdbNRfanW7oHrpm4G92t41WqsOEJqTMcHi5cLHA558sK/pJ45ZNgu9RTOlG8gelPlMtr1idRTMOS+zpY8y2R/UrJtwdS0/p2LZaje7/jCjKjXczvKW62Q3S2b7/YWtjUuW8IuWd3iWlZp2E= 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 SJ0PR10MB4462.namprd10.prod.outlook.com (2603:10b6:a03:2d7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.26; Wed, 31 Mar 2021 03:42:08 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee%8]) with mapi id 15.20.3977.033; Wed, 31 Mar 2021 03:42:08 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org 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 , Andrew Morton , Mike Kravetz Subject: [PATCH v3 4/8] hugetlb: create remove_hugetlb_page() to separate functionality Date: Tue, 30 Mar 2021 20:41:44 -0700 Message-Id: <20210331034148.112624-5-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210331034148.112624-1-mike.kravetz@oracle.com> References: <20210331034148.112624-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: CO2PR04CA0202.namprd04.prod.outlook.com (2603:10b6:104:5::32) 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 CO2PR04CA0202.namprd04.prod.outlook.com (2603:10b6:104:5::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.26 via Frontend Transport; Wed, 31 Mar 2021 03:42:07 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b1def4b4-22d3-4ce1-36a7-08d8f3f6f5e6 X-MS-TrafficTypeDiagnostic: SJ0PR10MB4462: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:590; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HPfoz1lGF7zdaFGTFDAuK6Xs++n7Hexyzz78iDNxs30r/0si//z4wiAIlsJRPoP9oY4Uhd00veWQHmQws7TkTeHpaNfr2xeo+NMG4kcI7IK1s/2tY3pgqdVO7M5TyR7kcQew8RUlo6oySOgQj9Q6dKU7SmVybm8vzzxtJco431hyqLVCeS5SFpyh84c3Ihpu2CG7zXlrD68DbhgT7ydjuo7P7SgMQH9KX46138405EMfbxsmwnDTVr75RzkAuOS64xAUc+cdoDMOiPxUVrNY10t5aTNI3TV1Dzg2CMfkfhguTrS5nMP/T5ap8iQhw5YuLvqJACrLm2tDRNmocp4BrEEyL/0RDXbS7ZTQzg5mKkcPu9jeJfYbkGAv8yTIgKz8UkryiroSBDmhqj6ViMHsalCEfAXcAvWMGhHXUYOhDdIe8Xx2x1d6Kh/xee0+Zsri85Wp1WcOiNz1UXkBvEWSLmqw0LoSJdMnPUTwx2U/Lq8f2RngGoAzVoSQY+tRZQEYmzXy9MiRREYBZid9gWrkCr3ZSSrkq2jkEa9ceD/XwabA//tlZXBFLOxJf57rl72t9UPMK8Wen6ww/pE9yh/XoCmUnw0xWhsZvLPyZc/2qZOHy04o5tKFTwB4RkhSKfdT6QSEpMWDNWdwUnhQGzfhqA== 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:(39860400002)(376002)(396003)(346002)(136003)(366004)(86362001)(36756003)(83380400001)(316002)(52116002)(7696005)(66946007)(54906003)(66476007)(66556008)(44832011)(7416002)(4326008)(8676002)(1076003)(8936002)(6666004)(956004)(2616005)(16526019)(6486002)(26005)(107886003)(2906002)(5660300002)(478600001)(38100700001)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 3kQdEYni9QMlmfcHGlTZJRngvdHC6ye1JjElEQYjwtdNdAEJDUkZpCS5E118a56J7TgUNjtSDwPYp+CLw+8jr1pE5lXQ9P7y5fUqmXZR/anNHoYG1tuhAY4jVn3gzdXWBwNDQ960gsgxZHWjYkvqDoAxB+SjzcA1uFQ3Cj/dwfThP/NFN6hCo7pxC247iH3PXUyolZSw6UO+UUvlDRKwZDTvvdngLOAKbCB8kESkSlBZ1j+lLQN+Y0vhvwY5g3qv8uDFjH5TQYPuoVi2d/ARJmVPyQE4DxW6ypccLZHvLwbVQCbJ/h8FIMXX0UodFFMCljY1BoDXA+hmz/QEm98a3JwVdSaX2AGzwf4ze7OuiSGnVrDM3nFuA3gvp4KSyOCTRaKmVFhvNdvKi54QtK0SdgpOCgh0P56Md90k8cpcf8v3kcVrOop4haYx2L26BWkCieEvHNNTxTc/XBMvnwEyG5xENanPSF+ckTAZM+s5cAMJemJy8JSGpvxfXmb/vDAGDK8EF0r2Ef0kxtn3uK6RS+skerqEQIIjohBLqjeDHI6Tsdql8cuZwtRH9wjSBHN35Uc8fuyrIaZ1gPlHc/dFy9hRM18FHSDOSlSz9q4XMTcrtDAqwhFdyuDx/YcMlHwsXGjEGDJFEOQ8FnnIW8XGrYAMgPaS04lc4cWlV7y7K82ckaqsRaluQ8QDYocTwd+rrRASsyRxHT/URsqdylrbIZ5TGeggE8CLMikyfUGtt4pkCLlSgiVxd4g/2vOooiB7gggLw0F/80umec1bYe36O9Gylv+7VWML2Wb2CrZGckv3UJXckopqq4k0qtUjQwYPa5aWFJ46T9HEkeRvBpVdL+YuR0zriwBC+fVO0C69EH/nC0tiQxbgUCkGUHFHgOj4r7JgDC4oSh8s5Nvv0uP+t7M0k7fMG2aXN0k9LDTd4LDQaEYFSm8x0c/zlo4cWltH4mz8SieoY4Y+3sKSJXaKnwSPtRIZvq3R18s8sozJFHKY1adeRQmYu9kJkBRfKKoIQDyD8FB42x1pYKhFd0RwZpiNWEbFl3kCRuMm1dLLwWz+192CvscahKsu20gtJ3B3THczUGaSMp3h2osxdLR3UhHkjEd3p6ZHhKL2HX8KqNUtXLHMsNtfFkbE6cyITR8vD7KBMZDDlApbVr8jRcntKB6Z8HTtodWoU6uh+HNkuqMEXMRWMq98ZzTlZdz+lN5WRbJNwVghDra6IeYcl3HswXeDaWSWjFF9dnSPo8MqOVqi8hlSQes5txGTlAhorngRkbxKoBzU5F+OrDHOU4byuxGnCb9ongFMNF7gAXERAQE//ncncmsGohBt5s0jAOqE X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b1def4b4-22d3-4ce1-36a7-08d8f3f6f5e6 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2021 03:42:08.8384 (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: ZD+Ha63kEv610w3WB6Ak6Z6LSQ8R+m17ogLaaRdBQsyrT+qX7FWo3qyFBr8/uNzKn9tJ1KkDn9j6kXC1yHlAxQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4462 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9939 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 spamscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103300000 definitions=main-2103310025 X-Proofpoint-ORIG-GUID: 58DRCebx8beg15Fc9awEMrewBao-OJTS X-Proofpoint-GUID: 58DRCebx8beg15Fc9awEMrewBao-OJTS X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9939 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 suspectscore=0 adultscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103300000 definitions=main-2103310025 X-Stat-Signature: c1hx4rq9dc84by9w65wrtk7ncy34cau4 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E192E90009DE Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf19; identity=mailfrom; envelope-from=""; helo=userp2130.oracle.com; client-ip=156.151.31.86 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617162153-460749 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. 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 --- mm/hugetlb.c | 67 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 8497a3598c86..16beabbbbe49 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1331,6 +1331,43 @@ 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); + + 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]--; + ClearHPageFreed(page); + } + if (adjust_surplus) { + h->surplus_huge_pages--; + h->surplus_huge_pages_node[nid]--; + } + + VM_BUG_ON_PAGE(hugetlb_cgroup_from_page(page), page); + VM_BUG_ON_PAGE(hugetlb_cgroup_from_page_rsvd(page), page); + + ClearHPageTemporary(page); + 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; @@ -1339,8 +1376,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 | @@ -1348,10 +1383,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)); @@ -1419,15 +1450,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); @@ -1712,13 +1740,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; @@ -1756,7 +1778,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; @@ -1787,9 +1808,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; @@ -2667,10 +2686,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 Wed Mar 31 03:41:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12174307 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71163C433E0 for ; Wed, 31 Mar 2021 03:42:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1CEC261954 for ; Wed, 31 Mar 2021 03:42:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1CEC261954 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 BA62B6B0088; Tue, 30 Mar 2021 23:42:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B7BF76B0089; Tue, 30 Mar 2021 23:42:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7FF736B008C; Tue, 30 Mar 2021 23:42:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0187.hostedemail.com [216.40.44.187]) by kanga.kvack.org (Postfix) with ESMTP id 5E0EF6B0088 for ; Tue, 30 Mar 2021 23:42:35 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 1B9408249980 for ; Wed, 31 Mar 2021 03:42:35 +0000 (UTC) X-FDA: 77978772270.02.67E4B3F Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by imf06.hostedemail.com (Postfix) with ESMTP id 8DCA1C0007C5 for ; Wed, 31 Mar 2021 03:42:34 +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 12V3dx2k196241; Wed, 31 Mar 2021 03:42: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=kT4yumVSTTqahsAGndQv5xgVPOigCYOjMZ8SzrU+Ips=; b=bd+/X7WDTzvcYi4Ja48u3kO45sFmYMv3SC83Qz0DIU3OaeBz487Cjq75/vAf7HB/dnp2 oxFyVpU8R6Sp8ky80UtKoym0zj4P1z5AoN4yiX6ns2zLeiQ8FbZCBQnvRwavGcQY3j9i 9a3qlL2Xc95s1XRPx1cE/VHtnyLZgK1r/wfPKLcqEyAEqKx9lBaVihXhC/owzh5zUxYh wklaYgxeJU9eftUx6foSoY64gwSy+9jH3T0RU5mc7DVATgDChxwCACq+lrh9PWL9uTIK 07hgpWLIQuAMd1572G06qMPOd/+S+4an3/TPW5W5CbCXf7Ov53mwE4/NBrSbPsnCKcSy DQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 37mad9rs09-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 Mar 2021 03:42:13 +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 12V3ddFr121881; Wed, 31 Mar 2021 03:42:12 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2047.outbound.protection.outlook.com [104.47.66.47]) by aserp3030.oracle.com with ESMTP id 37mabnuyq7-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 Mar 2021 03:42:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cCBmW9XpQo2fcOAFFLknzQGabNURIyANSM0K3FeNraoawYoBNeskqm8ATZUblknd95J0EEvSyhHYCJwRxHdelL/zj6YELSg9xb5n1LKoB4DIyllgTBIC/BWIP9p7adAnVRxcmGmCE4R9Jo19Bw2NA25EIwUX0scZVBz6RMjDPnR+324RYMh/l/20B4sirTGh104hIo1dgC1+htlWhIj6IrB426iIOnQAFuv0kCVR2bREkIoYJT43wd05xp27aFDUaxFbttdH/F8aD/VbLfAbgVTIhhwpqvkro+6HoX741Xj2bb9SA+C7W8QfLhZlRdE2tf2E5yRUUL1oH+UtnicgIA== 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=kT4yumVSTTqahsAGndQv5xgVPOigCYOjMZ8SzrU+Ips=; b=h5v4iND4N52yehR6adE+fF3ELx4wv8A2Q65E80ZAW0u7TsNmhVfX7BhB3XcvRWO4SFAFBreHg+bbkNKvxzvishk43GFwzO6xcq0dEC5F/b+0BzbrXQhS5AdbN19u8eoKtgUwC5b1PfQpvSnvquVOMQ6U/gELh0ze9DHFv2284T3KkyNVM+MozdD+5K6WdesFLD2yDCoPNSRDoZd+Nbfvyg2mwzjU7dYTDlH9lZ6tA0y3aPy/gmhZ3Hc/mH8Wji3wV6ZYr81fHPEHz6m0oTz+v3Mn7b9GqOi0RSpCQ1KXozsi7CZ6DZCaMsfS0pKqSAbPAZE86f8RPS8CRBRIsZ9fLQ== 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=kT4yumVSTTqahsAGndQv5xgVPOigCYOjMZ8SzrU+Ips=; b=luQrMZ9PTk3i0kJUzlUP2FHjXZFYQduQ9iKU/SsbYThUXwnylFXIA7Gg6vo3SlGv+KJxNekYzxgbiYA88iVQE7mjeTb+lQChsxStzTR0vtayG+fpZ1RiP5Aw8NNf/9pPDGF0eCqSpq1CwDqrqqwJUQgWnXYrm07sjU2Ebf+uEmM= 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 SJ0PR10MB4462.namprd10.prod.outlook.com (2603:10b6:a03:2d7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.26; Wed, 31 Mar 2021 03:42: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%8]) with mapi id 15.20.3977.033; Wed, 31 Mar 2021 03:42:10 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org 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 , Andrew Morton , Mike Kravetz Subject: [PATCH v3 5/8] hugetlb: call update_and_free_page without hugetlb_lock Date: Tue, 30 Mar 2021 20:41:45 -0700 Message-Id: <20210331034148.112624-6-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210331034148.112624-1-mike.kravetz@oracle.com> References: <20210331034148.112624-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: CO2PR04CA0202.namprd04.prod.outlook.com (2603:10b6:104:5::32) 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 CO2PR04CA0202.namprd04.prod.outlook.com (2603:10b6:104:5::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.26 via Frontend Transport; Wed, 31 Mar 2021 03:42:09 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 786a9967-ccd3-47d4-edb4-08d8f3f6f713 X-MS-TrafficTypeDiagnostic: SJ0PR10MB4462: 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: PkBYfJXbDs5aNYM5rZZZCbS+FNAc97uo6hG55mbhGSk9e4M7ocrCcQdugUmcA3NbUfEWyn8YS+HxRF0LxKxoW3KecaB2+dZrdV3IeMbzssVPOWPVEV4eq2xUYV/PjxTRaCqYTHo17zV5FqG9EkMvwhTcH7rlmI8Rj+7Y42F0s6we6PyL71JABRzzauVzL1wT8dJCbRNgcIawcOJXmq5xIGdTFFye7eEIiTDymNmKgNsPyW5EAeC++Qzp0y1XAPg1D9Gq28NxxtWoWBwQVYzvJr05uBofWGTOMuVQ5j4U2T/iephAWyDXQvzuqf1FoYIBd1S6itFvs/w42wbqFFBtGlnX+SfmFg8pGfAno4Y+o4uyUYEu8BY/TIoy/1zMhkwstxFZn2ONTYLNp/VkjPMqIcI1dcB+XtlWj7QmpNbukkTfOtUHpdc7wbqBSyYTjTvCSQ6ObV3bscPWAte9RpBXQBQ5SZ6pbEKNvFiE/L2sLwAmmQXoci0AHQ/z2IyKDXrL0TjzUOEs1Xf+6sxX10TF5ruXo0Tzu7yWwzr15T0c59dH1m877vh1y96kU0ynPTQ48C52BdTTMainxann0+F3f06QLLksZ+85JzrQibLr66Or8PRnfmUO3DcXWEZQSuaV95J41C4T+LytHOge9HwyWg== 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:(39860400002)(376002)(396003)(346002)(136003)(366004)(86362001)(36756003)(83380400001)(316002)(52116002)(7696005)(66946007)(54906003)(66476007)(66556008)(44832011)(7416002)(4326008)(8676002)(1076003)(8936002)(6666004)(956004)(2616005)(16526019)(15650500001)(6486002)(26005)(107886003)(2906002)(5660300002)(478600001)(38100700001)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: vPtNmo9ymXUNgayiTLJij2RohDNFXGUcbyXSGEsP3Tefcr0Kd1dFai8lnAIrqKFZGWBOUiAyBB73dCGvsvOX+MdL/qF/54x2lbiONTYDSRb7rsMbHubodxWB+jIS9ZZU3GD/wvPTNLEblKxIlI91tZ7tCLxklzFGkDdIW7slGIWU4Q47LO9it+Pdlec6zPlu2kdD0o6C/nA7yhMIh1TbOTFMEFbJCaE+1TntWwsoXJKqUbdhkqKB2pE4poXqeDAA3su1+CNjMnEz7i56vTBdjuzJwhP/Ikbdhp/0ddkSu/XAiZ5oaM3/nhi9yFcsiWOC9WSaqcgj9Lc8krhE6RrhPGeRuoactyJJdnBGuxm3IHFvAK0ySV6XnEBCAvZDmnc4AkAZKX16iyId/Wk87OOrYlh8xduyDScsdaru8wlbKdQNSa/MgJomBENvOcfTP6moLOZ5KtuojywJl9wFoBVg48r7RRBMLx5JMj795tQvjMZIRXKfaLcOn9KpEMWFV7CxINOGzcOojXzwzyWsn3MyWmRfN1F475tS6XThkR5UbeCZEbsP1kG+Kc6akuWeV8/pQpvZRkfy6iJGhGbXU7uh9ms3854HnVeUHXXJzOTeArE0E5v7T7WZc3ptOKw8tGyd0uiaZlnreudKMq5lSlcOONWOlzUNTWmMKSVmNsnwSTCKImIeMPgURqArlUOySsgScgKgXK76qiGLYgfXwlfLrtgRj0xYBisxp5qVx+zE4qVIalgHz0b/RtlNCxC8VohaLlm/IdGaoaRJNE5AKIlB4yLhRpuyhui5CzMheexw3hMrB3sApgiVHEES1sh3YpFml4V+hPxQ2/aw3HxZR4H4oYlqw53CXgQhfmmdvldnItICe2VW0G20dmV7BW1OGgAOX5feZCYfDXdtjPA2oYVURc7IksnQCeHxdDheQips8Kln8jYZyVm/nWMNegOGjFvyw7zTeIxmTTI2Gwv4voewYszxXdPWkkiQxqnp9R59c3Ov+OBQEzcmDKkW/GWYkDlh5E/Hcchij8k8eadT6rPT7e+6NTpt5Iat0p5koV5qxmyEl3n9Nw6rr6BTo56amGdWTnGPdzUgONvevKMK52kZCv9NeE2zebrj/rPjOT9hDKW4JpMQOf1g1xP6YsWbOpyi5DON6DpULWIEpM7pwWdrItroMlde6KN8oWMrXmHFXsvKFNtYH8OPcPKMrNsf+8VSDVrafow1qx70SU8mSixXUJkRSneXhX5YBfh4TO3Nc8hWLsp8x8CI5n+Vy9JiBnwDwL7D2wRccAf6BrgXFwBRzV9hkDV2fneKDS0CPdEdZwE+RbfddHFoT5+ruvt8n9qx X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 786a9967-ccd3-47d4-edb4-08d8f3f6f713 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2021 03:42:10.7340 (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: VvN193wgKmhwpDIsWZ+CTCwo0JQpd/zZErNo7LFCqI/wyOZeN2dmrvF/GKasWDMbifDURWrkBrN0tjDolqMroA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4462 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9939 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 spamscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103300000 definitions=main-2103310025 X-Proofpoint-ORIG-GUID: jxbsYDuhH3M8Xi0LCJiFV71YySRna8T4 X-Proofpoint-GUID: jxbsYDuhH3M8Xi0LCJiFV71YySRna8T4 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9939 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 suspectscore=0 adultscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103300000 definitions=main-2103310025 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 8DCA1C0007C5 X-Stat-Signature: jqdauc76o4hgbffkookccptx9us91but Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf06; identity=mailfrom; envelope-from=""; helo=userp2130.oracle.com; client-ip=156.151.31.86 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617162154-904158 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 --- mm/hugetlb.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 16beabbbbe49..ac4be941a3e5 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1451,16 +1451,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); } /* @@ -1741,7 +1743,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; } @@ -1810,8 +1818,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); @@ -2674,22 +2683,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 Wed Mar 31 03:41:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12174311 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70A36C433E0 for ; Wed, 31 Mar 2021 03:42:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0279E61954 for ; Wed, 31 Mar 2021 03:42:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0279E61954 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 3573C6B008A; Tue, 30 Mar 2021 23:42:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A5D16B0093; Tue, 30 Mar 2021 23:42:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB9DB6B008C; Tue, 30 Mar 2021 23:42:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0174.hostedemail.com [216.40.44.174]) by kanga.kvack.org (Postfix) with ESMTP id 7F5F26B0089 for ; Tue, 30 Mar 2021 23:42:36 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 49EE6180AD82F for ; Wed, 31 Mar 2021 03:42:36 +0000 (UTC) X-FDA: 77978772312.29.B7AC451 Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by imf12.hostedemail.com (Postfix) with ESMTP id 43A3C132 for ; Wed, 31 Mar 2021 03:42:35 +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 12V3djBt182236; Wed, 31 Mar 2021 03:42: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=3zU4pl1Ot5Tu7Z4gSP5dVU2b4RXriobkHAZmtAsLDMQ=; b=vizjcvO8D8nyXVyxU/CrC3XooIOEccHVw7ffHrfWPhfZSMXVRXbQSoqVQjsczQbXvHQP AAorSwJ/yUBwEMtF0v+1QCpf2hFk++ndZfhT/26TuhImW7S0VU7/B54WhgYIWcq9PtnG +vVlPvWhAn5hKTCE3n7GFFg4Dg5vU94HvCz9vdQd87azhALD6LAtBPAW+tSiUiZ5Gq8g 3qx/UC4RuZd3exSA7roYwfcmMY23vyxrXK6L8Ggg1tuANwSgSMMHTdfOl+nH7ZZDR3X9 Ff6CgZTpbSBjKQ/++gGedhEtjaurfDWyWpPi3dAyxD/9TMvRGwT9trbU3VqbYXbOM/5Q 8w== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 37mabqrsak-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 Mar 2021 03:42:15 +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 12V3fWW9086160; Wed, 31 Mar 2021 03:42:14 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by userp3030.oracle.com with ESMTP id 37mabkmmnx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 Mar 2021 03:42:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P77tQ2L9dW0HKxGZLKPI/8zWTLMKzKq088Nk+paVquZ3za7IerKrtslTmVE84oBdfDtoQbxKc2nenOkHpvEL4KN6ZFH2OlQwfzM6CXsYtw+rt1tk9HZW4r00kq9ivt51DA6qF7+70hjtfQMTbwaUwZDdDTbB3xImw1dsSy1uOJYB2qh6J8G9VWXQwhRYbBDMhIw+XdVC9ekgDW3jBsyR7ppKfapAs23oHUqUa3KisE7kljAlg+NqQymB1ZbckCCVX7PEABIcWb2mvWwCcHaEY1SDj7ozyyaA4a3kmNbzJIGx25ggG4+j9LPRlVaEwjaU4U/RUi/RTZJIUHeCWUdenw== 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=3zU4pl1Ot5Tu7Z4gSP5dVU2b4RXriobkHAZmtAsLDMQ=; b=nqFdXlmsmbql8RC2wK5o0vUY3hcl2DEJ1fiuG5jm/x+7xNXo7r2lDLK/wZtwp+NZuAk8BDmRNHOxOVYEPDLqGNUvVJPOb92m53YdFO/T0konHx2EH87fM3obVKPAk3eXEkcripN1xERLZQSkVjpvwbVOc7/dvs6KTZEk4aRyZSqrJf6fkEHB+Z4iG7aTaWrHlhMZQoftYZw/yAAOo4pu92H0xfzegBKyIMOfFMpVFCtoBO/UQOAxPcJqgRjnvdlmjGYp6OxwFOmrsD5xGfAd+nESQMm0ZNiCyBtE19f+ADuzVNUI9PZiFzY1i7l432gbWxDvXs/FfdhXNVCt4z8hKw== 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=3zU4pl1Ot5Tu7Z4gSP5dVU2b4RXriobkHAZmtAsLDMQ=; b=MGSdQcYFCNskqUwA93cqN9iWOB5xQEkv5E9zLZ3hmzVaicdhmuS5MGXHjrUqn+sHmD3z3YoglYGhiMra3fSxeDLj17y7FVt1Hf9oiavc5ojL8WJ9Gs9j0BLASLKprHUeURqQyYmsB6wrq5vdySdb1O5zWq5FAvK14R3z8Mv4r7k= 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 SJ0PR10MB4462.namprd10.prod.outlook.com (2603:10b6:a03:2d7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.26; Wed, 31 Mar 2021 03:42:12 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee%8]) with mapi id 15.20.3977.033; Wed, 31 Mar 2021 03:42:12 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org 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 , Andrew Morton , Mike Kravetz Subject: [PATCH v3 6/8] hugetlb: change free_pool_huge_page to remove_pool_huge_page Date: Tue, 30 Mar 2021 20:41:46 -0700 Message-Id: <20210331034148.112624-7-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210331034148.112624-1-mike.kravetz@oracle.com> References: <20210331034148.112624-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: CO2PR04CA0202.namprd04.prod.outlook.com (2603:10b6:104:5::32) 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 CO2PR04CA0202.namprd04.prod.outlook.com (2603:10b6:104:5::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.26 via Frontend Transport; Wed, 31 Mar 2021 03:42:11 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4fdfa20c-5981-42d7-04da-08d8f3f6f824 X-MS-TrafficTypeDiagnostic: SJ0PR10MB4462: 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: Sq3IXW/1nvk0uB6YiQO9528sUFK+HYm15lnA7fe3SFMw1tVQG98oXBe5oWyqUyQRi+PTuz2c0+7l7b+xPHPvqczCWZH74jd18IFq9JWN+eEHOKRAGW8b2qeDSmrDs9JodFwoqtoUjSfX9tHeGjTP0HYfi/BLewqxbTesWKBZeO7V9M7/ncX2xi72isjETl1lWtYfJhavSTn5GQlcIY2DKARy1vPBDOd7r8Be9cUeQU/PhChQo5hzGO4W2Q8LJ0ujajAmpoWOWwo0piH+d4KzQXTjqakiWoV8pz6La1KMvsjdHkBbdLlTblwvkhDx2brnJPar9eKXAg15Xfn9PF5e29FM7NGfx63ndvlyVVuvO6F1NuSO8sUMVYE8xs8l4WyM0EurMB/i5GuXrvg8m36XxwpIy26eKR+KImmDhRCKYg6kK9gGmvaZI17yUYdg4obNk5kZ2dFt/z6w+U/bzbwL+3MnKSoK4PI1p92KkCOhUtK01esnd1wHUYX/G7ftZcgx1OHCQo6TFWMR6ydwjt3yO7+/FDx4NBvOX4nA1JFZAygbllK32/Cvhv3yQOfUtNHokEB5cGAtai556MoigttEPzuyj41XbQOeGcnzkvxqRQeUyB9WiWI7O/ePzr7/MtBoMBiWHR5WcnhrJSYelzQdS+lDlOPKGxvNM4Bmc+uh/Js= 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:(39860400002)(376002)(396003)(346002)(136003)(366004)(86362001)(36756003)(83380400001)(316002)(52116002)(7696005)(66946007)(54906003)(66476007)(66556008)(44832011)(7416002)(4326008)(8676002)(1076003)(8936002)(6666004)(956004)(2616005)(16526019)(6486002)(26005)(107886003)(2906002)(5660300002)(478600001)(38100700001)(186003)(14583001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 0cgKrcdNlfpi5EfITp/UnAi8S0BmYEDo2fkee9xEvT5bHDO/N2CKx3VYYdNbvY2eHxDdyP6HuR8UjbvF2raMbRWPI4TPKomfCv49B1skbU/N7oQeJ8mZdXg2WW24GjyXhFnK2w7ZlyMgMhwRFcwGnQZZHZPc714dMEDHleYlHiGwC+1GRQFez2nop9KJfH/VpwuUzf3m0N3TxRDPrnUvI9PJlgUkjK9YQbBKGwlcajVF9CA8IabH9T+f89h1/pVyJeyboo6bmd/RFZf6Zr7Ro4aHV3Htl0Uo3pAIimqcRFX+6NtBaXo8LC8ZorH/VBcBvmyF/HKGU67gQ/fcqmDcxIrAlbTkIe3gJlCc5AH0U7Rr1ye4LicfgTFzio8SbkVDhj0KmkUcj4GeCMbAvA04cEVbZok+eAywqT0QeoupnmB+Xh7VSolbXWeuZ7kV04iwbEPRpKsSAd2nCRxIjlVzaUACZefmcCnu/UTvBiO9W2D7bq1frdM9jF6emrCQfnm1zEJWph0tohqyp6qCmkAT9IIpeq9JWc5s+Rs1bD6PzYXeTpolilGh9CnvotTWgvhgZtGtq7v9uX/Siq50rgWNIHh8kzLXyIrWln2ZsR/05e9MJnwtAgblF0QiIZWfY1ML2DziM45UyLEkuBo3NYVQVbs8U+99PlXMwkcfLqR0trAJmd7q73PShAr1HF6Qfp/2amCFIm/FFuiIbWOeh9h6mQuFEuvJa23A434lTPu0px38AK7OTBtNS0BY7XdwYmyXyrMXQ1NDS8JWTAdVFIATgTmtG0mUo6DJWUhGgYSmaxn+BOKaWiQLbG56A1VcLR36fCCB55UXW7OLp7eXfKzWsa48tgPz1fNRREUL1pV0YUyE7sjAUtOBMOnpA0IPJ0UilzsRngeO6KvqeRW7hVzIES5gy/UYrqe6s8Qfe1+vwqubPTA/G7CQXv4VVTroW+tYfgMT6lQHpQySxtxR+mdyUz5cJ+Ihn05rX30OQxRevSO/ipzZ57oVFsrtZcrbu8zkLNrbfFcpJD+96iFj9K5tATShqR/1JBTb8lb04Xavk9R1EqpvQmvRPUISpWjAadNeW+45KEorhSbeZU2kmHkATyo/9DzitddeUyeQGjQtoevp/9ae3qFmKTlCpQ1hUsbG1Sjqj7gbfpDl9Zlj31lGyzcNugb5vUO/X7gMsg1kaWjsao1y10w1m8cKFmUiyJHQEhFJ7FhtOqVHDx4VGbQzwcdu7pqXyrVmPD5j+iKLIPAtwqOohjaHxviSObQGnfhb8XPpMWkffJWo3x8BkPfYq9CsQLqHabvcSQSGPsS5YgvuzoWbSvTzcC7D0QN+KSeV X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4fdfa20c-5981-42d7-04da-08d8f3f6f824 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2021 03:42:12.5451 (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: s3jaLkYkARpnXIZL/GwssQh30x3b2/TzMs89eWxh8ZHA5mmc8t5UpZL9GyIVoqbcNwf2PoX6VVw8w2g92F7aFA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4462 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9939 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 suspectscore=0 spamscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103300000 definitions=main-2103310025 X-Proofpoint-ORIG-GUID: 65sAj6JnM0nd5t9K7AD8PJdW5a-0QTfb X-Proofpoint-GUID: 65sAj6JnM0nd5t9K7AD8PJdW5a-0QTfb X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9939 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 suspectscore=0 adultscore=0 mlxscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103300000 definitions=main-2103310025 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 43A3C132 X-Stat-Signature: bz7zcyn3c69xs14kkhfes6ius5b8fp86 Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf12; identity=mailfrom; envelope-from=""; helo=aserp2120.oracle.com; client-ip=141.146.126.78 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617162155-647578 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 --- mm/hugetlb.c | 93 ++++++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 42 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index ac4be941a3e5..5b2ca4663d7f 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1209,7 +1209,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. @@ -1391,6 +1391,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; @@ -1721,16 +1731,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) { /* @@ -1739,23 +1751,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; } /* @@ -2075,17 +2078,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)) @@ -2102,24 +2104,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); } @@ -2683,7 +2682,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)) @@ -2693,6 +2691,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) @@ -2706,10 +2705,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 @@ -2756,6 +2752,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); /* @@ -2868,11 +2866,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 Wed Mar 31 03:41: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: 12174309 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67EF7C433C1 for ; Wed, 31 Mar 2021 03:42:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E1D8D61954 for ; Wed, 31 Mar 2021 03:42:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E1D8D61954 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 0AB626B0089; Tue, 30 Mar 2021 23:42:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F27B76B008A; Tue, 30 Mar 2021 23:42:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF47E6B0092; Tue, 30 Mar 2021 23:42:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0103.hostedemail.com [216.40.44.103]) by kanga.kvack.org (Postfix) with ESMTP id 9894D6B008A for ; Tue, 30 Mar 2021 23:42:36 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 5891A181AEF3F for ; Wed, 31 Mar 2021 03:42:36 +0000 (UTC) X-FDA: 77978772312.04.D08FCB8 Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by imf26.hostedemail.com (Postfix) with ESMTP id ECD0740002C2 for ; Wed, 31 Mar 2021 03:42:34 +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 12V3e3Rd196433; Wed, 31 Mar 2021 03:42:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=5YNvFPurYJ/iLlKOIfYVeqvmYygFnDVjCOsULj/RHrk=; b=aE6htH8BaWkF5T9jnD/8xjlTW+EwueQmZTtwFun/5f+zQty9L6uM4jp2SD4nBr3RaWCQ WJQoc3jQvql7WOAlfiHCzCmCLG1Ynw+WKeazc0J9NA3nFRIqANAEO/R3Y+ci9LnWcfz/ e4wDQZEt3kS6qMEwUn1hFYAAiaP1tILneZ5yxrnCk88RpMai76ymqPxVWXPDtmm3Cv1a CQk1uYEZwcDYc6JQUt2+23v3RLMcYlIgT2rSnGYfThRWc788PbudN2ZVmoxu3gQsAgYe vlQgBH9kcenNcF8ABpR81KUgv6Xa04cIbY+SF+Pq2sluztFMvRPENdpvhUe+9fEVNuQu BQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 37mad9rs0b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 Mar 2021 03:42:17 +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 12V3ebfs133184; Wed, 31 Mar 2021 03:42:17 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2045.outbound.protection.outlook.com [104.47.66.45]) by userp3020.oracle.com with ESMTP id 37mac4wb6h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 Mar 2021 03:42:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ii799YiLV3NdRUwundnjuqcGfwq8qVFSQFChXngzwLnVbmiX7SnxaEPAU0IZEHg2mq5xP76FP9nShoU1LI9DFmgVbEJIA8f21UIC7FraOpTcQCCLPpfpS8Kqnk3GqxzpRbmoztBaNu7dw6j3na7Pxx3jJBPhRNNwtZV0gUm1soMB0jMDN3XExovCf1uGzPZJOVuxmFFexxfw77RFgJ13wpHlvQGu3UZrNNKS6zOVSWfFE7CBWJvnepIBeoDmo0mnQWiDL094vjeuzWx7wTPE+YaRRqJ9mj/SZNWTWfbuZpOItlz/teBTGS9BvUulZHX4/05WuV8nsTh3xQHZm01GWA== 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=5YNvFPurYJ/iLlKOIfYVeqvmYygFnDVjCOsULj/RHrk=; b=SPd2czEGkDXhr3yDds/Xsa3OEjd1D0qPxrSdf4SDJMoTeZuRlMSux5Y0KTePZtsUm3u55d18M0JOiBrExXsu78tMJ04nluJ2zDyTDybdhFMS5nX5aYVPPeUrC4vhX2cnr9HU8uvfQcNYDDvS/HasaF1zy64SE0v+y3Skku7Z+LRG6GNF6ohWKDdpFAMgkBx3GFqJP3Ld63iwhfthVSHaJufHhSSRv++bYjkNVF1rsrJu6F28QuUy7/6QX6nWnTnd+70W9dyPY+tGCpS6QPQMRf78KyLPhriPIFkX/FX0UaAruWjoe9IAfeHNazxHJDokxPaRUBI4FE05VmRZ8i1yoA== 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=5YNvFPurYJ/iLlKOIfYVeqvmYygFnDVjCOsULj/RHrk=; b=uR0fCnbsRdlAa/NTwrFChknIsRzrnhdaX/2QAr3wu/MU9jmnWC7/JgYDY1GKXDfwEMdyv7eFtk9Aq93sulAZzkcuwUirhnEVlZhZePA12xy/wjcj2O4UdAAVl6nbvN1oo0SfuZTUMM4WSc8fqUZzvUnFsdVT6l5QGN9C2tUoBcw= 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 SJ0PR10MB4462.namprd10.prod.outlook.com (2603:10b6:a03:2d7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.26; Wed, 31 Mar 2021 03:42:14 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee%8]) with mapi id 15.20.3977.033; Wed, 31 Mar 2021 03:42:14 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org 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 , Andrew Morton , Mike Kravetz Subject: [PATCH v3 7/8] hugetlb: make free_huge_page irq safe Date: Tue, 30 Mar 2021 20:41:47 -0700 Message-Id: <20210331034148.112624-8-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210331034148.112624-1-mike.kravetz@oracle.com> References: <20210331034148.112624-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: CO2PR04CA0202.namprd04.prod.outlook.com (2603:10b6:104:5::32) 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 CO2PR04CA0202.namprd04.prod.outlook.com (2603:10b6:104:5::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.26 via Frontend Transport; Wed, 31 Mar 2021 03:42:13 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b5499952-fd2b-475a-42e1-08d8f3f6f934 X-MS-TrafficTypeDiagnostic: SJ0PR10MB4462: 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: R4B3Z5defoI0MgOeHmQJzOyW0VBSmvQhjA+6eha5hJuJWBhv0Un43vSPaap4JWo/mHgnjgDX12qCSNVEG9OPTQTBkF3SPegznVSP69SZ7ULJfOJ9+FQkx+jh6xrWB3vDicr3prc79pchTBWTDSQf5Hvr4c7gD1VAjO293dJD4eED0FINFJcF+whBeHX/GoP8QqAXA4PBlo8Q7Q4ON7fcyNzrbMFILGgRG2UYQAhEfkfAUlfctCZ6LMuaheo7cd9M6hT+935IelhcURBWDuKbhcQt8ZI51NJq47uZ3GHd2YTUbBTlNZEved78OgPsnWySj64f5YntVBOP3H7KKIxjUDWtRd4d9W1R9czYBH8KyggIGUVBmwDJHijiSga/VUTiUXbtrLbHziEKOOs0SZCjqbCU3r/QdfeVJYhhaaq+n9Ac1okIYQVTHDpxOg1tTsJGbV062rKvIRyl9hdH0N1ArqTHaMhl+VWm6ecxMRveXyUWymhINy7qchp7HVHRczn9YQKa/UoYhoiE5OQFbOu76p5HoHQwVD6XwM3LXS8RlNoth1b2Too+WRVtbc/KE+1S7bwXY0Fav2Bdmi35iD0LHKCK+SMvOc3Uls9Y1Vx6tWYT8ue1d7I9X2LI+yXRdIF9Ohl89JkPKL8O80xp5tw0KRiVtxVhgul0FYs0GwQwzKp8oAkjR09J0PoNvh+W42mdTeqaTplwzeA9r6J8SGLyrNH8irqfpiqaRYAjNhebmB934lwLR+6FqiqmdZar83FO 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:(39860400002)(376002)(396003)(346002)(136003)(366004)(86362001)(36756003)(83380400001)(316002)(52116002)(7696005)(66946007)(54906003)(66476007)(66556008)(44832011)(7416002)(4326008)(966005)(8676002)(1076003)(8936002)(30864003)(6666004)(956004)(2616005)(16526019)(6486002)(26005)(107886003)(2906002)(5660300002)(478600001)(38100700001)(186003)(14583001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: UnJVsVsE8UWAG1ijxUUfHnGtBRETjiiHYdoKIeIXAPK1+fwFnzOtY4yn4jSpfPpSlxRzQSwlcvi8pVyvX0sqc+YVUNW2YSWnKPj6gvCMYeCwIDbic4VK/c5O6SPUul6jmbs54JwHwWOEZQVw/psNiiaop/9BHB8VcUpauE/uNT4A5ViGgIKuwnMry/EQagmZ4uJWk3QWlnTqAJjpNgukap+4p44gPLw/OuYw6g0rwWICdYZbhjeJZZXGrAzGIdFUaiW6qmzewSCS8nNIy6Q/0niXQ6EIhQODLCH25w602O2HF8L2rwhHPgOVqPqQk2QJYHuPFIo9pYsC2B+DCdaPRL5+oTGb61s9bz4GdnCzN6Cvczwv+CBaxYqHWmyCoki6j1dPuLqNYysfXAxLEIgNKVkKK4PcoczuY7jB4TwAnxdC84LSElmRD64MM8PAFdSzr4lfT0iFRKYYAejh94oabjNjkxTd/vGSi9Kf52Potuy2Lh0koEAeF2xio3jq8N1HCJ/veV+afMC7EO0/NvQzmc3xTRai8jIFbUEXojMbCG5SjDeBZnuqH1ZQtmV4N7J4o/7pJxUlkVzQijPulvo6mtDQUWCH3bntPbJ/yJOevyI1hDprNFP5u15jqJM57MagHdYVzIwLCegxhHpfTh7Xzdp+l5Dh1oqCULRyRN/IVziJzYSWxorNPp5U0pc0TBkRSFKnKKVT2g0gEtDYzPkjm3p5LRWYrzPHo2HKWmPJe++R5OHXvK3+DwbCdli+CHG0cD1AyP/uGCUXcLcfQL6pOY8VGFPagkrf0ktqvxIB9IJXlYh8OsG4Z4CDQ+U8LsgcqzHL6H0MvHgmqzqvyEfA3OfV87R6fIGb9bdchPlA8c2e2ksU1+SqgiEpqlIkpzIo61pVZN4fdfmzk6B3fbz1BnKFCdceVt3r8+mi4RmyBszW7YjjYLSb5J9HTny+3EDsUfsYD7LQPI3FCFDL23E48rKRCJZlohnWFrZ0hsxHuJGEn5fKiBbyaWwE4RUKo5O3RgROlokbfTpLtZPfsJCyrECKglvOXpkVphrbZpk1Wo6U+6D5Yz22A78kHKmY82SzBnLo0oaloai+4dD/nAFCYTbT6M3kX7qAqUDZbzCjEN03AhBbHPlbStUYdnZpasXSVQnVwh/qiu3vZATzfb6y0PtkwncakNqmvHQaNCuEToZTWkTskhBy8p0hmKtSSzVICLYjRL/sxJcPsb5pTl9tnTvKWooIJEI63+AgTYdvbP3137VQiOhXUjkwUs4+Ds/izAMnJk/c/yAJtxMHN3ij0p4TxJJzirfhS4ECjPpvQd/2pA+AEEvBRW8vPOy2yN0f X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b5499952-fd2b-475a-42e1-08d8f3f6f934 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2021 03:42:14.3372 (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: g3MORMA8t2Il4mQncRBs5rBmkQKhxbDDEEi0OyAh5C6Fvf1j/QNLSzmsrvJboukvbX589G7SsIjSGUpbf8Y3xQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4462 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9939 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 mlxscore=0 suspectscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103300000 definitions=main-2103310025 X-Proofpoint-ORIG-GUID: wp5a0rze3wgxpd-FUz29vd4CAJ24su91 X-Proofpoint-GUID: wp5a0rze3wgxpd-FUz29vd4CAJ24su91 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9939 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 suspectscore=0 adultscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103300000 definitions=main-2103310025 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: ECD0740002C2 X-Stat-Signature: xugb4oshdfa1etw8daqsdnha9m6n6fqf Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf26; identity=mailfrom; envelope-from=""; helo=userp2130.oracle.com; client-ip=156.151.31.86 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617162154-871901 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 Signed-off-by: Mike Kravetz --- mm/hugetlb.c | 167 ++++++++++++++++---------------------------- mm/hugetlb_cgroup.c | 8 +-- 2 files changed, 66 insertions(+), 109 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 5b2ca4663d7f..0bd4dc04df0f 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; } @@ -1412,7 +1416,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 @@ -1422,6 +1426,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); @@ -1450,7 +1455,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); @@ -1461,67 +1466,19 @@ 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); + spin_unlock_irqrestore(&hugetlb_lock, flags); } } -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; - } - - __free_huge_page(page); -} static void prep_new_huge_page(struct hstate *h, struct page *page, int nid) { @@ -1530,11 +1487,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) @@ -1780,7 +1737,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; @@ -1797,7 +1754,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(); /* @@ -1821,12 +1778,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; } @@ -1868,16 +1825,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 @@ -1887,7 +1844,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 { @@ -1896,7 +1853,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; } @@ -1946,17 +1903,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); } @@ -2004,7 +1961,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); @@ -2021,7 +1978,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) { @@ -2061,12 +2018,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; } @@ -2116,9 +2073,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); } @@ -2463,7 +2420,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 @@ -2471,7 +2428,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; @@ -2479,7 +2436,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 */ } @@ -2492,7 +2449,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); @@ -2704,9 +2661,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, @@ -2802,7 +2759,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; @@ -2832,14 +2789,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; @@ -2878,9 +2835,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)) @@ -2888,7 +2845,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); @@ -3044,9 +3001,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; } @@ -3633,9 +3590,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; @@ -3731,7 +3688,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 @@ -3770,7 +3727,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; } @@ -5834,7 +5791,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)) { @@ -5844,16 +5801,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); } @@ -5887,12 +5844,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 Wed Mar 31 03:41: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: 12174303 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E313AC433DB for ; Wed, 31 Mar 2021 03:42:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 89C8261954 for ; Wed, 31 Mar 2021 03:42:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 89C8261954 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 7D54E6B0083; Tue, 30 Mar 2021 23:42:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 788AC6B0087; Tue, 30 Mar 2021 23:42:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C5DB6B0088; Tue, 30 Mar 2021 23:42:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0145.hostedemail.com [216.40.44.145]) by kanga.kvack.org (Postfix) with ESMTP id 219F26B0083 for ; Tue, 30 Mar 2021 23:42: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 D42A61DE7 for ; Wed, 31 Mar 2021 03:42:33 +0000 (UTC) X-FDA: 77978772186.37.8F059BE Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) by imf01.hostedemail.com (Postfix) with ESMTP id E9FA45001526 for ; Wed, 31 Mar 2021 03:42:32 +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 12V3fcCr158760; Wed, 31 Mar 2021 03:42:18 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=ACpChQM95ueVORwk8vKkG+h8QzE08ollJKkIPrZEYb4=; b=nsgNN7bREA36yZuu/bF8CShAUr97nbkPWxerDbqeq9534qc8l/3QEqt6M+Nx2eLEdG+9 h5JFJ1nO35xn0aplcE6P1wBGiEPgxt4nMbooJL5NbIp95rpKt7UgfWHOObLwXIVB0t7i k4AsaulN5rCBV4VPW5TLTf68f9J5WLTDXJdsZQHAuQhigufoI+F6OLUa0HwMlrTU0rcY EvCs8gCLBDGJLjXpW0l4Ol7nG8ectpmma6vxUyQeDYa+mW7NOOedA/LFhuf03yeqpPuL XnXWX9tvI/z84cdGd3oTJ3VgaENlJDDN9DJRT/6XNuY+1ZQzQukp4qKIKn/Xy0VocfSY ZA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2130.oracle.com with ESMTP id 37mafv0rkj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 Mar 2021 03:42: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 12V3ebft133184; Wed, 31 Mar 2021 03:42:17 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2045.outbound.protection.outlook.com [104.47.66.45]) by userp3020.oracle.com with ESMTP id 37mac4wb6h-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 Mar 2021 03:42:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e+w5oZTXuaJT7pZF23qXTAiRPKEkgrz4AwsAJTl4A9A/eItCwGgXRdp0Ybl2jtZMMbvv8/GETAnNuAE8mUKS29dZ4e4Rwnw/mdIyPgM/+rz0HPc6B/n+z6J3tHv5tfgntj6QWfl3Z+bfzCZDh3xRGYMevcd/LvhqOWS2w9RDMv/oyms9HdsbuDKHB9NcQrT/SVbUlOMaB7suBSxouTThreB262rXeLIh/2PnFokg0huqRyfpTQyvGlQsFdFrJ9Bf2S//AUiMdri1uGiVXa0Fo8ZnH7JuyOg4dXptXP2/qB0Z91Gx59EuXzw9FU4R67P/nOhkKZsV6NzljS7p/bnRVA== 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=ACpChQM95ueVORwk8vKkG+h8QzE08ollJKkIPrZEYb4=; b=XVs4Z0W75gCn1L0rdbVzulQ65Apd35eoU5N5tG8mdbIi5gqEqE5rM/goVIa6Y6kGavP5UQOy+DxwFFBOIT+D3hFA/s9fyOvYFjeG31P/sBY88OAUYWL218kqOv2BjPnRx064qpBxQOomOXWdX11IdbgPBaJcLiK24IeKH4dqWFelgCbmRBnsg6BNgHsf3cW1X12Tfq7R0ecJBW9XbZDloYCw+I3nzPzkcBRkhFE4JRlFDF2HJ5hSNalmclZ/6JwywY87ncq+3Jl4X+gO3B20BvVJ1vvFzoRRL5YPQ2tGx2JEUoXGn+iQKQ39MVkV189Gdq0P0FNzwCflI7oL+MBx4Q== 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=ACpChQM95ueVORwk8vKkG+h8QzE08ollJKkIPrZEYb4=; b=PFfZI11QmxJ6WqX+XujbTyaJCtG8xlp9MwmiWZUMIi9/hOEcPio1eW8DY1ybI7hBOCJ/waNZKWOr3iWUwI6ZsgeI6t6s3lo/IIAxbYoJgWCH8dpbOGx7Ig0Yd9gGwjbm2wCAW4ux1ABuZMyCMfMuIZKfgoZgujlMY2GCxB/Bz/o= 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 SJ0PR10MB4462.namprd10.prod.outlook.com (2603:10b6:a03:2d7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.26; Wed, 31 Mar 2021 03:42:16 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee%8]) with mapi id 15.20.3977.033; Wed, 31 Mar 2021 03:42:16 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org 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 , Andrew Morton , Mike Kravetz Subject: [PATCH v3 8/8] hugetlb: add lockdep_assert_held() calls for hugetlb_lock Date: Tue, 30 Mar 2021 20:41:48 -0700 Message-Id: <20210331034148.112624-9-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210331034148.112624-1-mike.kravetz@oracle.com> References: <20210331034148.112624-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: CO2PR04CA0202.namprd04.prod.outlook.com (2603:10b6:104:5::32) 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 CO2PR04CA0202.namprd04.prod.outlook.com (2603:10b6:104:5::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.26 via Frontend Transport; Wed, 31 Mar 2021 03:42:15 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 66141ccb-c9cc-4ddd-eca9-08d8f3f6fa59 X-MS-TrafficTypeDiagnostic: SJ0PR10MB4462: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DYRidwm8/qVAH26RbfgSBPUZbbHlIMqlI45Puest0uVkwDnlP+k6I07PzT9bssqJiW+/d7JAwDRi2fU0t1ugystnnFZhxpax3/wgw8X605w+CXk5uBwyTDiiJzustN4uTBYvFhb9H/ZU8+GTpNIDyxdibejsLtneQOr87hWQ2eirjVCV02CICPdpvv/D4JHZNAhnE850ow14D+iJtBPEaHWpdrRETAie+o0nTSw/UlJph4olTAmujBGRgMddootpl6hIk09bFkVqSzSU53fIkaarFodZlP1kDgZCzBmNlDytnrmKX0TQnvnrsP9cd96VOswf77UdExnQeGsh0UkdmAonCtg9fVd2rmorhg7bmLJU8G/Iuo/ILbDfTbLM/z1XOCo0v8qx0EWENGFLF7M95OI7nmKcE29w/QzuXPeS77MPI/X5dzICWFUlZNQ5GC7INX2q3CXfi0X2cGdy1Rhpi53wKvmPQkFkvZvIHdzGtOq8Ix/w5nzWgfPTOF6IZmco6qdxuR9dUd/EXTf5jBL7tJHRt8piqLRsm3lmcDtUOC66AkrW74c6dis/87wiQFzZB9sigtTR37A2Vn7R6pvRo91oVZbQmuDw1frE5ZEC11FOkIQLcbAEbkiyyGiw7gYk7+8CmfPRDddmjCLSlJJB4A== 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:(39860400002)(376002)(396003)(346002)(136003)(366004)(86362001)(36756003)(83380400001)(316002)(52116002)(7696005)(66946007)(54906003)(66476007)(66556008)(44832011)(7416002)(4326008)(8676002)(1076003)(8936002)(6666004)(956004)(2616005)(16526019)(6486002)(26005)(107886003)(2906002)(5660300002)(478600001)(38100700001)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: ncJAgvieI3PnTt+vEYMzLQvlohzzjbC/bj2CnZkxBi/Hs0mtNiMx+l+eERxhG0UKhVSeYQdHn88XEUssfrXPibLZMdWQv3CrcEyo0z4QCSd2G4Vuh0V9wjqTcJ+TOmYx20UuKva+hWWAP6pm9zJxI0/7pkrYoW0btPrziZaIjl/wNPdAYn5Rv//XQVx2h2zRV+2o5nPPQhbhjptSvMoIR+6aL6DLxJvaFEkjD/G22gqy9jyFXmobW0xU6ox/SIl9PZBoC7Ff3NA9fGmKPE5nElD6ZlUem8t/THMR5qVB7sE0nUwmL5vfp2SOQrZppQnw9Y6/WkVnM9Gsjh7w/FBvDf1H2z0jzkgO1P12ga7IDH/bZYRgkr+O+PSmGD4Ig9ZScYYJWaTX6IFR2wveFBfKC77XWD8/iOBEtwzlm3dvux31gW0ZtcsChrcWvveYA9bq6YNTct7IfoagieJn6WsSOBTKNueA0hmJGszNK+2FCy8gr2UaKIEoIwC8Ke2UsLNfg/sCht48yWbj+u5/0gpee784E4u1Jf0iBbEoXKJonwQpb1ZhZ8j36hzb19mM+cQBC9cs3xqJmasACr45RoJ0Y7tOi7YpxX4WTNS6YoAbV2Faz7mj7Byh0m5+aci3xNlOwlMb880RXULub0YWnEgVp2mmRCLBCcwu2F/u3C3NQN179/AM+p+pTW8uGc2idfH+NqP4Dyv6JtNCaJ9yl+ZeT7BrFCUjhgf36gEHcKNkoZ++t8Fqfb6Ftdy6B1SlwdJQHiphegafKam7TneATxyCinK2R6XkRO+8gvpE3GVKE8qCNxqdIu48txrEPJo7bi1283+VmfWYfxrS3y4Osj0fn2rvPlswLKlsqXZVxRpSg/rC4xrTrmkWqULyyO9CvnVHT7cV2PCZlHDOcpZjw5ymigcpnCt4WJfEWH0SbDzE/0mT7P1lZ2R6jmGrGQWYWs+MsGW+yOY2dbdivRA20OOHgPJOLiiF47NyRbwrRIzc3JND9RvuVqVyBVmFOo+QNglhBtoHDZ/Y4nEtaW2m6UUp4d8+rAgjkDSZstC1z5xWHh0Ui5ibqJRnswnF3U3yaXFekCdrM//rgikt+j2lQJWZ+UOt5DDkdu+oY0rnkL6XzCZhkj41t9ucgUtZMnAERWDNwO4L6kM5sc7B08z6p3J5Za4ElPYJ1Ab7st/k2f1bLQBHEBV9pyBOYf6C6WLIbsXMRV5nag6mUAuJLqND5YZlWqjcThGa7pUvZv4YfHz15jbZ0FsTlHAIo3SC4Sc5OpF7PtMbru39Ueo+hAQtiR/XIOmqVOLOK2HJ6M/bSOFmpzdgEeAZrd1zpKHZkvDnh0YA X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 66141ccb-c9cc-4ddd-eca9-08d8f3f6fa59 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2021 03:42:16.2309 (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: 57X+JdLthOLexHSBVmvWaz6l+BeLelDhTt3DZ2nel9zXBjYPNVMAmKfJKjfUZrG4e2mj2hj47q87zPMaaNaXpg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4462 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9939 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 mlxscore=0 suspectscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103300000 definitions=main-2103310025 X-Proofpoint-ORIG-GUID: D9qyPm0UK6kOCRsNSWIXPt8eNutY2G3i X-Proofpoint-GUID: D9qyPm0UK6kOCRsNSWIXPt8eNutY2G3i X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9939 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 adultscore=0 impostorscore=0 bulkscore=0 spamscore=0 lowpriorityscore=0 mlxlogscore=999 priorityscore=1501 phishscore=0 malwarescore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103300000 definitions=main-2103310025 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: E9FA45001526 X-Stat-Signature: 4krupg16s1ircqr7mi4fgdparkqdhfxc Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf01; identity=mailfrom; envelope-from=""; helo=aserp2130.oracle.com; client-ip=141.146.126.79 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617162152-203032 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 --- mm/hugetlb.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 0bd4dc04df0f..c22111f3da20 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1068,6 +1068,8 @@ static void __enqueue_huge_page(struct list_head *list, struct page *page) static void enqueue_huge_page(struct hstate *h, struct page *page) { int nid = page_to_nid(page); + + lockdep_assert_held(&hugetlb_lock); __enqueue_huge_page(&h->hugepage_freelists[nid], page); h->free_huge_pages++; h->free_huge_pages_node[nid]++; @@ -1078,6 +1080,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; @@ -1346,6 +1349,7 @@ static void remove_hugetlb_page(struct hstate *h, struct page *page, { int nid = page_to_nid(page); + lockdep_assert_held(&hugetlb_lock); if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported()) return; @@ -1701,6 +1705,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 @@ -1950,6 +1955,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; @@ -2043,6 +2049,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; @@ -2641,6 +2648,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; @@ -2682,6 +2690,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) {