mm/vmpressure: skip socket pressure for costly order reclaim
Subsystems (6)
PATCH v2 1/1 mm/vmpressure: skip socket pressure for costly order reclaim
When kswapd reclaims at high order due to fragmentation, vmpressure() can report poor reclaim efficiency even though the system has plenty of free memory. This is because kswapd scans many pages but finds little to reclaim
- the pages are actively in use and don't need to be freed. The resulting scan:reclaim ratio triggers socket pressure, throttling TCP throughput unnecessarily.
Net allocations do not exceed order 3 (PAGE_ALLOC_COSTLY_ORDER), so high order reclaim difficulty should not trigger socket pressure. The kernel already treats this order as the boundary where reclaim is no longer expected to succeed and compaction may take over.
Make vmpressure() order-aware through an additional parameter sourced from scan_control at existing call sites. Socket pressure is now only asserted when order <= PAGE_ALLOC_COSTLY_ORDER.
Memcg reclaim is unaffected since try_to_free_mem_cgroup_pages() always uses order 0, which passes the filter unconditionally. Similarly, vmpressure_prio() now passes order 0 internally when calling vmpressure(), ensuring critical pressure from low reclaim priority is not suppressed by the order filter.
---
v2
- dropped extern specifier from vmpressure decl
- added comment to explain rationale of adjusted conditional
v1: https://lore.kernel.org/all/[email protected]/
include/linux/vmpressure.h | 9 +++++---- mm/vmpressure.c | 15 ++++++++++++--- mm/vmscan.c | 8 ++++---- 3 files changed, 21 insertions(+), 11 deletions(-)
include/linux/vmpressure.h +5 -4
@@ -30,8 +30,8 @@ struct vmpressure {struct mem_cgroup ;#ifdef CONFIG_MEMCG -extern void vmpressure (gfp_t gfp,struct mem_cgroup *memcg,bool tree, -unsigned long scanned,unsigned long reclaimed); +void vmpressure (gfp_t gfp,int order,struct mem_cgroup *memcg,bool tree, +unsigned long scanned,unsigned long reclaimed);extern void vmpressure_prio (gfp_t gfp,struct mem_cgroup *memcg,int prio);extern void vmpressure_init (struct vmpressure *vmpr);
@@ -44,8 +44,9 @@ extern int vmpressure_register_event(struct mem_cgroup *memcg,extern void vmpressure_unregister_event (struct mem_cgroup *memcg,struct eventfd_ctx *eventfd);#else -static inline void vmpressure (gfp_t gfp,struct mem_cgroup *memcg,bool tree, -unsigned long scanned,unsigned long reclaimed) {} +static inline void vmpressure (gfp_t gfp,int order,struct mem_cgroup *memcg, +bool tree,unsigned long scanned, +unsigned long reclaimed) {}static inline void vmpressure_prio (gfp_t gfp,struct mem_cgroup *memcg,int prio) {}#endif /* CONFIG_MEMCG */
mm/vmpressure.c +12 -3
@@ -218,6 +218,7 @@ static void vmpressure_work_fn(struct work_struct *work)/** * vmpressure() - Account memory pressure through scanned/reclaimed ratio * @gfp: reclaimer's gfp mask +* @order: allocation order being reclaimed for * @memcg: cgroup memory controller handle * @tree: legacy subtree mode * @scanned: number of pages scanned
@@ -236,7 +237,7 @@ static void vmpressure_work_fn(struct work_struct *work)* * This function does not return any value. */ -void vmpressure (gfp_t gfp,struct mem_cgroup *memcg,bool tree, +void vmpressure (gfp_t gfp,int order,struct mem_cgroup *memcg,bool tree,unsigned long scanned,unsigned long reclaimed) {struct vmpressure *vmpr;
@@ -307,7 +308,15 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree, level =vmpressure_calc_level (scanned, reclaimed); -if (level >VMPRESSURE_LOW ) { +/* +* Once we go above COSTLY_ORDER, reclaim relies heavily on +* compaction to make progress. Reclaim efficiency was never a +* great proxy for pressure to begin with, but it's outright +* misleading with these high orders. Don't throttle sockets +* because somebody is attempting something crazy like an order-7 +* and predictably struggling. +*/ +if (level >VMPRESSURE_LOW && order <=PAGE_ALLOC_COSTLY_ORDER ) {/* * Let the socket buffer allocator know that * we are having trouble reclaiming LRU pages.
@@ -348,7 +357,7 @@ void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio)* to the vmpressure() basically means that we signal 'critical' * level. */ -vmpressure (gfp, memcg, true, vmpressure_win,0 ); +vmpressure (gfp,0 , memcg, true, vmpressure_win,0 ); }#define MAX_VMPRESSURE_ARGS_LEN (strlen("critical") + strlen("hierarchy") + 2)
mm/vmscan.c +4 -4
@@ -5071,8 +5071,8 @@ static int shrink_one(struct lruvec *lruvec, struct scan_control *sc)shrink_slab (sc->gfp_mask, pgdat->node_id, memcg, sc->priority);if (!sc->proactive) -vmpressure (sc->gfp_mask, memcg, false, sc->nr_scanned - scanned, - sc->nr_reclaimed - reclaimed); +vmpressure (sc->gfp_mask, sc->order, memcg, false, + sc->nr_scanned - scanned, sc->nr_reclaimed - reclaimed);flush_reclaim_state (sc);
@@ -6175,7 +6175,7 @@ static void shrink_node_memcgs(pg_data_t *pgdat, struct scan_control *sc)/* Record the group's reclaim efficiency */ if (!sc->proactive) -vmpressure (sc->gfp_mask, memcg, false, +vmpressure (sc->gfp_mask, sc->order, memcg, false, sc->nr_scanned - scanned, sc->nr_reclaimed - reclaimed);
@@ -6220,7 +6220,7 @@ static void shrink_node(pg_data_t *pgdat, struct scan_control *sc)/* Record the subtree's reclaim efficiency */ if (!sc->proactive) -vmpressure (sc->gfp_mask, sc->target_mem_cgroup, true, +vmpressure (sc->gfp_mask, sc->order, sc->target_mem_cgroup, true, sc->nr_scanned - nr_scanned, nr_node_reclaimed);if (nr_node_reclaimed)
Signature · 1 line
2.52.0
Quoted 16 lines · JP Kobryn (Meta)
When kswapd reclaims at high order due to fragmentation,
vmpressure()can report poor reclaim efficiency even though the system has plenty of free memory. This is because kswapd scans many pages but finds little to reclaim
- the pages are actively in use and don't need to be freed. The resulting scan:reclaim ratio triggers socket pressure, throttling TCP throughput unnecessarily.Net allocations do not exceed order 3 (
PAGE_ALLOC_COSTLY_ORDER), so high order reclaim difficulty should not trigger socket pressure. The kernel already treats this order as the boundary where reclaim is no longer expected to succeed and compaction may take over.Make
vmpressure()order-aware through an additional parameter sourced fromscan_controlat existing call sites. Socket pressure is now only asserted when order <=PAGE_ALLOC_COSTLY_ORDER.
Quoted 7 lines
Memcg reclaim is unaffected since
try_to_free_mem_cgroup_pages()always uses order 0, which passes the filter unconditionally. Similarly,vmpressure_prio()now passes order 0 internally when callingvmpressure(), ensuring critical pressure from low reclaim priority is not suppressed by the order filter.Signed-off-by JP Kobryn (Meta) <[email protected]>
Quoted 1 line · JP Kobryn (Meta)
When kswapd reclaims at high order due to fragmentation,
* kswapd is woken up for the higher order reclaim request
But this can be direct reclaim as well.
Quoted 8 lines
vmpressure()can
report poor reclaim efficiency even though the system has plenty of free memory. This is because kswapd scans many pages but finds little to reclaim
- the pages are actively in use and don't need to be freed. The resulting scan:reclaim ratio triggers socket pressure, throttling TCP throughput unnecessarily.Net allocations do not exceed order 3 (
PAGE_ALLOC_COSTLY_ORDER),
Net not doing costly order allocations is irrelevant here. IIUC you want all costly order allocations (like THPs) to not raise vmpressure as those don't necessarily represents the memory pressure.
Quoted 9 lines
so high
order reclaim difficulty should not trigger socket pressure. The kernel already treats this order as the boundary where reclaim is no longer expected to succeed and compaction may take over.Make
vmpressure()order-aware through an additional parameter sourced fromscan_controlat existing call sites. Socket pressure is now only asserted when order <=PAGE_ALLOC_COSTLY_ORDER.
Quoted 7 lines
Memcg reclaim is unaffected since
try_to_free_mem_cgroup_pages()always uses order 0, which passes the filter unconditionally. Similarly,vmpressure_prio()now passes order 0 internally when callingvmpressure(), ensuring critical pressure from low reclaim priority is not suppressed by the order filter.Signed-off-by JP Kobryn (Meta) <[email protected]>
The patch looks good. I think we can ask Andrew to just adjust the commit message and then you don't need to resend.
Moving networking stack away from vmpressure in my plan for a long time and this tells me I should get to it sooner.
Rik van Riel
Reviewed-byQuoted 7 lines · Shakeel Butt
Net not doing costly order allocations is irrelevant here. IIUC you want all
costly order allocations (like THPs) to not raise vmpressure as those don't
necessarily represents the memory pressure.
It sure will be nice to not have THP enabled=always, defrag=defer result in smaller network buffers, and reduced network performance!
Signature · 1 line
All Rights Reversed.
Quoted 6 lines · Shakeel Butt
Quoted 1 line · JP Kobryn (Meta)
When kswapd reclaims at high order due to fragmentation,
* kswapd is woken up for the higher order reclaim request
But this can be direct reclaim as well.
Good call.
Quoted 8 lines
Quoted 8 lines
vmpressure()can
report poor reclaim efficiency even though the system has plenty of free memory. This is because kswapd scans many pages but finds little to reclaim
- the pages are actively in use and don't need to be freed. The resulting scan:reclaim ratio triggers socket pressure, throttling TCP throughput unnecessarily.
Quoted 5 lines
Quoted 1 line
Net allocations do not exceed order 3 (
PAGE_ALLOC_COSTLY_ORDER),Net not doing costly order allocations is irrelevant here. IIUC you want all costly order allocations (like THPs) to not raise vmpressure as those don't necessarily represents the memory pressure.
The supporting context I included was based on the investigation that led to the patch. But as you and Rik both noted, the patch has greater implications.
Quoted 16 lines
Quoted 16 lines
so high
order reclaim difficulty should not trigger socket pressure. The kernel already treats this order as the boundary where reclaim is no longer expected to succeed and compaction may take over.Make
vmpressure()order-aware through an additional parameter sourced fromscan_controlat existing call sites. Socket pressure is now only asserted when order <=PAGE_ALLOC_COSTLY_ORDER.Memcg reclaim is unaffected since
try_to_free_mem_cgroup_pages()always uses order 0, which passes the filter unconditionally. Similarly,vmpressure_prio()now passes order 0 internally when callingvmpressure(), ensuring critical pressure from low reclaim priority is not suppressed by the order filter.
Quoted 4 lines
Quoted 1 line
Signed-off-by JP Kobryn (Meta) <[email protected]>The patch looks good. I think we can ask Andrew to just adjust the commit message and then you don't need to resend.
It's no problem for me. I'll send a v3 with an updated commit message.
Quoted 6 lines · On Thu, 2 Apr 2026 16:25:11 -0700 JP Kobryn (Meta) wrote:
When kswapd reclaims at high order due to fragmentation,
vmpressure()can report poor reclaim efficiency even though the system has plenty of free memory. This is because kswapd scans many pages but finds little to reclaim
- the pages are actively in use and don't need to be freed. The resulting scan:reclaim ratio triggers socket pressure, throttling TCP throughput unnecessarily.
FWIW