From patchwork Mon Mar 29 23:23:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12171175 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 7BDC3C433E0 for ; Mon, 29 Mar 2021 23:24:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1287F6196C for ; Mon, 29 Mar 2021 23:24:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1287F6196C 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 C335A6B0081; Mon, 29 Mar 2021 19:24:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A429F6B0087; Mon, 29 Mar 2021 19:24:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E5516B0083; Mon, 29 Mar 2021 19:24:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0218.hostedemail.com [216.40.44.218]) by kanga.kvack.org (Postfix) with ESMTP id 3C6876B0081 for ; Mon, 29 Mar 2021 19:24:41 -0400 (EDT) Received: from smtpin39.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 0002A8249980 for ; Mon, 29 Mar 2021 23:24:40 +0000 (UTC) X-FDA: 77974493562.39.25826AF Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) by imf07.hostedemail.com (Postfix) with ESMTP id E859DA0009E5 for ; Mon, 29 Mar 2021 23:24:39 +0000 (UTC) Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 12TNIwoQ153749; Mon, 29 Mar 2021 23:24:21 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=kiYEXAzkj8k19ZaDk6k1MsXea5isDu5qDl+c5dI1+mk=; b=JyTDHQf7k9I1YjCEB7TIMjVqCbi6QtC8u243HxRy/HaLxrVLUH1I6c0K/f/PgZsXs5St acN/ZqHcissDPVNwsv4QhMvcjYRAf2gqRaUn01vPeFlWpENMyscdSUz6zACOsmFcQTl7 zC2rgKSJO/1/oZpe44fFCDF1IFxYY81RtS9WwmmPmxcTJ5rXnRaZA8Bt6eRdZPAz2ur3 ECvGcDgcOuC/sCiWYJmQj1lAdCDwPRYRoxxKgyvITSs+F+n6uRXBoBosSgFMZgYNVNU2 jeI5SsCykbKKdj+ObI/y+OVWj+zbdq9fJ60OdYf/Fnyt6Y3QIFRnTc+77HldH5rwexVY 9w== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2130.oracle.com with ESMTP id 37ht7bdbr5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Mar 2021 23:24:20 +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 12TNFYFk055873; Mon, 29 Mar 2021 23:24:20 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2174.outbound.protection.outlook.com [104.47.59.174]) by aserp3030.oracle.com with ESMTP id 37je9p06mw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Mar 2021 23:24:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Bqg2lHTur8yQyoZ5r1CubbEBTJ4q9/T1DAOd2/6mMDjtw67f3cqHZ7otrGA38E4n8GP8IzaT5KCYXL23bCHF40r4Z3riZSJSUT8pETMFftigYh50c2sLjGJCa6dt7mykXmW0yINjA+DESWtQ1PfF/j/P84yDUu927bd9gUQJgXvbNRCY6G7mkSfGziW/mkaGi+9gf0R4JlPmLAdcvipp1PtmNWG+XmhCAgturTgnww9DZNO+j4ih4EY/LY+Wev2Efm8/XtsaU+Ir8yE53cteiNwobndE6HL1Uc+zskaF9k1UvIgI30P5AL73czwIbsFmJLCoibyhHciZERxMsGO3TQ== 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=kiYEXAzkj8k19ZaDk6k1MsXea5isDu5qDl+c5dI1+mk=; b=D5eF2YS+Hfeu3PnSfNKB/+gSADLdApPbZlRbPr++fjYO2JLKCjM/YC0peCo+n7/TxXvgRzPzQTz5pTOUZ29Z5k57uBlqhEry+wIzeigizch9UBvibiCrk0JoEoAm0Tj5QZmbGd0HXIkjW1Pea6dHXo8mqZO2I2ixlYsfvShQrm6Yrd2dO9B2UmvQhke2d74KKPZb+ue8B0YPadcGnLl458TnlEKXA8gpH9xZUXFHd9HBpNv8Qm7nHGG+Hgpv7mdj1vQML1W8siIbCXRyzX2C+gv7qf+evjcAIUL9ykyUFYlJpIMVuPKJEO2G9s0tXcFWsvc9GdL1FBA+H65/daEv9g== 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=kiYEXAzkj8k19ZaDk6k1MsXea5isDu5qDl+c5dI1+mk=; b=sby6V7cP1Kabc14igMr67e/ykN533VXMKN9XJc9ZFlo4CWYei9+9Lx1gUS8svTfR1erHGqW0Ewq9CvdPEv+oZG2vEd+WO57YxvON/qo40FFxovcKCNVZUsnZscTgxazRdBRm18dcOVREB18n0LKKy+aiivPca30WZByVqBX2XB0= 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 BY5PR10MB4148.namprd10.prod.outlook.com (2603:10b6:a03:211::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25; Mon, 29 Mar 2021 23:24:18 +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; Mon, 29 Mar 2021 23:24:18 +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 v2 1/8] mm/cma: change cma mutex to irq safe spinlock Date: Mon, 29 Mar 2021 16:23:55 -0700 Message-Id: <20210329232402.575396-2-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210329232402.575396-1-mike.kravetz@oracle.com> References: <20210329232402.575396-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: MWHPR10CA0065.namprd10.prod.outlook.com (2603:10b6:300:2c::27) 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 MWHPR10CA0065.namprd10.prod.outlook.com (2603:10b6:300:2c::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Mon, 29 Mar 2021 23:24:17 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e9ef4317-bd97-4616-4d6f-08d8f309c667 X-MS-TrafficTypeDiagnostic: BY5PR10MB4148: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UxOv8S+tQU5gxfDaj+DmZnvZ/pYidg5LzArqQn7OO/R2bPfzgtvz4MKalpWIKa4WKs+l05VvunCrp6N15b4aWAQinGJQZnOFL1NOOqeryd07oMKhjjn73SXRVhDJ3uCvyAkcIyNbviPyq11SRVyvCjCghBl6/Wc0jIJiEcCIqrKaqLiiFvMEPdNGxHE0BoDJZwj46ox55t+vjyBigIyrkFL8kh/zRJAdEuO60E/BLFoFhx15jAR8M9bMPKU1ybGDsM4tlqBHYyzyKUTmT2JPio7Je5H0jbv6KrFczZG/l64XkHAfQochtYVzkeVTzQOiVueqJJ3OKYmom2uevTGjCbuQq7p0ozYvWe5nBCW1ZynnBAKTVBWZ9MNNmK+dT/fMFNs81d4YjdPp9CCCEucUcQ7QTQm53FIpQDi4xEricx6G0nn55o+9+0BghrkuqXgtbtq842Ck39rA3SjVVWAzZDVr/1v5MgIIdO+D39qLTkx+E+NSxFqLG7Kl8lcNTJP7pAZ7d/dlaF8K9AT7NbjWOOvzicgx30OpEZbEWxWq+dcF2PEnJ5nt9yTZG0cfTS9j97sumWY/vRsxFTRGvk6HYSf1H5c7+J6RoPuBJk8O8rTTlBMW7Y57+fgZNYkfypmOVYyTpsRHv36uhvF4oYb+0Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(376002)(366004)(346002)(136003)(396003)(39860400002)(16526019)(44832011)(52116002)(26005)(2616005)(36756003)(186003)(7696005)(7416002)(956004)(478600001)(4326008)(6486002)(54906003)(6666004)(86362001)(5660300002)(66946007)(66556008)(1076003)(66476007)(83380400001)(38100700001)(8676002)(316002)(8936002)(2906002)(107886003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: +TIliutXksls0XFOEchQDlU3IuGWwL/lvpmGbPVzG5e3Xs7qn+0OB2cwObu72PTQRa/6jVpEzZK7xPg+rRIoKqHJSUd+r0SHxwPAk+TT3x4vJuDtb+GCY0RAj41UVbC9iDrwwMgBY86m+nwUUPOBufTeVfqTGxjCmKsQHYnLu033Iyk4H4yeFucZQmI/2oHgTfoqbE724SKlkmhXRT/MHddAsao7n+uLB7HOtiOkPeYWLSbkqu/CFZXjd3m88fxpVwjgF9iIj5CED1ynSCgyDXqiS6d6cRH9GpuYkV1xac/BL9KEeqMNxjoAgv/87VTCb44cqeNLJ2FDkjlVs8pxB4SHrZs5DIxYqRFh2QT9akTfLu9DrMxtcMIyG2F/9J6N+Ye64FxFIEzr4zlp994iI+6AmHxXwzSyDbNNV3togVc1mx/ZQFzyKNUyMgMvMuRs/Bf0jVIj3ykx3pXv3S3NOj23+EmZa8+JL7oU9OXQboLr1dCU1etpc9Nn/S6o2+p0RUefCL5GxThmhWnIEKC0HbinFHtRVBGzFDdQ2r1HVlDxxO2zXOZe1VybuqinjnhFibLAng8ckzr4hD5VAq2SBpYZOy4LNvx/5R6SKbdhmFML78fzmlckXgNbMMwtjwxsFm/FeuTRxKIZZqgxBVj+KyIW5NpfU/wj9e3Lqcx9Hevuy/pdXthWbnQ/gHh+3z9lowc51PyNzJXB987VKnyhwjR8r28woOuBq6At7olv9Kq2xMWq9NwGd5AOQGCk1T96fkF7pBJi6rG6/YJHxXttxfz3Dt8cubFKpt2RwTEDzXTPcD80p4ORNiAr5DnYtfv3exm7hF/7DcQoVkUV3Nhj7DkKlb7CfjDEdfmhUGKYbVmfOiREWop+p9FcR7WOSd7tPszJ5ETJLYRZyP1xW15ZYncgsjXKIuujFtJfSStqjgfKmCZ50yMKXyNUIgNktC+JdQ5gPqMgSttZmb80f5FzJvlzixCN9w9AsjEt0YadjNjQ1eC+MS26qMXL8Wwe0swVHh58iFvzo4uqZkPOyrjrhkWSJUXorgUyDr05VNOyhAqjJx6zXmTWAH9Q5vZxifWv7dOJENnucwsEmCfWoC4SHkc9XKoEJ2si9+BLmyjEBJujKGye3i0tXJjBe/3EU1KNrSoxrMZ0vs+n1GaTy9Rb2KckXQCFECCwDZK9A1jVWeZwDe8GYjhJH+1BoU17e5xJq/a1GT/eVWkjRIIO8ZIOPH2U7P9Gn1p46aBK1hdkjhp9vebw7upSrQDFTmY7NrfzuZGD8EVQDeqEpf8TJmI16LBg/QQeWfZp7NizWBj2xLLA1rDn1PftkzFbciSOMCSl X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e9ef4317-bd97-4616-4d6f-08d8f309c667 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2021 23:24:18.2904 (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: 3JoasxsPKAUBepD+ogeDZHCApTRfeP8ZZGSbHxkrNa2Zlcoo2GgnYcUwZ5XfMk11IW24sfr+PrHc9V7+xTZEQg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4148 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9938 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 adultscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103250000 definitions=main-2103290173 X-Proofpoint-GUID: XDF7oFZfr-wMC_Zy1E4FC0_fKoGFD3LS X-Proofpoint-ORIG-GUID: XDF7oFZfr-wMC_Zy1E4FC0_fKoGFD3LS X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9938 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 spamscore=0 clxscore=1015 mlxscore=0 bulkscore=0 priorityscore=1501 adultscore=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103250000 definitions=main-2103290173 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: E859DA0009E5 X-Stat-Signature: 4kyf1posijnub7traftxwcbrotyd3wzd Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf07; identity=mailfrom; envelope-from=""; helo=aserp2130.oracle.com; client-ip=141.146.126.79 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617060279-333857 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: Ideally, cma_release could be called from any context. However, that is not possible because a mutex is used to protect the per-area bitmap. Change the bitmap to an irq safe spinlock. Signed-off-by: Mike Kravetz Acked-by: Roman Gushchin Reviewed-by: Barry Song --- mm/cma.c | 20 +++++++++++--------- mm/cma.h | 2 +- mm/cma_debug.c | 10 ++++++---- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/mm/cma.c b/mm/cma.c index b2393b892d3b..80875fd4487b 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); @@ -391,8 +391,9 @@ static void cma_debug_show_areas(struct cma *cma) unsigned long start = 0; unsigned long nr_part, nr_total = 0; unsigned long nbits = cma_bitmap_maxno(cma); + unsigned long flags; - mutex_lock(&cma->lock); + spin_lock_irqsave(&cma->lock, flags); pr_info("number of available pages: "); for (;;) { next_zero_bit = find_next_zero_bit(cma->bitmap, nbits, start); @@ -407,7 +408,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_irqrestore(&cma->lock, flags); } #else static inline void cma_debug_show_areas(struct cma *cma) { } @@ -430,6 +431,7 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, unsigned long pfn = -1; unsigned long start = 0; unsigned long bitmap_maxno, bitmap_no, bitmap_count; + unsigned long flags; size_t i; struct page *page = NULL; int ret = -ENOMEM; @@ -454,12 +456,12 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, goto out; for (;;) { - mutex_lock(&cma->lock); + spin_lock_irqsave(&cma->lock, flags); 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_irqrestore(&cma->lock, flags); break; } bitmap_set(cma->bitmap, bitmap_no, bitmap_count); @@ -468,7 +470,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_irqrestore(&cma->lock, flags); 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..6379cfbfd568 100644 --- a/mm/cma_debug.c +++ b/mm/cma_debug.c @@ -35,11 +35,12 @@ static int cma_used_get(void *data, u64 *val) { struct cma *cma = data; unsigned long used; + unsigned long flags; - mutex_lock(&cma->lock); + spin_lock_irqsave(&cma->lock, flags); /* pages counter is smaller than sizeof(int) */ used = bitmap_weight(cma->bitmap, (int)cma_bitmap_maxno(cma)); - mutex_unlock(&cma->lock); + spin_unlock_irqrestore(&cma->lock, flags); *val = (u64)used << cma->order_per_bit; return 0; @@ -52,8 +53,9 @@ static int cma_maxchunk_get(void *data, u64 *val) unsigned long maxchunk = 0; unsigned long start, end = 0; unsigned long bitmap_maxno = cma_bitmap_maxno(cma); + unsigned long flags; - mutex_lock(&cma->lock); + spin_lock_irqsave(&cma->lock, flags); for (;;) { start = find_next_zero_bit(cma->bitmap, bitmap_maxno, end); if (start >= bitmap_maxno) @@ -61,7 +63,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_irqrestore(&cma->lock, flags); *val = (u64)maxchunk << cma->order_per_bit; return 0; From patchwork Mon Mar 29 23:23:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12171177 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 37D66C433DB for ; Mon, 29 Mar 2021 23:24:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D563761996 for ; Mon, 29 Mar 2021 23:24:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D563761996 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 EB0CD6B0082; Mon, 29 Mar 2021 19:24:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B9E436B0085; Mon, 29 Mar 2021 19:24:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F70E6B0081; Mon, 29 Mar 2021 19:24:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0182.hostedemail.com [216.40.44.182]) by kanga.kvack.org (Postfix) with ESMTP id 419A16B0082 for ; Mon, 29 Mar 2021 19:24:41 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id E83D04DCF for ; Mon, 29 Mar 2021 23:24:40 +0000 (UTC) X-FDA: 77974493520.23.5F324A6 Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) by imf18.hostedemail.com (Postfix) with ESMTP id 9B8562000254 for ; Mon, 29 Mar 2021 23:24:40 +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 12TNOK3s074256; Mon, 29 Mar 2021 23:24:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=l1MGVnvXX5XZLTEdq/dQIWxlrE3poh+6I2f5BNcsii4=; b=uIHiavUBmeKuOAlCmHZqhvUCgqEk65uH0DVTNDK1Vn3ChgQiO3JIq3ndhPKAjkwuQ3Fe wpnAXEj/poPWszozq5LP+fteYwk2JjWzK8F7uVpsQRNGUdCECJSe3wbf/YgvXjLsJvDk adxn2iQevIadVR36imVl/YpYu9BRzz+ZtBmpJus+gu71XzjyAFG63y3gBo/Fy5f+cly2 Jvq8e3DalCgD0HiXKmVvNUut8jbp5X+J4w34FmVHTFZsMythdc2JqmkqlmDC7bKEOW3x 5nOczE6oGz8ObbDz220pC102Z2wxVSEjAjABZgTQGCNPAqe4ucL9HdQe4QZY35447m/q Iw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 37hwbnd6tx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Mar 2021 23:24:23 +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 12TNEmAx088315; Mon, 29 Mar 2021 23:24:22 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2176.outbound.protection.outlook.com [104.47.59.176]) by aserp3020.oracle.com with ESMTP id 37jekxsr9s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Mar 2021 23:24:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eaVPK3Lel/jzpUmXy83SnPGXXiRDmWlEE99HnsiaKf1oqsQfriZBHzwRbQokjmeb51gA6SwiVnmlZFXhVNIbTWmIc6r8HWCgMvvkdZgu9f+yTT2Fvq8B8kEHvRYaqpTkI5uXl6CFu/NnHau4fGC5N7nIqsu08tlOLnUhbPS1YBzt1+qBtpU4hFCpMKeqGSotJxnJVLKW3TQDsvD9xeneTb7ajtQMqfGFWjVDIuOdkiixFfTbocLfQ9WtDOOeAaULkn9zS692z+b4qOnuTGEG2al2NZk+5mKul0JKkFxqX1fL513hqYqVgjAKQontLPc48yvIzgy8HYk8Us65muXUQQ== 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=l1MGVnvXX5XZLTEdq/dQIWxlrE3poh+6I2f5BNcsii4=; b=fONDyymA3JT4mCHgGmsm75qmSuH3Psx6jGEH7s92LcgGD7am3lPvw2hsd46bPJX9xSi/S3FoeIrTvlCcUDsFyctwUDUFrhnWaZq+b10ybqv/c4vb04duN+AHxaEioxTm7tmsJjORVcW8Wx2qhK64znU+XfCWwxhKD1HAc/83BPpv2BHYWdSM5XhYnyrK6NsxoJVwERzMSHolee96LS0IhElFzqDLVQ2cA6bCHq7wtmbTjCEhaH0jcgkYsFVrL7Igl2jXvTGh8jdOrKFQTNXiYZHpx7VyPJp3rzFg7YOpZyNhYN0K1bMCOhAXMWE7XzomByJN3j2Dl4JmUxYZ2zu+pQ== 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=l1MGVnvXX5XZLTEdq/dQIWxlrE3poh+6I2f5BNcsii4=; b=kWwncddqXQoZWQLsWiyL/wBglKhe3ZZYlnerFMySroiPiCaZNbUUlkdwZtj1duf7+rvGA8YC/PlyUJTHsdEQwoj45Ll5EKrVppeGpwaRg2rwnFpSbtgV9EGa/12oxEWUk09+Phrjp5Z/mzXn4Z0ZNhouF+SBpAOdIK1oeWNAh0Y= 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 BY5PR10MB4148.namprd10.prod.outlook.com (2603:10b6:a03:211::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25; Mon, 29 Mar 2021 23:24:20 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee%8]) with mapi id 15.20.3977.033; Mon, 29 Mar 2021 23:24:20 +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 v2 2/8] hugetlb: no need to drop hugetlb_lock to call cma_release Date: Mon, 29 Mar 2021 16:23:56 -0700 Message-Id: <20210329232402.575396-3-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210329232402.575396-1-mike.kravetz@oracle.com> References: <20210329232402.575396-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: MWHPR10CA0065.namprd10.prod.outlook.com (2603:10b6:300:2c::27) 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 MWHPR10CA0065.namprd10.prod.outlook.com (2603:10b6:300:2c::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Mon, 29 Mar 2021 23:24:19 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 368e27ce-c047-4a42-cbd4-08d8f309c7be X-MS-TrafficTypeDiagnostic: BY5PR10MB4148: 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: s8FJa9kgKwidrG/8eR+gcO+oOGscanrAjo3YLk9neddh2u09XxOE/hIEO6hwShModqlB+L7vKGbWR2UMSChpM+jmqNaCLrMCEOEFFGAstD8vWSStrcnwois+aIq8OR8jZhAIApeV/4t/erk5Ho16je0KhrmLb9Ri5QazC/xuEjL2bDJ6SC0u5Z2JWYPx2j1vnVuNh9Di1iCV8foe5N9j4QjFw20ZVJ+m+5lkG8FoOoSWyXE/9ILwFsz8xcTRXXn/sRDaYD7nZDF552BKcR5G1MKsCnDtFvsQxvJ147gS3abazBD5A0nYDTr0znEfNW0OmFs54IjOmMYtmfT9K6ViZo3h6DODz6q6nzYiiBrfvrHnab0kS9wyORfgfCvcN6+ZN2cQJaNspsXHCfBs4bbB0060CGWxEJW9Cw3vLKhIMXVCQzbiWUp2oiRzUKS3n0dV6A104Fqp0fdP6mqTlVLn8OITu8VX4jZ8NTGcVBmD93mwkrH+rHuiWeZsXMK54A6R1FUq/RduPetTIy8DOViruNnfAY/Z++HYU/dtHrYyYlUJUGA3QtzM9zif8vf60hNfXmqeGNdMSVtayLCUoop5yQZln8d65wEPi+IiuSsZk+M9++4AvydUPOCOIHuI6orWEAEmcn8BNUO50BDZcX34WA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(376002)(366004)(346002)(136003)(396003)(39860400002)(16526019)(44832011)(52116002)(26005)(2616005)(36756003)(186003)(7696005)(7416002)(956004)(478600001)(4326008)(6486002)(54906003)(6666004)(86362001)(5660300002)(66946007)(66556008)(1076003)(4744005)(66476007)(83380400001)(38100700001)(8676002)(316002)(8936002)(2906002)(107886003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: PYEke/HQphU4VhSHbPr419OVppvRl5PmOw95hXzlC+YLmRsgtqPikmUivV2xEefTgZ9LD1Dq6YdlJ5UjgaXZBgvSSPlnf5KUP+DU+TrRGznZnW4zANZcPzzBRJAyXx90r44cxICtLXkmHrj9t3Qw6jrT5rGyXdVdjPU54PMA+kQmUw7UawwicA7uYrefAZkrwsNQ/ef3hOP6mxFL+oLV5KVu9ayc6/ZAUye0SY2d+b4l4lEYoFNARVC4LxpO6L2LPmYwlh09TJm8us/BPiRK1ETOtRLcqHduLVXYiP5WAHYCUrpJtDgT1fvks9VU75MrdDNpq+BaX+ZTKkQLRCFEBqDT4vPWWQetWEXmHW7RmqdUPD7s/y1oWCK4NOWpF07WspzdCW52qvcpO3l5xJeGiY5O7wJ8szLdcvy4S4NhOAQ+uFZCwIRyC1Q3ZbNIqejVZ57bc8ehcBNX9G1vXE8VTrl4Oxda25yHzTdlVgGSnmE4cFMqGSTHmHGGFRU4KWGjEqYM2B9unQIc4DPiBz+WWO1nhiOqty6Kmyv246Ty+RKvTeH0r89a0lpzhzW+waAOEBZUcfxE2afpT6nyD9nog5md2hjxsmBJxODItJnDCBw4KSJIHVsNlmVeV2lvTKoEc0FWJFoAzt6hRnj89sfo7lPlPuhHY5x64vE44euefm+jdxuRQfoZs4WV1lM6xGBbvj0GVIgxyY3Z2eQD7KI8lOh90ewfVxg+LCqGsL/Snl5VziUuoj3S+qQWgZmcdBpDkhEoHfh7b9T61arI5aMuL+FLF8IZlbdy7TeQrkAr4eek5MzfS7PT+IBfoB1E/pCLkir1F7WM3f7TIeCDeM1AcpNplqW4DhTYKcB19fde6hksY5F8mPYLc5BeFUs7L/ZhvgIEEMJwpStlVoKhDE9nksvsRzLw3FHiH/QehSoH8O8XZbt0TTQffurDls9aEPSyDq/Pj8XO9IOmwoalz4i8/UueRXvRwBAwrlRdxhiucNvy7fblSwjOq4bZW1X4bWk610NSTr0RgbGzq69VE1gO08sMw++bHBFh0QohAb4x8+el3alu1pegxg2h3NiPggqCbmqJvA3iF8wAhAjr3rgEXeQgG0bb6ukfk8IRUZbEji4x/JXkgRlnGrSRP95Eyd4haocXbijcP2Sm7jK0mz+oOvp+dkHWxdagJ46J2wvRrLLdUtP/xnj5/AJjtZOj7JoC3S6xbto7UYtuNVzOzs8dLOAiVOpzZ+HscVkjggUDaNCU8p9IlF533TM1Ed/8SdcYVmiiKo78BnUxjSd+D+yZNQwyRbalNK25+aYLFqt3nzAaizWhOAhdwU1AzBdIxwQM X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 368e27ce-c047-4a42-cbd4-08d8f309c7be X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2021 23:24:20.6411 (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: UhWYsA2ZT7xXWxHBPhclqrpKw00b4SgIV2mbikpzi/+TMko6+x7Cp+CXaVoZI8W8IXcde5iKzIWTyoWVLtyySg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4148 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9938 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 mlxscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103250000 definitions=main-2103290173 X-Proofpoint-GUID: rYtRNA97Q4qVHxkxfj7CUsMR25DaKGHx X-Proofpoint-ORIG-GUID: rYtRNA97Q4qVHxkxfj7CUsMR25DaKGHx X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9938 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 clxscore=1015 phishscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 spamscore=0 bulkscore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103250000 definitions=main-2103290174 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 9B8562000254 X-Stat-Signature: fj5jpgx48oq8it83ktk98nprwhau18eu Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf18; identity=mailfrom; envelope-from=""; helo=userp2120.oracle.com; client-ip=156.151.31.85 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617060280-464557 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 Mon Mar 29 23:23:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12171173 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 881E0C433C1 for ; Mon, 29 Mar 2021 23:24:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0A3ED6196C for ; Mon, 29 Mar 2021 23:24:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0A3ED6196C 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 983226B0080; Mon, 29 Mar 2021 19:24:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BBBA6B0082; Mon, 29 Mar 2021 19:24:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5FCCA6B0085; Mon, 29 Mar 2021 19:24:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0251.hostedemail.com [216.40.44.251]) by kanga.kvack.org (Postfix) with ESMTP id 3A25D6B0080 for ; Mon, 29 Mar 2021 19:24:41 -0400 (EDT) Received: from smtpin36.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id EFFE3180AD811 for ; Mon, 29 Mar 2021 23:24:40 +0000 (UTC) X-FDA: 77974493520.36.7A12D4E Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) by imf29.hostedemail.com (Postfix) with ESMTP id 0E552139 for ; Mon, 29 Mar 2021 23:24:37 +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 12TNIgsS153715; Mon, 29 Mar 2021 23:24:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=JI7Wa5vF5HhieQjdC46n81VLuOajTHtMNYL9ERUe/90=; b=z6+cnEmXG95XLymHMIPakoOFTiUkJ8Ki1Z6KL+nISJWRfOKILweyXhPOZ0/gQDI7aygU Y00N1g6Kr+q1Nqj87+qC+In3JWYiG067XGhp9wGC+WsNSibFTnq5jRJeOSndafe67JB2 H/+Bk3FQ3Duc3557h81hCFWrkasKv2N1623sRnIbGwf9ch9tA4TAvhwdjjrWuC78mu4a MzLzgMkfBdtq7w/MwTRa8xqEufr0rKK9o1LaaPj3ytPAxAUSwhJzi108SpAgUNga1es1 2tmZPQMMRqYTr9zFlFhQcgdOpd3+H3C8m7AEaC/kmto1uHip6KDt4Ye1OCetBt0EVhZc 2g== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2130.oracle.com with ESMTP id 37ht7bdbr9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Mar 2021 23:24:25 +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 12TNFYqE055827; Mon, 29 Mar 2021 23:24:25 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2170.outbound.protection.outlook.com [104.47.59.170]) by aserp3030.oracle.com with ESMTP id 37je9p06pp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Mar 2021 23:24:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q4mPw4OfmrzzsvIIOQ7aSfkz7xtFawgOAtyR/3L2nYmTOTZuUwUC7U1JSJ3bQnTNSFJ4BBQylv0v76uVXheFgLrEgNC8J4NcD34EAVjxBUN8spSBYHDOZa5/GQP8yVhD0u0wozlFU7tR3NxaS2ffaGBTjBOtOVsUMvDWaAAHDexke6k9UjrK0tSYETSBkm14qv6XPck7D0DxKOMx2Jn64GzrM9zMpbFX1AKwTs+R2gGiKOm8Ah4578FSM/7sGn+9RrcU5x6z60yu/r0PVY/XyalUIGR2dYPqI+cVPBamek0yE2C/vcTpHDvkJDfNlO4GzY/EYl0PqitqRhv9WsKmNw== 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=JI7Wa5vF5HhieQjdC46n81VLuOajTHtMNYL9ERUe/90=; b=XgXTY8kgYEPQLq7KXdiPMOFByz+bi1cWp1WtDfwxr7nHmzIZIqZH1jTzHoORVuyTOGww8y6yKQg1Cq0zovaMMsI30Hy8yZxFxih4dNGEbUfqx1em1axsEKr0bG+RNetMrxhSO9dKKnL924MGb7dk7k/jn6K0mUKzw1aHDH5VO6fVvgMTiqGkSbWUjU6cCZ8XdmTBJcKo6KPrBCagB9/2INXcAaTNGzvqFgSGygwCqDKrB30a2A3RnGdF9KUUCDTkuXtwHoFJiCwFL+YsqAkzEq3617n9tVgJWznASTT58RuajFle3BbF6iE6KUFHlws7rQA2QpV6kZIBNkP7ASU7Aw== 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=JI7Wa5vF5HhieQjdC46n81VLuOajTHtMNYL9ERUe/90=; b=duu8BKVc8fggFotz51sUrOpdHvLeda8S7yrurG/Nh1k0U1XKf6xytg2aLtSMAN+H5DBTxjQnmIdfijyDQ0Rdiln4qhjJzlKXpZ4UNo+H+opgoJo2ecFJ7Xp00evZ4SLbypICmXf6ctyQYVyKaSwOVco8ZrXoTZem3ypenzLQy0g= 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 BY5PR10MB4148.namprd10.prod.outlook.com (2603:10b6:a03:211::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25; Mon, 29 Mar 2021 23:24:23 +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; Mon, 29 Mar 2021 23:24:23 +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 v2 3/8] hugetlb: add per-hstate mutex to synchronize user adjustments Date: Mon, 29 Mar 2021 16:23:57 -0700 Message-Id: <20210329232402.575396-4-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210329232402.575396-1-mike.kravetz@oracle.com> References: <20210329232402.575396-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: MWHPR10CA0065.namprd10.prod.outlook.com (2603:10b6:300:2c::27) 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 MWHPR10CA0065.namprd10.prod.outlook.com (2603:10b6:300:2c::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Mon, 29 Mar 2021 23:24:22 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8dfa1fc8-b901-42dd-0102-08d8f309c93f X-MS-TrafficTypeDiagnostic: BY5PR10MB4148: 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: cXKXOH/vwrFvaQYNXm6aI0yf1juFoMS87Jh8n3OXQhasg/rduzUMqWdYy81oUbNUFrNRYy+RufsqELEY9RMrLHgJHFiw/2/aTjwx0pXGfjeoQI7tPL5R7RfRuXIIlP8CSDi8d95u56KLc+qEPMDgz5X9vJgkulbAU2e8in1420UzcSrdQDwsYqT+W82apR11Z2SscsKrsyKYOTsUo9tyqbKobSZqOn2al89GdyYXk1P/sqSBHelaQTf7W2yxxazTI9HyXX4ygwPa2eROnM3BoNFuyixsZaJD+D/TJiG4Ijoi2SvjkilGEHncP0NHV/5CERkquLFlstcwD9Cc4USXTCW8QLYiAjnCWLUdnyyexhUshzRPzZdwfKPv8Fc3fWa8+dB79pBMf0iJic2WqFl2djDR/gWAD2FutUgR4x3UPnjoarg1sZjrYW8h04xkYkHGYcFYkcJ1GhID2s398la5ondSVpr15ahU0A2WwjBdhuxbOODYNB3AjBzAomuC3rXwhVcLy8cZxnqkjQ3esO1xLOiA87b2gRZQftv/OV+wXgqhn2W/m5BQ7+BHP/SQfwzooj/KGT2FEuhTQoSO06x3SA8RwDFb4jFc0C2PBJ07FNYKmfZFLgdDBzDrRd5DCoSKu+uaAlijjfruz34c1Xlpyw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(376002)(366004)(346002)(136003)(396003)(39860400002)(16526019)(44832011)(52116002)(26005)(2616005)(36756003)(186003)(7696005)(7416002)(956004)(478600001)(4326008)(6486002)(54906003)(6666004)(86362001)(5660300002)(66946007)(66556008)(1076003)(66476007)(83380400001)(38100700001)(8676002)(316002)(8936002)(2906002)(107886003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: rXGBWcIcDTblO4PxC3sXDxBdIfL1BjHCaooPf/gsZJJq5DF7F8RSJOpB0Q8ZCsPfUKdTDwAmgrguvxA7ONJL8SGK/7Tq1kZYu3Xp2FlkQa6Jy3luv15ayy15WIyboR6fzjK7bJS5Xtmca7eDQiX+ZeNoRo8m3vIQ5uUOooyR+8skx357IAFj//Qv/FUhK8coLPof6qW/iS5BtjHIByJpZVP8q47TZYsWI+0qdaxYSU0ePbTRHpP7HQB7yiDK3lVJfCR5Hkw9v5ADW8VDTJ1SD7eju5MmKkZ5/RLbgZzrA2d7auswPu/E6gOSjHMT8E7EXMHiEsjnSgh0uC5CklcKYPVSxEW22GCfVBaXVMa/PunzBAHDzUo35kWIpvqGCzxDUXNQl1yjk+DCztcATcAGKqi2AyTVnlG2IImZcAUz4PT8U7mLU3QtZH8LIVmKaEwa9A5oQnJF3atSa+/85v1FBRuBB9fqHTx4Guuxfm5Moq5Mdq50LJZ1fa6EZOk1bk5WPW00HAVbSqqRcC15xyi66EnlBJwxva96V8ePkKlkHbJmqkdPfkF2xwa0BLt1NYV8DrmPHytDJenz6Wydzkfwemo79pCQJPf4gg7LZc6M/beMzUnx8YDYuniDc1tswLK3tOQlXXKsDCaLx/7YLymYyoGK26GzXlMxIOu/z0GD9oYj0AwppY3JLAiASuLsuKNLXIgQdg/+3ns4pziuE8RDQMj1nB9yAlzp189Q0q88gbNsEUmkXF8Pq38HB9jwVHPXw52201orMvb6r7BmtqJuOskE4qof+j3A0zLjhLpj0qpB9LQLxj3ZFPJfK1W5Qxqz1HtQbSJ/evIrpWfKzuLrwd3a7yyUdgrUqXKaXxt6IpducP1f9JeWFHBm3tErLoMbdX479hKqjRKXiISacmYmCChcP4XCONSdqMq9+zkoCZIURcoo3rfDAeSUMmO6WPloczjDxo16u9YUExB4+Xth9cKCb5FTtqvMvMZ5w5Up+G/go0H6M1aEemvak1PFqDxdEy/PQj5Rbk+TjfD5eIAChSD9u2JY1oasMuN7CNoCfcaiv4P5irHy3XmDKCnSZ5qgTlIfXpvNoVCer4G+q3LkL0iokgvgO2ZmdhseJfLfmedBZKjQ3dz9M81nz6fz7QsQO7d+S2sROSjaufFLEgsSIHKl2VOwPm/Ua9TF6YIe4LBK8j6jEQ09vPch6BONDSAWjXyF//juWJSfPVQL2GB7ErbNeoMGhqdl00sZeQAL1RSsgWiPY+BXRx44L++djrg8ZpXFqRr2ewK3oZ03ynVVbT2mJ+MfYgDL5qD0kvFXgv+D+Jah4elW18hcUD74v2a4 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8dfa1fc8-b901-42dd-0102-08d8f309c93f X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2021 23:24:23.0316 (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: piVkJ78VzyTfUIIcKNVeobUqfD6vxROif7NgfNf6Rh+ZWeM0zZPjM91UUSbz124EIB8xfSVqvAyuoEHY6/+HPQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4148 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9938 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 adultscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103250000 definitions=main-2103290173 X-Proofpoint-GUID: MwgaKWK70ae5Xy4aL-GrqhpjvWplNn4v X-Proofpoint-ORIG-GUID: MwgaKWK70ae5Xy4aL-GrqhpjvWplNn4v X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9938 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 spamscore=0 clxscore=1015 mlxscore=0 bulkscore=0 priorityscore=1501 adultscore=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103250000 definitions=main-2103290173 X-Rspamd-Queue-Id: 0E552139 X-Stat-Signature: qs8bnko6tkykkjzy9uk99ryiwproikmh X-Rspamd-Server: rspam02 Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf29; identity=mailfrom; envelope-from=""; helo=aserp2130.oracle.com; client-ip=141.146.126.79 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617060277-549965 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 Mon Mar 29 23:23:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12171179 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 26736C433C1 for ; Mon, 29 Mar 2021 23:24:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BB22761996 for ; Mon, 29 Mar 2021 23:24:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BB22761996 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 33DD36B0083; Mon, 29 Mar 2021 19:24:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 315D26B0085; Mon, 29 Mar 2021 19:24:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 11B5D6B0087; Mon, 29 Mar 2021 19:24:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0091.hostedemail.com [216.40.44.91]) by kanga.kvack.org (Postfix) with ESMTP id DB05C6B0083 for ; Mon, 29 Mar 2021 19:24:43 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9F359582C for ; Mon, 29 Mar 2021 23:24:43 +0000 (UTC) X-FDA: 77974493646.27.8AED25F Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) by imf24.hostedemail.com (Postfix) with ESMTP id 7A081A0009E7 for ; Mon, 29 Mar 2021 23:24:39 +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 12TNOK3t074256; Mon, 29 Mar 2021 23:24:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=7XROPzrFGkucbYlToRA9exFdiYfTr5yDZyzXfAg591c=; b=PPBBh2j9x4k8mx5oPxIq3oNUxiZ2iAn3hHlDEHMb24DC98Gc99djBmCgfo/HW+t5yqk+ sTDGWG94HwHUqeRFI4eCyCyseNbYrJR/yzuY1KG+S6gkwfwr1Usujto4O4aFtbWFZe1f dQr+Z8xZU+JJuQuH8v3Qw7s+TyAv4KP8s58n271TSJVwtIayp6h+OnRoW6pt2bkMkSn5 RjPPOJQW9PKCfb6DYXzy0oDNoErNIk35y/VGSozVlKPszfLm5c1z64U8YqUd+ezakfOX 7ZTZEpOKxIkWk8o6i8JvHgiUDvgxKR4pSxlE09Q5RKxIfwvALCYkdhlWTJlJkCgzhVle UQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 37hwbnd6u2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Mar 2021 23:24:28 +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 12TNFZJu055929; Mon, 29 Mar 2021 23:24:28 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2173.outbound.protection.outlook.com [104.47.59.173]) by aserp3030.oracle.com with ESMTP id 37je9p06qp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Mar 2021 23:24:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c4LRGL0SEtx/wleB74x0VRos97AuABxr6X9aDXNTSUvi3kxoxhuku6TnK0YkzA6DvrqMkAlh1Zy5xUFS+Gd1BWpqyUY9xuvrgSjth0p+PRkI8a8K6yMizFXdWYhRhyn0In4gj1u6djwRmwvl8vqFD4IFeaalswZr6NszBq188rWAALLNdvcV8ldcrVA1z4N3hAOrAP+GMGd3J1qtIeSJUcBDeCIsaSIJR3ngKtNV/xUjTSWIRYowhJjGdIvE6DraNdkQTei6cE4NIfLtHkY9GDVmf3uFpayqZSWhXun5CuyAFclSEbRILJtU8sTcvTNMomh3h7O+mB+w0J0TYLRBWQ== 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=jpq2SH6EhxJuCkLNv2z6gPVg0Ra8EYwyyD0bsGzbf+nLfZYd9Fih5lLd0ZGDBN9wQ+LVwXubHgeMS4cX4wQZifO0dd7N2SZ44Qf35exrcJ7VSpYr1XhwdEXNLKvqzkXdZ0jT43qdPTltzftlKFuQIrt8lvVR74+FP0/hoJLLPxfZP6wpqNLZiNgD/S+pjCfO0bGXPSkhDmbHcTvX20KD/peUYM95CT1XeHlknZrwtvKS0r+0X9NY8OxMS6faknd6+m4B1irtNXBNo8iYiRXrHGdXkSM2QhtlqN2VHeLIOtyCFwHz6Jxy97BGAU+hnWB4yLcTlw0hc5NlidOfsAittQ== 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=egdKsq3K/b4olq8A1PzaauMabunvWoEEpeBr4yiVGuxBq0Hne7RdbgKQ76GN9ZgjKRFqcBxO28bem6dPHSmYBQ8vX9YRW/+iSgUXgKyJqodrtUaOGzLQ+Dj69Rp9VXSoCU59oTFy2iiEnMFtFPVcR/ML046e2j80S6Z/erWF9VY= 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 BY5PR10MB4148.namprd10.prod.outlook.com (2603:10b6:a03:211::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25; Mon, 29 Mar 2021 23:24:25 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee%8]) with mapi id 15.20.3977.033; Mon, 29 Mar 2021 23:24:25 +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 v2 4/8] hugetlb: create remove_hugetlb_page() to separate functionality Date: Mon, 29 Mar 2021 16:23:58 -0700 Message-Id: <20210329232402.575396-5-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210329232402.575396-1-mike.kravetz@oracle.com> References: <20210329232402.575396-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: MWHPR10CA0065.namprd10.prod.outlook.com (2603:10b6:300:2c::27) 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 MWHPR10CA0065.namprd10.prod.outlook.com (2603:10b6:300:2c::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Mon, 29 Mar 2021 23:24:24 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b4487722-d170-4fb7-1a04-08d8f309ca7f X-MS-TrafficTypeDiagnostic: BY5PR10MB4148: 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: 0+6keLxO2TBAhIt8seV9spWKEQTzBuMRpp3KI6LsP2nqAmW5lLXRAVNoG6YoliYce8zCNSiGD/9sKVtPjV9EjPboPs/JUOakf8F7LuGfOKoExyEyMCI0b35ii0P9BZZrvJTvfxyornPcrlZ/I0qjG+1HkfEACyR0X+30TaJ+yvennqrKJoZP0VkfVJLtUfNvgjQWCv11MgwJUIRkKfIJz4BetSR0GAjYxJoHOUYwrOE5poCUH1BaJIvaXpU+q7jFZ2j62y1lkLCY6TTkzRpgoxCj03un+aY0EU2eXV0DDsDO1QfrLhCZjBORYmelP3I3I7Bfei8nSsceVJe0cOG83FPbu52d03MbEvgLtOm1bR7c+uIr47u9Gx0MiiDSVCmtQp+KJM8i8ma+qTrgo1XoWFIh9mNIy+yoAzbohBWx8LwZSvEYoqnpTCUR9Ro0XASn4E7vh5O2nVmahQfPCt/6lci6BGOMfQurRh9a66aKraRtF10d1Z4zTn9tljYKs70Ow5GEVeZgMIePoOKdW9XoV2Jvzq0QGNFgcGm5pbOMoljffve0Yt2gO4ZY6ZlvtEb9GCKqHkvG3JiMEWG8HCKA/5+ouASQKgjFJYV5QIgxqGsy5ZMlWQa9f0utPPmAJx+hpxKYW1HB9xnplTRpIQ060Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(376002)(366004)(346002)(136003)(396003)(39860400002)(16526019)(44832011)(52116002)(26005)(2616005)(36756003)(186003)(7696005)(7416002)(956004)(478600001)(4326008)(6486002)(54906003)(6666004)(86362001)(5660300002)(66946007)(66556008)(1076003)(66476007)(83380400001)(38100700001)(8676002)(316002)(8936002)(2906002)(107886003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: e6IEW3uxjbZR1ahTMdXuEJd0OBkxz06HAiv6Sg+cOoScS2J7ClNtfMNEQiMVud/oOZerUfEfhvDV5ej+zduPMpJbv0zIlns93XhDJgfevF8YFJ6dR48lFsZcPEElvItbQIk1P5mknWgH2G4M/XZSkkUcjyxHf84B3gMm63VV/zBfEZf8yIhO9Xwxa4gRYfROtHeAKh5YjYVVLX5sYWTjgZGHR/gjUqgngNbSd3fRbkwZzJLReIU6ABjPwaTck8tX1wMz5I4Lqs85dDmfx0Q+dgzU6icZR5CSYG6gBFXzbsbgoFQ8WxmDeFLVN9dIrme/dH2GyNcfsfjtTSrG4H1OqiCXMY0nyx2ko1Vr2Dz8n5z1MUqn/E19JruU/J2Vlp++Dm1kSeLk5HeSnf4RqNdpOCViupxR6iBFcK2KO40dFDTRYEiDjngGF9pX9wjFLh7FVCfdQjz/ugXRxU+sad4cGLkMp0Wvbkrm0NbrpeUDVdktU9O0vj5YQ2GJqiXF9mckzZeW6bhkvhv2YXc/zHCWUOVTEfnvNb8uYVC1G+sViLg6d3sHItyLyW7hKd64kinkWiUVLIXo28m7mfKOvflSNlkWoo3jZTJ03IYFFXjujcKAO9dGlk8Li0FdSF3icaMd7G1Dqd0NOyNJDZ4Vwm85CPSPXo3Ig47PcSzf+4LtrlbKi6mOgHzP/LUo4MtKmkgi9fOTNv7guTNg0iwNBGukm54nrrtQZkL4d9yrsHi+/4wM4yZ2HmOpFXeOl97FUvBMEdJqu3dwKbjlqmxUUT7Gra6QkPYawVAphwJaN0xK5VlomZX+XUaTWCBsWD+58pCeg4dKQ1qvh0QKVoeSaozdCm8y0Tr2OCu5XSzlLSq/Zix+1H6JhKb9uQd/BSmlUvQ/Gs2bvQuZmPdHeylXrevW1/vE5FAN4tkOsu4r38SoBeXgsZJTFoYqU5PKCA69+Zg5axo6zJZ3V2RoTSlfRUWndFZ/xIAFssXhVkAUfn3RfRjpjiHFUQaylnVepwE61wa/Q2aY268fX5UOiM1oDZy07AM7KIj7YxANysHJxcpmoeWX+gpqBkFXWouK5LodZ7O0vC8Rxiqy9ZcPBSM4wljmpcCBRMeWLFeHaQKeeegBNA6i15Bfxp+IkeLCpC8roxisEVaRlUltwHUqhVO9Pj/xQ4Tbzf0d0pX2EyJkXncieQY5zaE+bArIHFHOtopVTwda1XVRnqHq2VlG6TFLLQpq524LpIUnXe3Ud0tyzXAwj9JxUP0PxcQbaUEBxqLap3cA7zKxRi3KjfnrTwuc8ZaltVYA1Ilj6pDIJjXMdHdtZ3mTrIr4OYeoXGAhFsM+jpcU X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b4487722-d170-4fb7-1a04-08d8f309ca7f X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2021 23:24:25.1881 (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: frHFy/+U4/o2wn1ydhjhD64UKAh4ahgXEgZvpnipI/AMw1tKYezYRV6oH/TuGuo7Dkfzi7Ml4rHqaoJkduGq0Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4148 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9938 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 adultscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103250000 definitions=main-2103290173 X-Proofpoint-GUID: MjWLei6ZqedJkNYUHb27k5wPeRLtEti- X-Proofpoint-ORIG-GUID: MjWLei6ZqedJkNYUHb27k5wPeRLtEti- X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9938 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 clxscore=1015 phishscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 spamscore=0 bulkscore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103250000 definitions=main-2103290174 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 7A081A0009E7 X-Stat-Signature: o1r7mwzrwmz9gqj47kxk93959kmqfzmd Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf24; identity=mailfrom; envelope-from=""; helo=userp2120.oracle.com; client-ip=156.151.31.85 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617060279-41877 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 Mon Mar 29 23:23:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12171181 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 1F93EC433DB for ; Mon, 29 Mar 2021 23:24:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B972961990 for ; Mon, 29 Mar 2021 23:24:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B972961990 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 E60CF6B0085; Mon, 29 Mar 2021 19:24:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E119B6B0087; Mon, 29 Mar 2021 19:24:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC7F36B0088; Mon, 29 Mar 2021 19:24:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0211.hostedemail.com [216.40.44.211]) by kanga.kvack.org (Postfix) with ESMTP id 963486B0085 for ; Mon, 29 Mar 2021 19:24:44 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 5B926180AD811 for ; Mon, 29 Mar 2021 23:24:44 +0000 (UTC) X-FDA: 77974493688.09.51BBE25 Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by imf05.hostedemail.com (Postfix) with ESMTP id 574D0E0011C9 for ; Mon, 29 Mar 2021 23:24:43 +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 12TNOJ2n060855; Mon, 29 Mar 2021 23:24:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=chtyvAs784yyPCikCs1YAicr9bFeuv2v541t7rOIifA=; b=DAX7T3m10vMIIp9CjisZagIXvOX5tsFH416xyWu8+y4EoLfhtPFJMw1w8tga3FKAmnZ/ XAOyfocQwrSRKhPDmBOGEYhNBJ5snviON9a4dpeOBKsncTIaVVx+aTMjTs/a+DbZPwJ6 jS21VNO8/QyVy5K6dvv1f/25VTC6bFEWgO/xwFi8EX6aBy7rMC4IHxOrtHeTEJ/WX9xw OuRpm54cF1EE5IFChkzwhWt5IcA31TjFSEVVHmZETO+eVCx+mGjMkDetHfK2LgT+UXr8 wCYl+VskRtlYPZKNnSSjVPpQ7LARAOC3cAvizqzTPZJfGy8PL2tCujD5D8/Ary1HoWwg 6A== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 37hvnm57xg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Mar 2021 23:24:29 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 12TNFZJv055929; Mon, 29 Mar 2021 23:24:28 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2173.outbound.protection.outlook.com [104.47.59.173]) by aserp3030.oracle.com with ESMTP id 37je9p06qp-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Mar 2021 23:24:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HBFG8z0Q2d2fRHnGJTA8afuX2jWp0mDNCLiA594PELo+LFUtUmOSli3enhcGamTArxySCIHRsR+KmnkzJJ5gsJ5F6rkwYoEGK8mhw1z3Li0HaCeGrKywNtZsOXefMFbBnm0zc3nEOpv5+nZXfSBnyYNaGxHXeHOl2fBqWo/0Tg+0vHPLkmUr1B4DW6D9OO1YTNcuw5Ai0+1NgRZQcEW3FKU0D1DnOem9w2vwpYtK3C/TdYC7+ugM+mkv7nOyPO48lbYJ60L+4lQ+BcW7oatSHv5Fg9NvAe2WI67urcrzQ1auqp22bau7VcqIiyxvOaYZht44z0HRrjD1OYi4sjSgXg== 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=chtyvAs784yyPCikCs1YAicr9bFeuv2v541t7rOIifA=; b=T8GdXYJwKR0QMaBRDdvtPxrCWdypdKVHQwSCwfUZhNw/Kd3nD0/J7SfMA0ZnQ5K6uYIwR1hdyCDjwBFfIkCuTQvNPAGW5l25MfGeSVT3bA09uF0GEmpmTwSDFYpc377EOc1q+XM/s8sFLxMyFVX+ktwGtDjQILrBCInQyPVh2x7eCCYyZxjpU/2HnxlDfbiAeeHZXUH/Alz0D+Y6yxXKvR9owuDUiBJS7pvFF5lu/YwaxLbDURbqG//10q4eCNdC3VcKocLDZ22J++tA2EWDVJB3vnSvQ4AzcUFN9yoancX4brfQhYPDu0cZ5k1R95UEaDrCPcftIAeVbXTKKMR+lA== 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=chtyvAs784yyPCikCs1YAicr9bFeuv2v541t7rOIifA=; b=p7PhgQ5ZyGyyqHrLaLrqhk71oZhMDhsTonnz39Jj/TejGE5SfbYXK0hVJWh9iuZIYFvVbjU/2tsOkv1PR/L3WBDTBNrQazVLuUSOBNTVRgP7kOjVeNp75o2cDbN4ugN2SzRffUObOSgHy5ULmsFw/BvQgZQV1u+WA3/HRFYhXFQ= 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 BY5PR10MB4148.namprd10.prod.outlook.com (2603:10b6:a03:211::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25; Mon, 29 Mar 2021 23:24:27 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee%8]) with mapi id 15.20.3977.033; Mon, 29 Mar 2021 23:24:27 +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 v2 5/8] hugetlb: call update_and_free_page without hugetlb_lock Date: Mon, 29 Mar 2021 16:23:59 -0700 Message-Id: <20210329232402.575396-6-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210329232402.575396-1-mike.kravetz@oracle.com> References: <20210329232402.575396-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: MWHPR10CA0065.namprd10.prod.outlook.com (2603:10b6:300:2c::27) 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 MWHPR10CA0065.namprd10.prod.outlook.com (2603:10b6:300:2c::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Mon, 29 Mar 2021 23:24:26 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6f6a409f-84ba-4217-c146-08d8f309cbb7 X-MS-TrafficTypeDiagnostic: BY5PR10MB4148: 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: byZbKFIOVWza32WuKZMCuboiZm4n9tOVGmsIsLU61KMklLv4dP+hwu/CEvDqHwjP2J+nLoJXFv/+IIz3v3/yMXIIiPSPUHPE/jsf1T0poBzGuKVkth53JKtPPz9+jDOLJyJyzDbae60JaJN4N4FR44t00QQHULddri9Rhuqz5clQDR3u9p7kBYYw1JyTI+hkfMT4po5qM1DiENc7IBdIufWtP4bcXi1nDGfDaoYwFu0v0rN9Jm8vqqBJORxgx1hYDTMccaHws+dWou6tzN1Vkw5ADjB17IyI+CSLBW5qkW8aykWkcA/r8StarBOpdXaDCwOy7EVJ0IjZ5S+5GvPcVZ97/bNWgIZxdId81t2s3pE2dYgxi65wES8ooxQKXjCaOnqKmR8qH0z8WfigQ/ZPLYgcFbssdkkV5QYJL0e909Zik83lDD3q9c1nlbO16OPYMP/qQcbLYEWE+XhPwILwyJcXWHDCfCxK4UztB9LiWB7iY0ZvUztDw4x8gfi9OX4nMM4lDI5AYFq+GNunrgxigw7uzqrMdSlu0UWEbSXpFc52dwFFi2ru4mu4u2OJSDVL3bizpL6VLtgcw9jzPgFg1GXyDMa5dpjd/U8baM7b/BGtRQmLRjFl1ou0Tb/6RY+NjZEFrwFtyzwuMN7MmNjKiQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(376002)(366004)(346002)(136003)(396003)(39860400002)(16526019)(44832011)(52116002)(26005)(2616005)(36756003)(186003)(7696005)(7416002)(956004)(478600001)(4326008)(6486002)(54906003)(6666004)(86362001)(15650500001)(5660300002)(66946007)(66556008)(1076003)(66476007)(83380400001)(38100700001)(8676002)(316002)(8936002)(2906002)(107886003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: G+KL0YRTMu+oiOscuPZ7UH532ZADHtZpuaBwSqWHnyh+0/fgAv2jEj8dgA7FiykOR0FGVja5IZvMVmTWs+uazWkmgxssUxU+tl0lGxnTP77xXnwUnbT9SgKcHo0rWi2O6n7rU+p70GdBzap+PXTMe+PUooXC0BrhkXZ5i6W1AFPNMvZ1m7qVvSovJHhyd0cGRLOpe46HCEgN0NxEpcfpTtIvedya/Uerf1YOyveyVk3P+kfkXgd1b/VnTcCu0RAp8imyKE9xYq6T6BcExeBohQk9LPDGVQgO17Al7rsQZpJ/tXjJdWInmfbGbnVYEyHcFFOYccKQ0fw1oV+GKI35zeaHv8O2qFztWtvSexdSi2LAlD98zhVN9klQ+LEUcWVs0A0/Nmqpru8Eav9cJtS+SsJBTQmCKPoAI1UBANZ0eIxN3rJ0cPxKakQfE+U2OpJa/w/7kdWhQfhHivRYKKdv9p+Z9JJMfsSZarXxcNMSgLj6oQQ3XcJVAGwUo8lCwhrercAsVdcFGr/OHmzDHUwuS/Vu9Tf7lkDc7W5iVjNkSXKFNN7STgYOXF3rNlpHe5YbHvn3r4iVIi4QJ/JJ425GqjJuNujlKpeFOzJUY8teyt5cuxsf5mXcsC/ven2bIa8GxNrWnVKs4LTzAWk+nz2Zzge0DkgPVPHw4yO8i+Dcozcga24R1f9UOg14FLnzw9/8NMe48NzdRm0bEeiLyNnuJtAQAqjFFJm80uLM8+FfTtiDVC0rJnQ7kKCyEHaRrDuQdeeF+Yk41kbeeLa5VMwYigFWg8XGJyRn7gWcmiBRvcAnTHVXK5K2NQydfECod1UQesvolPDdqjqbu449ZRAnjKVhlWJCJ9EnTVH3zHXlahyP0P/89Yh/vl40kbi8xkLDZ0rEtMgaOt/o8xj7wuNaDAWB5jQXuR4nYGDgIhNJEzX9AbtNkVouRZW5mhC9Jv6LtB7UQ33E6tEuujKHKYpm1Kj9hvk8zza5OaPehYaG9NHgJBlpOZoaLKHlTcl6p7JBE6vr1S72o4lArLzn/bBchDsnd7Iqz4IomnJEbtItr7EJ6Ckj0gAQ1O5FNpuzQZXYO0qBtkM/+syhXuDDZBB2yc9+9tcYZzgRX18qJnspSjgo8glnhLKoRwddcrLf5/91Yb3rU468p02gUTrxW7FmdK7YDjnlY6Ny7B33QGOxlBlf171DsMCPUrA08/QTFLxnl7nb25D4ftW2GCN99cdA9BNmSXa/nf/AapyhOxCzk+fWJHZ8TqqyQQUooHyokIc0sOe0YZrYj1nIaCUEGy/z46COFZNAYaenSFxRMx9xJ5ZYQK8TBU85kSG7u3p3THHX X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6f6a409f-84ba-4217-c146-08d8f309cbb7 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2021 23:24:27.1983 (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: GQynTE9lGAwpaMrjCa7H0XS2r8fq6nOTMCydF0u7z9qNGaxyyaJEVN4tHYF3jzuMEJiIC+nLMTGTAqfAJ4hVSg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4148 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9938 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 adultscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103250000 definitions=main-2103290173 X-Proofpoint-GUID: c7FfU2fLLmTBooCUy4JjkHfK7tXJAGJv X-Proofpoint-ORIG-GUID: c7FfU2fLLmTBooCUy4JjkHfK7tXJAGJv X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9938 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 phishscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 suspectscore=0 mlxscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103250000 definitions=main-2103290174 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 574D0E0011C9 X-Stat-Signature: w48hxbtn98djo9zr3sepmg1hsa6z8hs4 Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf05; identity=mailfrom; envelope-from=""; helo=aserp2120.oracle.com; client-ip=141.146.126.78 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617060283-786326 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 | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 16beabbbbe49..dec7bd0dc63d 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,35 @@ 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 + */ + INIT_LIST_HEAD(&page_list); 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 Mon Mar 29 23:24:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12171183 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 0A6DDC433E0 for ; Mon, 29 Mar 2021 23:24:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 96D0961990 for ; Mon, 29 Mar 2021 23:24:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 96D0961990 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 785B46B0087; Mon, 29 Mar 2021 19:24:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 75F3C6B0088; Mon, 29 Mar 2021 19:24:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 49C346B0089; Mon, 29 Mar 2021 19:24:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0091.hostedemail.com [216.40.44.91]) by kanga.kvack.org (Postfix) with ESMTP id 2287A6B0087 for ; Mon, 29 Mar 2021 19:24:48 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id DD29D8249980 for ; Mon, 29 Mar 2021 23:24:47 +0000 (UTC) X-FDA: 77974493814.37.CB9611B Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by imf28.hostedemail.com (Postfix) with ESMTP id E63E12000249 for ; Mon, 29 Mar 2021 23:24:46 +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 12TNK47a086557; Mon, 29 Mar 2021 23:24:32 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=byxtiIA7N4E8ZgTCCVitoLstpHZXHHyvttpRxw/0DsA=; b=QaJQn0l5xaVAKYLS8AscpDTiVUQKMkjHcEweiNgexMU0emTclBB+kg1SO+SM3Q8iIbOo DjYrnP8l1ORbfKO98t6ZQ1/FtB+q7lwLEaoMWtKhz/rNhRpnzgs+Ir+8tmUFMo4xS698 S9k1rU1DGfZED27JSQ42EWTSEROZOS9dzKnyAW67F5UkSSE2c7JXJZfic4Zk8hXBfcEu K2zOtZiBqO+FLzGugbWA3C8IJOXHaYUluavjGdsoSGkeBU5F8YhmNJdK2u5BNQ8PgZ+g c3YJqmhRN2TxNsjpRuQMOHTslmfAr97mzBR1PXiqz9ySyaY2viHhkFS7JuyuTDpw1xCF zw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 37hv4r57u2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Mar 2021 23:24:32 +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 12TNFQM7068058; Mon, 29 Mar 2021 23:24:32 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2177.outbound.protection.outlook.com [104.47.59.177]) by userp3030.oracle.com with ESMTP id 37jemwc71w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Mar 2021 23:24:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eWwB3+valbwQ+cv6sBDcyutGCaKEF0iufGbmsx1Ii6Xm0FlDiOIzistaHzmu8Ms+VRScHQOG/oYDTOVXNMGzT0RKg6QhcwKyZXtlJD6nYpD5hb80zgETqCXBX2iFLo01vkE5EGt+bpeB79ct19eiIl9ghI3n3pBvU4Y1/OWbFQ1EpOokFKgs6L5QgXZle9KnVjH5zVqtkr6lZomQQ5Em5np/N5De6fX9y8axygbE6btbYfjgA889sGg9awLY5QwIC+M/cpsIPWjSkfgKLU511dS97lZ0ZpTAo3N4aAd9+FQyQjBkIWAr11o6MmasUR6oRfJyhEFX+YFqypWGbsgh1A== 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=byxtiIA7N4E8ZgTCCVitoLstpHZXHHyvttpRxw/0DsA=; b=ecHhotRFy3sgB7YN8MPBj/TVt/C6tOEt+cr3nINBUKNsD+VKljUpSckl1E+2ztYTAESFtwwWgj7sa4OlxymvhLozO43QedbCtOObmBbN6sGtH/umvPcvlXO3VEQGZTbS3YdZgSWAqxovfKE8ASMzbmJ0x8Pej3Phcvj+eBahd6+z0VKafiQjwkbBkIPEm/YrebbM5M/PNQaj2VrnatbtRjb899tIGTWyG9tY+YxqVwffKBEy5aUBXtxaeufxVL+EzPxXDoeNVAfBs9gDE3PrwR8rbJAjDRf+PZuLn33pVmAbCxFPQlQTWwAYf0Z28ypJUbFjgxoRyCTeX+FIRTz0Ww== 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=byxtiIA7N4E8ZgTCCVitoLstpHZXHHyvttpRxw/0DsA=; b=qMseT1E6HexR/Hccsbuyr6AsTl6ILfcqTEg4gnjXdK8LCGhLptr+h9S25nOHxKKq45n/sxoKc8SPnsodJycqn4+vYsBEKAjos8RppedZQC22aMPY3tAEic1pEZpMY93uD2fAbtHTr+MhPx5u1gRCng+9Kk4WwHRTFQKvwjTsWYY= 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 BY5PR10MB4148.namprd10.prod.outlook.com (2603:10b6:a03:211::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25; Mon, 29 Mar 2021 23:24:29 +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; Mon, 29 Mar 2021 23:24:29 +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 v2 6/8] hugetlb: change free_pool_huge_page to remove_pool_huge_page Date: Mon, 29 Mar 2021 16:24:00 -0700 Message-Id: <20210329232402.575396-7-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210329232402.575396-1-mike.kravetz@oracle.com> References: <20210329232402.575396-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: MWHPR10CA0065.namprd10.prod.outlook.com (2603:10b6:300:2c::27) 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 MWHPR10CA0065.namprd10.prod.outlook.com (2603:10b6:300:2c::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Mon, 29 Mar 2021 23:24:28 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 021dc397-3916-40c9-801b-08d8f309cd07 X-MS-TrafficTypeDiagnostic: BY5PR10MB4148: 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: nLoECzoce3FX7MTnSmtwDEsNnnAeWxiybjmUbRrl8CHf4536AzeF94wBsQHvvQ+rEIkeM7dXslUewuik/1MH/Jq/cA7tDlR7VOA40zeb8p93jHFjiGU7eJLyBuO9KkMNZcf1PqkMUKhKErSGZuzmNck/8GizTjlcaxUcO5USi3DhyBcu6lU2PlGtFkHG4tmxHnIE0iBkPszBfLiqRkhAlHLBpuhTi7dStK2II05TX9/afgf25PaeEqn2AbRO2N8V53/out2AJUxqB7Xgsv5zRRBFJAGJrJs9XQG0gz1VB1XXWk8B3FRRVOA274VWaShVstCjxVtj2z6j3JSvTwa46WBy5M5sAjs0hgeo2AC3Zg7l8kSfHr9reCQaqlEaS3u28uSj2QFuXfAlx/sQr7CcG1HZ1O4RVGR5rtL1YUHdhSshwdOBHAu9WyJGue+QCOXBMq00ZIyoPFHH72soJSOCiV+mrbSmbRrPyqqcs+KpyC3XjjVmcf8qzyo0w9qUDtHr/RlNAE6PgV4JfUZDcxJmGjRXbO+F3tDAyoFFWvu32e9SKFEGzI/elRbmygEC2SHcXXz/LWOgnHdm/2xEE/KWg2FofwdGp0iPh8SP5EWfw8wE+ZKvjw3qlKuI8lr1t705830omBwyePYVgu0eD01MKF9nMECrOOBG7LgJoDEFwz4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(376002)(366004)(346002)(136003)(396003)(39860400002)(16526019)(44832011)(52116002)(26005)(2616005)(36756003)(186003)(7696005)(7416002)(956004)(478600001)(4326008)(6486002)(54906003)(6666004)(86362001)(5660300002)(66946007)(66556008)(1076003)(66476007)(83380400001)(38100700001)(8676002)(316002)(8936002)(2906002)(107886003)(14583001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: MLMkdxZeZ8X/jmN1YNH8DsLI5VOc74D19agLjnZHshPlePTuEbuuPCCOM0LmHyqY/WbL2PMc84EB+u+MlQSKbsj1SLFr7Rz2QCN/0FIQU4MR4If/FVRHICZu79q4J4dU7llV0NQcuOi50RBNjpQTSglv5nFDSnpZTYlfscRSBfIUOsy4pYGBlFRnc0v4qlCHmk5m01vPvRI2Menkonk+9YQqyx/DJ7p2Yp0sO6tmJJ0DnV7Ihuf6UiQsfg9xuHUkCGVXRLfHIgd2+Ce/Q+ky1Hg/8wlryy82R7qagPM03hK+yAZ78rCntCss5rIp20MWYOuoOVkXPil2IjlvRK/5zE9yh+VBmgKAyC9ZOmkW5mPYz20eZC4XMccGzZsrXPuX6IFbkwULLzeqibdkDYx4RLngSOMWvCKPtgjpYbIU19kq8mE/5GmC2AxDHnmEtbi460QGH972D10i9rQ8iKOV50IiGh4nTyjQ5fHXKy4g/anFYZO3k4h1rr+MDJdmRUjUymr+wdggcxZnfXONepyNV2iuhPHOUbohxZ9tS7rhJxz6nn4JzjhsITeF0Ksr2HUBTHj6BUv0SB8vjEphiMHayOc2Ep+ceWDlhEoEiuuydXrUWSomKalVjqLAMPJmn9+3nAy8/3JGednt9GAKch6x5VIDMEOVq8E6z+VJ+sxAq5Sac3zCauWHmGL2e3FP4Phc0kdawSi0Xgf6fvEqkC1ri95iAeaHWVmit8/hH1AD9aCJPXx5//Ftwe1ZC9WeQd7Q2CpBzV+5uJ04qLcdEJ+F/4lPB+PE8xGIdGeOge6ttnLZKIWPLhSiJnyvs2QYhn+POuGWsJ/TFlv/4TB/wDAmk4w95UqJzPIYXLcDRnd49SVSC0CZPUCk0Q5eec90gKCWby1VqNqwUZ4b3s2GY9YLv2U6XhDH/W1uaXURcWBl1U74Z7OsYj8HEViQMwnN5rrFJWotT78Ik4aj0neE5Az3p0Nx4j6GcHQa6fwQwEX1IL/r2AqwHCqOU1ljty59Z3o3ndiQLCIXrXRVVH4uuq7lfY+lJh1DpViXl4a3vQTRJYkOX9gd/tzEFt93XKcrfDDtxx0vvKJdj1KUep76cp3/GgxmqLiBEe2P3JBMKlRHZS6Dqvkge1k9JW9E/rw3ZuhHVmEBePt3rlVctNsfXpWGuwJueMmgVmBI9l4svn8wFiNXUq5VagnRBhQPqf94faCEYmSofWzh9KrfCiDZS0MQq0wYfST6YFJBvDnPinpFJw7avySYUzqwrGkj73UB5pVIDHIWJL8CmvNK7ISELjrC8sJpcE53jCs+FX69rG3l2L9lvj+Gmp88Bdevz5diG7Zh X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 021dc397-3916-40c9-801b-08d8f309cd07 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2021 23:24:29.6515 (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: emUCToP1l+7f6BZlNK2WuZrDkH8BbY8k5gN8sigNsUcoi5DPdHtQnNzM0I685xNbJ6jf7J/utOMgjpDtBbmcFw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4148 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9938 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 mlxscore=0 spamscore=0 suspectscore=0 adultscore=0 phishscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103250000 definitions=main-2103290173 X-Proofpoint-ORIG-GUID: u8R7d3aIXj96LdvK2uAYjyAdZ-QXfT-8 X-Proofpoint-GUID: u8R7d3aIXj96LdvK2uAYjyAdZ-QXfT-8 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9938 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 phishscore=0 adultscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 suspectscore=0 clxscore=1015 bulkscore=0 lowpriorityscore=0 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103250000 definitions=main-2103290173 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: E63E12000249 X-Stat-Signature: 4x9yhz5tpekb738hhoxcjaha1u3tidd5 Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf28; identity=mailfrom; envelope-from=""; helo=userp2130.oracle.com; client-ip=156.151.31.86 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617060286-84926 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 | 95 +++++++++++++++++++++++++++++----------------------- 1 file changed, 53 insertions(+), 42 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index dec7bd0dc63d..d3f3cb8766b8 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,22 @@ 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. */ + INIT_LIST_HEAD(&page_list); 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 +2683,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)) @@ -2694,6 +2693,7 @@ static void try_to_free_low(struct hstate *h, unsigned long count, */ INIT_LIST_HEAD(&page_list); 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) @@ -2707,10 +2707,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 @@ -2757,6 +2754,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); /* @@ -2869,11 +2868,23 @@ 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 + */ + INIT_LIST_HEAD(&page_list); 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 Mon Mar 29 23:24:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12171185 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 41FFBC433C1 for ; Mon, 29 Mar 2021 23:24:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BC7A961990 for ; Mon, 29 Mar 2021 23:24:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC7A961990 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 2F4526B0088; Mon, 29 Mar 2021 19:24:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 208E66B0089; Mon, 29 Mar 2021 19:24:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED6976B008A; Mon, 29 Mar 2021 19:24:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0164.hostedemail.com [216.40.44.164]) by kanga.kvack.org (Postfix) with ESMTP id BE1276B0088 for ; Mon, 29 Mar 2021 19:24:51 -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 85BE98249980 for ; Mon, 29 Mar 2021 23:24:51 +0000 (UTC) X-FDA: 77974493982.02.4B35F21 Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) by imf20.hostedemail.com (Postfix) with ESMTP id 010EB139 for ; Mon, 29 Mar 2021 23:24:47 +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 12TNOZ6p164127; Mon, 29 Mar 2021 23:24:35 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=y9zys2i0cdd3Oi+3BnIautw4FxcBb5BI7MA2DnFDUiE=; b=JhLM4Y+qzMLQFQNyCohPJRvsjlPuBk1bzGX6r9aTn2ODxWqzu3DprrF3Su1Tec36rLrl FFLOEXJvk0pJIhk0WbyY6E4OYCjMaaS9L77uKr48J2n8QbQOqOhN7A/dUFFv1tYiHRcE 2xZcVQGQH1zOtr4n+4UFM0mT05IoDqBJTfxJM7u6ydUs3bP2oRAmq7cdDHf/ttuWS0qv dgR++T4ucMWNpktKwZ6+Nz6sDwTvG3jojYD9muN53UI2XG1Hje6/7mhDQo5RYGXggiWY Zkv2Vn2fgak42lBvK6s69gNLmhx6coRPomBk9vuM2wra89KTWv1gbjErHgtBkyVPWPHj hw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2130.oracle.com with ESMTP id 37ht7bdbrf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Mar 2021 23:24:35 +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 12TNFY1r055853; Mon, 29 Mar 2021 23:24:34 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2177.outbound.protection.outlook.com [104.47.59.177]) by aserp3030.oracle.com with ESMTP id 37je9p06s3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Mar 2021 23:24:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=diROtVkl5+0fVJywdo4McRAxY41H8eUsHxS+CH4m+oCl8nJpg8vlJx3mRTtwb9+R7CVXBa/GCSOiQLi5nYtRaDVfZFJ59vaQtrZHsqdmQSm3jYktBT6IvouS7HB279Hc751/p7jFluBaJ2yH3cjHHs+qy1FaoKEca/DX/I6joTjg/KEUDJxby/kK70xQhw1ey4/OuuHYl9RX8y0xtHCZQibOio7dKvVWOAPCrTtzVEmUnz9zM0O92+1xuHdngYWKswb9VoLlPh2nSV64jjmXytk4nYKj9C2c599+jN/yi9aqGcpIVzBsDyvTmpljIxrymuGUYJaVN8ztDY6GStwFsw== 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=y9zys2i0cdd3Oi+3BnIautw4FxcBb5BI7MA2DnFDUiE=; b=gtW+m02tAONCVNsAvqSBtI0ik9MpDcngEcb2s1vnqRE62fyoh1jbaA2GSsgtjEq0k8ED93F0vDAU1WjJFEX8x1A5DbVXXr4Qs9XzI/XV8ckye/gwDib6+HiIRpJ8W1MyFqqsKdFJixPcGb65EWeFcoJjFoPc9KHKl4WRWenVJyUePisXLAb+8KVoXGOaWZfGHelUot1vdS0eGPU7ZLC92swWgMOPpwbvi5YMCdmZWhVdgN7pbyDnjTkFhXqbtWpfetBFp2DgUppQN5B6vQYl0aNp4a65z8ydRmXKCor8mAcYfRdr55NpQu8O8aHsLnyoqzxKCRImq0MNx1GIzM8KDg== 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=y9zys2i0cdd3Oi+3BnIautw4FxcBb5BI7MA2DnFDUiE=; b=BBQmKWp4LKNSmCP7nDwTPhOVc1oMV7TFUBhU7mV5Mlynm0+g9NxMBPFJrxnVWdf3Y2Q3Ec+cnA7bGeFRhQ3SfmVikpA+zrLlvkl/pX5iplK/grngBqMr+jUwL0LBbcpz5FpcPCVRC2MU6ldK8vqSISDA5sC3MiRZfH57FlQ7t+c= 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 BY5PR10MB4148.namprd10.prod.outlook.com (2603:10b6:a03:211::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25; Mon, 29 Mar 2021 23:24:32 +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; Mon, 29 Mar 2021 23:24:31 +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 v2 7/8] hugetlb: make free_huge_page irq safe Date: Mon, 29 Mar 2021 16:24:01 -0700 Message-Id: <20210329232402.575396-8-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210329232402.575396-1-mike.kravetz@oracle.com> References: <20210329232402.575396-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: MWHPR10CA0065.namprd10.prod.outlook.com (2603:10b6:300:2c::27) 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 MWHPR10CA0065.namprd10.prod.outlook.com (2603:10b6:300:2c::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Mon, 29 Mar 2021 23:24:30 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 04329fb2-aae8-45b6-d8de-08d8f309ce82 X-MS-TrafficTypeDiagnostic: BY5PR10MB4148: 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: +vxO5lbtmTZiUVNHsSKKtHnPvIWrKAbkWYNNpS0XQbynQkVweKmLMx0WcZbT9RHeHllEc1MDYGRQYgjnR9G/5iYMPr4gAtVv4dYinsYd1nciFwEt5abxJgVtN+IZ6O5HfyJYbjYMdJeqtDli4JqjRzInToxHa7MLuH0zIr5MyIPcn7eW53oXUiw7By3tFDmt76q2sZ3q1XBlTVJCsF7W8SLsX7v16tXQrUuk1+otNJtmrSMDzl2mV05z+glKUnJR9QnfwTKih+BU73DAgEsP9rbSkQYWV+ER2xqLno4xQfj+Uqm49Ge6X+5ctZca4ptulxeG6ZtSxj5Y2Js+NLUmOaNGO//JzSUucHT327ZhViMz6teltDhaMQMD5nryaVwS1Ei0G07jD030nqGlc6aI+KKxu/XbuFE8wUvqfIz4Ef0Q+DJo829pB1MvcHetel0FRanqDYBAcd7XGQmfBI9aqNTulblSdo5BZru/5ir+87/5Nu7KEYt1c29pdfmE5awVH0kRzSxyGjULxrNwnOLYkhNhYBpVIh8yRLOAcajhLbBnfNhvI4OLCyS+ZJLL7X0FIb7Utnj4hQL6ImugCdK7ads9WfyQirBXvA4NzmsuR+8fyPwBOun+atW8yQ33RA0nxs/lCvIAsD891tbhKLrKkM8nkfqNKg4H4wFpAcO8Po/hYhpnpEZxyd9C94ZWKMv2b2IPttkDETs7uZmyeKGcYzAURSbE79SLyizVCDIYoOrmMhhZBdq3EnUHw6qpcz7W X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(376002)(366004)(346002)(136003)(396003)(39860400002)(16526019)(44832011)(52116002)(26005)(2616005)(36756003)(186003)(7696005)(7416002)(956004)(478600001)(4326008)(6486002)(54906003)(6666004)(86362001)(5660300002)(66946007)(66556008)(1076003)(30864003)(66476007)(83380400001)(38100700001)(8676002)(316002)(8936002)(966005)(2906002)(107886003)(14583001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: jtdxhXWUxMrQE9rr9hQgvjiwUHPwWT4Dl/9U3u5C8HgQPcTyIIPlvRqIkA0tYznWUP9ZVpG9cRpN2JqqK2hvcNtDJH9r70OoKChhFzBk0iVWMY3X8cwaGvcmpbvsYdKk4aTXx9y3EJQAqRqGY693WYgZ9/JSj3brXLJuLB9n+gxzbDVUfHNAfBN5JuduMGHEXuhr9tdFTk5hhFJvsHgkQIjbKn0UvzukOjSLNQeY8XYzpb+2j4YWhqxdUsy2iwwuM/y/eunPOcpzgMrWVhr22QOuKTyQkIsFdrmtWmw6X43P2IQZQAO7/iDsTN/tSaDPvrAOag0brjZLgRw9WSuzL0MypfkqdK19b/vhF5VY2mHauLiPYr2Yntm27ShNBIh5bhwevP4X0MD23+Tkavhwxau/B/HBqrRNp2CmHgRZrp5yC5P2T26uxqk9msKG3quf2WF8m46E3BGHh9r8mO19iNsm9uy8c9bCgxxAjCy8RaRpJEzvn94ZjYMT/rJjO57AVIMrhXPVLwrjYVW0hPa4TAEsvrT8Tmn4A2PuD2Kx/zI9z7DX0xu6y7htFujn2VRl9ihnkVpvRAQmzcWYAioWqa4/+Kjc08qG0YXZIOs96JHRTqQV7cODA236e4Xn+IMHWtU1yYIm5j0YFF5A+cCeyGmXIOtiXohLe3JnP3HDWMAv4CNWrDRzf+XUrRZJJYiGQIK++fqBdyKWy7YE+o5CR2sXq2woxkQ4YTmHeg6W1x1vkYuss1TKNF3d5bKRgMGJqnmLnDCGzKZsxRksuHwXhAXd42taZObbH/63GL+XMlJq1knGW7yu1tj6cA1JdRI8k/wwNnJ3O29QuIns1snIPUfLqc/ZF8ajaJLUgrpEzWGyjPPY2OH1RezK2Eo2hHy2lqhiU0xrUivIZ2VY9atCbeKNPYJE1LoZw59VcRSMD8y7LVyTDVqEbuISRYD762MPP8DNo+W+/DnK0WzXP85DaKBhpRVUm1S9svs6mcZRGdlPgkw8liCBmJMJQm0hZKWg3qJzO1fOf/QjsMPwUQ4QnHxQ2CUwc11kBz4eAI93xBH3yO0F26surDmYflfyj7eecMUJ90oQULrSGAExDsWdGkSB8ZXqCF2bqUEmX/15DQAt0W07SXUMJUCm8OQYj6AvxgekIJyDpTCTZfnnZitCA4vhenY2tK5S9E6nPXxHYBEjjQ2ijxQUBrNulDhLs4Hol+Hq14BoRU/w3rVz6Xw5juIeeMkm10GhnaATg/D6fC/R6SGOxTOVpESGbJ2P06GA25HPW6OUSlS5Xs8D9N5Zwqz+FPyiOAVWtGnrbYzkBp1zo9o8OaHyW+VOZMfLF3dK X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 04329fb2-aae8-45b6-d8de-08d8f309ce82 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2021 23:24:31.9056 (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: qM1n8q0rD+2aCBLZGv8QuBKR2B/N0riTFWqpiErXgWvw7zCx+5kFQxTKTG20jywExJpEBiqZKn6K+a2pInXBGA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4148 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9938 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 adultscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103250000 definitions=main-2103290173 X-Proofpoint-GUID: bN__hQdAlsL-XPl1d6kvy8Po3vWa67tR X-Proofpoint-ORIG-GUID: bN__hQdAlsL-XPl1d6kvy8Po3vWa67tR X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9938 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 spamscore=0 clxscore=1015 mlxscore=0 bulkscore=0 priorityscore=1501 adultscore=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103250000 definitions=main-2103290174 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 010EB139 X-Stat-Signature: ia8h9gfe1bbgpz1jna149z84bf1cmqwb Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf20; identity=mailfrom; envelope-from=""; helo=aserp2130.oracle.com; client-ip=141.146.126.79 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617060287-141472 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 --- 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 d3f3cb8766b8..bf36abc2305a 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; } @@ -2117,9 +2074,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); } @@ -2464,7 +2421,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 @@ -2472,7 +2429,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; @@ -2480,7 +2437,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 */ } @@ -2493,7 +2450,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); @@ -2706,9 +2663,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, @@ -2804,7 +2761,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; @@ -2834,14 +2791,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; @@ -2881,9 +2838,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)) @@ -2891,7 +2848,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); @@ -3047,9 +3004,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; } @@ -3636,9 +3593,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; @@ -3734,7 +3691,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 @@ -3773,7 +3730,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; } @@ -5837,7 +5794,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)) { @@ -5847,16 +5804,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); } @@ -5890,12 +5847,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 Mon Mar 29 23:24:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12171187 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 3EE03C433DB for ; Mon, 29 Mar 2021 23:24:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D7F436196C for ; Mon, 29 Mar 2021 23:24:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D7F436196C 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 AE0D16B0089; Mon, 29 Mar 2021 19:24:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB6A66B008A; Mon, 29 Mar 2021 19:24:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8BC0A6B008C; Mon, 29 Mar 2021 19:24:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0178.hostedemail.com [216.40.44.178]) by kanga.kvack.org (Postfix) with ESMTP id 5FC486B0089 for ; Mon, 29 Mar 2021 19:24:53 -0400 (EDT) Received: from smtpin35.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 211821DEE for ; Mon, 29 Mar 2021 23:24:53 +0000 (UTC) X-FDA: 77974494066.35.2532BD0 Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by imf14.hostedemail.com (Postfix) with ESMTP id AAED0C0007C5 for ; Mon, 29 Mar 2021 23:24:47 +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 12TNJ2Sf085899; Mon, 29 Mar 2021 23:24:38 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=E/j0flEP1Kls1T1q7bRm7gBdK+p9PElm2UJyBCVFWLo=; b=hR63QKOhCCwUpabDn0c3eS+7ZDti1CR5gwiQkd1qYszfDimmbs/faAOjTJ0cGl6VemRC zXJ9sFlcBfVDBq0nfDJic+iHZWZ+nE/Fj+5ckrp1cpIVLsH1SjMAkz/QhLqp3JnAOom5 SQjK7PUpoHWmlzTf7ajDAuuZo8V0MpDLxFVJYzUSIzLect3RKnI8XLhCNswwxB+GOVKo cYUxH4Qaelo0mVOMtvIeXT9zE49jT4gxHh7ZjMnlsLXT2eY6gRzZ3WtD/0J6sfBtS0uj 1dqik+t7tF59jYDF/f2OLShN3jRiaxAn+b5G3co371WpyAKmo0GYYko9Xa4+D35XEYI9 yw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 37hv4r57u5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Mar 2021 23:24:38 +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 12TNEmsa088346; Mon, 29 Mar 2021 23:24:37 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2177.outbound.protection.outlook.com [104.47.56.177]) by aserp3020.oracle.com with ESMTP id 37jekxsrdj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Mar 2021 23:24:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Oiat5dNdLSp1+mudpzLWxA6z3knUeKZeDL185CPCjFIE6X92yDWjISmtVtPyRTx3n7YYYXcOsnKip8rs34ACvmkPQblTSZJfRJZU9w1qwqnwTtnON5Hpi+BXEok2D/JUSoSEE6uCOrILcGe73Np4ISRjqdtqFS2rUw0I/OQB73ekUOw+JqSiPr8//KUqtQI+/2SfQx4hYlePK6GT6zJUVkgBLSZiNpwGn7m7RErBkklt52SpuYriW8g1x6LsCtAhOjJwgbfWc4QFQz3dkNPuWYjHrXYXqG9pUMn7VM1YbspNfy1KrHUpeHGgXm9twBLT+JCjKFxYEA5+9+F3TV22Jg== 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=E/j0flEP1Kls1T1q7bRm7gBdK+p9PElm2UJyBCVFWLo=; b=SbfSe50A7joxsl4maGLrJCyfknEQfYCLue7DNUw9h8T5rU0OF42eTSxwi2btuiSWKR8B3mFejKU46jE0JgwIVWFvy6OqDQLiZfmXL1UzxBj1QLzkApvPN5yBmuXacNJtOuMc9rEqrnzTaQPcM9Xhbs2DP7fJuyxzR8R7VWHozI5hqufwFpH4FuaSMvIwd1zqg1wpFQeZNpLa1q8USXAhMYccH37+U6+UC6lXdtAREa27LO72KPT581XpBq+78RxUkBf9ojtSykqKhdkRMoGEqy7omPn3pC3v1qFDjX572+HfiKasWelkL5W3Z76jJBH3x5tzP0XhseDb4YtJKKvc/A== 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=E/j0flEP1Kls1T1q7bRm7gBdK+p9PElm2UJyBCVFWLo=; b=fZ70yb9EjVyvQBRODWRhhFf1IzBxcsc2sWsaOV5D7x/4mf7nTAPglwWk/MofwwXNPhKPWnyPNRX3Mrmdt3kgxplqHJOIV272VKV9lNWtPslIWqrr4N42vu2c+4bhuji06mKCA2gTDr50FFkX/8RmltNm0K6pQ3eWExzkyHsDIuA= 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 BYAPR10MB3301.namprd10.prod.outlook.com (2603:10b6:a03:14d::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24; Mon, 29 Mar 2021 23:24:34 +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; Mon, 29 Mar 2021 23:24:34 +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 v2 8/8] hugetlb: add lockdep_assert_held() calls for hugetlb_lock Date: Mon, 29 Mar 2021 16:24:02 -0700 Message-Id: <20210329232402.575396-9-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210329232402.575396-1-mike.kravetz@oracle.com> References: <20210329232402.575396-1-mike.kravetz@oracle.com> X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: MWHPR10CA0065.namprd10.prod.outlook.com (2603:10b6:300:2c::27) 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 MWHPR10CA0065.namprd10.prod.outlook.com (2603:10b6:300:2c::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Mon, 29 Mar 2021 23:24:33 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6bc9152e-0d75-4876-bf06-08d8f309cfde X-MS-TrafficTypeDiagnostic: BYAPR10MB3301: 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: UdBKnjt5MoTwlTrUn1pcaOZJzSB41pq7HIKWCMj7ujV7b4sg2TVa4ccRrzkDnzr+pVIBN+skoroWWp8eR34LTyTy6ZBbbP5amgbalbC5TbBEbPKq6yatc7lAZPaegbkH5n8ehqXwYQA1O1Knh+xuBM4H5dfE4skuI8oIIIOi22PAnU8ul9A8dxuoFVyjnhbToB2iDI27lQyIxDIkI8tJD8fMBT8KMj9MP4U7WAZGWrhnmmLrP7L7gS3I9l5USImDi7X0Qi58fZ//HqV5TY87W1Wo5ZgfKgCburryEtC+/CtN6XY5qYUf04ta3Qcmi3Lq9aWZZOOlHezZsQpYmnOGnip6NhffcnDmyUFYl80/myoR9EcTJt4PmmYzYd8WonK++fIeCMhUg1ZeblgKy6FSFaUFCeUDDh5IhbiP+N0aaM4hBA1+4MkDDmGcPRut7nLbQVwKK4l3raHO1PpDRpHzxRrHul+6zuYqlCzPJd8MXJUbnwReC4rzjNRRP0dm4279r/eCTdnkB60+CPy6xvuQs0Nhnl8nGNZJL7NE25sBx0CPebrUvNvHbRPuX4S+lJovmLl2l3SDqTsxhT7RTT3Kn7O7aRZolpk2sizyLJr9nNP0Mlsk/MANRzXqo4itKp3xRkbLnQNCwTP6yKZAkBxm8Q== 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:(366004)(39860400002)(376002)(136003)(346002)(396003)(316002)(5660300002)(8936002)(54906003)(66556008)(6666004)(6486002)(956004)(107886003)(4326008)(16526019)(2616005)(186003)(1076003)(7416002)(86362001)(38100700001)(66946007)(66476007)(26005)(478600001)(83380400001)(8676002)(44832011)(36756003)(52116002)(2906002)(7696005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 2qxPvR8aNKQH2JoHjuA/+8Q4KoPjBK2P102AfMqucJRgPLTm5BSvrLvf3R2GpmWwk4q/Ohnxb4qLj/jwb0SEv0eW8Q8sg6AHn8zFE2Bp3DpR8mDYEtNtEb2LtAaNaERDeXCv6gDGC9YL9YB4HSvRGWCEvvr94abMgpkNjhS4jmmZ8SVAQ7WuIoyM1SKqNqSZS60v5r+3YDOeeb0z1WJM2YAC4SGOd0Ly0JUy52XT+WUNbfVapzZb4Pvu53LGbGosGaa0LCdUqylSASl3M60bX7cuw4Wpox5JescR2wWNGBrEH/o4QCiGenL3UVA0k/ScvV4mBfsIlgohr51axGfcgZiE2IwLFLK2ulUQwgmskyDOFroE9HlpuH2CmYwlON5RvLFTTSKBBTmuiqOWrb7LdvGK1gbRPwlcFkypXM6kSV68nVDmlrN4+FOpRz2GvwNiKVFMislu7MT0B5ro68QmBLYzeGaPcCtVsMJ9rZoRmDaIp+Z1NsevIsLUq8vJscD5hVnzTSFwAr+S049JXume0vWkxEV+UUWDqVJc0QbuK317XRRyeH+CoSbACGNkwK/+ARkscxGXCO0lLEOpURCwtI/wUxnUByd/Ouzs5ITZvETTQtCtPaAILL8ukKqsjDcnLDWrQ6Gyg8KmdtCDI2vT+LXEDW2YIhXSTXDN59fRjqYNeBZk1rfcqCZ/zWGWhPQH4P4N0YJ32ms2GS5s6f3pAVWv6CIiZXpM+7kC9ge0MYeSXbxLkma5AAV836I9KBwqmBQtsskW2zgx6Ldk6iAZXEdyLBStKFCcHwUmILocI6DgmEJ/RbKhPM5hptoMO1cSu/Zcewo6fLUoQo756lyOQ6zH4HJKhUz3R6Yx5edDxytQIXm4A4JYpENKPs3SR+cZnaATOdqNLnTfpF7txBDN38sCNHI2F/qA4puoYfADOKSsZIFFi8fELcNXqYlKKdjZQENPswcHfgXmgQvWt13zRyYx8GlccOdRnhOwGUQKQfhHbBZBQhDUQcJTgpi6kAdpflKcmsVFUtv78NxU9j/w/xEWOWd+BZ27hTFt3/UBWailyg1f+lOzBM5td9CPXfnDKwy8asQu/6kwpr6Sh8TIjhlS1PvMhyXWbMxorhCdJaHotu5vyMq6HBboULAoAB059HrRnOYfJIdI90kAD8Ctjydybfj/E0i019t72nhuJhevmPHDizFQ88XeGkY+b4In6hSuqgnW8/lJ/7hAkcdc1RXyeJSJBus4VcOjMgnEjWTnjfscwk9CAGPutzG6NwCz8ooHJ8Y8wILz6R07CI1kqSfc3BGnll9L5e1ytRJxC46WzpDsPJ217HncvKsGexhf X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6bc9152e-0d75-4876-bf06-08d8f309cfde X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2021 23:24:34.6526 (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: 2yxQobtZAoY132BpJGbp26nPLG3xphZnnWZsLLehOFxU7vqRkwZ4m0z1gdk2j5PpKO2HsZrRNGFxIqLHX4Opww== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3301 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9938 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 mlxscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103250000 definitions=main-2103290173 X-Proofpoint-ORIG-GUID: eNEPhUXXKycuHjFhxqkTGMEU4-YRi_n4 X-Proofpoint-GUID: eNEPhUXXKycuHjFhxqkTGMEU4-YRi_n4 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9938 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 phishscore=0 adultscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 suspectscore=0 clxscore=1015 bulkscore=0 lowpriorityscore=0 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103250000 definitions=main-2103290173 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: AAED0C0007C5 X-Stat-Signature: 5s66z394894wfw6z3bc9osyhik3hwkom Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf14; identity=mailfrom; envelope-from=""; helo=userp2130.oracle.com; client-ip=156.151.31.86 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617060287-726021 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 bf36abc2305a..06282f340f40 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; @@ -2642,6 +2649,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; @@ -2684,6 +2692,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) {