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=-15.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,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 8F11FC4338F for ; Tue, 27 Jul 2021 09:48:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D4E1F61266 for ; Tue, 27 Jul 2021 09:48:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D4E1F61266 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 61F2F6B0036; Tue, 27 Jul 2021 05:48:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A7D56B005D; Tue, 27 Jul 2021 05:48:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 449038D0001; Tue, 27 Jul 2021 05:48:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0087.hostedemail.com [216.40.44.87]) by kanga.kvack.org (Postfix) with ESMTP id 2B9B56B0036 for ; Tue, 27 Jul 2021 05:48:48 -0400 (EDT) Received: from smtpin34.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B643122006 for ; Tue, 27 Jul 2021 09:48:47 +0000 (UTC) X-FDA: 78407893494.34.224ABDC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf25.hostedemail.com (Postfix) with ESMTP id 50249B0030AE for ; Tue, 27 Jul 2021 09:48:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627379326; 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=lcHYy4rfAcV2BB+JWTtejLxqwQCZQnvr/lBGXuRnna0=; b=P+uTIyXf8idIGU1QKBPtG63VNNA93BJuz/aJ9lzHI+tTpZ7Hdrrx3MoFp3QI0eoX213DA0 SpEjm6Mo4hodzOrAB23Kvh2Iq5269GS30gkY5SFOtBdMWPKZkP3IMAPF+WHuI/2gjBC4AN FXC6bFU4291NOL5iROdAuWWn+OZekPc= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-227-V5qEkHf-PCaKKqQESfSL_w-1; Tue, 27 Jul 2021 05:48:10 -0400 X-MC-Unique: V5qEkHf-PCaKKqQESfSL_w-1 Received: by mail-wm1-f71.google.com with SMTP id k4-20020a05600c1c84b0290210c73f067aso925199wms.6 for ; Tue, 27 Jul 2021 02:48:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:organization:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=lcHYy4rfAcV2BB+JWTtejLxqwQCZQnvr/lBGXuRnna0=; b=KfgbZPe88Jz90yvoz4ipKdwadwZoC4Oe8vdStTEI5j1v4FoWeDeYBqCi6MCWwC2QTy qfXE5r36IjG5CNG7MWwjfUG4Hj3HOdCYhEaBzbKA5U3HS1vfRUmlQD/tUzBha6WSek2P H3F0SiVlPrJ0lWb+pjM9bwYu8BF8NS74D20Z24jH86SjD93bgc72jmCMEazOOMQ3bcdx zf0Enn9DrN/sMWRmGPLx/VHf51sMhHPTNnAsnykYAtUf15bMZdch7YSeO2vaB7EKgEOW eQGNMuniTUpf3L4gf8tkLm3Oe5oc8nQAafR6a+IFfWe9JHVJ1lPQ//Ctso7s48w/lJwI qOwg== X-Gm-Message-State: AOAM530KTvN3uKNYneCevLqi6MMSzKWqCLgRbeHhuy2ZeCcgHCwHAegm dUh/dpcB2BfXXbVedB4rSdY9cv7fsgbQ84B9BzGAhOKDVKR8FqPdPsiaz86hHs4Djpb5ZdU47lt qd9PEzU973F/MQDOzOz1UVsfnsvS0mj4umpaeazL9Mdymy5OtaIH2v2KRKEI= X-Received: by 2002:adf:fbce:: with SMTP id d14mr23630138wrs.236.1627379288911; Tue, 27 Jul 2021 02:48:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyW+5bsug3BLc5GikuPVa91Lj121RhsP8kBvehx197gg7taI+A14JR9q78R+cw9t8XabRPdHg== X-Received: by 2002:adf:fbce:: with SMTP id d14mr23630096wrs.236.1627379288633; Tue, 27 Jul 2021 02:48:08 -0700 (PDT) Received: from [192.168.3.132] (p4ff23c36.dip0.t-ipconnect.de. [79.242.60.54]) by smtp.gmail.com with ESMTPSA id e3sm2719905wrw.51.2021.07.27.02.48.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 27 Jul 2021 02:48:08 -0700 (PDT) To: Evan Green , Andrew Morton Cc: Michal Hocko , Pavel Machek , linux-api@vger.kernel.org, Alex Shi , Alistair Popple , Johannes Weiner , Joonsoo Kim , "Matthew Wilcox (Oracle)" , Miaohe Lin , Minchan Kim , Suren Baghdasaryan , Vlastimil Babka , linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20210726171106.v4.1.I09866d90c6de14f21223a03e9e6a31f8a02ecbaf@changeid> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v4] mm: Enable suspend-only swap spaces Message-ID: Date: Tue, 27 Jul 2021 11:48:07 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210726171106.v4.1.I09866d90c6de14f21223a03e9e6a31f8a02ecbaf@changeid> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 50249B0030AE Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=P+uTIyXf; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf25.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=david@redhat.com X-Stat-Signature: upd5ryc1k1ppzfhucrgcynzzs63u9rgp X-HE-Tag: 1627379327-538148 Content-Transfer-Encoding: quoted-printable 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.07.21 02:12, Evan Green wrote: > Add a new SWAP_FLAG_HIBERNATE_ONLY 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 hibernate /dev/sda2= . >=20 > Currently it's not possible to enable hibernation without also enabling > generic swap for a given area. One semi-workaround for this is to delay > the call to swapon() until just before attempting to hibernate, and the= n > call swapoff() just after hibernate completes. This is somewhat kludgy, > and also doesn't really work to keep swap out of the hibernate region. > When hibernate begins, it starts by allocating a large chunk of memory > for itself. This often ends up forcing a lot of data out into swap. By > this time the hibernate region is eligible for generic swap, so swap > ends up leaking into the hibernate region even with the workaround. >=20 > There are a few reasons why usermode might want to be able to > exclusively steer swap and hibernate. One reason relates to SSD wearing= . > Hibernate's endurance and speed requirements are different from swap. > It may for instance be advantageous to keep hibernate in primary > storage, but put swap in an SLC namespace. These namespaces are faster > and have better endurance, but cost 3-4x in terms of capacity. > Exclusively steering hibernate and swap enables system designers to > accurately partition their storage without either wearing out their > primary storage, or overprovisioning their fast swap area. >=20 > Another reason to allow exclusive steering has to do with security. > The requirements for designing systems with resilience against > offline attacks are different between swap and hibernate. Swap > effectively requires a dictionary of hashes, as pages can be added and > removed arbitrarily, whereas hibernate only needs a single hash for the > entire image. If you've set up block-level integrity for swap and > image-level integrity for hibernate, then allowing swap blocks to > possibly leak out to the hibernate region is problematic, since it > creates swap pages not protected by any integrity. >=20 > Swap regions with SWAP_FLAG_HIBERNATE_ONLY set will not appear in > /proc/meminfo under SwapTotal and SwapFree, since they are not usable a= s > general swap. These regions do still appear in /proc/swaps. Right, and they also don't account towards the memory overcommit=20 calculations. Thanks for extending the patch description! [...] > + if (swap_flags & SWAP_FLAG_HIBERNATE_ONLY) { > + if (IS_ENABLED(CONFIG_HIBERNATION)) { > + if (swap_flags & ~SWAP_HIBERNATE_ONLY_VALID_FLAGS) > + return -EINVAL; > + > + } else { > + return -EINVAL; > + } > + } We could do short if ((swap_flags & SWAP_FLAG_HIBERNATE_ONLY) && (!IS_ENABLED(CONFIG_HIBERNATION) || (swap_flags & ~SWAP_HIBERNATE_ONLY_VALID_FLAGS))) return -EINVAL; or if (swap_flags & SWAP_FLAG_HIBERNATE_ONLY)) if (!IS_ENABLED(CONFIG_HIBERNATION) || (swap_flags & ~SWAP_HIBERNATE_ONLY_VALID_FLAGS)) return -EINVAL; > + > if (!capable(CAP_SYS_ADMIN)) > return -EPERM; > =20 > @@ -3335,16 +3366,20 @@ SYSCALL_DEFINE2(swapon, const char __user *, sp= ecialfile, int, swap_flags) > if (swap_flags & SWAP_FLAG_PREFER) > prio =3D > (swap_flags & SWAP_FLAG_PRIO_MASK) >> SWAP_FLAG_PRIO_SHIFT; > + > + if (swap_flags & SWAP_FLAG_HIBERNATE_ONLY) > + p->flags |=3D SWP_HIBERNATE_ONLY; > enable_swap_info(p, prio, swap_map, cluster_info, frontswap_map); > =20 > - pr_info("Adding %uk swap on %s. Priority:%d extents:%d across:%lluk = %s%s%s%s%s\n", > + pr_info("Adding %uk swap on %s. Priority:%d extents:%d across:%lluk = %s%s%s%s%s%s\n", > p->pages<<(PAGE_SHIFT-10), name->name, p->prio, > nr_extents, (unsigned long long)span<<(PAGE_SHIFT-10), > (p->flags & SWP_SOLIDSTATE) ? "SS" : "", > (p->flags & SWP_DISCARDABLE) ? "D" : "", > (p->flags & SWP_AREA_DISCARD) ? "s" : "", > (p->flags & SWP_PAGE_DISCARD) ? "c" : "", > - (frontswap_map) ? "FS" : ""); > + (frontswap_map) ? "FS" : "", > + (p->flags & SWP_HIBERNATE_ONLY) ? "H" : ""); > =20 > mutex_unlock(&swapon_mutex); > atomic_inc(&proc_poll_event); >=20 Looks like the cleanest alternative to me, as long as we don't want to=20 invent new interfaces. Acked-by: David Hildenbrand --=20 Thanks, David / dhildenb