Skip to content

Commit 0af5928

Browse files
Sebastian Andrzej SiewiorPaolo Abeni
authored andcommitted
rds: Acquire per-CPU pointer within BH disabled section
rds_page_remainder_alloc() obtains the current CPU with get_cpu() while disabling preemption. Then the CPU number is used to access the per-CPU data structure via per_cpu(). This can be optimized by relying on local_bh_disable() to provide a stable CPU number/ avoid migration and then using this_cpu_ptr() to retrieve the data structure. Cc: Allison Henderson <[email protected]> Cc: [email protected] Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent aaaaa66 commit 0af5928

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

net/rds/page.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ int rds_page_remainder_alloc(struct scatterlist *scat, unsigned long bytes,
8686
goto out;
8787
}
8888

89-
rem = &per_cpu(rds_page_remainders, get_cpu());
9089
local_bh_disable();
90+
rem = this_cpu_ptr(&rds_page_remainders);
9191

9292
while (1) {
9393
/* avoid a tiny region getting stuck by tossing it */
@@ -116,12 +116,11 @@ int rds_page_remainder_alloc(struct scatterlist *scat, unsigned long bytes,
116116

117117
/* alloc if there is nothing for us to use */
118118
local_bh_enable();
119-
put_cpu();
120119

121120
page = alloc_page(gfp);
122121

123-
rem = &per_cpu(rds_page_remainders, get_cpu());
124122
local_bh_disable();
123+
rem = this_cpu_ptr(&rds_page_remainders);
125124

126125
if (!page) {
127126
ret = -ENOMEM;
@@ -140,7 +139,6 @@ int rds_page_remainder_alloc(struct scatterlist *scat, unsigned long bytes,
140139
}
141140

142141
local_bh_enable();
143-
put_cpu();
144142
out:
145143
rdsdebug("bytes %lu ret %d %p %u %u\n", bytes, ret,
146144
ret ? NULL : sg_page(scat), ret ? 0 : scat->offset,

0 commit comments

Comments
 (0)