Skip to content

Commit 87654cf

Browse files
linke litehcaster
authored andcommitted
mm/slub: mark racy accesses on slab->slabs
The reads of slab->slabs are racy because it may be changed by put_cpu_partial concurrently. In slabs_cpu_partial_show() and show_slab_objects(), slab->slabs is only used for showing information. Data-racy reads from shared variables that are used only for diagnostic purposes should typically use data_race(), since it is normally not a problem if the values are off by a little. This patch is aimed at reducing the number of benign races reported by KCSAN in order to focus future debugging effort on harmful races. Signed-off-by: linke li <lilinke99@qq.com> Reviewed-by: Chengming Zhou <chengming.zhou@linux.dev> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
1 parent ad7c5eb commit 87654cf

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

mm/slub.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6036,7 +6036,7 @@ static ssize_t show_slab_objects(struct kmem_cache *s,
60366036
else if (flags & SO_OBJECTS)
60376037
WARN_ON_ONCE(1);
60386038
else
6039-
x = slab->slabs;
6039+
x = data_race(slab->slabs);
60406040
total += x;
60416041
nodes[node] += x;
60426042
}
@@ -6241,7 +6241,7 @@ static ssize_t slabs_cpu_partial_show(struct kmem_cache *s, char *buf)
62416241
slab = slub_percpu_partial(per_cpu_ptr(s->cpu_slab, cpu));
62426242

62436243
if (slab)
6244-
slabs += slab->slabs;
6244+
slabs += data_race(slab->slabs);
62456245
}
62466246
#endif
62476247

@@ -6255,7 +6255,7 @@ static ssize_t slabs_cpu_partial_show(struct kmem_cache *s, char *buf)
62556255

62566256
slab = slub_percpu_partial(per_cpu_ptr(s->cpu_slab, cpu));
62576257
if (slab) {
6258-
slabs = READ_ONCE(slab->slabs);
6258+
slabs = data_race(slab->slabs);
62596259
objects = (slabs * oo_objects(s->oo)) / 2;
62606260
len += sysfs_emit_at(buf, len, " C%d=%d(%d)",
62616261
cpu, objects, slabs);

0 commit comments

Comments
 (0)