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.3 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,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 B9132C47404 for ; Mon, 7 Oct 2019 22:32:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 436252133F for ; Mon, 7 Oct 2019 22:32:43 +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="BR+IQlU3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 436252133F 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 BE8738E0005; Mon, 7 Oct 2019 18:32:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B97038E0003; Mon, 7 Oct 2019 18:32:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AAD7E8E0005; Mon, 7 Oct 2019 18:32:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0137.hostedemail.com [216.40.44.137]) by kanga.kvack.org (Postfix) with ESMTP id 88C658E0003 for ; Mon, 7 Oct 2019 18:32:42 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 225F682437CF for ; Mon, 7 Oct 2019 22:32:42 +0000 (UTC) X-FDA: 76018439364.05.glove06_51b804dfe7c01 X-HE-Tag: glove06_51b804dfe7c01 X-Filterd-Recvd-Size: 8066 Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Mon, 7 Oct 2019 22:32:41 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id d26so9072466pgl.7 for ; Mon, 07 Oct 2019 15:32:41 -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=hiuX0Jm0bCtT3BIySJJRKR+rSDVOe9U3UnF9soHBS3Q=; b=BR+IQlU3MBLtlHtKmrmierNzXNA5zdlAIeJfrNQW7Pt6H5vmGeYc5OwL9pnkdnZN8n e+YmBvw5vYSkiSqPLRCNFTWbwIZdM9JLLljeqEanpvf1jWqh4JOtS8wjeFeb0lhexvd+ KDT+TsNj0evX6PGfUiNrA/NMjqt3vXwevtlKjqwpIsWIJ/UjmgraIplN7G5mMKS+uSAM qo7lrocH6sfCKjeIe/9joczjMKIjZmy82/y7cOBYpOMWDxYTKZ310AC1HMqvbUJUh3/J +fIeGz4UY9kwTK7sUXuKnXmslUUphD04krDR8FCSCHWQlVg+9vvvP1O7Jasuq46BGuqm Cp6A== 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=hiuX0Jm0bCtT3BIySJJRKR+rSDVOe9U3UnF9soHBS3Q=; b=hAV8NxL5s7MIdJL6b+WwY/5QLdKLYWIjfE9UwBKWVdB6Rf9QtP12YagBfMhihgx9Gl AZUCc38ZeuAfBxPrlBpU4Yi8sbw0/urf8u2h79GjYs7OA59J03epORDHI8tBvOTHyxMD bvIQX5EA7MkUdjVTHwC+yPr2iIkYCwLPq2XRToV/3u/JDq8ocJ9HN62vxqx1ervpfvzQ i/afTyjjG1mkKWQ7hwdc+mZfy4EF/XmvJ1vyL3pPLCIxkdBbqQnAjZqvZJhEUcUPgUCn 6jbOYjSxvDVrmoRxoY9NsDFyxNw17R3XKq2tfmjOQBd6o6rZAyBor1df3zJJMqyVkZZM SSDw== X-Gm-Message-State: APjAAAVDb1Td0wOUhwn/aCGz2Do3YnlnTh0ys3/iaqL67rDFWmF7pntU 7tlObPFr+bGyEYN1fgKQmwk+uA== X-Google-Smtp-Source: APXvYqzaZZpQ5BSpA4RdbHF5+VdeV/W+KCKJthMIXWzHjUJWbfPMLqY1XER/XP+yzw27l+oovmphXw== X-Received: by 2002:a63:f915:: with SMTP id h21mr32877460pgi.269.1570487559259; Mon, 07 Oct 2019 15:32:39 -0700 (PDT) Received: from spider ([71.212.141.220]) by smtp.gmail.com with ESMTPSA id d1sm17075850pfc.98.2019.10.07.15.32.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Oct 2019 15:32:38 -0700 (PDT) Date: Mon, 7 Oct 2019 15:32:36 -0700 From: "Gary B. Genett" To: Hugh Dickins Cc: linux-mm@kvack.org Subject: [PATCH] shmem: add shmem_size option, set filesystem size Message-ID: <20191007223235.GA22291@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 and command line parameter 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 is necessary would be if the initramfs were larger than half of the memory, such as a 2.5GB filesystem with 4GB of memory. Without this option, this causes a kernel panic. With this option, the user may specify something like 75%, which would allow the filesystem into memory, while still leaving enough resources to run a functioning system. This patch creates the SHMEM_SIZE configuration option and the shmem_size parameter, which may be specified in bytes, human notation (1G, 100M, etc.) or percentage (75%). The default remains unchanged. This patch has no impact unless the values are changed. Signed-off-by: Gary B. Genett --- Documentation/admin-guide/kernel-parameters.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 5 +++ init/Kconfig | 8 ++++ mm/shmem.c | 57 +++++++++++++++++++++++-- 4 files changed, 67 insertions(+), 4 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.rst b/Documentation/admin-guide/kernel-parameters.rst index d05d531b4ec9..33122a6df04f 100644 --- a/Documentation/admin-guide/kernel-parameters.rst +++ b/Documentation/admin-guide/kernel-parameters.rst @@ -149,6 +149,7 @@ parameter is applicable:: APPARMOR AppArmor support is enabled. SERIAL Serial support is enabled. SH SuperH architecture is enabled. + SHMEM Full shmem filesystem is enabled. SMP The kernel is an SMP kernel. SPARC Sparc architecture is enabled. SWSUSP Software suspend (hibernation) is enabled. diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index c7ac2f3ac99f..aeac92577569 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -4307,6 +4307,11 @@ shapers= [NET] Maximal number of shapers. + shmem_size= [SHMEM] + Size of shmem filesystem. Can be specified as a plain + integer, in memory size notation (such as 1024M or 1G), + or as a percentage (50%). + simeth= [IA-64] simscsi= diff --git a/init/Kconfig b/init/Kconfig index b4daad2bac23..7b07f5c448af 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1537,6 +1537,14 @@ 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 + string "Hard-set the shmem filesystem size" + default 0 + depends on SHMEM + help + Size of shmem filesystem. Can be specified as a plain integer, in + memory size notation (such as 1024M or 1G), or as a percentage (50%). + config AIO bool "Enable AIO support" if EXPERT default y diff --git a/mm/shmem.c b/mm/shmem.c index cd570cc79c76..ad6109524ad1 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -95,6 +95,12 @@ 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) */ +#define SHMEM_SIZE_DEFAULT ((totalram_pages * PAGE_SIZE) / 2) +/* Final initialized size of shmem filesystem, and stored parameter value */ +unsigned long shmem_size_final; +char shmem_size_param[20]; + /* * 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 +129,56 @@ struct shmem_options { }; #ifdef CONFIG_TMPFS +static void shmem_size_parse(void) +{ + char *str, *t; + + sprintf(shmem_size_param, "%s", "0"); + str = strstr(boot_command_line, "shmem_size="); + if (str) { + t = strsep(&str, " "); + t += 11; + sprintf(shmem_size_param, "%s", t); + } +} + +static void shmem_size(char *str, char *val) +{ + char *rest; + unsigned long mem = memparse(val, &rest); + + if (*rest == '%') { + mem *= (totalram_pages * PAGE_SIZE); + do_div(mem, 100); + } + if (mem > 0) { + pr_info("shmem: found %s value: %s (%ld pages, %ld bytes)\n", + str, val, (mem / PAGE_SIZE), mem); + shmem_size_final = (mem / PAGE_SIZE); + } +} + +static void shmem_size_init(void) +{ + char tmp[20]; + + sprintf(tmp, "%ld", SHMEM_SIZE_DEFAULT); + shmem_size("default", tmp); +#ifdef CONFIG_SHMEM_SIZE + shmem_size("kernel configuration", CONFIG_SHMEM_SIZE); +#endif + shmem_size_parse(); + shmem_size("kernel parameter", shmem_size_param); +} + static unsigned long shmem_default_max_blocks(void) { - return totalram_pages() / 2; + return shmem_size_final; } 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(totalram_pages - totalhigh_pages, shmem_size_final); } #endif @@ -3887,6 +3933,9 @@ int __init shmem_init(void) { int error; +#ifdef CONFIG_TMPFS + shmem_size_init(); +#endif shmem_init_inodecache(); error = register_filesystem(&shmem_fs_type); -- 2.15.2