Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2238046pxm; Fri, 4 Mar 2022 12:04:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJwxKL1NLYriGEPEZmbtOstTEIEAh7jDREO0TDaTp7kjNMEH4Ezc2SSgRgkqUsmUxlSA0rq0 X-Received: by 2002:a17:903:183:b0:151:af32:890d with SMTP id z3-20020a170903018300b00151af32890dmr53894plg.0.1646424273474; Fri, 04 Mar 2022 12:04:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646424273; cv=none; d=google.com; s=arc-20160816; b=vjtEW5Nn60HNGH5UcdqpW2KQ49m6hOv0Mk78SC0OrHIBEH/zw4ojWxh/mH+WO/jn7d oKeU519GYTfgXB9pSqhxHnGsLVVSfHqYzHnY3aSIP1Hh81cpJmPIJMaClxHi6r9j21JR XDLEqBXXdOREcHvS/l8T0CMJAmrNhaK5QoewsrQl/W2SbxCw8bttasi88aFjyvGfm7uD pejyg2tuiDCXBzDduJdRNUUKuXJPHooYDbL2aPZ2Nv7FtwaJk8ED7g4IhG8E/KobtsWH nWSYtZLE53WtqMRH9t6CfoCi6ff/DtE3UmODmM0BhI+ojz7f1R+uLu6PNil8RiqFcLnH f1wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=J64es7HM/NEnjdZCnfIshrO3wOmcq5xIZ4GZ3l0aZZI=; b=DzNxDXRCfDuXUYxCtqmVFXEwpYpHuAYO5nNRRrcPgEmYVIMoB9O4u2Gpbhqvb1eqYy K4sie7JGmsRaNGv5/IIKtKndolV/oIa+BQi+4FiyBYpd4iMNDd9w57dZuBph0iBiWIyM hycg3z9lBAok14vCB90G1W6iK6Jtg4Ns0/ydqoCgqA+PPC8teIARNeXNGSRiE0PlKo7z BfmGBjDSv1HyELmqovOQqyKRsJ7sHU8oq/OA6fmQxfsnx8CMneUBMGYci/RB+SBG+lcs 6NQtYROuEfGckrixMZ6rpplPpHGxTHzQHA0Pyz2/breENpBBihnxWpEqCWFVd3T3mGXu Ch6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=GItdpzKU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a10-20020a170902ecca00b00151c3be71a4si1371733plh.103.2022.03.04.12.04.14; Fri, 04 Mar 2022 12:04:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=GItdpzKU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229850AbiCDUDd (ORCPT + 99 others); Fri, 4 Mar 2022 15:03:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229723AbiCDUDQ (ORCPT ); Fri, 4 Mar 2022 15:03:16 -0500 Received: from mail-oi1-x249.google.com (mail-oi1-x249.google.com [IPv6:2607:f8b0:4864:20::249]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 697E82A7534 for ; Fri, 4 Mar 2022 11:59:56 -0800 (PST) Received: by mail-oi1-x249.google.com with SMTP id u13-20020a056808150d00b002d73c61e0d7so6237221oiw.6 for ; Fri, 04 Mar 2022 11:59:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=J64es7HM/NEnjdZCnfIshrO3wOmcq5xIZ4GZ3l0aZZI=; b=GItdpzKUBGucNm4WOe+HN7O/1STAH96AycQndTvxw/AJHcG/IZXBQqhHpuZ05xhR4h s4/tKY3tQeE7DrutZ5Ai6jwAl8HZtsKW56JRi+K1/bpZ5fj9ArMcTSHKmuftwci5pnc5 8185Z7VFl8q58WBsa5DKcW7AqVcRHiRJlzc8uTybp2GtjLt3aimA8WJqpE9dZYDCaKpg nSDfUCu2diH4MZ2AkU0UqvXwMpOpJHeKUdcg+CDWj/hZdns7uGct3IOKaTBZkWLRZBTm LT0ppGdP7Ddd/W2mtx4Yd4qmSgUu1hBcDWvQ1o0GawHtl57BA07e3RkLP77VwgB12XvH SzyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=J64es7HM/NEnjdZCnfIshrO3wOmcq5xIZ4GZ3l0aZZI=; b=YN3lUN68o6VzuTaTSrpFcumbnZo8jVUMdFJwOSXW6ug+yDv3QFdkPWgyjFf8FSoix0 N8JUAQW2w9cOyiY19q6F2UqawOt2M0dqSpf+rJQeB2N0hi7zoFOivewWpfPARyNOmPV3 m1GAAJwLPhj1sbvERMFvMAqbrRAnXhPxz2B+yHJY3kFK3Nz5SsnHyL5kZNt6G4842rLV FcribcbSujJv1OxAyzP8Vf4BkICU69Z3MFJayHnllWDNCl1+ZwOA8/5Ch5+sACeBLQm+ ONoRWaqGdZNuTwiQzoByV5lZfRpJy+Fiude32YEHyb8lQIwN0odngshpnPI2swVXSIke Br1g== X-Gm-Message-State: AOAM533PYg0PRJ3PmrncxqrBl/eAPXrHW18rc5QnAmIbmM5tJr4K+UWI O/I4vGwEzM0lgTALW66OdmWtCoZPNMG3QQ== X-Received: from shakeelb.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:28b]) (user=shakeelb job=sendgmr) by 2002:a05:6902:3cc:b0:628:73aa:9c7f with SMTP id g12-20020a05690203cc00b0062873aa9c7fmr20910540ybs.632.1646421963101; Fri, 04 Mar 2022 11:26:03 -0800 (PST) Date: Fri, 4 Mar 2022 19:26:00 +0000 In-Reply-To: <20220304171912.305060-1-hannes@cmpxchg.org> Message-Id: <20220304192600.rvmgbg72aq6idooc@google.com> Mime-Version: 1.0 References: <20220304171912.305060-1-hannes@cmpxchg.org> Subject: Re: [PATCH] mm: madvise: MADV_DONTNEED_LOCKED From: Shakeel Butt To: Johannes Weiner Cc: Andrew Morton , Michal Hocko , Vlastimil Babka , Nadav Amit , David Hildenbrand , dgilbert@redhat.com, Mike Kravetz , linux-mm@kvack.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8"; format=flowed; delsp=yes X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 Fri, Mar 04, 2022 at 12:19:12PM -0500, 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. > - 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: Michal Hocko Reviewed-by: Shakeel Butt