Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oin38-0001U9-ST for mharc-grub-devel@gnu.org; Wed, 12 Oct 2022 21:30:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oin36-0001TA-Pi for grub-devel@gnu.org; Wed, 12 Oct 2022 21:30:13 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]:46733) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oin35-0003mq-1c for grub-devel@gnu.org; Wed, 12 Oct 2022 21:30:12 -0400 Received: by mail-pj1-x102b.google.com with SMTP id t12-20020a17090a3b4c00b0020b04251529so617090pjf.5 for ; Wed, 12 Oct 2022 18:30:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WsaOF3u+aFjS2TtEtmMXWRY+sBXwB3oo1IsxvmdfG/w=; b=beVSb8KuTFklqMyuA5vwT59EV6Ud5Am0zQuV4vjpMe8A7UKacWPbslsMo55+VRa5aJ SjzfwNsopD1mQBNmOZU1jNnhQXE5yBo8uQJIUxmjLKes0j4araDfGWny0pXE7gsvXq4C zOFEQenGevMH7QugSQQllZrQVCD08yPcJF2t72nD54f6lv21/cQWa6JzArlvUGFYSt/5 /IBsBiJHQ1JF66voP8VOS9o+tkrW40Uo6DxFwMooHHGwLHL5gFAZzhiBOLvfS34MzrlG ikwpUMPoMVKt9/5zYFXORHLG93Vu/P2nK7qW6aGqmvtk9FyNM5TOeZfJt4ifFYe4kYRV IH3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WsaOF3u+aFjS2TtEtmMXWRY+sBXwB3oo1IsxvmdfG/w=; b=DgOcb1aFKucNgfxAXvjo4jgBMGRBrXPoL8fpozjCN3e2hyHAsiYi+ke3V+PBlaalEw 8p+CWeOaOpq2+gGJcYN7Et7KBm1fLl4Yne/PlUHPxqV7Rrowp0GefFbTS1uyB9OQnk/d wn3fmz3KQJ98HBpEIkZqeBOOWOmrtW76cWiEw+kkUQWe9rxeeWTNMPM2g/c6bmkO9xr7 BiF+w8v36iqyQTA9A3yfzFmb2+laIA/y65fc/T9CBnQ98w80Y7wnDREIpSFbVCT2LT6l Buuh4dLzhxzISnbLprjfv9ZOtAu7npbBx9ubaeLlWqKOCh5po4pzWZYsxd5KUuRXsuri V4cQ== X-Gm-Message-State: ACrzQf0VWTtVcjfkh0/5BdvwTwJbVrJAFtDiH3mgQHHaRmyBN6wBU8V6 Irg9F2/3xfdASN9GfA/w06OiYyIXR71/ig== X-Google-Smtp-Source: AMsMyM79yxYI5RU87ZDC1RHkQq7xuSVAONHTT726qK8bhfB8JrFDpaUT6TV7Gk/XGRzL3jfUkhOiWg== X-Received: by 2002:a17:902:e414:b0:17f:5c82:ac01 with SMTP id m20-20020a170902e41400b0017f5c82ac01mr31843636ple.123.1665624609768; Wed, 12 Oct 2022 18:30:09 -0700 (PDT) Received: from localhost.localdomain (ec2-13-113-80-70.ap-northeast-1.compute.amazonaws.com. [13.113.80.70]) by smtp.gmail.com with ESMTPSA id z20-20020a63e554000000b0046a1c832e9fsm1971807pgj.34.2022.10.12.18.30.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Oct 2022 18:30:09 -0700 (PDT) From: Zhang Boyang To: grub-devel@gnu.org Cc: dkiper@net-space.pl, ps@pks.im, jim945@mail.ru, glin@suse.com, dja@axtens.net, droidbittin@gmail.com, heinrich.schuchardt@canonical.com, langner.marcel@myiq.de, marcan@marcan.st, Zhang Boyang Subject: [RFC PATCH v3 1/2] mm: Try invalidate disk caches last when out of memory Date: Thu, 13 Oct 2022 09:29:18 +0800 Message-Id: <20221013012919.173082-2-zhangboyang.id@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221013012919.173082-1-zhangboyang.id@gmail.com> References: <20221013012919.173082-1-zhangboyang.id@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=zhangboyang.id@gmail.com; helo=mail-pj1-x102b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Oct 2022 01:30:13 -0000 Previously, every heap grow will cause all disk caches invalidated, which decreases performance severely. This patch moves disk cache invalidation code to the last of memory squeezing measures, so disk caches are released only when no other ways to get free memory. Signed-off-by: Zhang Boyang --- grub-core/kern/mm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/grub-core/kern/mm.c b/grub-core/kern/mm.c index 75f6eacbe..ae2279133 100644 --- a/grub-core/kern/mm.c +++ b/grub-core/kern/mm.c @@ -443,12 +443,6 @@ grub_memalign (grub_size_t align, grub_size_t size) switch (count) { case 0: - /* Invalidate disk caches. */ - grub_disk_cache_invalidate_all (); - count++; - goto again; - - case 1: /* Request additional pages, contiguous */ count++; @@ -458,7 +452,7 @@ grub_memalign (grub_size_t align, grub_size_t size) /* fallthrough */ - case 2: + case 1: /* Request additional pages, anything at all */ count++; @@ -474,6 +468,12 @@ grub_memalign (grub_size_t align, grub_size_t size) /* fallthrough */ + case 2: + /* Invalidate disk caches. */ + grub_disk_cache_invalidate_all (); + count++; + goto again; + default: break; } -- 2.30.2