Skip to content

Commit 7bbac2e

Browse files
committed
Update alignment requirement for PathBuildingHop with new map
1 parent cee3762 commit 7bbac2e

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

lightning/src/routing/router.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,7 @@ fn iter_equal<I1: Iterator, I2: Iterator>(mut iter_a: I1, mut iter_b: I2)
16631663
/// Fee values should be updated only in the context of the whole path, see update_value_and_recompute_fees.
16641664
/// These fee values are useful to choose hops as we traverse the graph "payee-to-payer".
16651665
#[derive(Clone)]
1666-
#[repr(C)] // Force fields to appear in the order we define them.
1666+
#[repr(align(128))] // Force the struct to align to cache line pairs
16671667
struct PathBuildingHop<'a> {
16681668
candidate: CandidateRouteHop<'a>,
16691669
/// If we've already processed a node as the best node, we shouldn't process it again. Normally
@@ -1684,11 +1684,6 @@ struct PathBuildingHop<'a> {
16841684
/// channel scoring.
16851685
path_penalty_msat: u64,
16861686

1687-
// The last 16 bytes are on the next cache line by default in glibc's malloc. Thus, we should
1688-
// only place fields which are not hot there. Luckily, the next three fields are only read if
1689-
// we end up on the selected path, and only in the final path layout phase, so we don't care
1690-
// too much if reading them is slow.
1691-
16921687
fee_msat: u64,
16931688

16941689
/// All the fees paid *after* this channel on the way to the destination
@@ -1706,16 +1701,9 @@ struct PathBuildingHop<'a> {
17061701
}
17071702

17081703
// Checks that the entries in the `find_route` `dist` map fit in (exactly) two standard x86-64
1709-
// cache lines. Sadly, they're not guaranteed to actually lie on a cache line (and in fact,
1710-
// generally won't, because at least glibc's malloc will align to a nice, big, round
1711-
// boundary...plus 16), but at least it will reduce the amount of data we'll need to load.
1712-
//
1713-
// Note that these assertions only pass on somewhat recent rustc, and thus are gated on the
1714-
// ldk_bench flag.
1715-
#[cfg(ldk_bench)]
1716-
const _NODE_MAP_SIZE_TWO_CACHE_LINES: usize = 128 - core::mem::size_of::<(NodeId, PathBuildingHop)>();
1717-
#[cfg(ldk_bench)]
1718-
const _NODE_MAP_SIZE_EXACTLY_CACHE_LINES: usize = core::mem::size_of::<(NodeId, PathBuildingHop)>() - 128;
1704+
// cache lines.
1705+
const _NODE_MAP_SIZE_TWO_CACHE_LINES: usize = 128 - core::mem::size_of::<Option<PathBuildingHop>>();
1706+
const _NODE_MAP_SIZE_EXACTLY_CACHE_LINES: usize = core::mem::size_of::<Option<PathBuildingHop>>() - 128;
17191707

17201708
impl<'a> core::fmt::Debug for PathBuildingHop<'a> {
17211709
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {

0 commit comments

Comments
 (0)