3

ここで概説されている指示に従って、C ++で(Ubuntu10.04のposixaioライブラリを使用して)非同期でディスクの読み取りと書き込みを行おうとしています:aioチュートリアル。非同期で読み取りと書き込みを行うことはできますが、ある種の小さなメモリリークが発生するのではないかと心配しています。私のvalgrindの出力は、288バイトが失われた可能性があり、3,648バイトがまだ到達可能であることを示しています。これらの数値は、ファイルから実際に読み取られるバイト数とは無関係のようです。このリークをどこで、どのように排除するかがわかりません。aioライブラリに問題があるようにさえ見えます。誰かがこれを見たことがありますか?完全なvalgrind出力は以下のとおりです。前もって感謝します。

== 22330 ==
== 22330 ==ヒープの概要:
== 22330 ==終了時に使用中:3ブロックで3,936バイト
== 22330 ==合計ヒープ使用量:25の割り当て、22の解放、15,648バイトの割り当て
== 22330 ==
== 22330==1ブロックの64バイトは損失レコード1/3でまだ到達可能です
== 22330 == 0x4C274A8:malloc(vg_replace_malloc.c:236)
== 22330 == by 0x4C27522:realloc(vg_replace_malloc.c:525)
== 22330 == by 0x504CAF1:__aio_enqueue_request(aio_misc.c:127)
== 22330 == by 0x504D25A:aio_read(aio_read.c:30)
== 22330 == by 0x406EB7:baio :: read(std :: string、char *、long)(baio_unix.cxx:58)
== 22330 == by 0x40613E:test_read_helper(char *)(test_read.cxx:16)
== 22330 == by 0x4063E1:test_read()(test_read.cxx:54)
== 22330 == by 0x40664C:test_read_main(int、char **)(test_read.cxx:74)
== 22330 == by 0x40959D:testlib_run_test_unit(unsigned long、int、char **)(testlib_main.cxx:116)
== 22330 == by 0x4097A9:testlib_main(int、char **)(testlib_main.cxx:155)
== 22330 == by 0x4060B4:main(test_driver.cxx:12)
== 22330 ==
== 22330==1ブロックの288バイトが損失レコード2/3で失われる可能性があります
== 22330 == 0x4C267CC:calloc(vg_replace_malloc.c:467)
== 22330 == by 0x4012395:_dl_allocate_tls(dl-tls.c:300)
== 22330 == by 0x4E34728:pthread_create @@ GLIBC_2.2.5(allocatestack.c:561)
== 22330 == by 0x504C9A8:__aio_enqueue_request(aio_misc.h:60)
== 22330 == by 0x504D25A:aio_read(aio_read.c:30)
== 22330 == by 0x406EB7:baio :: read(std :: string、char *、long)(baio_unix.cxx:58)
== 22330 == by 0x40613E:test_read_helper(char *)(test_read.cxx:16)
== 22330 == by 0x4063E1:test_read()(test_read.cxx:54)
== 22330 == by 0x40664C:test_read_main(int、char **)(test_read.cxx:74)
== 22330 == by 0x40959D:testlib_run_test_unit(unsigned long、int、char **)(testlib_main.cxx:116)
== 22330 == by 0x4097A9:testlib_main(int、char **)(testlib_main.cxx:155)
== 22330 == by 0x4060B4:main(test_driver.cxx:12)
== 22330 ==
== 22330==1ブロックの3,584バイトは3/3の損失レコードでまだ到達可能です
== 22330 == 0x4C267CC:calloc(vg_replace_malloc.c:467)
== 22330 == by 0x504CA27:__aio_enqueue_request(aio_misc.c:139)
== 22330 == by 0x504D25A:aio_read(aio_read.c:30)
== 22330 == by 0x406EB7:baio :: read(std :: string、char *、long)(baio_unix.cxx:58)
== 22330 == by 0x40613E:test_read_helper(char *)(test_read.cxx:16)
== 22330 == by 0x4063E1:test_read()(test_read.cxx:54)
== 22330 == by 0x40664C:test_read_main(int、char **)(test_read.cxx:74)
== 22330 == by 0x40959D:testlib_run_test_unit(unsigned long、int、char **)(testlib_main.cxx:116)
== 22330 == by 0x4097A9:testlib_main(int、char **)(testlib_main.cxx:155)
== 22330 == by 0x4060B4:main(test_driver.cxx:12)
== 22330 ==
== 22330 ==リークの概要:
== 22330 ==間違いなく失われました:0ブロックで0バイト
== 22330 ==間接的に失われました:0ブロックで0バイト
== 22330 ==失われる可能性:1ブロックで288バイト
== 22330 ==まだ到達可能:2ブロックで3,648バイト
== 22330 ==抑制:0ブロックで0バイト
4

1 に答える 1

2

2 番目のブロックは、非同期読み取りを処理するために作成されたライブラリ所有のスレッドに関連付けられたスレッド ローカル ストレージのように見えます。

==22330==    by 0x4012395: _dl_allocate_tls (dl-tls.c:300)
==22330==    by 0x4E34728: pthread_create@@GLIBC_2.2.5 (allocatestack.c:561)

1 番目と 3 番目は、未解決の非同期読み取りに関連付けられた内部構造体のように見えます。

これだけ気をつけて長く走れるなら、ちょっとした慈悲に感謝したくなる本能。ライブラリには、非同期読み取りの結果を関連付けるために永続メモリを割り当てるためのある程度の自由度が必要です。

于 2010-11-22T18:23:21.843 に答える