This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
When linking a huge binary, gold uses a lot of memory because it keeps the input files mapped throughout the link. This can slow down the link considerably and sometimes the linker runs out of memory. The attached patch adds an option that can reduce gold's memory usage considerably by letting it unmap the memory used by input files between linker passes. I had a bit of a dilemma with the option name. Ideally, I wanted to use --[no-]keep-files-mapped, but that option already exists, to control whether the linker maps files as a whole instead of piecemeal. I chose to rename that option to --[no-]map-whole-files, which is closer to its actual meaning, and adopt --keep-files-mapped for the new control. The defaults are the same as before: --map-whole-files is the default for 64-bit linkers, --no-map-whole-files is the default for 32-bit linkers, and --keep-files-mapped is the default for either case. For mapping whole files, I changed it to create the initial whole file mapping at the first request for any view, rather than as soon as the file is opened. I also keep the whole file view on the list of views for the file, making it eligible for removal. I found a couple of gotchas in Add_symbols::run() and Scan_relocs::run() -- gold was calling release() on the File object before deleting the sd_ and rd_ objects, both of which contain several File_view objects obtained from get_lasting_view(). With those File_view objects still alive, release() was not actually clearing the views. Linking a 400MB binary, according to gold --stats output, with the 64-bit default --map-whole-files, the --no-keep-files-mapped option reduced the total number of bytes mmaped at one time from 1011 MB to only 32 MB; link time went down marginally from 19.6s to 19.3s (wall time). According to ps, the memory high-water mark was reduced from 478,297 pages to 236,276 pages. Experiments with other combinations of the two options showed that --no-keep-files-mapped --no-map-whole-files increased link time slightly, while --keep-files-mapped --no-map-whole-files increased link time quite a bit (to 37s). All tests pass on x86_64, debug and opt. OK to commit? -cary * fileread.cc (File_read::~File_read): Don't delete whole_file_view_. (File_read::open[1]): Remove initial mapping of whole_file_view_. (File_read::open[2]): Add whole_file_view_ to list of views. (File_read::make_view): Remove test of whole_file_view_. (File_read::find_or_make_view): Create whole_file_view_ if necessary. (File_read::clear_views): Replace bool parameter with enum; adjust all callers. Don't delete views with unowned data; do delete cached views and views from archives if --no-keep-files-mapped is set. Set whole_file_view_ to NULL if clearing the corresponding view. * fileread.h (File_read::Clear_views_mode): New enum. (File_read::View::is_data_owned): New method. (File_read::clear_views): Replace bool parameter with enum; adjust all callers. * options.h (General_options): Change keep_files_mapped option; add map_whole_files. * readsyms.cc (Add_symbols::run): Delete sd_ object before releasing the file. * reloc.cc (Scan_relocs::run): Delete rd_ object before releasing the file.
Attachment:
gold-no-keep-patch.txt
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |