History

mm: memcg: normalize the value passed into memcg_rstat_updated()

memcg_rstat_updated() uses the value of the state update to keep track of the magnitude of pending updates, so that we only do a stats flush when it's worth the work. Most values passed into memcg_rstat_updated() are in pages, however, a few of them are actually in bytes or KBs. To put this into perspective, a 512 byte slab allocation today would look the same as allocating 512 pages. This may result in premature flushes, which means unnecessary work and latency. Normalize all the state values passed into memcg_rstat_updated() to pages. Round up non-zero sub-page to 1 page, because memcg_rstat_updated() ignores 0 page updates.

Yosry Ahmed committed 3 years ago

Commit 7bd5bc31 parent ff841a01 file · +18 −2Browse files

Unified · Split

mm/memcontrol.c+18−2
@@ -763,6 +763,22 @@ unsigned long memcg_page_state(struct mem_cgroup *memcg, int idx) · 762 unmodified lines
763763 return x;
764764 }
765765
766+static int memcg_page_state_unit(int item);
767+
768+/*
769+ * Normalize the value passed into memcg_rstat_updated() to be in pages. Round
770+ * up non-zero sub-page updates to 1 page as zero page updates are ignored.
771+ */
772+static int memcg_state_val_in_pages(int idx, int val)
773+{
774+ int unit = memcg_page_state_unit(idx);
775+
776+ if (!val || unit == PAGE_SIZE)
777+ return val;
778+ else
779+ return max(val * unit / PAGE_SIZE, 1UL);
780+}
781+
766782 /**
767783 * __mod_memcg_state - update cgroup memory statistics
768784 * @memcg: the memory cgroup
@@ -775,7 +791,7 @@ void __mod_memcg_state(struct mem_cgroup *memcg, int idx, int val) · 6 unmodified lines
775791 return;
776792
777793 __this_cpu_add(memcg->vmstats_percpu->state[idx], val);
778− memcg_rstat_updated(memcg, val);
794+ memcg_rstat_updated(memcg, memcg_state_val_in_pages(idx, val));
779795 }
780796
781797 /* idx can be of type enum memcg_stat_item or node_stat_item. */
@@ -826,7 +842,7 @@ void __mod_memcg_lruvec_state(struct lruvec *lruvec, enum node_stat_item idx, · 44 unmodified lines
826842 /* Update lruvec */
827843 __this_cpu_add(pn->lruvec_stats_percpu->state[idx], val);
828844
829− memcg_rstat_updated(memcg, val);
845+ memcg_rstat_updated(memcg, memcg_state_val_in_pages(idx, val));
830846 memcg_stats_unlock();
831847 }
832848

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t