@@ -5326,7 +5326,6 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
5326
5326
INIT_LIST_HEAD (& memcg -> deferred_split_queue .split_queue );
5327
5327
memcg -> deferred_split_queue .split_queue_len = 0 ;
5328
5328
#endif
5329
- idr_replace (& mem_cgroup_idr , memcg , memcg -> id .id );
5330
5329
lru_gen_init_memcg (memcg );
5331
5330
return memcg ;
5332
5331
fail :
@@ -5398,14 +5397,27 @@ static int mem_cgroup_css_online(struct cgroup_subsys_state *css)
5398
5397
if (alloc_shrinker_info (memcg ))
5399
5398
goto offline_kmem ;
5400
5399
5401
- /* Online state pins memcg ID, memcg ID pins CSS */
5402
- refcount_set (& memcg -> id .ref , 1 );
5403
- css_get (css );
5404
-
5405
5400
if (unlikely (mem_cgroup_is_root (memcg )))
5406
5401
queue_delayed_work (system_unbound_wq , & stats_flush_dwork ,
5407
5402
FLUSH_TIME );
5408
5403
lru_gen_online_memcg (memcg );
5404
+
5405
+ /* Online state pins memcg ID, memcg ID pins CSS */
5406
+ refcount_set (& memcg -> id .ref , 1 );
5407
+ css_get (css );
5408
+
5409
+ /*
5410
+ * Ensure mem_cgroup_from_id() works once we're fully online.
5411
+ *
5412
+ * We could do this earlier and require callers to filter with
5413
+ * css_tryget_online(). But right now there are no users that
5414
+ * need earlier access, and the workingset code relies on the
5415
+ * cgroup tree linkage (mem_cgroup_get_nr_swap_pages()). So
5416
+ * publish it here at the end of onlining. This matches the
5417
+ * regular ID destruction during offlining.
5418
+ */
5419
+ idr_replace (& mem_cgroup_idr , memcg , memcg -> id .id );
5420
+
5409
5421
return 0 ;
5410
5422
offline_kmem :
5411
5423
memcg_offline_kmem (memcg );
0 commit comments