Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3538246pxp; Tue, 8 Mar 2022 16:57:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJxaqv/pOjSy6xPemFp927ooOGw6zFAPLOnGEpXwjblulSP4QKW/Szwq4sR+z9ilMMMdM9Mf X-Received: by 2002:a05:6a00:b52:b0:4f6:d3b4:9323 with SMTP id p18-20020a056a000b5200b004f6d3b49323mr20484499pfo.30.1646787439729; Tue, 08 Mar 2022 16:57:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646787439; cv=none; d=google.com; s=arc-20160816; b=ekQThKrRRJT158cNxRaRsAlKa7F1PDHCIhBES77oF1RFI3yRtaI2FgPaxAqi4LTZbM wergVgw2A4UgogZP5Zen/dUn0lkCoay3vBGqDf/oYlv6V35MiI7nlaFfIIQQa3nQROvE lrMRNyB8iXzzhSZN13RRdc+2+b/tFhlP1N4s6Is98l24ZVuMuM6vXocgL8F+WQyyKvaN /vu+QwLdBJTh9gZvsQRKX425Cd1uizcR84vXuoCbRsxhKQ67xLqcyD13OtFboUEiLK/7 4FoiQUc+jblV2r8QcEl7axpejbAP7jBXqwkd01Sk5n/XRyIDsxrIEqX8Cv95BE4OOyWU E+JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=w0vmAh/kccjRH8guMo493NivfH2oji8DnSzxOP03BLQ=; b=F4BAmPzeysZCTlcv02G2Kk2+3v0oYcDtr0rAF57gkXL4qLWvk+uL6/cSjEt4k7nQMO MkXND0Hdwd0A22HXExTVwUDZ/NSsdxWQpqoJS1+F7yFC7JMJ2mi3i+U/E1EY7FLhf3di 21+8LMZsFlir8EFbAYwDZhibc7dwOmqoMRp++o1ihkH4lXTIhbgiI7Cx3bcPBT7uKz3T TfLTXjMKP1fezUdlOJcJIELZhjwBP3IKge+LxGteM9SmmaTLyFZ80qtL+DYQSHknrpeM PXyDgoprrUanRin/2+Kz761zbGHrkBeeLyEU/ykTmSSuy4Vi8NqWnxE3IgqgbdXPZvn0 PKEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=mrMLGWOu; dkim=neutral (no key) header.i=@suse.cz header.b=45qz6+e4; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x9-20020a634849000000b00378baddb8d4si408876pgk.355.2022.03.08.16.57.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 16:57:19 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=mrMLGWOu; dkim=neutral (no key) header.i=@suse.cz header.b=45qz6+e4; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B686D159E9D; Tue, 8 Mar 2022 16:05:56 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344294AbiCHPcZ (ORCPT + 99 others); Tue, 8 Mar 2022 10:32:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231561AbiCHPcY (ORCPT ); Tue, 8 Mar 2022 10:32:24 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EAED4E3A5; Tue, 8 Mar 2022 07:31:28 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 2DA191F37E; Tue, 8 Mar 2022 15:31:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1646753487; h=from:from:reply-to: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=w0vmAh/kccjRH8guMo493NivfH2oji8DnSzxOP03BLQ=; b=mrMLGWOuBBlfsroDd6oYIT/7H1v5hOJXMp5a9QPISbpXl/ekUC+1iESI2GAUSNovV78Maj 9NtPV5QtvFp7sAqRzPVyUrGOi2xg7es9JiM4YHxtUJZtm8NjSyEObJHMlrpvZygvjp4Fbl uonAlY5UhIUfagInBoDjjpcUDtVCOdk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1646753487; h=from:from:reply-to: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=w0vmAh/kccjRH8guMo493NivfH2oji8DnSzxOP03BLQ=; b=45qz6+e4yjrb0c3W0MEw6xycEFn3U5t98k4ELCcCVRhgC/GF4XdUa95qeeK4qgWSQ8SX8b bzSKLApuO61dPvAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id F07B013CCE; Tue, 8 Mar 2022 15:31:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id JR+yOc52J2JoWAAAMHmgww (envelope-from ); Tue, 08 Mar 2022 15:31:26 +0000 Message-ID: Date: Tue, 8 Mar 2022 16:31:26 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [PATCH] mm: madvise: MADV_DONTNEED_LOCKED Content-Language: en-US To: Johannes Weiner , Andrew Morton Cc: Michal Hocko , Nadav Amit , David Hildenbrand , dgilbert@redhat.com, Mike Kravetz , linux-mm@kvack.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220304171912.305060-1-hannes@cmpxchg.org> From: Vlastimil Babka In-Reply-To: <20220304171912.305060-1-hannes@cmpxchg.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/4/22 18:19, Johannes Weiner wrote: > MADV_DONTNEED historically rejects mlocked ranges, but with > MLOCK_ONFAULT and MCL_ONFAULT allowing to mlock without populating, > there are valid use cases for depopulating locked ranges as well. > > Users mlock memory to protect secrets. There are allocators for secure > buffers that want in-use memory generally mlocked, but cleared and > invalidated memory to give up the physical pages. This could be done > with explicit munlock -> mlock calls on free -> alloc of course, but > that adds two unnecessary syscalls, heavy mmap_sem write locks, vma > splits and re-merges - only to get rid of the backing pages. > > Users also mlockall(MCL_ONFAULT) to suppress sustained paging, but are > okay with on-demand initial population. It seems valid to selectively > free some memory during the lifetime of such a process, without having > to mess with its overall policy. > > Why add a separate flag? Isn't this a pretty niche usecase? > > - MADV_DONTNEED has been bailing on locked vmas forever. It's at least > conceivable that someone, somewhere is relying on mlock to protect > data from perhaps broader invalidation calls. Changing this behavior > now could lead to quiet data corruption. > > - It also clarifies expectations around MADV_FREE and maybe > MADV_REMOVE. It avoids the situation where one quietly behaves > different than the others. MADV_FREE_LOCKED can be added later. Looks like the parameter is not a bitmask, so it makes sense to have MADV_FREE_LOCKED instead of a generic flag that combines with one of those. > - The combination of mlock() and madvise() in the first place is > probably niche. But where it happens, I'd say that dropping pages > from a locked region once they don't contain secrets or won't page > anymore is much saner than relying on mlock to protect memory from > speculative or errant invalidation calls. It's just that we can't > change the default behavior because of the two previous points. > > Given that, an explicit new flag seems to make the most sense. > > Signed-off-by: Johannes Weiner Acked-by: Vlastimil Babka > Acked-by: Michal Hocko