From 9937e9797925938470e881747445849369028488 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Mon, 26 Feb 2018 15:37:32 +0000 Subject: [PATCH] lualoader: Re-work menu skipping bits This is motivated by a want to reduce heap usage if the menu is being skipped. Currently, the menu module must be loaded regardless of whether it's being skipped or not, which adds a cool ~50-100KB worth of memory usage. Move the menu skip logic out to core (and remove a debug print), then check in loader.lua if we should be skipping the menu and avoid loading the menu module entirely if so. This keeps our memory usage below ~115KB for a boot with the menu stripped. Also worth noting: with this change, we no longer explicitly invoke autoboot if we're skipping the menu. Instead, we let the standard loader behavior apply: try to autoboot if we need to, then drop to a loader prompt if not or if the autoboot sequence is interrupted. The only thing we still handle before dropping to the loader autoboot sequence is loadelf(), so that we can still apply any of our kernel loading behavior. --- stand/lua/core.lua | 14 ++++++++++++++ stand/lua/loader.lua | 14 ++++++++++++-- stand/lua/menu.lua | 19 ------------------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/stand/lua/core.lua b/stand/lua/core.lua index c67c49e46276..0d22def075e6 100644 --- a/stand/lua/core.lua +++ b/stand/lua/core.lua @@ -285,6 +285,20 @@ function core.isSystem386() return loader.machine_arch == "i386" end +-- Is the menu skipped in the environment in which we've booted? +function core.isMenuSkipped() + if core.isSerialBoot() then + return true + end + local c = string.lower(loader.getenv("console") or "") + if c:match("^efi[ ;]") ~= nil or c:match("[ ;]efi[ ;]") ~= nil then + return true + end + + c = string.lower(loader.getenv("beastie_disable") or "") + return c == "yes" +end + -- This may be a better candidate for a 'utility' module. function core.deepCopyTable(tbl) local new_tbl = {} diff --git a/stand/lua/loader.lua b/stand/lua/loader.lua index 68afb9f8a6a2..963e7705c0da 100644 --- a/stand/lua/loader.lua +++ b/stand/lua/loader.lua @@ -30,8 +30,12 @@ -- require("cli") +local core = require("core") local config = require("config") -local menu = require("menu") +local menu +if not core.isMenuSkipped() then + menu = require("menu") +end local password = require("password") local result = lfs.attributes("/boot/lua/local.lua") @@ -42,4 +46,10 @@ end config.load() password.check() -menu.run() +-- menu might be disabled +if menu ~= nil then + menu.run() +else + -- Load kernel/modules before we go + config.loadelf() +end diff --git a/stand/lua/menu.lua b/stand/lua/menu.lua index fe18d70fdfb0..d6233cc04a30 100644 --- a/stand/lua/menu.lua +++ b/stand/lua/menu.lua @@ -405,11 +405,6 @@ function menu.process(menudef, keypress) end function menu.run() - if menu.skip() then - core.autoboot() - return - end - menu.draw(menu.default) local autoboot_key = menu.autoboot() @@ -420,20 +415,6 @@ function menu.run() print("Exiting menu!") end -function menu.skip() - if core.isSerialBoot() then - return true - end - local c = string.lower(loader.getenv("console") or "") - if c:match("^efi[ ;]") ~= nil or c:match("[ ;]efi[ ;]") ~= nil then - return true - end - - c = string.lower(loader.getenv("beastie_disable") or "") - print("beastie_disable", c) - return c == "yes" -end - function menu.autoboot() local ab = loader.getenv("autoboot_delay") if ab ~= nil and ab:lower() == "no" then