All of lore.kernel.org
 help / color / mirror / Atom feed
From: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
To: "wangnan0@huawei.com" <wangnan0@huawei.com>,
	"ptesarik@suse.cz" <ptesarik@suse.cz>
Cc: "kexec@lists.infradead.org" <kexec@lists.infradead.org>,
	"hui.geng@huawei.com" <hui.geng@huawei.com>
Subject: RE: [PATCH v2] makedumpfile: code cleanup: set_bitmap
Date: Mon, 28 Apr 2014 07:27:32 +0000	[thread overview]
Message-ID: <0910DD04CBD6DE4193FCF86B9C00BE9720DF19@BPXM01GP.gisp.nec.co.jp> (raw)
In-Reply-To: <535B36A9.6000901@huawei.com>

>On 2014/4/25 16:03, Petr Tesarik wrote:
>> On Fri, 25 Apr 2014 13:25:23 +0800
>> Wang Nan <wangnan0@huawei.com> wrote:
>>
>>> On 2014/4/24 17:28, Petr Tesarik wrote:
>>>> On Thu, 24 Apr 2014 17:11:13 +0800
>>>> Wang Nan <wangnan0@huawei.com> wrote:
>>> [...]
>>>>>  set_bitmap(struct dump_bitmap *bitmap, unsigned long long pfn,
>>>>>      int val)
>>>>>  {
>>>>> @@ -3317,20 +3345,11 @@ set_bitmap(struct dump_bitmap *bitmap, unsigned long long pfn,
>>>>>  	old_offset = bitmap->offset + BUFSIZE_BITMAP * bitmap->no_block;
>>>>>  	new_offset = bitmap->offset + BUFSIZE_BITMAP * (pfn / PFN_BUFBITMAP);
>>>>
>>>> After applying this patch, both old_offset and new_offset are
>>>> calculated only to compare for equality. And new_offset is in fact
>>>> computed twice (once in set_bitmap and once in sync_bitmap).
>>>>
>>>> This could be cleaned up by replacing the offsets with:
>>>>
>>>> 	int new_no_block = pfn / PFN_BUFBITMAP;
>>>>
>>>> Then change all occurrences of if (old_offset != new_offset) to:
>>>>
>>>> 	if (bitmap->no_block != new_no_block)
>>>>
>>>> and finally re-use new_no_block in the assignment to bitmap->no_block
>>>> near the end of the function, like this:
>>>>
>>>> -		bitmap->no_block = pfn / PFN_BUFBITMAP;
>>>> +		bitmap->no_block = new_no_block;
>>>>
>>>> Petr T
>>>>
>>>>>
>>>>> -	if (0 <= bitmap->no_block && old_offset != new_offset) {
>>>>> -		if (lseek(bitmap->fd, old_offset, SEEK_SET) < 0 ) {
>>>>> -			ERRMSG("Can't seek the bitmap(%s). %s\n",
>>>>> -			    bitmap->file_name, strerror(errno));
>>>>> -			return FALSE;
>>>>> -		}
>>>>> -		if (write(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP)
>>>>> -		    != BUFSIZE_BITMAP) {
>>>>> -			ERRMSG("Can't write the bitmap(%s). %s\n",
>>>>> -			    bitmap->file_name, strerror(errno));
>>>>> +	if (old_offset != new_offset) {
>>>>> +		if (!sync_bitmap(bitmap)) {
>>>>> +			ERRMSG("Can't sync bitmap\n");
>>>>>  			return FALSE;
>>>>>  		}
>>>>> -	}
>>>>> -	if (old_offset != new_offset) {
>>>>>  		if (lseek(bitmap->fd, new_offset, SEEK_SET) < 0 ) {
>>>>>  			ERRMSG("Can't seek the bitmap(%s). %s\n",
>>>>>  			    bitmap->file_name, strerror(errno));
>>> [ .. see below .. ]
>>>
>>> Good suggestion, but new_offset is still needed to be calculated for these lseeks.
>>
>> True, but it will be calculated only once (in sync_bitmap). OTOH the
>> block number is always needed, because it is stored in bitmap->no_block.
>>
>> Okay, that can be changed, and you can store the offset instead. I
>> don't have a strong opinion on this.
>>
>>> In addition, I have another idea: what about to replace all lseek .. read/write pattern to pread/pwrite?
>>
>> Definitely! After doing that, we could even reuse the same file descriptor
>> for all processes.
>>
>
>I posted a series of patches for lseek. If Atsushi Kumagai accept them, I will
>redo this patch on top of them.

I haven't gotten a chance to review them yet, but I accept your idea.
So please give me a time for reviewing.


Thanks
Atsushi Kumagai

>> Now, since the original patch looks good as it is, let's see if Atsushi
>> Kumagai takes it into the tree and post more clean up patches afterwards.
>>
>> Petr T
>>
>


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

      reply	other threads:[~2014-04-28  7:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-14  6:15 [PATCH] makedumpfile: code cleanup: set_bitmap Wang Nan
2014-04-21  7:33 ` Atsushi Kumagai
2014-04-24  9:11   ` [PATCH v2] " Wang Nan
2014-04-24  9:28     ` Petr Tesarik
2014-04-25  5:25       ` Wang Nan
2014-04-25  8:03         ` Petr Tesarik
2014-04-26  4:31           ` Wang Nan
2014-04-28  7:27             ` Atsushi Kumagai [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0910DD04CBD6DE4193FCF86B9C00BE9720DF19@BPXM01GP.gisp.nec.co.jp \
    --to=kumagai-atsushi@mxc.nes.nec.co.jp \
    --cc=hui.geng@huawei.com \
    --cc=kexec@lists.infradead.org \
    --cc=ptesarik@suse.cz \
    --cc=wangnan0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.