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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CC1AC433EF for ; Fri, 28 Jan 2022 09:55:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 82DF06B0071; Fri, 28 Jan 2022 04:55:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7DD7E6B0072; Fri, 28 Jan 2022 04:55:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 67D706B0073; Fri, 28 Jan 2022 04:55:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0249.hostedemail.com [216.40.44.249]) by kanga.kvack.org (Postfix) with ESMTP id 558E86B0071 for ; Fri, 28 Jan 2022 04:55:08 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 006698249980 for ; Fri, 28 Jan 2022 09:55:07 +0000 (UTC) X-FDA: 79079237496.22.074B0A5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 86A24140028 for ; Fri, 28 Jan 2022 09:55:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643363706; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ylz87V1WG45yYtILZ9U05QYarg4IApL3yG/h/CzZXDg=; b=BIG4/eTjbCwNMmsCfQpH+lbSOLaEXMhLZRq1J1w9yXEnK39AspHKh+sgN5Ii44pGfkWCvM 5zbWKS9rRPjVZY50UBupYMmixvABlU1s2wl/hiCVV08egk4Y47kuqHFu68dCWNW0gmjpmH f3pCGzZ3OkqumJTAVqyKvEzn30KqQzE= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-301-u3mjVNUDMe2paoNsIZ0ezw-1; Fri, 28 Jan 2022 04:55:03 -0500 X-MC-Unique: u3mjVNUDMe2paoNsIZ0ezw-1 Received: by mail-wr1-f71.google.com with SMTP id b3-20020a5d4b83000000b001d676462248so2052938wrt.17 for ; Fri, 28 Jan 2022 01:55:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=Ylz87V1WG45yYtILZ9U05QYarg4IApL3yG/h/CzZXDg=; b=L/yG7UMEYJPfBW350Z1AwsUy2zCiJj6pA9P8pirfnlBqmNUPUZoxzUYqz7askSrcJQ 81qLGH9wx4x4Tay7nx0p09ditsegXlltDQTU8OwRP16stoe6WqQXFrMV7FLrPQasqJ6N sNIqrJuXQJjAUnK2zWju8+IsHIJIBrXkKi+gCmT3UMdkXEd8FLNkNxpocpKYO7SyJkR/ +orWNvt3FuMycrcq0ITaXcfy6u9YtRi/+ulv+sInYP2ZWjYiYhQlci40xs3wD2gd0umG iBnpgrnDiFXqsjXI5w396YKUo0AX01PIOkofi7c+vjYpBo4ZtPxr2Su6V2oikPQdW3RS e07Q== X-Gm-Message-State: AOAM533Ruetp9/m4K+oUAiE+DWWO66oJjog7SzouBuyw3rH96BRef5b0 eNqvy0JbXytN06BWzBzQ1k7wCDS3yeO14iLengEfQ/XCVQmrzE2sQx/JmN3SlRm3HARg57Fx0Uf YDAjoGWoNFog= X-Received: by 2002:a5d:4205:: with SMTP id n5mr6324461wrq.479.1643363702397; Fri, 28 Jan 2022 01:55:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJzLum6pte96pf8j4lks4HqDl2FTk5t1ERYShrc8FV8j9dMFbmCX/cqz6Z/mfrBEG7A5whbDIg== X-Received: by 2002:a5d:4205:: with SMTP id n5mr6324431wrq.479.1643363702152; Fri, 28 Jan 2022 01:55:02 -0800 (PST) Received: from ?IPV6:2003:cb:c70e:5c00:522f:9bcd:24a0:cd70? (p200300cbc70e5c00522f9bcd24a0cd70.dip0.t-ipconnect.de. [2003:cb:c70e:5c00:522f:9bcd:24a0:cd70]) by smtp.gmail.com with ESMTPSA id n26sm1671855wms.13.2022.01.28.01.55.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 28 Jan 2022 01:55:01 -0800 (PST) Message-ID: <2ddd0a26-33fd-9cde-3501-f0584bbffefc@redhat.com> Date: Fri, 28 Jan 2022 10:55:00 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 To: Mike Kravetz , linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Michal Hocko , Naoya Horiguchi , Axel Rasmussen , Peter Xu , Andrea Arcangeli , Mina Almasry , Shuah Khan , Andrew Morton References: <20220113180308.15610-1-mike.kravetz@oracle.com> <21242c94-6748-b76d-f38e-5ac140c6117b@oracle.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [RFC PATCH 0/3] Add hugetlb MADV_DONTNEED support In-Reply-To: <21242c94-6748-b76d-f38e-5ac140c6117b@oracle.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 86A24140028 X-Stat-Signature: chymi7zferkptpp4qgxxkqzgwiyops5j X-Rspam-User: nil Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="BIG4/eTj"; spf=none (imf23.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1643363707-23757 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 27.01.22 18:55, Mike Kravetz wrote: > On 1/27/22 03:57, David Hildenbrand wrote: >> On 13.01.22 19:03, Mike Kravetz wrote: >>> Userfaultfd selftests for hugetlb does not perform UFFD_EVENT_REMAP >>> testing. However, mremap support was recently added in commit >>> 550a7d60bd5e ("mm, hugepages: add mremap() support for hugepage backed >>> vma"). While attempting to enable mremap support in the test, it was >>> discovered that the mremap test indirectly depends on MADV_DONTNEED. >>> >>> hugetlb does not support MADV_DONTNEED. However, the only thing >>> preventing support is a check in can_madv_lru_vma(). Simply removing >>> the check will enable support. >>> >>> This is sent as a RFC because there is no existing use case calling >>> for hugetlb MADV_DONTNEED support except possibly the userfaultfd test. >>> However, adding support makes sense as it is fairly trivial and brings >>> hugetlb functionality more in line with 'normal' memory. >>> >> >> Just a note: >> >> QEMU doesn't use huge anonymous memory directly (MAP_ANON | MAP_HUGE...) >> but instead always goes either via hugetlbfs or via memfd. >> >> For MAP_PRIVATE hugetlb mappings, fallocate(FALLOC_FL_PUNCH_HOLE) seems >> to get the job done (IOW: also discards private anon pages). See the >> comments in the QEMU code below. I remember that that is somewhat >> inconsistent. For ordinary MAP_PRIVATE mapped files I remember that we >> always need fallocate(FALLOC_FL_PUNCH_HOLE) + madvise(QEMU_MADV_DONTNEED) >> to make sure >> >> a) All file pages are removed >> b) All private anon pages are removed >> >> IIRC hugetlbfs really is different in that regard, but maybe other fs >> behave similarly. > > Yes it is really different. And, some might even consider that a bug? > Imagine if those private anon (COW) pages contain important data. They > could be unmapped/freed by some other process that has write access to > the hugetlb file on which the private mapping is based. Right, that's also what I once worried about in QEMU code. But then I realized that any kind of fallocate(FALLOC_FL_PUNCH_HOLE) on a file shared by multiple parties mapped MAP_PRIVATE might be bogus already. Assume you have a VM running with MAP_SHARED on a file. The file contains the VM memory state. Assume you pause the VM and want to convert it into 2 instances that will continue running independently based on the captured file state. You'd have to MAP_PRIVATE the file such that both VMs start with the original state and only see their modifications. ... but if one process decides to fallocate(FALLOC_FL_PUNCH_HOLE), for example, due to memory ballooning, even a page that's still shared by both processes (!COW), you'd corrupt the other VM. So my assumption is that MAP_PRIVATE in combination with fallocate(FALLOC_FL_PUNCH_HOLE) on a file mapped by more than one process is just bogus already. > > I believe this same issue exists for hugetlbfs ftruncate. When fallocate > hole punch support was added, it was based on the ftruncate functionality. > > I am hesitant to change the behavior of hugetlb hole punch or truncate > as people may be relying on that behavior today. Your QEMU example is > one such case. Yes, I assume we're stuck with that. -- Thanks, David / dhildenb