From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2337EC43457 for ; Thu, 15 Oct 2020 10:00:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C758F22249 for ; Thu, 15 Oct 2020 10:00:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730940AbgJOKAW (ORCPT ); Thu, 15 Oct 2020 06:00:22 -0400 Received: from out4436.biz.mail.alibaba.com ([47.88.44.36]:62700 "EHLO out4436.biz.mail.alibaba.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726157AbgJOKAW (ORCPT ); Thu, 15 Oct 2020 06:00:22 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=richard.weiyang@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0UC62.Wb_1602756009; Received: from localhost(mailfrom:richard.weiyang@linux.alibaba.com fp:SMTPD_---0UC62.Wb_1602756009) by smtp.aliyun-inc.com(127.0.0.1); Thu, 15 Oct 2020 18:00:09 +0800 Date: Thu, 15 Oct 2020 18:00:09 +0800 From: Wei Yang To: David Hildenbrand Cc: Wei Yang , linux-kernel@vger.kernel.org, linux-mm@kvack.org, virtualization@lists.linux-foundation.org, Andrew Morton , "Michael S . Tsirkin" , Jason Wang , Pankaj Gupta Subject: Re: [PATCH v1 02/29] virtio-mem: simplify calculation in virtio_mem_mb_state_prepare_next_mb() Message-ID: <20201015100009.GH86495@L-31X9LVDL-1304.local> Reply-To: Wei Yang References: <20201012125323.17509-1-david@redhat.com> <20201012125323.17509-3-david@redhat.com> <20201015040204.GB86495@L-31X9LVDL-1304.local> <730d6536-f6a6-72e5-327f-00ce1224b730@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <730d6536-f6a6-72e5-327f-00ce1224b730@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 15, 2020 at 10:00:15AM +0200, David Hildenbrand wrote: >On 15.10.20 06:02, Wei Yang wrote: >> On Mon, Oct 12, 2020 at 02:52:56PM +0200, David Hildenbrand wrote: >>> We actually need one byte less (next_mb_id is exclusive, first_mb_id is >>> inclusive). Simplify. >>> >>> Cc: "Michael S. Tsirkin" >>> Cc: Jason Wang >>> Cc: Pankaj Gupta >>> Signed-off-by: David Hildenbrand >>> --- >>> drivers/virtio/virtio_mem.c | 4 ++-- >>> 1 file changed, 2 insertions(+), 2 deletions(-) >>> >>> diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c >>> index a1f5bf7a571a..670b3faf412d 100644 >>> --- a/drivers/virtio/virtio_mem.c >>> +++ b/drivers/virtio/virtio_mem.c >>> @@ -257,8 +257,8 @@ static enum virtio_mem_mb_state virtio_mem_mb_get_state(struct virtio_mem *vm, >>> */ >>> static int virtio_mem_mb_state_prepare_next_mb(struct virtio_mem *vm) >>> { >>> - unsigned long old_bytes = vm->next_mb_id - vm->first_mb_id + 1; >>> - unsigned long new_bytes = vm->next_mb_id - vm->first_mb_id + 2; >>> + unsigned long old_bytes = vm->next_mb_id - vm->first_mb_id; >>> + unsigned long new_bytes = old_bytes + 1; >> >> This is correct. >> >> So this looks more like a fix? > >We allocate an additional new page "one memory block too early". > >So we would allocate the first page for blocks 0..510, and already >allocate the second page with block 511, although we could have fit it >into the first page. Block 512 will then find that the second page is >already there and simply use the second page. > >So as we do it consistently, nothing will go wrong - that's why I >avoided using the "fix" terminology. > Yes, my feeling is this is not a simplification. Instead this is a more precise calculation. How about use this subject? virtio-mem: more precise calculation in virtio_mem_mb_state_prepare_next_mb() >Thanks! > >-- >Thanks, > >David / dhildenb -- Wei Yang Help you, Help me