Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

memcg-v1: no need for memcg locking for dirty tracking

During the era of memcg charge migration, the kernel has to be make
sure that the dirty stat updates do not race with the charge migration.
Otherwise it might update the dirty stats of the wrong memcg. Now
with the memcg charge migration gone, there is no more race for dirty
stat updates and the previous locking can be removed.

Link: https://lkml.kernel.org/r/20241025012304.2473312-4-shakeel.butt@linux.dev
Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Acked-by: Michal Hocko <mhocko@suse.com>
Reviewed-by: Roman Gushchin <roman.gushchin@linux.dev>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Hugh Dickins <hughd@google.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Yosry Ahmed <yosryahmed@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Shakeel Butt and committed by
Andrew Morton
a8cd9d4c 6b611388

+3 -18
-5
fs/buffer.c
··· 736 736 * Lock out page's memcg migration to keep PageDirty 737 737 * synchronized with per-memcg dirty page counters. 738 738 */ 739 - folio_memcg_lock(folio); 740 739 newly_dirty = !folio_test_set_dirty(folio); 741 740 spin_unlock(&mapping->i_private_lock); 742 741 743 742 if (newly_dirty) 744 743 __folio_mark_dirty(folio, mapping, 1); 745 - 746 - folio_memcg_unlock(folio); 747 744 748 745 if (newly_dirty) 749 746 __mark_inode_dirty(mapping->host, I_DIRTY_PAGES); ··· 1191 1194 struct folio *folio = bh->b_folio; 1192 1195 struct address_space *mapping = NULL; 1193 1196 1194 - folio_memcg_lock(folio); 1195 1197 if (!folio_test_set_dirty(folio)) { 1196 1198 mapping = folio->mapping; 1197 1199 if (mapping) 1198 1200 __folio_mark_dirty(folio, mapping, 0); 1199 1201 } 1200 - folio_memcg_unlock(folio); 1201 1202 if (mapping) 1202 1203 __mark_inode_dirty(mapping->host, I_DIRTY_PAGES); 1203 1204 }
+3 -13
mm/page-writeback.c
··· 2743 2743 /* 2744 2744 * Helper function for set_page_dirty family. 2745 2745 * 2746 - * Caller must hold folio_memcg_lock(). 2747 - * 2748 2746 * NOTE: This relies on being atomic wrt interrupts. 2749 2747 */ 2750 2748 static void folio_account_dirtied(struct folio *folio, ··· 2775 2777 /* 2776 2778 * Helper function for deaccounting dirty page without writeback. 2777 2779 * 2778 - * Caller must hold folio_memcg_lock(). 2779 2780 */ 2780 2781 void folio_account_cleaned(struct folio *folio, struct bdi_writeback *wb) 2781 2782 { ··· 2792 2795 * If warn is true, then emit a warning if the folio is not uptodate and has 2793 2796 * not been truncated. 2794 2797 * 2795 - * The caller must hold folio_memcg_lock(). It is the caller's 2796 - * responsibility to prevent the folio from being truncated while 2797 - * this function is in progress, although it may have been truncated 2798 + * It is the caller's responsibility to prevent the folio from being truncated 2799 + * while this function is in progress, although it may have been truncated 2798 2800 * before this function is called. Most callers have the folio locked. 2799 2801 * A few have the folio blocked from truncation through other means (e.g. 2800 2802 * zap_vma_pages() has it mapped and is holding the page table lock). ··· 2837 2841 */ 2838 2842 bool filemap_dirty_folio(struct address_space *mapping, struct folio *folio) 2839 2843 { 2840 - folio_memcg_lock(folio); 2841 - if (folio_test_set_dirty(folio)) { 2842 - folio_memcg_unlock(folio); 2844 + if (folio_test_set_dirty(folio)) 2843 2845 return false; 2844 - } 2845 2846 2846 2847 __folio_mark_dirty(folio, mapping, !folio_test_private(folio)); 2847 - folio_memcg_unlock(folio); 2848 2848 2849 2849 if (mapping->host) { 2850 2850 /* !PageAnon && !swapper_space */ ··· 2967 2975 struct bdi_writeback *wb; 2968 2976 struct wb_lock_cookie cookie = {}; 2969 2977 2970 - folio_memcg_lock(folio); 2971 2978 wb = unlocked_inode_to_wb_begin(inode, &cookie); 2972 2979 2973 2980 if (folio_test_clear_dirty(folio)) 2974 2981 folio_account_cleaned(folio, wb); 2975 2982 2976 2983 unlocked_inode_to_wb_end(inode, &cookie); 2977 - folio_memcg_unlock(folio); 2978 2984 } else { 2979 2985 folio_clear_dirty(folio); 2980 2986 }