Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp743243pxv; Thu, 22 Jul 2021 11:02:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLA6Tg6Jvy8upZV8yOh0TS0OAViSXRHfnmqoBfmNvw6/T3t1ugVRksuy2sXnttCWvMQ1LJ X-Received: by 2002:a6b:ec0d:: with SMTP id c13mr738762ioh.108.1626976961665; Thu, 22 Jul 2021 11:02:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626976961; cv=none; d=google.com; s=arc-20160816; b=UBvOUiMlB87/wjCKp2yGyz8p4bIiciS7/3EliqQLxnHP5nPI7iGlrTZUORg/mHBTdU fPsKxp+bqgIVxAh225pOJH7qTfHo6TcK5FElvyqDsSe2ResgA5Bv+gpf58vE+7bUP9gO wXeW3AxUGPMQW1wM72bxz0yia9uN+zYJG761WbKnICx5chSgQueD3OXngBiekW26h//k HO2zkXLE5Q908C9osuXxfFqjE9mLXpQMEz2hRaqEDIf8sT9O4EObq8/8NgQT7M+wcD/x PR8Iy+3KI27DROICuTwWhVwXTp8jecOIosI4MJ68fhDdiV5ea7EsgS+3srLZLrHVqrfC fIyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=XCe9Px5IbYx9WoehfjTAmfQBvNYKzF4HFGZVPEMv3Dw=; b=TAuxkU0Agdn1KQ1luHjwUEvtq2C8kewrpcvtmTabpTyVL7JL8ec28dLddO5qEaFT73 FTX40SBPrAnlzz0nz4aUHF+mg3vGNgjru3C6rT6HUozAeCZ9/LPkoT5ng5FWTU9WJmnK 3wnU9qargJDw2fKuKLwtFMxN7MdJs9EWezHog5y3uFLTUT4ud3k8AokUqdQ8OKaZr/Cc OOii9JUbSuL+JvM8m32ykpJwWLNPZObGEkVQh+a1LH4d+cwAPifG/R8N9mYYo/trZLFW c1CQ/BtVZm3/zTN1Ro94St8KQI5wS+okZock1E920tswgX9PYizrvrCDP8Aar8PZ5twE T7mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bTcBVSLQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e14si28514991ilu.148.2021.07.22.11.02.29; Thu, 22 Jul 2021 11:02:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bTcBVSLQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229826AbhGVRVD (ORCPT + 99 others); Thu, 22 Jul 2021 13:21:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229906AbhGVRVA (ORCPT ); Thu, 22 Jul 2021 13:21:00 -0400 Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 340E1C061757 for ; Thu, 22 Jul 2021 11:01:35 -0700 (PDT) Received: by mail-il1-x134.google.com with SMTP id s5so6199300ild.5 for ; Thu, 22 Jul 2021 11:01:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=XCe9Px5IbYx9WoehfjTAmfQBvNYKzF4HFGZVPEMv3Dw=; b=bTcBVSLQGMhrpoZxQ5uU5iBAxtON1Fb8TJYSzfATlcDOrA52tzAbADe6fEnjQ4M1t4 vtIxTuWPNU6xUPZTCnBBpPdhpSyNLdQuBeYti8gELBuBnp+9OMVxMLmuCnqpY94Z7hoy 4wioJg6a8kbT5fXAJhoUuorTKFv2ViM5xfS7I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XCe9Px5IbYx9WoehfjTAmfQBvNYKzF4HFGZVPEMv3Dw=; b=iI2360nQRbiBkH/ajeHJ65gNEv7/g2t9Pjpp3yViMJmNonU/Ag3jGGy6JVrS4tSpkp ot5Hy78o56qof5k2BiIKNBVg034EtV41Jm1vzLkTifo8TB20i8u6QMT5BO312iULpJcV C4njC4c+65o8zIjUSUiSEtuvwT1wGm3bqxRUCsKY/TLiYdWstvBYRvtl6UKiCdefDAjk FiTqv0jWvMBU36xwx5t35g1az4iRAAUrpZ9HQymPqaKgpcdSItiJKmOpLSfj64G6Xv3y 1X0gGJZsq3m4tO/XsRFSE9RtZvbJUGbtHCyfpfoxwr2dS7w40RS9/HQULdp7WJ1V5Ut9 qqfQ== X-Gm-Message-State: AOAM532vbtJDKX/3jGYCh+cKYS8Id4yaiebkVRPvYqIaTnEe+k5d167f END3a4QuwoFnwZ2cQjv2gFBc7XQO2FznYA== X-Received: by 2002:a92:8707:: with SMTP id m7mr707026ild.177.1626976894546; Thu, 22 Jul 2021 11:01:34 -0700 (PDT) Received: from mail-il1-f177.google.com (mail-il1-f177.google.com. [209.85.166.177]) by smtp.gmail.com with ESMTPSA id h6sm15435435ilo.0.2021.07.22.11.01.33 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Jul 2021 11:01:33 -0700 (PDT) Received: by mail-il1-f177.google.com with SMTP id s5so6199220ild.5 for ; Thu, 22 Jul 2021 11:01:33 -0700 (PDT) X-Received: by 2002:a05:6e02:1aa2:: with SMTP id l2mr662668ilv.224.1626976892898; Thu, 22 Jul 2021 11:01:32 -0700 (PDT) MIME-Version: 1.0 References: <20210721143946.v3.1.I09866d90c6de14f21223a03e9e6a31f8a02ecbaf@changeid> In-Reply-To: From: Evan Green Date: Thu, 22 Jul 2021 11:00:56 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3] mm: Enable suspend-only swap spaces To: David Hildenbrand Cc: Andrew Morton , linux-api@vger.kernel.org, Michal Hocko , Pavel Machek , Alex Shi , Alistair Popple , Johannes Weiner , Joonsoo Kim , "Matthew Wilcox (Oracle)" , Miaohe Lin , Minchan Kim , Suren Baghdasaryan , Vlastimil Babka , LKML , linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 22, 2021 at 12:12 AM David Hildenbrand wrote: > > On 21.07.21 23:40, Evan Green wrote: > > Currently it's not possible to enable hibernation without also enabling > > generic swap for a given swap area. These two use cases are not the > > same. For example there may be users who want to enable hibernation, > > but whose drives don't have the write endurance for generic swap > > activities. Swap and hibernate also have different security/integrity > > requirements, prompting folks to possibly set up something like block-level > > integrity for swap and image-level integrity for hibernate. Keeping swap > > and hibernate separate in these cases becomes not just a matter of > > preference, but correctness. > > > > Add a new SWAP_FLAG_NOSWAP that adds a swap region but refuses to allow > > generic swapping to it. This region can still be wired up for use in > > suspend-to-disk activities, but will never have regular pages swapped to > > it. This flag will be passed in by utilities like swapon(8), usage would > > probably look something like: swapon -o noswap /dev/sda2. > > Just a minor comment, I'd call it rather SWAP_FLAG_HIBERNATE_ONLY and > SWAP_FLAG_HIBERNATE_ONLY -- that calls the child by its name. I went back and forth on this too. It seemed pretty close to toss-up to me. I went with NOSWAP ultimately because it seemed more closely tied to what the flag was actually doing, rather than building in my one expected use case into the name. In some world years from now where either hibernate has diverged, been deleted, or maybe some new usage has been invented for swap space, the NOSWAP name felt like it had a better chance of holding up. The argument is weak though, as these features are pretty well cast in stone, and the likelihood of any of those outcomes seems low. I can change it if you feel strongly, but would probably keep it as-is otherwise. > > I think some other flags might not apply with that new flag set, right? > For example, does SWAP_FLAG_DISCARD_ONCE or SWP_AREA_DISCARD still have > any meaning with the new flag being set? > > We should most probably disallow enabling any flag that doesn't make any > sense in combination. Good point, I can send a followup patch for that. From my reading SWAP_FLAG_DISCARD and SWAP_FLAG_DISCARD_ONCE are still valid, since the discard can be run at swapon() time. SWAP_FLAG_PREFER (specifying the priority) doesn't make sense, and SWAP_FLAG_DISCARD_PAGES never kicks in because it's called at the cluster level. Hm, that sort of seems like a bug that freed hibernate swap doesn't get discarded. I can disallow it now as unsupported, but might send a patch to fix it later. > > Apart from that, I'd love to see a comment in here why the workaround > suggested by Michal isn't feasible -- essentially a summary of what we > discussed. Ah sorry, I had tried to clarify that in the commit text, but didn't explicitly address the workaround. To summarize, the workaround keeps generic swap out of your hibernate region... until hibernate time. But once hibernate starts, a lot of swapping tends to happen when the hiber-image is allocated. At this point the hibernate region is eligible for general swap even with the workaround. The reasons I gave for wanting to exclusively steer swap and hibernate are SSD write wearing, different integrity solutions for swap vs hibernate, and our own security changes that no-op out the swapon/swapoff syscalls after init. > > I had a quick glimpse and nothing jumed at me, no mm/swapfile.c expert, > though :) Thanks David! -Evan > > > > -- > Thanks, > > David / dhildenb >