Skip to content

Commit 3db5f1e

Browse files
committed
Update alignment requirement for PathBuildingHop with new map
1 parent 09a5cd3 commit 3db5f1e

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
@@ -1673,7 +1673,7 @@ fn iter_equal<I1: Iterator, I2: Iterator>(mut iter_a: I1, mut iter_b: I2)
16731673
/// Fee values should be updated only in the context of the whole path, see update_value_and_recompute_fees.
16741674
/// These fee values are useful to choose hops as we traverse the graph "payee-to-payer".
16751675
#[derive(Clone)]
1676-
#[repr(C)] // Force fields to appear in the order we define them.
1676+
#[repr(align(128))] // Force the struct to align to cache line pairs
16771677
struct PathBuildingHop<'a> {
16781678
candidate: CandidateRouteHop<'a>,
16791679
/// If we've already processed a node as the best node, we shouldn't process it again. Normally
@@ -1694,11 +1694,6 @@ struct PathBuildingHop<'a> {
16941694
/// channel scoring.
16951695
path_penalty_msat: u64,
16961696

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

17041699
/// All the fees paid *after* this channel on the way to the destination
@@ -1716,16 +1711,9 @@ struct PathBuildingHop<'a> {
17161711
}
17171712

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

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

0 commit comments

Comments
 (0)