forked from mirrors/linux
		
	block: fix default IO priority handling
The default IO priority is the best effort (BE) class with the normal priority level IOPRIO_NORM (4). However, get_task_ioprio() returns IOPRIO_CLASS_NONE/IOPRIO_NORM as the default priority and get_current_ioprio() returns IOPRIO_CLASS_NONE/0. Let's be consistent with the defined default and have both of these functions return the default priority IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_NORM) when the user did not define another default IO priority for the task. In include/uapi/linux/ioprio.h, introduce the IOPRIO_BE_NORM macro as an alias to IOPRIO_NORM to clarify that this default level applies to the BE priotity class. In include/linux/ioprio.h, define the macro IOPRIO_DEFAULT as IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_BE_NORM) and use this new macro when setting a priority to the default. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com> Link: https://lore.kernel.org/r/20210811033702.368488-7-damien.lemoal@wdc.com [axboe: drop unnecessary lightnvm change] Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
		
							parent
							
								
									202bc942c5
								
							
						
					
					
						commit
						e70344c059
					
				
					 4 changed files with 13 additions and 7 deletions
				
			
		| 
						 | 
					@ -5411,7 +5411,7 @@ static struct bfq_queue **bfq_async_queue_prio(struct bfq_data *bfqd,
 | 
				
			||||||
	case IOPRIO_CLASS_RT:
 | 
						case IOPRIO_CLASS_RT:
 | 
				
			||||||
		return &bfqg->async_bfqq[0][ioprio];
 | 
							return &bfqg->async_bfqq[0][ioprio];
 | 
				
			||||||
	case IOPRIO_CLASS_NONE:
 | 
						case IOPRIO_CLASS_NONE:
 | 
				
			||||||
		ioprio = IOPRIO_NORM;
 | 
							ioprio = IOPRIO_BE_NORM;
 | 
				
			||||||
		fallthrough;
 | 
							fallthrough;
 | 
				
			||||||
	case IOPRIO_CLASS_BE:
 | 
						case IOPRIO_CLASS_BE:
 | 
				
			||||||
		return &bfqg->async_bfqq[1][ioprio];
 | 
							return &bfqg->async_bfqq[1][ioprio];
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -170,7 +170,7 @@ static int get_task_ioprio(struct task_struct *p)
 | 
				
			||||||
	ret = security_task_getioprio(p);
 | 
						ret = security_task_getioprio(p);
 | 
				
			||||||
	if (ret)
 | 
						if (ret)
 | 
				
			||||||
		goto out;
 | 
							goto out;
 | 
				
			||||||
	ret = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, IOPRIO_NORM);
 | 
						ret = IOPRIO_DEFAULT;
 | 
				
			||||||
	task_lock(p);
 | 
						task_lock(p);
 | 
				
			||||||
	if (p->io_context)
 | 
						if (p->io_context)
 | 
				
			||||||
		ret = p->io_context->ioprio;
 | 
							ret = p->io_context->ioprio;
 | 
				
			||||||
| 
						 | 
					@ -182,9 +182,9 @@ static int get_task_ioprio(struct task_struct *p)
 | 
				
			||||||
int ioprio_best(unsigned short aprio, unsigned short bprio)
 | 
					int ioprio_best(unsigned short aprio, unsigned short bprio)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (!ioprio_valid(aprio))
 | 
						if (!ioprio_valid(aprio))
 | 
				
			||||||
		aprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_NORM);
 | 
							aprio = IOPRIO_DEFAULT;
 | 
				
			||||||
	if (!ioprio_valid(bprio))
 | 
						if (!ioprio_valid(bprio))
 | 
				
			||||||
		bprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_NORM);
 | 
							bprio = IOPRIO_DEFAULT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return min(aprio, bprio);
 | 
						return min(aprio, bprio);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,6 +8,11 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <uapi/linux/ioprio.h>
 | 
					#include <uapi/linux/ioprio.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Default IO priority.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define IOPRIO_DEFAULT	IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_BE_NORM)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Check that a priority value has a valid class.
 | 
					 * Check that a priority value has a valid class.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
| 
						 | 
					@ -51,7 +56,7 @@ static inline int get_current_ioprio(void)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (ioc)
 | 
						if (ioc)
 | 
				
			||||||
		return ioc->ioprio;
 | 
							return ioc->ioprio;
 | 
				
			||||||
	return IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0);
 | 
						return IOPRIO_DEFAULT;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,8 +44,9 @@ enum {
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Fallback BE priority
 | 
					 * Fallback BE priority level.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
#define IOPRIO_NORM	(4)
 | 
					#define IOPRIO_NORM	4
 | 
				
			||||||
 | 
					#define IOPRIO_BE_NORM	IOPRIO_NORM
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* _UAPI_LINUX_IOPRIO_H */
 | 
					#endif /* _UAPI_LINUX_IOPRIO_H */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue