AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / unix / Perguntas / 788843
Accepted
Ole Tange
Ole Tange
Asked: 2024-12-30 03:53:08 +0800 CST2024-12-30 03:53:08 +0800 CST 2024-12-30 03:53:08 +0800 CST

Por que não consigo interceptar `write` em `seq`?

  • 772

Com base na velocidade de E/S do arquivo Limit que criei https://git.data.coop/tange/tangetools/src/branch/master/iothrottle

Funciona para alguns programas:

iothrottle -i 10M cat foo > bar # Yes, here you could just use pv
iothrottle -o 1M ffmpeg -i foo.mp3 foo.wav
iothrottle -o 1M cp -a foodir /other/fs/foodir

Isto não:

iothrottle -o 1M cp -a foodir /same/fs/foodir

porque no mesmo sistema de arquivos cpusa uma única chamada para copy_file_rangecada arquivo.

Estou bem com essa limitação.

Também não funciona para seq. Quando corro, strace seq 100000recebo:

write(1, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14"..., 8192) = 8192
write(1, "\n1861\n1862\n1863\n1864\n1865\n1866\n1"..., 4096) = 4096
write(1, "2680\n2681\n2682\n2683\n2684\n2685\n26"..., 4096) = 4096
write(1, "499\n3500\n3501\n3502\n3503\n3504\n350"..., 4096) = 4096
write(1, "18\n4319\n4320\n4321\n4322\n4323\n4324"..., 4096) = 4096
write(1, "7\n5138\n5139\n5140\n5141\n5142\n5143\n"..., 4096) = 4096
write(1, "\n5957\n5958\n5959\n5960\n5961\n5962\n5"..., 4096) = 4096
write(1, "6776\n6777\n6778\n6779\n6780\n6781\n67"..., 4096) = 4096
write(1, "595\n7596\n7597\n7598\n7599\n7600\n760"..., 4096) = 4096
write(1, "14\n8415\n8416\n8417\n8418\n8419\n8420"..., 4096) = 4096
write(1, "3\n9234\n9235\n9236\n9237\n9238\n9239\n"..., 3838) = 3838

Então parece que chama write(e não alguma mmapoutra mágica), e assim deveria funcionar.

Mas quando eu corro: IOTHROTTLE_DEBUG=1 iothrottle -o 1M seq 10000 >/dev/nullEu recebo:

init called: default read_limit=0, write_limit=0
IOTHROTTLE_READ=0
IOTHROTTLE_WRITE=1048576
Final read_limit=0, write_limit=1048576
allowed: 608 written: 0
allowed: 617 written: 0

Isso me diz que iothrottleintercepta apenas 2 chamadas para write.

O que estou perdendo?

shared-library
  • 1 1 respostas
  • 38 Views

1 respostas

  • Voted
  1. Best Answer
    Stéphane Chazelas
    2024-12-30T15:24:18+08:002024-12-30T15:24:18+08:00

    Seus iothrottletrabalhos sequestram as funções da biblioteca C que acabam¹ fazendo chamadas de sistema como write(), pwrite()ou splice()².

    stracerastreia as chamadas do sistema, não as chamadas de função de biblioteca dinâmica, para as quais você precisa ltraceem sistemas GNU ( ltracetambém pode rastrear chamadas do sistema com -S; em outros sistemas, comandos equivalentes como trussou tusc(HP/UX) também podem fazer as duas coisas).

    Aqui zshdo Debian:

    $ ltrace seq 10 |& grep -e{write,put,send}
    fwrite_unlocked("1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", 21, 1, 0x7f5b1d7185c0) = 1
    
    $ ltrace -S seq 10 |& grep -e{write,put,send}
    fwrite_unlocked("1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", 21, 1, 0x7fe86c4785c0 <unfinished ...>
    <... fwrite_unlocked resumed> )                  = 1
    write@SYS(1, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", 211
    

    seqestá chamando a fwrite_unlocked()função stdio que você não sequestra, fwrite()o que não explica por que sua função iothrottlenão é eficaz nela.

    $ nm -uD  =seq | grep -e{write,put,send}
                     U fputc_unlocked@GLIBC_2.2.5
                     U fputs_unlocked@GLIBC_2.2.5
                     U fwrite@GLIBC_2.2.5
                     U fwrite_unlocked@GLIBC_2.2.5
    

    Mostra alguns dos símbolos dinâmicos -uindefinidos que precisam ( podem ser escritos em outros shells).-Dseq=seq"$(command -v seq)"

    Chamar no ambiente o símbolo dinâmico que mostra informações sobre qual símbolo é encontrado, onde e para quem também pode ajudar seq:LD_DEBUG=bindings

    $ LD_PRELOAD=$PWD/iothrottle.so IOTHROTTLE_WRITE=1000 LD_DEBUG=bindings seq 10  |& grep -e{write,put,send,iothrot}
         14982: binding file .../iothrottle.so [0] to .../iothrottle.so [0]: normal symbol `init'
         14982: binding file .../iothrottle.so [0] to .../iothrottle.so [0]: normal symbol `original_pread'
         14982: binding file .../iothrottle.so [0] to .../iothrottle.so [0]: normal symbol `original_write'
         14982: binding file .../iothrottle.so [0] to .../iothrottle.so [0]: normal symbol `original_pwrite'
         14982: binding file .../iothrottle.so [0] to .../iothrottle.so [0]: normal symbol `original_copy_file_range'
         14982: binding file .../iothrottle.so [0] to .../iothrottle.so [0]: normal symbol `original_fwrite'
         14982: binding file .../iothrottle.so [0] to .../iothrottle.so [0]: normal symbol `original_writev'
         14982: binding file .../iothrottle.so [0] to .../iothrottle.so [0]: normal symbol `original_fflush'
         14982: binding file .../iothrottle.so [0] to .../iothrottle.so [0]: normal symbol `original_readv'
         14982: binding file .../iothrottle.so [0] to .../iothrottle.so [0]: normal symbol `original_sendfile'
         14982: binding file .../iothrottle.so [0] to .../iothrottle.so [0]: normal symbol `original_splice'
         14982: binding file .../iothrottle.so [0] to /lib/x86_64-linux-gnu/libc.so.6 [0]: normal symbol `__cxa_finalize' [GLIBC_2.2.5]
         14982: binding file .../iothrottle.so [0] to .../iothrottle.so [0]: normal symbol `original_read'
         14982: binding file .../iothrottle.so [0] to seq [0]: normal symbol `stderr' [GLIBC_2.2.5]
         14982: calling init: .../iothrottle.so
         14982: binding file .../iothrottle.so [0] to /lib/x86_64-linux-gnu/libc.so.6 [0]: normal symbol `clock_gettime' [GLIBC_2.17]
         14982: binding file .../iothrottle.so [0] to /lib/x86_64-linux-gnu/libc.so.6 [0]: normal symbol `getenv' [GLIBC_2.2.5]
         14982: binding file .../iothrottle.so [0] to /lib/x86_64-linux-gnu/libc.so.6 [0]: normal symbol `strtoull' [GLIBC_2.2.5]
         14982: binding file seq [0] to /lib/x86_64-linux-gnu/libc.so.6 [0]: normal symbol `fwrite_unlocked' [GLIBC_2.2.5]
         14982: binding file seq [0] to .../iothrottle.so [0]: normal symbol `fflush' [GLIBC_2.2.5]
         14982: binding file .../iothrottle.so [0] to /lib/x86_64-linux-gnu/libc.so.6 [0]: normal symbol `dlsym' [GLIBC_2.34]
         14982: binding file .../iothrottle.so [0] to /lib/x86_64-linux-gnu/libc.so.6 [0]: normal symbol `fflush'
         14982: binding file .../iothrottle.so [0] to .../iothrottle.so [0]: normal symbol `throttle'
    

    ¹ ou pode acabar como os stdio, que muitas vezes apenas enchem alguns buffers sem fazer nenhuma E/S até que esses buffers sejam esvaziados.

    ² A propósito, há mais funções como send(), sendto(), sendmsg()que também podem fazer algumas E/S e mais funções stdio que podem acabar fazendo algumas write()s como fput(), putchar(), printf()....

    • 1

relate perguntas

  • O que significa "dependências diretas não utilizadas"?

  • Mint 19 - Pidgin IM - Erro ao iniciar: libpurple.so.0: não é possível abrir o arquivo de objeto compartilhado

  • A ABI da biblioteca compartilhada é compatível, desde que suas versões sejam as mesmas?

  • Como instalar uma biblioteca compartilhada ao instalar em um caminho do sistema?

  • Pandoc está faltando um arquivo de biblioteca [fechado]

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Possível firmware ausente /lib/firmware/i915/* para o módulo i915

    • 3 respostas
  • Marko Smith

    Falha ao buscar o repositório de backports jessie

    • 4 respostas
  • Marko Smith

    Como exportar uma chave privada GPG e uma chave pública para um arquivo

    • 4 respostas
  • Marko Smith

    Como podemos executar um comando armazenado em uma variável?

    • 5 respostas
  • Marko Smith

    Como configurar o systemd-resolved e o systemd-networkd para usar o servidor DNS local para resolver domínios locais e o servidor DNS remoto para domínios remotos?

    • 3 respostas
  • Marko Smith

    apt-get update error no Kali Linux após a atualização do dist [duplicado]

    • 2 respostas
  • Marko Smith

    Como ver as últimas linhas x do log de serviço systemctl

    • 5 respostas
  • Marko Smith

    Nano - pule para o final do arquivo

    • 8 respostas
  • Marko Smith

    erro grub: você precisa carregar o kernel primeiro

    • 4 respostas
  • Marko Smith

    Como baixar o pacote não instalá-lo com o comando apt-get?

    • 7 respostas
  • Martin Hope
    user12345 Falha ao buscar o repositório de backports jessie 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl Por que a maioria dos exemplos do systemd contém WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky Como exportar uma chave privada GPG e uma chave pública para um arquivo 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll status systemctl mostra: "Estado: degradado" 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim Como podemos executar um comando armazenado em uma variável? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S Por que /dev/null é um arquivo? Por que sua função não é implementada como um programa simples? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 Como ver as últimas linhas x do log de serviço systemctl 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - pule para o final do arquivo 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla Por que verdadeiro e falso são tão grandes? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis Substitua a string em um arquivo de texto enorme (70 GB), uma linha 2017-12-30 06:58:33 +0800 CST

Hot tag

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve