.Net アセンブリローディングの最適化

.Net アセンブリローディングの最適化

これはdllに関する.Netの質問ですが、Linuxに展開しているので、Linuxの質問です。

私は単一のLinuxシステムに数十の異なる.Netアプリケーションをデプロイします。

各個々のアプリケーションには、アプリケーション間で同じ複数の.dllファイルがあります。

私の質問は次のとおりです。 .Net/Monoは別々のファイルにもかかわらず同じであることを認識して、自動的にメモリ使用量を最適化しますか?

これらのファイルを共有メモリにロードし、メモリ使用量を減らすために中央の場所に移動するにはどうすればよいですか?

私の質問は、さまざまなUNIXベースのシステムで.soファイルがどのように処理されるかについての私の経験に基づいて書かれています。

参考までに、以下は1つのアプリケーションの.dllダンプです。

docroot@machine:~/Deployment/PrimaryApp_2023-07-12_01-16-59$ file *.dll */*.dll
AppConfigSdk.dll:                                      PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
AppLoginSdk.dll:                                       PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
Dapper.Transaction.dll:                                PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
Dapper.dll:                                            PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
DataAccess.dll:                                        PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
Microsoft.AspNetCore.Mvc.Razor.Extensions.dll:         PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.dll: PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
Microsoft.AspNetCore.Razor.Language.dll:               PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
Microsoft.CodeAnalysis.CSharp.dll:                     PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
Microsoft.CodeAnalysis.Razor.dll:                      PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
Microsoft.CodeAnalysis.dll:                            PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
Microsoft.Extensions.DependencyModel.dll:              PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
NLog.Extensions.Logging.dll:                           PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
NLog.Web.AspNetCore.dll:                               PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
NLog.dll:                                              PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
Newtonsoft.Json.dll:                                   PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
System.Data.SqlClient.dll:                             PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
PrimaryApp.dll:                                        PE32 executable (console) Intel 80386 Mono/.Net assembly, for MS Windows
cs/Microsoft.CodeAnalysis.CSharp.resources.dll:        PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
cs/Microsoft.CodeAnalysis.resources.dll:               PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
de/Microsoft.CodeAnalysis.CSharp.resources.dll:        PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
de/Microsoft.CodeAnalysis.resources.dll:               PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
es/Microsoft.CodeAnalysis.CSharp.resources.dll:        PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
es/Microsoft.CodeAnalysis.resources.dll:               PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
fr/Microsoft.CodeAnalysis.CSharp.resources.dll:        PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
fr/Microsoft.CodeAnalysis.resources.dll:               PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
it/Microsoft.CodeAnalysis.CSharp.resources.dll:        PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
it/Microsoft.CodeAnalysis.resources.dll:               PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
ja/Microsoft.CodeAnalysis.CSharp.resources.dll:        PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
ja/Microsoft.CodeAnalysis.resources.dll:               PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
ko/Microsoft.CodeAnalysis.CSharp.resources.dll:        PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
ko/Microsoft.CodeAnalysis.resources.dll:               PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
pl/Microsoft.CodeAnalysis.CSharp.resources.dll:        PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
pl/Microsoft.CodeAnalysis.resources.dll:               PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
pt-BR/Microsoft.CodeAnalysis.CSharp.resources.dll:     PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
pt-BR/Microsoft.CodeAnalysis.resources.dll:            PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
ru/Microsoft.CodeAnalysis.CSharp.resources.dll:        PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
ru/Microsoft.CodeAnalysis.resources.dll:               PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
tr/Microsoft.CodeAnalysis.CSharp.resources.dll:        PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
tr/Microsoft.CodeAnalysis.resources.dll:               PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
zh-Hans/Microsoft.CodeAnalysis.CSharp.resources.dll:   PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
zh-Hans/Microsoft.CodeAnalysis.resources.dll:          PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
zh-Hant/Microsoft.CodeAnalysis.CSharp.resources.dll:   PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows
zh-Hant/Microsoft.CodeAnalysis.resources.dll:          PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows

[編集]明確にするには...同じ.soファイルをロードするAIXの2つのプロセスは、その.soの読み取り専用コードブロックの物理メモリを共有します。つまり、最初のプロセスはディスクから.soをロードしますが、2番目のプロセスは同じ物理メモリを指すページテーブルを変更します。 Linuxにも同様の最適化機能があるようですが、わかりません。

ベストアンサー1

これらのファイルを共有メモリにロードし、メモリ使用量を減らすために中央の場所に移動するにはどうすればよいですか?

これは共有メモリの動作/使用方法ではありません。異なるプロセス間のメモリは、オペレーティングシステムを介してのみ共有できます。モノは全く参加しません。 Linuxでは、ケースマンこれは可能です。

これを行うには、mono使用するページに注釈を付ける必要があり、MADV_MERGEABLEKSMを有効にする必要があります(リンクされたページを参照)。さらに、KSMはプロセス間の境界を弱めるため、一部のシステムではセキュリティ上の理由で無効になる可能性があります。

カーネルロードアセンブリを共有することが推奨されるかどうかはわかりませんmono(私の考えではそうではありません)。ソースコードをすばやく調べて、知っている兆候があるかどうかを確認しましたが、MADV_MERGEABLE何も見つかりませんでした。これは、コアに簡単で効果的な追加になる可能性があるため、これを改善することを決定した場合、管理者はパッチを歓迎すると思います。

おすすめ記事