Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp6268648rwb; Tue, 9 Aug 2022 12:06:05 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Bn1bD9rXE+zIPqk5aZlpdqyaaMC1QTqDQXpTeZl/la0pxbLOYOk5Ts/Ke/D4QyejyS6z0 X-Received: by 2002:a63:1d63:0:b0:41d:7ab5:ef1a with SMTP id d35-20020a631d63000000b0041d7ab5ef1amr8680480pgm.566.1660071846379; Tue, 09 Aug 2022 12:04:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660071846; cv=none; d=google.com; s=arc-20160816; b=VV0sCPC87NNl41ugh12HTcxaA1mKd6Pz5MuygGW6bNH7X9lv40cLIrlVnu+iDnU1sw 4uXq56aAmxHWTSPDgi0NjmJRlnU2Dfo5DJKOr1CMe+koPm531oTkNDFomFjnSL1j4q1d jPgI7K/fM6emhgXBbx64znT4jdS5fZxVTl2/CQ/XHf107K3zSjkpvXdwyWOSKUaNZChe W3nLpxLExgYGgqSLsYjJ8q7FhSBViIKVUOwl8YdWxxwyMMcQj3W66YRjnpSXQj4EDsv3 eL95YcqWYRsWNfjhv8jYldnpNM7Ox31bjLwXKVTdDzEbWQJWe5cOh9LnONrbXrf0Puh5 nA+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:subject:cc:to:from:date; bh=Um8Hg2jrCOwKX4aIV/UICxc5nu+Jp9NOfvCQ+3ySSUI=; b=VtF5He9HacEYB4HShX7ccDU1Vu0uXv1hFnOnbmBFPhyAzFUzqUK7PpOH3QSqYqqFUk aDKtjAnqHBYOVOZTpeEPBkG1aMvxjYa7zVHDGV/rznz+/vSFew8egdcfhEaB7N3CWW76 3TrrbUPfyjj4/BYa2S0XDFUat7cEaTQTsPuVKoYJOjjxbbZ59jrYCKNnBCmdoyo0z24f CID595pPZDKpJPr4jKCXaLwCdzXfe3oj/nsgW3Sj485thdifjpFtmxKzyX64pFR9yUwe dpNFxaUxBcYSIfHxGEYnnVCPipCEG4cfyPGHabPZWtUANHg52lJLvj7mFpI6ah3cm0XU 3S3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a16-20020a63e410000000b0041d70c03da6si1291867pgi.855.2022.08.09.12.03.36; Tue, 09 Aug 2022 12:04:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245568AbiHISzI (ORCPT + 99 others); Tue, 9 Aug 2022 14:55:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343575AbiHISyw (ORCPT ); Tue, 9 Aug 2022 14:54:52 -0400 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FFF354666 for ; Tue, 9 Aug 2022 11:25:08 -0700 (PDT) Received: from [2603:3005:d05:2b00:6e0b:84ff:fee2:98bb] (helo=imladris.surriel.com) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1oLTuT-0004fH-Iw; Tue, 09 Aug 2022 14:24:57 -0400 Date: Tue, 9 Aug 2022 14:24:57 -0400 From: Rik van Riel To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Matthew Wilcox , Yang Shi Subject: [PATCH v2] mm: align larger anonymous mappings on THP boundaries Message-ID: <20220809142457.4751229f@imladris.surriel.com> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.31; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: riel@shelob.surriel.com X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Align larger anonymous memory mappings on THP boundaries by going through thp_get_unmapped_area if THPs are enabled for the current process. With this patch, larger anonymous mappings are now THP aligned. When a malloc library allocates a 2MB or larger arena, that arena can now be mapped with THPs right from the start, which can result in better TLB hit rates and execution time. Signed-off-by: Rik van Riel --- v2: avoid the chicken & egg issue with MMF_VM_HUGEPAGE (Yang Shi) mm/mmap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index c035020d0c89..1d859893436d 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2229,6 +2229,9 @@ get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, */ pgoff = 0; get_area = shmem_get_unmapped_area; + } else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) { + /* Ensures that larger anonymous mappings are THP aligned. */ + get_area = thp_get_unmapped_area; } addr = get_area(file, addr, len, pgoff, flags); -- 2.37.1