Skip to contentSkip to conversation

kexec: yield to scheduler when loading kimage segments

PATCH In review Jarrett Farnitano 2 participants 5 messages Jun 11, 2018 – Jun 12, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kexec: yield to scheduler when loading kimage segments

Without yielding while loading kimage segments, a large initrd will block all other work on the CPU performing the load until it is completed. For example loading an initrd of 200MB on a low power single core system will lock up the system for a few seconds.

To increase system responsiveness to other tasks at that time, call cond_resched() in both the crash kernel and normal kernel segment loading loops.

---
 kernel/kexec_core.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/kexec_core.c +4 -0
index 5616755..8ee07d6 100644
@@ -783,6 +783,8 @@ static int kimage_load_normal_segment(struct kimage *image,
 		else
 			buf += mchunk;
 		mbytes -= mchunk;
+
+		cond_resched();
 	}
 out:
 	return result;
@@ -847,6 +849,8 @@ static int kimage_load_crash_segment(struct kimage *image,
 		else
 			buf += mchunk;
 		mbytes -= mchunk;
+
+		cond_resched();
 	}
 out:
 	return result;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 9 lines · Jarrett Farnitano

Without yielding while loading kimage segments, a large initrd will block all other work on the CPU performing the load until it is completed. For example loading an initrd of 200MB on a low power single core system will lock up the system for a few seconds.

To increase system responsiveness to other tasks at that time, call cond_resched() in both the crash kernel and normal kernel segment loading loops.

I remember years ago something like this was proposed and there was a reason we did not include it. I don't remember what that reason is right now. But I am reluctant to ack this until I remember.

Is there a practical problem with unresponsiveness? You are talking an embedded machine and rarely are there people in front of embedded computers these days.

Eric

Quoted 27 lines
---
 kernel/kexec_core.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/kexec_core.c +4 -0
index 5616755..8ee07d6 100644
@@ -783,6 +783,8 @@ static int kimage_load_normal_segment(struct kimage *image,
 		else
 			buf += mchunk;
 		mbytes -= mchunk;
+
+		cond_resched();
 	}
 out:
 	return result;
@@ -847,6 +849,8 @@ static int kimage_load_crash_segment(struct kimage *image,
 		else
 			buf += mchunk;
 		mbytes -= mchunk;
+
+		cond_resched();
 	}
 out:
 	return result;
#2 lore raw
Quoted 5 lines

On 6/11/18, 4:00 PM, "Eric W. Biederman" <[email protected]> wrote:

Is there a practical problem with unresponsiveness? You are talking an embedded machine and rarely are there people in front of embedded computers these days.

I did run into a practical problem. Hardware watchdogs on embedded systems can have short timers on the order of seconds. If the system is locked up for a few seconds with only a single core available, the watchdog may not be pet in a timely fashion. If this happens, the hardware watchdog will fire and reset the system.

This really only becomes a problem when you are working with a single core, a decently sized initrd, and have a constrained hardware watchdog.

Jarrett

#3 lore raw
Quoted 12 lines · Jarrett
Quoted 5 lines

On 6/11/18, 4:00 PM, "Eric W. Biederman" <[email protected]> wrote:

Is there a practical problem with unresponsiveness? You are talking an embedded machine and rarely are there people in front of embedded computers these days.

I did run into a practical problem. Hardware watchdogs on embedded systems can have short timers on the order of seconds. If the system is locked up for a few seconds with only a single core available, the watchdog may not be pet in a timely fashion. If this happens, the hardware watchdog will fire and reset the system.

Quoted 3 lines

This really only becomes a problem when you are working with a single core, a decently sized initrd, and have a constrained hardware watchdog.

That would do it.

My foggy memory says this was not included back in the days where cond_resched was spelled "if (need_resched) schedule();" There were concerns with spreading that too thin. cond_resched in this path seems as reasonable as anything.

Eric

Reviewed-by on v1 1/1
#4 lore raw
In reply to Jarrett Farnitano
Quoted 11 lines · Jarrett Farnitano

Without yielding while loading kimage segments, a large initrd will block all other work on the CPU performing the load until it is completed. For example loading an initrd of 200MB on a low power single core system will lock up the system for a few seconds.

To increase system responsiveness to other tasks at that time, call cond_resched() in both the crash kernel and normal kernel segment loading loops.

Quoted 26 lines
---
 kernel/kexec_core.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/kexec_core.c +4 -0
index 5616755..8ee07d6 100644
@@ -783,6 +783,8 @@ static int kimage_load_normal_segment(struct kimage *image,
 		else
 			buf += mchunk;
 		mbytes -= mchunk;
+
+		cond_resched();
 	}
 out:
 	return result;
@@ -847,6 +849,8 @@ static int kimage_load_crash_segment(struct kimage *image,
 		else
 			buf += mchunk;
 		mbytes -= mchunk;
+
+		cond_resched();
 	}
 out:
 	return result;