Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1ojhwv-0008RB-0K for mharc-grub-devel@gnu.org; Sat, 15 Oct 2022 10:15:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56924) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ojhwt-0008Pu-8v for grub-devel@gnu.org; Sat, 15 Oct 2022 10:15:36 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:38487) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ojhwr-0002uF-PJ for grub-devel@gnu.org; Sat, 15 Oct 2022 10:15:35 -0400 Received: by mail-pl1-x634.google.com with SMTP id o21so4740173ple.5 for ; Sat, 15 Oct 2022 07:15:33 -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=GE6At6AR1ZpUFN/RjWg1p7hHiotaZwvEE99sKRlkpis=; b=i+uFmdz9if3OdJV7F4OtYAzxeVKdGE9R1OVmY8LIeYz01swpd6fXIAXJ7osIvD4CAB KhA82bWQxr9wpa/gMSUx/40zsk/FOWgnQZJmfFQgH4cGAkU4OHZYn25TyeApxafV4ljK apRFVWTsLGlYR0jQIaDd7+JJv2y0bOGt8vg/r73eQAX47iHZ7Xn5YOs2I9yWt3boK/rq JF8cEcxnR+eevjb6BSiMpn60uVmxBzSdtdhIVp9erfFiuBGW1m3yCxDhkZ2PKkzovEUu veor9V+ZDp4xqboIaAWZryGJAn8GezJsgerCzVh+x9DWzkAWqVrllQ1/9tFpsxKJtmVs LcCA== 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=GE6At6AR1ZpUFN/RjWg1p7hHiotaZwvEE99sKRlkpis=; b=w4oYb1Q9A9Dxu7p/O9i+87VbzveYGRtMBnz2mL5BKgclkMA2oBFDbYuEmdGD/1zKal ljX8K44cpteUbjXc0EhKb+5KtcJNS9d/+oG2Or8vCL9gu2O0XqREktyWLkwEXKbyoWHi XAxBEzGO54ic5qb2kk+eddUnkckj+1dgINc0pmV0uMa0lcyNG0tHeRPyP8YhXyO3Ws2Z AOe7cF6/sKtVvI8SFqe4Z4xLKSM/pFDQKpIY8/06zAUgYl+vOXvgPZoM5z+aQSSVOjNI oBEstf+hui4xEQY04K2BrRvHHzoAXI+gtljK4qYvrg9zZIo8bkcQocm3ozKMT8FyyzNt 7xKw== X-Gm-Message-State: ACrzQf1UEsKbcqONJlhczf2aEJnPV6AnSI/rmcrC+6twBcM/ihrqUgPT GG1Zv6AhEyi+x5Lgw8cDQurHepN1j9zIsw== X-Google-Smtp-Source: AMsMyM7lSxUj3q/kGPwoC8ZWolxsk62U1PuISITCdZnSmK9SOk4owHdevRCYbk0RqVs0R5E/+/3zCw== X-Received: by 2002:a17:902:8205:b0:185:33e:2a0e with SMTP id x5-20020a170902820500b00185033e2a0emr3022135pln.92.1665843332339; Sat, 15 Oct 2022 07:15:32 -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 i15-20020a62870f000000b00562adeac326sm3580890pfe.102.2022.10.15.07.15.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Oct 2022 07:15:32 -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 , Daniel Kiper Subject: [PATCH v4 1/2] mm: Try invalidate disk caches last when out of memory Date: Sat, 15 Oct 2022 22:15:11 +0800 Message-Id: <20221015141512.72193-2-zhangboyang.id@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221015141512.72193-1-zhangboyang.id@gmail.com> References: <20221015141512.72193-1-zhangboyang.id@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=zhangboyang.id@gmail.com; helo=mail-pl1-x634.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: Sat, 15 Oct 2022 14:15:36 -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 Reviewed-by: Daniel Kiper Reviewed-by: Patrick Steinhardt --- 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