summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDong-Heon Jung <dheon.jung@samsung.com>2019-08-31 06:05:53 +0900
committer정동헌/Common Platform Lab(SR)/Principal Engineer/삼성전자 <dheon.jung@samsung.com>2019-12-03 14:57:12 +0900
commit4b8fcc6d449e3bcd9c5e95181c063e6ce73e40d1 (patch)
tree60458361d0e1fce1d53c2ac1f75473de866f3109
parentedfccc15cc34faeb13fecbb5993833f92d5cd18c (diff)
downloadcoreclr-4b8fcc6d449e3bcd9c5e95181c063e6ce73e40d1.tar.gz
coreclr-4b8fcc6d449e3bcd9c5e95181c063e6ce73e40d1.tar.bz2
coreclr-4b8fcc6d449e3bcd9c5e95181c063e6ce73e40d1.zip
Mark Relocation Section as NotNeeded (#25715)
- After relocation, relocation section in zap image is not necessary. - Mark the section as NotNeeded by giving advice(madvise with MADV_DONTNEED) - It reduces 120~150KB PSS in tizen sample apps.
-rw-r--r--src/pal/inc/pal.h16
-rw-r--r--src/pal/src/include/pal/map.hpp7
-rw-r--r--src/pal/src/loader/module.cpp33
-rw-r--r--src/pal/src/map/map.cpp51
-rw-r--r--src/vm/peimagelayout.cpp3
5 files changed, 110 insertions, 0 deletions
diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h
index 11b434dcd2..5a4e758aaf 100644
--- a/src/pal/inc/pal.h
+++ b/src/pal/inc/pal.h
@@ -2755,6 +2755,22 @@ Return value:
BOOL
PAL_LOADUnloadPreloadedPEFiles();
+/*++
+ PAL_LOADMarkSectionAsNotNeeded
+
+ Mark a section as NotNeeded that was loaded by PAL_LOADLoadPEFile().
+
+Parameters:
+ IN ptr - the section address mapped by PAL_LOADLoadPEFile()
+
+Return value:
+ TRUE - success
+ FALSE - failure (incorrect ptr, etc.)
+--*/
+BOOL
+PALAPI
+PAL_LOADMarkSectionAsNotNeeded(void * ptr);
+
#ifdef UNICODE
#define LoadLibrary LoadLibraryW
#define LoadLibraryEx LoadLibraryExW
diff --git a/src/pal/src/include/pal/map.hpp b/src/pal/src/include/pal/map.hpp
index 16ee58ec43..a2d8e2b748 100644
--- a/src/pal/src/include/pal/map.hpp
+++ b/src/pal/src/include/pal/map.hpp
@@ -138,6 +138,13 @@ extern "C"
returns TRUE if successful, FALSE otherwise
--*/
BOOL MAPUnmapPEFile(LPCVOID lpAddress);
+
+ /*++
+ Function :
+ MAPMarkSectionAsNotNeeded - mark a section as NotNeeded
+ returns TRUE if successful, FALSE otherwise
+ --*/
+ BOOL MAPMarkSectionAsNotNeeded(LPCVOID lpAddress);
}
namespace CorUnix
diff --git a/src/pal/src/loader/module.cpp b/src/pal/src/loader/module.cpp
index 78069b8875..35c51ac5ee 100644
--- a/src/pal/src/loader/module.cpp
+++ b/src/pal/src/loader/module.cpp
@@ -1000,6 +1000,39 @@ PAL_LOADUnloadPEFile(PVOID ptr)
}
/*++
+ PAL_LOADMarkSectionAsNotNeeded
+
+ Mark a section as NotNeeded that was loaded by PAL_LOADLoadPEFile().
+
+Parameters:
+ IN ptr - the section address mapped by PAL_LOADLoadPEFile()
+
+Return value:
+ TRUE - success
+ FALSE - failure (incorrect ptr, etc.)
+--*/
+BOOL
+PALAPI
+PAL_LOADMarkSectionAsNotNeeded(void * ptr)
+{
+ BOOL retval = FALSE;
+
+ ENTRY("PAL_LOADMarkSectionAsNotNeeded (ptr=%p)\n", ptr);
+
+ if (nullptr == ptr)
+ {
+ ERROR( "Invalid pointer value\n" );
+ }
+ else
+ {
+ retval = MAPMarkSectionAsNotNeeded(ptr);
+ }
+
+ LOGEXIT("PAL_LOADMarkSectionAsNotNeeded returns %d\n", retval);
+ return retval;
+}
+
+/*++
PAL_GetSymbolModuleBase
Get base address of the module containing a given symbol
diff --git a/src/pal/src/map/map.cpp b/src/pal/src/map/map.cpp
index 05cfd611bb..2e57bddf09 100644
--- a/src/pal/src/map/map.cpp
+++ b/src/pal/src/map/map.cpp
@@ -3147,3 +3147,54 @@ BOOL MAPUnmapPEFile(LPCVOID lpAddress)
TRACE_(LOADER)("MAPUnmapPEFile returning %d\n", retval);
return retval;
}
+
+/*++
+Function :
+ MAPMarkSectionAsNotNeeded - Mark a section as NotNeeded
+ returns TRUE if successful, FALSE otherwise
+--*/
+BOOL MAPMarkSectionAsNotNeeded(LPCVOID lpAddress)
+{
+ TRACE_(LOADER)("MAPMarkSectionAsNotNeeded(lpAddress=%p)\n", lpAddress);
+
+ if ( NULL == lpAddress )
+ {
+ ERROR_(LOADER)( "lpAddress cannot be NULL\n" );
+ return FALSE;
+ }
+
+ BOOL retval = TRUE;
+ CPalThread * pThread = InternalGetCurrentThread();
+ InternalEnterCriticalSection(pThread, &mapping_critsec);
+ PLIST_ENTRY pLink, pLinkNext = NULL;
+
+ // Look through the entire MappedViewList for all mappings associated with the
+ // section with an address 'lpAddress' which we want to mark as NotNeeded.
+
+ for(pLink = MappedViewList.Flink;
+ pLink != &MappedViewList;
+ pLink = pLinkNext)
+ {
+ pLinkNext = pLink->Flink;
+ PMAPPED_VIEW_LIST pView = CONTAINING_RECORD(pLink, MAPPED_VIEW_LIST, Link);
+
+ if (pView->lpAddress == lpAddress) // this entry is associated with the section
+ {
+ if (-1 == madvise(pView->lpAddress, pView->NumberOfBytesToMap, MADV_DONTNEED))
+ {
+ ERROR_(LOADER)("Unable to mark the section as NotNeeded.\n");
+ retval = FALSE;
+ }
+ else
+ {
+ pView->dwDesiredAccess = 0;
+ }
+ break;
+ }
+ }
+
+ InternalLeaveCriticalSection(pThread, &mapping_critsec);
+
+ TRACE_(LOADER)("MAPMarkSectionAsNotNeeded returning %d\n", retval);
+ return retval;
+}
diff --git a/src/vm/peimagelayout.cpp b/src/vm/peimagelayout.cpp
index 1d08558c70..719c90eece 100644
--- a/src/vm/peimagelayout.cpp
+++ b/src/vm/peimagelayout.cpp
@@ -296,6 +296,9 @@ void PEImageLayout::ApplyBaseRelocations(BOOL isRelocated)
ThrowLastError();
}
}
+#ifdef FEATURE_PAL
+ PAL_LOADMarkSectionAsNotNeeded((void*)dir);
+#endif // FEATURE_PAL
#endif // CROSSGEN_COMPILE
if (pFlushRegion != NULL)