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=-5.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 A9DABC433E0 for ; Tue, 9 Mar 2021 10:32:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3EC7E6521D for ; Tue, 9 Mar 2021 10:32:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EC7E6521D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D331E8D00DD; Tue, 9 Mar 2021 05:32:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CBDD68D007F; Tue, 9 Mar 2021 05:32:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B10AC8D00DD; Tue, 9 Mar 2021 05:32:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0166.hostedemail.com [216.40.44.166]) by kanga.kvack.org (Postfix) with ESMTP id 947F88D007F for ; Tue, 9 Mar 2021 05:32:34 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 5A91B4DC3 for ; Tue, 9 Mar 2021 10:32:34 +0000 (UTC) X-FDA: 77899971828.21.3FC8E84 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 98C73E8 for ; Tue, 9 Mar 2021 10:32:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615285953; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kc+ippEfdybOuxAlfDDRv/mawpuuZ9lZY0w3v8v7TMw=; b=QZwmbSEFDW+MY/EuRIQvhqu6xG0I5u6MEfZ8q8OKuNBVp6bvXgtcZCUcX3FJTNQcpy8kL1 T12Lu3ZZC9Ix3hEj7x7xokUUCsIOBoq2fKjGOhKT+zAh+YBFnaG9aDLaNyedz3mOjixrUq Wnv7+Tv9RMCk73L+cGR7vSP64MutR8k= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-541-4AfvGYJcOfKYWjpl-HUnsA-1; Tue, 09 Mar 2021 05:32:29 -0500 X-MC-Unique: 4AfvGYJcOfKYWjpl-HUnsA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4E460108BD07; Tue, 9 Mar 2021 10:32:28 +0000 (UTC) Received: from [10.36.114.143] (ovpn-114-143.ams2.redhat.com [10.36.114.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 86E2A5D6D7; Tue, 9 Mar 2021 10:32:26 +0000 (UTC) To: Bruce Merry , Linux MM , Mike Kravetz References: From: David Hildenbrand Organization: Red Hat GmbH Subject: Re: Is MAP_POPULATE supposed to fail silently? Message-ID: Date: Tue, 9 Mar 2021 11:32:25 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 98C73E8 X-Stat-Signature: cymxukbp3xharim6ssdk7pde46ufqd85 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf20; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=216.205.24.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615285950-816936 Content-Transfer-Encoding: quoted-printable 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 09.03.21 10:33, Bruce Merry wrote: > Hi >=20 > I've run into a problem with using mmap(..., MAP_ANONYMOUS |=20 > MAP_POPULATE | MAP_HUGETLB). If there are no huge pages available due t= o=20 > vm.nr_hugepages (or hugetlb.2MB.rsvd.limit_in_bytes cgroup setting) the= n=20 > the mmap call fails and I can gracefully fall back to 4KB pages.=20 > However, if neither of the above apply but hugetlb.2MB.limit_in_bytes=20 > prevents pages being mapped, then it appears that MAP_POPULATE is=20 > silently ignored (according to mincore), and rather than being able to=20 > gracefully fall back, attempting to use the memory results in SIGBUS. I would have imagined that the hugepage reservation would fail. But=20 looks like they might get reserved, however, actual population is=20 restricted using cgroups later. Huge page reservation is actually pretty weird in some special cases=20 (including NUMA bindings). >=20 > Is that expected behaviour? I don't see anything in the mmap(2) man pag= e=20 > about it being best-effort (in contrast to MAP_LOCKED, which explicitly= =20 > says the call won't fail if it can't lock the memory). I think it has been best-effort forever, just like MAP_LOCKED. You could use memfd_create() to create an anonymous file backed by huge=20 pages, then try allocating backend storage using fallocate() - which=20 fails in a safe way. You just have to make sure to map it MAP_SHARED=20 later to avoid nasty side effects with private mappings + fallocate(). >=20 > This is on Linux 5.8 on Ubuntu 20.04. I can provide sample code if it's= =20 > of interest, or test on a newer kernel if it'll help. >=20 Note that I'm working on a reliable populate mechanism that can also=20 work on parts of a mapping only, especially relevant in combination with=20 MAP_NORESERVE. Not sure if that applies to your use case, sounds like=20 memfd_create() +fallocate() could be good enough - unless you also=20 really want to have all page tables properly populated already or really=20 need MAP_PRIVATE. https://lkml.kernel.org/r/20210308164520.18323-1-david@redhat.com --=20 Thanks, David / dhildenb