From patchwork Tue Feb 7 02:52:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13130898 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4F54C05027 for ; Tue, 7 Feb 2023 02:53:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F19E86B0074; Mon, 6 Feb 2023 21:53:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EC9FE6B0075; Mon, 6 Feb 2023 21:53:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D921C6B0078; Mon, 6 Feb 2023 21:53:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C5B796B0074 for ; Mon, 6 Feb 2023 21:53:10 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 92B25160464 for ; Tue, 7 Feb 2023 02:53:10 +0000 (UTC) X-FDA: 80438974140.28.474F7CD Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf27.hostedemail.com (Postfix) with ESMTP id A01B540005 for ; Tue, 7 Feb 2023 02:53:08 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="AfWwCM1/"; spf=none (imf27.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675738389; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=i4yenvsgq3ZGN+thpbBGgSGc/CQ/bzRD70KdvQeiS/c=; b=1VV3gYrZKKwTbhrhYJESBMP2oXb38FPznC79ozQ/ZrF++hjbkwN5U3LwV+FTjGP0McRZSn WRWs5VJYv2+iSQ8xp4I2qTKz2/gJeOqjGAQYFgoI6cory7k/BAGRqbyiFv1CTyP/QBfehX TGqzVttlNidXmreV6cbmNLs51KuXaAA= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="AfWwCM1/"; spf=none (imf27.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675738389; a=rsa-sha256; cv=none; b=M3WNVsT666E7V/b/w/iulIK5DDinmSejVongqJ0Qeu5f1OsmJLiGFKnc8305qiQdAVR47l hrtRquk2DYNeBBb+JPSGTj5jLnsz0m51UEHJ8/zKwOCWro+ChZLf8y/Z3W5Tg1jqvzp1kR bZkcpAuNqhx5P1+qUkM8AtX2wHmBtjI= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:In-Reply-To:References; bh=i4yenvsgq3ZGN+thpbBGgSGc/CQ/bzRD70KdvQeiS/c=; b=AfWwCM1/rprXxexkw1OpAUb+qK RjH2OlPja0doEdVyL7mxPu04NI8R/H5WjYyO5TPZnI55ztBFyoApXbpZUok0F+U4NH3oXi7VaVfHG 1ql9FkBIeeHvgE86tI30wvSdGoXS0TQd5It1QRBR69aXHjVJ+IRLt+8/yva4KeXpOocInYYK8iSha cKYBzfZBkKtKnfrexkLk2ES8mvARG1zRFV5RrHgopElmsKuHXOYm96pIokFzD8Ke4BS6YnuBjS3I7 NZiD4Sweg20lmCISgFdyo2XVRYVoG5nW9dooZZMxQPzUGN3fMv2NdCMpL3qHu6KkGE1VwPQOclpDD 3AtdDf5g==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pPE6Q-00AaIT-Uu; Tue, 07 Feb 2023 02:53:02 +0000 From: Luis Chamberlain To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org Cc: linux-mm@kvack.org, p.raghav@samsung.com, dave@stgolabs.net, a.manzanares@samsung.com, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [RFC 0/2] tmpfs: add the option to disable swap Date: Mon, 6 Feb 2023 18:52:57 -0800 Message-Id: <20230207025259.2522793-1-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: A01B540005 X-Stat-Signature: dnpjpqgz4cwtfxwu5frnoe3sumunxnph X-HE-Tag: 1675738388-236653 X-HE-Meta: U2FsdGVkX19LpXW3/Au9dE6UTvQB2WRQybhqolD+SjXzrjhDjeZkWJLuk0Yr6RHxp7sI8RsJ3jvmjuz3gR97nmDux+jJdOWdGm2r/y4Y3dQhZOwc3jjPEOAY8+ethA4RGa+s1pN6nSUiAs+d7wyXS7RTrh3Urolh/TU0hoMzrjXj6zIVyHFnbfK7V1rk5Yv+oaq+//cVG8P5u+oLfPrFVyE9YwZZrQb7HRYluhocUDQu6c9nW0/otvRxOLKFyCSi3OFdgqFlQK0UHEKTalymuR+7/RyAWtbyIoOZhQiSrQ62YidGPE5TyzbYlEZt7uneF7rsSbukYsj37gtGm/AH6UpV08lw8k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precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Many folks suggest using tmpfs is not great because it can use swap. That's not a good reason to *not* use tmpfs, what's just missing is just the option to let you disable it. And so this does that, to enable that and also let users experiment with it. Reconfiguring is not supported, so what you set up first is what you can keep with regards to swap options. Enabling support to disable on the fly and add swap on the fly *is* possible, but I'm not sure we need that yet. Matthew -- the first patch just makes it easier to read the second, but it does beg a few questions in it with regards to semantics about the folio and the inode after splitting a huge page so review for that would be greatly appreciated. To test I've used kdevops [0] 8 vpcu 4 GiB libvirt guest on linux-next. I'm doing this work as part of future experimentation with tmpfs and the page cache, but given a common complaint found about tmpfs is the innability to work without the page cache I figured this might be useful to others. It would also prove useful if folks ask for patches for future experimentation we are doing. To see if you hit swap: mkswap /dev/nvme2n1 swapon /dev/nvme2n1 free -h With swap - what we see today ============================= mount -t tmpfs -o size=5G tmpfs /data-tmpfs/ dd if=/dev/urandom of=/data-tmpfs/5g-rand2 bs=1G count=5 free -h total used free shared buff/cache available Mem: 3.7Gi 2.6Gi 1.2Gi 2.2Gi 2.2Gi 1.2Gi Swap: 99Gi 2.8Gi 97Gi Without swap ============= free -h total used free shared buff/cache available Mem: 3.7Gi 387Mi 3.4Gi 2.1Mi 57Mi 3.3Gi Swap: 99Gi 0B 99Gi mount -t tmpfs -o size=5G -o noswap tmpfs /data-tmpfs/ dd if=/dev/urandom of=/data-tmpfs/5g-rand2 bs=1G count=5 free -h total used free shared buff/cache available Mem: 3.7Gi 2.6Gi 1.2Gi 2.3Gi 2.3Gi 1.1Gi Swap: 99Gi 21Mi 99Gi The mix and match remount testing ================================= # Cannot disable swap after it was first enabled: mount -t tmpfs -o size=5G tmpfs /data-tmpfs/ mount -t tmpfs -o remount -o size=5G -o noswap tmpfs /data-tmpfs/ mount: /data-tmpfs: mount point not mounted or bad option. dmesg(1) may have more information after failed mount system call. dmesg -c tmpfs: Cannot disable swap on remount # Remount with the same noswap option is OK: mount -t tmpfs -o size=5G -o noswap tmpfs /data-tmpfs/ mount -t tmpfs -o remount -o size=5G -o noswap tmpfs /data-tmpfs/ dmesg -c # Trying to enable swap with a remount after it first disabled: mount -t tmpfs -o size=5G -o noswap tmpfs /data-tmpfs/ mount -t tmpfs -o remount -o size=5G tmpfs /data-tmpfs/ mount: /data-tmpfs: mount point not mounted or bad option. dmesg(1) may have more information after failed mount system call. dmesg -c tmpfs: Cannot enable swap on remount if it was disabled on first mount [0] https://github.com/linux-kdevops/kdevops Luis Chamberlain (2): shmem: set shmem_writepage() variables early shmem: add support to ignore swap include/linux/shmem_fs.h | 1 + mm/shmem.c | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-)