[PATCH V2 1/2] nvme-core: replace ctrl page size with a macro

Chaitanya Kulkarni Chaitanya.Kulkarni at wdc.com
Mon Jul 13 20:02:07 EDT 2020


On 7/13/20 00:42, Christoph Hellwig wrote:
> On Thu, Jul 09, 2020 at 04:40:24PM -0700, Chaitanya Kulkarni wrote:
>> +/*
>> + * Default to a 4K page size, with the intention to update this
>> + * path in the future to accommodate architectures with differing
>> + * kernel and IO page sizes.
>> + */
>> +#define NVME_CTRL_PAGE_SHIFT	12
>> +#define NVME_CTRL_PAGE_SIZE	4096
> NVME_CTRL_PAGE_SIZE can be defined as
> 
> (1 << NVME_CTRL_PAGE_SHIFT) instead of duplicating the value.
This adds a calculation every time we use the macro and makes us rely on 
compiler to substitute the value, I guess we are okay with this, will 
send V3.
> 
>> index 45e94f016ec2..68f7c090cf51 100644
>> --- a/drivers/nvme/host/pci.c
>> +++ b/drivers/nvme/host/pci.c
>> @@ -348,8 +348,8 @@ static bool nvme_dbbuf_update_and_check_event(u16 value, u32 *dbbuf_db,
>>    */
>>   static int nvme_npages(unsigned size, struct nvme_dev *dev)
>>   {
>> -	unsigned nprps = DIV_ROUND_UP(size + dev->ctrl.page_size,
>> -				      dev->ctrl.page_size);
>> +	unsigned nprps = DIV_ROUND_UP(size + NVME_CTRL_PAGE_SIZE,
>> +						NVME_CTRL_PAGE_SIZE);
>>   	return DIV_ROUND_UP(8 * nprps, PAGE_SIZE - 8);
> This looks like the existing code here is wrong, as DIV_ROUND_UP already
> adds the page size itself.  But that is better left for another patch..
> 

This nprp calculation should be  ?

DIV_ROUND_UP(size, dev->ctrl.page_size);

Should I add a 3rd patch to get it done since we are touching this code 
in this series ?



More information about the Linux-nvme mailing list