From mboxrd@z Thu Jan 1 00:00:00 1970 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=-7.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 B982BC433E1 for ; Tue, 23 Mar 2021 23:18:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ECF68619DD for ; Tue, 23 Mar 2021 23:18:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ECF68619DD 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 D73D96B029B; Tue, 23 Mar 2021 19:18:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D4B3C6B029C; Tue, 23 Mar 2021 19:18:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B4F538D0012; Tue, 23 Mar 2021 19:18:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 978F16B029B for ; Tue, 23 Mar 2021 19:18:42 -0400 (EDT) Received: from smtpin34.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 4F2AA1801BB9E for ; Tue, 23 Mar 2021 23:18:42 +0000 (UTC) X-FDA: 77952705684.34.0862A59 Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) by imf06.hostedemail.com (Postfix) with ESMTP id 4D2CBC0007D0 for ; Tue, 23 Mar 2021 23:18:41 +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 12NNEvoR033485; Tue, 23 Mar 2021 23:18:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : in-reply-to : content-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=GapeZICg63arON+TMaGj2+EZ/fF07YJPgYCGC4ENTQk=; b=gituu8oJ+E7JK/z2z38lrUEUCXbCFpfavYql5tkQUymUJKMwNUAdELiLEEJ8SdacvhiZ O3nUibk2I4HjsHIUFT2+5e7iFPZ1WQoPfyh02Mqfnjvf9FfTFQa+2mloKQ0haSHpNr7H COQtgo8dumVTvmQZfwwXH6y28RV/oD70AZRosW9yyrLRRab+c289R9pGlHjfnh3E05bE k9Rn4KDpqaCJWZyKGrut8ma+P8fyq/1h721mZMGlo7lsMBThvx99u30ty0sptC7VmCg8 BGX+PrOgYKgVMZXntZWJcygyiQu6RkGr5u6j0eHe9OWp0nytw0/YQioNDIu6uwmAZNk1 Kg== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 37d9pn0wsv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 Mar 2021 23:18:14 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 12NNG86x083060; Tue, 23 Mar 2021 23:18:14 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2177.outbound.protection.outlook.com [104.47.59.177]) by userp3020.oracle.com with ESMTP id 37dttsk9q7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 Mar 2021 23:18:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Hojf9mdpzIdchR834Ngc3dLvPOxiOifuk5xHxQeJuGrc02XVQatTVhPbhwY6Pow3vK5YcfggAS74Ge5bHsbL8GxPWlsYjakXNsBo9/MW4TPA+0J310lHqJZMm7VdRpTicejuTkblMpFeYdl4ACRw2QlpGdc6ktdk4w8Oeecy9NNJw2R9sUcmt/SZd1JCv2k6GNq36aGpFboVgDOxwSzm26HBoS3cfRtTMUqFLsty+7R5VDx2hOkKWiDrQhNIy7bA5dePf8t9I/352Bm/fu1qHzENlIs6KSXduu/pd4P4RIQpuBUiSoExzguR2bFvvu5FQEw+3tYxgM9epfVtQYa32Q== 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=GapeZICg63arON+TMaGj2+EZ/fF07YJPgYCGC4ENTQk=; b=J7Fu7F4U6nY8WMkVuKgWZA5cXSvJPoOemYd46PJabdXzvbbCGylsIAQL6sCWUtScwnsoR3zr+lU9fqCHdXGtK9cHKQsyJVHDml0nxyO5nJgFk+HmKksrMEEWH8LihzchAU4I+cPJzk2SPBmxRLgdQfZETUWkLNfRPQRyoITQOnyIYhsSPaS/xiPhK/xwLi39rYVLaw0cCHbqtdiKCk0kgWgN1FbkSpPSuYI4ZUsfurFATf+LkeeNYsBnrn/HIwqy9Su+5CBdn/6DidsyibJhbEAaDAck74lvv+eItLNPWm5tmMtcQvt9JN5W6GkdkUZUNdmsxOhrIEdO1E/UD8RSXw== 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=GapeZICg63arON+TMaGj2+EZ/fF07YJPgYCGC4ENTQk=; b=XG1I9YvYdoaOaxFswqpalIFZqyEAeZFSJFhNGfXWqZHYPkSFq4fvHuUEJnwD3DQLPXZg5BBMOZeKeTvJcXEJ+0hTGEXbkr06QuKUI+r93ArqEhJ3K6JTOE5FXVw+hQwaiTZkQMhVpsROeBrLifdRbz6OZl4jtBm0DHCsTVvTSpU= Authentication-Results: linux-foundation.org; dkim=none (message not signed) header.d=none;linux-foundation.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by BYAPR10MB3494.namprd10.prod.outlook.com (2603:10b6:a03:11d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18; Tue, 23 Mar 2021 23:18:11 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::980e:61ba:57d2:47ee%6]) with mapi id 15.20.3955.027; Tue, 23 Mar 2021 23:18:11 +0000 Subject: Re: [RFC PATCH 2/8] hugetlb: recompute min_count when dropping hugetlb_lock To: Michal Hocko , Peter Zijlstra Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Shakeel Butt , Oscar Salvador , David Hildenbrand , Muchun Song , David Rientjes , Miaohe Lin , Matthew Wilcox , HORIGUCHI NAOYA , "Aneesh Kumar K . V" , Waiman Long , Peter Xu , Mina Almasry , Andrew Morton References: <20210319224209.150047-1-mike.kravetz@oracle.com> <20210319224209.150047-3-mike.kravetz@oracle.com> From: Mike Kravetz Message-ID: <52db15d1-4ed1-6c3c-b638-6efdccf6e62e@oracle.com> Date: Tue, 23 Mar 2021 16:18:08 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: CO2PR04CA0181.namprd04.prod.outlook.com (2603:10b6:104:5::11) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.2.112] (50.38.35.18) by CO2PR04CA0181.namprd04.prod.outlook.com (2603:10b6:104:5::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24 via Frontend Transport; Tue, 23 Mar 2021 23:18:10 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f7736d27-9133-42b7-c35a-08d8ee51ece7 X-MS-TrafficTypeDiagnostic: BYAPR10MB3494: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: W/dUrktjN/qNtpJoijQcAg15BkSeDwuipYZMQ5SR1JHbQX6MI32Qonrjyge/+fNn9J4xmHsQsCpMJO8BdvSalk5ji6Et4rNiHMzzru36kscoWIH71Rn7wXWPqEAUcMS3kr+RWQdpXePIp75AXVv1iRarv0T5eBGQeINLei8hfmKrEeo7hlpSIvpVR2e5/9KPhTiM4GLCx7mMW2mMoc4K1NRQ0uSux1eYWvplNbYElW70aK78j4HrAdY+4NF8DB+bHk7MlAX+O0Go1+0Bn/rLQm5zGyDaPYPYC3kZCXn0szKiEZnWgcd6UBkJiwpy3WRAdTrJmIJ7eywi16EoLQEy8Q7TdfUmiEsIFPc5afFkHwi65I7m61jUNo2TgnyvJZ6dUQoGkh3dnZ3OUEOiJAWCdj4lL5SCiIsZcUVF88zsDBPGM3RnWTq3Iw/CdEHvDzUr5Yxv6sGotk+YQ3YuDYdT8Q1AbBxYDs0fJXVi4vVOZALIPzlUQUqwQZefZZiqeliSIQVF+JrtvA6naC1mbk0meb9owGJ3RxwhFzeIIrOkwD1qIUxBoVe+LD2w3tB1pOBWVcltGKr4uq1dnzGwoVhUDz3XA5o9KKowR/M871QoO2XbjLg+lBTQz6Tgh/6xTm9JTVee7Ub4MulLqMxBm4FiO0u0yiGoFTtSfY5pejOkvfWFgFgLdNbc+Izrpzvjqw4Zq32i3EYGS1qL4jC7SoRQww== 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:(396003)(346002)(376002)(39860400002)(136003)(366004)(2616005)(31686004)(8676002)(36756003)(4326008)(52116002)(2906002)(26005)(66556008)(186003)(956004)(16526019)(44832011)(86362001)(8936002)(16576012)(31696002)(6486002)(66946007)(7416002)(54906003)(478600001)(5660300002)(110136005)(66476007)(83380400001)(38100700001)(53546011)(316002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?QjlodDVyMWR3UlNCV1BLZUFzNHlkUnRML0ZOclZDYm9oYjhRbkJXTXpoY3dk?= =?utf-8?B?TEQ3T0FWQmVaMDZwd2Q0Z1RnYTRFR2NvcnZnckh2QTZpM204NEtpcjVXZVlO?= =?utf-8?B?OUc3VHJ2bzRjM3NIWGNILzZRcm5BYkI2cE9IOVp4Mmdzays4SlR4ZDlMOGYx?= =?utf-8?B?aFNuWWZPUEs2L2x5b01JSnM2dDFiNjNDYi9oeTNZUFRLUmFTOTgrcDdCQVJE?= =?utf-8?B?UTI1ak8yaklGRHAwZlNwQTZJQXhOMGdTS3ZzcTA4dE5MYlgxYmdKcVpEdVV3?= =?utf-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1llazVkMW1WL2FHWnZt?= =?utf-8?B?aDhYdnlYTU5uUXhLcFpCNUhwZDdOdjNvYjNwK0xoMjIzZU5mQ3dsYlhDaVNH?= =?utf-8?B?NGdsZmZwT0YzNVhCTkpVQmdZVGk0dWRwTnJkNlZBWU5qWUIvendnakp1TExC?= =?utf-8?B?UVZMc2dyUCsrcXdFYWZneWZEaHVZU2dHOHlZc3N4bGJ5UE1ndko3WmRJbEZP?= =?utf-8?B?OElSK0hxQnRoaDQ1d1VaV0lUUWZQTGp1VldRc3UzeGhHTTJSS2MwU01hQkNE?= =?utf-8?B?Q1BrZDhIdERxVmVTN2NoNW1obE5GK1BhY0dDZkdzZGsyWGZiM2Z0MnFwOEl1?= =?utf-8?B?ZVNXdWpsSkpsUWtEMm1aTVJNbm1pbFhCRkhvZmxoaDVDbldFLzhuVGhNbVVn?= =?utf-8?B?SXk2dk9CUlVoZTFBSGh2T2lHN3J6dC9qQSt5VWdnaDFvMWJ3WkpiSG8wVEZv?= =?utf-8?B?d3VxajlzN0kvZnQ2cVFyaktIaVd1NGJpcXpnUFJhK0dwOXlnSHRYWUNaL3Jk?= =?utf-8?B?NU5sRnZJVFEyQ09xTlU5OGNmU0VFNnZHU3dCWEpobnJuQW1LTnNMRmtEUEdj?= =?utf-8?Q?D8z3l2As9WFvZ3l1u3ttxqtM5tOzOh2nDpWO55i?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f7736d27-9133-42b7-c35a-08d8ee51ece7 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 23:18:11.0653 (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: jF87I9c7/DC58kQfi+RpcTFd26fLRwI/yW1GADfgy883lEkI29GVAxEr7Pmot64MUYlOp6kCy9xfUKbfp44gQQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3494 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9932 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 spamscore=0 mlxscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103230172 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9932 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 bulkscore=0 spamscore=0 adultscore=0 clxscore=1015 malwarescore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103230172 X-Stat-Signature: zhzzqxuc4em341zhrcoahqymu7babrrn X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 4D2CBC0007D0 Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf06; identity=mailfrom; envelope-from=""; helo=userp2120.oracle.com; client-ip=156.151.31.85 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616541521-135930 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: On 3/23/21 1:14 AM, Michal Hocko wrote: > On Tue 23-03-21 09:01:02, Peter Zijlstra wrote: >> On Tue, Mar 23, 2021 at 08:50:53AM +0100, Michal Hocko wrote: >> >>>>>> +static inline unsigned long min_hp_count(struct hstate *h, unsigned long count) >>>>>> +{ >>>>>> + unsigned long min_count; >>>>>> + >>>>>> + min_count = h->resv_huge_pages + h->nr_huge_pages - h->free_huge_pages; >>>>>> + return max(count, min_count); >>>>> >>>>> Just out of curiousity, is compiler allowed to inline this piece of code >>>>> and then cache the value? In other words do we need to make these >>>>> READ_ONCE or otherwise enforce the no-caching behavior? >>>> >>>> I honestly do not know if the compiler is allowed to do that. The >>>> assembly code generated by my compiler does not cache the value, but >>>> that does not guarantee anything. I can add READ_ONCE to make the >>>> function look something like: >>>> >>>> static inline unsigned long min_hp_count(struct hstate *h, unsigned long count) >>>> { >>>> unsigned long min_count; >>>> >>>> min_count = READ_ONCE(h->resv_huge_pages) + READ_ONCE(h->nr_huge_pages) >>>> - READ_ONCE(h->free_huge_pages); >>>> return max(count, min_count); >>>> } >>> >>> Maybe just forcing to never inline the function should be sufficient. >>> This is not a hot path to micro optimize for no function call. But there >>> are much more qualified people on the CC list on this matter who could >>> clarify. Peter? >> >> I'm not sure I understand the code right. > > We need to ensure the function is evaluated each time it is called > because it will be used after a lock is dropped and reacquired so > numbers could have changed. The point of wrapping this into a function > is to reduce the code duplication IIUC. > >> But inline or not doesn't >> matter, LTO completely ruins that game. Just like if it was a static >> function, then the compiler is free to inline it, even if the function >> lacks an inline attribute. > > OK > >> Basically, without READ_ONCE() the compiler is allowed to entirely elide >> the load (and use a previous load), or to duplicate the load and do it >> again later (reaching a different result). >> >> Similarly, the compiler is allowed to byte-wise load the variable in any >> random order and re-assemble. >> >> If any of that is a problem, you have to use READ_ONCE(). > > Thanks for the confirmation! > Here is another thought. In patch 5 you suggest removing all pages from hugetlb with the lock held, and adding them to a list. Then, drop the lock and free all pages on the list. If we do this, then the value computed here (min_count) can not change while we are looping. So, this patch would be unnecessary. That is another argument in favor of batching the frees. Unless there is something wrong in my thinking, I am going to take that approach and drop this patch. -- Mike Kravetz