Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

244
Visualizações
Is mmap + madvise really a form of async I/O?

I'm trying to figure out if mmap'ing a file, and then using madvise() or posix_madvise() with MADV_WILLNEED/POSIX_MADV_WILLNEED actually triggers background async I/O for read-ahead. The man pages for madvise don't specify whether this is the case - the actual behavior of madvise is left mostly unclear, in order to allow for flexibility of the implementation.

But does any actual mainstream POSIX implementation (like Linux) actually perform async file I/O when madvise() with MADV_WILLNEED is called? I can't seem to get any reliable information about this. This question suggests it does, on Linux at least, even if it is not ideal since there is no callback mechanism.

This book excerpt claims that posix_fadvise with POSIX_FADV_WILLNEED will do asynchronous read ahead, but doesn't mention if madvise() does async read ahead.

Furthermore, it would seem that the whole concept of "read-ahead" I/O doesn't really make any sense unless it's asynchronous. If it was synchronous, it simply makes the user application block for the read-ahead, instead of later when actually reading the file, which doesn't seem like a particularly powerful optimization.

So, does madvise() with MADV_WILLNEED actually do async read-ahead on any mainstream platform (like Linux)?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

With Linux you can always check the source code.

See fadvise.c:

case POSIX_FADV_WILLNEED:
    ...
    force_page_cache_readahead(mapping, f.file, start_index,
                   nrpages);
    break;

So posix_fadvise calls force_page_cache_readahead to perform readahead.

Now lets look at madvise.c:

static long madvise_willneed(...)
{
    ...
    force_page_cache_readahead(file->f_mapping, file, start, end-start);
    return 0;
}

So MADV_WILLNEED and POSIX_FADV_WILLNEED are equivalent on Linux.

Can this be called asynchronous I/O? I don't think so. Async IO usually implies there is some notification that allows you to retrieve data. Advise is just an advise: not only you do not know when data is ready to be read, but if you are too late, data might be thrown away already.

over 4 years ago · Santiago Trujillo Relatório

0

In general, you should assume that the m* functions won't perform async readahead.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda