Skip to contentSkip to conversation

Incorrect comment in disk.h (and bigger cache) ?

DISCUSSION Benjamin Herrenschmidt 3 participants 6 messages Feb 9, 2023 – Feb 15, 2023

lore
Share & tools
lore
#0 lore raw

Hi 1

Stumbled upon this:

/* The size of a disk cache in 512B units. Must be at least as big as the
largest supported sector size, currently 16K. */
#define GRUB_DISK_CACHE_BITS 6
#define GRUB_DISK_CACHE_SIZE (1 << GRUB_DISK_CACHE_BITS)

It's me or somebody had a bad day with math ? :-) It's 32K no ?

I'm tempted to increase this to speed things up on UEFI especially, either that or maybe changing grub_fshelp_read_file() so that get_block can optionally return a count of contiguous blocks so we can issue larger requests ?

What do you think ?

Cheers,
Ben.

#1 lore raw
Quoted 8 lines · * On 2/9/23 01:05, Benjamin Herrenschmidt wrote:

Stumbled upon this:

/* The size of a disk cache in 512B units. Must be at least as big as the
largest supported sector size, currently 16K. */
#define GRUB_DISK_CACHE_BITS 6
#define GRUB_DISK_CACHE_SIZE (1 << GRUB_DISK_CACHE_BITS)

It's me or somebody had a bad day with math ? :-) It's 32K no ?

I believe that you merely misinterpreted the comment, though it would be good to clarify it. The largest currently supported sector size seems to be 16 KByte, not the cache size. This said, the comment might also be out of date, not sure if the sector size is actually still limited any longer. biosdisk for instance should give hints to that (although, naturally, that is not the only place where this is used).

Quoted 4 lines

I'm tempted to increase this to speed things up on UEFI especially, either that or maybe changing grub_fshelp_read_file() so that get_block can optionally return a count of contiguous blocks so we can issue larger requests ?

Is that really necessary? Note that this is also used for legacy MBR/BIOS systems and I faintly remember places using that, which may do so in a fixed way, so I advise to check it well if you really intend to change it.

Mihai

#2 lore raw
Quoted 8 lines · Mihai Moldovan
Quoted 7 lines · * On 2/9/23 01:05, Benjamin Herrenschmidt wrote:

Stumbled upon this:

/* The size of a disk cache in 512B units. Must be at least as big as the
largest supported sector size, currently 16K. */
#define GRUB_DISK_CACHE_BITS 6
#define GRUB_DISK_CACHE_SIZE (1 << GRUB_DISK_CACHE_BITS)

Quoted 8 lines
Quoted 1 line

It's me or somebody had a bad day with math ? :-) It's 32K no ?

I believe that you merely misinterpreted the comment, though it would be good to clarify it. The largest currently supported sector size seems to be 16 KByte, not the cache size. This said, the comment might also be out of date, not sure if the sector size is actually still limited any longer. biosdisk for instance should give hints to that (although, naturally, that is not the only place where this is used).

After looking at this once again I agree with Mihai. Though I am not native speaker. So, you have to take it with a grain of salt... :-) Anyway, I think the comment should be clarified...

Quoted 8 lines
Quoted 4 lines

I'm tempted to increase this to speed things up on UEFI especially, either that or maybe changing grub_fshelp_read_file() so that get_block can optionally return a count of contiguous blocks so we can issue larger requests ?

Is that really necessary? Note that this is also used for legacy MBR/BIOS systems and I faintly remember places using that, which may do so in a fixed way, so I advise to check it well if you really intend to change it.

I concur. I think I would do this only for UEFI systems first. If at all we need to increase this value. How often the GRUB reads the same files from the disk? Did you notice faster loads/boots when you increase the disk cache size?

Daniel

#3 lore raw
Quoted 8 lines · Daniel Kiper
Quoted 3 lines

Is that really necessary? Note that this is also used for legacy MBR/BIOS systems and I faintly remember places using that, which may do so in a fixed way, so I advise to check it well if you really intend to change it.

I concur. I think I would do this only for UEFI systems first. If at all we need to increase this value. How often the GRUB reads the same files from the disk? Did you notice faster loads/boots when you increase the disk cache size?

It depends :-) But yes, we have empirical evidence. This is indeed mostly an issue on UEFI systems where we tend to load a few large files since all the modules are contained within the pre-built grub image.

Anyways, i'll play around and see if I can come up with something that works.

Just increasing the size of cache entries actually has a negative impact in things like filesystem metadata for example. And caching large files doesn't make much sense.

So I wonder if we can pass some hints or open-time flags to indicate that some files (kernel, initrd) shouldn't bother with caching, along with making get_block() be able to return a number of contiguous blocks, allowing large file reads to avoid any bouncing, caching, and enable larger chunks.

At this point, it's something I'm putting on my backburner todo list, I might get to it in the future...

Cheers,
Ben.

#4 lore raw
In reply to Mihai Moldovan
Quoted 8 lines · Mihai Moldovan
Quoted 7 lines

I'm tempted to increase this to speed things up on UEFI especially, either
that or maybe changing grub_fshelp_read_file() so that get_block can
optionally return a count of contiguous blocks so we can issue larger
requests ?

Quoted 6 lines

Is that really necessary? Note that this is also used for legacy MBR/BIOS
systems and I faintly remember places using that, which may do so in a fixed
way, so I advise to check it well if you really intend to change it.

That's ok as the MBS/BIOS bits will impose limits at other levels.

The reason I want larger IOs is that it will help with cloud setups where the EFI "disk" is actually  some kind of networked storage. We are chasing milliseconds in instance launch times :-)

Anyways, I think the "right" approach is to make get_blocks() called by grub_fshelp_read_file() optionally return the number of contiguous blocks, so we can chose to do larger chunks.

I'll look into it if/when I have time.

Cheers,
Ben.

#5 lore raw
Quoted 17 lines · Benjamin Herrenschmidt
Quoted 8 lines · Mihai Moldovan
Quoted 7 lines

I'm tempted to increase this to speed things up on UEFI especially, either
that or maybe changing grub_fshelp_read_file() so that get_block can
optionally return a count of contiguous blocks so we can issue larger
requests ?

Quoted 6 lines

Is that really necessary? Note that this is also used for legacy MBR/BIOS
systems and I faintly remember places using that, which may do so in a fixed
way, so I advise to check it well if you really intend to change it.

That's ok as the MBS/BIOS bits will impose limits at other levels.

Quoted 7 lines

The reason I want larger IOs is that it will help with cloud setups where the EFI "disk" is actually  some kind of networked storage. We are chasing milliseconds in instance launch times :-)

Anyways, I think the "right" approach is to make get_blocks() called by grub_fshelp_read_file() optionally return the number of contiguous blocks, so we can chose to do larger chunks.

It seems to me that this approach or something similar will be better than just increasing disk cache size.

Quoted 1 line

I'll look into it if/when I have time.

Cool! Thanks!

Daniel