From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id DE5703858D20 for ; Fri, 14 Apr 2023 16:27:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DE5703858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33EEmqW1012212; Fri, 14 Apr 2023 16:27:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=references : from : to : cc : subject : in-reply-to : date : message-id : content-type : mime-version; s=corp-2023-03-30; bh=QdIMO5wAa6nJSoNnsXpOQe0mOUyeulPGtJBZNBogaMs=; b=lKWSTc2A9p1DS8BSuyw8VqBs5MYBfre13IFuIIR0mIdVeq+g312Mxs44Ggv8J4sSkJcT BKTc3nBcowzUY9hLGPIBC+yh09KSgcmwXLPg3mSMxpsfeIm4zRMaMFZUDb6XJ4dh1RXl X4H3znSglln/KBU+x57r7y54AbiEObhmUkBheVcm5QEfILwdFEDmOqYv3XKIdw4Qn3ki u2TqryMub6ZkEeFniOFX4I5B58s5JH9a35ltBjDkyAzGi+tsjGPTYei8pESKR19xxvWo ebN4lkl133jDOtTr0kbD84P+Ee439v1PXPQY3nbI0lZn1T1vIYhvVqZiRKD78sVOntyW vw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pu0bwpjh2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 14 Apr 2023 16:27:43 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33EGFX5a011350; Fri, 14 Apr 2023 16:27:42 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2169.outbound.protection.outlook.com [104.47.58.169]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3puw96aq1t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 14 Apr 2023 16:27:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kvrzh3mFpl+x6Lk8hH2h0eMpXfBDmoGKDhH4uOv+gzvYiPNSolsH47ZR99dluDv0OZ4ADJxq7pbGeQ81Xw8meSNZIZWyfvm+VYmvKJscN/pxnyMW2+hUHPmHm5JEMGz3VCE3lG5huTAHZRvby6hmAc/Utq+WWZY9kAb/eLTysgqVC3h9VndpXgMSJfR35/x4LbWHo6ZFw5XRCtd74b4JERk87TjWL14AQCLY23SMnQ3VSC4VCT28MuKN2616HikQiqT7Kr3REgx+AsI3XJjWxEgxJTZg2Gnv+WKuNXAErh5JRPlEMtT5+FU8R4TL1h2gGNa+aRgousaXt/0ww2XftQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QdIMO5wAa6nJSoNnsXpOQe0mOUyeulPGtJBZNBogaMs=; b=cGkimdteNWBxdylQNlVqDPgjjV6X7kwgrIaQj+pP8U20fVrvi7OkHP4TwTWnQyuqbQFL8YmgDkocWVpOB16tusT7QrbLx58kUVKY32JaAsZrk259UHx5r0j9kTBk2OWZb8gnSeYrCunsRt0M2JSZwBdKGh+nJl0KhW70Ea4EFUsjS0b1kzvjlmfNrHnBwaJv444y4YgVhBs7jdbIHnlcYmh8TucyF2f5k8TxMOSvMYrYTr7RNAY06xz+0fn3pZyAjM1vuVCmjWqzJcm3Hab1Pyxg1+9L9G0K4g0n0gMPzGB7soklpuf+CaYpX4aq3pnwDxt9jjNbGNpAPxXS2/QTcA== 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=QdIMO5wAa6nJSoNnsXpOQe0mOUyeulPGtJBZNBogaMs=; b=LQ4OiycHJCxN3DEP7P4WL1xe0yBd1GO7aada92vBfCShTEAvNFBmJ+mM8EL0KReJgKCAm80lAtQIg9kMi1G1qkVC3SjbcctlHimxbQRf8e1XRerDBbCR4VM6HtyAzEp+FWgbiz/UFMr0hZRaECnPBGUIWjVIJUef62MwZH0xdLU= Received: from BN6PR1001MB2340.namprd10.prod.outlook.com (2603:10b6:405:30::36) by IA0PR10MB7601.namprd10.prod.outlook.com (2603:10b6:208:48e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.43; Fri, 14 Apr 2023 16:27:40 +0000 Received: from BN6PR1001MB2340.namprd10.prod.outlook.com ([fe80::4998:96fd:86b1:a388]) by BN6PR1001MB2340.namprd10.prod.outlook.com ([fe80::4998:96fd:86b1:a388%6]) with mapi id 15.20.6277.036; Fri, 14 Apr 2023 16:27:40 +0000 References: <87mt3bda4s.fsf@oracle.com> <7fd2f7b1-73d3-1bc3-cabf-c67d1930cefc@linaro.org> <878reud7nu.fsf@oracle.com> <87y1mubjtr.fsf@oracle.com> User-agent: mu4e 1.4.15; emacs 28.1 From: Cupertino Miranda To: Wilco Dijkstra Cc: Adhemerval Zanella Netto , 'GNU C Library' Subject: Re: [PATCH v5 1/1] Created tunable to force small pages on stack allocation. In-reply-to: Date: Fri, 14 Apr 2023 17:27:36 +0100 Message-ID: <87ttxibf9j.fsf@oracle.com> Content-Type: text/plain X-ClientProxiedBy: LO2P265CA0205.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9e::25) To BN6PR1001MB2340.namprd10.prod.outlook.com (2603:10b6:405:30::36) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN6PR1001MB2340:EE_|IA0PR10MB7601:EE_ X-MS-Office365-Filtering-Correlation-Id: 8f7f939d-b02f-4b3b-fce3-08db3d052a5d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9a1e1LwhZo5TwPJO55tLdbviP76IhqT8wYlbpdL/PvkkVBJkvUM5chrOgxCbl++DgMVN7OVGTJB3pEZDWF9G02TEjldHwvO3QCggodrsyNrUSlF/Utt6plN25JWaj3Tvfd5XAaod+pN39yC682JkT3pePi6S3q+/Gl4KfYr8xqlhrUzy8LqUHHciQPy/w7hlXrhullWm3nw0n+DFElnh4L+ZqT6qCKNJqsJWjFg/eoaCtIAROpD/8f5DzgZGUO8jJBtaWF4KFTbzsruw5GXr+9POKO8jEV3SxijCV1T3UetU+CA8l26ngq3WFgpCzqshF3YnW2TxItK2E7Ui6uVjhhyn8wrz5DJQpECJeuERzggu+YJlyKNAzK4sTHZo1GDxQCAnvlHopZaLOOB9Vw1AC8OesZXXvc7dOBA9G39jLOIO89+UfK9bd9LiZG7Ho23sJVu1QYbOvcQP8XDnQG2pDI/88cR4uQKjLZaJnqyWd+fLWSK+5ulzbbSVL5/uCat+YYGKZz0osr61zRWX54nePx3SfqMN5r3FX9kpXNir8oD67jEqOTh5XKVOerzRCdie X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN6PR1001MB2340.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(376002)(346002)(366004)(396003)(136003)(39860400002)(451199021)(8936002)(186003)(6512007)(6506007)(6666004)(5660300002)(44832011)(478600001)(86362001)(38100700002)(316002)(83380400001)(54906003)(41300700001)(2906002)(66476007)(36756003)(2616005)(66556008)(6486002)(66946007)(4326008)(8676002)(6916009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?XnqyvvZ7c5x39LtSF28jX3iJExN6SJ2aDBUK26oYV/kMH7k5PhmSsL/FLrZ3?= =?us-ascii?Q?gOZdSVNrYr/8yoOK6StROwavngg049m7e2Bt+mE29Xfu/iJf3bAOCnKeHDmc?= =?us-ascii?Q?R6mZWIntgJFg6L9O6TeVQyHNQdg33ubvu1v1bWZMMkHLIuZPI2kdi4khOPBm?= =?us-ascii?Q?qjeNoVN209DFN70GMkLnXZbfdDVDXeSaiHiCOsy8pFDw4IRIgRSggziSFDHN?= =?us-ascii?Q?7KO7ICU/DNyC7Uyk7JAv1nHyq4uNu71Osu5LQIwbv1kQb/K9ZIaAx1xv27NG?= =?us-ascii?Q?tsVtMTMyVeWWP7dGTc9E84w72jHUM5n5+BB23ZvfVJn/d5to4Uh5BWk/gPMz?= =?us-ascii?Q?eseGCuCKEwdX/3Vfg6uawNbuaZMmIdEqfY5TU+Yd5JpUDYwsAehuaPJheD0o?= =?us-ascii?Q?Un3+8uwXFdbpdB9wqeCv6+vv+y6NKHABuGGXs/jA1erbX6Jggh3G4CqZaeeC?= =?us-ascii?Q?w4VZel1Tjpxndc2eLflz3rj7NanoircURxMHZGe4zLROSsrCFdDkaaa07Pp5?= =?us-ascii?Q?dLsQLV/oyr1gU0yYHleURI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rFK3oddNH5Ppd1R6DSx0HBNmHUwoZ9VwsRQEuNZPQ1p1/Nvu/y7dFZFLE0XSV14ooJsZMjk8XLu0rqKKDk2RZAwhopdYCLcKGlOzOPPQR8L X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8f7f939d-b02f-4b3b-fce3-08db3d052a5d X-MS-Exchange-CrossTenant-AuthSource: BN6PR1001MB2340.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Apr 2023 16:27:40.1420 (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: v6eznuQpIadWaml76xyMxLF+dsRPPbKClmw3Tz+UHAeiiWN7jdQ4LIQMzq6pZYmnSTXXzXI1rZ4GUBz8zfIHI+yyr8cfelFjgNwfemnFRTs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR10MB7601 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-14_09,2023-04-14_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=830 adultscore=0 suspectscore=0 mlxscore=0 bulkscore=0 malwarescore=0 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304140144 X-Proofpoint-ORIG-GUID: SqKIkRBKrOOS40d5nNQ-0IpZCtXdu2MH X-Proofpoint-GUID: SqKIkRBKrOOS40d5nNQ-0IpZCtXdu2MH X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: > Hi Cupertino, > >> To contextualize the tunable was proposed to reduce stack memory usage while >> still having THP enabled in the kernel for all other allocation types. >> We identified a scenario which THP will be initially used for stack >> allocation, but once protection gets set for the guard region, it will >> split the huge page into 4k pages, when the 2M page is already marked >> dirty, not really making use of THP benefits, but bloating RSS as all >> the small pages are assumed as touch. > > So after the guard region is reserved, we lose 2MB of real memory that will > never be used (as only the top of the stack is used), right? Right > The next question is whether the splitting of one huge page causes the whole > stack mmap to use small pages too. If so then it never makes sense to use huge > pages for the stack if the guard page is smaller than a huge page (since you lose > 2MB of memory and never use huge pages anyway). If one wants to get guardsize of 2MB they can specify that in pthread_create attributes. That is already controllable through pthread api. My tunable is really an optimization to reduce RSS, i.e. always avoid THP to be used for stack allocation. Even if you want to allocate big stack spaces, those would be using small pages to reduce RSS. Adhemerval suggestion is more of an heuristic to detect when, although you prefer THP to be used, the configuration of the stack would not allow to assign a huge page anyway, and instead of having the kernel bloat the RSS by 2MB at allocation time, one would advise the kernel not to attempt THP here. When glibc changes the protection mode for a small guard space that fits in the same huge page as the rest of the stack, although the huge page is split into 4k pages, the RSS would be kept at 2MB, since the huge page was already written on and is marked as dirty. This is what is attempted to be avoided in Adhemerval patch by madvise-ing in advance. > Alternatively, if the rest of the stack can still use huge pages, we actually lose 4MB > of RSS (since the top of the stack is a large page and is obviously used). As I > explained, huge pages for stack can still make sense for applications that need > a large amount of stack. For these cases you could just increase the guard size > to avoid wasting the extra 2MB of memory. > >> I think you are suggesting the oposite, i.e. it would increase RSS. > > Where did I suggest increasing RSS? Wouldn't increasing the guard size to 2MB not increase RSS by 2MB ? > >> Also Adhemerval patch intention is not to detect when the THP for stack >> allocation makes sense, but rather the oposite. It is to detect when THP >> will not bring any benefit. > > It doesn't matter which way around you do it - it is absolutely trivial either way. Regarding condition changes I made in Adhemerval patch, it is likely that it is not complete. In any case, the approach is more about detecting when THP are not going to be possible, rather then changing allocation parameters to make it possible. Cheers, Cupertino