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

Configure Feed

Select the types of activity you want to include in your feed.

mm/khugepaged: factor out common logic in [scan,alloc]_sleep_millisecs_store()

Both scan_sleep_millisecs_store() and alloc_sleep_millisecs_store()
perform the same operations: parse the input value, update their
respective sleep interval, reset khugepaged_sleep_expire, and wake up the
khugepaged thread.

Factor out this duplicated logic into a helper function
__sleep_millisecs_store(), and simplify both store functions.

No functional change intended.

Link: https://lkml.kernel.org/r/20251021134431.26488-1-leon.hwang@linux.dev
Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Lance Yang <lance.yang@linux.dev>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Nico Pache <npache@redhat.com>
Reviewed-by: Dev Jain <dev.jain@arm.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Leon Hwang and committed by
Andrew Morton
2da6fe91 fae4e860

+11 -16
+11 -16
mm/khugepaged.c
··· 129 129 return sysfs_emit(buf, "%u\n", khugepaged_scan_sleep_millisecs); 130 130 } 131 131 132 - static ssize_t scan_sleep_millisecs_store(struct kobject *kobj, 133 - struct kobj_attribute *attr, 134 - const char *buf, size_t count) 132 + static ssize_t __sleep_millisecs_store(const char *buf, size_t count, 133 + unsigned int *millisecs) 135 134 { 136 135 unsigned int msecs; 137 136 int err; ··· 139 140 if (err) 140 141 return -EINVAL; 141 142 142 - khugepaged_scan_sleep_millisecs = msecs; 143 + *millisecs = msecs; 143 144 khugepaged_sleep_expire = 0; 144 145 wake_up_interruptible(&khugepaged_wait); 145 146 146 147 return count; 148 + } 149 + 150 + static ssize_t scan_sleep_millisecs_store(struct kobject *kobj, 151 + struct kobj_attribute *attr, 152 + const char *buf, size_t count) 153 + { 154 + return __sleep_millisecs_store(buf, count, &khugepaged_scan_sleep_millisecs); 147 155 } 148 156 static struct kobj_attribute scan_sleep_millisecs_attr = 149 157 __ATTR_RW(scan_sleep_millisecs); ··· 166 160 struct kobj_attribute *attr, 167 161 const char *buf, size_t count) 168 162 { 169 - unsigned int msecs; 170 - int err; 171 - 172 - err = kstrtouint(buf, 10, &msecs); 173 - if (err) 174 - return -EINVAL; 175 - 176 - khugepaged_alloc_sleep_millisecs = msecs; 177 - khugepaged_sleep_expire = 0; 178 - wake_up_interruptible(&khugepaged_wait); 179 - 180 - return count; 163 + return __sleep_millisecs_store(buf, count, &khugepaged_alloc_sleep_millisecs); 181 164 } 182 165 static struct kobj_attribute alloc_sleep_millisecs_attr = 183 166 __ATTR_RW(alloc_sleep_millisecs);