]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
mm: Try invalidate disk caches last when out of memory
authorZhang Boyang <zhangboyang.id@gmail.com>
Sat, 15 Oct 2022 14:15:11 +0000 (22:15 +0800)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 27 Oct 2022 13:49:48 +0000 (15:49 +0200)
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 there are no other ways to get free memory.

Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
grub-core/kern/mm.c

index 75f6eacbeec873ddf78a2358c4310d086cbd91c3..ae2279133228a0ceffe08c6f113fa2e5110e584c 100644 (file)
@@ -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;
     }