diff mbox series

khugepaged: Raplace barrier() with READ_ONCE() for a selective variable

Message ID 20210323092730.247583-1-yanfei.xu@windriver.com (mailing list archive)
State New, archived
Headers show
Series khugepaged: Raplace barrier() with READ_ONCE() for a selective variable | expand

Commit Message

Xu, Yanfei March 23, 2021, 9:27 a.m. UTC
From: Yanfei Xu <yanfei.xu@windriver.com>

READ_ONCE() is more selective and lightweight. It is more appropriate that
using a READ_ONCE() for the certain variable to prevent the compiler from
reordering.

Signed-off-by: Yanfei Xu <yanfei.xu@windriver.com>
---
 mm/khugepaged.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

Kirill A. Shutemov March 23, 2021, 10:21 a.m. UTC | #1
On Tue, Mar 23, 2021 at 05:27:30PM +0800, yanfei.xu@windriver.com wrote:
> From: Yanfei Xu <yanfei.xu@windriver.com>
> 
> READ_ONCE() is more selective and lightweight. It is more appropriate that
> using a READ_ONCE() for the certain variable to prevent the compiler from
> reordering.
> 
> Signed-off-by: Yanfei Xu <yanfei.xu@windriver.com>

Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
diff mbox series

Patch

diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index b81521dfbb1a..034d05a26cb0 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -2202,11 +2202,9 @@  static void khugepaged_do_scan(void)
 {
 	struct page *hpage = NULL;
 	unsigned int progress = 0, pass_through_head = 0;
-	unsigned int pages = khugepaged_pages_to_scan;
+	unsigned int pages = READ_ONCE(khugepaged_pages_to_scan);
 	bool wait = true;
 
-	barrier(); /* write khugepaged_pages_to_scan to local stack */
-
 	lru_add_drain_all();
 
 	while (progress < pages) {