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=-9.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 7366AC433E0 for ; Mon, 1 Feb 2021 19:20:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 318A860234 for ; Mon, 1 Feb 2021 19:20:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229646AbhBATUR (ORCPT ); Mon, 1 Feb 2021 14:20:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231152AbhBATUH (ORCPT ); Mon, 1 Feb 2021 14:20:07 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00775C061573 for ; Mon, 1 Feb 2021 11:19:26 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id c4so15162206wru.9 for ; Mon, 01 Feb 2021 11:19:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=bpPec5GaqUSpiFKH55nc+mRy05EutxL4zvW4JDLSH2w=; b=L1BFVP6DKWTRXYjr/HG5kzKEhOwfZpItCIQI+widwKu8yrXD87Lkr3WHZ+WOh8FijZ 5Yu5VU4MipyyJdu4pN+2CIL9GE0jLdCHpnVSpNjppS0CngxZjBaH17J+P0iFmdebm5ym SNpFdMpRHgguYbfn7wb5MaymuFam3ufPha33+aHG2UjDnQXhe1xjyo5g4GzkxqGCraS6 G17Ti1vasQlQsUHGZNiqYEvxCROKO9WOe7SRea2EjzigXHmpIWuHinzDoBadufY6zXh/ PJLmLLh62TqV904Q6DHSUGdNpjJfMXCC3eampfSGwkHCgIZnvIDLWF9LSDff6vnUND78 xwWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=bpPec5GaqUSpiFKH55nc+mRy05EutxL4zvW4JDLSH2w=; b=oF8NxkUWr2xNMxUaiFoT3/pT3ZdUXQOJx6q5pfOyFlGJo5nOo8D9h80nzR9ea9T2Qe 7SsyK3h4YT77rUx7cZotFs2iFKB1xwUs42CaF47xE3WOtl9R1NhJMp9ArqGw/4veFebp 8DBrbMf9kaQfSzlkFTpHbhfdW+z2BFsq5NVwJJ2IbU5EDUo9eQM/VzP8MgYFEtkPhtuN +jv58/ftVbpSX3ANdeilpgTePR3mjzgM0E5LUVHmzPselsqm2uhxvM2CJmhsGhwtMHNA zEisn1GZi/2cD76HES3RqvTKarAvagbWKWXaUvRtDoEjCPGP03IBRuKKypsqIbkturyN kHjg== X-Gm-Message-State: AOAM5323cz1/D97lhZBrLSz54t4oHb4hMFyMqC/DPlcuH5KdswvzTI/p FyavcsyZ+S4oXPWBjDVB6fQ= X-Google-Smtp-Source: ABdhPJx3pMVLb9CkOou36g3t7qqdGANy/dfEotKyLpnw7vAMg5cnQZHLxWuac8auMVYBUSGMG7/Jdw== X-Received: by 2002:adf:eacc:: with SMTP id o12mr19659558wrn.202.1612207165733; Mon, 01 Feb 2021 11:19:25 -0800 (PST) Received: from [192.168.2.27] (39.35.broadband4.iol.cz. [85.71.35.39]) by smtp.gmail.com with ESMTPSA id p15sm27989090wrt.15.2021.02.01.11.19.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 01 Feb 2021 11:19:24 -0800 (PST) Subject: Re: Very slow unlockall() To: Vlastimil Babka , Michal Hocko Cc: linux-mm@kvack.org, Linux Kernel Mailing List , Mikulas Patocka References: <70885d37-62b7-748b-29df-9e94f3291736@gmail.com> <20210108134140.GA9883@dhcp22.suse.cz> <9474cd07-676a-56ed-1942-5090e0b9a82f@suse.cz> <6eebb858-d517-b70d-9202-f4e84221ed89@suse.cz> From: Milan Broz Message-ID: Date: Mon, 1 Feb 2021 20:19:23 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <6eebb858-d517-b70d-9202-f4e84221ed89@suse.cz> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/02/2021 19:55, Vlastimil Babka wrote: > On 2/1/21 7:00 PM, Milan Broz wrote: >> On 01/02/2021 14:08, Vlastimil Babka wrote: >>> On 1/8/21 3:39 PM, Milan Broz wrote: >>>> On 08/01/2021 14:41, Michal Hocko wrote: >>>>> On Wed 06-01-21 16:20:15, Milan Broz wrote: >>>>>> Hi, >>>>>> >>>>>> we use mlockall(MCL_CURRENT | MCL_FUTURE) / munlockall() in cryptsetup code >>>>>> and someone tried to use it with hardened memory allocator library. >>>>>> >>>>>> Execution time was increased to extreme (minutes) and as we found, the problem >>>>>> is in munlockall(). >>>>>> >>>>>> Here is a plain reproducer for the core without any external code - it takes >>>>>> unlocking on Fedora rawhide kernel more than 30 seconds! >>>>>> I can reproduce it on 5.10 kernels and Linus' git. >>>>>> >>>>>> The reproducer below tries to mmap large amount memory with PROT_NONE (later never used). >>>>>> The real code of course does something more useful but the problem is the same. >>>>>> >>>>>> #include >>>>>> #include >>>>>> #include >>>>>> #include >>>>>> >>>>>> int main (int argc, char *argv[]) >>>>>> { >>>>>> void *p = mmap(NULL, 1UL << 41, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); > > So, this is 2TB memory area, but PROT_NONE means it's never actually populated, > although mlockall(MCL_CURRENT) should do that. Once you put PROT_READ | > PROT_WRITE there, the mlockall() starts taking ages. > > So does that reflect your use case? munlockall() with large PROT_NONE areas? If > so, munlock_vma_pages_range() is indeed not optimized for that, but I would > expect such scenario to be uncommon, so better clarify first. It is just a simple reproducer of the underlying problem, as suggested here https://gitlab.com/cryptsetup/cryptsetup/-/issues/617#note_478342301 We use mlockall() in cryptsetup and with hardened malloc it slows down unlock significantly. (For the real case problem please read the whole issue report above.) m.