From patchwork Fri Jan 11 20:10:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 10760663 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 106D313B4 for ; Fri, 11 Jan 2019 20:12:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00BFE2A14C for ; Fri, 11 Jan 2019 20:12:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8FF92A1B8; Fri, 11 Jan 2019 20:12:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50DA82A14C for ; Fri, 11 Jan 2019 20:12:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C91B8E0002; Fri, 11 Jan 2019 15:12:35 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 077D48E0001; Fri, 11 Jan 2019 15:12:35 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA9018E0002; Fri, 11 Jan 2019 15:12:34 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f71.google.com (mail-yw1-f71.google.com [209.85.161.71]) by kanga.kvack.org (Postfix) with ESMTP id BA62D8E0001 for ; Fri, 11 Jan 2019 15:12:34 -0500 (EST) Received: by mail-yw1-f71.google.com with SMTP id i2so8402477ywb.1 for ; Fri, 11 Jan 2019 12:12:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id; bh=n1i+b3unkjpNYxqcEhfDSmY/9FySvsyj3Uo3w/fMxNE=; b=XTDyEQzv3B9FSDzzZVAC+/Mi7A2SuE5FkZQ6hgYPfi+qN7T9604gnlnto5xCqpOoNG LMiIQDAAnhJkq92lMG+2ai1Kpt++utEJWsSjK3jIP00iCsAwuEAECj8/tvxsPLjFxErU dldz/NaFApMRI3qBksolha9arzsGp19Q5aVJ+edHcXDXlL6yDvbDOU+r/Fn6hcvByru7 WCm+c/8hduBcpgVq5eRUoUMKAF9s7rn5UMF2xh5plD0S+yCQGFH2swBAIFFjhseNJ/Jf IwJjf31OqZpfDIDDK7RRwALykJdzBEjMtPXzcJ9FRhNSSru05lBQT1W5FKYP+hcWWim/ 3y3Q== X-Gm-Message-State: AJcUukfNfY751RFlpKwlcgXbf6IwCbiVvH0dvYb6e1eVe4fsSsoSs26g Pl/GBCLwGhj29eCLqehLAG+fzo3geGfdi5n1F/ssd+5BV/w/kUH93Q5nOEwgEGITSrc8LBRykoS 836GWD0Qt7POK/3sRLcmRbXU5i8DHG1O5TYvU5N1YRb2m/2NUz/udl1In2tnjUS4U0Q== X-Received: by 2002:a25:bcce:: with SMTP id l14mr5508982ybm.457.1547237554327; Fri, 11 Jan 2019 12:12:34 -0800 (PST) X-Google-Smtp-Source: ALg8bN6mywSoYL/CkQ3iWDGAOjmiePnN8Z0ptOsw+VTqvgASLvDc7Ml1KXoJ+RdYmWtFisMxyf5p X-Received: by 2002:a25:bcce:: with SMTP id l14mr5508937ybm.457.1547237553665; Fri, 11 Jan 2019 12:12:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547237553; cv=none; d=google.com; s=arc-20160816; b=kt4hFtqRV6eMGPuvDA9fEbLK7uqSP3pOMT+kcpOSMzf1UzcC9Ov1oJ8ifgmj6UPola /snW6aOP+dEfyWe9A7WPfi3BZnbFusYcQEfFTjj4F9eJktsM3IaZZ7A/QvbRN+HpjCgM rufaA+MD1YHMn8pCNN5bKIz5oMuDo9n/wI2KL+LWZ/6Ov/hEhFYe4Q7O+/hW9YTF7L2L OMeCsxcmt+H1r2ZZwUtAiJ711cPGXNZBKgrACYvytu70ahL29H+CYD+C5zzePnTaJ0P2 3RXQvXLllIQMXP8Frv3XGUM0qr+a+XqPh0J43jxzmFUT7mWvoFZNdsKAEoi88vVqTl9X Kc/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=n1i+b3unkjpNYxqcEhfDSmY/9FySvsyj3Uo3w/fMxNE=; b=T3gUGtdCnX5LZZM+hrN6nWs1qHRX4cFkGrvzmJG/UliCN6Vb9k8+hNKiLPq3e/Qm0X CwwxqJaBlUBIrD1cSdhG7UgIrNBS2zYWKmkdBmnCprRdZnvyr5j+QNaU4JQ/8qN8col/ F3uPUbB5AZEFyI1NflZwFhm6SPTrhX1rn2h7iNTW8OuOhapDXP12GQ7/hIlGWtc/wPII HWoLf6/JvdorpJi+X9o8DtLBvZFyWpGB0yNSSA7TgrUWeO0xVND5LrYdiw4iuExbsWz6 pJ83l0RNuLkCLP8xeIJYIe4V71wgrJS+ZC7ZDAqqRCSUS4nEtXj1VICpvakNIzkUz4qP SKhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=YSHauSFf; spf=pass (google.com: domain of mike.kravetz@oracle.com designates 141.146.126.79 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from aserp2130.oracle.com (aserp2130.oracle.com. [141.146.126.79]) by mx.google.com with ESMTPS id m7si46489497ywe.146.2019.01.11.12.12.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Jan 2019 12:12:33 -0800 (PST) Received-SPF: pass (google.com: domain of mike.kravetz@oracle.com designates 141.146.126.79 as permitted sender) client-ip=141.146.126.79; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=YSHauSFf; spf=pass (google.com: domain of mike.kravetz@oracle.com designates 141.146.126.79 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x0BK3YQ7038845; Fri, 11 Jan 2019 20:10:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=n1i+b3unkjpNYxqcEhfDSmY/9FySvsyj3Uo3w/fMxNE=; b=YSHauSFf1/rr7TAiE5uAWY4ThO9J3AN3nFh5+xR+uUG35wUhXc2r5mWzSNluzu9CYXNu nP4ILwnO5vnbzUFHZF+jkzN7MnOQCJ7fNQz8+O6yht6eWBpb9m+/IieJpIydiNxc3tJU jcDFwWqDFm1p1QJat/S2EbMu//+FJh8ChFJTnbhxHdS7vmhAfp8lUuYBapcXwOrYG9H9 mGUFSyea19jcHRtmH4tmEfh0L5HQk4BMK7kWufEoyCUR1wuWFDSu8jxg+YSkhfcFHDHj q8xrAp0jzTEmFL5/VXqWm0+2MUxfkVIljvrsxZA52io9jz8LqIb6JO6CV6mlIVL+HAjc oQ== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2130.oracle.com with ESMTP id 2ptj3ef3dn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Jan 2019 20:10:17 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x0BKAGmd022776 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Jan 2019 20:10:16 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x0BKADA6013556; Fri, 11 Jan 2019 20:10:13 GMT Received: from monkey.oracle.com (/50.38.38.67) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 11 Jan 2019 12:10:13 -0800 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Hugh Dickins , "Kirill A . Shutemov" , Michal Hocko , Dan Williams , Matthew Wilcox , Toshi Kani , Boaz Harrosh , Andrew Morton , Mike Kravetz Subject: [RFC PATCH] mm: align anon mmap for THP Date: Fri, 11 Jan 2019 12:10:03 -0800 Message-Id: <20190111201003.19755-1-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.17.2 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9133 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901110159 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: X-Virus-Scanned: ClamAV using ClamSMTP At LPC last year, Boaz Harrosh asked why he had to 'jump through hoops' to get an address returned by mmap() suitably aligned for THP. It seems that if mmap is asking for a mapping length greater than huge page size, it should align the returned address to huge page size. THP alignment has already been added for DAX, shm and tmpfs. However, simple anon mappings does not take THP alignment into account. I could not determine if this was ever considered or discussed in the past. There is a maze of arch specific and independent get_unmapped_area routines. The patch below just modifies the common vm_unmapped_area routine. It may be too simplistic, but I wanted to throw out some code while asking if something like this has ever been considered. Signed-off-by: Mike Kravetz --- include/linux/huge_mm.h | 6 ++++++ include/linux/mm.h | 3 +++ mm/mmap.c | 11 +++++++++++ 3 files changed, 20 insertions(+) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 4663ee96cf59..dbff7ea7d2e7 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -117,6 +117,10 @@ static inline bool transparent_hugepage_enabled(struct vm_area_struct *vma) return false; } +#define thp_enabled_globally() \ + (transparent_hugepage_flags & \ + ((1<flags & VM_UNMAPPED_AREA_TOPDOWN) return unmapped_area_topdown(info); else diff --git a/mm/mmap.c b/mm/mmap.c index 6c04292e16a7..f9c111394052 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1864,6 +1864,17 @@ unsigned long mmap_region(struct file *file, unsigned long addr, return error; } +void thp_vma_unmapped_align(struct vm_unmapped_area_info *info) +{ + if (!thp_enabled_globally()) + return; + + if (info->align_mask || info->length < HPAGE_PMD_SIZE) + return; + + info->align_mask = PAGE_MASK & (HPAGE_PMD_SIZE - 1); +} + unsigned long unmapped_area(struct vm_unmapped_area_info *info) { /*