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

vmw_balloon: dynamically allocate the vmw-balloon shrinker

In preparation for implementing lockless slab shrink, use new APIs to
dynamically allocate the vmw-balloon shrinker, so that it can be freed
asynchronously via RCU. Then it doesn't need to wait for RCU read-side
critical section when releasing the struct vmballoon.

And we can simply exit vmballoon_init() when registering the shrinker
fails. So the shrinker_registered indication is redundant, just remove it.

Link: https://lkml.kernel.org/r/20230911094444.68966-28-zhengqi.arch@bytedance.com
Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
Reviewed-by: Muchun Song <songmuchun@bytedance.com>
Acked-by: Nadav Amit <namit@vmware.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Abhinav Kumar <quic_abhinavk@quicinc.com>
Cc: Alasdair Kergon <agk@redhat.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: Andreas Gruenbacher <agruenba@redhat.com>
Cc: Anna Schumaker <anna@kernel.org>
Cc: Bob Peterson <rpeterso@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Carlos Llamas <cmllamas@google.com>
Cc: Chandan Babu R <chandan.babu@oracle.com>
Cc: Chao Yu <chao@kernel.org>
Cc: Chris Mason <clm@fb.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Christian Koenig <christian.koenig@amd.com>
Cc: Chuck Lever <cel@kernel.org>
Cc: Coly Li <colyli@suse.de>
Cc: Dai Ngo <Dai.Ngo@oracle.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: "Darrick J. Wong" <djwong@kernel.org>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: David Airlie <airlied@gmail.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Sterba <dsterba@suse.com>
Cc: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Cc: Gao Xiang <hsiangkao@linux.alibaba.com>
Cc: Huang Rui <ray.huang@amd.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: Jeffle Xu <jefflexu@linux.alibaba.com>
Cc: Joel Fernandes (Google) <joel@joelfernandes.org>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Josef Bacik <josef@toxicpanda.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Kent Overstreet <kent.overstreet@gmail.com>
Cc: Kirill Tkhai <tkhai@ya.ru>
Cc: Marijn Suijten <marijn.suijten@somainline.org>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Mike Snitzer <snitzer@kernel.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Neil Brown <neilb@suse.de>
Cc: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Cc: Olga Kornievskaia <kolga@netapp.com>
Cc: Paul E. McKenney <paulmck@kernel.org>
Cc: Richard Weinberger <richard@nod.at>
Cc: Rob Clark <robdclark@gmail.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Sean Paul <sean@poorly.run>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Song Liu <song@kernel.org>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Steven Price <steven.price@arm.com>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Trond Myklebust <trond.myklebust@hammerspace.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Cc: Yue Hu <huyue2@coolpad.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Qi Zheng and committed by
Andrew Morton
17c4eb03 a6a1eb62

+12 -26
+12 -26
drivers/misc/vmw_balloon.c
··· 380 380 /** 381 381 * @shrinker: shrinker interface that is used to avoid over-inflation. 382 382 */ 383 - struct shrinker shrinker; 384 - 385 - /** 386 - * @shrinker_registered: whether the shrinker was registered. 387 - * 388 - * The shrinker interface does not handle gracefully the removal of 389 - * shrinker that was not registered before. This indication allows to 390 - * simplify the unregistration process. 391 - */ 392 - bool shrinker_registered; 383 + struct shrinker *shrinker; 393 384 }; 394 385 395 386 static struct vmballoon balloon; ··· 1559 1568 1560 1569 static void vmballoon_unregister_shrinker(struct vmballoon *b) 1561 1570 { 1562 - if (b->shrinker_registered) 1563 - unregister_shrinker(&b->shrinker); 1564 - b->shrinker_registered = false; 1571 + shrinker_free(b->shrinker); 1572 + b->shrinker = NULL; 1565 1573 } 1566 1574 1567 1575 static int vmballoon_register_shrinker(struct vmballoon *b) 1568 1576 { 1569 - int r; 1570 - 1571 1577 /* Do nothing if the shrinker is not enabled */ 1572 1578 if (!vmwballoon_shrinker_enable) 1573 1579 return 0; 1574 1580 1575 - b->shrinker.scan_objects = vmballoon_shrinker_scan; 1576 - b->shrinker.count_objects = vmballoon_shrinker_count; 1577 - b->shrinker.seeks = DEFAULT_SEEKS; 1581 + b->shrinker = shrinker_alloc(0, "vmw-balloon"); 1582 + if (!b->shrinker) 1583 + return -ENOMEM; 1578 1584 1579 - r = register_shrinker(&b->shrinker, "vmw-balloon"); 1585 + b->shrinker->scan_objects = vmballoon_shrinker_scan; 1586 + b->shrinker->count_objects = vmballoon_shrinker_count; 1587 + b->shrinker->private_data = b; 1580 1588 1581 - if (r == 0) 1582 - b->shrinker_registered = true; 1589 + shrinker_register(b->shrinker); 1583 1590 1584 - return r; 1591 + return 0; 1585 1592 } 1586 1593 1587 1594 /* ··· 1872 1883 1873 1884 error = vmballoon_register_shrinker(&balloon); 1874 1885 if (error) 1875 - goto fail; 1886 + return error; 1876 1887 1877 1888 /* 1878 1889 * Initialization of compaction must be done after the call to ··· 1894 1905 vmballoon_debugfs_init(&balloon); 1895 1906 1896 1907 return 0; 1897 - fail: 1898 - vmballoon_unregister_shrinker(&balloon); 1899 - return error; 1900 1908 } 1901 1909 1902 1910 /*