Skip to content

Commit c3cc391

Browse files
hnaztorvalds
authored andcommitted
mm: memcontrol: fix NR_WRITEBACK leak in memcg and system stats
After commit a983b5e ("mm: memcontrol: fix excessive complexity in memory.stat reporting"), we observed slowly upward creeping NR_WRITEBACK counts over the course of several days, both the per-memcg stats as well as the system counter in e.g. /proc/meminfo. The conversion from full per-cpu stat counts to per-cpu cached atomic stat counts introduced an irq-unsafe RMW operation into the updates. Most stat updates come from process context, but one notable exception is the NR_WRITEBACK counter. While writebacks are issued from process context, they are retired from (soft)irq context. When writeback completions interrupt the RMW counter updates of new writebacks being issued, the decs from the completions are lost. Since the global updates are routed through the joint lruvec API, both the memcg counters as well as the system counters are affected. This patch makes the joint stat and event API irq safe. Link: http://lkml.kernel.org/r/[email protected] Fixes: a983b5e ("mm: memcontrol: fix excessive complexity in memory.stat reporting") Signed-off-by: Johannes Weiner <[email protected]> Debugged-by: Tejun Heo <[email protected]> Reviewed-by: Rik van Riel <[email protected]> Reviewed-by: Andrew Morton <[email protected]> Cc: Vladimir Davydov <[email protected]> Cc: Michal Hocko <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 101110f commit c3cc391

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

include/linux/memcontrol.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -523,9 +523,11 @@ static inline void __mod_memcg_state(struct mem_cgroup *memcg,
523523
static inline void mod_memcg_state(struct mem_cgroup *memcg,
524524
int idx, int val)
525525
{
526-
preempt_disable();
526+
unsigned long flags;
527+
528+
local_irq_save(flags);
527529
__mod_memcg_state(memcg, idx, val);
528-
preempt_enable();
530+
local_irq_restore(flags);
529531
}
530532

531533
/**
@@ -606,9 +608,11 @@ static inline void __mod_lruvec_state(struct lruvec *lruvec,
606608
static inline void mod_lruvec_state(struct lruvec *lruvec,
607609
enum node_stat_item idx, int val)
608610
{
609-
preempt_disable();
611+
unsigned long flags;
612+
613+
local_irq_save(flags);
610614
__mod_lruvec_state(lruvec, idx, val);
611-
preempt_enable();
615+
local_irq_restore(flags);
612616
}
613617

614618
static inline void __mod_lruvec_page_state(struct page *page,
@@ -630,9 +634,11 @@ static inline void __mod_lruvec_page_state(struct page *page,
630634
static inline void mod_lruvec_page_state(struct page *page,
631635
enum node_stat_item idx, int val)
632636
{
633-
preempt_disable();
637+
unsigned long flags;
638+
639+
local_irq_save(flags);
634640
__mod_lruvec_page_state(page, idx, val);
635-
preempt_enable();
641+
local_irq_restore(flags);
636642
}
637643

638644
unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order,
@@ -659,9 +665,11 @@ static inline void __count_memcg_events(struct mem_cgroup *memcg,
659665
static inline void count_memcg_events(struct mem_cgroup *memcg,
660666
int idx, unsigned long count)
661667
{
662-
preempt_disable();
668+
unsigned long flags;
669+
670+
local_irq_save(flags);
663671
__count_memcg_events(memcg, idx, count);
664-
preempt_enable();
672+
local_irq_restore(flags);
665673
}
666674

667675
/* idx can be of type enum memcg_event_item or vm_event_item */

0 commit comments

Comments
 (0)