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: remove memcg move locking code

The memcg v1's charge move feature has been deprecated. All the places
using the memcg move lock, have stopped using it as they don't need the
protection any more. Let's proceed to remove all the locking code related
to charge moving.

Link: https://lkml.kernel.org/r/20241025012304.2473312-7-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
a29c0e4b cf4a6553

-143
-54
include/linux/memcontrol.h
··· 299 299 /* For oom notifier event fd */ 300 300 struct list_head oom_notify; 301 301 302 - /* taken only while moving_account > 0 */ 303 - spinlock_t move_lock; 304 - unsigned long move_lock_flags; 305 - 306 302 /* Legacy tcp memory accounting */ 307 303 bool tcpmem_active; 308 304 int tcpmem_pressure; 309 - 310 - /* 311 - * set > 0 if pages under this cgroup are moving to other cgroup. 312 - */ 313 - atomic_t moving_account; 314 - struct task_struct *move_lock_task; 315 305 316 306 /* List of events which userspace want to receive */ 317 307 struct list_head event_list; ··· 418 428 * 419 429 * - the folio lock 420 430 * - LRU isolation 421 - * - folio_memcg_lock() 422 431 * - exclusive reference 423 - * - mem_cgroup_trylock_pages() 424 432 * 425 433 * For a kmem folio a caller should hold an rcu read lock to protect memcg 426 434 * associated with a kmem folio from being released. ··· 487 499 * 488 500 * - the folio lock 489 501 * - LRU isolation 490 - * - lock_folio_memcg() 491 502 * - exclusive reference 492 - * - mem_cgroup_trylock_pages() 493 503 * 494 504 * For a kmem folio a caller should hold an rcu read lock to protect memcg 495 505 * associated with a kmem folio from being released. ··· 1853 1867 return p->memcg_in_oom; 1854 1868 } 1855 1869 1856 - void folio_memcg_lock(struct folio *folio); 1857 - void folio_memcg_unlock(struct folio *folio); 1858 - 1859 - /* try to stablize folio_memcg() for all the pages in a memcg */ 1860 - static inline bool mem_cgroup_trylock_pages(struct mem_cgroup *memcg) 1861 - { 1862 - rcu_read_lock(); 1863 - 1864 - if (mem_cgroup_disabled() || !atomic_read(&memcg->moving_account)) 1865 - return true; 1866 - 1867 - rcu_read_unlock(); 1868 - return false; 1869 - } 1870 - 1871 - static inline void mem_cgroup_unlock_pages(void) 1872 - { 1873 - rcu_read_unlock(); 1874 - } 1875 - 1876 1870 static inline void mem_cgroup_enter_user_fault(void) 1877 1871 { 1878 1872 WARN_ON(current->in_user_fault); ··· 1872 1906 unsigned long *total_scanned) 1873 1907 { 1874 1908 return 0; 1875 - } 1876 - 1877 - static inline void folio_memcg_lock(struct folio *folio) 1878 - { 1879 - } 1880 - 1881 - static inline void folio_memcg_unlock(struct folio *folio) 1882 - { 1883 - } 1884 - 1885 - static inline bool mem_cgroup_trylock_pages(struct mem_cgroup *memcg) 1886 - { 1887 - /* to match folio_memcg_rcu() */ 1888 - rcu_read_lock(); 1889 - return true; 1890 - } 1891 - 1892 - static inline void mem_cgroup_unlock_pages(void) 1893 - { 1894 - rcu_read_unlock(); 1895 1909 } 1896 1910 1897 1911 static inline bool task_in_memcg_oom(struct task_struct *p)
-1
mm/filemap.c
··· 119 119 * ->i_pages lock (folio_remove_rmap_pte->set_page_dirty) 120 120 * bdi.wb->list_lock (folio_remove_rmap_pte->set_page_dirty) 121 121 * ->inode->i_lock (folio_remove_rmap_pte->set_page_dirty) 122 - * ->memcg->move_lock (folio_remove_rmap_pte->folio_memcg_lock) 123 122 * bdi.wb->list_lock (zap_pte_range->set_page_dirty) 124 123 * ->inode->i_lock (zap_pte_range->set_page_dirty) 125 124 * ->private_lock (zap_pte_range->block_dirty_folio)
-82
mm/memcontrol-v1.c
··· 401 401 return nr_reclaimed; 402 402 } 403 403 404 - /** 405 - * folio_memcg_lock - Bind a folio to its memcg. 406 - * @folio: The folio. 407 - * 408 - * This function prevents unlocked LRU folios from being moved to 409 - * another cgroup. 410 - * 411 - * It ensures lifetime of the bound memcg. The caller is responsible 412 - * for the lifetime of the folio. 413 - */ 414 - void folio_memcg_lock(struct folio *folio) 415 - { 416 - struct mem_cgroup *memcg; 417 - unsigned long flags; 418 - 419 - /* 420 - * The RCU lock is held throughout the transaction. The fast 421 - * path can get away without acquiring the memcg->move_lock 422 - * because page moving starts with an RCU grace period. 423 - */ 424 - rcu_read_lock(); 425 - 426 - if (mem_cgroup_disabled()) 427 - return; 428 - again: 429 - memcg = folio_memcg(folio); 430 - if (unlikely(!memcg)) 431 - return; 432 - 433 - #ifdef CONFIG_PROVE_LOCKING 434 - local_irq_save(flags); 435 - might_lock(&memcg->move_lock); 436 - local_irq_restore(flags); 437 - #endif 438 - 439 - if (atomic_read(&memcg->moving_account) <= 0) 440 - return; 441 - 442 - spin_lock_irqsave(&memcg->move_lock, flags); 443 - if (memcg != folio_memcg(folio)) { 444 - spin_unlock_irqrestore(&memcg->move_lock, flags); 445 - goto again; 446 - } 447 - 448 - /* 449 - * When charge migration first begins, we can have multiple 450 - * critical sections holding the fast-path RCU lock and one 451 - * holding the slowpath move_lock. Track the task who has the 452 - * move_lock for folio_memcg_unlock(). 453 - */ 454 - memcg->move_lock_task = current; 455 - memcg->move_lock_flags = flags; 456 - } 457 - 458 - static void __folio_memcg_unlock(struct mem_cgroup *memcg) 459 - { 460 - if (memcg && memcg->move_lock_task == current) { 461 - unsigned long flags = memcg->move_lock_flags; 462 - 463 - memcg->move_lock_task = NULL; 464 - memcg->move_lock_flags = 0; 465 - 466 - spin_unlock_irqrestore(&memcg->move_lock, flags); 467 - } 468 - 469 - rcu_read_unlock(); 470 - } 471 - 472 - /** 473 - * folio_memcg_unlock - Release the binding between a folio and its memcg. 474 - * @folio: The folio. 475 - * 476 - * This releases the binding created by folio_memcg_lock(). This does 477 - * not change the accounting of this folio to its memcg, but it does 478 - * permit others to change it. 479 - */ 480 - void folio_memcg_unlock(struct folio *folio) 481 - { 482 - __folio_memcg_unlock(folio_memcg(folio)); 483 - } 484 - 485 404 static u64 mem_cgroup_move_charge_read(struct cgroup_subsys_state *css, 486 405 struct cftype *cft) 487 406 { ··· 1108 1189 { 1109 1190 INIT_LIST_HEAD(&memcg->oom_notify); 1110 1191 mutex_init(&memcg->thresholds_lock); 1111 - spin_lock_init(&memcg->move_lock); 1112 1192 INIT_LIST_HEAD(&memcg->event_list); 1113 1193 spin_lock_init(&memcg->event_list_lock); 1114 1194 }
-5
mm/memcontrol.c
··· 1189 1189 * These functions are safe to use under any of the following conditions: 1190 1190 * - folio locked 1191 1191 * - folio_test_lru false 1192 - * - folio_memcg_lock() 1193 1192 * - folio frozen (refcount of 0) 1194 1193 * 1195 1194 * Return: The lruvec this folio is on with its lock held. ··· 1210 1211 * These functions are safe to use under any of the following conditions: 1211 1212 * - folio locked 1212 1213 * - folio_test_lru false 1213 - * - folio_memcg_lock() 1214 1214 * - folio frozen (refcount of 0) 1215 1215 * 1216 1216 * Return: The lruvec this folio is on with its lock held and interrupts ··· 1233 1235 * These functions are safe to use under any of the following conditions: 1234 1236 * - folio locked 1235 1237 * - folio_test_lru false 1236 - * - folio_memcg_lock() 1237 1238 * - folio frozen (refcount of 0) 1238 1239 * 1239 1240 * Return: The lruvec this folio is on with its lock held and interrupts ··· 2372 2375 * 2373 2376 * - the page lock 2374 2377 * - LRU isolation 2375 - * - folio_memcg_lock() 2376 2378 * - exclusive reference 2377 - * - mem_cgroup_trylock_pages() 2378 2379 */ 2379 2380 folio->memcg_data = (unsigned long)memcg; 2380 2381 }
-1
mm/rmap.c
··· 32 32 * swap_lock (in swap_duplicate, swap_info_get) 33 33 * mmlist_lock (in mmput, drain_mmlist and others) 34 34 * mapping->private_lock (in block_dirty_folio) 35 - * folio_lock_memcg move_lock (in block_dirty_folio) 36 35 * i_pages lock (widely used) 37 36 * lruvec->lru_lock (in folio_lruvec_lock_irq) 38 37 * inode->i_lock (in set_page_dirty's __mark_inode_dirty)