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=-8.2 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 D2056C4360C for ; Tue, 8 Oct 2019 20:17:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7EAAE21721 for ; Tue, 8 Oct 2019 20:17:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=garybgenett-net.20150623.gappssmtp.com header.i=@garybgenett-net.20150623.gappssmtp.com header.b="St2yQftk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7EAAE21721 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=garybgenett.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1AC358E0005; Tue, 8 Oct 2019 16:17:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 134C58E0003; Tue, 8 Oct 2019 16:17:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0220A8E0005; Tue, 8 Oct 2019 16:17:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0224.hostedemail.com [216.40.44.224]) by kanga.kvack.org (Postfix) with ESMTP id CF6478E0003 for ; Tue, 8 Oct 2019 16:17:16 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 88FE155F8B for ; Tue, 8 Oct 2019 20:17:16 +0000 (UTC) X-FDA: 76021726872.25.cup33_7997966570b0d X-HE-Tag: cup33_7997966570b0d X-Filterd-Recvd-Size: 6145 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Tue, 8 Oct 2019 20:17:15 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id q21so18644pfn.11 for ; Tue, 08 Oct 2019 13:17:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garybgenett-net.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=xZY/gh1J11ZnWjxu0i5SpKPYZDdtXNq5PcR83Aa8zgI=; b=St2yQftkEklueEYzH2Vyz6Bmq3u6NAkYQWAH6H6gS2ibOud+6L6JWFHYPNxXGMiCsv YZHKKsSj/sFqjeiaAzqLC5IJDKBkGfBJR+9Vcznqjilxw2DrPYrTOVNDfFDbF2tvmwco 0SSjz02QqPMw22XDZXtp360vfWHov2S+cAO0OCWYRZ7vdx2slUb8wqLG9bczLlqvaNZj eAIYT3/+BKcdqmemP5Ab+5wlezmizga9mbYMwhLHnPitWkT/28baDt9rvK/B65BrRCm6 QMjfwmEFORjo6orrIjGGdjJQ0/BSzaqZs1XJaakzMxKZU/XLlSSHoQOj5aB8YZ65qpUq o3zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=xZY/gh1J11ZnWjxu0i5SpKPYZDdtXNq5PcR83Aa8zgI=; b=PiCZpHJZF8mpm4RWSf7KkGXSXrBBo8lQkR95Gby23ijJmZRD8ji7ozurFw+RdXYBsi ALcPZ2D/lUfuZ+QZCukJVZXW0LQx8Hb6IIdQHlcIrOkgvgWDVt3aE7sAybvmhQYqL4eS hQEjnHwqDtNE6gFpFvxDrFAhjheOoZSC3mXwen+Rpm3M6Z452JWwFEhi66wJSwgVvXH2 TZZJ3Wuu7epJ4CqlNdzYHt/0ESdTyPIpYdSdNCIA6wSVTggC7w99NfKDkMiM5VTvc6A+ 2bYqdbBNzjeVxNUKDIPQKMCrsv+SU84U65c7J3r6PQ8o3kBeyLnwpLK9zNtxmEnY0VML J/ng== X-Gm-Message-State: APjAAAXfJMzkeZP+uCyV9ap6CS3iXhS7xt3IbNVMM0JuMBiUgdKxOQ5s n70ayKK/CpHzprrU0g8B57/5GQ== X-Google-Smtp-Source: APXvYqy1eOpW5/1sFZ5afYRGy1RbmVNzRKpi7JzB+Ccw0WjgtYCw5RpSZ2nRhLdKXkFwC2pDdSd5Fg== X-Received: by 2002:a17:90a:fa0d:: with SMTP id cm13mr7971843pjb.121.1570565833880; Tue, 08 Oct 2019 13:17:13 -0700 (PDT) Received: from spider ([71.212.141.220]) by smtp.gmail.com with ESMTPSA id k15sm50109pgt.25.2019.10.08.13.17.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Oct 2019 13:17:13 -0700 (PDT) Date: Tue, 8 Oct 2019 13:17:11 -0700 From: "Gary B. Genett" To: Qian Cai Cc: Hugh Dickins , linux-mm@kvack.org Subject: [PATCH] shmem: add shmem_size option for full filesystem Message-ID: <20191008201710.GA21892@spider> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) 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: Adds a kernel configuration option to specify the size of the shmem filesystem. It is currently hard-coded to 50% of memory. Users should have the option to set this value as they see fit. A specific case where this would be necessary is if the initramfs were larger than half of the memory, such as a 2.5GB "live" filesystem on a system with 4GB of memory. Without this option, this causes a kernel panic. With this option, the user may specify the number of pages of memory they need for their root filesystem. This patch creates the SHMEM_SIZE configuration option, which is specified as the number of memory pages to use for the shmem filesystem. The default remains unchanged. This patch has no impact unless the values are changed. The option is marked as expert, and the help text is clear that it should only be set if the user knows what they are doing. Signed-off-by: Gary B. Genett --- init/Kconfig | 11 +++++++++++ mm/shmem.c | 20 ++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/init/Kconfig b/init/Kconfig index b4daad2bac23..fcff0f1ea3e8 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1537,6 +1537,17 @@ config SHMEM option replaces shmem and tmpfs with the much simpler ramfs code, which may be appropriate on small systems without swap. +config SHMEM_SIZE + int "Set the full shmem filesystem size" if EXPERT + default 0 + depends on SHMEM + help + Size of full shmem filesystem. Defaults to 50% of memory, + dynamically. Must be defined as the number of 4096 byte memory + pages, which will be static regardless of the amount of actual + memory. Unless you have a special use case, this value should not + be changed. + config AIO bool "Enable AIO support" if EXPERT default y diff --git a/mm/shmem.c b/mm/shmem.c index cd570cc79c76..d5baaf7ac9e8 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -95,6 +95,13 @@ static struct vfsmount *shm_mnt; /* Symlink up to this size is kmalloc'ed instead of using a swappable page */ #define SHORT_SYMLINK_LEN 128 +/* Default size of shmem filesystem (defaults to 50% of memory) */ +#if defined(CONFIG_SHMEM_SIZE) && (CONFIG_SHMEM_SIZE > 0) +#define SHMEM_SIZE_DEFAULT ((unsigned long)CONFIG_SHMEM_SIZE) +#else +#define SHMEM_SIZE_DEFAULT (totalram_pages() / 2) +#endif + /* * shmem_fallocate communicates with shmem_fault or shmem_writepage via * inode->i_private (with i_mutex making sure that it has only one user at @@ -123,16 +130,22 @@ struct shmem_options { }; #ifdef CONFIG_TMPFS +static void shmem_size_info(void) +{ + pr_info("shmem: setting default size: %lu pages, %lu bytes\n", + SHMEM_SIZE_DEFAULT, (SHMEM_SIZE_DEFAULT * PAGE_SIZE)); +} + static unsigned long shmem_default_max_blocks(void) { - return totalram_pages() / 2; + return SHMEM_SIZE_DEFAULT; } static unsigned long shmem_default_max_inodes(void) { unsigned long nr_pages = totalram_pages(); - return min(nr_pages - totalhigh_pages(), nr_pages / 2); + return min(nr_pages - totalhigh_pages(), SHMEM_SIZE_DEFAULT); } #endif @@ -3887,6 +3900,9 @@ int __init shmem_init(void) { int error; +#ifdef CONFIG_TMPFS + shmem_size_info(); +#endif shmem_init_inodecache(); error = register_filesystem(&shmem_fs_type); -- 2.15.2