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=-2.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, 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 7501BCA9EBA for ; Tue, 22 Oct 2019 18:42:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 157832184C for ; Tue, 22 Oct 2019 18:42:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="lC/Nm3hC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 157832184C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8F36F6B0005; Tue, 22 Oct 2019 14:42:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A42D6B0006; Tue, 22 Oct 2019 14:42:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 793106B000A; Tue, 22 Oct 2019 14:42:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0033.hostedemail.com [216.40.44.33]) by kanga.kvack.org (Postfix) with ESMTP id 58C1E6B0005 for ; Tue, 22 Oct 2019 14:42:00 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 0533E83EC for ; Tue, 22 Oct 2019 18:42:00 +0000 (UTC) X-FDA: 76072290000.29.trees66_68b0996f7f337 X-HE-Tag: trees66_68b0996f7f337 X-Filterd-Recvd-Size: 5858 Received: from hqemgate14.nvidia.com (hqemgate14.nvidia.com [216.228.121.143]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Oct 2019 18:41:59 +0000 (UTC) Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 22 Oct 2019 11:42:03 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 22 Oct 2019 11:41:58 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 22 Oct 2019 11:41:58 -0700 Received: from DRHQMAIL107.nvidia.com (10.27.9.16) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 22 Oct 2019 18:41:57 +0000 Received: from [10.110.48.28] (10.124.1.5) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 22 Oct 2019 18:41:57 +0000 Subject: Re: [PATCH 1/1] mm/gup_benchmark: fix MAP_HUGETLB case To: Jerome Glisse CC: Andrew Morton , Keith Busch , LKML , , References: <20191021212435.398153-1-jhubbard@nvidia.com> <20191021212435.398153-2-jhubbard@nvidia.com> <20191022171452.GA5169@redhat.com> From: John Hubbard X-Nvconfidentiality: public Message-ID: <1095fd94-1c0b-de61-7ceb-c963e29575b6@nvidia.com> Date: Tue, 22 Oct 2019 11:41:57 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20191022171452.GA5169@redhat.com> X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To DRHQMAIL107.nvidia.com (10.27.9.16) Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1571769723; bh=JT3F3dTTKjKzOGM9MyYbERGszfW34mcd8Au3SboJObQ=; h=X-PGP-Universal:Subject:To:CC:References:From:X-Nvconfidentiality: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=lC/Nm3hCblA57K9jdrp7xEdECWAxkYwE4XhvI2g6acMV/up4ev7q990mcF1lsaBwU a/TEspy2QuvvK46Z/mk6KPGqX3iLVCJEqmS6EHRYABuh7xrDk3SVLTW81KTKwIr+5m IlbaJVPUVXF9v5RRjC5FLo3z9N5/9PxNqeIwDnfx4VYvrp2yBmI2CqYJV08yIHXMcv CKc6fPj8c25YM9KbpMGmWOulWkJQ1AEsS1RDZEKOVEFNrhhemvH6m2srdZYPEZSVG9 QEmcVj8k/U5mQX5wJZQMkLOh59wMVmryjHdSlSCN4on+pCxTNEUyrV/9PmQKROHIMk 8QHNdDn0gRkZw== 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 10/22/19 10:14 AM, Jerome Glisse wrote: > On Mon, Oct 21, 2019 at 02:24:35PM -0700, John Hubbard wrote: >> The MAP_HUGETLB ("-H" option) of gup_benchmark fails: >> >> $ sudo ./gup_benchmark -H >> mmap: Invalid argument >> >> This is because gup_benchmark.c is passing in a file descriptor to >> mmap(), but the fd came from opening up the /dev/zero file. This >> confuses the mmap syscall implementation, which thinks that, if the >> caller did not specify MAP_ANONYMOUS, then the file must be a huge >> page file. So it attempts to verify that the file really is a huge >> page file, as you can see here: >> >> ksys_mmap_pgoff() >> { >> if (!(flags & MAP_ANONYMOUS)) { >> retval = -EINVAL; >> if (unlikely(flags & MAP_HUGETLB && !is_file_hugepages(file))) >> goto out_fput; /* THIS IS WHERE WE END UP */ >> >> else if (flags & MAP_HUGETLB) { >> ...proceed normally, /dev/zero is ok here... >> >> ...and of course is_file_hugepages() returns "false" for the /dev/zero >> file. >> >> The problem is that the user space program, gup_benchmark.c, really just >> wants anonymous memory here. The simplest way to get that is to pass >> MAP_ANONYMOUS whenever MAP_HUGETLB is specified, so that's what this >> patch does. > > This looks wrong, MAP_HUGETLB should only be use to create vma > for hugetlbfs. If you want anonymous private vma do not set the > MAP_HUGETLB. If you want huge page inside your anonymous vma > there is nothing to do at the mmap time, this is the job of the > transparent huge page code (THP). > Not the point. Please look more closely at ksys_mmap_pgoff(). You'll see that, since 2009 (and probably earlier; 2009 is just when Hugh Dickens moved it over from util.c), this routine has had full support for using hugetlbfs automatically, via mmap. It does that via hugetlb_file_setup(): unsigned long ksys_mmap_pgoff(unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags, unsigned long fd, unsigned long pgoff) { ... if (!(flags & MAP_ANONYMOUS)) { ... } else if (flags & MAP_HUGETLB) { struct user_struct *user = NULL; struct hstate *hs; hs = hstate_sizelog((flags >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK); if (!hs) return -EINVAL; len = ALIGN(len, huge_page_size(hs)); /* * VM_NORESERVE is used because the reservations will be * taken when vm_ops->mmap() is called * A dummy user value is used because we are not locking * memory so no accounting is necessary */ file = hugetlb_file_setup(HUGETLB_ANON_FILE, len, VM_NORESERVE, &user, HUGETLB_ANONHUGE_INODE, (flags >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK); if (IS_ERR(file)) return PTR_ERR(file); } ... Also, there are 14 (!) other pre-existing examples of passing MAP_HUGETLB | MAP_ANONYMOUS to mmap, so I'm not exactly the first one to reach this understanding. > NAK as misleading Ouch. But I think I'm actually leading correctly, rather than misleading. Can you prove me wrong? :) thanks, John Hubbard NVIDIA