From c6f3d60d6e6e3a1d3f7f23259b9d254518fa378b Mon Sep 17 00:00:00 2001 From: scott snyder Date: Wed, 20 Oct 2021 16:27:37 +0200 Subject: [PATCH 1/4] AthAllocators: A couple fixes. Fix error reporting when mprotect() fails --- should use errno, not the return value. Allow ArenaBlockAllocatorBase::reserve() to allocate blocks smaller than the originally requested block size. --- Control/AthAllocators/AthAllocators/DataPool.h | 4 ++-- Control/AthAllocators/AthAllocators/DataPool.icc | 8 ++++---- Control/AthAllocators/src/ArenaBlock.cxx | 4 ++-- Control/AthAllocators/src/ArenaBlockAllocatorBase.cxx | 5 +---- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Control/AthAllocators/AthAllocators/DataPool.h b/Control/AthAllocators/AthAllocators/DataPool.h index bc5f2ebfba6..33a2805ced5 100644 --- a/Control/AthAllocators/AthAllocators/DataPool.h +++ b/Control/AthAllocators/AthAllocators/DataPool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef ATHALLOCATORS_DATAPOOL_H @@ -159,7 +159,7 @@ public: const static typename alloc_t::Params s_params; /// minimum number of elements in pool - static const unsigned int s_minRefCount = 1024; + static constexpr size_t s_minRefCount = 1024; }; diff --git a/Control/AthAllocators/AthAllocators/DataPool.icc b/Control/AthAllocators/AthAllocators/DataPool.icc index 890fca4a2fa..da78e3de571 100644 --- a/Control/AthAllocators/AthAllocators/DataPool.icc +++ b/Control/AthAllocators/AthAllocators/DataPool.icc @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ //----------------------------------------------------------- @@ -22,7 +22,7 @@ DataPool::DataPool(size_type n /*= 0*/) : m_handle (&s_params) { if (n > 0) - m_handle.reserve (n); + m_handle.reserve (std::max (n, s_minRefCount)); } template @@ -31,7 +31,7 @@ DataPool::DataPool(const EventContext& ctx, : m_handle (static_cast(nullptr), ctx, &s_params) { if (n > 0) - m_handle.reserve (n); + m_handle.reserve (std::max (n, s_minRefCount)); } template @@ -40,7 +40,7 @@ DataPool::DataPool(SG::Arena* arena, : m_handle (arena, nullptr, &s_params) { if (n > 0) - m_handle.reserve (n); + m_handle.reserve (std::max (n, s_minRefCount)); } //----------------------------------------------------------- diff --git a/Control/AthAllocators/src/ArenaBlock.cxx b/Control/AthAllocators/src/ArenaBlock.cxx index 01bb5569a10..064b43559cd 100644 --- a/Control/AthAllocators/src/ArenaBlock.cxx +++ b/Control/AthAllocators/src/ArenaBlock.cxx @@ -172,7 +172,7 @@ void ArenaBlock::protect() int stat = mprotect (this, m_size*m_elt_size+ArenaBlockBodyOffset, PROT_READ); if (stat) { - throw SG::ExcProtection (stat); + throw SG::ExcProtection (errno); } } @@ -188,7 +188,7 @@ void ArenaBlock::unprotect() int stat = mprotect (this, m_size*m_elt_size+ArenaBlockBodyOffset, PROT_READ + PROT_WRITE); if (stat) { - throw SG::ExcProtection (stat); + throw SG::ExcProtection (errno); } } diff --git a/Control/AthAllocators/src/ArenaBlockAllocatorBase.cxx b/Control/AthAllocators/src/ArenaBlockAllocatorBase.cxx index 861f857f0b9..7521344dbc4 100644 --- a/Control/AthAllocators/src/ArenaBlockAllocatorBase.cxx +++ b/Control/AthAllocators/src/ArenaBlockAllocatorBase.cxx @@ -124,11 +124,8 @@ void ArenaBlockAllocatorBase::reserve (size_t size) } if (size > m_stats.elts.total) { // Growing the pool. - // Make a new block of the required size (but not less than nblock). + // Make a new block of the required size. size_t sz = size - m_stats.elts.total; - if (sz < m_params.nblock) { - sz = m_params.nblock; - } ArenaBlock* newblock = ArenaBlock::newBlock (sz, m_params.eltSize, m_params.constructor); -- GitLab From e3a0e1a1219c25aa5504aaffd95814dd6e6ad80e Mon Sep 17 00:00:00 2001 From: scott snyder Date: Wed, 20 Oct 2021 16:57:41 +0200 Subject: [PATCH 2/4] SiSPSeededTrackFinderData: Memory improvement. When using DataVectorWithAlloc, call reserve on it before filling in order to minimize wasted memory. --- .../SiSPSeededTrackFinderData/src/SiTrajectory_xk.cxx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/InnerDetector/InDetRecEvent/SiSPSeededTrackFinderData/src/SiTrajectory_xk.cxx b/InnerDetector/InDetRecEvent/SiSPSeededTrackFinderData/src/SiTrajectory_xk.cxx index 6825946d83b..a3c918b6b90 100644 --- a/InnerDetector/InDetRecEvent/SiSPSeededTrackFinderData/src/SiTrajectory_xk.cxx +++ b/InnerDetector/InDetRecEvent/SiSPSeededTrackFinderData/src/SiTrajectory_xk.cxx @@ -57,6 +57,7 @@ InDet::SiTrajectory_xk::convertToTrackStateOnSurface() { auto dtsos = Trk::TrackStateOnSurfaceProtContainer::make_unique(); + dtsos->reserve (1 + m_lastElement - m_firstElement); bool multi = m_tools->multiTrack(); if (m_nclusters <= m_tools->clustersmin() || pTfirst() < m_tools->pTmin()) multi = false; @@ -105,6 +106,7 @@ InDet::SiTrajectory_xk::convertToTrackStateOnSurfaceWithNewDirection() { auto dtsos = Trk::TrackStateOnSurfaceProtContainer::make_unique(); + dtsos->reserve (1 + m_lastElement - m_firstElement); bool multi = m_tools->multiTrack(); if (pTfirst() < m_tools->pTmin()) multi = false; @@ -157,6 +159,7 @@ Trk::TrackStateOnSurfaceProtContainer::ContainerUniquePtr InDet::SiTrajectory_xk::convertToSimpleTrackStateOnSurface() { auto dtsos = Trk::TrackStateOnSurfaceProtContainer::make_unique(); + dtsos->reserve (2 + m_lastElement - m_firstElement); int i = m_firstElement; @@ -210,6 +213,7 @@ Trk::TrackStateOnSurfaceProtContainer::ContainerUniquePtr InDet::SiTrajectory_xk::convertToSimpleTrackStateOnSurfaceWithNewDirection() { auto dtsos = Trk::TrackStateOnSurfaceProtContainer::make_unique(); + dtsos->reserve (1 + m_lastElement - m_firstElement); int i = m_lastElement; @@ -260,6 +264,7 @@ Trk::TrackStateOnSurfaceProtContainer::ContainerUniquePtr InDet::SiTrajectory_xk::convertToSimpleTrackStateOnSurfaceForDisTrackTrigger() { auto dtsos = Trk::TrackStateOnSurfaceProtContainer::make_unique(); + dtsos->reserve (1 + m_lastElement - m_firstElement); int i = m_firstElement; @@ -2173,12 +2178,14 @@ InDet::SiTrajectory_xk::convertToNextTrackStateOnSurface() } auto dtsos = Trk::TrackStateOnSurfaceProtContainer::make_unique(); + dtsos->reserve (m_ntos); if (i==m_ntos) { dtsos->elt_allocator().protect(); return dtsos; } + dtsos->reserve (m_ntos); for (i=0; i!=m_ntos; ++i) { auto tsos = m_elements[m_atos[i]].tsos(*dtsos, m_itos[i]); -- GitLab From 58a3834a554ec4562182f072cd8e4c63e321fe60 Mon Sep 17 00:00:00 2001 From: scott snyder Date: Wed, 20 Oct 2021 17:02:04 +0200 Subject: [PATCH 3/4] InDetAmbiTrackSelectionTool: Memory improvement. When using DataVectorWithAlloc, call reserve on it before filling in order to minimize wasted memory. --- .../src/InDetAmbiTrackSelectionTool.cxx | 1 + .../src/InDetDenseEnvAmbiTrackSelectionTool.cxx | 1 + 2 files changed, 2 insertions(+) diff --git a/InnerDetector/InDetRecTools/InDetAmbiTrackSelectionTool/src/InDetAmbiTrackSelectionTool.cxx b/InnerDetector/InDetRecTools/InDetAmbiTrackSelectionTool/src/InDetAmbiTrackSelectionTool.cxx index dd4bfb998e7..17734407109 100755 --- a/InnerDetector/InDetRecTools/InDetAmbiTrackSelectionTool/src/InDetAmbiTrackSelectionTool.cxx +++ b/InnerDetector/InDetRecTools/InDetAmbiTrackSelectionTool/src/InDetAmbiTrackSelectionTool.cxx @@ -556,6 +556,7 @@ Trk::Track* InDet::InDetAmbiTrackSelectionTool::createSubTrack( const std::vecto } auto vecTsos = Trk::TrackStateOnSurfaceProtContainer::make_unique(); + vecTsos->reserve (tsos.size()); // loop over TSOS, copy TSOS and push into vector for (const Trk::TrackStateOnSurface* tsosIt : tsos) { diff --git a/InnerDetector/InDetRecTools/InDetAmbiTrackSelectionTool/src/InDetDenseEnvAmbiTrackSelectionTool.cxx b/InnerDetector/InDetRecTools/InDetAmbiTrackSelectionTool/src/InDetDenseEnvAmbiTrackSelectionTool.cxx index f7428d7899e..20e02edfa11 100644 --- a/InnerDetector/InDetRecTools/InDetAmbiTrackSelectionTool/src/InDetDenseEnvAmbiTrackSelectionTool.cxx +++ b/InnerDetector/InDetRecTools/InDetAmbiTrackSelectionTool/src/InDetDenseEnvAmbiTrackSelectionTool.cxx @@ -1488,6 +1488,7 @@ Trk::Track* InDet::InDetDenseEnvAmbiTrackSelectionTool::createSubTrack( const st } auto vecTsos = Trk::TrackStateOnSurfaceProtContainer::make_unique(); + vecTsos->reserve (tsos.size()); // loop over TSOS, copy TSOS and push into vector for (const Trk::TrackStateOnSurface* iTsos : tsos) { -- GitLab From e8705fe6387bce2256996ac7fab2510401cf280c Mon Sep 17 00:00:00 2001 From: scott snyder Date: Wed, 20 Oct 2021 17:07:24 +0200 Subject: [PATCH 4/4] TrkGaussianSumFilter: Memory improvement. When using DataVectorWithAlloc, call reserve on it before filling in order to minimize wasted memory. --- .../TrkFitter/TrkGaussianSumFilter/src/GaussianSumFitter.cxx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GaussianSumFitter.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GaussianSumFitter.cxx index 1980f9aa657..8d4124ba60a 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GaussianSumFitter.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GaussianSumFitter.cxx @@ -356,6 +356,7 @@ Trk::GaussianSumFitter::fit( // Store only TSOS in tracks instead of MCSOS if (!m_StoreMCSOS) { auto slimmedSmoothedTrajectory = Trk::TrackStateOnSurfaceProtContainer::make_unique(); + slimmedSmoothedTrajectory->reserve (smoothedTrajectory->size()); for (const Trk::TrackStateOnSurface* tsos : *smoothedTrajectory) { slimmedSmoothedTrajectory->push_back(slimmedSmoothedTrajectory->allocate(*tsos)); } @@ -494,6 +495,7 @@ Trk::GaussianSumFitter::fit( // Store only TSOS in tracks instead of MCSOS if (!m_StoreMCSOS) { auto slimmedSmoothedTrajectory = Trk::TrackStateOnSurfaceProtContainer::make_unique(); + slimmedSmoothedTrajectory->reserve (smoothedTrajectory->size()); for (const Trk::TrackStateOnSurface* tsos : *smoothedTrajectory) { slimmedSmoothedTrajectory->push_back(slimmedSmoothedTrajectory->allocate(*tsos)); } @@ -1034,6 +1036,7 @@ Trk::GaussianSumFitter::fit( * we opt for const ptr* */ auto smoothedTrajectory = SmoothedTrajectoryProt::make_unique(); + smoothedTrajectory->reserve (5 + forwardTrajectory.size()); auto smootherPredictionMultiState = std::make_unique(); -- GitLab